<?php
include_once("../include/main.inc.php");
check_session('MyCpanel','index.php');

################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start)==0 or $start=="")?$start=0:$start;
$pagesize = intval($pagesize)==0?$pagesize=100:$pagesize;
if($parentID=="") {
	$parentID=1;
}
$heading="Manage Products";
$record_type="Products";
$script_name="manage_products.php";
$table_name="product_tbl";

if($id=="add_record") {
  $file_name_array = [];
	if(count($_FILES['image']) > 0){
        if($_FILES['image']['name']!=''){
		foreach($_FILES["image"]["tmp_name"] as $key=>$tmp_name) {
		    $file_name=$_FILES["image"]["name"][$key];
		    $file_tmp=$_FILES["image"]["tmp_name"][$key];
		    $ext=pathinfo($file_name,PATHINFO_EXTENSION);   
		    $filename=basename($file_name,$ext);
			$filename=str_replace('.','-',$filename);
			$filename=str_replace(' ','-',$filename);
            $newFileName=$filename.time().".".$ext;
		    move_uploaded_file($file_tmp=$_FILES["image"]["tmp_name"][$key],"../uploaded-files/product-images/".$newFileName);
		    array_push($file_name_array, $newFileName);
		}
		$file_name1 = implode(',', $file_name_array);
        }
	}
	if ($_FILES['catalog']['name'] != "") {
        $file_extension = strtolower(getExtension($_FILES['catalog']['name']));
        if ($file_extension != "jpg"   && $file_extension != "pdf") {
          $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg, .pdf Format Only) </div>';
          
          exit;
        }
        if ($_FILES['catalog']['name'] != "") {
          $cat = str_replace(" ", "-", $product_title);
          $pdf_name = $cat . "-catalog-" . date("s");
          $pdf_catalog = upload_file($pdf_name, "catalog", "uploaded-files/pdf");
        }
      }
	$prouct_cat = implode(',',$_POST['product_id']);
  $product_title = htmlentitiesDecode($product_title);
    $sql=db_query("insert into $table_name set product_title='$product_title',product_name='$product_name', product_code='$product_code', product_image='$file_name1', product_specfi='$product_specfi',  product_video='$link',catalog='$pdf_catalog',product_cat='$prouct_cat'");
    
		$_SESSION['session_message']='<div class="btn btn-success">New '.$record_type.' has been added successfully</div>';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;

	}
	

  if(isset($_REQUEST['id']) && $_REQUEST['id']=='delete'){

    $name = $_REQUEST['name'];
    $cat_id = $_REQUEST['cat_id'];
    $delete_sql = mysqli_query($dbconn,"SELECT * FROM $table_name WHERE product_id='$cat_id'");
    $result = mysqli_fetch_array($delete_sql);
    if(count($result) > 0){
      $image_array = explode(',',$result['product_image']);
      if(in_array($name, $image_array)){
        $new_array = array_diff($image_array, [$name]);
        $file_name = implode(',',$new_array);
        $table = mysqli_query($dbconn,"UPDATE $table_name SET product_image='$file_name' WHERE product_id='$cat_id'");
      }	
    }
    
  }
