<?php include("_config/dbconfig.php"); ?>
<?php include("_includes/head.php");?>
<title>Assigning</title>

<style>
    .table-bordered > thead > tr > th, .table-bordered > thead > tr > td, .table-bordered  tr  td {
        border-width: 1px !important; 
        //border: 1px solid #676767 !important;
} 
</style>


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

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

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


if(isset($_POST['deniedReason'])){
    
    $assign_id = $_POST['assign_id'];
    $reason_id = $_POST['reason'];
     
    $obj_jobs_class->updateDeniedReasonsClient($assign_id,$reason_id);
    $obj_jobs_class->updateClientsAssign($assign_id, 'deny', '0');
       
    echo "<script>window.location='".$link."'</script>";
    die();
}



if(isset($_POST['AddTaskSubmit'])){
    
    $task_title = $_POST['title_task'];
    $assign_id = $_POST['assign_id'];
    $event_id = $_POST['event_id'];
    $client_id = $_POST['client_id'];
    $start_date = $_POST['start_date'];
    $end_date = $_POST['end_date'];
    $contact_person = $_POST['contact_person'];

    $obj_jobs_class->addEventTask($assign_id, $event_id, $client_id, $task_title, $start_date, $end_date, $contact_person, $agent_id);
    
    echo "<script>window.location='".$link."'</script>";
    die();
}

if(isset($_POST['CommentSubmit'])){

    //echo '<pre>'; print_r($_POST); echo '</pre>'; 
    $assign_id = $_POST['assign_id'];
    $event_id = $_POST['event_id'];
    $client_id = $_POST['client_id'];
    $comments  = $_POST['comments'];
    
    $obj_jobs_class->addEventComment($assign_id, $event_id, $client_id, $comments, $agent_id);
    
    echo "<script>window.location='".$link."'</script>";
    die();
}



if(isset($_POST['delete_now'])){ 

    if(count($_POST['select'])>0)
    $sel_event = base64_decode($_GET['event']);
    foreach($_POST['select'] as $client_list){
        $obj_jobs_class->removeAssignClients($sel_event, $client_list,$agent_id);
    }
      
   echo "<script>window.location='".$link."'</script>";
  die();
}


if(isset($_POST['submit_now'])){
    
    $sel_event = base64_decode($_GET['event']);
    "<script>window.location='".$link."'</script>";
    //die();
}
         
if(isset($_GET['event']) && !empty($_GET['event'])){
    
    $exhibition_id = base64_decode($_GET['event']); 
    $event = $obj_events_class->getEvent($exhibition_id);
    $AssignClients =  $obj_jobs_class->getAssignClients($exhibition_id, $agent_id);
    
    $DeniedReasons =  $obj_jobs_class->getDeniedReasons();
    
    /*echo '<pre>';
    print_r($AssignClients);
    echo '</pre>';   */
}
else {
    
     echo "<script>window.location='events_marketing.php'</script>";
     die();
}

$modal = '';
$select_status ="";

 if(isset($_GET['st'])){
     $select_status = $_GET['st'];
 }
         
         
?>

      
<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_marketing.php">Exhibitions</a></li>
          <li class="active">Assigned Clients</li>
          <li class="right"><a href="event_graph.php?event=<?php echo $_GET['event']?>">View Graph</a></li>
    </ol>
     
    
<div class="col-sm-12 a_client">
     
    <div class="row">
      <div class="col-sm-12">
          
      <div class="table-result table-responsive">  
          
          <form action="" method="GET" id="_form">
                
                <div class="col-sm-2 col-xs-2 form-group">
                    <label>Select Status </label>                    
                </div>
                <div class="col-sm-3 col-xs-4 form-group">
                  <select class="chosen-select form-control"   id="exi_id" tabindex="-1" name="event" required="required" onchange="goEvent();">
                        <option value="">---Select---</option> 
                        <option value="all" <?php if($select_status=="all") echo 'selected="selected"'; ?> >All </option> 
                        <option value="1" <?php if($select_status=="1") echo 'selected="selected"'; ?>>Accepted </option> 
                        <option value="2" <?php if($select_status=="2") echo 'selected="selected"'; ?>>Pending</option> 
                        <option value="0" <?php if($select_status=="0") echo 'selected="selected"'; ?>>Denied</option> 
                        <option value="80" <?php if($select_status=="80") echo 'selected="selected"'; ?>>Hot</option>
                        <option value="50" <?php if($select_status=="50") echo 'selected="selected"'; ?>>Warm </option>
                        <option value="10" <?php if($select_status=="10") echo 'selected="selected"'; ?>>Cold </option> 
                    </select> 
                </div>
            </form>
          
          
          

          <form action="<?php echo $link;?>" method="POST" id="assignForm">

		<table class="table table-bordered">
                    <thead>
                            <tr>
                            	<th>Sr. </th>
                                <th>Company Name </th>
				<th style="width:300px;">Contact Persons </th>
                                <th class='center-align' style="line-height:10px;">Mobile No. </th> 
                                <th class='center-align' style="line-height:10px;">Email </th>
                                  
                                <th class='center-align'> Status </th>
                            </tr>
                        </thead>
                	<tbody>
                        
