<?php
include_once("../include/main.inc.php");
check_session('MyCpanel', 'index.php');
?>
<script type="text/javascript">
  function chk_valid_date() {
    if (document.bannerFrm.validFrom.value == 0) {
      alert("Please select Validity Period");
      return false;
    }
    if (document.bannerFrm.validTo.value == 0) {
      alert("Please select Validity Period");
      return false;
    }
  }
</script>
<?php
################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start) < 0 or $start == "") ? 0 : $start;
$pagesize = intval($pagesize) == 0 ? $pagesize = 20 : $pagesize;
$res = getResult("admin_details", " where user_type='admin'");

$heading = "Manage Trusted Client Logo";
$record_type = "Trusted Client Logo";
$script_name = "manage-clients.php";
$table_name = "client_tbl";
####################################################



if ($action == "Update") {
  $input = $_POST;
  $part = array_splice($input, 0, 2);

  while (list($key, $val) = each($input)) {
      if (substr($key, 0, 6) == "order_") {
          $key1 = substr($key, 6, strlen($key) - 6);

          $qry1 = db_query("update $table_name set client_order='$val' where id='$key1'");
      }
  }
  //$_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been updated successfully  </div>';

  header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
  exit;
}

if (isset($_POST['active'])) {
  if (!empty($_POST['cat_arr'])) {
      $catid = $_POST['cat_arr'];
      foreach ($catid as $id) {
          mysqli_query($dbconn, "UPDATE $table_name SET status = 'Y' WHERE id = '$id'");
      }
      //$_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been updated successfully</div>';
  } else {
      //$_SESSION['session_message'] = '<div class="btn btn-danger">No Category selected</div>';
  }
  header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
  exit;
}

if (isset($_POST['inactive'])) {
  if (!empty($_POST['cat_arr'])) {
      $catid = $_POST['cat_arr'];
      foreach ($catid as $id) {
          mysqli_query($dbconn, "UPDATE $table_name SET status = 'N'  WHERE id = '$id'");
      }
      //$_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been updated successfully</div>';
  } else {
      //$_SESSION['session_message'] = '<div class="btn btn-danger">No Category selected</div>';
  }
  header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
  exit;
}

