<?php require_once('../auth/auth.php'); ?>
<?php 
$cfid_check_default = mysqli_query($conn,"SELECT cfid  FROM custom_field WHERE coid='$coid'");
 $count = mysqli_num_rows($cfid_check_default);
if($count < 1){
mysqli_query($conn,"INSERT INTO `custom_field`(`coid`,`userid`) VALUES ('$coid','$uid')")or die(mysqli_error($conn));
}
$custom_field= mysqli_query($conn,"SELECT sales FROM custom_field WHERE coid='$coid' LIMIT 1 ") or die (mysqli_error($conn));
$rowcf= mysqli_fetch_assoc ($custom_field);
$p=$rowcf['sales'];
function checked($ap)
{
  if (strpos($GLOBALS['p'], $ap) !== false) {
    return $checked='checked';
 } else {
    return $checked='';
 }
}
?>

<section class="content">
   <div class="container-fluid">
      <div class="row">
         <div class="col-md-4">
            <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(67);?></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>
            <form id="cusper_form" action="#" method="post" autocomplete="off">
              <input type="hidden" value="<?php echo $coid ?>" name="getcoid">
              <input type="hidden" value="" name="cus_check[]">
              <div class="card-body">
               <div class="col-md-12">
                  <div class="row" style="margin:3px;">
                     <div class="col-md-12">
                        <div class="card card card-outline direct-chat direct-chat shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
                           <div class="card-header" style="background: #28a745;padding: 4px 8px;color: whitesmoke;">
                             <h3 style="float:left" class="card-title"> <?php echo language(67);?></h3>
                             <div class="card-tools" >
                              <button type="button"  class="btn btn-tool" data-card-widget="remove"> <i class="fas fa-times" style="color: whitesmoke;"></i></button>
                             </div>
                           </div>
                           <table id="trbl_table" class="searchtable ttable" cellpadding="0" cellspacing="0">
                              <tr>  
                                 <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(222);?> </td>  
                                 <td>
                                    <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                       <input type="checkbox" class="custom-control-input"  name="cus_check[]"  id="selectAllcus"/>
                                       <label class="custom-control-label" for="selectAllcus"></label>
                                    </div>
                                 </td>
                              </tr> 
                              <tr>  
                              <td><i class="ion-ios-navigate-outline text-success"> </i><?php echo language(62);?> <?php echo language(150);?> </td>   
                              <td>
                                 <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                    <input type="checkbox" id="casnarration" class="custom-control-input selectAll c_per"  name="cus_check[]" value="casnarration" <?php echo checked('casnarration');?>>
                                    <label class="custom-control-label" for="casnarration"></label>
                                 </div>
                              </td>  
                           </tr> 
                           <tr>  
                              <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(63);?> <?php echo language(150);?> </td>   
                              <td>
                                 <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                    <input type="checkbox" id="narration" class="custom-control-input selectAll c_per"  name="cus_check[]" value="narration" <?php echo checked('narration');?>>
                                    <label class="custom-control-label" for="narration"></label>
                                 </div>
                              </td>  
                           </tr> 
                           <tr>  
                              <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(151);?> </td>  
                              <td>
                                 <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                    <input type="checkbox" id="m_invoice" class="custom-control-input selectAll c_per" c_per="m_invoice" name="cus_check[]" value="m_invoice" <?php echo checked('m_invoice');?>>
                                    <label class="custom-control-label" for="m_invoice"></label>
                                 </div>
                              </td>  
                           </tr>  
                 
                           <tr>  
                              <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(152);?> </td>   
                              <td>
                                 <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                    <input type="checkbox" id="d_man" class="custom-control-input selectAll c_per" c_per="d_man" name="cus_check[]" value="d_man" <?php echo checked('d_man');?>>
                                    <label class="custom-control-label" for="d_man"></label>
                                 </div>
                              </td>  
                           </tr>  
                           <tr>  
                              <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(104);?> </td>   
                              <td>
                                 <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                    <input type="checkbox" id="wharehouse" class="custom-control-input selectAll c_per" c_per="wharehouse" name="cus_check[]" value="wharehouse" <?php echo checked('wharehouse');?>>
                                    <label class="custom-control-label" for="wharehouse"></label>
                                 </div>
                              </td>  
                           </tr> 
                              <tr>  
                                 <td ><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(131);?> </td>  
                                 <td style="width: 5%">
                                    <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                       <input type="checkbox" id="invoice_date" class="custom-control-input selectAll c_per" c_per="invoice_date" name="cus_check[]" value="invoice_date" <?php echo checked('invoice_date');?>>
                                       <label class="custom-control-label" for="invoice_date"></label>
                                    </div>
                                 </td>  
                              </tr>  
                              <tr>  
                                 <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(132);?> </td>  
                                 <td>
                                    <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                      <input type="checkbox" id="sms" class="custom-control-input selectAll c_per" c_per="sms" name="cus_check[]" value="sms" <?php echo checked('sms');?>>
                                      <label class="custom-control-label" for="sms"></label>
                                   </div>
                                </td>  
                             </tr> 

                             <tr>  
                                 <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(155);?> </td>  
                                 <td>
                                    <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                      <input type="checkbox" id="email" class="custom-control-input selectAll c_per" c_per="email" name="cus_check[]" value="email" <?php echo checked('email');?>>
                                      <label class="custom-control-label" for="email"></label>
                                   </div>
                                </td>  
                             </tr>   
           
                           <tr>  
                              <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(154);?>  </td>   
                              <td>
                                 <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                    <input type="checkbox" id="d_account" class="custom-control-input selectAll c_per" c_per="d_account" name="cus_check[]" value="d_account" <?php echo checked('d_account');?>>
                                    <label class="custom-control-label" for="d_account"></label>
                                 </div>
                              </td>  
                           </tr> 
                           <tr>  
                              <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(142);?>  </td>   
                              <td>
                                 <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                    <input type="checkbox" id="f_charge" class="custom-control-input selectAll c_per" c_per="f_charge" name="cus_check[]" value="f_charge" <?php echo checked('f_charge');?>>
                                    <label class="custom-control-label" for="f_charge"></label>
                                 </div>
                              </td>  
                           </tr> 
                            <tr>  
                              <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(98);?>   </td>   
                              <td>
                                 <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                    <input type="checkbox" id="u_type" class="custom-control-input selectAll c_per"  name="cus_check[]" value="u_type" <?php echo checked('u_type');?>>
                                    <label class="custom-control-label" for="u_type"></label>
                                 </div>
                              </td>  
                           </tr> 
                           <tr>  
                              <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo language(149);?> </td>   
                              <td>
                                 <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                    <input type="checkbox" id="p_account" class="custom-control-input selectAll c_per" c_per="p_account" name="cus_check[]" value="p_account" <?php echo checked('p_account');?>>
                                    <label class="custom-control-label" for="p_account"></label>
                                 </div>
                              </td>  
                           </tr> 
                            <tr>  
                              <td><i class="ion-ios-navigate-outline text-success"> </i> <?php echo 'Start Calculator';?> </td>   
                              <td>
                                 <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                    <input type="checkbox" id="s_calculator" class="custom-control-input selectAll c_per" c_per="s_calculator" name="cus_check[]" value="s_calculator" <?php echo checked('s_calculator');?>>
                                    <label class="custom-control-label" for="s_calculator"></label>
                                 </div>
                              </td>  
                           </tr> 
       
                        </table> 
                     </div>  
                  </div>
               </div>
            </div>
         </div>
      </form> 
      </div>
   </div>
</div>
</div>
</section>
<script type="text/javascript">
   if ($('.selectAll:checked').length === $('.selectAll').length) {
      $('#selectAllcus').prop('checked', true);   
   }

   $('#selectAllcus').click(function(){
      $('.selectAll').prop('checked', true);
      if(!$(this).prop("checked")) {
         $('.selectAll').prop('checked', false);
      }
   });
   $('.selectAll').change(function() {
      if(!$(this).prop("checked")) {
         $('#selectAllcus').prop('checked', false);
      } else {
         if ($('.selectAll:checked').length === $('.selectAll').length) {
            $('#selectAllcus').prop('checked', true);
         }
      }
   });
</script>
<script>
   $(document).ready(function() {
     $('#cusper_form input[type=checkbox]').change(function(e) { 
      e.preventDefault(); 
      $.post("../sales/setting_db.php",$('#cusper_form').serialize(),function(data){
       toastr.success(data, yourdata);
    });
   });
  });  
</script>