<?php $i =1; foreach($AssignClients as $a_client){
    
        $row_color = '';
        $assign_id = $a_client['assign_id'];
        $assign_CallSMSEmail = $obj_jobs_class->getClientsAssignDetails($a_client['assign_id']);
        if($a_client['status_order'] == 1){$row_color = 'style="background-color:#BBEF7E;"';}
        else if($a_client['status_order'] ==  0){$row_color = 'style="background-color:#FFAAAA"';}
        else if($a_client['status_order'] ==  4){$row_color = 'style="background-color:#FDF704"';}
        

        
   if(isset($_GET['st']) && ($a_client['status_order'] == $_GET['st'] ||$a_client['pipeline'] == $_GET['st'])  ){     ?>
                            
<tr <?=$row_color?>>
    <td><?= $i++ ?></td>
    
    <td><?php echo $a_client['company_name'] ?> </td>
    
    <td><?php if(count($a_client['persons'])>0){
                foreach($a_client['persons'] as $ac_person){
                        echo $ac_person['f_name'].' '.$ac_person['l_name'].'('.$ac_person['designation'].') / ';
                }
        ?>
            <a data-toggle="modal" data-target="#persons_<?= $a_client['client_id']?>" style="cursor: pointer;" href="#">
                <i class='fa fa-list-ul'></i>
            </a>
       <?php  } ?>
                                

<div id="persons_<?= $a_client['client_id']?>" class="modal fade left-align" role="dialog" >

  <div class="modal-dialog client-modal">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h4 class="modal-title">Contact Persons</h4>
      </div>
      <div class="modal-body">
	  
          <table style="table-layout: fixed; width: 100%" class="ttttt">
             <tbody><tr>
                 <td width="50%" style="border-top:none !important; "><small>Company: </small> <strong> <?php echo $a_client['company_name'] ?></strong> </td>
                <td width="50%" style="border-top:none !important; "><small>Owner's Name: </small> <strong> <?php echo $a_client['owner_name'] ?> </strong> </td>
            </tr>
             
            <tr>  <td width="50%"><br></td>
                  <td width="50%"> <br></td>
            </tr>
            
            
<?php if(count($a_client['persons'])>0){$per=1; 
        
        $person_mobile = '';  $person_email = '';
        foreach($a_client['persons'] as $ac_person){ ?> 
              
            <tr>
                <td colspan="2" width="100%" style="background-color: #eee;">  <strong>Contact Persons <?php echo $per++; ?></strong></td>
            </tr>
            
            <tr>
                <td width="50%"> <small>Name: </small> <strong> <?php echo $ac_person['f_name'].' '.$ac_person['l_name']; ?> </strong> </td>
                <td width="50%"><small>Designation: </small> <strong> <?php echo $ac_person['designation']; ?> </strong></td>
            </tr>
            <tr>
                <td width="50%" colspan="2"> <small>Email: </small> <strong>
                        <?php echo $ac_person['email']; $person_email .=$ac_person['email'].', ';  ?> </strong>
                </td>
            </tr>
            
            <tr>
                <td width="50%"><small>Mobile: </small> <strong>
                    <?php echo $ac_person['mobile']; $person_mobile .=  $ac_person['mobile'].', '; ?> </strong>
                </td>
                <td width="50%"> <small>Land Line: </small> <strong>  <?php echo $ac_person['landline']; ?> </strong> </td>
            </tr>
            <tr>
                <td width="50%" colspan="2"><small>Ext: </small> <strong> <?php echo $ac_person['line_ext']; ?> </strong></td>
            </tr>
            
<?php  }      }   ?>     
            
        </tbody></table>
        
      </div>
      
    </div>

  </div>
</div>
	         

       </td>
       <td class='center-align'>
    <?php 
           $person_mobile = trim($person_mobile);
           $person_mobile = substr($person_mobile, 0,  strlen($person_mobile)-1 ); 
           echo $person_mobile ;
           $person_mobile_all[] = $person_mobile;
           
    ?>
        </td>
        
        <td class='center-align'>
            <?php 
                   $person_email = trim($person_email);
                   $person_email = substr($person_email, 0,  strlen($person_email)-1 );
                   echo $person_email;
                   $person_email_all[] = $person_email;
            ?>
        </td>
          

        <td class='center-align' style="color:#000; font-size:13px;"> 
    <?php   
            if($a_client['status_order']==1) echo 'Accepted';
            else if($a_client['status_order']==0) echo 'Denied';
            else if($a_client['status_order']==2) echo 'Pending ';
    
            else if($a_client['status_order']==4){    ?>
            <?php if($a_client['pipeline']==80) echo ' Hot '; ?> 
            <?php if($a_client['pipeline']==50) echo 'Warm"'; ?> 
            <?php if($a_client['pipeline']==10) echo 'Cold'; ?>
        
    <?php } ?> 
        
</td>

            </tr>
            
        <?php } 
        
    elseif(!isset($_GET['st']) || $_GET['st']=="all") { ?>
                                   
<tr <?=$row_color?>>
    <td><?= $i++ ?></td>
    
    <td><?php echo $a_client['company_name'] ?> </td>
    
    <td><?php if(count($a_client['persons'])>0){
                foreach($a_client['persons'] as $ac_person){
                        echo $ac_person['f_name'].' '.$ac_person['l_name'].'('.$ac_person['designation'].') / ';
                }
        ?>
            <a data-toggle="modal" data-target="#persons_<?= $a_client['client_id']?>" style="cursor: pointer;" href="#">
                <i class='fa fa-list-ul'></i>
            </a>
       <?php  } ?>
                                

<div id="persons_<?= $a_client['client_id']?>" class="modal fade left-align" role="dialog" >

  <div class="modal-dialog client-modal">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h4 class="modal-title">Contact Persons</h4>
      </div>
      <div class="modal-body">
	  
          <table style="table-layout: fixed; width: 100%" class="ttttt">
             <tbody><tr>
                 <td width="50%" style="border-top:none !important; "><small>Company: </small> <strong> <?php echo $a_client['company_name'] ?></strong> </td>
                <td width="50%" style="border-top:none !important; "><small>Owner's Name: </small> <strong> <?php echo $a_client['owner_name'] ?> </strong> </td>
            </tr>
             
            <tr>  <td width="50%"><br></td>
                  <td width="50%"> <br></td>
            </tr>
            
            
<?php if(count($a_client['persons'])>0){$per=1; 
        
        $person_mobile = '';  $person_email = '';
        foreach($a_client['persons'] as $ac_person){ ?> 
              
            <tr>
                <td colspan="2" width="100%" style="background-color: #eee;">  <strong>Contact Persons <?php echo $per++; ?></strong></td>
            </tr>
            
            <tr>
                <td width="50%"> <small>Name: </small> <strong> <?php echo $ac_person['f_name'].' '.$ac_person['l_name']; ?> </strong> </td>
                <td width="50%"><small>Designation: </small> <strong> <?php echo $ac_person['designation']; ?> </strong></td>
            </tr>
            <tr>
                <td width="50%" colspan="2"> <small>Email: </small> <strong>
                        <?php echo $ac_person['email']; $person_email .=$ac_person['email'].', ';  ?> </strong>
                </td>
            </tr>
            
            <tr>
                <td width="50%"><small>Mobile: </small> <strong>
                    <?php echo $ac_person['mobile']; $person_mobile .=  $ac_person['mobile'].', '; ?> </strong>
                </td>
                <td width="50%"> <small>Land Line: </small> <strong>  <?php echo $ac_person['landline']; ?> </strong> </td>
            </tr>
            <tr>
                <td width="50%" colspan="2"><small>Ext: </small> <strong> <?php echo $ac_person['line_ext']; ?> </strong></td>
            </tr>
            
<?php  }      }   ?>     
            
        </tbody></table>
        
      </div>
      
    </div>

  </div>
</div>
	         

       </td>
       <td class='center-align'>
    <?php 
           $person_mobile = trim($person_mobile);
           $person_mobile = substr($person_mobile, 0,  strlen($person_mobile)-1 ); 
           echo $person_mobile ;
           $person_mobile_all[] = $person_mobile;
           
    ?>
        </td>
        
        <td class='center-align'>
            <?php 
                   $person_email = trim($person_email);
                   $person_email = substr($person_email, 0,  strlen($person_email)-1 );
                   echo $person_email;
                   $person_email_all[] = $person_email;
            ?>
        </td>
          

        <td class='center-align' style="color:#000; font-size:13px;"> 
    <?php   
            if($a_client['status_order']==1) echo 'Accepted';
            else if($a_client['status_order']==0) echo 'Denied';
            else if($a_client['status_order']==2) echo 'Pending ';
    
            else if($a_client['status_order']==4){    ?>
            <?php if($a_client['pipeline']==80) echo ' Hot '; ?> 
            <?php if($a_client['pipeline']==50) echo 'Warm"'; ?> 
            <?php if($a_client['pipeline']==10) echo 'Cold'; ?>
        
    <?php } ?> 
        
</td>

            </tr>
        
        <?php }            } ?>
        </tbody>
    </table> 
