<?php 
include('inc/header.php');
include('inc/sidebar.php');


$manage_testimonial = new website();
if(isset($_POST['active']))
{

    if(count($_POST['opt'])==1)
    {
        $id = "where id='".$_POST['opt'][0]."'";
        $total_row = 1;
    }
    else
    {
        $total_row = count($_POST['opt']);
        $id_emp = implode(',',$_POST['opt']);
        $id = "where id in ($id_emp)";

    }

    $manage_testimonial->active("tbl_testimonial",$id,$total_row,$page);
}
if(isset($_POST['deactive']))
{
  

    if(count($_POST['opt'])==1)
    {
        $id = "where id='".$_POST['opt'][0]."'";
        $total_row = 1;
    }
    else
    {
        $total_row = count($_POST['opt']);
        $id_emp = implode(',',$_POST['opt']);
        $id = "where id in ($id_emp)";

    }

    $manage_testimonial->deactive("tbl_testimonial",$id,$total_row,$page);
}
if(isset($_POST['delete']))
{

    if(count($_POST['opt'])==1)
    {
        $id = "where id='".$_POST['opt'][0]."'";
        $total_row = 1;
    }
    else
    {
        $total_row = count($_POST['opt']);
        $id_emp = implode(',',$_POST['opt']);
        $id = "where id in ($id_emp)";

    }

    $manage_testimonial->delete("tbl_testimonial",$id,$total_row,$page);
}

?>    
    <script type="text/javascript">
function checkall(objForm)
{
    var x = objForm;
  
   
len = objForm.elements.length;
var i=0;
for( i=0 ; i<len ; i++) 
{
if (objForm.elements[i].type=='checkbox') 
{
objForm.elements[i].checked=objForm.check_all.checked;
}
}
}  
</script>
		 
		<!--start page wrapper -->
				<!--start page wrapper -->
		<div class="page-wrapper">
			<div class="page-content"> 
				<!--breadcrumb-->
				 
				<h6 class="mb-0 text-uppercase">Testimonial List <a href="add-testimonial.php" class="pull-right btn btn-primary">Add Testimonial</a> </h6>
				<hr/>
				<div class="card">
					<div class="card-body">
						<form  method="post" >
						<div class="table-responsive">
							<table id="example2" class="table table-striped table-bordered text-center">
								<thead>
									<tr >
										<th>Sr.</th>
										<th>Name</th>
										<th>Image</th>
										 <th>Date</th>
										<th>Status</th>
										<th>Edit</th>
										  <th>
                                <div class="checkbox d-inline-block">
                                    <input type="checkbox" class="checkbox-input"  id="check_all" onclick="checkall(this.form)" value="check_all" name="checkbox">
                                    <label for="checkbox1" class="mb-0"></label>
                                </div>
                            </th>
										 
									</tr>
								</thead>
								<tbody>
									

									 <?php
                       $testimonial_list = $manage_testimonial->self_query("select * from tbl_testimonial order by id desc");
                       
                        if(count($testimonial_list)==0)
                        {
                            echo '<tr><td><td><td><span style="color:red">No Record Found</span></td></td></td></tr>';
                        }
                        else
                        {
                            for($i=0;$i<count($testimonial_list);$i++)
                            {
                                

                       ?>
                        <tr>
                            
                            <td><?=$i+1?></td>
                           
							            <td> <?=$testimonial_list[$i]['title']?></td>
							             <td><img height="100" width="100" src="../images/main_img/<?=$testimonial_list[$i]['image']?>"> </td> 
										 
										<td><?=date('d-m-Y',strtotime($testimonial_list[$i]['add_date']));?></td>
										<td><?php if($testimonial_list[$i]['status']==1) {?> <button type="button" class="btn btn-success" style="background-color: green;">Active</button><?php } else {?><button type="button" class="btn btn-danger" style="background-color: red;">Deactive</button><?php } ?></td>
										
										<td>
											  <div class="text-center">
                                  
                                    <a  href="add-testimonial.php?edit=<?=$testimonial_list[$i]['id']?>">Edit <i class="fa fa-eye"></i></a>
                                    
                                </div>

											</td>
										 

								<td>
                                <div class="checkbox d-inline-block">
                                    <input type="checkbox" class="checkbox-input" id="checkbox2" name="opt[]" value="<?=$testimonial_list[$i]['id']?>">
                                    <label for="checkbox2" class="mb-0"></label>
                                </div>
                            </td>
									 
									</tr>

								<?php } }?>

									 
								</tbody>
								 
							</table>
						</div>

						 <div class="row">
                <div class="col-md-4"></div>
                  <div class="col-md-8">
                       <button type="submit" class="btn btn-primary" name="active">Active</button>
                       <button type="submit" class="btn btn-primary" name="deactive">Deactive</button>
                       <button type="submit" class="btn btn-primary" name="delete" onClick="return confirm('Are You Sure')">Delete</button>
                  </div>
               </div>
               <br>
               </form>

					</div>
				</div>
			</div>
		</div>
		 
		<!--end page wrapper -->
				<!--end page wrapper -->
				<?php 

        include 'inc/footer.php';
    ?>

	 
	</div>
	<!--end wrapper-->
    
	
    <script src="assets/plugins/datatable/js/jquery.dataTables.min.js"></script>
    <script src="assets/plugins/datatable/js/dataTables.bootstrap5.min.js"></script>

    <script>
		$(document).ready(function() {
			$('#example').DataTable();
		  } );
	</script>
	<script>
		$(document).ready(function() {
			var table = $('#example2').DataTable( {
				lengthChange: false,
				buttons: [ 'copy', 'excel', 'pdf', 'print']
			} );
		 
			table.buttons().container()
				.appendTo( '#example2_wrapper .col-md-6:eq(0)' );
		} );
	</script>
	</body>

 
</html>
