<?php include 'inc_classes.php'; 
include "admin_authentication.php";
$edit_access='';
$sel_acc="select * from edit_previleges where admin_id='".$_SESSION['admin_id']."' and privilege_id='392'";
$ptr_access=mysql_query($sel_acc);
if(mysql_num_rows($ptr_access))
{
	$edit_access='yes';
}
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Add Individual Task</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap datepicker -->
    <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="plugins/iCheck/all.css">
    <!-- Bootstrap Color Picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css">
    <!-- Bootstrap time Picker -->
    <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="bower_components/select2/dist/css/select2.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- paginate style -->
    <link rel="stylesheet" href="dist/css/paginate.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
    <!-- Google Font -->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<script>
// function select_repeat(type)
// {
// 	var repeat_data="action=repeat&type="+type;
//     alert(type);
// 	$.ajax({
// 	url: "individual_task_ajax.php",type:"post", data: repeat_data,cache: false,
// 	success: function(repeatation)
// 	{
// 		document.getElementById("show_data").innerHTML=repeatation;
// 		// document.getElementById("show_category").innerHTML=retwing;
// 		// document.getElementById("wing").innerHTML='';

// 		// $("#property").chosen({allow_single_deselect:true});
// 		// $("#category").chosen({allow_single_deselect:true});
// 		// alert(property_id);
// 	}
// 	});
// }
// function select_date()
// {
//     // document.getElementById("discount_coupon_per").value
// 	var dating=document.getElementByName("date1").value;
//     alert(dating);
// }
</script>
<script type="text/javascript">
// function show() { document.getElementById('payment').style.display = 'block'; $('#pay_type').removeClass("obrderclass");  }
// function hide() { document.getElementById('payment').style.display = 'none'; $('#pay_type').removeClass("obrderclass");  }
function show_types(value)
{
	Repeat_type=value.split("-");
	// alert(Repeat_type[0]);
	if(Repeat_type[0]=="weakly")
	{
		document.getElementById("weakly_type").style.display = 'block';
        document.getElementById("dead_line").style.display = 'none';
		document.getElementById("monthly_type").style.display = 'none';
		document.getElementById("yearly_type").style.display = 'none';
	}
    else if(Repeat_type[0]=="once")
	{
		document.getElementById("monthly_type").style.display = 'none';
        document.getElementById("dead_line").style.display = 'block';
        document.getElementById("weakly_type").style.display = 'none';
		document.getElementById("yearly_type").style.display = 'none';
		
	}
	else if(Repeat_type[0]=="monthly")
	{
		document.getElementById("monthly_type").style.display = 'block';
        document.getElementById("dead_line").style.display = 'block';
        document.getElementById("weakly_type").style.display = 'none';
		document.getElementById("yearly_type").style.display = 'none';
		
	}
	else if(Repeat_type[0]=="yearly")
	{
        document.getElementById("weakly_type").style.display = 'none';
        document.getElementById("dead_line").style.display = 'block';
		document.getElementById("monthly_type").style.display = 'none';
		document.getElementById("yearly_type").style.display = 'block';
    }
	else
	{
		document.getElementById("weakly_type").style.display = 'none';
        document.getElementById("dead_line").style.display = 'none';
		document.getElementById("monthly_type").style.display = 'none';
		document.getElementById("yearly_type").style.display = 'none';
	}
}

function select_staff(branch)
{
	var branch_data="action=staff&branch_name="+branch;
    // alert(branch);
	$.ajax({
	url: "tk_staff_ajax.php",type:"post", data: branch_data,cache: false,
	success: function(retstaff)
	{
		// alert(retstaff);
		document.getElementById("staff_name1").innerHTML=retstaff;
	
	}
	});
}
function select_admin(branch1)
{
	var branch_data1="action=admin&branch_name1="+branch1;
    // alert(branch);
	$.ajax({
	url: "tk_staff_ajax.php",type:"post", data: branch_data1,cache: false,
	success: function(retadmin)
	{
		// alert(retstaff);
		document.getElementById("admin_name").innerHTML=retadmin;
	
	}
	});
}
function show_hours(priority)
{
	var priority_data="action=hours&priority="+priority;
    // alert(branch);
	$.ajax({
	url: "tk_staff_ajax.php",type:"post", data: priority_data,cache: false,
	success: function(rethours)
	{
		// alert(retstaff);
		document.getElementById("hours").innerHTML=rethours;
	
	}
	});
}
</script>

