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

@extract($_REQUEST);
if (empty($catID)) {
  $heading = "Add New Category";
} else {
  $heading = "Edit Category";
}
$res = getResult("admin_details", " where user_type='admin'");

$record_type = "New Category";
$script_name = "addeditcategory.php";
$redirect_script_name = "manage_categories.php";
$table_name = "category_tbl";
#################### Add Record ##################
if ($id == 'remove_image') {
  mysqli_query($dbconn, "UPDATE $table_name SET $field='' where catID = '$catID'");
  $_SESSION['session_message'] = $record_type . ' has been updated successfully';
  header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
  exit;
}


if ($id == 'remove_pdf') {
  mysqli_query($dbconn, "delete from catalogue_tbl where id='$del_id'");
  $_SESSION['session_message'] = $record_type . ' has been updated successfully';
  header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
  //header('Location: '.$_SERVER['REQUEST_URI']);
  exit;
}

if ($_REQUEST['action'] == "add_record" && $catName != "") {

  $catDesc = $_POST['catDesc'];
  $catDesc1 = $_POST['catDesc1'];
  $fcontent = $_POST['fcontent'];

  $numCnt = getCount($table_name, " where catName='$catName' and parentID='$parentID' and catID!='$catID' and catgType='$catgType' ");
  $count_cat = mysqli_query($dbconn, "SELECT * FROM $table_name");
  if (mysqli_num_rows($count_cat) >= $res['category_count']) {
    $_SESSION['session_message'] = '<div class="btn btn-danger"> ' . $record_type . ' count exceeds the allowed limit ['. $res[category_count] .']  </div>';
  } else {
    if ($numCnt > 0) {
      $_SESSION['session_message'] = '<div class="btn btn-warning">' . $record_type . ' already exist  </div>';
    } else {
        
      if ($_FILES['image']['name']!=" ") {
        $file_extension = strtolower(getExtension($_FILES['image']['name']));
        if ($_FILES['image']['name'] != "") {
          $cat = str_replace(" ", "-", $catName);
          $img_name = $cat . date("s");
          $img = upload_file($img_name, "image", "uploaded-files/category/images");
        }
      }
      
      $file_name_array = [];
    	if(count($_FILES['category_images']) > 0){
            if($_FILES['category_images']['name']!=''){
    		foreach($_FILES["category_images"]["tmp_name"] as $key=>$tmp_name) {
    		    $file_name=$_FILES["category_images"]["name"][$key];
    		    $file_tmp=$_FILES["category_images"]["tmp_name"][$key];
    		    $ext=pathinfo($file_name,PATHINFO_EXTENSION);   
    		    $filename=basename($file_name,$ext);
    			$filename=str_replace('.','-',$filename);
    		    $newFileName=$filename.date('dhms').".".$ext;
    		    move_uploaded_file($file_tmp=$_FILES["category_images"]["tmp_name"][$key],"../uploaded-files/category/images/".$newFileName);
    		    array_push($file_name_array, $newFileName);
    		}
    		$category_images = implode(',', $file_name_array);
            }
    	}

      if ($_FILES['banner']['name'] != "") {
        $file_extension = strtolower(getExtension($_FILES['banner']['name']));
        if ($file_extension != "jpg" && $file_extension != "gif" && $file_extension != "jpeg" && $file_extension != "png") {
          $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg,.gif,.png Format Only) </div>';
          header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
          exit;
        }
        if ($_FILES['banner']['name'] != "") {
          $cat = str_replace(" ", "-", $catName);
          $banner_name = $cat . "-banner" . date("s");
          $banner = upload_file($banner_name, "banner", "uploaded-files/category/banners");
        }
      }
      if ($_FILES['icon']['name'] != "") {
        $file_extension = strtolower(getExtension($_FILES['icon']['name']));
        if ($file_extension != "jpg" && $file_extension != "gif" && $file_extension != "jpeg" && $file_extension != "png") {
          $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg,.gif,.png Format Only) </div>';
          header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
          exit;
        }
        if ($_FILES['icon']['name'] != "") {
          $cat = str_replace(" ", "-", $catName);
          $banner_icon_name = $cat . "-banner-icon" . date("s");
          $banner_icon = upload_file($banner_icon_name, "icon", "uploaded-files/category/icons");
        }
      }
      if ($_FILES['faq_icon']['name'] != "") {
        $file_extension = strtolower(getExtension($_FILES['faq_icon']['name']));
        if ($file_extension != "jpg" && $file_extension != "gif" && $file_extension != "jpeg" && $file_extension != "png") {
          $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg,.gif,.png Format Only) </div>';
         
          header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
          exit;
        }
        if ($_FILES['faq_icon']['name'] != "") {
          $cat = str_replace(" ", "-", $catName);
          $faq_icon_name = $cat . "-faq-icon" . date("s");
          $faq_icon = upload_file($faq_icon_name, "faq_icon", "uploaded-files/category/icons");
        }
      }
      $maxRes = mysqli_fetch_array(mysqli_query($dbconn, "select max(catOrder) from `$table_name` where parentID='$parentID'"));
      $catOrder = $maxRes[0] + 1;
      if($_FILES['catalog']){
      
      $catalogname = $_FILES['catalog']['name'];
      $cimg = upload_file($catalogname, "catalog", "uploaded_files/catalog_images");
      }
      $catDesc = str_ireplace("'", "&apos;", $catDesc);
      $catDesc1 = str_ireplace("'", "&apos;", $catDesc1);
      $sql = mysqli_query($GLOBALS['dbconn'], "insert into `$table_name` set parentID='$parentID', catVideo='$catVideo', catName='$catName', displayName='$displayName', catgType='$catgType', catDesc='$catDesc', catDesc1='$catDesc1', catDesc2='$catDesc2', catImage='$img', catBanner='$banner', catIcon='$banner_icon',faq_icon='$faq_icon',catOrder='$catOrder', pageTitle='$pageTitle', pageKeywords='$pageKeywords', pageDescription='$pageDescription', footerContent='$fcontent', catalogImage='$cimg', catalogLink='$catlink',keyword1='$keyword1',keyword2='$keyword2',keyword3='$keyword3', category_images='$category_images'");
      $_SESSION['session_message'] ='<div class="btn btn-success">' . $catName . ' has been added successfully  </div> ';

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

