<div class="content_title"><a href="/master/employees">Pracownicy</a> > dodaj</div>
<script type="text/javascript">
$(document).ready(function() {
	
		//typ
		function change_typ($value)
		{
			//pracownik
			if ($value == 2)
			{
				$('#pracownik').show();
				$('#pracownik input').removeAttr("disabled");
				$('#pracownik select').removeAttr("disabled"); 
		 
			}//ksiegowa	
			else if($value == 3)
			{
				$('#pracownik').hide();
				$('#pracownik input').attr("disabled", true);
				$('#pracownik select').attr("disabled", true);
			}
			else
				alert('Wystapił błąd: nieprawidłowy typ afilianta');
		}
			
		$("#typ").change(function(){
				change_typ($("#typ").val());
			});
		$("#typ").change();	
					
	
		function setCustomersSelectVisibility(){
			if ($('#active').val() == 1) {
				$('#customers_row').show();
			}
			else
			{
				$('#customers_row').hide();				
			}
		}
		setCustomersSelectVisibility();
		
		$('#active').change(function() {
		  setCustomersSelectVisibility();
		});		
		
		$('#customers').multiSelect();

});		
</script>
<?php if(!empty($info))
	echo '<p class="info_box">'.$info.'</p>';
?>
<form action="/master/add_employee" method="post">
		<!-- IMIE -->
		<p>
			<label for="nazwa" class="form_label">Login*</label>
			<input type="text" name="imie" value="<?php if(!empty($form_data['imie'])) echo $form_data['imie'];?>"/>
			<span class="error_info"><?php if(!empty($errors['imie'])) echo $errors['imie'];?></span>
		</p>
		<!-- EMAIL -->	
		<p>
			<label for="email" class="form_label">Email*</label>
			<input type="text" name="email" value="<?php if(!empty($form_data['email'])) echo $form_data['email'];?>"/>
			<span class="error_info"><?php if(!empty($errors['email'])) echo $errors['email'];?></span>
		</p>
		<!-- AKTYWNOSC -->
		<p>
			<label for="active" class="form_label">Aktywność*</label>
				<select name="active" id="active">
					<?php
						echo '<option value="1" '.((!empty($form_data['active']) && $form_data['active']==1) ? 'selected="selected"':'').'>tak</option>';
						echo '<option value="0" '.((!empty($form_data['active']) && $form_data['active']==0) ? 'selected="selected"':'').'>nie</option>';
					?>
				</select>	
		</p>		
		<!-- TYPE -->
		<p>
			<label for="typ" class="form_label">Typ*</label>
			<?php
					if(isset($employee_types) && count($employee_types)>0)
					{
						echo '<select name="type" id="typ">';
							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'
			?>
			<span class="error_info"><?php if(!empty($errors['type'])) echo $errors['type'];?></span>
		</p>						

		<!-- HASLO -->
		<p>
			<label for="password" class="form_label">Hasło*</label>
			<input type="password" name="haslo" value="<?php if(!empty($form_data['haslo'])) echo $form_data['haslo'];?>"/>
			<span class="error_info"><?php if(!empty($errors['haslo'])) echo $errors['haslo'];?></span>
		</p>
		<!-- POTWIERDZ HASŁO -->
		<p>
			<label for="haslo2" class="form_label">Potwierdź hasło*</label>
			<input type="password" name="haslo2" value="<?php if(!empty($form_data['haslo2'])) echo $form_data['haslo2'];?>" />
			<span class="error_info"><?php if(!empty($errors['haslo2'])) echo $errors['haslo2'];?></span>
		</p>
			
		<div id="pracownik">	
				<!-- UTRZYMANIE -->
				<p>
					<label for="utrzymanie" class="form_label">Utrzymanie*</label>
						<select name="utrzymanie">
							<?php
								for($i=10;$i<=40;$i+=5)
									echo '<option value="'.$i.'" '.((!empty($form_data['upzymanie']) && $form_data['upzymanie']==$i) ? 'selected="selected"':'').' >'.$i.'%</option>'; 
							?>
						</select>
					<span class="error_info"><?php if(!empty($errors['utrzymanie'])) echo $errors['utrzymanie'];?></span>
				</p>
				<!-- RABAT -->
				<p>
					<label for="rabat" class="form_label">Rabat*</label>
					<input type="text" name="rabat" value="<?php if(isset($form_data['rabat'])) echo $form_data['rabat'];?>" size="4"/>
					<span class="error_info"><?php if(!empty($errors['rabat'])) echo $errors['rabat'];?></span>
				</p>
				<!-- KLIENCI -->
				<p id="customers_row" <?php echo (!empty($form_data['active']) && $form_data['active']==1) ? 'style="display:block;"':'style="display:none;"' ?> >
					<label for="nazwa" class="form_label">Klienci*</label>
						<?php
							
							function is_in_array($val,$arr)
							{
				
								for($i=0;$i<count($arr);$i++)
								{
									if($arr[$i] == $val)
									{
										return pUE;
									}
								}
								
								return FALSE;						
							}
							
							if(!empty($free_customers) && count($free_customers) > 0)
							{
								echo '<select id="customers" name="customers[]" class="arc90_multiselect" multiple="multiple" title="customers">';
									foreach($free_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 wolnych klientów';
							?>
				</p>
		</div>		
		<p>
                <div class="formHr">&nbsp;</div>
				<input type="submit" value="Dodaj" class="formButton"/>
                <input type="button" name="anuluj" value="Anuluj" class="formButton" onClick="document.location.href='<?php echo base_url();?>master/employees';"/>				
				<span class="field_required">* - pole wymagane</span>			
		</p>
</form>