<?php 

include('../dbconnect.php');
ob_start();
session_start();
include('uppernav.php');

if( !isset($_SESSION['user']) ) {
 header("Location: ../index.php");
 exit;
}
/*
$teamtab = 'style="display: block"';
$inditab = 'style="display: block"';
$teamactive = 'active';
$indiactive=''; 

*/

$teamtab = $_GET['teamtab'];
$inditab = $_GET['inditab'];

/////TEAM UPDATE SCHEDULE/////////////////////////////

$week = $_POST['week'];

$getday = $_POST['day'];
$getdate = $_POST['date'];
$off = $_POST['off'];
$hol = $_POST['hol'];
$start = $_POST['start'];
$end = $_POST['end'];
$years = date('Y');

$getweek = $_GET['week'];

$hidden= "hidden";

///get Team Schedule 
$scheddetails ="SELECT * FROM schedule WHERE team='$team' AND week='$getweek' AND year='$years' AND indi='Original' GROUP BY day ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
$schedresult = mysqli_query($conn, $scheddetails);
$teamday = array();
$teamdate = array();
$teamstart = array();
$teamend = array();
while($schedrow = mysqli_fetch_assoc($schedresult)) {

 $teamday[] =  $schedrow['day'];
$teamdate[] =  $schedrow['date']; 
$teamstart[] =  $schedrow['starttime'];
$teamend[] = $schedrow['endtime'];
}




if(isset($_POST['set'])){
    
    $hidden = " ";

    $first_week_no = $_;

}
else{
  $first_week_no = date('W', $timestamp); 
}


$first_week_no = $_GET['week'];

if(isset($_POST['updatesc'])){

 
                
     
       
            $updateschedsql = "UPDATE schedule SET `starttime` = '$start[0]', `endtime` = '$end[0]', `day` ='$getday[0]', `date` = '$getdate[0]' WHERE `team`='$team' AND `week`='$getweek' AND `year`='$years' AND `day`='Sunday'";
            $updateschedsql1 = "UPDATE schedule SET `starttime` = '$start[1]', `endtime` = '$end[1]', `day` ='$getday[1]', `date` = '$getdate[1]' WHERE `team`='$team' AND `week`='$getweek' AND `year`='$years' AND `day`='Monday'";
            $updateschedsql2 = "UPDATE schedule SET `starttime` = '$start[2]', `endtime` = '$end[2]', `day` ='$getday[2]', `date` = '$getdate[2]' WHERE `team`='$team' AND `week`='$getweek' AND `year`='$years' AND `day`='Tuesday'";
            $updateschedsql3 = "UPDATE schedule SET `starttime` = '$start[3]', `endtime` = '$end[3]', `day` ='$getday[3]', `date` = '$getdate[3]' WHERE `team`='$team' AND `week`='$getweek' AND `year`='$years' AND `day`='Wednesday'";
            $updateschedsql4 = "UPDATE schedule SET `starttime` = '$start[4]', `endtime` = '$end[4]', `day` ='$getday[4]', `date` = '$getdate[4]' WHERE `team`='$team' AND `week`='$getweek' AND `year`='$years' AND `day`='Thursday'";
            $updateschedsql5 = "UPDATE schedule SET `starttime` = '$start[5]', `endtime` = '$end[5]', `day` ='$getday[5]', `date` = '$getdate[5]' WHERE `team`='$team' AND `week`='$getweek' AND `year`='$years' AND `day`='Friday'";
            $updateschedsql6 = "UPDATE schedule SET `starttime` = '$start[6]', `endtime` = '$end[6]', `day` ='$getday[6]', `date` = '$getdate[6]' WHERE `team`='$team' AND `week`='$getweek' AND `year`='$years' AND `day`='Saturday'";
            
            //$updateschedsql = "UPDATE schedule SET `starttime` = '22:00', `endtime` = '08:00', `day` ='Monday', `date` = '12/06/2019' WHERE `team`='IT/Data Analytics' AND `week`='2' AND `year`='2019' AND `day`='Monday'";

                
                if (mysqli_query($conn, $updateschedsql) && mysqli_query($conn, $updateschedsql1) && mysqli_query($conn, $updateschedsql2) && mysqli_query($conn, $updateschedsql3) && mysqli_query($conn, $updateschedsql4) && mysqli_query($conn, $updateschedsql5) && mysqli_query($conn, $updateschedsql6))
                 {
                  $alert="<div class='alert alert-success'>
                  <strong style='font-size:12pt;'>Schedule Successfully Updated</strong> 
                  </div>";
                  header('location: schedule.php');

            
               
                 } 
                 else 
                 {
                    echo "Error updating record: " . mysqli_error($conn);
                  
                 }


        
              
               

                 
            

            

}


