<?php include("_config/dbconfig.php"); ?>
<?php include("_includes/head.php");?>
<title>Assign Client Step 3</title>

<?php include("_includes/header.php"); 

$taskList =  $obj_jobs_class->getAssignStep3Tasks();
if(isset($_SESSION['user_session'])){
$agent_id = $_SESSION['user_session'];
} 

$ee = explode("/", $_SERVER["PHP_SELF"]); 
$link  =  end($ee).'?'.$_SERVER["QUERY_STRING"] ;
 

if(isset($_POST['task_date_submit'])){ 
    
    $task_id    = $_POST['task'];
    $last_date  = $_POST['date'];
    $event_id   = base64_decode($_GET['event']); 
    $obj_jobs_class->addAssignStep3TaskDate($event_id, $task_id, $last_date, $agent_id);
    
    echo "<script>window.location='".$link."'</script>";
    die();
} 
/*echo "<pre>";
print_r($dates_list);
echo "</pre>";
*/
if(isset($_GET['event']) && !empty($_GET['event'])){
    
    $event_id = base64_decode($_GET['event']); 
    $ApprovedClients= $obj_jobs_class->getApprovedAssignClients($event_id, $agent_id);    
    $event = $obj_events_class->getEvent($event_id);
    
    $dates_list = $obj_jobs_class->getAssignStep3TasksDates($event_id);
    
}
 
/*echo "<pre>";
print_r($ApprovedClients);
echo "</pre>";*/
     
?>
 <style type="text/css">
.boxscroll {
	height: 500px;
	border: 0px solid #000;
	overflow: auto;
}

</style>     
  <div class="col-sm-12 right_form">
        <div class="title">
                
                    <h1><?php echo $event['event_name'];?>
                    
                    
                    <p class="date_d">
                        <?php 
                        if(!empty($event['start_date']))
                        echo $obj_jobs_class->change_date2($event['start_date']);
                        
                        if(!empty($event['end_date']))
                        echo ' to '.$obj_jobs_class->change_date2( $event['end_date']); ?> 
                    
                    </p>
                    </h1>
                
        </div>
         
    <ol class="breadcrumb white">
          <li><a href="dashboard.php">Dashboard</a></li>
          <li><a href="events.php">Exhibitions</a></li>
          <li class="active">Assign Client Step 3</li>
    </ol>
      
    	<div class="col-sm-12 form_inner eventask">
            <div class="row">
                <form action="#" method="POST" >
                	<div class="col-sm-3 col-xs-4 form-group">
                            <select data-placeholder="Select Subject" class="chosen-select form-control" style="width:100%;" tabindex="2" name="task" required="required">
                                <?php foreach($taskList as $tl){?>
                                <option value="<?php echo $tl['id'];?>"><?php echo $tl['task'];?></option>
                                <?php } ?>
                            </select>
                    </div>
                    <div class="col-sm-3 col-xs-4 form-group">
                    	<div class="date_calendar">
                            <input class="form-control txt_field date calendar_icon" name="date" id="#basic_example_1" type="text" placeholder="Date" required="required">
                    	</div>
                    </div>
                    <div class="col-sm-3 col-xs-4 form-group">
                        <button type="submit" class="btn" name="task_date_submit">Submit</button>
                    </div>
                    
                    <div class="col-md-3 col-sm-12"> 
                        <a href="send_sms_step3.php?event=<?php echo $_GET['event']?>" style="cursor: pointer; float: right;" class="btn btn-primary btn-o  ">
                	 Send SMS</a>
                    </div> 
                    
                </form>
			</div>            
			<div class="col-md-12 table_inner" style="padding:0;">
                <div class="table-responsive boxscroll">
                    <table id="example" class="display nowrap lisitng_table table" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                            	<th class="c-name">Company Name</th>
                                
                                <?php $date_td='';
                                      foreach($dates_list as $dll){
                                          if(is_array($dll['last_date'])){
                                          $llss = implode("<br>", $dll['last_date']);}
                                          else { $llss = ''; }
                                          ?>
                                        <th><?php echo $dll['task']; ?></th>
                                <?php  $date_td .= '<td>'.$llss.'</td>'; 
                                    } ?>
                                        <th class="status-row">Status</th>
                            </tr>
                            
                        </thead>
                        <tbody>
                        	<tr class="date">
                            	<td class="c-name">Date</td>
                        	<?php echo $date_td; ?>
                                <td></td>
                        	</tr>
                                
                            
                                
                <?php foreach ($ApprovedClients as $ApCl){?>    
                    <tr>
                        <td class="c-name" ><?php echo $ApCl['company_name']?></td>
                        <?php foreach($ApCl['tasks'] as $ttask){
                            if(isset($ttask['task_status']) && $ttask['task_status'] == 1){
                        ?> 
                    <td id="row_<?= $ApCl['client_id'] ?>_<?= $ttask['task_id'] ?>_">
                    <input type="checkbox" name="" value="1" onclick="setStatus(<?= $event_id ?>,  <?= $ApCl['client_id'] ?>,  <?= $agent_id ?>, <?= $ttask['task_id'] ?>, 'remove');" checked="checked">
                      <!--  <i class="fa fa-check"></i>-->
                    </td>
                        <?php  }else {?>
                    <td id="row_<?= $ApCl['client_id'] ?>_<?= $ttask['task_id'] ?>_">
                        <input type="checkbox" name="" value="1" onclick="setStatus(<?= $event_id ?>,  <?= $ApCl['client_id'] ?>,  <?= $agent_id ?>, <?= $ttask['task_id'] ?>, 'add');">
                    </td>
                    
                            <?php }
                            ?>
                        <?php } ?>
                    <td class="status-row">
                        <?php $width = $obj_jobs_class->getStep3TasksPercent($event_id, $ApCl['client_id'], $agent_id)?>
                        <div class="progress-box" id="status_<?= $ApCl['client_id'] ?>_">
                            <div class="progress-box-innr" style="width:<?= $width; ?>%" > </div>
                            <span><?= $width ?>%</span>
                        </div>
                        
                    </td>
                    </tr>
                            
                        <?php } ?>
                                
                        </tbody>
    				</table>
                </div>
            </div>
		</div>
    </div>


