<div style="border-bottom:1px solid #999999;width:100%">Edycja pracownika</div>
<script language="JavaScript" type="Text/JavaScript" src="/files/js/arc90_multiselect.js"></script>
<script type="text/javascript">
$(document).ready(function() {
		function setCustomersSelectVisibility(){
			if ($('#active').val() == 1) {
				$('#customers_row').show();
				$('#managers_row').hide();
			}
			else
			{
				$('#customers_row').hide();
				$('#managers_row').show();				
			}
		}
		setCustomersSelectVisibility();
		
		$('#active').change(function() {
		  setCustomersSelectVisibility();
		});		
		
		$(function()
			{
				$('#customers').multiSelect(
				{
					//select_all_min: 3,
					//no_selection: "Please select a few items!",
					selected_text: " clicked"
			});
		});
});		
</script>
<?php if(!empty($info))
	echo '<p class="info_box">'.$info.'</p>';
?>
<form action="" method="post">
	<table>
		<!-- IMIE -->
		<tr>
			<td width="200">Imię</td>
			<td>
				<input type="text" name="imie" value="<?php if(!empty($form_data['imie'])) echo $form_data['imie'];?>"/>
			</td>
		</tr>
		<tr>
			<td></td>
			<td><span class="error_info"><?php if(!empty($errors['imie'])) echo $errors['imie'];?></span></td>
		</tr>
		<!-- EMAIL -->	
		<tr>
			<td>Email</td>
			<td>
				<input type="text" name="email" value="<?php if(!empty($form_data['email'])) echo $form_data['email'];?>"/>
			</td>
		</tr>		
		<tr>
			<td></td>
			<td><span class="error_info"><?php if(!empty($errors['email'])) echo $errors['email'];?></span></td>				
		</tr>
		<!-- TYPE -->
		<tr>
			<td>Typ</td>
			<td>
				<?php
					if(isset($employee_types) && count($employee_types)>0)
					{
						echo '<select name="type">';
							foreach($employee_types as $k=>$v)
							{
								if($v != 'master')
								echo '<option value="'.$k.'" '.((!empty($form_data['type']) && ($k == $form_data['type'])) ? 'selected="selected"':'').'>'.$v.'</option>';
							}
						echo '</select>';
					}
					else
						echo 'brak danych'
				?>
			</td>
		</tr>
		<tr>
			<td></td>
			<td><span class="error_info"><?php if(!empty($errors['type'])) echo $errors['type'];?></span></td>
		</tr>
				
		<!-- HASLO -->
		<tr>
			<td>Nowe hasło</td>
			<td><input type="password" name="haslo" value="<?php if(!empty($form_data['haslo'])) echo $form_data['haslo'];?>"/></td>
			
		</tr>		
		<tr>
			<td></td>
			<td><span class="error_info"><?php if(!empty($errors['haslo'])) echo $errors['haslo'];?></span></td>
		</tr>
		<!-- POTWIERDZ HASŁO -->
		<tr>
			<td>Potwierdź nowe hasło</td>
			<td><input type="password" name="haslo2" value="<?php if(!empty($form_data['haslo2'])) echo $form_data['haslo2'];?>"/></td>
		</tr>
		<tr>
			<td></td>
			<td><span class="error_info"><?php if(!empty($errors['haslo2'])) echo $errors['haslo2'];?></span></td>
		</tr>		
		<!-- UTRZYMANIE -->
		<tr>
			<td width="200">Utrzymanie</td>
			<td>
				<select name="utrzymanie">
					<?php
						for($i=10;$i<=40;$i+=5)
							echo '<option value="'.$i.'" '.((!empty($form_data['utrzymanie']) && $form_data['utrzymanie']==$i) ? 'selected="selected"':'').' >'.$i.'%</option>'; 
					?>
				</select>
			</td>			
		</tr>
		<tr>
			<td></td>
			<td><span class="error_info"><?php if(!empty($errors['utrzymanie'])) echo $errors['utrzymanie'];?></span></td>
		</tr>
		<!-- RABAT -->
		<tr>
			<td width="200">Rabat</td>
			<td>
				<input type="text" name="rabat" value="<?php if(isset($form_data['rabat'])) echo $form_data['rabat'];?>"/>
			</td>	
		</tr>
		<tr>
			<td></td>
			<td><span class="error_info"><?php if(!empty($errors['rabat'])) echo $errors['rabat'];?></span></td>
		</tr>
		<!-- AKTYWNOSC -->
		<tr>
			<td width="200">Aktywny</td>
			<td>
				<select name="active" id="active">
					<?php
						echo '<option value="1" '.((isset($form_data['active']) && $form_data['active']==1) ? 'selected="selected"':'').'>tak</option>';
						echo '<option value="0" '.((isset($form_data['active']) && $form_data['active']==0) ? 'selected="selected"':'').'>nie</option>';
					?>
				</select>	
			</td>					
		</tr>
		<!-- KLIENCI -->
		<tr id="customers_row" <?php echo (!empty($form_data['active']) && $form_data['active']==1) ? 'style="display:block;"':'style="display:none;"' ?> >
			<td width="200" valign="top">Klienci</td>
			<td>
				<?php
	
					function is_in_array($val,$arr)
					{
		
						for($i=0;$i<count($arr);$i++)
						{
							if($arr[$i] == $val)
							{
								return TRUE;
							}
						}						
						return FALSE;						
					}				
											
					if(!empty($customers) && count($customers) > 0)
					{
						echo '<select id="customers" name="customers" class="arc90_multiselect" multiple="multiple" title="customers">';
							foreach($customers as $k=>$v)
								echo '<option value="'.$v['id'].'"  '.((!empty($form_data['customers']) && is_in_array($v['id'], $form_data['customers'])) ? 'selected="selected"':'').'">'.$v['name'].'</option>';
						echo '</select>';
					}
					else
						echo 'brak danych';
					?>
			</td>
		</tr>
		<!-- PRACOWNICY -->
		<tr id="managers_row" <?php echo (!empty($form_data['active']) && $form_data['active']==1) ? 'style="display:none;"':'style="display:block;"' ?> >
			<td width="200" valign="top">Przepisz klientów</td>
			<td>
				<?php
					if(isset($employees) && count($employees)>0)
					{
						echo '<select name="new_manager" id="new_manager">';
							foreach($employees as $k=>$v)
							{
								if($v['id'] != $superadmin['id'])
									echo '<option value="'.$v['id'].'" '.((!empty($form_data['new_manager']) && ($v['id']==$form_data['new_manager'])) ? 'selected="selected"':'').'">'.$v['name'].'</option>';
							}
						echo '</select>';
					}
					else
						echo 'brak danych'						
				?>	
			</td>					
		</tr>
		<tr>
			<td></td>
			<td><span class="error_info"><?php if(!empty($errors['new_manager'])) echo $errors['new_manager'];?></span></td>
		</tr>													
		<tr>
			<td colspan="2" align="left">
				<a href="/master/employees" class="simpleButton">Anuluj</a>
				<input type="submit"  value="Edytuj"/>
			</td>
		</tr>
	</table>
</form>