if ($_REQUEST['action'] == "update_record" && $catName != "") {
  $catDesc = $_POST['catDesc'];
  $catDesc1 = $_POST['catDesc1'];
  $numCnt = getCount($table_name, " where catName='$catName' and parentID='$parentID' and catID!='$catID' and catgType='$catgType'");
  if ($numCnt > 0) {
    $_SESSION['session_message'] = '<div class="btn btn-warning">' . $record_type . ' already exist  </div>';
    header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
    exit;
  }

  if ($_FILES['image']['name'] != "") {
    $file_extension = strtolower(getExtension($_FILES['image']['name']));
    if ($file_extension != "jpg" && $file_extension != "gif" && $file_extension != "jpeg" && $file_extension != "png") {
      $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg,.gif,.png Format Only) </div>';
      header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
      exit;
    }
    if ($_FILES['image']['name'] != "") {
      $categoryRes = getResult($table_name, " where catID='$catID'", "catImage");
      $filename = $categoryRes['catImage'];
      if ($filename != "") {
        $file = SITE_DIR_PATH . "/uploaded-files/category/images/" . $filename;
        if (file_exists($file)) {
          unlink($file);
        }

        $file_thumb = SITE_DIR_PATH . "/uploaded-files/category/images/thumbs/" . $filename;
        if (file_exists($file_thumb)) {
          unlink($file_thumb);
        }
      }
      $cat = str_replace(" ", "-", $catName);
      $img_name = $cat . date("s");
      $img = upload_file($img_name, "image", "uploaded-files/category/images");
      updateTable($table_name, " catImage='$img' where catID='$catID'");
    }
  }
  
