<?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 Tour Packages";
$record_type="package";
$script_name="manage_package.php";
$table_name="packages_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.uniqid().".".$ext;
		    move_uploaded_file($file_tmp=$_FILES["image"]["tmp_name"][$key],"../uploaded-files/package-images/".$newFileName);
            $destinationPath = "../uploaded-files/package-images/" . $newFileName;
            $width = "450";
            $height = "450";
    
            $source_folder = SITE_DIR_PATH . "../uploaded-files/package-images/";
            $destination_folder = SITE_DIR_PATH . "../uploaded-files/package-images/thumbs/";
            saveResizedPhoto($newFileName, $width, $height, $source_folder, $destination_folder);
		    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(" ", "-", $package_title);
          $pdf_name = $cat . "-catalog-" .uniqid();
          $pdf_catalog = upload_file($pdf_name, "catalog", "uploaded-files/pdf");
        }
      }
	$prouct_cat = implode(',',$_POST['package_id']);
  $package_title = htmlentitiesDecode($package_title);
  $product_metadesc = htmlentitiesDecode($product_metadesc);
  $metakeyword = htmlentitiesDecode($metakeyword);

    $sql=db_query("insert into $table_name set package_title='$package_title', product_metadesc='$product_metadesc', metakeyword ='$metakeyword', package_url='$package_url', location='$location', product_metatitle='$product_metatitle', package_image='$file_name1', package_desc='$package_desc', day='$day',night='$night',map='$map',catalog='$pdf_catalog',product_cat='$prouct_cat',package_desc2='$package_desc2',package_desc3='$package_desc3'");
    
		$_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 package_id='$cat_id'");
    $result = mysqli_fetch_array($delete_sql);
    if(count($result) > 0){
      $image_array = explode(',',$result['package_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 package_image='$file_name' WHERE package_id='$cat_id'");
      }	
    }
    
  }