if($id=="update_record") {
  $prod_sql = mysqli_query($dbconn,"SELECT * FROM $table_name where product_id='$recordID'");
  $prod_res = mysqli_fetch_array($prod_sql);
  if(count($prod_res) > 0){
    $file_name_array = [];
$image = $_FILES['image'];
if($image['size'][0]!=0){
  foreach($_FILES["image"]["tmp_name"] as $key=>$tmp_name) {
      $file_name=$_FILES["image"]["name"][$key];
      $file_tmp=$_FILES["image"]["tmp_name"][$key];
      $ext=pathinfo($file_name,PATHINFO_EXTENSION);   
      $filename=basename($file_name,$ext);
    $filename=str_replace('.','-',$filename);
    $filename=str_replace(' ','-',$filename);
      $newFileName=$filename.date('s').".".$ext;
      move_uploaded_file($file_tmp=$_FILES["image"]["tmp_name"][$key],"../uploaded-files/product-images/".$newFileName);
      array_push($file_name_array, $newFileName);
  }

  $file_name1 = implode(',', $file_name_array);
  $file_array = explode(',',$prod_res['product_image']);
    $new_array = array_merge($file_array, $file_name_array);
    $file_name1 = implode(',', $new_array);	
    mysqli_query($dbconn,"UPDATE $table_name SET product_image='$file_name1' WHERE product_id='$recordID'");
}

  }
  if ($_FILES['catalog']['name'] != "") {
    $categoryRes = mysqli_query($dbconn,"SELECT * FROM $table_name where product_id='$recordID'");
    $catalog_pdf = $categoryRes['catalog'];
    if ($catalog_pdf != "") {
      $banner = SITE_DIR_PATH . "/uploaded-files/pdf/" . $catalog_pdf;
      if (file_exists($banner)) {
      unlink($banner);
      }
    }
    $cat = str_replace(" ", "-", $product_title);
    $pdf_name = $cat . "-catalog-" . date("s");
    $catalogpdf = upload_file($pdf_name, "banner", "uploaded-files/pdf");
    updateTable($table_name, " catalog='$catalogpdf' where product_id='$recordID'");
    }
      $prouct_cat = implode(',',$_POST['product_id']);
         $product_title = htmlentitiesDecode($product_title);
		updateTable($table_name, "product_title='$product_title',product_name='$product_name', product_video='$link', product_code='$product_code', product_specfi='$product_specfi',product_cat='$prouct_cat' where product_id='$recordID'");
		
		$_SESSION['session_message']='<div class="btn btn-success">'.$record_type.' has been updated successfully</div>';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;
	}
	
	else {
	
	}	
if($id=="delete_record") {
	db_query("UPDATE $table_name SET product_status = '2' where product_id='$recordID'");
	$_SESSION['session_message']='<div class="alert alert-danger" role="alert">'.$record_type.' has been deleted successfully</div>';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if(isset($feature_pro)){
	foreach($pro_arr as $id){
		mysqli_query($dbconn,"UPDATE $table_name SET product_theme = '1' where product_id='$id'");
	}
	$_SESSION['session_message']='<div class="btn btn-warning">' . $record_type . ' has been set as Feature Product</div>';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize);
		exit;
}


if (isset($_POST['make_active'])) {
    $product_id = $_POST['product_id'];
    mysqli_query($GLOBALS['dbconn'], "UPDATE product_tbl SET product_status = '1' WHERE product_id = '$product_id'");
    // Optionally, redirect to avoid resubmission
    header("Location: " . $_SERVER['PHP_SELF']);
    exit();
}

if (isset($_POST['activate']) && isset($_POST['pro_arr'])) {
    $product_ids = $_POST['pro_arr'];
    foreach ($product_ids as $id) {
        mysqli_query($GLOBALS['dbconn'], "UPDATE product_tbl SET product_status = '1' WHERE product_id = '$id'");
    }
    header("Location: " . $_SERVER['PHP_SELF']);
    exit();
}


if (isset($_POST['inactive']) && isset($_POST['pro_arr'])) {
    $product_ids = $_POST['pro_arr'];
    foreach ($product_ids as $id) {
        mysqli_query($GLOBALS['dbconn'], "UPDATE product_tbl SET product_status = '0' WHERE product_id = '$id'");
    }
    header("Location: " . $_SERVER['PHP_SELF']);
    exit();
}