</form>  

               
<?php   
if(isset($person_mobile_all) && isset($person_email_all) ){
        $person_mobile_text = implode(", ", $person_mobile_all);
        $person_email_text = implode(", ", $person_email_all);
?>        
            <a data-toggle="modal" data-target="#persons_emails_all" class="btn btn-primary btn-o add-event" style="cursor: pointer; position: absolute; right: 200px; top: 10px;" href="#">
      View All Email
          </a>  
    <div id="persons_emails_all" class="modal fade left-align" role="dialog" >

  <div class="modal-dialog client-modal">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h4 class="modal-title">Contact Persons Emails</h4>
      </div>
      <div class="modal-body">
	  
          <table style="table-layout: fixed; width: 100%" class="ttttt">
             <tbody> 
             
            <tr>  <td width="50%"><br></td>
                  <td width="50%"> <br></td>
            </tr> 
                
            <tr>
                <td colspan="2"> 
                    <textarea class="form-control" rows="8" id="allEmail" readonly="readonly"><?php echo $person_email_text; ?></textarea>
                </td>
            </tr>
            
            <tr>
                <td width="50%">   </td>
                <td width="50%"></td>
            </tr>
            
          
            
              
              
        </tbody>
          
          </table>
        <br><br><br>
          
      </div>
      
    </div>

  </div>
</div>

          
    <a data-toggle="modal" data-target="#persons_mobile_all" class="btn btn-primary btn-o add-event" style="cursor: pointer; margin-right: 20px; position: absolute; right: 10px; top: 10px;" href="#">
        View All Mobile Nos.
    </a>
    <div id="persons_mobile_all" class="modal fade left-align" role="dialog" >

      <div class="modal-dialog client-modal"> 
        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">×</button>
            <h4 class="modal-title">Contact Persons Emails</h4>
          </div>
          <div class="modal-body"> 
              <table style="table-layout: fixed; width: 100%" class="ttttt">
                 <tbody>  
                <tr>  <td width="50%"><br></td>
                      <td width="50%"> <br></td>
                </tr>  
                <tr>
                    <td colspan="2"> 
                        <textarea class="form-control" rows="8" id="allEmail" readonly="readonly"><?php echo $person_mobile_text; ?></textarea>
                    </td>
                </tr> 
                <tr>
                    <td width="50%">   </td>
                    <td width="50%"></td>
                </tr> 
            </tbody> 
              </table>
            <br><br><br>
          </div>
        </div>
      </div>
    </div>
          
<?php }else {$person_mobile_text  = "";  $person_email_text = "";
        echo 'No client found.';
}

