<div id="example" class="modal hide fade in" style="display: none;">

	<div class="modal-header">
		<a class="close" href="<?php echo $link->link('attendence',Admin);?>">x</a>


		<div class="modal-body">
			<form class="form-horizontal" method="post" action=""
				enctype="multipart/form-data">

				<div class="control-group">
					<label class="control-label" for="amount">Employee Name</label>
					<div class="controls">
						<select name="name">
							<option value="" disabled="disabled" selected="selected">Select
								The Name</option>
							<?php
							$name = $db->get_all ( 'employees' );
							foreach ( $name as $s_name ) {
								?><?php

								echo $s_name ['e_id'];
								?>
								<option value="<?php echo $s_name['e_id']; ?>"><?php echo $s_name['e_name'];?></option>
							<?php
							}
							?>
					</select>
					</div>
					<!-- /controls -->
				</div>
				<!-- /control-group -->

				<div class="control-group">

					<div class="controls">
						<select name="set" id="set">

							<option value="present" selected="selected">Present</option>
							<option value="absent" id="absent">Absent</option>
						</select>
					</div>
					<!-- /controls -->
				</div>
				<!-- /control-group -->

				<div class="control-group" id="date">
					<label class="control-label" for="amount">Date</label>
					<div class="controls">
						<span> <input class="span1 date-picker" id="id-date-picker-1"
							type="text" data-date-format="dd-mm-yyyy" name="date1" />
						</span> <span> <input class="span1 date-picker"
							id="id-date-picker-1" type="text" data-date-format="dd-mm-yyyy"
							name="date2" />
						</span>
						<!-- <input type="text" name="date" id="id-date-range-picker-2" > -->
					</div>
					<!-- /controls -->
				</div>
				<!-- /control-group -->

				<div class="second" style="display: none;">
					<div class="control-group">
						<label class="control-label" for="amount">Type Of Leaves</label>
						<div class="controls">
							<select name="t_leave">
								<option value="" selected="selected" disabled="disabled">Type Of
									Leave</option>
								<option value="casual">Casual Leave</option>
								<option value="sick">Sick Leave</option>
								<option value="maternity">Maternity Leave</option>
								<option value="other">Other Leave</option>
							</select>
						</div>
						<!-- /controls -->
					</div>
					<!-- /control-group -->

					<div class="control-group">
						<label class="control-label" for="amount">Range Of Leaves</label>
						<div class="controls">
							<select name="r_leave">
								<option value="" selected="selected" disabled="disabled">Range
									Of Leaves</option>
								<option value="firsthalf">First Half Leave</option>
								<option value="secondhalf">Second Half Leave</option>
								<option value="fullday">Full Day Leave(s)</option>
							</select>
						</div>
						<!-- /controls -->
					</div>
					<!-- /control-group -->

					<div class="control-group">
						<label class="control-label" for="amount">Application</label>
						<div class="controls">
							<input type="file" name="application">
						</div>
						<!-- /controls -->
					</div>
					<!-- /control-group -->

				</div>
				<!-- .second -->
		
		</div>
		<!-- .modal body -->

		<div class="row-fluid">
			<div class="span5"></div>
			<div class="span4">
				<div class="control-group">
					<div class="controls">
						<span class="span12"> <input type="hidden" name="id" value='+id+'>
							<button type="submit" name="submit"
								class="btn btn-small btn-primary">Save</button>
						</span>
					</div>
					<!-- .control -->
				</div>
				<!-- .control group -->
			</div>
		</div>
		</form>
	</div>