admin_header("Manage $record_type");
?>
<style>
   .display-img ul {
    list-style: none;
    padding: 0;
}
.display-img li {
    display: inline-block;
    margin: 5px;
    cursor: move;
    position: relative;
}
.display-img img {
    width: 100px;
    height: auto;
}
.ui-sortable-placeholder {
    background: #f0f0f0;
    border: 2px dashed #ccc;
    width: 100px; /* Adjust according to your image size */
    height: auto;
    visibility: visible !important;
}
</style>
<div class="content-wrapper">
    <div class="page-header">
        <?php
           if($_GET['recordID']=="" || $id!="edit_record") {
	          ?>
        <h3 class="page-title">Add New <?=$record_type;?></h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?admin_url?>welcome.php">Admin</a></li>
                <li class="breadcrumb-item active" aria-current="page">Add New <?=$record_type;?></li>
            </ol>
        </nav>
        <?php }else{ ?>
        <h3 class="page-title">Edit <?=$record_type;?></h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?admin_url?>welcome.php">Admin</a></li>
                <li class="breadcrumb-item active" aria-current="page">Edit <?=$record_type;?></li>
            </ol>
        </nav>
        <?php } ?>
    </div>
    <div class="row">
        <div class="col-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <form name="bannerFrm" method=post action="" enctype="multipart/form-data"
                        onsubmit="return validate('bannerFrm') && chk_valid_date();">
                        <?php
                  if($_GET['recordID']=="" || $id!="edit_record") {
                    ?>
                        <div class="form-group">
                            <h3>Add New <?=$record_type;?></h3>
                        </div>
                        <?php
 }
 else {
	 ?>
                        <div class="form-group">
                            <h3>Edit <?=$record_type;?></h3>
                        </div>
                        <div class="form-group text-right">
                            <a href="<?=$script_name;?>" class="btn btn-primary text-white"><b>Add New
                                    <?=$record_type;?></b></a>
                        </div>
                        <?php
 }
 $res=getResult($table_name," where product_id='$_GET[recordID]'");
 ?>

                        <div class="form-group">
                            <label for="cate">Product Title <font color="red">*</font></label>
                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="text" name="product_title" id="product_title" class="form-control" value=""
                                placeholder="Product Title ">
                            <?php
 }
 else { ?>
                            <input type="text" name="product_title" id="product_title" class="form-control"
                                value="<?=$res['product_title']?>" placeholder="Product Title ">
                            <?php } ?>
                        </div>
                        <div class="form-group">
                            <label for="cate">Product Name (For Url) <font color="red">*</font></label>
                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="text" name="product_name" class="form-control" value=""
                            id="product_name"   placeholder="Product Name (Do not use special character" readonly>
                            <?php
 }
 else { ?>
                            <input type="text" name="product_name"  id="product_name" class="form-control"
                                value="<?=$res['product_name']?>" placeholder="Do not use special character " readonly>
                            <?php } ?>
                        </div>
                        <div class="form-group">
                            <label for="cate">Product Code <font color="red">*</font></label>

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="text" name="product_code" class="form-control" value=""
                                placeholder="Product Code  ">
                            <?php
 }
 else { ?>
                            <input type="text" name="product_code" class="form-control"
                                value="<?=$res['product_code']?>" placeholder="Product code ">
                            <?php } ?>
                        </div>
                        <div class="form-group">
                            <label for="cate">Product Youtube Video id <font color="red">*</font></label>

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="text" name="link" class="form-control" value=""
                                placeholder="Product Youtube Video id ">
                            <?php
 }
 else { ?>
                            <input type="text" name="link" class="form-control" value="<?=$res['product_video']?>"
                                placeholder="Product Youtube Video id ">
                            <?php } ?>
                        </div>
                        <div class="form-group">
                            <label for="cate">Select Category<font color="red">*</font></label>
                            <ul class="awardsChecks">
                                <?php
			$sql_cat = mysqli_query($dbconn, "select * from category_tbl where parentID='0'");
			while ($res_cat = mysqli_fetch_assoc($sql_cat)) {
				$catids = explode(',', $res['product_cat']);
				$checked =  in_array($res_cat['catID'], $catids) ? 'checked' : '';
			?>
                                <li class="first"><label><input type="checkbox" name="product_id[]"
                                            value="<?php echo $res_cat['catID']; ?>"
                                            <?= $checked; ?>><?php echo $res_cat['catName']; ?></label>
                                    <ul>
                                        <?php
						$sql_cat_sub = mysqli_query($dbconn, "select * from category_tbl where parentID='$res_cat[catID]'");
						while ($res_cat_sub = mysqli_fetch_assoc($sql_cat_sub)) {
							$checked =  in_array($res_cat_sub['catID'], $catids) ? 'checked' : '';
						?>
                                        <li><label><input type="checkbox" name="product_id[]"
                                                    value="<?php echo $res_cat_sub['catID']; ?>" <?= $checked; ?>>
                                                <?php echo $res_cat_sub['catName']; ?></label>
                                            <ul class="line_one">
                                                <?php
						$sql_cat_subsub = mysqli_query($dbconn, "select * from category_tbl where parentID='$res_cat_sub[catID]'");
						while ($res_cat_subsub = mysqli_fetch_assoc($sql_cat_subsub)) {
							$checked =  in_array($res_cat_subsub['catID'], $catids) ? 'checked' : '';
						?>
                                                <li><label><input type="checkbox" name="product_id[]"
                                                            value="<?php echo $res_cat_subsub['catID']; ?>"
                                                            <?= $checked; ?>>
                                                        <?php echo $res_cat_subsub['catName']; ?></label>
                                                    <ul>
                                                        <?php
						$sql_cat_subsubsub = mysqli_query($dbconn, "select * from category_tbl where parentID='$res_cat_subsub[catID]'");
						while ($res_cat_subsubsub = mysqli_fetch_assoc($sql_cat_subsubsub)) {
							$checked =  in_array($res_cat_subsubsub['catID'], $catids) ? 'checked' : '';
						?>
                                                        <li><label><input type="checkbox" name="product_id[]"
                                                                    value="<?php echo $res_cat_subsubsub['catID']; ?>"
                                                                    <?= $checked; ?>>
                                                                <?php echo $res_cat_subsubsub['catName']; ?></label>
                                                        </li>
                                                        <?php } ?>
                                                    </ul>
                                                </li>
                                                <?php } ?>
                                            </ul>

                                        </li>
                                        <?php } ?>
                                    </ul>
                                </li>
                                <?php } ?>
                            </ul>

                        </div>
                        <!-- <div class="form-group">
      <label for="cate">Select Category<font color="red">*</font></label>
        <select class="form-control" name="cat">
            <option>Select Category</option>
            <?php