if (isset($_POST['delete'])) {
  if (!empty($_POST['cat_arr'])) {
      $arr_id = $_POST['cat_arr'];
      foreach ($arr_id as $id) {
          mysqli_query($dbconn, "DELETE FROM $table_name WHERE id = '$id'");
      }
      // $_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been deleted successfully</div>';
  } else {
      //$_SESSION['session_message'] = '<div class="btn btn-danger">No Category selected</div>';
  }
  header("Location: ".SITE_ADMIN_URL."/".$script_name);
  exit;
}
admin_header("");
$qry= mysqli_query($dbconn,"select * from $table_name order by id desc");	  
?>
   <div class="content-wrapper">
          <div class="page-header">
            <h3 class="page-title">
			<?=$heading;?>
            </h3>
            <nav aria-label="breadcrumb">
              <ol class="breadcrumb">

              <li class="nav-item d-none d-lg-flex">
            <a class="nav-link" href="<?=admin_url?>manage_top_heading_clients.php">
            <span class="btn btn-info">+ Manage Top Heading Client</span>
           
            </a>
          </li>
			  <li class="nav-item d-none d-lg-flex">
            <a class="nav-link" href="<?=admin_url?>addeditclient.php">
              <span class="btn btn-primary">+ Add Trusted Client Logo</span>
            </a>
          </li>
              </ol>
            </nav>
          </div>
          <div class="card">
            <div class="card-body">
              <div class="row">
                <div class="col-12">
                  <form action="" method="POST">
                  <div class="table-responsive">
                   <table id="order-listing" class="table table-bordered table-hover">
                      <thead>
                        <tr>
                            <th>#</th>
							<th>S.No.</th>
                            <th>Trsuted Client Name</th>
                            <th>Client Logo</th>
                            <th>Order</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                      </thead>
                      <tbody>
					  <?php
 $sl=$start+1;
 while($arr=mysqli_fetch_array($qry)) { ?>
 <tr>
                            <td><input type="checkbox" name="cat_arr[]" value="<?= $arr['id'] ?>"></td>
                            <td><?=$sl?></td>
     <td><p class="ordern"><?=$arr['name'];?></p></td>
                             <td><p class="dongle-dcs"> <?php
	   if($arr['logo_image']!="") {
		   $file1=SITE_DIR_PATH."/uploaded-files/client-image/".$arr['logo_image'];
			   $dimens=GetImageSize($file1);
			   if($dimens[0]>130) {
				   $dimens[0]=$dimens[0]+30;
				   $dimens[1]=$dimens[1]+80;
			   }
			   else{
				   $dimens[0]=200;
				   $dimens[1]=200;
			   }
			   ?>
                <a href="javascript:void(0);" onClick="openwin('<?=SITE_ADMIN_URL;?>/popup_new.php?img=client-image/<?=$arr['logo_image'];?>', '<?=$dimens[0];?>', '<?=$dimens[1];?>')">    <span class="adminThumb">
                                                        <!-- <img src="<? //= SITE_ADMIN_URL; ?>/popup_new.php?img=category/images/<? //= $arr['catImage']; ?>', '<? //= $dimens[0]; ?>', '<? //= $dimens[1]; ?>'"> -->
                                                        <img src="<?=site_url?>/uploaded-files/client-image/<?= $arr['logo_image']; ?>">
                                                    </span></a>
        <?php } ?></td>

        <td>
                                                <input name="order_<?= $arr['id']; ?>" class="form-control order" type="text" size="2" value="<?= $arr['client_order']; ?>">
                                            </td>

                                            <td>
                                                <p class="status-dcs"><?php if ($arr['status'] == 'Y') { ?><label class="badge badge-success badge-pill">Active</label><?php } else if ($arr['status'] == 'N') { ?> <label class="badge badge-danger badge-pill">In-Active</label>
                                                    <?php } ?></p>
                                            </td>
                           <td><p class="download-dcs">
                            <a href="<?=SITE_ADMIN_URL?>/addeditclient.php?catID=<?=$arr['id'];?>"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit-3"><path d="M12 20h9"></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path></svg></a>
                               </p></td>
						</tr>

 <?php  $sl++; } ?>
                       
                      </tbody>
                    </table>
                    <div class="btn-grp">
                                <button type="submit" name="active" onclick="return select_chk()" class="btn btn-success btn-icon-text btn-sm">
                                    <i class="fas fa-toggle-on mr-1"></i>Activate
                                </button>
                                <button type="submit" name="inactive" onclick="return select_chk()" class="btn btn-warning btn-icon-text btn-sm">
                                    <i class="far fa-times-circle mr-1"></i>Deactivate
                                </button>
                          
                                <button type="submit" name="action" value="Update" class="btn btn-default btn-icon-text btn-sm">
                                    <i class="far fa-check-square mr-1"></i>Update Order
                                </button>
                                <button type="submit" name="delete" onclick="return select_chk()" class="btn btn-danger btn-icon-text btn-sm">
                                    <i class="fas fa-trash-alt mr-1"></i>Delete
                                </button>

                            </div>
 </form>
                  </div>
                  
                </div>
              </div>
            </div>
          </div>
        </div>
        <script language="javascript">
function select_chk(){
var chks = document.getElementsByName('cat_arr[]');
var hasChecked = false;
for (var i = 0; i < chks.length; i++){
if (chks[i].checked){
  hasChecked = true;
  break;
  }
}
if (hasChecked == false){
alert("Please Select At Least One.");
return false;
}
}
</script>
                  <?php
                  admin_footer();
                  exit;
                  ?>