if($id=="update_record") {
  $prod_sql = mysqli_query($dbconn,"SELECT * FROM $table_name where package_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.uniqid().".".$ext;
      move_uploaded_file($file_tmp=$_FILES["image"]["tmp_name"][$key],"../uploaded-files/package-images/".$newFileName);
      $destinationPath = "../uploaded-files/package-images/" . $newFileName;
      $width = "450";
      $height = "450";

      $source_folder = SITE_DIR_PATH . "../uploaded-files/package-images/";
      $destination_folder = SITE_DIR_PATH . "../uploaded-files/package-images/thumbs/";
      saveResizedPhoto($newFileName, $width, $height, $source_folder, $destination_folder);
      array_push($file_name_array, $newFileName);
  }

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

  }
  if ($_FILES['catalog']['name'] != "") {
    $categoryRes = mysqli_query($dbconn,"SELECT * FROM $table_name where package_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(" ", "-", $package_title);
    $pdf_name = $cat . "-catalog-" . uniqid();
    $catalogpdf = upload_file($pdf_name, "banner", "uploaded-files/pdf");
    updateTable($table_name, " catalog='$catalogpdf' where package_id='$recordID'");
    }
      $prouct_cat = implode(',',$_POST['package_id']);
         $package_title = htmlentitiesDecode($package_title);
         $product_metadesc = htmlentitiesDecode($product_metadesc);
  $metakeyword = htmlentitiesDecode($metakeyword);

        //  echo "package_title='$package_title', package_url='$package_url', product_video='$link', location='$location', product_metatitle='$product_metatitle', package_desc='$package_desc',product_cat='$prouct_cat',day='$day',night='$night',map='$map',package_desc2='$package_desc2',package_desc3='$package_desc3'";
        //  exit;
		updateTable($table_name, "package_title='$package_title', package_url='$package_url', product_video='$link', location='$location', product_metatitle='$product_metatitle', product_metadesc='$product_metadesc', metakeyword ='$metakeyword', package_desc='$package_desc',product_cat='$prouct_cat',day='$day',night='$night',map='$map',package_desc2='$package_desc2',package_desc3='$package_desc3' where package_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("delete from $table_name where package_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 package_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;
}

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 package_id='$_GET[recordID]'");
 ?>

                        <div class="form-group">
                            <label for="cate">Package Title <font color="red">*</font></label>
                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="text" name="package_title" id="package_title" class="form-control" value=""
                                placeholder="Package Title ">
                            <?php
 }
 else { ?>
                            <input type="text" name="package_title" id="package_title" class="form-control"
                                value="<?=$res['package_title']?>" placeholder="Package Title ">
                            <?php } ?>
                        </div>
                        <div class="form-group">
                            <label for="cate">Package Url <font color="red">*</font></label>
                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="text" name="package_url" class="form-control" value="" id="package_url"
                                placeholder="Package Url" readonly>
                            <?php
 }
 else { ?>
                            <input type="text" name="package_url" id="package_url" class="form-control"
                                value="<?=$res['package_url']?>" placeholder="Package Url" readonly>
                            <?php } ?>
                        </div>
                        <div class="form-group">
                            <label for="cate">Location <font color="red">*</font></label>

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="text" name="location" class="form-control" value=""
                                placeholder="Location">
                            <?php
 }
 else { ?>
                            <input type="text" name="location" class="form-control" value="<?=$res['location']?>"
                                placeholder="Location">
                            <?php } ?>
                        </div>


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

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="text" name="product_metatitle" class="form-control" value=""
                                placeholder="Meta Title">
                            <?php
 }
 else { ?>
                            <input type="text" name="product_metatitle" class="form-control" value="<?=$res['product_metatitle']?>"
                                placeholder="Meta Title">
                            <?php } ?>
                        </div>



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

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="text" name="product_metadesc" class="form-control" value=""
                                placeholder="Meta Description">
                            <?php
 }
 else { ?>
                            <input type="text" name="product_metadesc" class="form-control" value="<?=$res['product_metadesc']?>"
                                placeholder="Meta Description">
                            <?php } ?>
                        </div>




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

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <input type="text" name="metakeyword" class="form-control" value=""
                                placeholder="Meta Keyword">
                            <?php
 }
 else { ?>
                            <input type="text" name="metakeyword" class="form-control" value="<?=$res['metakeyword']?>"
                                placeholder="Meta Keyword">
                            <?php } ?>
                        </div>


                        <div class="form-group row">
                            <div class="col">
                                <label for="cate">Package Duration (Day) <font color="red">*</font></label>

                                <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                                <select class="form-control" name="day" id="day">
                                <option selected>Select Day</option>
                                    <option value="1">1 DAY</option>
                                    <option value="2">2 DAY</option>
                                    <option value="3">3 DAY</option>
                                    <option value="4">4 DAY</option>
                                    <option value="5">5 DAY</option>
                                    <option value="6">6 DAY</option>
                                    <option value="7">7 DAY</option>
                                    <option value="8">8 DAY</option>
                                    <option value="9">9 DAY</option>
                                    <option value="10">10 DAY</option>
                                    <option value="11">11 DAY</option>
                                    <option value="12">12 DAY</option>
                                    <option value="13">13 DAY</option>
                                    <option value="14">14 DAY</option>
                                    <option value="15">15 DAY</option>
                                </select>
                                <?php
 }
 else { ?>
                               <select class="form-control" name="day" id="day">
                              
                                    <option value="1" <? if ($res['day']=='1') { echo "selected"; }?>>1 DAY</option>
                                    <option value="2" <? if ($res['day']=='2') { echo "selected"; }?>>2 DAY</option>
                                    <option value="3" <? if ($res['day']=='3') { echo "selected"; }?>>3 DAY</option>
                                    <option value="4" <? if ($res['day']=='4') { echo "selected"; }?>>4 DAY</option>
                                    <option value="5" <? if ($res['day']=='5') { echo "selected"; }?>>5 DAY</option>
                                    <option value="6" <? if ($res['day']=='6') { echo "selected"; }?>>6 DAY</option>
                                    <option value="7" <? if ($res['day']=='7') { echo "selected"; }?>>7 DAY</option>
                                    <option value="8" <? if ($res['day']=='8') { echo "selected"; }?>>8 DAY</option>
                                    <option value="9" <? if ($res['day']=='9') { echo "selected"; }?>>9 DAY</option>
                                    <option value="10" <? if ($res['day']=='10') { echo "selected"; }?>>10 DAY</option>
                                    <option value="11" <? if ($res['day']=='11') { echo "selected"; }?>>11 DAY</option>
                                    <option value="12" <? if ($res['day']=='12') { echo "selected"; }?>>12 DAY</option>
                                    <option value="13" <? if ($res['day']=='13') { echo "selected"; }?>>13 DAY</option>
                                    <option value="14" <? if ($res['day']=='14') { echo "selected"; }?>>14 DAY</option>
                                    <option value="15" <? if ($res['day']=='15') { echo "selected"; }?>>15 DAY</option>
                                </select>
                                <?php } ?>
                            </div>
                            <div class="col">
                            <label for="cate">Package Duration (Night) <font color="red">*</font></label>

