<?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;}
    .pendinggg{}
    .processss td{background-color:#FDF704 !important; border-bottom: 1px solid #999;}
    .completeee td{background-color:#BBEF7E !important; border-bottom: 1px solid #999;}
.dropdown-menu { min-width: 100px !important;}

.table-responsive{     overflow-x: visible; }



</style>
<?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='my_tasks.php'</script>"; 
       die();
}

$event_all      = $obj_events_class->getEvent();   
       
       if(isset($_GET['st']) && isset($_GET['id']) ){
            $id     = base64_decode($_GET['id']);
            $status = base64_decode($_GET['st']);
            
            $obj_jobs_class->updateAgentTasks($id, $status);
          
            
            echo "<script>window.location='my_tasks.php'</script>";
            die();
       }
       
       
        if(isset($_GET['del'])){
            $id     = base64_decode($_GET['del']);
            $obj_jobs_class->deleteAgentTasks($id);
          
            
            echo "<script>window.location='my_tasks.php'</script>";
            die();
       }
       
       
       
       
       $tasks_all      = $obj_jobs_class->getAgentTasks($agent_id);
       
       /*echo '<pre>';
       print_r($tasks_all);
       echo '</pre>';*/
       
?>
<div class="col-sm-12 right_form">
        <div class="title">
            <div class="row">
                <div class="col-md-10 col-sm-12">
                    <h1>Tasks</h1>
                </div>
                
                  <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 class="active">Tasks  </li>
    </ol>
    
    
    
</div> 

<?php 
/*        echo "<pre>";
        print_r($_SESSION);
        echo '</pre>';
   */     
?>
  	<div class="col-sm-12 form_inner">
			<div class="col-md-12 table_inner" style="padding:0;">
                <div class="table-responsive" style="min-height: 300px;">
                    <table id="example" class="display nowrap lisitng_table" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                            	<th >Sr. </th>
                                <th>Task Title</th>
                                <th>Start Date</th>
                                <th>End Date</th>
                                <th>Exhibition</th>
                                <th style="width:30%;">Description</th>
                                <th>Status</th>
                                <th>Modify</th>
                                <th></th>
                                
                            </tr>
                        </thead>
                        <tbody>
                        <?php $i=1; foreach($tasks_all as $task){ 
                            if($task['status']=='1'){$cc= 'processss';}
                            else if($task['status']=='2'){$cc= 'completeee';}
                            else { $cc= ''; }
                            ?>    
                            <tr  class="<?= $cc ?>">
                        <td><?php echo $i++;?></td>
                        <td style="word-wrap: break-word !important; white-space: normal; max-width: 250px !important; " >
                            <?php echo $task['title']?> </td>
                        <td><?php echo $task['start_date']?></td>
                        <td><?php echo $task['end_date']?></td>
                        <td><?php echo $task['exhibition']?></td>
                        <td style="word-wrap: break-word !important; white-space: normal; max-width: 350px !important; ">
                            <?php echo $task['description']?></td>
                        <td>    <?php   $task['status']; ?> 
                        <?php 
                                if($task['status']=='0') echo 'Pending'; 
                                else if($task['status']=='1') echo 'Process'; 
                                else if($task['status']=='2') echo 'Complete'; 
                        ?>
                        
                        
                        </td>
                        <td> 
                            <div class="dropdown">
                                <button data-toggle="dropdown" class="btn btn-default dropdown-toggle" aria-haspopup="true" aria-expanded="false">
                                    Action <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
                                    <li><a href="my_tasks.php?id=<?php echo base64_encode($task['id']) ?>&st=<?php echo base64_encode('0') ?>">Pending</a></li>
                                    <li><a href="my_tasks.php?id=<?php echo base64_encode($task['id']) ?>&st=<?php echo base64_encode('1') ?>">Process</a></li>
                                    <li><a href="my_tasks.php?id=<?php echo base64_encode($task['id']) ?>&st=<?php echo base64_encode('2') ?>">Complete</a></li>
                                </ul>
                            </div>
                        </td>
                        <td>
                            
                            <a href="my_tasks.php?del=<?php echo base64_encode($task['id']) ?>" style="font-size: 30px;" onclick="return window.confirm('Are you sure you want to delete?');" >
                                <i class="fa fa-times-circle"></i>
                            </a> 
                            
                        </td>
                      
                    </tr>
                        <?php  } ?> 
                        </tbody>
                    </table>
                </div>
            </div>
		</div>

<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>




<?php include("_includes/footer.php"); ?>
<script>
$(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)
            }
        });   
        
        
    
    $('.dropdown-toggle').dropdown()
    
    
    $('#example').DataTable()
    
        
/*        {
        responsive: {
            details: {
                type: 'column',
                target: -1
            }
        },
        columnDefs: [ {
            className: 'control',
            orderable: false,
            targets:   -1
        }]
    });*/
});
</script>