/////////////////END TEAM UPDATE SCHEDULE/////////////////

//////////INDIVIDUAL SCHEDULE UPDATE ////////////////////

$indiweek = $_POST['week'];

$Pindigetday = $_POST['indiday'];
$Pindigetdate = $_POST['indidate'];
$Pindioff = $_POST['indioff'];
$Pindihol = $_POST['indihol'];
$Pindistart = $_POST['indistart'];
$Pindiend = $_POST['indiend'];
$indiyears = date('Y');
$empid = $_GET['empid'];
$indigetweek = $_GET['indi'];

$hidden= "hidden";

///get Team Schedule 
$scheddetails1 ="SELECT * FROM schedule WHERE week='$indigetweek' AND year='$indiyears' AND empid='$empid' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
$schedresult1 = mysqli_query($conn, $scheddetails1);
$indiday = array();
$indidate = array();
$indistart = array();
$indiend = array();

while($schedrow1 = mysqli_fetch_assoc($schedresult1)) {
$indiday[] =  $schedrow1['day']; 
$indidate[] =  $schedrow1['date']; 
$indistart[] =  $schedrow1['starttime'];
$indiend[] = $schedrow1['endtime'];


}




if(isset($_POST['updateindi'])){
 
    $indiupdateschedsql =  "UPDATE schedule  SET `starttime` = '$Pindistart[0]', `endtime` = '$Pindiend[0]', `day` ='$Pindigetday[0]',`date` = '$Pindigetdate[0]', indi='1' WHERE `empid`='$empid' AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Sunday'";
    $indiupdateschedsql1 = "UPDATE schedule SET `starttime` = '$Pindistart[1]', `endtime` = '$Pindiend[1]', `day` ='$Pindigetday[1]', `date` = '$Pindigetdate[1]', indi='1' WHERE `empid`='$empid' AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Monday'";
    $indiupdateschedsql2 = "UPDATE schedule SET `starttime` = '$Pindistart[2]', `endtime` = '$Pindiend[2]', `day` ='$Pindigetday[2]', `date` = '$Pindigetdate[2]', indi='1' WHERE `empid`='$empid' AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Tuesday'";
    $indiupdateschedsql3 = "UPDATE schedule SET `starttime` = '$Pindistart[3]', `endtime` = '$Pindiend[3]', `day` ='$Pindigetday[3]', `date` = '$Pindigetdate[3]', indi='1' WHERE `empid`='$empid'  AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Wednesday'";
    $indiupdateschedsql4 = "UPDATE schedule SET `starttime` = '$Pindistart[4]', `endtime` = '$Pindiend[4]', `day` ='$Pindigetday[4]', `date` = '$Pindigetdate[4]', indi='1' WHERE `empid`='$empid'  AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Thursday'";
    $indiupdateschedsql5 = "UPDATE schedule SET `starttime` = '$Pindistart[5]', `endtime` = '$Pindiend[5]', `day` ='$Pindigetday[5]', `date` = '$Pindigetdate[5]', indi='1' WHERE `empid`='$empid'  AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Friday'";
    $indiupdateschedsql6 = "UPDATE schedule SET `starttime` = '$Pindistart[6]', `endtime` = '$Pindiend[6]', `day` ='$Pindigetday[6]', `date` = '$Pindigetdate[6]', indi='1' WHERE `empid`='$empid' AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Saturday'";
    /*
    echo $indiupdateschedsql.'<br/>';
    echo $indiupdateschedsql1.'<br/>';
    echo $indiupdateschedsql2.'<br/>';
    echo $indiupdateschedsql3.'<br/>';
    echo $indiupdateschedsql4.'<br/>';
    echo $indiupdateschedsql5.'<br/>';
    echo $indiupdateschedsql6.'<br/>';        

           
       /*
            $indiupdateschedsql =  "UPDATE schedule  SET `starttime` = '$indistart[0]', `endtime` = '$indiend[0]', `day` ='$indigetday[0]',`date` = '$indigetdate[0]', indi='1' WHERE `empid`='$empid' AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Sunday'";
            $indiupdateschedsql1 = "UPDATE schedule SET `starttime` = '$indistart[1]', `endtime` = '$indiend[1]', `day` ='$indigetday[1]', `date` = '$indigetdate[1]', indi='1' WHERE `empid`='$empid' AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Monday'";
            $indiupdateschedsql2 = "UPDATE schedule SET `starttime` = '$indistart[2]', `endtime` = '$indiend[2]', `day` ='$indigetday[2]', `date` = '$indigetdate[2]', indi='1' WHERE `empid`='$empid' AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Tuesday'";
            $indiupdateschedsql3 = "UPDATE schedule SET `starttime` = '$indistart[3]', `endtime` = '$indiend[3]', `day` ='$indigetday[3]', `date` = '$indigetdate[3]', indi='1' WHERE `empid`='$empid'  AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Wednesday'";
            $indiupdateschedsql4 = "UPDATE schedule SET `starttime` = '$indistart[4]', `endtime` = '$indiend[4]', `day` ='$indigetday[4]', `date` = '$indigetdate[4]', indi='1' WHERE `empid`='$empid'  AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Thursday'";
            $indiupdateschedsql5 = "UPDATE schedule SET `starttime` = '$indistart[5]', `endtime` = '$indiend[5]', `day` ='$indigetday[5]', `date` = '$indigetdate[5]', indi='1' WHERE `empid`='$empid'  AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Friday'";
            $indiupdateschedsql6 = "UPDATE schedule SET `starttime` = '$indistart[6]', `endtime` = '$indiend[6]', `day` ='$indigetday[6]', `date` = '$indigetdate[6]', indi='1' WHERE `empid`='$empid' AND `week`='$indigetweek' AND `year`='$indiyears' AND `day`='Saturday'";
            
 */
            //$indiupdateschedsql =  "UPDATE schedule  SET `starttime` = '00:00', `endtime` = '06:00', `day` ='Sunday',`date` = '01/06/2019', indi='1' WHERE `empid`='ATV18-01' AND `week`='2' AND `year`='2019' AND `day`='Sunday'"; 
       
                if (mysqli_query($conn, $indiupdateschedsql) && mysqli_query($conn, $indiupdateschedsql1) && mysqli_query($conn, $indiupdateschedsql2) && mysqli_query($conn, $indiupdateschedsql3) && mysqli_query($conn, $indiupdateschedsql4) && mysqli_query($conn, $indiupdateschedsql5) && mysqli_query($conn, $indiupdateschedsql6))
                 {
                  $alert="<div class='alert alert-success'>
                  <strong style='font-size:12pt;'>Schedule Successfully Updated</strong> 
                  </div>";
                  header('location: schedule.php');

            
               
                 } 
                 else 
                 {
                    echo "Error updating record: " . mysqli_error($conn);
                  
                 }

        
              
               

                
            

            

}