$sql_cat=mysqli_query($dbconn,"select * from category_tbl");
while ($res_cat=mysqli_fetch_array($sql_cat))
{
?>
<option value="<?php echo $res_cat['catID']; ?>" <? if ($res['product_cat']==$res_cat['catID']) { echo "selected"; }?>><?php echo $res_cat['catName']; ?></option>
<?php
}
?>
    </select>
    </div> -->

                        <div class="form-group">
                            <label for="cate">Product Specification <font color="red">*</font></label>

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <textarea type="text" name="product_specfi" class="form-control editor" value=""
                                placeholder="Product Specification"></textarea>
                            <?php
 }
 else { ?>
                            <textarea type="text" name="product_specfi" class="form-control editor" value=""
                                placeholder="Product Specification">
         <?=$res['product_specfi'];?></textarea>
                            <?php } ?>
                        </div>
                        <div class="form-group">
                            <label for="catalog">Catalog<font color="red">*</font></label>
                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="file" name="catalog" class="form-control" size="60" value=""
                                id="NOBLANK~Please enter Person Name.~DM~" />
                            <?php }else{ ?>
                            <input type="file" name="catalog" class="form-control" size="60"
                                value="<?=$res['catalog'];?>" id="NOBLANK~Please enter Person Name.~DM~" />
                            <?php } ?>
                        </div>

                        <div class="form-group">
                            <label for="multimage">Multiple Image<font color="red">*</font></label>
                            <input type="file" name="image[]" class="form-control" multiple size="60" value=""
                                id="NOBLANK~Please enter Person Name.~DM~" />
                        </div>
                        <!-- <?php
if($res['product_image']!=""){
	$image_array = explode(',', $res['product_image']);?>

                        <div class="display-img">
                            <ul>
                                <?php foreach($image_array as $image){?>
                                <li>


                                    <img src="<?=site_url;?>/uploaded-files/product-images/<?= $image ?>">

                                    <div class="card-footer">
                                        <a href="?id=delete&name=<?= $image ?>&cat_id=<?= $res['product_id'] ?>"
                                            onclick="confirm('Do you want to delete the image?')">Delete</a>
                                    </div>

                                </li>
                                <?php } ?>
                            </ul>
                        </div>
                        <?php } ?> -->
                        <?php if ($res['product_image'] != "") {
    $image_array = explode(',', $res['product_image']);
    ?>

    <div class="display-img">
        <ul id="sortable" data-product-id="<?= $res['product_id'] ?>">
            <?php foreach ($image_array as $image) { ?>
                <li class="ui-state-default" data-filename="<?= $image ?>">
                    <img src="<?= site_url; ?>/uploaded-files/product-images/<?= $image ?>">
                    <div class="card-footer">
                        <a href="?id=delete&name=<?= $image ?>&cat_id=<?= $res['product_id'] ?>"
                           onclick="return confirm('Do you want to delete the image?')">Delete</a>
                    </div>
                </li>
            <?php } ?>
        </ul>
        <button onclick="saveOrder()" class="btn btn-success" style="margin-bottom: 1rem">Save Order</button>
    </div>

    

<?php } ?>
                        <div class="form-group">
                            <?php
   if($recordID !="") {
	   ?>
                            <input type="submit" class="btn btn-primary" name="submit" value="Update <?=$record_type;?>"
                                class="button">
                            <input type="hidden" name="recordID" value="<?=$res['product_id'];?>">
                            <input type="hidden" name="id" value="update_record">
                            <?php	   
   }
   else{
	   ?>
                            <input type="submit" class="btn btn-primary" name="submit"
                                value="Add New <?=$record_type;?>" class="button">
                            <input type="hidden" name="id" value="add_record">
                            <?php
   }
   ?>
                            <input type="hidden" name="start" value="<?=$start;?>">
                            <input type="hidden" name="pagesize" value="<?=$pagesize;?>">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="page-header">
        <h3 class="page-title">
            <?=$heading;?>
        </h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="welcome.php">Admin</a></li>
                <li class="breadcrumb-item active" aria-current="page">Products</li>
            </ol>
        </nav>
  </div>

        <div class="card">
            <div class="card-body">
                <div class="row">
                    <div class="col-12">
