<?php session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$tableZone ="#tableZone".$pageSequence; 
$_SESSION['sequence']++;
//echo  dirname(__FILE__);  
//echo $_SERVER['DOCUMENT_ROOT'] . "   ".dirname(__FILE__)."  ".str_replace($_SERVER['DOCUMENT_ROOT'],"",dirname(__FILE__)) ;

$currentBaseDir = str_replace($_SERVER['DOCUMENT_ROOT'],"",dirname(__FILE__));
include($_SESSION['basedir']."core.php");

$res = $dba->crmGetAgentList($_SESSION['right'], $_SESSION['ownerId'], -1);


?>
<div id="<?php echo $toDiv; ?>" class="tab-content">
<style type="text/css">
/*@import url('https://fonts.googleapis.com/css?family=Open+Sans'); */

body{
    background:#f3f3f4;
    padding-top:30px;
    font-family: 'Open Sans', sans-serif;
}
.userMain .userBlock{
    float: left;
    width: 100%;
    box-shadow: 0px 0px 23px -3px #ccc;
    padding-bottom: 12px;
    margin-bottom: 30px;
    overflow: hidden;
    background:#fff;
    

}
.userMain .userBlock .backgrounImg{
    float: left;
    overflow: hidden;
    height: 77px;
}
.userMain .userBlock .backgrounImg img{
    width: auto;
}
.userMain .userBlock .userImg{
    text-align: center;
}
.userMain .userBlock .userImg img{
    width: 80px;
    height: 80px;
    margin-top: -39px;
    border-radius: 100%;
    border: 5px solid #fff;
    
}
.userMain .userBlock .userDescription{
    text-align: center;
}
.userMain .userBlock .userDescription h5{
    margin-bottom: 2px;
    font-weight: 600;
}
.userMain .userBlock .userDescription p{
    margin-bottom: 5px;
}
.userMain .userBlock .userDescription .btn{
    padding: 0px 23px 0px 23px;
    height: 22px;
    border-radius: 0;
    font-size: 12px;
    background: #0198dd;
    color: #fff;
}
.userMain .userBlock .userDescription .btn:hover{
    
    opacity:0.7;
}

.userMain .userBlock .followrs{
    display: inline-flex;
    margin-right: 10px;
    border-right: 1px solid #ccc;
    padding-right: 10px;
}
.userMain .userBlock .followrs .number{
    font-size: 15px;
    font-weight: bold;
    margin-right: 5px;
    margin-top: -1px;
}

</style>




    <table width="100%" border="0" >

        <tr>

            <td> 



                <div id="<?php echo $resultZoneDiv; ?>">  </div></td>

        </tr>



    </table>



    <table width="100%"  >



        <td align="center">

          

                <table width="94%" border="0" cellspacing="1" cellpadding="1">



              <tr>

                        <td align="center" valign="top" ></td>







                    <tr>

                        <td colspan="2" align="center" valign="top"><b style="color:red">

                            </b></td>

                    </tr>

                    <tr height="40">

                        <td height="19" colspan="2" class="connection" valign="top" align="left">

       

                                <div id="routeType1" >

                                    <fieldset >

                                      <legend><em>Etat des conseillers clients</em><!-- Paramètre de configuration Modem-->
                                    </legend>



<div class="container">
	 <div class="row userMain">
      <div class="col-md-10">    
      <?php

            $cmpt = 1;

            for ($i = 0; $i < count($res); $i++) {

        ?>


    
       <div class="col-md-3 col-sm-4">
           <div class="userBlock">
               <div class="backgrounImg">
                <?php   if($manager->getAgentSipUserStatus($res[$i]['mobile_phone_v'])) { ?>
                   <img src="images/bg-agent-online.jpg">
                <?php } else { ?>
                   <img src="images/bg-agent-offline.jpg">
                <?php } ?>
               </div>
               <div class="userImg">
               <img src="dist/img/user.png">
                 
               </div>
               <div class="userDescription">
                   <h5>  <?php echo $res[$i]['first_name_v']. " ".$res[$i]['last_name_v']; ?> </h5>
                              
                   
                    <div class="followrs">
                       <span class="number"><?php echo $res[$i]['mobile_phone_v']; ?></span>
                        <span></span>
                    </div>
                    
                       <?php  $aStatus = $manager->getAgentQueueMemberStatus($res[$i]['mobile_phone_v']) ;
					       if($aStatus  == 'Actif') {  ?>
                        <a href="#" data-href="<?php echo $currentBaseDir; ?>/updateStatus.php?mobilePhone=<?php echo $res[$i]['mobile_phone_v']; ?>&status=pause" class="btn-updateStatus"> <button class="btn">Actif</button></a>
                       <?php  } elseif($aStatus  == 'Pause') {  ?>
                        <a href="#" data-href="<?php echo $currentBaseDir; ?>/updateStatus.php?mobilePhone=<?php echo $res[$i]['mobile_phone_v']; ?>&status=unpause" class="btn-updateStatus"> <button class="btn">Pause</button></a>
                       <?php } else { ?>
                        <button class="btn disabled">Désactivé</button>
                       <?php } ?>
                    
               </div>
              
           </div>
       </div>
       
       
       
     <?php   }  ?>
     
     </div>
  
    </div>
</div>
                                        









                                  </fieldset>

                                </div> 

                         









                        </td>

                    </tr>



                </table>


        </td>

        </tr>





    </table>



</div>
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>

<script type="text/javascript" >

     var time = new Date().getTime();
     $(document.body).bind("mousemove keypress", function(e) {
         time = new Date().getTime();
     });

     function refresh() {
         if(new Date().getTime() - time >= 5000) {
			 //alert('Reloding Tab');
             $('#<?php echo $toDiv; ?>').load('<?php echo $currentBaseDir; ?>/crm_user_status.php');
		 }
         else 
             setTimeout(refresh, 10000);
     }

     setTimeout(refresh, 10000);
	 
	 
	 
	 $("a[class='btn-updateStatus']").on('click', function(){
  // create the backdrop and wait for next modal to be triggered
 // $('body').modalmanager('loading');
 var customerurl = $(this).attr('data-href') ;
 
// alert(customerurl);
   $('#loader').loading({
		  message : "Chargement...",
		  theme : 'dark'
		  
		});
		
		$.confirm({
                   title: 'Attention!',
                   content: 'Voulez-vous changer le statut?',
				   buttons: {
						confirm: {
						  text : 'Confirmer',
						  btnClass: 'btn-blue',
						  action: function () {
							  	  $.getJSON( customerurl ,
									function(obj) {
						                  if(obj.errorCode == 0 ) {
											  	 $('#<?php echo $toDiv; ?>').load('<?php echo $currentBaseDir; ?>/crm_user_status.php');
												 $.alert({
													 icon: 'glyphicon glyphicon-ok',
													 title: 'RESULTAT',
													 content: obj.errorMessage,
													 type: 'green',
													 typeAnimated: true
									
													});
											   }
											   else {
												   
												   $.alert({
														 icon: 'glyphicon glyphicon-warning-sign',
														 title: 'RESULTAT',
														 content: obj.errorMessage,
														 type: 'red',
														 typeAnimated: true
													});
													
												
											      }
				                         });            
                         } 
		
		             },
					cancel: {
					  text: 'Annuler', 
					  action:  function () {
						
					}
				  }
               } // Closing button
		}); // Closing confirm
		
		// alert($(this).attr('data-href'));
		 $('#loader').loading('stop'); 
		 
 
});



</script>

<link rel="stylesheet" href="css/jquery-confirm.min.css">
<script src="js/jquery-confirm.min.js"></script>