<?php include("_config/dbconfig.php");
include("_includes/head.php");?>
<title>Tasks </title>
<style>
    .deactive_row td { background-color: #FFAAAA !important; }
    .dropdown-menu { background: #eee;}
    .dropdown-menu li{border-bottom: 1px solid #ccc;}
    .fc-day-grid-event .fc-time{display: none;}
</style>
<link rel="stylesheet" href="css/fullcalendar.min.css" media="screen">
<link rel="stylesheet" href="css/bootstrap-datetimepicker.min.css" media="screen">
<?php include("_includes/header.php"); 

if(isset($_SESSION['user_session'])){
$agent_id = $_SESSION['user_session'];
}else {
$agent_id = 0;	
}


if(isset($_POST['task_submit'])){
         
       
       $title= $_POST['title'];
       $description= $_POST['descp'];
       $start_date = $_POST['eventStartDate'];
       $end_date = $_POST['eventEndDate'];
       $exhibition = $_POST['exhibition'];
       
       $obj_jobs_class->addAgentTask($title, $description, $start_date, $end_date, $exhibition, $agent_id);
      /* echo '<pre>';
       print_r($_POST);
       echo '</pre>';*/
       echo "<script>window.location='task_calender.php'</script>"; 
       die();
}


$tasks_all = array();
$event_all      = $obj_events_class->getAgetEvent($agent_id);   

$ck = '';
if(isset($_GET['pt']) &&  $_GET['pt']> 0){ $tasks_all      = $obj_jobs_class->getAgentPendingTasks($agent_id); }
else if(!isset($_GET['pt'])){ $tasks_all      = $obj_jobs_class->getAgentPendingTasks($agent_id); }

$exi_task_list = array();
if(isset($_GET['exi']) && !empty($_GET['exi'])) { 
    
    if($_GET['exi']>0 && $_GET['exi']!='all'){
        $exi_task_list =  $obj_jobs_class->getEventPendingTasks($agent_id,$_GET['exi']);
    }else {
        $exi_task_list = $obj_jobs_class->getEventPendingTasks($agent_id);
    }
}
 
/*echo '<pre>';
print_r($exi_task_list);
echo '</pre>';        */
        
         
?>
<div class="col-sm-12 right_form">
        <div class="title">
            <div class="row">
                <div class="col-md-2 col-sm-2">
                    <h1>Task Calendar</h1>
                </div>
                
                <div class="col-md-2 col-sm-2">
                      <div class="">
                           <?php    $ck = '';
                                    if(isset($_GET['pt']) &&  $_GET['pt']> 0){ $ck = 'checked="checked"';  }
                                    else if(!isset($_GET['pt'])){ $ck = 'checked="checked"';  }
                           ?>
                          <input type="checkbox" onclick="chekMyTask();" id="MyTask"  <?php echo $ck ;?>>
                            <label>  View Personal Task </label>
                        </div>  
                </div>
                <form action="#" method="POST">
                <div class="col-md-2 col-sm-2">
                      <div class="">
                          <input onclick="chekExi();" type="checkbox" <?php if(isset($_GET['exi']) && !empty($_GET['exi'])) echo 'checked="checked"';  ?> id="sel_exi" placeholder="Enter title" required="required" class="" name="title">
                            <label>   Select Exhibition </label>
                        </div>  
                </div>
                 
                <div class="col-md-4 col-sm-4">
                      <div class=" " <?php if(!isset($_GET['exi'])) echo 'style="display: none !important;"';  ?> id="exhibition_select" >
                          <select  class="chosen-select col-md-4 col-sm-4 " name="exhibition" required="required" onchange="exiChange();" id="exi_val">
                                <option value=""> Select Exhibition </option>
                                <option value="all" <?php if(isset($_GET['exi']) && $_GET['exi']== 'all' ) echo 'selected="selected"';  ?> > All Exhibition </option>
                                <?php foreach($event_all as $event){?>
                                <option <?php if(isset($_GET['exi']) && $_GET['exi']== $event['event_id'] ) echo 'selected="selected"';  ?> value="<?= $event['event_id']; ?>"><?php echo $event['event_name']; ?></option>
                                <?php } ?>
                            </select>
                      </div>
                    
                    
                </div>
                </form>
                 
                <div class="col-md-2 col-sm-2">
                    <a data-toggle="modal" data-target="#newFullEvent" style="cursor: pointer;" class="btn btn-primary btn-o add-event">
                	 <i class="fa fa-plus"></i>Add New  Task</a>
                </div>
            </div>
        </div>
    
    
      <ol class="breadcrumb white">
        <li><a href="dashboard.php">Dashboard</a></li>
        <li><a href="my_tasks.php">Tasks</a></li>
        <li class="active">Tasks Calendar</li>
    </ol>
    
    
    
</div> 


 	<div class="col-sm-12 ev_calendar" style="padding:0;">
		<!-- start: CALENDAR -->
		<div class="container-fluid container-fullw bg-white">
                    <div class="row">
                        <div class="col-sm-12"> 
                            <div id='calendar'></div>
                        </div>
                    </div>
                </div>
		<!-- end: CALENDAR -->
                
        <!-- start: EVENTS ASIDE -->
<div class="modal fade modal-aside horizontal right events-modal"  id="newFullEvent" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog modal-sm">
        <div class="modal-content">
            <form class="form-full-event" action="#" method="POST">
                <div class="modal-body"> 
                <div class="form-group">
                    <label>  Task Title </label>
                    <input type="text" id="title" placeholder="Enter title" required="required" class="form-control underline text-large" name="title">
                </div>
                <div class="form-group">
                        <label> Description </label>
                        <span class="input-icon">
                            <textarea class="form-control"  name="descp"></textarea>
                        </span>
                </div>
                    
                <div class="form-group">
                        <label> Start Date</label>
                        <span class="input-icon">
                        <input type="text" autocomplete="off" onkeydown="return false;" id="start_date1" class="form-control underline  date calendar_icons" required="required" name="eventStartDate"/>
                        <i class="ti-calendar"></i> </span>
                </div>
                <div class="form-group">
                        <label> End Date </label>
                        <span class="input-icon">
                            <input type="text"  autocomplete="off" onkeydown="return false;" id="end_date1" class="form-control date underline calendar_icon" required="required" name="eventEndDate" />
                            <i class="ti-calendar"></i> </span>
                </div>

               <div class="form-group">
				 <label>  Exhibition/Reference </label>
                    <input type="text" id="title" placeholder="Enter Exhibition/Reference"  class="form-control underline text-large" name="exhibition">
                </div>
            </div>
            <div class="modal-footer"> 
                <input type="submit" name="task_submit" class="btn btn-primary btn-o save-event" value="Save" >
            </div>
            </form>
        </div>
</div>
</div>
        <!-- ends: EVENTS ASIDE -->
        </div>



<?php 
/*        echo "<pre>";
        print_r($_SESSION);
        echo '</pre>';
   */     

function rand_color() {
    return sprintf('#%06X', mt_rand(0, 0xFFFFFF));
}


?>
  	 

<?php include("_includes/footer.php"); ?>
<script src="js/calendar_moment.min.js"></script>
<script src="js/fullcalendar.min.js"></script>
  <script src="https://code.jquery.com/ui/1.14.1/jquery-ui.js"></script>
<script src="js/calendar-datetimepicker.min.js"></script>
<script src="js/pages-calendar.js"></script>
<script>
jQuery(document).ready(function() {
     
	  
         $("#start_date1").datepicker({
            dateFormat: 'yy-mm-dd',
            numberOfMonths: 1,
            onSelect: function(selected) {
              $("#end_date1").datepicker("option","minDate", selected)
            }
        });
        $("#end_date1").datepicker({
            dateFormat: 'yy-mm-dd',
            numberOfMonths: 1,
            onSelect: function(selected) {
               // $("#start_date1").datepicker("option","maxDate", selected)
            }
        });   


        
        $('#calendar').fullCalendar({
			header: {
				left: 'prev,next today',
				center: 'title',
				right: ''
			},
			 defaultDate: '<?php echo date("Y-m-d")?>',
			editable: false,
			eventLimit: true, // allow "more" link when too many events
			events: [
                            <?php 
                            
                                    foreach($tasks_all as $tsk){
                                        //print_r($tsk);
                                        echo "{
                                                title: '".$tsk["title"]."',
                                                start: '".$tsk["start_date"]." ',
                                                end: '".$tsk["end_date"]." 24:00:00 ',
                                                color: '".rand_color()."'
                                            },";
                                    }
                                    
                                    foreach($exi_task_list as $tsk_2){
                                        //print_r($tsk);
                                        echo "{
                                                title: '".$tsk_2["title"]."',
                                                start: '".$tsk_2["start_date"]." ',
                                                end: '".$tsk_2["end_date"]." 24:00:00',
                                                color: '".rand_color()."'
                                            },";
                                    }//'#3c763d'
                                    
                                    
                                            
                                            
                                            
                            ?>
			]
		});
});

function chekExi(){
         
        if($('#sel_exi').prop('checked') === true){
            $("#exhibition_select").css('display','block');
            
        }else{
            $("#exhibition_select").css('display','none');
            window.location= 'task_calender.php';
        } 
}

function exiChange(){
        vvv  = $("#exi_val").val();
        
        if($('#MyTask').prop('checked') === true && vvv!=''){
                window.location= 'task_calender.php?exi='+vvv+"&pt=1";
            }else if(vvv!=''){
                window.location= 'task_calender.php?exi='+vvv+"&pt=0";
            }
}



function chekMyTask(){
        vvv  = $("#exi_val").val();

        if($('#MyTask').prop('checked') === true){
             if($('#sel_exi').prop('checked') === true && vvv!=''){
                window.location= 'task_calender.php?exi='+vvv+"&pt=1";
            }
            
            
        }else{
            
            if($('#sel_exi').prop('checked') === true && vvv!=''){
                window.location= 'task_calender.php?exi='+vvv+"&pt=0";
            }
        
            /*$("#exhibition_select").css('display','none');
            window.location= 'task_calender.php';*/
        } 
}



//$('.date').datepicker(); 

</script>  
