<?php
if (isset ( $_POST ['submit'] )) {
	$getid = $db->get_col ( "employees", array ("email" => $uemail ), 'e_id' );
	$e_id = $getid [0];
	
	if ($_POST ['date1'] != '')
		$_POST ['date1'] = date ( 'Y-m-d', strtotime ( $_POST ['date1'] ) );
	if ($_POST ['date2'] != '')
		$_POST ['date2'] = date ( 'Y-m-d', strtotime ( $_POST ['date2'] ) );
	$date1 = strtotime ( $_POST ['date1'] );
	$date2 = strtotime ( $_POST ['date2'] );
	$current_date = date ( 'Y-m-d' );
	
	$office = $db->get_row ( 'office', array ('id' => 1 ) );
	
	{
		$count = 0;
		if ($_POST ['t_leave'] == '' || $_POST ['r_leave'] == '' || $e_id == '') {
			?>
<div class="hide1">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-2" class="gritter-item-wrapper gritter-warning"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">
				<div class="gritter-close" id="gritterremove"
					style="display: inline;"></div>
				<h5>Oops! Please Select The Type Of Leave Or Range Of Leave Or
					Select The Name Or Select The Date ...</h5>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
		
		}
		if ($_POST ['t_leave'] == 'casual') {
			$firsthalfcasual = $db->run ( "SELECT SUM( firsthalf )FROM attendence WHERE e_id = $e_id
							and t_leave= 'casual'" )->fetchColumn ();
			$secondhalfcasual = $db->run ( "SELECT SUM( secondhalf )FROM attendence WHERE e_id = $e_id
									and t_leave= 'casual'" )->fetchColumn ();
			$casual = $firsthalfcasual + $secondhalfcasual;
			$office ['c_leave'];
			if ($office ['c_leave'] <= $casual) {
				?>
<div class="hide1">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-2" class="gritter-item-wrapper gritter-warning"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">
				<div class="gritter-close" id="gritterremove"
					style="display: inline;"></div>
				<h5>Oops! No Casual Leave Remaining...</h5>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
				
				$count = 5;
			}
		
		}
		if ($_POST ['t_leave'] == 'sick') {
			$firsthalfsick = $db->run ( "SELECT SUM( firsthalf )FROM attendence WHERE e_id = $e_id
											and t_leave= 'sick'" )->fetchColumn ();
			$secondhalfsick = $db->run ( "SELECT SUM( secondhalf )FROM attendence WHERE e_id = $e_id
											and t_leave= 'sick'" )->fetchColumn ();
			
			$sick = $firsthalfsick + $secondhalfsick;
			if ($office ['s_leave'] <= $sick) {
				?>
<div class="hide1">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-2" class="gritter-item-wrapper gritter-warning"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">
				<div class="gritter-close" id="gritterremove"
					style="display: inline;"></div>
				<h5>Oops! No Sick Leave Remaining...</h5>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
				
				$count = 5;
			}
		}
		if ($_POST ['t_leave'] == 'maternity') {
			$firsthalfmaternity = $db->run ( "SELECT SUM( firsthalf )FROM attendence WHERE e_id = $e_id
											and t_leave= 'maternity'" )->fetchColumn ();
			$secondhalfmaternity = $db->run ( "SELECT SUM( secondhalf )FROM attendence WHERE e_id = $e_id
											and t_leave= 'maternity'" )->fetchColumn ();
			
			$maternity = $firsthalfmaternity + $secondhalfmaternity;
			if ($office ['m_leave'] <= $maternity) {
				?>
<div class="hide1">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-2" class="gritter-item-wrapper gritter-warning"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">
				<div class="gritter-close" id="gritterremove"
					style="display: inline;"></div>
				<h5>Oops! No Maternity Leave Remaining...</h5>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
				
				$count = 5;
			}
		}
		if ($_POST ['t_leave'] == 'other') {
			$firsthalfother = $db->run ( "SELECT SUM( firsthalf )FROM attendence WHERE e_id = $e_id
											and t_leave= 'other'" )->fetchColumn ();
			$secondhalfother = $db->run ( "SELECT SUM( secondhalf )FROM attendence WHERE e_id = $e_id
											and t_leave= 'other'" )->fetchColumn ();
			
			$other = $firsthalfother + $secondhalfother;
			if ($office ['o_leave'] <= $other) {
				?>
<div class="hide1">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-2" class="gritter-item-wrapper gritter-warning"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">
				<div class="gritter-close" id="gritterremove"
					style="display: inline;"></div>
				<h5>Oops! No Other Leave Remaining...</h5>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
				
				$count = 5;
			}
		}
		if ($count != 5) {
			
			// retrieve eventual CLI parameters
			$cli = (isset ( $argc ) && $argc > 1);
			if ($cli) {
				if (isset ( $argv [1] ))
					$_GET ['file'] = $argv [1];
				if (isset ( $argv [2] ))
					$_GET ['dir'] = $argv [2];
				if (isset ( $argv [3] ))
					$_GET ['pics'] = $argv [3];
			}
			
			// set variables
			$dir_dest = (isset ( $_GET ['dir'] ) ? $_GET ['dir'] : 'uploads/employees/' . $e_id);
			$dir_pics = (isset ( $_GET ['pics'] ) ? $_GET ['pics'] : $dir_dest);
			
			if ($date2 == '') {
				if ($_FILES ['application'] ['name'] != '') {
					// echo 'application ke andr';
					// we create an instance of the class, giving as argument
					// the PHP object
					// corresponding to the file field from the form
					// All the uploads are accessible from the PHP object
					// $_FILES
					
					$name = mt_rand ( 15, 250 ) . '___' . preg_replace ( '/\s+/', '', $_FILES ['application'] ['name'] );
					$_FILES ['application'] ['name'] = str_replace ( array ('(', ')' ), '', $name );
					$handle = new upload ( $_FILES ['application'] );
					
					// then we check if the file has been uploaded properly
					// in its *temporary* location in the server (often, it is
					// /tmp)
					if ($handle->uploaded) {
						// yes, the file is on the server
						// now, we start the upload 'process'. That is, to copy
						// the uploaded file
						// from its temporary location to the wanted location
						// It could be something like
						// $handle->Process('/home/www/my_uploads/');
						// we now process the image a second time, with some
						// other settings
						
						$handle->image_resize = true;
						$handle->image_ratio_crop = true;
						$handle->image_y = 200;
						$handle->image_x = 250;
						
						$handle->Process ( $dir_dest );
						
						// we check if everything went OK
						if ($handle->processed) {
							// everything was fine !
							$application = $_FILES ['application'] ['name'];
							
							if ($_POST ['r_leave'] == 'fullday') {
								
								$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date1'] ) );
								if ($check1) {
									$full = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date1'] ), array ('date' => $_POST ['date1'], 'e_id' => $e_id ) );
									if ($full) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								} else {
									$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date1'] ) );
									
									if ($query1) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								}
							}
							
							if ($_POST ['r_leave'] == 'secondhalf') {
								$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date1'] ) );
								if ($check1) {
									$sec = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.00', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date1'] ), array ('date' => $_POST ['date1'], 'e_id' => $e_id ) );
									if ($sec) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								} else {
									$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date1'] ) );
									
									if ($query1) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								}
							}
							if ($_POST ['r_leave'] == 'firsthalf') {
								$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date1'] ) );
								if ($check1) {
									$first = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.00', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date1'] ), array ('date' => $_POST ['date1'], 'e_id' => $e_id ) );
									
									if ($first) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								} else {
									$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date1'] ) );
									
									if ($query1) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								}
							}
						
						} // --handle proccessed
					} // --handle upload
				} 				// --application are not blank
				else {
					if ($_POST ['r_leave'] == 'fullday') {
						$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date1'] ) );
						if ($check1) {
							$full1 = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date1'] ), array ('date' => $_POST ['date1'], 'e_id' => $e_id ) );
							
							if ($full1) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
							
							}
						} else {
							$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date1'] ) );
							
							if ($query1) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
							
							}
						}
					}
					
					if ($_POST ['r_leave'] == 'secondhalf') {
						$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date1'] ) );
						if ($check1) {
							$sec1 = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.00', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date1'] ), array ('date' => $_POST ['date1'], 'e_id' => $e_id ) );
							
							if ($sec1) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
							
							}
						} else {
							$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date1'] ) );
							if ($query1) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>


<?php
							
							}
						}
					}
					if ($_POST ['r_leave'] == 'firsthalf') {
						$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date1'] ) );
						if ($check1) {
							$first1 = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.00', 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date1'] ), array ('date' => $_POST ['date1'], 'e_id' => $e_id ) );
							if ($first1) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
							
							}
						} else {
							$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date1'] ) );
							
							if ($query1) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
							
							}
						}
					}
				}
			
			}
			if ($date1 == '') {
				
				if ($_FILES ['application'] ['name'] != '') {
					
					// echo 'application ke andr';
					// we create an instance of the class, giving as argument
					// the PHP object
					// corresponding to the file field from the form
					// All the uploads are accessible from the PHP object
					// $_FILES
					
					$name1 = mt_rand ( 15, 250 ) . '___' . preg_replace ( '/\s+/', '', $_FILES ['application'] ['name'] );
					$_FILES ['application'] ['name'] = str_replace ( array ('(', ')' ), '', $name1 );
					$handle = new upload ( $_FILES ['application'] );
					
					// then we check if the file has been uploaded properly
					// in its *temporary* location in the server (often, it is
					// /tmp)
					if ($handle->uploaded) {
						// yes, the file is on the server
						// now, we start the upload 'process'. That is, to copy
						// the uploaded file
						// from its temporary location to the wanted location
						// It could be something like
						// $handle->Process('/home/www/my_uploads/');
						// we now process the image a second time, with some
						// other settings
						
						$handle->image_resize = true;
						$handle->image_ratio_crop = true;
						$handle->image_y = 200;
						$handle->image_x = 250;
						
						$handle->Process ( $dir_dest );
						
						// we check if everything went OK
						if ($handle->processed) {
							// everything was fine !
							$application = $_FILES ['application'] ['name'];
							
							if ($_POST ['r_leave'] == 'fullday') {
								$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date2'] ) );
								if ($check1) {
									$full2 = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date2'] ), array ('date' => $_POST ['date2'], 'e_id' => $e_id ) );
									if ($full2) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								} else {
									$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date2'] ) );
									
									if ($query1) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								}
							}
							
							if ($_POST ['r_leave'] == 'secondhalf') {
								$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date2'] ) );
								if ($check1) {
									$sec2 = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => 0.00, 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date2'] ), array ('date' => $_POST ['date2'], 'e_id' => $e_id ) );
									
									if ($sec2) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								} else {
									$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date2'] ) );
									
									if ($query1) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								}
							
							}
							
							if ($_POST ['r_leave'] == 'firsthalf') {
								$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date2'] ) );
								if ($check1) {
									$first2 = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => 0.00, 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date2'] ), array ('date' => $_POST ['date2'], 'e_id' => $e_id ) );
									
									if ($first2) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>


<?php
									
									}
								} else {
									$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $_POST ['date2'] ) );
									
									if ($query1) {
										?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
									
									}
								}
							} // firsthalf end
						
						} // --handle proccessed
					} // --handle upload
				} 				// --application are not blank
				else {
					if ($_POST ['r_leave'] == 'fullday') {
						$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date2'] ) );
						if ($check1) {
							$full3 = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date2'] ), array ('date' => $_POST ['date2'], 'e_id' => $e_id ) );
							
							if ($full3) {
								?>

<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
							
							}
						} else {
							$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date2'] ) );
							
							if ($query1) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
							
							}
						}
					}
					
					if ($_POST ['r_leave'] == 'secondhalf') {
						$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date2'] ) );
						if ($check1) {
							$sec3 = $db->update ( 'attendence', array ('e_id' => $e_id, 'secondhalf' => 0.50, 'firsthalf' => 0.00, 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date2'] ), array ('date' => $_POST ['date2'], 'e_id' => $e_id ) );
							if ($sec3) {
								?>

<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
							
							}
						} else {
							$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date2'] ) );
						}
					}
					if ($_POST ['r_leave'] == 'firsthalf') {
						$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $_POST ['date2'] ) );
						if ($check1) {
							$first3 = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => 0.50, 'secondhalf' => 0.00, 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date2'] ), array ('date' => $_POST ['date2'], 'e_id' => $e_id ) );
							if ($first3) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>

<?php
							
							}
						} else {
							$query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $_POST ['date2'] ) );
							
							if ($query1) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>