$file_name_array = [];
if($_FILES['category_images']){
    $category_sql = mysqli_query($dbconn,"SELECT * FROM $table_name where catID='$catID'");
	$categoryRes = mysqli_fetch_array($category_sql);
    $image = $_FILES['category_images'];
    if($image['size'][0]!=0){
    		foreach($_FILES["category_images"]["tmp_name"] as $key=>$tmp_name) {
    		    $file_name=$_FILES["category_images"]["name"][$key];
    		    $file_tmp=$_FILES["category_images"]["tmp_name"][$key];
    		    $ext=pathinfo($file_name,PATHINFO_EXTENSION);   
    		    $filename=basename($file_name,$ext);
    			$filename=str_replace('.','-',$filename);
    		    $newFileName=$filename.date('dhms').".".$ext;
    		    move_uploaded_file($file_tmp=$_FILES["category_images"]["tmp_name"][$key],"../uploaded-files/category/images/".$newFileName);
    		    array_push($file_name_array, $newFileName);
    		}
    
    		$file_name1 = implode(',', $file_name_array);
    		if($categoryRes['category_images']){
    		$file_array = explode(',',$categoryRes['category_images']);
    			$new_array = array_merge($file_array, $file_name_array);
    			$file_name1 = implode(',', $new_array);	
    		}
    			mysqli_query($dbconn,"UPDATE $table_name SET category_images='$file_name1' WHERE catID='$catID'");
    	}
    	
}
		
  if ($_FILES['banner']['name'] != "") {
    $categoryRes = getResult($table_name, " where catID='$catID'", "catImage");
    $banner_name = $categoryRes['catBanner'];
    if ($banner_name != "") {
      $banner = SITE_DIR_PATH . "/uploaded-files/category/banners/" . $banner_name;
      if (file_exists($banner)) {
        unlink($banner);
      }
    }
    $cat = str_replace(" ", "-", $catName);
    $banner_name = $cat . "-banner" . date("s");
    $banner = upload_file($banner_name, "banner", "uploaded-files/category/banners");
    updateTable($table_name, " catBanner='$banner' where catID='$catID'");
  }
  if ($_FILES['icon']['name'] != "") {
    $categoryRes = getResult($table_name, " where catID='$catID'", "catIcon");
    $icon_name = $categoryRes['catIcon'];
    if ($icon_name != "") {
      $banner = SITE_DIR_PATH . "/uploaded-files/category/banners/icons/" . $icon_name;
      if (file_exists($banner)) {
        unlink($banner);
      }
    }
    $cat = str_replace(" ", "-", $catName);
    $icon = $cat . "-banner-icon" . date("s");
    $cat_icon = upload_file($icon, "icon", "uploaded-files/category/icons");
    updateTable($table_name, " catIcon='$cat_icon' where catID='$catID'");
  }
  if ($_FILES['faq_icon']['name'] != "") {
    $categoryRes = getResult($table_name, " where catID='$catID'", "faq_icon");
    $icon_name = $categoryRes['faq_icon'];
    if ($icon_name != "") {
      $banner = SITE_DIR_PATH . "/uploaded-files/category/banners/icons/" . $icon_name;
      if (file_exists($banner)) {
        unlink($banner);
      }
    }
    $cat = str_replace(" ", "-", $catName);
    $faq_icon1 = $cat . "-faq-icon" . date("s");
    $faq_icon = upload_file($faq_icon1, "faq_icon", "uploaded-files/category/icons");
    updateTable($table_name, " faq_icon='$faq_icon' where catID='$catID'");
  }

$c_name = implode(",", $c_name);
$countArr = count($c_name);

if($countArr > 0)
{
for($i=0;$i<$countArr;$i++)
{

  $uploads_dir = SITE_DIR_PATH.'/uploaded-files/catalog_images';
  $pdf_file =  $_FILES['c_pdf']['name'][$i];
  $extension = pathinfo($pdf_file, PATHINFO_EXTENSION );
  $file_name = str_replace(" ", "-", $c_name[$i]);
  $pdf_final = $file_name . $i . date("is").'.'.$extension;

//   $sql_s = mysqli_query($GLOBALS['dbconn'], "insert into catalogue_tbl set catelogue_title='$c_name[$i]',catelogue_image='$pdf_final', categoryID='$catID'");

         $tmp_name = $_FILES["c_pdf"]["tmp_name"][$i];
         
        //  move_uploaded_file($tmp_name, "$uploads_dir/$pdf_final");

 }
}

$catDesc = str_ireplace("'", "&apos;", $catDesc);
$catDesc1 = str_ireplace("'", "&apos;", $catDesc1);
  updateTable($table_name, " catName='$catName', displayName='$displayName', catgType='$catgType', catVideo='$catVideo', catDesc='$catDesc', catDesc1='$catDesc1', catDesc2='$catDesc2', pageTitle='$pageTitle', pageKeywords='$pageKeywords', pageDescription='$pageDescription', footerContent='$fcontent', catalogLink='$catlink',keyword1='$keyword1',keyword2='$keyword2',keyword3='$keyword3' where catID='$catID'");
  $_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been added successfully  </div>';
   
  header("Location: " . SITE_ADMIN_URL . "/" . $redirect_script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
  exit;
}

