
<?php
include('dbconfig.php');
//error_reporting(0);
if (isset($_POST["submit"])) {
    
    

    
    
if (count($_POST["ids"]) > 0 ) {
// Imploding checkbox ids
$all = implode(",", $_POST["ids"]);
$sql =mysqli_query($con,"DELETE FROM airtime_contacts WHERE contact_id in ($all)");
if ($sql) {
$errmsg ="Data has been deleted successfully";
} else {
$errmsg ="Error while deleting. Please Try again.";
}
} else {
$errmsg = "You need to select atleast one checkbox to delete!";
}
}



?>




<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>

<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!--


<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">

-->





  <div class="page-title">
              <div class="title_left" style="margin-left:0px;">
                <h3> Find All Your Contacts </h3> </div>
            </div>
            <div class="row">
			
   <!---- table starts here -->
   
       
	<a href="viewcontacts.php">  <button class=" pull-left " style="margin-left:20px;" ><i class="fa fa-th"> </i> </button> </a>
	     <button class="btn btn-primary pull-right" data-toggle="modal" data-target="#myModal" > Add New Contacts </button> 
	<!-- Modal -->

               <!-- add contact form -->
			  <?php include("addcontactsform.php"); ?>
			 
	
	     

    <!-- edd contact form model -->
	
			<!-- <a href="" class="btn btn-primary"> Add New Contacts </a> </div>   -->

              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2> My Contacts List </h2>
                    	 <a target="_blank" href="print_to_pdf/print_group_contacts.php"> <button type="submit" class="btn btn-success " name="sendairtime">Export PDF</button>  </a>
                     <div class="dropdown pull-right">
                         
                         
<a  href="pdf/contactsreport.php" target="_blank" ><i class="fa fa-bars"></i>Export PDF<span class="fa fa-chevron-right"></span></a>
<a  href="excelreports/excelcontacts.php" ><i class="fa fa-bars"></i>Export Excel<span class="fa fa-chevron-right"></span></a>
<a  href="excel/contactscsv.php" ><i class="fa fa-bars"></i>Export CVS<span class="fa fa-chevron-right"></span></a>
                         
                         <a href="delete_my_contacts.php" onClick="return confirm('Are you sure you want to delete all your Contacts??');"><button class="btn btn-danger btn-sm"> <i class='fa fa-trash'>
                         </i> <b style="margin-left:0.3em;">Delete All Contacts</b> </button>  </a>
						<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Tools <span class="caret"></span></button>
				
					
				
							<form name="multipledeletion" method="post"   action=""   >
							
					</div>
					
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
	<input type="submit" name="submit" value="Delete" class="btn btn-primary btn-md pull-left" onClick="return confirm('Are you sure you want to delete?');" >
                 

<p style="color:red; font-size:16px;">
<?php if($errmsg){ echo $errmsg; } ?> </p>



				 
                    <table id="datatable-buttons" class="table table-striped table-bordered">

<!-- Deletion Button -->
     <tr>
                          <th>Name</th>
                          <th>Contact</th>
                          <th>Group</th>   
						  
						  <th>
<!-- For Selecting All -->
<li><input type="checkbox" id="select_all" /> Select all</li></th>
						  
						  
                          <th>Actions</th>
                        </tr>





<?php
$query=mysqli_query($con,"select * from airtime_contacts left join airtime_groups on airtime_groups.group_id=airtime_contacts.group_id where airtime_contacts.customer_id = '$session_id'  ");
$totalcnt = mysqli_num_rows($query);
if ($totalcnt > 0) {
while ($row=mysqli_fetch_array($query)) {
?>
<tr>


<td><?php echo htmlentities($row['fname']);?></td>
<td><?php echo htmlentities($row['contact']);?></td>
<td><?php echo htmlentities($row['name']);?></td>
<td><input type="checkbox" class="checkbox" name="ids[]" value="<?php echo htmlentities($row['contact_id']);?>"/></td>
	  <td>  
						<a rel="tooltip" title="Edit Contact" id="<?php echo $id ?>" href="#editcontact<?php echo $id ?>" data-toggle="modal"  >
								<i class='fa fa-edit'></i> </a> 
					  
						 <a rel="tooltip" title="Delete Contact" id="<?php echo $id ?>" href="#deletecontact<?php echo $id ?>" data-toggle="modal">
								<i class='fa fa-trash'></i> </a> 
			
					                   
						</td>
</tr>
<?php } } else { ?>
					  <td>  
						<a rel="tooltip" title="Edit Contact" id="<?php echo $id ?>" href="#editcontact<?php echo $id ?>" data-toggle="modal"  >
								<i class='fa fa-edit'></i> </a> 
					     <?php include('edit_contact.php'); ?>
						 <a rel="tooltip" title="Delete Contact" id="<?php echo $id ?>" href="#deletecontact<?php echo $id ?>" data-toggle="modal">
								<i class='fa fa-trash'></i> </a> 
					     <?php include('delete_contact.php'); ?>
					                   
						</td>
					   <?php
				
				       }  
                       echo "</table>";
					  
					  ?>  
                       
                       
                        
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
			  
			  
</form>
			  
			  
		<script type="text/javascript">
$(document).ready(function(){
$('#select_all').on('click',function(){
if(this.checked){
$('.checkbox').each(function(){
this.checked = true;
});
}else{
$('.checkbox').each(function(){
this.checked = false;
});
}
});
$('.checkbox').on('click',function(){
if($('.checkbox:checked').length == $('.checkbox').length){
$('#select_all').prop('checked',true);
}else{
$('#select_all').prop('checked',false);
}
});
});
</script>	   
			   
			   <!--- table ends here -->
            </div>
          
        <!-- /page content -->

      
     