///////////INDIVIDUAL UPDATE SCHEDULE//////////////////////////////////////////////

?>
<!DOCTYPE html>
<html lang="en">

  <head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Team Head | Edit Schedule</title>

    <!-- Bootstrap core CSS-->
    <link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom fonts for this template-->
    <link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

    <!-- Page level plugin CSS-->
    <link href="../vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">

    <!-- Custom styles for this template-->
        <link href="../css/sb-admin.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">

    <link rel="icon" href="../images/logo.jpg" type="image/gif" sizes="16x16">
    <script>
    function opentm(){
        document.getElementById('teamtab').style.display ="block";
        document.getElementById('inditab').style.display ="none";
        document.getElementById('tm').style.backgroundColor ="#dddddd";
        document.getElementById('indi').style.backgroundColor ="#f1f1f1";
        window.history.pushState('object', document.title, location.href.split("?")[0]);
    }
    function openindi(){
        //window.history.pushState('object', document.title, location.href.split("?")[0]);
        document.getElementById('teamtab').style.display ="none";
        document.getElementById('inditab').style.display ="block";
        document.getElementById('tm').style.backgroundColor ="#f1f1f1";
        document.getElementById('indi').style.backgroundColor ="#dddddd";
        

    }
    
function ol(){
    
   
var off =  document.getElementsByName("off[]");
var offlength = off.length;     

var hol =  document.getElementsByName("hol[]");
var hollength = hol.length;    

var start =  document.getElementsByName("start[]");

var end =  document.getElementsByName("end[]");

        
    for(k=0; k < 7;k++)
    {
 
        if(off[k].checked == true){
            hol[k].disabled = true;
        start[k].readOnly = true;
        end[k].readOnly = true;
        start[k].type = 'text';
        start[k].value = 'OFF';
        end[k].type = 'text';
        end[k].value = 'OFF';
        end[k].hidden = true;;

            
     

   
    }
    if(hol[k].checked == true){
        start[k].readOnly = true;
        end[k].readOnly = true;
        off[k].disabled = true;
        start[k].type = 'text';
        start[k].value = 'HOLIDAY OFF';
        end[k].type = 'text';
        end[k].value = 'HOLIDAY OFF';
        end[k].hidden = true;




        
      
    }


    }

///////INDIVIDUAL INDIVIDUAL////////////////////


var indioff =  document.getElementsByName("indioff[]");
var indiofflength = indioff.length;     

var indihol =  document.getElementsByName("indihol[]");
var indihollength = indihol.length;    

var indistart =  document.getElementsByName("indistart[]");

var indiend =  document.getElementsByName("indiend[]");

        
    for(b=0; b < 7;b++)
    {
 
        if(indioff[b].checked == true){
            indihol[b].disabled = true;
            indistart[b].readOnly = true;
            indiend[b].readOnly = true;
            indistart[b].type = 'text';
            indistart[b].value = 'OFF';
            indiend[b].type = 'text';
            indiend[b].value = 'OFF';
            indiend[b].hidden = true;;

 
    }
    if(indihol[b].checked == true){
        indistart[b].readOnly = true;
        indiend[b].readOnly = true;
        indioff[b].disabled = true;
        indistart[b].type = 'text';
        indistart[b].value = 'HOLIDAY OFF';
        indiend[b].type = 'text';
        indiend[b].value = 'HOLIDAY OFF';
        indiend[b].hidden = true;




        
      
    }


    }
 
    
}
function cb(){

var off =  document.getElementsByName("off[]");
var offlength = off.length;     

var hol =  document.getElementsByName("hol[]");
var hollength = hol.length;    

var start =  document.getElementsByName("start[]");

var end =  document.getElementsByName("end[]");

        

for(k=0; k < offlength;k++)
{
    //off[k].checked = false;

    start[k].readOnly = false;
        end[k].readOnly = false;
        start[k].type = "time";
        end[k].type = "time";
        end[k].hidden = false;
        
    if(off[k].checked == true){
        hol[k].disabled = true;
        start[k].readOnly = true;
        end[k].readOnly = true;
        start[k].type = 'text';
        start[k].value = 'OFF';
        end[k].type = 'text';
        end[k].value = 'OFF';
        end[k].hidden = true;;


   
    }
    else{
        hol[k].disabled = false;
     

    }

    if(hol[k].checked == true){
        start[k].readOnly = true;
        end[k].readOnly = true;
        off[k].disabled = true;
        start[k].type = 'text';
        start[k].value = 'HOLIDAY OFF';
        end[k].type = 'text';
        end[k].value = 'HOLIDAY OFF';
        end[k].hidden = true;




        
      
    }
    else{
        off[k].disabled = false;
       
    }

        
    


}



}