if($_REQUEST['id'] == 'delete'){
    $image_name = $_GET['name'];
    $category_id = $_GET['cat_id'];
    unlink( SITE_DIR_PATH . "/uploaded-files/category/images".$image_name);
    $select_img = mysqli_query($GLOBALS['dbconn'], "select category_images from $table_name where catID='$category_id'");
    $res_img = mysqli_fetch_array($select_img);
    $cat_images = str_replace($image_name, '', $res_img['category_images']);
    $cat_images = str_replace(",,", ",", $cat_images);
    $cat_images = rtrim($cat_images,",");

    mysqli_query($GLOBALS['dbconn'], "update ".$table_name." set category_images='$cat_images' where catID='$category_id'");
    header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?catID=" . $category_id . "&parentID=" . $parentID);
  exit;
}

########################################################
admin_header();
?>

<div align="left" class="myTitle"><?= $heading; ?></div>
<hr size="2" width="100%" color="#92B2D6">
<?php
print_message();
$res = getResult($table_name, " where catID='$catID'");
//$res_pdf = getResult('catalogue_tbl', " where catID='$catID'");

$catName = $res['catName'];
$displayName = $res['displayName'];
$catDesc = $res['catDesc'];
$catDesc1 = $res['catDesc1'];
$catgType = $res['catgType'];
$pageTitle = $res['pageTitle'];
$catVideo = $res['catVideo'];
$pageKeywords = $res['pageKeywords'];
$pageDescription = $res['pageDescription'];
$footerContent = $res['footerContent'];
$catalogLink = $res['catalogLink'];
$catDesc2 = $res['catDesc2'];
$keyword1 = $res['keyword1'];
$keyword2 = $res['keyword2'];
$keyword3 = $res['keyword3'];
?>
<input type="button" class="button btn btn-warning" value="Go Back <?= $record_type; ?>" onclick="window.location.href = '<?= SITE_ADMIN_URL ?>/<?= $redirect_script_name; ?>?parentID=<?= $parentID; ?>&catID=<?= $catID; ?>&start=<?= $start; ?>&pagesize=<?= $pagesize; ?>';" style="float: right;
    margin-bottom: 25px;">
   
      <br />