<?php include("_includes/footer.php"); ?>
<script>

	$( document ).ready(function() {
		
	<!-- Date Picker  -->
	
	   $('.date').datepicker(); 
		$('.date').on('change',function(){
		   var index=$('.date') .index(this);
		   $('.date:eq('+index+')').val();
			
		});
		
	<!-- Select Option Chosen  -->
		var config = {
		  '.chosen-select'           : {},
		  '.chosen-select-deselect'  : {allow_single_deselect:true},
		  '.chosen-select-no-single' : {disable_search_threshold:10},
		  '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
		  '.chosen-select-width'     : {width:"95%"}
		}
		for (var selector in config) {
		  $(selector).chosen(config[selector]);
		}
    });
    
function setStatus(event, client, agent, task, stat){
       
        var url = 'ajax.php?task=add_step3Task&event='+event+'&client='+client+'&agent='+agent+'&task_id='+task+'&stat='+stat+'&1=1';
        /*$.post('ajax.php?task=add_step3Task&event='+event+'&client='+client+'&agent='+agent+'&task_id='+task+'&stat='+stat+'&1=1', function(data){
                console.log(data);
                //if(data=='1'){     location.reload();  }
        })*/
        
           $.ajax({
              type: "POST",
              url: url,
              data: 'id', // serializes the form's elements.
              success: function(data){
                  //console.log(data);
                   {
                     $("#status_"+client+"_").html('<div class="progress-box-innr" style="width:'+data+'%"> </div><span>'+data+'%</span>')
                   //  $("#row_"+client+"_"+task+"_").html('<i class="fa fa-check"></i>');
                     
                  }
              }
            });
            
            
            
        
        
}



</script>