<!-- this is the query where only active products will display deleeted will not show -->
                        <?php
                        $qry1= mysqli_query($dbconn,"select * from $table_name");
                        $reccnt = mysqli_num_rows($qry1);
                        $qry = mysqli_query($dbconn, "SELECT * FROM $table_name WHERE product_status IN ('0', '1') ORDER BY product_id DESC");
                        // echo pageNavigation($reccnt,$pagesize,$start);
                        print_message();
                        ?>
                        <form name="formn" method="post" action="" enctype="multipart/form-data">
                            <div class="table-responsive">
                                <table id="order-listing" class="table table-bordered table-hover">
                                    <?php
                        if($reccnt>0) {
             ?>
                                    <thead>
                                        <tr>
                                        <th class="_reab">#</th>
                                        <th>S.No.</th>
                                        <th>Product Title</th>
                                        <th>Product Code</th>
                                        <th>Product status</th>
                                        <th>Product Image</th>
                                        <th>Product Feature</th>
                                        <th>Category</th>
                                        <th>Options</th>
                                        
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
	 $sl=$start+1;
      while($arr=mysqli_fetch_array($qry)) { 
      ?>
                                        <tr>
                                            <td><label class="container1"><input type="checkbox" name="pro_arr[]"
                                                        value="<?= $arr['product_id'] ?>" /> <span
                                                        class="checkmark"></span></label></td>
                                            <td><?=$sl;?></td>
                                            <td><?=$arr['product_title'];?></td>
                                            <td><?=$arr['product_code'];?></td>
                                            <!-- new condition for delete here starts -->
                                           <!-- <td>
    <?php if ($arr['product_status'] == '1') { ?>
        <label class="badge badge-success badge-pill">Active</label>
    <?php } else if ($arr['product_status'] == '2') { ?>
        <label class="badge badge-danger badge-pill">Deleted</label>
        <form method="post" action="" style="display:inline;">
            <input type="hidden" name="product_id" value="<?= $arr['product_id']; ?>">
            <button type="submit" name="make_active" class="btn btn-sm btn-outline-success" style="padding: 2px 8px; font-size: 12px; margin-top: 5px;">Make Active</button>
        </form>
    <?php } else { ?>
        <label class="badge badge-warning badge-pill">Unknown</label>
    <?php } ?>
</td> -->


<td>
                                                <p class="status-dcs"><?php if ($arr['product_status'] == '1') { ?><label class="badge badge-success badge-pill">Active</label><?php } else if ($arr['product_status'] == '0') { ?> <label class="badge badge-danger badge-pill">In-Active</label>
                                                     <?php 
                                             } else if ($arr['product_status'] == '2') { ?>
                                                 <label class="badge badge-secondary badge-pill">Deleted</label>
                                             <?php 
                                             } else { ?>
                                                 <label class="badge badge-warning badge-pill">Deleted</label> <!-- fallback -->
                                             <?php } ?></p>
                                            </td>

<!-- new condition for delete ends starts -->

                                            <td>
                                                <?php
	   if($arr['product_image']) {
$multiple_img =explode(",",$arr['product_image']);
		   $file1=SITE_DIR_PATH."/uploaded_files/product-images/".$multiple_img['0'];
			   $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.php?img=product-images/<?=$multiple_img['0'];?>', '<?=$dimens[0];?>', '<?=$dimens[1];?>')"
                                                    class="linkgray fontbold"><strong>View Image</strong></a>
                                                <?php
	   }

	   ?>
                                            </td>
                                            <td>
                                                <?if($arr['product_theme']==0){ echo "No";}else{ echo "Yes";}?>
                                            </td>
                                            <td>
                                                <?php
		 $cct=$arr['product_cat'];
		 $sql_cat=mysqli_query($dbconn,"select * from category_tbl where catID='$cct'");
         $res_cat=mysqli_fetch_array($sql_cat);
		 echo $res_cat['catName'];
         ?>
                                            </td>
                                            <td>&nbsp;<a
                                                    href="<?=$script_name;?>?id=edit_record&start=<?=$start;?>&pagesize=<?=$pagesize?>&recordID=<?=$arr['product_id'];?>#bot"><i
                                                        class="fa fa-edit"></i></a>&nbsp;<a
                                                    href="<?=$script_name;?>?id=delete_record&start=<?=$start;?>&pagesize=<?=$pagesize?>&recordID=<?=$arr['product_id'];?>"
                                                    onClick="return confirm('Are you sure to delete this record...');"><i
                                                        class="fa fa-trash"></i></a>
                                            </td>
                                        </tr>
                                        <?php $sl++; }  ?>
                                    </tbody>
                                    <?php } else { ?> <tr>
                                        <td>
                                            <h5>Not Record Found ... </h5>
                                        </td>
                                    </tr><?php } ?>
                                </table>
                            </div>
                            <div class="text-right">
                                <input type="submit" name="feature_pro" value="feature Product" class="btn btn-primary">
                                  <button type="submit" name="activate" onclick="return select_chk()" class="btn btn-success btn-icon-text btn-sm">
    <i class="far fa-check-circle 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>
                              
                            </div>
                      
                        </form>
                    </div>
                </div>
           
    </div>