<form name="formn" method="post" action="" enctype="multipart/form-data" onsubmit="return validate(this);">
  <?= $msg; ?>
  <div class="form-group">
    <label for="catName">Category Name *:</label>
    <input type="text" class="form-control txtfieldadmin" value="<?= $catName ?>" placeholder="Enter Category Name" name="catName">
  </div>
  <div class="form-group">
    <label for="displayName">Display Name *:</label>
    <input type="text" class="form-control txtfieldadmin" value="<?= $displayName ?>" placeholder="Enter Category Display Name" name="displayName">
  </div>
    <div class="form-group">
    <label for="catVideo">Video Link *:</label>
    <input type="text" class="form-control txtfieldadmin" value="<?= $catVideo ?>" placeholder="Enter Category Video Link" name="catVideo">
  </div>
  <div class="form-group">
    <label for="email">Meta Title *:</label>
    <input type="text" class="form-control txtfieldadmin"  value="<?= $pageTitle ?>" placeholder="Enter Meta Title" name="pageTitle">
  </div>
  <div class="form-group">
    <label for="pageKeywords">Meta Keyword *:</label>
    <input type="text" class="form-control txtfieldadmin" value="<?= $pageKeywords ?>" placeholder="Enter Meta Title" name="pageKeywords">
  </div>

  <div class="form-group">
    <label for="pageDescription">Meta Description:</label>
    <textarea name="pageDescription" class="form-control" rows="5" placeholder="Enter Meta Description"><?= $pageDescription ?></textarea>
  </div>
  
  <div class="row">
      <div class="col-md-4">
           <div class="form-group">
               <label for="keyword1" class="text-danger">KeyWord 1:</label>
     <input type="text" class="form-control txtfieldadmin" value="<?=$keyword1;?>" placeholder="Enter Keyword1" name="keyword1">
  </div>
      </div>
       <div class="col-md-4">
           <div class="form-group">
    <label for="comment" class="text-danger">KeyWord 2:</label>
     <input type="text" class="form-control txtfieldadmin" value="<?=$keyword2;?>" placeholder="Enter Keyword2" name="keyword2">
  </div>
      </div> <div class="col-md-4">
           <div class="form-group">
   <label for="keyword3" class="text-danger">KeyWord 3:</label>
     <input type="text" class="form-control txtfieldadmin" value="<?=$keyword3;?>" placeholder="Enter Keyword3" name="keyword3">
  </div>
      </div>
  </div>
  <div class="form-group">
    <label for="catDesc">Short Description:</label>
    <textarea name="catDesc"  class="form-control" rows="5"><?= $catDesc ?></textarea>
  </div>
  <div class="form-group">
    <label for="catDesc1">Description:</label>
    <textarea name="catDesc1" id="catDesc1" class="form-control" rows="5"><?= $catDesc1 ?></textarea>
  </div>
  <div class="form-group">
    <label for="catDesc2">Description 2:</label>
    <textarea name="catDesc2" id="catDesc2" class="form-control" rows="5"><?= $catDesc2 ?></textarea>
  </div>
  <div class="form-group">
    <label for="image">Category Image *:</label>
    <input type="file" class="form-control txtfieldadmin" name="image">
    <?php
    if ($res['catImage'] != "") {
      $file1 = SITE_DIR_PATH . "/uploaded-files/category/images/" . $res['catImage'];

      $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=category/images/<?= $res['catImage']; ?>', '<?= $dimens[0]; ?>', '<?= $dimens[1]; ?>')" class="linkgray fontbold"><strong>&nbsp;View Image</strong></a>&nbsp; <strong><a href="<?= SITE_ADMIN_URL ?>/addeditcategory.php?catID=<?= $catID ?>&id=remove_image&field=catImage">Remove</a></strong>
      <?php
    }
    ?>
    <br/><strong>Image Size: Please upload square image for better view.</strong>
  </div>
  <div class="form-group">
    <label for="email">Category Banner *:</label>
    <input type="file" class="form-control txtfieldadmin" name="banner">
    <?php
    if ($res['catBanner'] != "") {
      $file1 = SITE_DIR_PATH . "/uploaded-files/category/banners/" . $res['catBanner'];
      if (file_exists($file1)) {
        $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=category/banners/<?= $res['catBanner']; ?>', '<?= $dimens[0]; ?>', '<?= $dimens[1]; ?>')" class="linkgray fontbold"><strong>&nbsp;View Image</strong></a>&nbsp; <strong><a href="<?= SITE_ADMIN_URL ?>/addeditcategory.php?catID=<?= $catID ?>&id=remove_image&field=catBanner">Remove</a></strong>
        <?php
      }
    }
    ?>

  </div>
  <div class="form-group">
      <label for="category_images">Multiple Category Image<font color="red">*</font></label>
        <input type="file" name="category_images[]" class="form-control" multiple size="60" value="" id="NOBLANK~Please enter Person Name.~DM~" />
    </div>
    <?php