<?php
							
							}
						}
					}
				}
			
			}
			if ($date1 <= $date2 && $date1 != '' && $date2 != '') {
				$a = $date1;
				$b = $date2;
				
				if ($_FILES ['application'] ['name'] != '') {
					
					// we create an instance of the class, giving as argument
					// the PHP object
					// corresponding to the file field from the form
					// All the uploads are accessible from the PHP object
					// $_FILES
					
					$name2 = mt_rand ( 15, 250 ) . '___' . preg_replace ( '/\s+/', '', $_FILES ['application'] ['name'] );
					$_FILES ['application'] ['name'] = str_replace ( array ('(', ')' ), '', $name2 );
					$handle = new upload ( $_FILES ['application'] );
					
					// then we check if the file has been uploaded properly
					// in its *temporary* location in the server (often, it is
					// /tmp)
					if ($handle->uploaded) {
						// yes, the file is on the server
						// now, we start the upload 'process'. That is, to copy
						// the uploaded file
						// from its temporary location to the wanted location
						// It could be something like
						// $handle->Process('/home/www/my_uploads/');
						// we now process the image a second time, with some
						// other settings
						
						$handle->image_resize = true;
						$handle->image_ratio_crop = true;
						$handle->image_y = 200;
						$handle->image_x = 250;
						
						$handle->Process ( $dir_dest );
						
						// we check if everything went OK
						if ($handle->processed) {
							// everything was fine !
							$application = $_FILES ['application'] ['name'];
							while ( $a <= $b ) {
								
								$c = date ( 'Y-m-d', $a );
								
								if ($_POST ['r_leave'] == 'fullday') {
									$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $c ) );
									if ($check1) {
										$xwhile = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $c ), array ('date' => $c, 'e_id' => $e_id ) );
									} else {
										$wwhile = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $c ) );
									}
								}
								
								if ($_POST ['r_leave'] == 'secondhalf') {
									$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $c ) );
									if ($check1) {
										$xwhile = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => 0.00, 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $c ), array ('date' => $c, 'e_id' => $e_id ) );
									} else {
										$wwhile = $query1 = $db->insert ( 'attendence', array ('e_id' => $e_id, 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $c ) );
									}
								}
								if ($_POST ['r_leave'] == 'firsthalf') {
									$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $c ) );
									if ($check1) {
										$xwhile = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => 0.00, 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $c ), array ('date' => $c, 'e_id' => $e_id ) );
									} else {
										$wwhile = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'application' => $application, 'date' => $c ) );
									}
								}
								
								$d = date ( 'Y-m-d', strtotime ( $c . "+ 1 days" ) );
								$a = strtotime ( $d );
							
							}
							if ($xwhile) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
							
							}
							if ($wwhile) {
								?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
							
							}
						} // --handle proccessed
					} // --handle upload
				} 				// --application are not blank
				else {
					while ( $a <= $b ) {
						
						$c = date ( 'Y-m-d', $a );
						
						if ($_POST ['r_leave'] == 'fullday') {
							$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $c ) );
							if ($check1) {
								$xwhile = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $c ), array ('date' => $c, 'e_id' => $e_id ) );
							} else {
								$wwhile = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $c ) );
							}
						}
						
						if ($_POST ['r_leave'] == 'secondhalf') {
							$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $c ) );
							if ($check1) {
								$xwhile = $db->update ( 'attendence', array ('e_id' => $e_id, 'secondhalf' => 0.50, 'firsthalf' => 0.00, 't_leave' => $_POST ['t_leave'], 'date' => $c ), array ('date' => $c, 'e_id' => $e_id ) );
							} else {
								$wwhile = $db->insert ( 'attendence', array ('e_id' => $e_id, 'secondhalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $c ) );
							}
						}
						if ($_POST ['r_leave'] == 'firsthalf') {
							$check1 = $db->exists ( 'attendence', array ('e_id' => $e_id, 'date' => $c ) );
							if ($check1) {
								$xwhile = $db->update ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => 0.50, 'secondhalf' => 0.00, 't_leave' => $_POST ['t_leave'], 'date' => $c ), array ('date' => $c, 'e_id' => $e_id ) );
							} else {
								$wwhile = $db->insert ( 'attendence', array ('e_id' => $e_id, 'firsthalf' => '0.50', 't_leave' => $_POST ['t_leave'], 'date' => $c ) );
							}
						}
						
						$d = date ( 'Y-m-d', strtotime ( $c . "+ 1 days" ) );
						$a = strtotime ( $d );
					
					}
					if ($xwhile) {
						?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Updated...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
					
					}
					if ($wwhile) {
						?>
<div id="hide">
	<div id="gritter-notice-wrapper">
		<div id="gritter-item-1" class="gritter-item-wrapper gritter-success"
			style="">
			<div class="gritter-top"></div>
			<div class="gritter-item">

				<div class="gritter-without-image">
					<span class="gritter-title">Cheers..
						<div class="gritter-close" id="gritterremove"
							style="display: inline;"></div>
					</span>
					<p>Your Record Is Inserted...</p>
				</div>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
					
					}
				}
			}
		}
	}

}
?>