</div>
<!-- .example -->
<div class="page-content">
	<div class="page-header position-relative">
		<h1>
			Attendence <small> <i class="icon-double-angle-right"></i> with
				editable events
			</small>
		</h1>
	</div>
	<!--/.page-header-->

	<div class="row-fluid">

		<div class="span3">
			<?php if(isset($_POST['show'])){?>
				<a class="btn btn-danger btn-small"
				href="<?php echo $link->link('attendence', Admin); ?>">Today</a>
			<?php }?>		
			</div>
		<!-- .span4 -->


		<div class="span7" id="8">
			<form class="form-horizontal" method="post" action="">
				<div class="control-group">
					<label class="control-label">Date Range:</label>
					<div class="controls">
						<div class="row-fluid input-prepend">

							<input class="span6" type="text" name="date[final]"
								id="id-date-range-picker-1"
								placeholder="<?php echo $date['final']; ?>" /> <span
								class="add-on"> <i class="icon-calendar big"></i>
							</span> <input type="hidden" name="check" value="date">
							<button class="btn btn-small btn-purple" name="show">Show</button>

						</div>
						<!-- .row-fluid input-prepend -->


					</div>
					<!-- /controls -->
				</div>
				<!-- /control-group -->
			</form>
		</div>
		<!-- .span6 -->

		<div class="span2">
			<div class="control-group">

				<div class="controls">
					<p data-toggle="modal" href="#example" class="btn btn-primary"
						id='edit'>Mark Attendence</p>
				</div>
				<!-- /controls -->
			</div>
			<!-- /control-group -->
		</div>
		<!-- .span2 -->

	</div>
	<!-- .rowfluid -->



	<div class="row-fluid">
		<div class="span12" style="overflow-x: scroll;">
			<!--PAGE CONTENT BEGINS-->
							<?php
							$query = $db->get_all ( 'employees' );
							if (isset ( $_POST ['show'] )) {
								$date = $_POST ['date'];
								
								$final = explode ( '-', $date ['final'] );
								
								$date ['date1'] = $final [0];
								$date ['date2'] = $final [1];
								
								$date1 = strtotime ( $date ['date1'] );
								
								$date2 = strtotime ( $date ['date2'] );
								
								$time = $db->get_all ( 'attendence' );
								$var = 0;
								foreach ( $time as $row ) {
									$dtime = $row ['date'];
									$datenew = date ( "d-m-Y", strtotime ( $dtime ) );
									$db_time = strtotime ( $datenew );
									
									if ($date1 <= $db_time && $date2 >= $db_time) {
										$select [] = $row;
									} else {
										$warning = "<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 Is No Data For Required Date...
											</h5>
											<div style='clear:both'></div>
											</div>
											<div class='gritter-bottom'></div>
											</div>
											</div>
											</div>";
									}
								}
								if ($select == '') {
									echo $warning;
									$query = $db->get_all ( 'employees', array ('e_id' => 0 ) );
								} else {
									$query = $select;
								
								}
								?>
									<?php
								
								foreach ( $query as $row ) {
									$employee = $db->get_row ( 'employees', array ('e_id' => $row ['e_id'] ) );
									
									$empname .= $employee ['e_id'] . '@@@' . $employee ['e_name'] . '@@@' . $employee ['p_photograph'] . ',';
								
								}
								
								$arr = explode ( ',', $empname );
								$sto = array_pop ( $arr );
								$f_arr = array_unique ( $arr, SORT_REGULAR );
								?>
									
										<table id="sample-table-1"
				class="table table-striped table-bordered table-hover"
				style="overflow-x: scroll;">

				<thead>
					<tr>
						<th>S.no</th>
						<th>Employee Name</th>
						<th>Attendence</th>
						<th>Image</th>

					</tr>
				</thead>
				<tbody>
										<?php
								$snum = 1;
								foreach ( $f_arr as $first ) {
									echo '<tr>';
									echo '<td>';
									echo $snum;
									echo '</td>';
									echo '<td>';
									$getid = explode ( '@@@', $first );
									?>
											<a
						href="<?php echo $link->link('employee_preview', Admin, '?id='.$getid[0]);?>"> <?php echo $getid[1];?></a>
											<?php
									
									echo '</td>';
									echo '<td>';
									foreach ( $query as $row1 ) {
										
										if ($row1 ['e_id'] == $getid [0]) {
											
											$check = $db->exists ( 'attendence', array ('e_id' => $row1 ['e_id'], 'firsthalf' => 0.00, 'secondhalf' => 0.00, 't_leave' => '', 'date' => $row1 ['date'] ) );
											if ($check) {
												?>
														<span class="label label-inverse"><?php echo $row1['date'];?></span>
					<span class="label label-success arrowed">Present</span>
														
													<?php
												
												echo '<br>';
											} else {
												?>
														<span class="label label-inverse"><?php echo $row1['date'];?></span>
					
					<?php
												$type = $db->get_row ( "attendence", array ('e_id' => $row1 ['e_id'], 'date' => $row1 ['date'] ) );
												?>
												<?php if($type['firsthalf'] == 0.50){?>
												<span class="label label-important arrowed-in">Absent In
						Firsthalf</span>
												<?php }if($type['secondhalf'] == 0.50){?>
												<span class="label label-important arrowed-in">Absent In
						Secondhalf</span>
												<?php }if($type['secondhalf'] == 0.50 && $type['firsthalf'] == 0.50){?>
												<span class="label label-important arrowed-in">Absent
						Fullday</span>
												<?php }?>
					<span class="label label-info arrowed-in-right arrowed"><?php echo $type['t_leave'];?></span>
					<?php if($type['application']!=''){?>
					<a
						href="<?php echo  $link->link ( 'downloads', Admin, '?load=' . $type['application'] . '&path=' . 'uploads/employees/' . $type['e_id'].'/' );?>">Click
						To See Application</a>
					<?php }else{?>
					<span class="label label-warning">No Application</span>
					<?php }?>
													<?php
												
												echo '<br>';
											}
										
										}
									
									}
									echo '</td>';
									echo '<td>';
									?>
									<?php
									if ($getid [2] != '') {
										?>
									<a
						href="<?php echo $link->link('employee_preview', Admin,'?id='.$getid[0]);?>">
						<img
						src="<?php echo SITE_URL. '/uploads/employees/'.$getid[0].'/'.$getid[2]; ?>"
						style="width: 40px; height: 40px;">
					</a>
							<?php
									} else {
										echo "no image";
									}
									echo '</td>';
									
									echo '</tr>';
									$snum ++;
								}
								?>
										</tbody>
			</table>
										
								<?php
							
							} else {
								?>
							<table id="sample-table-2"
				class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th>S.no</th>
						<th>Employee Code</th>
						<th>Employees Image</th>
						<th>Employees Name</th>
						<th>Today Attendence</th>
					</tr>
				</thead>

				<tbody>
										<?php
								$a = 1;
								foreach ( $query as $row ) {
									
									?>
						                <form method="post" action=""
						enctype="multipart/form-data">
						<tr>
							<td> <?php echo $a; ?> </td>
							<td><a
								href="<?php echo $link->link('employee_preview', Admin,'?id='.$row['e_id']);?>"><?php echo $row['e_code'];?></a></td>
							<td>
							<?php if($row['p_photograph']!=''){?>
							<a
								href="<?php echo $link->link('employee_preview', Admin,'?id='.$row['e_id']);?>">
									<img
									src="<?php echo SITE_URL. '/uploads/employees/'.$row['e_id'].'/'.$row['p_photograph']; ?>"
									class="span3">
							</a>
							<?php }else {echo "No Image";}?>
							</td>
							<td><a
								href="<?php echo $link->link('employee_preview', Admin,'?id='.$row['e_id']);?>">
						                     		<?php echo $row['e_name']; ?>
						                     	</a></td>

							<td class="td-actions center">
												<?php
									$today = date ( "Y-m-d" );
									$present = $db->exists ( 'attendence', array ('e_id' => $row ['e_id'], 'firsthalf' => 0.00, 'secondhalf' => 0.00, 'date' => $today ) );
									
									if ($present) {
										?>
														<p class="span6">
									<span class="label label-success arrowed">Present</span>
								</p>
													<?php
									
									}
									$absent = $db->exists ( 'attendence', array ('e_id' => $row ['e_id'], 'firsthalf' => '0.50', 'date' => $today ) );
									$absent1 = $db->exists ( 'attendence', array ('e_id' => $row ['e_id'], 'secondhalf' => '0.50', 'date' => $today ) );
									if ($absent || $absent1) {
										?>
														<p class="span6">
									<span class="label label-important arrowed-in">Absent</span>
								</p>
													<?php
									
									}
									$attendence = $db->exists ( 'attendence', array ('e_id' => $row ['e_id'], 'date' => $today ) );
									if (! $attendence) {
										?>
														<p class="span6">
									<span
										class="label label-small label-pink arrowed-in-right arrowed-in ">Attendence
										Not Marked</span>
								</p>
													<?php
									
									}
									?>
											</td>
						</tr>
					</form>
										  <?php
									$a ++;
								}
								?>       
									</tbody>
			</table> 
								<?php
							}
							?>
							<!--PAGE CONTENT ENDS-->
		</div>
		<!--/.span-->
	</div>
	<!--/.row-fluid-->
</div>
<!--/.page-content-->


</div>
<!--/.main-content-->