if($res['category_images']!=""){
	$image_array = explode(',', $res['category_images']);?>
	
	<div class="display-img">
	<ul>
	<?php foreach($image_array as $image){?>
				<li>
					
						
<img src="<?=site_url;?>/uploaded-files/category/images/<?= $image ?>">
					
						<div class="card-footer">
							<a href="?id=delete&name=<?= $image ?>&cat_id=<?= $res['catID'] ?>&parentID=<?= $res['parentID'] ?>" onclick="confirm('Do you want to delete the image?')">Delete</a>
						</div>
				
				</li>
			<?php } ?>
	</ul>
</div>
<?php } ?>
  <div class="form-group">
    <!--<label for="email">Category Banner *:</label>-->
    <!--<input type="file" class="form-control txtfieldadmin" name="icon">-->
    <?php
    if ($res['catIcon'] != "") {
      $file2 = SITE_DIR_PATH . "/uploaded-files/category/icons/" . $res['catIcon'];
      if (file_exists($file2)) {
        $dimens = GetImageSize($file2);
        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=category/icons/<?= $res['catIcon']; ?>', '<?= $dimens[0]; ?>', '<?= $dimens[1]; ?>')" class="linkgray fontbold"><strong>&nbsp;View Image</strong></a>&nbsp; <strong><a href="<?= SITE_ADMIN_URL ?>/addeditcategory.php?catID=<?= $catID ?>&id=remove_image&field=catIcon">Remove</a></strong>
        <?php
      }
    }
    ?>
  </div>
  <div class="form-group">
    <!--<label for="email">Category Banner *:</label>-->
    <!--<input type="file" class="form-control txtfieldadmin" name="faq_icon">-->
    <?php
    if ($res['faq_icon'] != "") {
      $file2 = SITE_DIR_PATH . "/uploaded-files/category/icons/" . $res['faq_icon'];
      if (file_exists($file2)) {
        $dimens = GetImageSize($file2);
        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=category/icons/<?= $res['faq_icon']; ?>', '<?= $dimens[0]; ?>', '<?= $dimens[1]; ?>')" class="linkgray fontbold"><strong>&nbsp;View Image</strong></a>&nbsp; <strong><a href="<?= SITE_ADMIN_URL ?>/addeditcategory.php?catID=<?= $catID ?>&id=remove_image&field=faq_icon">Remove</a></strong>
        <?php
      }
    }
    ?>
  </div>
  <?php
          if ($res['catID']!='') {
            ?>
  <div class="table-responsive">
<table class="table table-bordered" id="dynamic_field">
<label for="Catelogue">Catelogue File :</label>
<tr>
<td><input type="text" name="c_name[]" placeholder="Catalogue Title" class="form-control name_list" /></td>
<td><input type="file" name="c_pdf[]" class="form-control name_list" /></td>
<td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>
</tr>

<?php }?>
</table>


<table class="table table-bordered">
<?php $sql_pdf = mysqli_query($GLOBALS['dbconn'],"select * from catalogue_tbl where categoryID='$catID'");
       if(mysqli_num_rows($sql_pdf) > 0){
      while($res_pdf = mysqli_fetch_assoc($sql_pdf))
      {?>
<tr>

        <td><input type="text" value="<?=$res_pdf['catelogue_title'];?>" class="form-control name_list" /></td>
        <td><a href="<?=site_url;?>/uploaded-files/catalogue/<?=$res_pdf['catelogue_image'];?>" download><span class="glyphicon glyphicon-download-alt"></span></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?=SITE_ADMIN_URL;?>/addeditcategory.php?del_id=<?=$res_pdf['id'];?>&id=remove_pdf&catID=<?= $catID; ?>&start=<?= $start; ?>&pagesize=<?= $pagesize; ?>"><span class="glyphicon glyphicon-trash"></span></a></td>
</tr>
<?php }}?>
</table>


    <div class="col-md-12 submitbtntop"> 
          <?php
          if ($res['catID'] == "") {
            ?>
            <input type="submit" name="add_record" class="button btn btn-success" value="Add <?= $record_type; ?>"><input type="hidden" name="action" value="add_record">
            <?php
          } else {
            ?>
            <input type="submit" name="update_record" class="button btn btn-success" value="Update <?= $record_type; ?>"><input type="hidden" name="action" value="update_record">
            <?php
          }
          ?>
          &nbsp;&nbsp;<input type="button" name="cancel" class="button btn btn-dark" value="Cancel" onclick="javascript: window.location.href = '<?= SITE_ADMIN_URL; ?>/<?= $redirect_script_name; ?>?parentID=<?= $parentID; ?>&catID=<?= $catID; ?>&start=<?= $start; ?>&pagesize=<?= $pagesize; ?>'">   
       
</div>
</form>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
	<script>
	        var i = 1;
	        $('#add').click(function() {
	            i++;
	            $('#dynamic_field').append('<tr id="row' + i + '"><td><input type="text" name="c_name[]" placeholder="Catalogue Title" class="form-control name_list" /></td><td><input type="file" name="c_pdf[]" placeholder="Enter your Skill" class="form-control name_list" /></td><td><button type="button" name="remove" id="' + i + '" class="btn btn-danger btn_remove">X</button></td></tr>');
	        });

	        $(document).on('click', '.btn_remove', function() {
	            var button_id = $(this).attr("id");
	            $('#row' + button_id + '').remove();
	        });

         
	</script>


<?php
admin_footer();
exit;
?>