</div>

<link rel='stylesheet' href='calendar.css' title='calendar'>
<script language="javascript" src="calendar.js"></script>
<script src="jquery.min.js"></script>
<!-- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> -->
<!-- <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> -->

<script>
$(document).ready(function() {
    $('#product_title').on('input blur', function() {
        let input = $(this).val();
        let inputResponse = removeSpecialChars(input);

        $('#product_name').val(inputResponse);


        // $.ajax({
        //     url: 'your-server-endpoint', // Replace with your server endpoint
        //     type: 'POST',
        //     data: { value: inputValue },
        //     success: function(response){
        //         $('#result').html(response);
        //     },
        //     error: function(xhr, status, error){
        //         console.error('AJAX Error: ' + status + error);
        //     }
        // });
    });
});
</script>
<script type="text/javascript">
$("#quickCity").change(function() {

    var cityid = $('#quickCity').val();

    $.ajax({

        url: "ajax99.php", //The url where the server req would we made.

        async: false,

        type: "POST", //The type which you want to use: GET/POST

        data: "cityid=" + cityid, //The variables which are going.

        dataType: "html", //Return data type (what we expect).

        //This is the function which will be called if ajax call is successful.

        success: function(data) {

            //data is the html of the page where the request is made.

            $('#locatity').html(data);

        }

    })

});
</script>
<script type="text/javascript">
$("#locatity").change(function() {

    var locatityid = $('#locatity').val();

    $.ajax({

        url: "ajax999.php", //The url where the server req would we made.

        async: false,

        type: "POST", //The type which you want to use: GET/POST

        data: "locatityid=" + locatityid, //The variables which are going.

        dataType: "html", //Return data type (what we expect).

        //This is the function which will be called if ajax call is successful.

        success: function(data) {

            //data is the html of the page where the request is made.

            $('#asd').html(data);

        }

    })

});
</script>
<script type="text/javascript">
$("#asd").change(function() {

    var asdid = $('#asd').val();

    $.ajax({

        url: "ajax9999.php", //The url where the server req would we made.

        async: false,

        type: "POST", //The type which you want to use: GET/POST

        data: "asdid=" + asdid, //The variables which are going.

        dataType: "html", //Return data type (what we expect).

        //This is the function which will be called if ajax call is successful.

        success: function(data) {

            //data is the html of the page where the request is made.

            $('#asd1').html(data);

        }

    })

});
</script>

<iframe width=174 height=189 name="gToday:normal:agenda.js" id="gToday:normal:agenda.js"
    src="<?=SITE_URL_PATH;?>/js/calendar/themes/Normal/ipopeng.htm" scrolling="no" frameborder="0"
    style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;">
</iframe>

<?php
admin_footer();
exit;
?>