<?php include("_config/dbconfig.php");
// error_reporting(-1);
?>
<div class="dashboard_view"> 
<?php include("_includes/head.php");?>
<title>Dashboard</title>
<?php include("_includes/header.php"); 

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

$exhibitions    = $obj_jobs_class->getDashboardEvents();
$tasks_all      = $obj_jobs_class->getEventTasks('','', $agent_id,1);
$mytasks        = $obj_jobs_class->getAgentTasks($agent_id,1);

/*echo "<br><br><br><br><pre>";
print_r($exhibitions);
echo '</pre>';    */
//echo "<br><br><br><br><pre>";
//$mytasks = $obj_jobs_class->getNotifications();

?>
<style>
    .lisitng_table.first_small td:first-child {
       width: 0.5%;
    }
    .media-heading{ display:inline-block; font-weight: 600; font-size: 12px;}
</style>

<div class="col-sm-12  " style="margin-top: 100px;">
    <?php  
            if($_SESSION['user_role_session']=="Admin"){
               
                $mytasks = $obj_jobs_class->getNotifications(); 
                ?>
    
    
      <div class="col-sm-6 ">
          <div class="dashboard_box">
          <h3> Exhibitions <a href="events.php" style="font-size: 13px; ">  <i class="fa fa-list-ul"></i>  </a> </h3>  
          <table class="lisitng_table table first_small">
              <thead>
                  <tr><th>Sr.</th>
                      <th width="20%" >Exhibition Name</th>
                      <th>Start Date</th> 
                      <th> </th>
                      <th>View Clients</th> 
                  </tr>
              </thead>
              <tbody>
                  <?php
                  if(count($exhibitions)>0){
                  $sr=1;
                  foreach($exhibitions as $exi){ 
                      ?>
                  <tr id="<?php echo $exi['event_id']; ?>_row" class="none_bg">
                      <td><?php echo $sr++;?></td>
                      <td><?php echo $exi['event_name']; 
                            
                      ?>
                      </td>
                      <td><?php
                            if(!empty($exi['start_date'])){
                                echo  $obj_jobs_class->change_date2($exi['start_date']); 
                            }?>
                      </td>
                      <td>
                          <a href="assign_client_step2.php?event=<?php echo base64_encode($exi['event_id']); ?>">Step 2</a> &nbsp;|&nbsp;
                          <a href="assign_client_step3.php?event=<?php echo base64_encode($exi['event_id']); ?>">Step 3</a>
                      </td>
                      <td style="text-align: center;">
                          <a style="font-size: 13px;cursor: pointer; text-align: center;  " onclick=" viewClients('<?php echo  $exi['event_id']?>');"> 
                              <i class="fa fa-list-ul"></i>  </a>
                      </td>
                      
                  </tr>
                  <?php } }else{ echo " No task found. "; } ?> 
                  <tr>
                      <td></td><td></td><td></td><td></td><td></td>
                  </tr>
              </tbody>
          </table>
          </div>
        </div>
      
      <div class="col-sm-6 ">
          <div class="dashboard_box" id="ap_Client">
              
          </table>
          </div>
           
        </div>
    
    
        <?php } elseif($_SESSION['user_role_session']=="Agent"){
            
                  $exhibitions    = $obj_events_class->getAgetEvent($agent_id,"Active");
            ?>
    
    <div class="col-sm-4 ">
          <div class="dashboard_box">
          <h3> Exhibitions <a href="events.php" style="font-size: 13px; ">  <i class="fa fa-list-ul"></i>  </a> </h3> 
          <table class="lisitng_table table first_small">
              <thead>
                  <tr><th>Sr.</th>
                      <th>Company Name</th>
                      <th></th>
                  </tr>
              </thead>
              <tbody>
                  <?php
                  if(count($exhibitions)>0){
                  $sr=1;
                  foreach($exhibitions as $exi){ ?>
                  <tr>
                      <td><?php echo $sr++;?></td>
                      <td><?php echo $exi['event_name']; ?></td>
                      <td class="small_step">
                            <a href="assign_client.php?event=<?php echo base64_encode($exi['event_id']); ?>">Step 1</a> &nbsp;|&nbsp;
                            <a href="assign_client_step2.php?event=<?php echo base64_encode($exi['event_id']); ?>">Step 2</a> &nbsp;|&nbsp;
                            <a href="assign_client_step3.php?event=<?php echo base64_encode($exi['event_id']); ?>">Step 3</a>
                      </td>
                  </tr>
                  <?php } }else{ echo " No task found. "; } ?> 
                  <tr>
                      <td></td><td></td><td></td>
                  </tr>
              </tbody>
          </table>
          </div>
        </div>
    
      <div class="col-sm-4">
          <div class="dashboard_box">
          <h3> Exhibitions Tasks <a href="event_tasks.php" style="font-size: 13px; ">  <i class="fa fa-list-ul"></i>  </a> </h3>
          <table class="lisitng_table table first_small">
              <thead>
                  <tr><th>Sr.</th>
                      <th style="width:25%;">Task Title</th>
                       <th>Days Left</th>
                      <th style="width:10%;">Start Date </th>
                  </tr>
              </thead>
              <tbody>
                 <?php  $color = '';
                        if(count($tasks_all)>0){
                        $i=1; foreach($tasks_all as $task){  ?>
                        <tr>
                            <td><?php echo $i++; ?></td>
                            <td><?php echo $task['title']; ?>     </td>
                            <td>
                                <?php 
                                 if(!empty($exi['start_date'])){
                                  $today = date("Y-m-d");
                                  $today = date( "Y-m-d H:i:s", strtotime($today)-3*3600 );
                                  $datetime1 = new DateTime($today);
                                  $datetime2 = new DateTime($task['end_date']);
                                  $interval = $datetime1->diff($datetime2);
                                   $days = $interval->format('%R%a');
                                       if($days > 0){
                                            echo  str_replace('+', '', $days);
                                            $color = "";
                                       }else {
                                           echo "<span  style='color:red;'>".str_replace('-', '', $days)." due</span>";
                                           $color = "#FFAAAA";
                                       }
                                       
                                       if(isset($days) && $days <= 0){
                                            
                                       }else { }
                                       /*else if(isset($days) && $days <= 5 ){
                                           $color = "#AACCFF";
                                       }
                                       else if(isset($days) && $days <= 8){
                                           $color = "#FDF704";
                                       }*/
                                       
                                 }
                                 ?> 
                            </td>
                            <td bgcolor="<?= $color ?>"><?php echo $obj_jobs_class->change_date4($task['start_date']);?>/<?php echo $obj_jobs_class->change_date4($task['end_date']);?></td> 
                        </tr>
                        <?php } }else{ echo " No task found. "; } ?> 
                  <tr>
                      <td></td><td></td> <td></td> <td></td> 
                  </tr>
              </tbody>
          </table>
           </div>
      </div>
      
    
      <div class="col-sm-4">
          <div class="dashboard_box">
          <h3> Personal Tasks
          <a href="my_tasks.php" style="font-size: 13px; ">  <i class="fa fa-list-ul"></i>  </a> 
          </h3>
          
          <table class="lisitng_table table first_small">
            <thead>
                <tr><th>Sr.</th>
                    <th style="width:25%;">Task Title</th>
                    <th>Days Left</th>
                    <th style="width:10%;">Start Date </th> 
                </tr> 
            </thead>
            <tbody>
                  
            <?php 
                if(count($mytasks)>0){
                $i=1; foreach($mytasks as $task){ ?>
                <tr>
                    <td><?php echo $i++;?></td>
                    <td><?php echo $task['title']?>    </td>
                    <td>
                     <?php 
                                 if(!empty($task['start_date'])){
                                  $today = date("Y-m-d");
                                  $today = date( "Y-m-d H:i:s", strtotime($today)-3*3600 );                                  
                                  $datetime1 = new DateTime($today);                                  
                                  $datetime2 = new DateTime($task['end_date']);
                                  $interval = $datetime1->diff($datetime2);
                                  $days = $interval->format('%R%a');
                                       if($days > 0){
                                           echo  str_replace('+', '', $days);
                                           $color1 = "";
                                       }else {
                                           echo "<span  style='color:red;'>".str_replace('-', '', $days)." due</span>";
                                           $color1 = "#FFAAAA";
                                       }

                                       if(isset($days) && $days <= 1){
                                            
                                       }
                                       /*else if(isset($days) && $days <= 5 ){
                                           $color1 = "#AACCFF";
                                       }
                                       else if(isset($days) && $days <= 8){
                                           $color1 = "#FDF704";
                                       }*/
                                 }
                                 ?> 
                    
                    </td>
                    <td bgcolor="<?= $color1 ?>"><?php 
                    if(!empty($task['start_date']))?>
					<?php echo $obj_jobs_class->change_date4($task['start_date']);?>/<?php echo $obj_jobs_class->change_date4($task['end_date']);?></td> 
                      
                    </tr>
            <?php  }
                }else {   echo " No task found. ";    }    ?>   
                  <tr>
                      <td></td><td></td> <td></td> <td></td> 
                  </tr>
              </tbody>
        </table>
          
        </div>
          
      </div>
      <?php }?>
      
      <!--
    	<div class="col-sm-12 form_inner dashboard_page">
        	<div class="container dashboard_wrapper">
            	<div class="col-sm-3">
                	<div class="category_box">
                    	<div class="title_cat">
                        	<h3>Category</h3>
                        </div>
                        <div class="box_body">
                        	<i class="fa fa-th"></i>
                        </div>
                        <div class="box_footer">
                        	<a href="category_controls.php">Create New</a>
                                <a href="categories.php">Category List</a>
                        </div>
                    </div>
                </div>
                <div class="col-sm-3">
                	<div class="category_box">
                    	<div class="title_cat">
                        	<h3>Exhibition</h3>
                        </div>
                        <div class="box_body">
                        	<i class="fa fa-flag-checkered"></i>
                        </div>
                        <div class="box_footer">
                            <a href="event_controls.php">Add New</a>
                            <a href="events.php">All Exhibitions</a>
                        </div>
                    </div>
                </div>
                    
                <?php if($_SESSION['user_role_session']== 'Admin'){ ?>    
                        <div class="col-sm-3">
                                <div class="category_box">
                                <div class="title_cat">
                                        <h3>Agent</h3>
                                </div>
                                <div class="box_body">
                                        <i class="fa fa-user-secret"></i>
                                </div>
                                <div class="box_footer">
                                    <a href="agent_controls.php">Add New</a>
                                    <a href="agents.php">View List</a>
                                </div>
                            </div>
                        </div>
                <?php } ?>    
                    
                <div class="col-sm-3">
                	<div class="category_box">
                    	<div class="title_cat">
                        	<h3>Client</h3>
                        </div>
                        <div class="box_body">
                        	<i class="fa fa-user"></i>
                        </div>
                        <div class="box_footer">
                            <a href="client_controls.php">Add New</a>
                            <a href="clients.php">View All Clients</a>
                        </div>
                    </div>
                </div>
            </div>
		</div>
      
      
      
      
      -->
    </div>


<?php include("_includes/footer.php"); ?>
</div>
<script> 
    
function viewClients(id){ 
        var url = "ajax.php?task=getClientNameDash&event_id="+id+'&1=1'; 
        $.ajax({
              type: "POST",
              url: url,
              //data: 'id', // serializes the form's elements.
              success: function(data){ 
                  $("#ap_Client").html(data);
                  $(".none_bg").css("background", "none");
                  $("#"+id+"_row").css("background-color", "#BBEF7E");
                  
                  
                  
               //  alert(data);
              }
            });
        }
        
          <?php if(count($exhibitions)>0){?>
                  viewClients('<?php echo  $exhibitions[0]['event_id']?>');
          <?php } ?>
              
              
</script>