<?php
if($_GET['recordID']=="" || $id!="edit_record") {
?>
<select class="form-control" name="night" id="night">
<option selected>Select Night</option>
    <option value="1">1 NIGHT</option>
    <option value="2">2 NIGHT</option>
    <option value="3">3 NIGHT</option>
    <option value="4">4 NIGHT</option>
    <option value="5">5 NIGHT</option>
    <option value="6">6 NIGHT</option>
    <option value="7">7 NIGHT</option>
    <option value="8">8 NIGHT</option>
    <option value="9">9 NIGHT</option>
    <option value="10">10 NIGHT</option>
    <option value="11">11 NIGHT</option>
    <option value="12">12 NIGHT</option>
    <option value="13">13 NIGHT</option>
    <option value="14">14 NIGHT</option>
    <option value="15">15 NIGHT</option>
</select>
<?php
}
else { ?>
<select class="form-control" name="night" id="night">

    <option value="1" <? if ($res['night']=='1') { echo "selected"; }?>>1 NIGHT</option>
    <option value="2" <? if ($res['night']=='2') { echo "selected"; }?>>2 NIGHT</option>
    <option value="3" <? if ($res['night']=='3') { echo "selected"; }?>>3 NIGHT</option>
    <option value="4" <? if ($res['night']=='4') { echo "selected"; }?>>4 NIGHT</option>
    <option value="5" <? if ($res['night']=='5') { echo "selected"; }?>>5 NIGHT</option>
    <option value="6" <? if ($res['night']=='6') { echo "selected"; }?>>6 NIGHT</option>
    <option value="7" <? if ($res['night']=='7') { echo "selected"; }?>>7 NIGHT</option>
    <option value="8" <? if ($res['night']=='8') { echo "selected"; }?>>8 NIGHT</option>
    <option value="9" <? if ($res['night']=='9') { echo "selected"; }?>>9 NIGHT</option>
    <option value="10" <? if ($res['night']=='10') { echo "selected"; }?>>10 NIGHT</option>
    <option value="11" <? if ($res['night']=='11') { echo "selected"; }?>>11 NIGHT</option>
    <option value="12" <? if ($res['night']=='12') { echo "selected"; }?>>12 NIGHT</option>
    <option value="13" <? if ($res['night']=='13') { echo "selected"; }?>>13 NIGHT</option>
    <option value="14" <? if ($res['night']=='14') { echo "selected"; }?>>14 NIGHT</option>
    <option value="15" <? if ($res['night']=='15') { echo "selected"; }?>>15 NIGHT</option>
</select>
<?php } ?>
                            </div>

                        </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="package_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="package_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="package_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="package_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">Map Listing <font color="red">*</font></label>

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <textarea type="text" name="map" class="form-control" value=""
                                placeholder="Map Listing"></textarea>
                            <?php
 }
 else { ?>
                            <textarea type="text" name="map" class="form-control" value=""
                                placeholder="Map Listing">
         <?=$res['map'];?></textarea>
                            <?php } ?>
                        </div>

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

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <textarea type="text" name="package_desc" class="form-control editor" value=""
                                placeholder="Package Description"></textarea>
                            <?php
 }
 else { ?>
                            <textarea type="text" name="package_desc" class="form-control editor" value=""
                                placeholder="Package Description">
         <?=$res['package_desc'];?></textarea>
                            <?php } ?>
                        </div>

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

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <textarea type="text" name="package_desc2" class="form-control editor" value=""
                                placeholder="Trip Inclusions"></textarea>
                            <?php
 }
 else { ?>
                            <textarea type="text" name="package_desc2" class="form-control editor" value=""
                                placeholder="Trip Inclusions">
         <?=$res['package_desc2'];?></textarea>
                            <?php } ?>
                        </div>

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

                            <?php
 if($_GET['recordID']=="" || $id!="edit_record") {
	 ?>
                            <textarea type="text" name="package_desc3" class="form-control editor" value=""
                                placeholder="Trip Exclusions"></textarea>
                            <?php
 }
 else { ?>
                            <textarea type="text" name="package_desc3" class="form-control editor" value=""
                                placeholder="Trip Exclusions">
         <?=$res['package_desc2'];?></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['package_image']!=""){
	$image_array = explode(',', $res['package_image']);?>

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


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

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

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

                        <div class="display-img">
                            <ul id="sortable" data-product-id="<?= $res['package_id'] ?>">
                                <?php foreach ($image_array as $image) { ?>
                                <li class="ui-state-default" data-filename="<?= $image ?>">
                                    <img src="<?= site_url; ?>/uploaded-files/package-images/<?= $image ?>">
                                    <div class="card-footer">
                                        <a href="?id=delete&name=<?= $image ?>&cat_id=<?= $res['package_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['package_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">

                    <?php
                        $qry1= mysqli_query($dbconn,"select * from $table_name");
                        $reccnt = mysqli_num_rows($qry1);
                        $qry= mysqli_query($dbconn,"select * from $table_name order by package_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>Package Title</th>
                                        <th>Product Code</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)) { 
        $pkgID =$arr['package_id'];
        $amminities_query = mysqli_query($dbconn, "SELECT * from amminities_tbl where category_id = '$pkgID'");
      ?>
                                    <tr>
                                        <td><label class="container1"><input type="checkbox" name="pro_arr[]"
                                                    value="<?= $arr['package_id'] ?>" /> <span
                                                    class="checkmark"></span></label></td>
                                        <td><?=$sl;?></td>
                                        <td><?=$arr['package_title'];?>
                                        <p class="user-dcs">
                                                <a
                                                    href="<?= SITE_ADMIN_URL; ?>/manage-amminities.php?category_id=<?= $pkgID; ?>">
                                                    Amminities <span>[<?= mysqli_num_rows($amminities_query) ?>]</span></a>
                                            </p>
                                    </td>
                                        <td><?=$arr['location'];?></td>
                                        <td>
                                            <?php
	   if($arr['package_image']) {
$multiple_img =explode(",",$arr['package_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['package_id'];?>#bot"><i
                                                    class="fa fa-edit"></i></a>&nbsp;<a
                                                href="<?=$script_name;?>?id=delete_record&start=<?=$start;?>&pagesize=<?=$pagesize?>&recordID=<?=$arr['package_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">
                        </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() {
        $('#package_title').on('input blur', function() {
            let input = $(this).val();
            let inputResponse = removeSpecialChars(input);

            $('#package_url').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;
?>