?>
           

      </div>
    </div>
</div>
</div>	
		
</div>


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

<script>
    
    function completeTask(id){
        $.post('ajax.php?id='+id+'&task=complete_task', function(data){
            console.log(data);
             if(data=='1'){
                     location.reload();
                  }
        })
    }




$(document).ready(function() {
//        $('#example').DataTable();
            $('#example').dataTable( {
                  "aoColumnDefs": [
                      { 'bSortable': false, 'aTargets': [ 1 ] }
                   ]
            });

        $('#CallAll').click(function(){
            
            console.log($(this).attr('checked'));
            if($(this).is(':checked')){
                $('input:checkbox.all_call').attr('checked',true);
                $('.all_call').css('display', 'none');
                $('.sellect_call').css('display', 'inline-block');
            }
            else{  
                $('input:checkbox.all_call').attr('checked',false);
                $('.sellect_call').css('display', 'none');    
                $('.all_call').css('display', 'inline-block')
            }
        });
        
        $('#SMSAll').click(function(){
            
            console.log($(this).attr('checked'));
            if($(this).is(':checked')){
                $('input:checkbox.all_sms').attr('checked',true);
                $('.all_sms').css('display', 'none');
                $('.sellect_sms').css('display', 'inline-block');
            }
            else{  
                $('input:checkbox.all_sms').attr('checked',false);
                $('.sellect_sms').css('display', 'none');    
                $('.all_sms').css('display', 'inline-block')
            }
        });

	$('#EmailAll').click(function(){
            
            console.log($(this).attr('checked'));
            if($(this).is(':checked')){
                $('input:checkbox.all_email').attr('checked',true);
                $('.all_email').css('display', 'none');
                $('.sellect_email').css('display', 'inline-block');
            }
            else{  
                $('input:checkbox.all_email').attr('checked',false);
                $('.sellect_email').css('display', 'none');    
                $('.all_email').css('display', 'inline-block')
            }
        });
    });