////INDIVIDUAL CB 

function indicb(){

var off =  document.getElementsByName("indioff[]");
var offlength = off.length;     

var hol =  document.getElementsByName("indihol[]");
var hollength = hol.length;    

var start =  document.getElementsByName("indistart[]");

var end =  document.getElementsByName("indiend[]");

        

for(k=0; k < offlength;k++)
{
    //off[k].checked = false;

    start[k].readOnly = false;
        end[k].readOnly = false;
        start[k].type = "time";
        end[k].type = "time";
        end[k].hidden = false;
        
    if(off[k].checked == true){
        hol[k].disabled = true;
        start[k].readOnly = true;
        end[k].readOnly = true;
        start[k].type = 'text';
        start[k].value = 'OFF';
        end[k].type = 'text';
        end[k].value = 'OFF';
        end[k].hidden = true;;


   
    }
    else{
        hol[k].disabled = false;
     

    }

    if(hol[k].checked == true){
        start[k].readOnly = true;
        end[k].readOnly = true;
        off[k].disabled = true;
        start[k].type = 'text';
        start[k].value = 'HOLIDAY OFF';
        end[k].type = 'text';
        end[k].value = 'HOLIDAY OFF';
        end[k].hidden = true;




        
      
    }
    else{
        off[k].disabled = false;
       
    }

        
    


} 

}

