<?php
$getid = $link->hrefquery ();
$id = $getid [1];
$name = $db->get_col ( 'employees', array ('e_id' => $id ), 'e_name' );

?>
<?php

if (isset ( $_POST ['submit'] ) && $_POST ['check'] == 'attendence' && $_POST ['action'] == 'multiple') {
	$day = $_POST ['day'];
	$attendence = $_POST ['attendence'];
	
	$e_id = $attendence ['e_id'];
	
	$w_days = $attendence ['radio'];
	
	$firsthalf = $attendence ['firsthalf'];
	
	$secondhalf = $attendence ['secondhalf'];
	
	$fullday = $attendence ['fullday'];
	
	$mixdate = $attendence ['mixdate'];
	
	$test = explode ( '-', $mixdate );
	
	$formdate = $test [0];
	
	$todate = $test [1];
	
	$query = $db->insert ( 'leaves', array ('e_id' => $e_id, 'w_days' => $w_days, 'firsthalf' => $firsthalf, 'secondhalf' => $secondhalf, 'fullday' => $fullday, 'formdate' => $formdate, 'todate' => $todate ) );
	
	if ($query) {
		$lstid = $db->insert_id;
	}
	$cli = (isset ( $argc ) && $argc > 1);
	($cli);
	if ($cli) {
		if (isset ( $argv [1] ))
			$_GET ['file'] = $argv [1];
		print_r ( $_GET ['file'] );
		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/attendence');
	$dir_pics = (isset ( $_GET ['pics'] ) ? $_GET ['pics'] : $dir_dest);
	
	if (! $cli && ! (isset ( $_SERVER ['HTTP_X_FILE_NAME'] ) && isset ( $_SERVER ['CONTENT_LENGTH'] ))) 

	{
		
		$files = array ();
		
		foreach ( $_FILES ['my_field'] as $k => $l ) {
			foreach ( $l as $i => $v ) {
				
				if (! array_key_exists ( $i, $files ))
					$files [$i] = array ();
				
				$files [$i] [$k] = $v;
			}
		}
		
		// now we can loop through $files, and feed each element to the class
		foreach ( $files as $file ) {
			// we instanciate the class for each element of $file
			$name = $lstid . "___" . mb_strtolower ( preg_replace ( '/\s+/', '', $file ['name'] ) . ___ . mt_rand ( 15, 215 ) );
			$file ['name'] = str_replace ( array ('(', ')' ), '', $name );
			$savedname .= $file ['name'] . ' ';
			$handle = new upload ( $file );
			
			// then we check if the file has been uploaded properly
			// in its *temporary* location in the server (often, it is /tmp)
			
			if ($handle->uploaded) {
				
				// 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/');
				$handle->Process ( $dir_dest );
				$update = $db->update ( 'leaves', array ('application' => $savedname ), array ('id' => $lstid ) );
			}
		
		}
	}
	
	if ($update && $lstid != '') {
		?>
<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
	
	} else {
		?>
<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! There Are Some Problem In Inserted...</h5>
				<div style="clear: both"></div>
			</div>
			<div class="gritter-bottom"></div>
		</div>
	</div>
</div>
<?php
	
	}
	// }

}
?>