<?php

// No direct access.
use Joomla\CMS\Router\Route;

defined('_JEXEC') or die;

?>

<form method="post" action="<?php echo $this->address; ?>" id='form-club'>
<input type='hidden' name='id' value='<?php echo $this->object->getId(); ?>'>
<h2>Stammdaten</h2>
<table>
  <tr>
    <td>Bezeichnung</td>
    <td><input type='text' name='name' value='<?php echo htmlentities($this->object->getName()); ?>'></td>
  </tr>
  
  <tr>
    <td>Adresse</td>
    <td>
    	<textarea name='address' rows='5'><?php echo htmlentities($this->object->getAddress()); ?></textarea>
	</td>
  </tr>
  
  <tr>
    <td>Stadt</td>
    <td><input type='text' name='city' value='<?php echo htmlentities($this->object->getCity()); ?>'></td>
  </tr>
  
  <tr>
    <td>Homepage</td>
    <td><input type='text' name='homepage' value='<?php echo htmlentities($this->object->getHomepage()); ?>'></td>
  </tr>
  
  <tr>
    <td>E-Mail</td>
    <td><input type='text' name='mail' value='<?php echo htmlentities($this->object->getMail()); ?>'></td>
  </tr>
  <tr>
    <td>IBAN</td>
    <td><input type='text' name='iban' value='<?php echo htmlentities($this->object->getIban()); ?>'></td>
  </tr>
  
  <tr>
    <td>BIC</td>
    <td><input type='text' name='bic' value='<?php echo htmlentities($this->object->getBic()); ?>'></td>
  </tr>
  
  <tr>
    <td>Gemeinn&uuml;tzig</td>
    <td><input type='checkbox' name='charitable' value='1' <?php echo $this->object->isCharitable() ? 'checked' : ''; ?>></td>
  </tr>
  
  <tr>
    <td>Vorsitzende/r</td>
    <td>
    	<select name='president'>
    		<?php foreach($this->users as $u): ?>
    			<option value='<?php echo $u->getId(); ?>' <?php if ($this->object->getPresident() !== null && $this->object->getPresident()->getId() == $u->getId()) echo 'selected="selected"'; ?>>
    				<?php echo htmlentities("{$u->getName()}, {$u->getCity()}"); ?>
				</option>
			<?php endforeach; ?>
    	</select>
    </td>
  </tr>
  
  
  <?php if(! $this->isNew): ?>
  <tr>
    <td>ID</td>
    <td><?php echo $this->object->getId(); ?></td>
  </tr>
  <?php endif; ?>
</table>


<?php if(! $this->isNew): ?>
<h2>Angebote</h2>
<?php foreach($this->object->getOffers() as $oconf): ?>
	<input type='checkbox' name='offers[]' value='<?php echo $oconf['offer']->getId(); ?>' <?php if($oconf['valid']) echo 'checked="checked"';?>> 
	<?php echo htmlentities($oconf['offer']->getName()); ?><br />
<?php endforeach; ?>

<h2>Posten</h2>
<?php if(sizeof($this->object->getUsers()) == 0 ): ?>
	<p>Dem Verein ist bisher kein Posten zugewiesen.</p>
<?php else: ?>
    <table width='100%' class='table table-stiped, table-hover' id='userassocs'>
    	<tr>
    		<th width='20%'>Rolle</th>
    		<th width='25%'>Name</th>
    		<th width='10%'>Stadt</th>
    		<th width='5%' style='text-align: center;'>Admin?</th>
    		<th></th>
    		<th width='5%'>ID</th>
    	</tr>
    	<?php foreach($this->object->getUsers() as $ua): ?>
        	<?php
        	   $user = $ua->getUser();
        	   if($user == null)
        	   {
        	       $username = '<i>Derzeit vakant</i>';
        	       $usercity = '';
        	   }
        	   else
        	   {
        	       $username = htmlentities($user->getName());
        	       $usercity = htmlentities($user->getCity());
        	   }
        	?>
    		<tr id='userassoc-<?php echo $ua->getId(); ?>'>
    			<td><?php echo htmlentities($ua->getPosition()->getName()); ?></td>
    			<td><?php echo $username; ?></td>
    			<td><?php echo $usercity; ?></td>
    			<td style='text-align: center;'><?php if($ua->isAdmin()) echo "<span class='icon-checkmark'></span>"; ?></td>
    			<td>
    				<a href='<?php echo Route::_("index.php?option=com_clubs&view=clubposition&layout=edit&club={$this->object->getId()}&id={$ua->getId()}"); ?>' class='edit-position'><span class='icon-edit'></span></a>
    				<a href='<?php echo Route::_("index.php?option=com_clubs&task=clubposition.delete&format=json&id={$ua->getId()}"); ?>' class='del-position'><span class='icon-delete'></span></a>
    			</td>
    			<td><?php echo $ua->getId(); ?></td>
    		</tr>
    	<?php endforeach; ?>
    </table>
<?php endif; ?>
<p><a href='<?php echo Route::_("index.php?option=com_clubs&view=clubposition&layout=edit&club={$this->object->getId()}&id=new"); ?>' id='new-position'><span class='icon-new'></span> Neuen Posten einf&uuml;gen</a></p>
<?php endif; ?>

<input type='submit' value='Speichern' class='form-exit'> <br /><a href='<?php echo Route::_('index.php?option=com_clubs&view=clubs'); ?>' class='form-exit'>Zur&uuml;ck zur &Uuml;bersicht</a>
</form>

<div id='dialog-club' class='dialog-hidden'>
    <div class='background'></div>
    <div class='dialog'>Ein Test</div>
    <div id='hidden-id'><?php echo $this->object->getId(); ?></div>
</div>