<?php
 require_once('../auth/auth.php');
$Getuser_query= mysqli_query($conn,"SELECT `brid`,`sms_api_key`, `sms_senderid`,sms_status  FROM branch
      WHERE  coid='$coid' AND brid='$brid' LIMIT 1 ") or die (mysqli_error($conn));
      $rowuid= mysqli_fetch_assoc($Getuser_query);
       $get_brid=$rowuid['brid'];
       $sms_api_key=$rowuid['sms_api_key'];
       $sms_senderid=$rowuid['sms_senderid'];



?>
<section class="content">
   <div class="container-fluid">
      <div class="row">
         <div class="col-md-12">
            <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
               <div class="card-header" style="padding: 5px 8px;">
                  <h3 class="card-title"><?php echo language(426); ?></h3>
                  <div class="card-tools"> <button type="button" class="btn btn-tool" data-card-widget="remove"> <i class="fas fa-times"></i>  </button> </div>
               </div>



            
              <?php   if($sms_senderid>0){  ?>
                        <?php
                        $message_query= mysqli_query($smsdb,"SELECT `ID`, `number`, `message`, `schedule`, `sentDate`, `deliveredDate`, `expiryDate`, `status`, `resultCode`, `errorCode`, `retries`, `userID`, `deviceID`, `simSlot`, `groupID`, `type`, `attachments` FROM Message WHERE   deviceID ='$sms_senderid' ORDER BY sentDate  DESC   LIMIT 100 ") or die (mysqli_error($conn));
                        $i=0;
                        while ($rowsms= mysqli_fetch_array ($message_query) ){
                        $ID  =$rowsms['ID'];                  
                        ?>
            
          <div class="col-md-12 mt-2">
            <div class="timeline">
              <div class="time-label">
                <span class="bg-red"><?php echo date('d M. y', strtotime($rowsms['sentDate']));?> </span>
              </div>
              
              <div>
                    <?php if($rowsms['status']=='Sent'){ ?>
                       <i class="fa-solid fa-plane-circle-check bg-success"></i>
                    <?php }else if($rowsms['status']=='Received'){  ?>
                       <i class="fa-solid  fa-download bg-info"></i>
                    <?php }else if($rowsms['status']=='Queued') { ?>
                    <i class="fa-solid fas fa-envelope bg-success"></i>
                    <?php }else if($rowsms['status']=='Pending') { ?>
                    <i class="fa-solid fa fa-wifi"></i>
                    <?php }else if($rowsms['status']=='Failed') { ?>
                    <i class="fa-solid fas fa-times bg-danger"></i>
                    <?php }else if($rowsms['status']=='Delivered') { ?>
                    <i class="fa-solid fa-envelope bg-success"></i>
                    <?php  }else{  ?>
                      <i class="fa-solid fa-envelope-circle-check bg-success"></i>
                     <?php  }   ?>

                <div class="timeline-item" style="margin-left:75px !important">
                  <span class="time"><i class="fas fa-clock"></i> <?php echo date(' h:i:s a', strtotime($rowsms['sentDate']));?></span>
                  <h3 class="timeline-header"><a href="#"> <i class="fa-solid fa-mobile-retro"></i>  <?php echo $rowsms['number'];?></a>  || <i class="fa-solid fa-sim-card"></i> <?php 
                           if($rowsms['simSlot']==0){
                           echo "Sim 1";
                           }else if($rowsms['simSlot']==1){
                               echo "Sim 2";
                           }else{
                               
                               echo "unknown";
                           }
                           ?></h3>

                  <div class="timeline-body">
                   <?php echo $rowsms['message'];?>
                  </div>
                  <div class="timeline-footer">
                    <!--<a class="btn btn-primary btn-sm "  onclick="sms_view('<?php echo $rowsms['ID'];?>')">Read more</a>-->
                    <a class="btn btn-success  btn-sm">Status : <?php echo $rowsms['status'];?></a>
                  </div>
                </div>
              </div>
            </div>
          </div>

                   <?php } ?> 

<div class="col-md-12 mt-2">
            <div class="timeline">
              <div class="time-label  text-center bg danger">
                  <?php  }else{ echo "Device Not Connected"; } ?>
                  </div>
                  </div>
                  </div>
          
          <!-- /.col -->
        </div>

      </div>
        </div>
          </div>
    </section>
 <script type="text/javascript">
   function sms_view(smsid){    
     $("#modal-lg").modal({backdrop: "static"});
     pagecall('../sms/mobile_view.php?smsid='+smsid,'#mdview');   
   }  
</script>
