<?php 
require_once('includes/check-login.php');
require_once('includes/header.php'); 
require_once('includes/menu.php'); 
require_once('includes/config.php'); 
$tablename="services";	
$addurl="addservices.php";
$sql = "SELECT id,service_name,image,status,created,modified from ".$tablename."";
$result = $con->query($sql);
?>
        <!-- Datatable CSS -->
        <link href='data_tables/datatables.min.css' rel='stylesheet' type='text/css' />        

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">                                
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>                    
                        <li class="active"><a href="services.php">Services</a></li>           
                    </ol>                
            </section>

            <!-- Main content -->
            <section class="content">                
                <!-- Default box -->
                <div class="box box-form">
                    <div class="box-header with-border">
                        <h3 class="box-title">Services</h3>
						<?php if(isset($_SESSION[$tablename."succ_msg"])) {?>
                 <div class="alert alert-success">
                 <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
                 <?php echo $_SESSION[$tablename."succ_msg"];  unset($_SESSION[$tablename."succ_msg"]);?>
                 </div>
                <?php }?>   
                <?php if(isset($_SESSION[$tablename."err_msg"])) {?>
                <div class="alert alert-success">
                <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
                <?php echo $_SESSION[$tablename."err_msg"]; unset($_SESSION[$tablename."err_msg"]);?>
                </div>
               <?php }?>			  
                        <div class="box-tools pull-right">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
                                <i class="fa fa-minus"></i></button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
                                <i class="fa fa-times"></i></button>
                        </div>
						 <header class="box-typical-header"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
			    <div class="tbl-cell btn-group btn-group-sm"><a href="<?php echo $base_url.$addurl;?>" class="tabledit-delete-button btn btn-sm btn-success" title="Add"><span class="glyphicon glyphicon-plus"></span> Add</a></div>
			    <div class="tbl-cell btn-group btn-group-sm pull-right"><a href="javascript:void(0)" class="tabledit-delete-button btn btn-sm btn-danger deleterow" title="Delete"><span class="glyphicon glyphicon-trash"></span> Delete</a></div>     
				</header>	
                    </div>
                    <div class="box-body">    
                        <!-- Table -->
                        <table id='workapp' class='display dataTable table table-bordered table-hover'>
                            <thead>
                            <tr>
							    <th class="table-check">
						         <div class="checkbox checkbox-only">
						         <input type="checkbox" id="table-check" class="checkAll"/>
						        <label for="table-check"></label>
						        </div>
						        </th>
                                <th>Service Name</th>                                              
                                <th>Image</th>                                          
                                <th>Datetime</th>                                                              
                                <th>Action</th>                                 
                            </tr>
                            </thead> 
                              <tbody>
							<?php $i=1;
							if ($result->num_rows > 0) {
                            while($row = $result->fetch_assoc()) {?>
						   <tr>
						   <td class="table-check">
						   <div class="checkbox">
						   <input type="checkbox" id="table-check-<?php echo $i;?>" name="id" value="<?php echo $row['id'];?>"/>
						   <label for="table-check-<?php echo $i;?>"></label>
						   </div></td>
						   <td><?php echo $row['service_name'];?></td>
						   <td><img src="<?php if(@is_array(getimagesize(UPLOAD_SERVICEIMG.$row['image']))){echo $base_url.UPLOAD_SERVICEIMG.$row['image'];}else{echo BASE_URL1.'image/default.jpg';}?>" alt="<?php echo $row['service_name'];?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="<?php echo $row['service_name'];?>"></td>
						   <td><p>Created : <?php echo $row['created'];?></p><p>Modified : <?php echo $row['modified'];?></p></td>
						   <td><a href="<?php echo $base_url.$addurl;?>?id=<?php echo $row['id'];?>" class="tabledit-edit-button btn btn-sm btn-primary" title="Edit"><span class="glyphicon glyphicon-pencil"></span></a></td>
						    </tr>								  
							 <?php $i++;}}?>
                           </tbody>							
                        </table>

                    </div>
                    
                    <!-- /.box-footer-->                    
                </div>
                <!-- /.box -->

            </section>
            <!-- /.content -->                                        
        </div>
        <!-- /.content-wrapper -->        
<script src="js/common.js"></script>  
<script src="js/datatables.js"></script>    
<script>
$(document).ready( function() {
$(".checkAll").change(function () {
    $("input:checkbox").prop('checked', $(this).prop("checked"));
});
});
$(document).ready( function() {		
		$(".deleterow").off('click').on('click',function(e) {
		e.preventDefault();
		var anyBoxesChecked = false;
		var deletearray = new Array();		
		$('input[name="id"]:checked').each(function(){			
			deletearray.push($(this).val());
              anyBoxesChecked = true;	
		});		
		 if(anyBoxesChecked == true) {
                Lobibox.confirm({
                    msg: "Are you sure you want to delete this row?",
                    callback: function ($this, type) {
                        if (type === 'yes') {
                            Lobibox.notify('success', {
								msg: 'You have Deleted Successfully.'			     
                            });           
	       var table="<?php echo $tablename;?>";		  
           $.ajax({
           type: "POST",
           url: "deleterecord.php",
           data:{id:deletearray,table:table},
           cache: false,
           success: function(data){
          setTimeout(function(){location.reload();},1000); 
            }   
           });               } else if (type === 'no') {
                            Lobibox.notify('info', {
                                msg: 'Your row not deleted.'
                            });
                        }
                    }
                });
				}
			else{
				alert("Please select at least one checkbox");
			}
            });
})
</script>
<script src="<?php echo $base_url;?>js/lobibox.js"></script>  
<?php require_once('includes/footer.php'); ?>