function redirect(){
        var cat = $('#category').val();
        window.location='assign_client.php?cat='+cat+'&event=<?php  // $_GET['event']?>';
}

function changePipeline(as_id, as_id_code){
    
        var stat = $("#pipe_"+as_id+"_").val();
        
        if(stat !=''){
            var url = 'assign_client_step2.php?event=<?php echo $_GET["event"]; ?>&st=<?php echo base64_encode('4')?>&as='+as_id_code+'&st_code='+stat;
            //alert(url);
            window.location=url;
            
        }
}



function submit_form(){
    
        var url = "ajax.php?task=add_assign"; 
        $.ajax({
              type: "POST",
              url: url,
              data: $("#assignForm").serialize(), // serializes the form's elements.
              success: function(data)
              {
                  //alert(data); // show response from the php script.
                  if(data=='1'){
                      location.reload();
                  }
                  
              }
            });
        }         
        
        
function addTask_form(id){
        //alert(id);
        var url = "ajax.php?task=add_task_form"; 
        $.ajax({
              type: "POST",
              url: url,
              data: $("#task_form_"+id+"_").serialize(), // serializes the form's elements.
              success: function(data)
              {
                  alert(data); // show response from the php script.
                  //if(data=='1'){ location.reload();  }
                  
              }
            });
        }
        
        
function deleteTask(id){
        //alert(id);
        var url = "ajax.php?id="+id+"&task=delete_task"; 
        $.ajax({
              type: "POST",
              url: url,
              data: 'id', // serializes the form's elements.
              success: function(data){
                   if(data=='1'){
                       
                     location.reload();
                  }
              }
            });
        }
        
        
    function goEvent(){
        vv = $("#exi_id").val();
        if(vv!=''){
            window.location = 'assign_client_marketing.php?event=<?= $_GET['event']; ?>&st='+vv+'&1=1';
        }else{
             window.location = 'assign_client_marketing.php?event=<?= $_GET['event']; ?>&1=1'; 
        }
    } 
    




</script>


<script>
$(document).ready(function(){
    $(".start_date").datepicker({
        dateFormat: 'yy-mm-dd',
        numberOfMonths: 1,
        onSelect: function(selected) {
          $(".end_date").datepicker("option","minDate", selected)
        }
    });
    $(".end_date").datepicker({
        dateFormat: 'yy-mm-dd',
        numberOfMonths: 1,
        onSelect: function(selected) {
           //$("#start_date").datepicker("option","maxDate", selected)
        }
    });  
});
</script>