
<section class="content-header">
  <h1>
	<? echo "All Timers"; ?>
  </h1>		
</section>
	<section class="content">
		<div class="row">
			<div class="col-xs-12">
				<div class="box">

				<div class="box-body">
				<div class="row" style="padding:0px 10px;">
					<?php 
                    //include_once('add_timesheet.inc.php');
                    ?>
				</div>
				<!--<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">-->
				<!--<form action="?page=view&name=<?=$name?>" method="post" name="form1" id="form1">-->
				<? 
				 if($_SESSION['is_super_admin']){
					//$timer_condition = "";
					$timer_condition = " WHERE timer.admin_id = '".$_SESSION['user_id']."' ";
				}else{
					$timer_condition = " WHERE timer.admin_id = '".$_SESSION['user_id']."' ";
				}
                $sql_timer="select *,timer.admin_id as admin_id1,job_project_mapping.id as id from timer LEFT JOIN job_project_mapping ON job_project_mapping.id = timer.project_id $timer_condition order by timer.id desc";
                $res_timer=mysqli_query($conn,$sql_timer);
                $result=mysqli_num_rows($res_timer);
                echo "<script type='text/javascript'>var totalcounter=".$result.";</script>"; //IMPORTANT to run timer. specify total number of counter
                if($result>0){
				?>
					<!-- Start  records header -->
				<table id="example1" class="table table-bordered table-striped">
					<thead>
						<tr>
							<th>User Id</th>
							<th>User Name</th>
							<th>Org. Id</th>
							<th>Org. Name</th>
							<th>Project Id</th>
							<th>Project Name</th>
							<th>Timer</th>
							<th></th>
						</tr>
					</thead>
					<tbody>
					<!-- End records header -->
					<?
                    $cnt=1;
					while($row = mysqli_fetch_array($res_timer)){
					    if($row_timer["is_running"]=="1"){
                            $disabled = "disabled";
                        }
                    ?>
					<!-- Start data -->
					<tr>
						<td><?php echo $row['admin_id1']; ?></td>
						<td><?php echo ucfirst(Admin::getAdminById($row['admin_id1'])); ?></td>
						<td><?php echo $row['job_id']; ?></td>
						<td><?php echo $gsi->getJobUserById($row['job_id']); ?></td>
						<td><?php echo $row['project_id']; ?></td>
						<td><a href="<? echo $config->siteURL?>/enquiry_management/index?page=view_project_progress&job_id=<?=$row['job_id']?>&project_id=<?=$row['id']?>"><?php echo ucfirst($row['project_title']); ?></a></td>
						<td><?php echo '<h2 id="timer_value_'.$cnt.'" style="float:left;clear:right;margin-top:0px;margin-top: 5px;"><time>00:00:00</time></h2>'; ?></td>
						<td>
                        <?php 
                        echo '<button id="start_'.$cnt.'" '.$disabled.' class="btn btn-info" style="float:left;clear:right;margin-left:5px;margin-top: 5px;" onclick="return startcounter('.$cnt.');">start</button>
						<button id="stop_'.$cnt.'" class="btn bg-yellow" style="float:left;clear:right;margin-left:5px;margin-top: 5px;" onclick="return pausecounter('.$cnt.');">pause</button>
						<a href="'.$config->siteURL.'/enquiry_management/index?page=view_project_progress&job_id='.$row["job_id"].'&project_id='.$row["project_id"].'"> <button id="clear_'.$cnt.'" class="btn bg-red" style="float:left;clear:right;margin-left:5px;margin-top: 5px;" /* onclick="return stopcounter('.$cnt.');" */>stop</button></a>'; 
                        echo '<input type="hidden" id="hid_timer_'.$cnt.'" value="'.(($row["is_running"]=="1")?0:1).'"/>';
                        echo '<input type="hidden" id="hid_job_id_'.$cnt.'" value="'.$row["job_id"].'"/>';
						echo '<input type="hidden" id="hid_admin_id_'.$cnt.'" value="'.$row["admin_id1"].'"/>';
                        echo '<input type="hidden" id="hid_project_id_'.$cnt.'" value="'.$row["project_id"].'"/>';
                        ?></td>
					</tr>
					<!-- End data -->
					<?
                    $cnt=$cnt+1; 
					}
                    ?>
					<?}else{?>
					<tr>
						<td colspan="6">No Timer found...</td>
					</tr>
					<?php }?>
					</tbody>
					
				</table>
					<!-- Paging starts here  -->
					<? 
					$next_page_condition .="&page=view";
					include("paging/paging_row.inc.php") ?>
					<!-- Paging ends starts here  -->
						
					<!--</table>-->
					<!--</form>-->
					</div>
				</div>
			</div>
		</div>
	</section>
		