function insweek(){


var getteam = document.getElementById('getteam').value;

var teamtab = 'style="display: block"'
if(getteam != ''){

    window.location.href = "updatesched.php?team=" + getteam + "&teamtab=" + teamtab; 
}


}

function getweek(){

var inditab = 'style="display: block"';
var getemp = document.getElementById('empid').value;
document.getElementById('teamtab').style.display ="none";
        document.getElementById('inditab').style.display ="block";
        document.getElementById('tm').style.backgroundColor ="#f1f1f1";
        document.getElementById('indi').style.backgroundColor ="#dddddd";


if(getemp != ''){


    window.location.href = "updatesched.php?empid=" + getemp + "&inditab=" + inditab; 
}


}


function show(){

var teamtab = 'style="display: block"';
var weekno = document.getElementById('week').value;

window.location.href = "updatesched.php?week=" + weekno  + "&teamtab=" + teamtab;

}
function indishow(){
    var inditab = 'style="display: block"';

var weekno = document.getElementById('indiweek').value;
var getemp = document.getElementById('empid').value;
window.location.href = "updatesched.php?indi=" + weekno + "&empid=" + getemp + "&inditab=" + inditab;
   
}


    
    </script>


  </head>

  <body id="page-top" onload="ol()">




      <!-- Sidebar -->
      
      <?php 
      $sched="active";
      $admintools = "active";
      include('sidebar.php');
      ?>
       
      <div id="content-wrapper">

        <div class="container-fluid">

          <!-- Breadcrumbs-->
          <ol class="breadcrumb">
            <li class="breadcrumb-item">
              <a href="schedule.php"> Schedule</a>
            </li>
            <li class="breadcrumb-item active">Update Employee Schedule</li>
          </ol>
        <ul class="nav nav-tabs" id="myTab" role="tablist">
            <li class="nav-item">
                <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
            </li>
        </ul>
        <div class="tab-content" id="myTabContent">
        <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
        <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
        <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
        </div>
          <div class="row p-3">
           
            <div class="col-sm-12">
                <h4>Edit Employee Schedule</h4>
            </div>
            <div class="col-sm-12">
                <div class="tab">
                        <button class="tablinks <?php echo $teamactive?>" id="tm" onclick="opentm()" ><strong>Team</strong></button>
                        <button class="tablinks <?php echo $indiactive?>" id="indi" onclick="openindi()"><strong>Individual</strong></button>
                    
                        
                </div>

                <div id="teamtab" class="tabcontent" <?php echo $teamtab?>>
                <form method="POST">
                    <div class="row">
                            <div class="col-sm-12 form-group">
                                <h5>Team</h5>
                            </div>
                            <div class="col-sm-12 form-inline">
                   

                                                <label><b> Week : &nbsp &nbsp </b></label>
                                                <?php 
                                             
                                                $qt = "SELECT * FROM schedule WHERE team='$team' GROUP BY week ORDER BY date ASC";                                                
                                                $rt = mysqli_query ($conn,$qt); 
                                                echo "<select name='weekno' id='week' class='form-control' required>"; 
                                                echo "<option value='' disabled selected> Week </option>";
                                        
                                                while($r = mysqli_fetch_array($rt)) {

                                                    $wk =  $r['week'];

                                                    $endweek = "SELECT MAX(date) AS 'max_date' FROM schedule WHERE year='$years' AND week= '$wk' ";
                                                    $endweekres = mysqli_query ($conn,$endweek); 
                                                    $endweekrow = mysqli_fetch_assoc($endweekres);

                                                    $month = $r['month'];
                                                    if($weekno==$r['week'] || $getweek == $r['week']){
                                                        echo "<option value='".$r['week']."' selected='selected'>Week # ".$r['week']." ".date('F d,Y', strtotime($r['date']))." - ".date('F d,Y', strtotime($endweekrow['max_date']))."</option>";
                                                
                                                    }
                                                    else{
                                                        echo "<option value='".$r['week']."' >Week # ".$r['week']." ".date('F d,Y', strtotime($r['date']))." - ".date('F d,Y', strtotime($endweekrow['max_date']))."</option>";
                                                    }
                                                    
                                                }
                                                echo "</select>"; 
                                                
                                                ?> &nbsp &nbsp 
                                            
                                                
                                                &nbsp &nbsp<button type="button" class="btn btn-success form-control" name="set" id="set" onclick="show()">Set</button>
                                </div>




                    <div class="col-sm-12 form-group" id="divsched" <?php echo $teamtab?>>
                        <div class="row">

                            <?php 
                            for ($i = 0; $i < 7; $i++) {
                                $off='';
                                $holiday ='';
                                if($teamstart[$i] == 'OFF'){
                                    $off ='checked';
                                }
                                if($teamstart[$i] == 'HOLIDAY OFF'){
                                    $holiday ='checked';
                                }
                               
                                    echo '
                                    <div class="col-sm-3 form-group">
                                        <div class="col-sm-12">
                                        <label> <b>'.$teamday[$i].'</b></label>
                                        <input type="text" name="day[]" placeholder="Time" class="form-control" value="'.$teamday[$i].'" hidden> 
                                        </div>
                                        <div class="col-sm-12">
                                        <span>'.date('m/d/Y', strtotime($teamdate[$i])).'</span>
                                        <input type="text" name="date[]" placeholder="Time" class="form-control" value="'.$teamdate[$i].'" hidden> 
                                        </div>
                                        <div class="col-sm-12 form-inline">
                                        <input type="checkbox" class="off" name="off[]" id ="off" onclick="cb()" value="OFF" style="height: 20px; width: 20px;" '.$off.'>&nbsp<label>&nbsp<b> OFF</b> </label>
                                        &nbsp&nbsp&nbsp&nbsp
                                        <input type="checkbox"  class="hol" name="hol[]" id="hol[]" onclick="cb()" value="HOLIDAY OFF" style="height: 20px; width: 20px;" '.$holiday.'>&nbsp<label>&nbsp<b> HOLIDAY OFF</b> </label>
                                        </div>
                                        <div class="col-sm-12 form-inline">

                                    
                                        ';

                                        
                                        
                                  
                                          
                                        echo' <input type="time" name="start[]" id="start" placeholder="Time" class="form-control" value="'.$teamstart[$i].'" required> &nbsp-&nbsp<input type="time" name="end[]" id="end" placeholder="Time" class="form-control" value="'.$teamend[$i].'" required>

                                        
                                        
                                       
                                      
                                        </div>
                                    </div>
                                
                                ';
                                   

                                    
                                
                                }
                            
                            ?>
                      
                           
                            <div class="col-sm-3 form-group">
                                <br><br><br>
                                <span class="pull-right">  <button type="button" class="btn btn-success" data-toggle="modal" data-target="#updateschedmodal"><i class="fa fa-check"></i> Submit </button>
                                    <button class="btn btn-danger">Cancel</button>
                                </span>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="modal fade" id="updateschedmodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">Confirm Team Schedule Update</h5>
                            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                            </button>
                    </div>
                    <div class="modal-body">Are you sure you want to update team schedule?</div>
                    <div class="modal-footer">
                        <input type="submit" class="btn btn-success" name="updatesc" value=" ✓ Yes" style="margin-right: 5px;" > 
                        <button class="btn btn-danger" type="button" data-dismiss="modal"><i class="fa fa-close"></i> No</button>
                                            
                    </div>
                    </div>
                    </div>
                </div>

                </form>
                </div>

                <div id="inditab" class="tabcontent" <?php echo $inditab?>>
                    <form method="POST">
                        <div class="row">
                                <div class="col-sm-12 form-group">
                                    <h5>Individual</h5>
                                    <?php echo $alert;?>
                                </div>
                                <div class="col-sm-12 form-inline">
                                    <label><b> Employee : &nbsp &nbsp </b></label>
                                                <?php 
                                                    $getempid = $_GET['empid'];
                                                    $qt = "SELECT * FROM empdetails JOIN empinfo ON empinfo.empid = empdetails.detailid WHERE supervisor='$accountname'";

                                                    $rt = mysqli_query ($conn,$qt); 
                                                    echo "<select name='empid' id='empid' class='form-control' onchange='getweek()' required>"; 
                                                    echo "<option value='' disabled selected> Employee ID </option>";
                                            
                                                    while($r = mysqli_fetch_array($rt)) {
                                                        if($empid==$r['empid'] || $getempid == $r['empid']){
                                                            echo "<option value='".$r['empid']."' selected='selected'>".$r['empid']." ".$r['firstname']." ".$r['surname']."</option>";
                                                    
                                                        }
                                                    else{
                                                        echo "<option value='".$r['empid']."' >".$r['empid']." ".$r['firstname']." ".$r['surname']."</option>";
                                                    }
                                                        
                                                    }
                                                    echo "</select>"; ?> &nbsp &nbsp
                                                    <label><b> Week : &nbsp &nbsp </b></label>
                                                    <?php 
                                                
                                                    $qt = "SELECT * FROM schedule WHERE empid='$getempid' GROUP BY week ORDER BY date ASC";                                                
                                                    $rt = mysqli_query ($conn,$qt); 

                                                    
                                                    echo "<select name='weekno' id='indiweek' class='form-control' required>"; 
                                                    echo "<option value='' disabled selected> Week </option>";
                                            
                                                    while($r = mysqli_fetch_array($rt)) {
                                                        $month = $r['month'];
                                                        $wk = $r['week'];

                                                        $endweek = "SELECT MAX(date) AS 'max_date' FROM schedule WHERE year='$years' AND week= '$wk' ";
                                                        $endweekres = mysqli_query ($conn,$endweek); 
                                                        $endweekrow = mysqli_fetch_assoc($endweekres);
                                                        

                                                        if($weekno==$r['week'] || $indigetweek == $r['week']){
                                                            echo "<option value='".$r['week']."' selected='selected'>Week # ".$r['week']." ".date('F d, Y', strtotime($r['date']))." - ".date('F d, Y', strtotime($endweekrow['max_date']))."</option>";
                                                    
                                                        }
                                                        else{
                                                            echo "<option value='".$r['week']."' >Week #".$r['week']." ".date('F d, Y', strtotime($r['date']))." - ".date('F d, Y', strtotime($endweekrow['max_date']))."</option>";
                                                        }
                                                        
                                                    }
                                                    echo "</select>"; 
                                                    
                                                    ?>
                                                
                                                    
                                                    &nbsp &nbsp<button type="button" class="btn btn-success form-control" name="indiset" id="indiset" onclick="indishow()">Set</button>
                                    </div>



                        
     

                        <div class="col-sm-12 form-group" id="divsched" >
                            <div class="row">

                                <?php 
                                for ($i = 0; $i < 7; $i++) {
                                    $indioff='';
                                    $indiholiday ='';

                                    if($indistart[$i] == 'OFF'){
                                        $indioff ='checked';
                                    }
                                    if($indistart[$i] == 'HOLIDAY OFF'){
                                        $indiholiday ='checked';
                                    }
                                
                                        echo '
                                        <div class="col-sm-3 form-group">
                                            <div class="col-sm-12">
                                            <label> <b>'.$indiday[$i].'</b></label>
                                            <input type="text" name="indiday[]" placeholder="Time" class="form-control" value="'.$indiday[$i].'" hidden> 
                                            </div>
                                            <div class="col-sm-12">
                                            <span>'.date('m/d/Y', strtotime($indidate[$i])).'</span>
                                            <input type="text" name="indidate[]" placeholder="Time" class="form-control" value="'.$indidate[$i].'" hidden> 
                                            </div>
                                            <div class="col-sm-12 form-inline">
                                            <input type="checkbox" class="off" name="indioff[]" id ="off" onclick="indicb()" value="OFF" style="height: 20px; width: 20px;" '.$indioff.'>&nbsp<label>&nbsp<b> OFF</b> </label>
                                            &nbsp&nbsp&nbsp&nbsp
                                            <input type="checkbox"  class="hol" name="indihol[]" id="hol[]" onclick="indicb()" value="HOLIDAY OFF" style="height: 20px; width: 20px;" '.$indiholiday.'>&nbsp<label>&nbsp<b> HOLIDAY OFF</b> </label>
                                            </div>
                                            <div class="col-sm-12 form-inline">

                                        
                                            ';

                                            
                                            
                                    
                                            
                                            echo' <input type="time" name="indistart[]" id="start" placeholder="Time" class="form-control" value="'.$indistart[$i].'" required> &nbsp-&nbsp<input type="time" name="indiend[]" id="end" placeholder="Time" class="form-control" value="'.$indiend[$i].'" required>

                                            
                                            
                                        
                                        
                                            </div>
                                        </div>
                                    
                                    ';
                                    

                                        
                                    
                                    }
									mysqli_close($conn);
                                
                                ?>
                        
                            
                                <div class="col-sm-3 form-group">
                                    <br><br><br>
                                    <span class="pull-right">  <button type="button" class="btn btn-success" data-toggle="modal" data-target="#updateindimodal"><i class="fa fa-check"></i> Submit </button>
                                        <button class="btn btn-danger">Cancel</button>
                                    </span>
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="modal fade" id="updateindimodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">Confirm  Schedule Update</h5>
                            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                            </button>
                    </div>
                    <div class="modal-body">Are you sure you want to update  schedule?</div>
                    <div class="modal-footer">
                        <input type="submit" class="btn btn-success" name="updateindi" value=" ✓ Yes" style="margin-right: 5px;" > 
                        <button class="btn btn-danger" type="button" data-dismiss="modal"><i class="fa fa-close"></i> No</button>
                                            
                    </div>
                    </div>
                    </div>
                    </form>
                </div>

                

             
            </div>
      
          </div>

          <!-- Icon Cards-->
      
        <!-- /.container-fluid -->

        <!-- Sticky Footer -->


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

    </div>
    <!-- /#wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
      <i class="fas fa-angle-up"></i>
    </a>

    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
          <div class="modal-footer">
            <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
            <a class="btn btn-primary" href="login.html">Logout</a>
          </div>
        </div>
      </div>
    </div>
   
    <!-- Bootstrap core JavaScript-->
    <script src="../vendor/jquery/jquery.min.js"></script>
    <script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="../vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Page level plugin JavaScript-->
    <script src="../vendor/chart.js/Chart.min.js"></script>
    <script src="../vendor/datatables/jquery.dataTables.js"></script>
    <script src="../vendor/datatables/dataTables.bootstrap4.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="../js/sb-admin.min.js"></script>

    <!-- Demo scripts for this page-->
    <script src="../js/demo/datatables-demo.js"></script>
    <script src="../js/demo/chart-area-demo.js"></script>

          <script language="javascript" type="text/javascript">
            $(document).ready(function(){
            $("form").on("submit", function(){
                $("#pageloader").fadeIn();
            });//submit

             $('#preloader').fadeOut();
            });//document ready



        </script>
</body>

</html>