<body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">
        <?php include "include/header-main.php"; ?>
        <!-- Left side column. contains the logo and sidebar -->
        <?php include "include/menu_left.php"; ?>
        <!-- Content Wrapper. Contains page content -->
        <!-- Left side column. contains the logo and sidebar -->
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                    Add Task
                    <!--<small>Version 2.0</small>-->
                </h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                    <li class="active">Dashboard</li>
                </ol>
            </section>
            <?php
                if($_REQUEST['id']!='')
                {
                    $record_id=$_REQUEST['id'];
                    $query="select * from tk_individual_task where staff_task_id='$record_id'";
                    $ptr_data_3=mysql_query($query);
                    $data=mysql_fetch_array($ptr_data_3);
                }
                else
                {
                    $record_id=''; 
                }

         if(isset($_POST['submit']))
           {
               $branch_name=($_POST['branch_name']);
                if (empty($_POST['task_name'])){
                    $task_Err = "Field is required";
                }
                else{
                $task_name=addslashes($_POST['task_name']);
                }
                if (empty($_POST['staff_name1'])){
                    $staff_Err = "Field is required";
                }
                else{
                $staff_id=$_POST['staff_name1'];
                }        
                if (empty($_POST['repeat_type'])){
                    $repeat_Err = "Field is required";
                }
                else{
                    $repetation=$_POST['repeat_type'];
                }
                $repeat1="select type_id from tk_task_repetation_type where repetation_type='".$repetation."'";
                $ptr_repeat1=mysql_query($repeat1);
                $data_repeat1=mysql_fetch_array($ptr_repeat1);
                $repetation_id=$data_repeat1['type_id'];
                if (empty($_POST['desc'])){
                    $desc_Err = "Field is required";
                }
                else{
                    $description=addslashes($_POST['desc']);
                }
                if (empty($_POST['priority1'])){
                    $priority_Err = "Field is required";
                }
                else{
                $Priority=$_POST['priority1'];
                }
                if (empty($_POST['hours'])){
                    $hours_Err = "Field is required";
                }
                else{
                $hours=$_POST['hours'];
                }
                $days=$_POST['days'];
                $repeat_date_month=$_POST['monthly_date'];
                $repeat_date_year=$_POST['yearly_date'];
                $due_date=$_POST['due_date'];
                $new_date=explode("/",$due_date);
                $due_date_fromat=$new_date[2].'-'.$new_date[1].'-'.$new_date[0];
                $admin_id =$_SESSION['admin_id'];

                $sel_id="select staff_id from tk_employee_total_performance";
                $ptr_id=mysql_query($sel_id);
                $data_id=mysql_fetch_array($ptr_id);
                $emp_id=$data_id['staff_id'];

                    $sel_point="select points from tk_performance where Priority='".$Priority."' and hours='".$hours."'";
					$ptr_point=mysql_query($sel_point);
					$data_point=mysql_fetch_array($ptr_point);
					$points=$data_point['points'];
                
                if($_SESSION['type']=='S' || $_SESSION['type']=='Z' || $_SESSION['type']=='LD')
				{
					$sel_branch="select cm_id, admin_id from site_setting where branch_name='".$branch_name."' and type='A'";
					$ptr_branch=mysql_query($sel_branch);
					$data_branch=mysql_fetch_array($ptr_branch);
					$cm_id=$data_branch['cm_id'];
                    $Validation="valid";
				}
				else
				{
					$cm_id=$_SESSION['cm_id'];
                    $Validation="pending";
				}
                   if($record_id)
                   { 
                    if($task_name !="" &&   $Priority !="" &&   $staff_id !="" && $hours !="" )
                    {
                         '<br>'.  $upd_task="update tk_individual_task set `task_name`='".$task_name."', `staff_id`='".$staff_id."',`priority`='".$Priority."',`hours`='".$hours."',`points`='".$points."',`description`='".$description."',`cm_id`='".$cm_id."', `repetation_id`='".$repetation_id."', `repeat_date_month`='".$repeat_date_month."', `repeat_date_year`='".$repeat_date_year."',`due_date`='".$due_date_fromat."' where staff_task_id='".$record_id."' ";
                          $ptr_upd_task=mysql_query($upd_task); 
                          $days_count=count($days);
                          if($days_count > 0)
							{
                                $delete_rec="delete from tk_repetation_days where staff_task_id='".$record_id."'";
                                $ptr_delete_rec=mysql_query($delete_rec);
                          for($i=0;$i<$days_count;$i++)
                              {
                            '<br>'. $insert_days="insert into tk_repetation_days(`staff_task_id`,`repetation_id`,`days`) values('".$record_id."','".$repetation_id."','".$days[$i]."')";
                              $ptr_days=mysql_query($insert_days);
                              }
                                  }
                          if ($ptr_upd_task)
                            {
                                ?>
                                <div class="alert alert-success alert-dismissible">
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                    <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                                    <p> Record Updated Successfully.</p>
                                </div>
                                <script>setTimeout('document.location.href="tk_add_individual_task.php";', 1000);</script>
                                <?php
                            }       
                        }  
                    }
                    else
                   {
                        if($task_name !="" &&   $Priority !="" &&   $staff_id !="" )
                        {
                             $insert_task="insert into tk_individual_task(`task_name`,`staff_id`,`description`,`priority`,`hours`,`points`,`due_date`,`deadline_count`,`Validation`,`status`,`repetation_id`,`repeat_date_month`,`repeat_date_year`,`cm_id`,`admin_id`,`added_date`) values('".$task_name."','".$staff_id."','".$description."','". $Priority."','". $hours."','". $points."','".$due_date_fromat."','1','".$Validation."','in_progress','".$repetation_id."','".$repeat_date_month."','".$repeat_date_year."','".$cm_id."','".$admin_id."','".date('Y-m-d : H:i:s')."')";
                          $ptr_ins_t=mysql_query($insert_task);
                          $task_id=mysql_insert_id(); 

                          if($task_id !="")
                          {
                              // detail inserting
                             $task_details="insert into individual_task_details(`staff_task_id`,`admin_id`,`cm_id`,`added_date`) values('".$task_id."','".$admin_id."','".$_SESSION['cm_id']."','".date('Y-m-d : H:i:s')."')";
                              $ptr_data=mysql_query($task_details); 
                          } 
                          $days_count=count($days);
							for($i=0;$i<$days_count;$i++)
								{
                                $insert_days="insert into tk_repetation_days(`staff_task_id`,`repetation_id`,`days`) values('".$task_id."','".$repetation_id."','".$days[$i]."')";
                                $ptr_days=mysql_query($insert_days);
                                    }
                            if($emp_id!=$staff_id){
                            $insert_id="insert into tk_employee_total_performance(`staff_id`) values('".$staff_id."')";
                            $ptr_id=mysql_query($insert_id);
                                    }
                          if ($ptr_ins_t)
                            {
                                ?>
                                <div class="alert alert-success alert-dismissible">
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                    <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                                    <p> Record Inserted Successfully.</p>
                                </div>
                                <script>setTimeout('document.location.href="tk_add_individual_task.php";', 1000);</script>
                                <?php
                            }
                        }
                    }
            }
            // task  deleting
              if($_REQUEST['deleteRecord']!='' && $_REQUEST['id']!='')
                {
                        $id=$_REQUEST['id'];
                        $delete_task="delete from tk_individual_task where staff_task_id='".$id."'";   //task delete
                        $ptr_delete_task=mysql_query($delete_task);
                        $delete_task_details="delete from individual_task_details where staff_task_id='".$id."'";     //task detail delete
                        $ptr_delete_details=mysql_query($delete_task_details);
                        $delete_task_days="delete from tk_repetation_days where staff_task_id='".$id."'";     //task repetation days delete
                        $ptr_delete_days=mysql_query($delete_task_days);
                        if ($ptr_delete_task)
                        {
                        ?>
                            <div class="alert alert-danger alert-dismissible">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                                <p> Record Deleted Successfully.</p>
                            </div>
                            <script>
                                //  if(confirm("Are you sure, you want to delete selected record(s)?")){
                                setTimeout('document.location.href="tk_add_individual_task.php";', 1000);
                                                            // }
                            </script>
                        <?php
                        }
                }
            ?>
            <!-- Main content -->
            <section class="content">
                <!-- SELECT2 EXAMPLE -->
                <div class="box box-default">
                    <div class="box-body">
                        <form name="task_form" method="post">
                            <div class="row">
                                <div class="col-md-5">
                                    <p style="color:red"> * Required Field</p>
                                    <?php
                                    if($_SESSION['type']=='S'){
                                    ?>
                                    <label>Branch Name </label>
                                    <div class="form-group">
                                        <select class="form-control select2"  style="width:200px" name="branch_name" id="sel1" onchange="select_staff(this.value)">
                                        <option value="">Select Branch</option>
                                        <?php
                                              $sel_branch = "SELECT * FROM branch where 1 order by branch_id asc ";	 
                                              $query_branch = mysql_query($sel_branch);
                                              while($row_branch = mysql_fetch_array($query_branch))
                                              {
                                                  $selected='';
                                                  if($_POST['branch_name']== $row_branch['branch_name'])
                                                  {
                                                       $selected='selected="selected"';
                                                  }
                                                  $selected_branch="select branch_name from site_setting where cm_id= '".$data['cm_id']."' and type='A' ";
                                                  $ptr_selected=mysql_query($selected_branch);
                                                  if(mysql_num_rows($ptr_selected))
                                                  {
                                                      $data_cm_id=mysql_fetch_array($ptr_selected);
                                                      if($data_cm_id['branch_name'] == $row_branch['branch_name'] )
                                                      {
                                                           $selected='selected="selected"';
                                                      }
                                                  }
                                                  ?>
                                                  <option <?php echo $selected; ?> value="<?php echo $row_branch['branch_name'];?>"><?php echo $row_branch['branch_name']; ?> 
                                                  </option>
                                                  <?php
                                              }
                                              ?>
                                        </select>
                                    </div>
                                    <?php
                                    } 
                                    else { ?>
                                        <input type="hidden" name="branch_name" id="branch_name" value="<?php echo $_SESSION['branch_name']; ?>"  />
                                                   <?php }?>
                    
                                    <div class="form-group">
                                        <label><span style="color:red">*</span>Task Name &nbsp;&nbsp;<span style="color:red">
                                                <?php echo $task_Err ;?></span></label>
                                        <input type="text" class="form-control" style="width:200px" name="task_name" id="task_name"
                                            placeholder="Task Name" value="<?=$data['task_name']?>">
                                    </div>
                                    <div class="form-group" >
                                    <label><span style="color:red">*</span>Task Staff &nbsp;&nbsp;<span style="color:red"> <?php echo $staff_Err ;?></span></label>
                                    <?php
                                    if($record_id){
                                        ?>
                                        <div>
                                        <select class="form-control select2"  style="width:200px" name="staff_name1" id="staff_name1">
                                        <option value="">Select Staff</option>
                                        <?php
                                        $sel_staff1="select admin_id,name from site_setting where cm_id='".$data['cm_id']."'order by name ASC";
                                        $c_query=mysql_query($sel_staff1);
                                        while($data_c=mysql_fetch_array($c_query))
                                       {
                                            $sel='';
                                            if($data['staff_id']==$data_c['admin_id'])
                                            {
                                              $sel='selected=selected';
                                            }
                                            ?>
                                        <option <?php echo $sel;?> value="<?php echo $data_c['admin_id'] ;?>"><?php echo ucfirst($data_c['name']);?> </option>
                                        <?php
                                        }
                                        ?>
                                        </select>
                                    </div>
                                        <?php
                                    }
                                    else{
                                    ?>
                                    <div >
                                        <select class="form-control select2"  style="width:200px" name="staff_name1" id="staff_name1">
                                        <option value="">Select Staff</option>
                                        </select>
                                    </div>
                                    <?php
                                    }
                                    ?>
                                    </div>
                                    <!-- <div class="form-group">
                                        <div> 
                                            <label>
                                                <span style="color:red">*</span> Priority &nbsp;&nbsp;<span style="color:red"> <?php echo $priority_Err ;?></span>
                                           </label>
                                        </div>
                                        <label class="radio-inline"><input type="radio" name="optradio" id="high" <?php
                                                if($data['priority']=='high' ) echo 'checked="checked"' ; ?>
                                            value="high">High</label>
                                        <label class="radio-inline"><input type="radio" name="optradio" id="medium"
                                                <?php if($data['priority']=='medium' ) echo 'checked="checked"' ; ?>
                                            value="medium">Medium</label>
                                        <label class="radio-inline"><input type="radio" name="optradio" id="low" <?php
                                                if($data['priority']=='low' ) echo 'checked="checked"' ; ?>
                                            value="low">Low</label>
                                    </div> -->
                                    <div class="form-group">
                                    <label><span style="color:red">*</span>Description &nbsp;&nbsp;<span style="color:red"> <?php echo $desc_Err ;?></span></label>
                                        <textarea class="form-control" name="desc" rows="3"
                                            placeholder="Enter ..."> <?php echo $data['description'] ?></textarea>
                                    </div>
                                    <!-- <div class="form-group">
                                        <label>Due Date</label>
                                        <div class="input-group date">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="form-control pull-left" name="due_date"
                                                id="datepicker" value="<?php //echo $data['due_date'];?>">
                                        </div>
                                    </div> -->
                                </div>
                                <div class="col-md-5">
                                    <!-- <div><br><br></div> -->
                                    <div class="form-group">
                                        <div>
                                     <label><span style="color:red">*</span>Priority &nbsp;&nbsp;<span style="color:red"> <?php echo $priority_Err ;?></span></label>
                                </div>
                                        <select class="form-control select2"  style="width:250px;" name="priority1" id="select1" onChange="show_hours(this.value)">
                                        <option value="">Select </option>
                                        <option value="low" <? if ($_POST['priority1'] == "Low") echo "selected='selected'"; else if($data['priority'] == "Low") echo "selected='selected'";?>>Low </option>
                                        <option value="medium" <? if ($_POST['priority1'] == "Medium") echo "selected='selected'"; else if($data['priority'] == "Medium") echo "selected='selected'";?>>Medium </option>
                                        <option value="high" <? if ($_POST['priority1'] == "High") echo "selected='selected'"; else if($data['priority'] == "High") echo "selected='selected'";?>>High </option>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                       <div>
                                             <label><span style="color:red">*</span>Task Hours &nbsp;&nbsp;<span style="color:red"> <?php echo $hours_Err ;?></span></label>
                                       </div>
                                       <?php
                                    if($record_id){
                                        ?>
                                        <div>
                                        <select class="form-control select2"  style="width:250px" name="hours" id="hours">
                                        <option value="">Select Hours</option>
                                        <?php
                                        $sel_hour="select hours,points from tk_performance where priority='".$data['priority']."'";
                                        $hour_query=mysql_query($sel_hour);
                                        while($data_hour=mysql_fetch_array($hour_query))
                                       {
                                            $sel='';
                                            if($data['hours']==$data_hour['hours'])
                                            {
                                              $sel='selected=selected';
                                            }
                                            ?>
                                        <option <?php echo $sel;?> value="<?php echo $data_hour['hours'] ;?>"><?php echo $data_hour['hours'] ;?> </option>
                                        <?php
                                        }
                                        ?>
                                        </select>
                                    </div>
                                        <?php
                                    }
                                    else{
                                    ?>
                                       <div >
                                           <select class="form-control select2"  style="width:250px" name="hours" id="hours">
                                               <option value="">Select Hours</option>
                                            </select>
                                        </div> 
                                        <?php
                                    }
                                    ?>
                                    </div>

                                   <div class="form-group">
                                    <div>
                                     <label><span style="color:red">*</span>Repetation &nbsp;&nbsp;<span style="color:red"> <?php echo $repeat_Err ;?></span></label>
                                                </div>
                                        <select class="form-control select2"  style="width:250px;" name="repeat_type" id="select" onChange="show_types(this.value)">
                                        <option value="">Select </option>
                                        <?php
                                                    $repeat="select type_id,repetation_type from tk_task_repetation_type order by type_id ASC";
                                                    $ptr_repeat=mysql_query($repeat);
                                                    while($data_repeat=mysql_fetch_array($ptr_repeat))
                                                   {
                                                        $sel='';
                                                        if($data['repetation_id']==$data_repeat['type_id'])
                                                        {
                                                          $sel='selected=selected';
                                                        }
                                                        echo  '<option '.$sel.' value="'.$data_repeat['repetation_type'].'">'.strip_tags(ucfirst($data_repeat['repetation_type'])). '</option>';
                                                    }
                                                ?>
                                        </select>
                                    </div>
                                    <div id="weakly_type" <?php if($data['repetation_id']==3) echo 'style="display:block"';else echo 'style="display:none"';?>>
                                        <label>Select Days</label>
                                        <div class="checkbox" >
                                            <?php
                                            $sel_day="select days from tk_days ";
                                            $ptr_days=mysql_query($sel_day);
                                           while($data_day=mysql_fetch_array($ptr_days)){
                                               $sel='';
                                               if($record_id){
                                                 $task_day="select * from tk_repetation_days where staff_task_id='".$data['staff_task_id']."' and days='".$data_day['days']."'";
                                                    $ptr_task_days=mysql_query($task_day);
                                                    if(mysql_num_rows($ptr_task_days))
                                                    {
                                                        $sel='checked="checked"';
                                                    }
                                                }
                                                ?>      
                                                    <label><input type="checkbox" <?php echo $sel; ?> value="<?php $data_day['days']; ?>" name="days[]"><b <?php if($data_day['days']=='Sun') echo 'style="color:red;"'; else 'style="color:blue;"'?>><?php echo $data_day['days'] ?></b></label>&nbsp;&nbsp;&nbsp;&nbsp; 
                                                    <?php   
                                           }
                                            ?>
                                        </div>
                                    </div>
                                    <div id="monthly_type" <?php if($data['repetation_id']==4) echo 'style="display:block"';else echo 'style="display:none"';?>>
                                    <div class="form-group">
                                    <label>Create Date</label>
                                        <div class="input-group date">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="form-control pull-left" name="monthly_date" id="datepicker1" value="<?php echo $data['repeat_date_month'];?>">
                                        </div>
                                    </div>
                                    </div>
                                    <div id="yearly_type" <?php if($data['repetation_id']==5) echo 'style="display:block"';else echo 'style="display:none"';?>>
                                    <div class="form-group">
                                    <label>Create Date</label>
                                        <div class="input-group date">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="form-control pull-left" name="yearly_date" id="datepicker2" value="<?php echo $data['repeat_date_year'];?>">
                                        </div>
                                    </div>
                                    </div>
                                    <div id="dead_line" <?php if($data['repetation_id']=='1' || $data['repetation_id']=='4' || $data['repetation_id']=='5') echo 'style="display:block"';else echo 'style="display:none"';?>>
                                    <div class="form-group">
                                        <label>Dead Line</label>
                                        <div class="input-group date">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="form-control pull-left" name="due_date" id="datepicker" value="<?php if($_POST['due_date']) echo $_POST['due_date']; else {
										if($data['due_date'] !='')
										{
											$arrage_date= explode('-',$data['due_date'],3);     
											echo $arrage_date[2].'/'.$arrage_date[1].'/'.$arrage_date[0]; 
										}
										$row_record['staff_dob'];
									}?>" />
                                        </div>
                                    </div>
                                    </div>
                                </div> 
                                <div class="col-md-12">
                                    <input type="submit" name="submit"
                                        value="<?php if($record_id) echo 'Update'; else echo 'Submit'; ?>"
                                        class="btn btn-block btn-success">
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

                <!-- manage task and task table -->
                <div class="row">
                    <!-- Left col -->
                    <div class="col-md-12">
                        <!-- TABLE: LATEST ORDERS -->
                        <div class="box box-info">
                            <div class="box-header with-border">
                                <h3 class="box-title">manage Task</h3>
                            </div>
                            <!-- search filter -->
                            <div class="">
                            <table>
                                <form method="get" name="search">
                                    <tr>
                                        <td>
                                        <?php if($_SESSION['type']=='S' || $_SESSION['type']=='Z' || $_SESSION['type']=='LD' || $edit_access=='yes')
                                    {
                                        ?>

                                        <select class="form-control select2" id="branch_name1" style="width:200px"  name="branch_name1" onchange="select_admin(this.value)";>
                                            <option value="">Select Branch</option>
                                                <?php 
                                                $sel_branch="select branch_id,branch_name from branch";
                                                $ptr_sel=mysql_query($sel_branch);
                                                while($data_branch=mysql_fetch_array($ptr_sel))
                                                {
                                                $sel='';
                                                if($data_branch['branch_name']==$_GET['branch_name'])
                                                {
                                                    $sel='selected="selected"';
                                                }
                                                echo '<option '.$sel.' value="'.$data_branch['branch_name'].'" >'.$data_branch['branch_name'].'</option>';
                                                }
                                                ?>
                                            </select>
                                            <?php
                                            }
                                            else
                                            {
                                            ?>
                                            <input type="hidden" name="branch_name1" id="branch_name1" value="<?php echo $_SESSION['branch_name']; ?>"  />
                                            <?php
                                            }
                                            ?>
                                        </td>
                                        <td width="5px"></td>
                                        <td>
                                            <div>
                                                <select class="form-control select2" style="width:200px" id="admin_name" name="admin_name" >
                                                    <option value="">Assinged To</option>
                                                </select>
                                            </div>
                                        </td>
                                        <td width="5px"></td>
                                        <?php if($_SESSION['type']=='S' || $_SESSION['type']=='Z' || $_SESSION['type']=='LD' || $edit_access=='yes')
                                    {
                                        ?>
                                        <td>
                                            <div>
                                                <select class="form-control select2" style="width:200px" id="staff_names" name="staff_names" >
                                                    <option value="">Assinged By</option>
                                                    <?php
                                                    $categary="select admin_id,name from site_setting order by name ASC";   //where cm_id='".$branch_data['cm_id']."'
                                                    $c_query=mysql_query($categary);
                                                    while($data_c=mysql_fetch_array($c_query))
                                                    {
                                                        echo  '<option  value="'.$data_c['admin_id'].'">'.ucfirst($data_c['name']). '</option>';
                                                    }
                                                    ?>
                                                </select>
                                            </div>
                                        </td>
                                        <td width="5px"></td>
                                        <?php
                                        }
                                        ?>
                                        <td>
                                            <input type="text" class="form-control" name="keyword" id="search_project" value="<?php if($_REQUEST['search']!="search") echo $_REQUEST['search'];?>" placeholder="search">
                                        </td> 
                                        <td width="5px"></td>
                                        <td>
                                            <input type="image" src="images/search.jpg" name="search" value="search" style="height:32px;">
                                        </td>
                                    </tr>
                                </form>
                                </table>
                            </div>
                             <!-- end search filter -->
                            <style>
                                th {
                                    text-align: center;
                                }
                            </style>
                            <div class="box-body">
                                <div class="table-responsive">
                                    <table class="table no-margin" style="text-align:center">
                                        <thead>
                                            <tr>
                                                <th>Sr. No.</th>
                                                <th>Task Name</th>
                                                <th>Assinged To</th>
                                                <th>Repetation</th>
                                                <th>Hours</th>
                                                <th>Priority</th>
                                                <th>Status</th>
                                                <th>Added Date</th>
                                                <th>Dead Line</th>
                                                <th>Assinged BY</th>
                                                <th>Validation</th>
                                                <th>Details</th>
                                                <?php
                                            //  if($_SESSION['type']=='S'){
                                                ?>
                                                <th>Action</th>
                                                <?php
                                            //  }
                                                ?>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                               
                                               if(isset($_REQUEST['submit_valiadtion']))
                                               {
                                                   $task_ids=$_POST['task_id1'];
                                                   $validation=$_POST['validation'];
                                                   $reason=$_POST['reason'];
                                                   $admin_id =$_SESSION['admin_id'];
   
                                                  if($reason!=''){
                                                       $insert_project="insert into tk_task_validation(`staff_task_id`,`reasons`,`added_date`,`admin_id`) values('".$task_ids."','".$reason."','".date('Y-m-d : H:i:s')."','".$admin_id."')";
                                                       $ptr_ins=mysql_query($insert_project);
                                                  }
                                                  if($validation!=''){
                                                       $update_status="update tk_individual_task set `Validation`='".$validation."' where staff_task_id='".$task_ids."'";
                                                       $ptr_ins_t=mysql_query($update_status);
                                                  }
                                               }
                                    ?>
                                    <?php
                                                if($_REQUEST['branch_name1']!='')
                                                {
                                                  $branch_name=$_REQUEST['branch_name1'];
                                                  $select_cm_id="select cm_id from site_setting where branch_name='".$branch_name."' and type='A'";
                                                  $ptr_cm_id=mysql_query($select_cm_id);
                                                  $data_cm_id=mysql_fetch_array($ptr_cm_id);
                                                  $search_cm_id="and cm_id='".$data_cm_id['cm_id']."'";
                                                }
                                                else
                                                {
                                                  $search_cm_id='';
                                                }
                                                // $search=$_REQUEST['staff_name'];
                                                if($_REQUEST['admin_name']!='')
                                                {
                                                  $staff_id=$_REQUEST['admin_name'];
                                                  $search_staff_id="and staff_id='".$staff_id."'";
                                                }
                                                else
                                                {
                                                  $search_staff_id='';
                                                }
                                                if($_REQUEST['staff_names']!='')
                                                {
                                                  $admin_ids=$_REQUEST['staff_names'];
                                                  $search_admin_id="and admin_id='".$admin_ids."'";
                                                }
                                                else
                                                {
                                                  $search_admin_id='';
                                                }
                            
                                                $i=1;
                                                if($_REQUEST['keyword']!="keyword")
                                                $search=trim($_REQUEST['keyword']);
                                                if($search)
                                                {
                                                  $task_search=" and (task_name like '%".$search."%' || priority like '%".$search."%' || status like '%".$search."%')";
                                                }
                                                else
                                                {
                                                  $task_search="";
                                                }
                                                if($_SESSION['type']=='S' || $edit_access=='yes'){
                                                    
													$sel_task="select * from tk_individual_task where 1 ".$search_admin_id." ".$search_staff_id." ".$task_search." order by staff_task_id desc";
                                                }
                                               else{
                                               		$sel_task="select * from tk_individual_task where 1 and admin_id='".$_SESSION['admin_id']."' ".$search_staff_id." ".$task_search." order by staff_task_id desc";
                                               }
                                            //    echo $sel_task;
                                               $ptr_sel_task=mysql_query($sel_task);
                                               $ptr_sel_task=mysql_query($sel_task);
                                               while($data1=mysql_fetch_array($ptr_sel_task))
                                               {
                                                    $sel_staff="select name from site_setting where 1 and admin_id='".$data1['staff_id']."'";
                                                    $ptr_staff=mysql_query($sel_staff);
                                                    $data_staff=mysql_fetch_array($ptr_staff);

                                                    $add_data="select name from site_setting where 1 and admin_id='".$data1['admin_id']."'";
                                                    $ptr_data_a=mysql_query($add_data);
                                                    $data_add=mysql_fetch_array($ptr_data_a);
                                                    ?>
                                                    <tr>
                                                        <td>
                                                            <?php echo $i++ ?>
                                                        </td>
                                                        
                                                        <td>
                                                            <?php echo strip_tags(ucwords($data1['task_name']))?>
                                                        </td>
                                                        <td>
                                                            <?php echo strip_tags(ucwords($data_staff['name']))?>
                                                        </td>
                                                        <td>
                                                            <?php 
                                                             $repeat="select repetation_type from tk_task_repetation_type where type_id='".$data1['repetation_id']."' order by type_id ASC";
                                                             $ptr_repeat=mysql_query($repeat);
                                                             $data_repeat=mysql_fetch_array($ptr_repeat);
                                                            echo ucwords($data_repeat['repetation_type']);
                                                            ?>
                                                        </td>
                                                        <!-- <td> -->
                                                            <?php //echo strip_tags(substr(ucwords($data['description']),0,50))?>
                                                        <!-- </td> -->
                                                        <td>
                                                            <?php echo ucfirst($data1['priority'])?>
                                                        </td>
                                                        <td>
                                                            <?php
                                                             if($data1['status']=='complete') 
                                                                { 
                                                                ?>
                                                                <p class="label label-success"> <?php echo ucfirst($data1['status']);?></p>
                                                                <?php
                                                                } 
                                                                if($data1['status']=='in_progress') 
                                                                { 
                                                                ?>
                                                                <p class="label label-warning"><?php echo ucfirst($data1['status']);?></p>
                                                                <?php
                                                                } 
                                                                if($data1['status']=='in_complete') 
                                                                { 
                                                                    ?>
                                                                    <p class="label label-danger"><?php echo ucfirst($data1['status']);?></p>
                                                                    <?php
                                                                } 
                                                                if($data1['status']=='cancel') 
                                                                { 
                                                                    ?>
                                                                    <p class="label label-default"><?php echo ucfirst($data1['status']);?></p>
                                                                    <?php
                                                                }
                                                                if($data1['status']=='halt') 
                                                                { 
                                                                    ?>
                                                                    <p class="label label-primary"><?php echo ucfirst($data1['status']);?></p>
                                                                    <?php
                                                                }
                                                            ?>
                                                        </td> 
                                                     
                                                        <td>
                                                            <?php
                                                                $new_addDate = date("d-m-Y", strtotime($data1['added_date']));  
                                                                echo $new_addDate;  
                                                            ?>
                                                        </td>
                                                        <td>
                                                            <?php 
                                                            if($data1['due_date']!=''){
                                                                $new_dueDate = date("d-m-Y", strtotime($data1['due_date']));
                                                                echo $new_dueDate ;
                                                                // echo $data['due_date'];
                                                            }
                                                            ?>
                                                        </td>
                                                        <td>
                                                            <?php echo ucfirst($data_add['name']);?>
                                                        </td>
                                                        <td>
                                                        <?php
                                                  if($_SESSION['type']=="S" || $edit_access=='yes'){
                                                  ?>
                                                        <button type="button" class="btn btn-default" data-toggle="modal"
                                                            data-target="#<?php echo $data1['staff_task_id'];?>" style="width:70px;"><?php echo ucfirst($data1['Validation']);?>
                                                        </button><?php
                                                        }
                                                        else{
                                                            $sel_reason="select reasons,admin_id from tk_task_validation where staff_task_id='".$data1['staff_task_id']."'order by v_id DESC ";
                                                            $ptr_reason=mysql_query($sel_reason);
                                                            $data_reason=mysql_fetch_array($ptr_reason);
                                                            ?>
                                                           <span title="<?php echo(ucwords($data_reason['reasons'])) ?>"> <?php echo ucfirst($data1['Validation']); ?></span>
                                                            <?php
                                                        }
                                                        ?>
                                                                <div class="modal fade" id="<?php echo $data1['staff_task_id'];?>">
                                                                <div class="modal-dialog">
                                                                    <div class="modal-content">
                                                                        <div class="modal-body">
                                                                            <!-- body code -->
                                                                            <div class="box box-default">
                                                                                <form name="task_form12" method="post">
                                                                                    <div class="box-body">
                                                                                        <div class="row">
                                                                                            <div class="col-md-8">
                                                                                            <div class="form-group">
                                                                                                <?php
                                                                                                if($_SESSION['type']=="S" || $edit_access=='yes'){ ?>
                                                                                                    <label>Task Validation </label><br>
                                                                                                    <label>Valid
                                                                                                    <input type="radio" name="validation" value="valid" <?php if($_POST['validation'] == "valid") echo 'checked="checked"'; else if($data1['Validation']== "valid") echo 'checked="checked"'; ?> class="minimal" >
                                                                                                    </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                                                                    <label>In-Valid
                                                                                                    <input type="radio" name="validation" value="in_valid"  <?php if($_POST['validation'] == "in_valid") echo 'checked="checked"'; else if($data1['Validation']== "in_valid") echo 'checked="checked"'; ?> class="minimal-red">
                                                                                                    </label>
                                                                                                    <?php }
                                                                                                    else {
                                                                                                        echo '<div><b>'.ucfirst($data1['Validation']).'</b></div>';
                                                                                                    } ?>
                                                                                                    <input type="hidden" name="task_id1" value="<?php echo $data1['staff_task_id'];?>" >
                                                                                                </div>
                                                                                                <div class="form-group">
                                                                                                    <textarea type="" class="form-control" name="reason" id="reason"
                                                                                                    value=""  placeholder="Add Query"></textarea>
                                                                                                </div>
                                                                                                <div class="form-group">
                                                                                                    <div class="">
                                                                                                        <input type="submit" name="submit_valiadtion" value="Submit" class="btn btn-block btn-success">
                                                                                                    </div>
                                                                                                </div>
                                                                                                </div>
                                                                                                <div class="col-md-4">
                                                                                                <div class="direct-chat-messages">
                                                                                                    <?php
                                                                                                    $sel_reason="select reasons,admin_id from tk_task_validation where staff_task_id='".$data1['staff_task_id']."'";
                                                                                                    $ptr_reason=mysql_query($sel_reason);
                                                                                                    $no_records=mysql_num_rows($ptr_reason);
                                                                                                    if($no_records){
                                                                                                    ?>
                                                                                                <label>Reasons </label><br>
                                                                                                    <?php
                                                                                                    while($data_reason=mysql_fetch_array($ptr_reason)){
                                                                                                    $add="select name from site_setting where 1 and admin_id='".$data_reason['admin_id']."'";
                                                                                                    $ptr=mysql_query($add);
                                                                                                    $data2=mysql_fetch_array($ptr);
                                                                                                    if($data_reason['reasons']!=''){
                                                                                                        echo '<div><b>'.ucfirst($data2['name']).'</b></div>';
                                                                                                        echo '<li>'.ucwords($data_reason['reasons']).'</li>';
                                                                                                    }
                                                                                                }
                                                                                                    }
                                                                                                    ?>
                                                                                                </div>
                                                                                                </div>
                                                                                        </div>
                                                                                    </div>
                                                                                </form>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <?php
                                                            // echo $data1['staff_task_id'];
                                                            if($data1['Validation']=='valid' || $_SESSION['type']=="S" || $edit_access=='yes'){
                                                                ?>
                                                            <a href="tk_individual_task_detail.php?id=<?=$data1['staff_task_id'] ?>" target=""><i class="fa fa-file"></i></a> 
                                                            <?php
                                                            }
                                                                ?>
                                                        </td>
                                                        <td>
                                                        <?php
                                                            // echo $data1['staff_task_id'];
                                                            if($data1['status']!='complete'){
                                                                ?>
                                                                <a href="tk_add_individual_task.php?id=<?=$data1['staff_task_id']?>"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;
                                                            <a href="tk_add_individual_task.php?deleteRecord=1&id=<?=$data1['staff_task_id']?>">
                                                                <i class="fa fa-trash"></i></a>
                                                                <?php
                                                            }
                                                                ?>
                                                        </td>
                                                    </tr>
                                                    <?php
                                                }
                                            ?>
                                        </tbody>
                                    </table>
                                     <!-- table pagination code -->
                                    <div class="pagination">
                                        <a href="#">&laquo;</a>
                                        <a href="" class="active">1</a>
                                        <a href="" >2</a>
                                        <a href="">3</a>
                                        <a href="">&raquo;</a>
                                  </div>
                                </div>
                                <!-- /.table-responsive -->
                                <!-- /.box-body -->
                            </div>
                            <!-- /.box-footer -->
                        </div>
                        <!-- /.box -->
                    </div>
                    <!-- /.col -->
                </div>
                <!--end manage task and task table -->
                <!-- /.box -->
            </section>
            <!-- /.content -->
        </div>
        <!-- /.content-wrapper -->
        <?php include "include/footer-main.php"; ?>
    </div>

    <!-- jQuery 3 -->
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap 3.3.7 -->
    <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- Select2 -->
    <script src="bower_components/select2/dist/js/select2.full.min.js"></script>
    <!-- InputMask -->
    <script src="plugins/input-mask/jquery.inputmask.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>
    <!-- date-range-picker -->
    <script src="bower_components/moment/min/moment.min.js"></script>
    <script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
    <!-- bootstrap datepicker -->
    <script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
    <!-- bootstrap color picker -->
    <script src="bower_components/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js"></script>
    <!-- bootstrap time picker -->
    <script src="plugins/timepicker/bootstrap-timepicker.min.js"></script>
    <!-- SlimScroll -->
    <script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
    <!-- iCheck 1.0.1 -->
    <script src="plugins/iCheck/icheck.min.js"></script>
    <!-- FastClick -->
    <script src="bower_components/fastclick/lib/fastclick.js"></script>
    <!-- AdminLTE App -->
    <script src="dist/js/adminlte.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="dist/js/demo.js"></script>
    <!-- Page script -->
    <script>
        $(function () {
            //Initialize Select2 Elements
            $('.select2').select2()

            //Datemask dd/mm/yyyy
            /*$('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
            //Datemask2 mm/dd/yyyy
            $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
            //Money Euro
            $('[data-mask]').inputmask()
        
            //Date range picker
            $('#reservation').daterangepicker()
            //Date range picker with time picker
            $('#reservationtime').daterangepicker({ timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A' })
            //Date range as a button
            $('#daterange-btn').daterangepicker(
              {
                ranges   : {
                  'Today'       : [moment(), moment()],
                  'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                  'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
                  'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                  'This Month'  : [moment().startOf('month'), moment().endOf('month')],
                  'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                },
                startDate: moment().subtract(29, 'days'),
                endDate  : moment()
              },
              function (start, end) {
                $('#daterange-btn span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
              }
            )*/

            //Date picker
            $('#datepicker').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                startDate: '-0d',
                Default: true,
                todayHighlight: true
            })
            $('#datepicker1').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                Default: true,
                todayHighlight: true
            })
             $('#datepicker2').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                Default: true,
                todayHighlight: true
            })
            // $('#datepicker21').datepicker({
            //     autoclose: true,
            //     format: 'dd/mm/yyyy',
            //     Default: true,
            //     todayHighlight: true
            // })
            // $('#datepicker12').datepicker({
            //     autoclose: true,
            //     format: 'dd/mm/yyyy',
            //     Default: true,
            //     todayHighlight: true
            // })
            //iCheck for checkbox and radio inputs
            $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue'
            })
            //Red color scheme for iCheck
            $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
                checkboxClass: 'icheckbox_minimal-red',
                radioClass: 'iradio_minimal-red'
            })
            //Flat red color scheme for iCheck
            $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
                checkboxClass: 'icheckbox_flat-green',
                radioClass: 'iradio_flat-green'
            })

            //Colorpicker
            $('.my-colorpicker1').colorpicker()
            //color picker with addon
            $('.my-colorpicker2').colorpicker()

            //Timepicker
            $('.timepicker').timepicker({
                showInputs: false
            })
        })
    </script>
    <?php
	if($_SESSION['type']!='S'){
		?>
	<script>
		branch=document.getElementById("branch_name").value;
	    select_staff(branch);
    </script>
<?php
	}
	?>
</body>

</html>