<?php
session_name("AUTHENUSER");
session_start();
$USERNAME = $_SESSION['SES_USERNAME'];
if(!session_name("AUTHENUSER"))
	{
?>
						<script language="javascript">
						 alert("Waktu Login telah habis.Silahkan Login Kembali");
						document.location="index.php";
						</script>
<?php
	}
if(!$USERNAME)
	{
?>
						<script language="javascript">
						 alert("Harap Login Dahulu.");
						document.location="index.php";
						</script>
<?php
	}
	?>
	<?php 
	include "common/config.php";
	include "include/head.php";

	$act  = $_REQUEST['act'];
	$id_branch  = $_REQUEST['id_branch'];
	$fetch = mysql_fetch_array(mysql_query("select * from tbl_workingtime where id_branch='$id_branch'"));
	$timestart  = $fetch['timestart'];
	$timefinish  = $fetch['timefinish'];
	if($act == 1)
	{
		$id_branch  = $_REQUEST['id_branch'];
		$timestart  = $_REQUEST['timestart'];
		$timefinish  = $_REQUEST['timefinish'];
		if($timestart >= $timefinish)
		{
		?>
				<script language="javascript">
                alert("Check Time Start and Time Finish");
                document.location="edit_time.php?id_branch=<?php echo $id_branch; ?>";
                </script>
		<?php	
		}
		else
		{
			$insert = mysql_query("update tbl_workingtime set timestart='$timestart', timefinish = '$timefinish', user_update = '$USERNAME', date_update = '$tanggal_update' where id_branch = '$id_branch'"); //echo $insert; exit;
			if($insert)
			{
				?>
				<script language="javascript">
                alert("Edit Working Time Success");
                document.location="master_time.php";
                </script>
				<?php
			}
			else
			{
				?>
				<script language="javascript">
                alert("Edit Working Time Failed");
                document.location="edit_time.php?id_branch=<?php echo $id_branch; ?>";
                </script>
				<?php	
			}
		}
	}
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-th"></i> Edit Working Time</h1>
</div>

<!--<ol class="breadcrumb">
  <li><a href="#">Home</a></li>
  <li><a href="#">Bread</a></li>
  <li><a href="#">Crumbs</a></li>
  <li class="active">Example</li>
</ol>-->
          <div class="main-content">
            <div class="row">
                <div class="widget">
                  <div class="widget-content-white glossed">
                    <div class="padded">
                      <form method="post" action="edit_time.php?act=1&id_branch=<?php echo $id_branch; ?>" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label">Branch</label>
                          <div class="col-md-8">
                             <select class="form-control" name="branch" id="branch">
                              <?php
                                              $sql3 = "select * from  tbl_branch where id_branch='$id_branch'";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                        <option value="<?php echo $fetch3['id_branch']; ?>"><?php echo  $fetch3['nama_branch'];  ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                          </div>
                          </div>
                            <div class="form-group">
                          <label class="col-md-4 control-label">Time Start</label>
                          <div class="col-md-8">
                            <select class="form-control" name="timestart" id="timestart">
                           <?php
                                             $sql3 = "select * from tbl_time order by time";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                       
                                        <option <?php if($fetch3['time']==$timestart) { ?> selected="selected" <?php } ?> value="<?php echo $fetch3['time']; ?>"><?php echo $fetch3['time']; ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                          </div>
                        </div>
                           <div class="form-group">
                          <label class="col-md-4 control-label">Time Finish</label>
                          <div class="col-md-8">
                            <select class="form-control" name="timefinish" id="timefinish">
                              <?php
                                              $sql3 = "select * from tbl_time order by time";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                        <option <?php if($fetch3['time']==$timefinish) { ?> selected="selected" <?php } ?> value="<?php echo $fetch3['time']; ?>"><?php echo $fetch3['time']; ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                          </div>
                        </div>
                   
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="submit" class="btn btn-default">Submit</button>
                            <button type="reset" class="btn btn-default">Reset</button>
                          </div>
                        </div>
                      </form>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

<?php include "include/foot.php"; ?>
<script src='assets/js/for_pages/dashboard.js'></script>
</body>

</html>