<?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-category.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);
  exit;
}

if ($action == "add_record" && $catname != "") {
 
  $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>';
  } else {
    // if ($_FILES['image']['name'] != " ") {
    //   $file_extension = strtolower(getExtension($_FILES['image']['name']));
    //   if ($_FILES['image']['name'] != "") {
    //     $cat = str_replace(" ", "-", $catname);
    //     $img_name = $cat;
    //     $img = upload_file($img_name, "image", "uploaded-files/category/images");
    //   }
    // }

if (!empty($_FILES['image']['name'])) {
    $file_extension = strtolower(getExtension($_FILES['image']['name']));

    $cat = str_replace(" ", "-", strtolower(trim($catname)));
    $original_name = pathinfo($_FILES['image']['name'], PATHINFO_FILENAME);
    $original_name = str_replace(" ", "-", strtolower(trim($original_name)));

    $img_name = $cat . '-' . $original_name;

    $img = upload_file($img_name, "image", "uploaded-files/category/images");
}



    if ($_FILES['catIcon']['name'] != " ") {
      $file_extension = strtolower(getExtension($_FILES['catIcon']['name']));
      if ($_FILES['catIcon']['name'] != "") {
        $cat1 = str_replace(" ", "-", $catname);
        $img_name1 = $cat1;
        $img1 = upload_file($img_name1, "catIcon", "uploaded-files/category/caticon");

        $width = "242";
        $height = "242";

        $source_folder = SITE_DIR_PATH . "/uploaded-files/category/caticon";
        $destination_folder = SITE_DIR_PATH . "/uploaded-files/category/caticon/thumbs/";
        saveResizedPhoto($img1, $width, $height, $source_folder, $destination_folder);
      }
    }


    if ($_FILES['header_icon_image']['name'] != " ") {
      $file_extension = strtolower(getExtension($_FILES['header_icon_image']['name']));
      if ($_FILES['header_icon_image']['name'] != "") {
        $cat1 = str_replace(" ", "-", $catname);
        $img_name1 = $cat1 . uniqid();
        $img1 = upload_file($img_name1, "header_icon_image", "uploaded-files/category/caticon");

        $width = "50";
        $height = "50";

        $source_folder = SITE_DIR_PATH . "/uploaded-files/category/caticon";
        $destination_folder = SITE_DIR_PATH . "/uploaded-files/category/caticon/thumbs/";
        saveResizedPhoto($img1, $width, $height, $source_folder, $destination_folder);
      }
    }


    if ($_FILES['cat_home_image']['name'] != " ") {
      $file_extension = strtolower(getExtension($_FILES['cat_home_image']['name']));
      if ($_FILES['cat_home_image']['name'] != "") {
        $cat1 = str_replace(" ", "-", $catname);
        $img_name1 = $cat1 . uniqid();
        $img2 = upload_file($img_name1, "catIcon", "uploaded-files/category/images");

        //Thumb Cut
        $width = "242";
        $height = "242";

        $source_folder = SITE_DIR_PATH . "/uploaded-files/category/images";
        $destination_folder = SITE_DIR_PATH . "/uploaded-files/category/images/thumbs/";
        saveResizedPhoto($img2, $width, $height, $source_folder, $destination_folder);
      }
    }

    if ($_FILES['catHeadingImage']['name'] != " ") {
      $file_extension = strtolower(getExtension($_FILES['catHeadingImage']['name']));
      if ($_FILES['catHeadingImage']['name'] != "") {
        $cat1 = str_replace(" ", "-", $catname);
        $img_name1 = $cat1 . uniqid();
        $img3 = upload_file($img_name1, "catHeadingImage", "uploaded-files/category/images");

        //Thumb Cut
        $width = "636";
        $height = "380";

        $source_folder = SITE_DIR_PATH . "/uploaded-files/category/images";
        $destination_folder = SITE_DIR_PATH . "/uploaded-files/category/images/thumbs/";
        saveResizedPhoto($img2, $width, $height, $source_folder, $destination_folder);
      }
    }
    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(count($_FILES['m_image']) > 0){
      if($_FILES['m_image']['name']!=''){
        $file_name_array = [];
  foreach($_FILES["m_image"]["tmp_name"] as $key=>$tmp_name) {
      $file_name=$_FILES["m_image"]["name"][$key];
      $file_tmp=$_FILES["m_image"]["tmp_name"][$key];
      $ext=pathinfo($file_name,PATHINFO_EXTENSION); 
      if($filename)  { 
      $filename=basename($file_name,$ext);
  }
    $filename=str_replace('.','-',$filename);
    $filename=str_replace(' ','-',$filename);
    if($filename) {
          $newFileName=$filename.time().".".$ext;
      move_uploaded_file($file_tmp=$_FILES["m_image"]["tmp_name"][$key],"../uploaded-files/category/images/".$newFileName);
      array_push($file_name_array, $newFileName);
    }
  }
  $file_name1 = implode(',', $file_name_array);
      }
}
    $maxRes = mysqli_fetch_array(mysqli_query($dbconn, "select max(catOrder) from `$table_name` where parentID='$parentID'"));
    $catOrder = $maxRes[0] + 1;
    // $catgurl = getValidFileName($catname);
    // $catalogname = $_FILES['catalog']['name'];
    // $cimg = upload_file($catalogname, "catalog", "uploaded_files/catalog_images");
    // echo $sql_insert = "insert into `$table_name` set parentID='$parentID',catName='".$catname."',displayName='".$catDname."',catgurl='$catgurl',catDesc='".$shortdesc."',catDesc1='".$fulldesc."',catImage='".$img."',catOrder='$catOrder',pageTitle='".$metatitle."',pageKeywords='".$metakeyword."',pageDescription='".$metadesc."', gst='$gst',mca='$mca',epf='$epf',iec='$iec',ptr='$ptr',eticket='$eticket',cp='$cp',cbe='$cbe',etp='$etp',vb='$vb',dgft='$dgft',iet='$iet'";
    // die();
    // $keywords =  htmlentitiesDecode($keywords);
    $catName = htmlentitiesDecode($catName);
    $catDname = htmlentitiesDecode($catDname);
    $keyword1 = htmlentitiesDecode($keyword1);
    $keyword2 = htmlentitiesDecode($keyword2);
    $keyword3 = htmlentitiesDecode($keyword3);
    $shortdesc = htmlentitiesDecode($shortdesc);
    $catDesc = htmlentitiesDecode($catDesc);
    $sql = mysqli_query($GLOBALS['dbconn'], "insert into `$table_name` set parentID='$parentID',catName='" . $catname . "',catUrl='" . $catUrl . "',displayName='" . $catDname . "',catDesc='" . $shortdesc . "',catDesc1='" . $fulldesc . "',catDesc2='" . $fulldesc2 . "',catImage='" . $img . "',cat_home_image='$img2',catOrder='$catOrder',catIcon='$img1',heading1='" . $heading1 . "',heading2='" . $heading2 . "',heading3='" . $heading3 . "',pageTitle='" . $metatitle . "',pageKeywords='" . $metakeyword . "',pageDescription='" . $metadesc . "',alt='" . $alt . "',title='" . $title . "',is_redirect='" . $is_redirect . "',redirect_link='" . $redirect_link . "',header_icon_image='" . $header_icon_image . "',catHeading1='$catHeading1',catHeading2='$catHeading2',catHeading3='$catHeading3',catHeadingButton='$catHeadingButton',catHeadingLink='$catHeadingLink',catHeadingImage='$img3',
catHeadingImageAlt='$catHeadingImageAlt',catHeadingImageTitle='$catHeadingImageTitle',catBanner='$banner',keyword1='$keyword1',keyword2='$keyword2',keyword3='$keyword3',multi_image='$file_name1'");

//insert data in wps_meta
$insertedcatId = mysqli_insert_id($GLOBALS['dbconn']);
    $sqlmeta = mysqli_query($GLOBALS['dbconn'], "insert into `wps_meta_tags` set 
entity_id='$insertedcatId',
page_table='$table_name',
page_url='$catUrl',
entity_type='index/category',
entity_name='category',
meta_title='$metatitle',
meta_description='$metadesc',
meta_keyword='$metakeyword',
keyword_1='$keyword1',
keyword_2='$keyword2'
 ");


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

if ($action == "update_record" && $catname != "") {


  if ($catUrl != $catOldUrl) {
    $catOldUrlUp = $catOldUrl;
  } else {
    $catOldUrlUp = $catOldUrlCheck;
  }

  $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);
    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" && $file_extension != "webp") {
      $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg,.gif,.png,.webp Format Only) </div>';
      header("Location: " . SITE_ADMIN_URL . "/" . $script_name);
      exit;
    }
    if ($_FILES['image']['name'] != "") {
      $categoryRes = getResult($table_name, " where catID='$catID'", "catImage");
      $filename = $categoryRes['catImage'];
      if ($filename != "") {
        $file = site_url . "/uploaded-files/category/images/" . $filename;
        if (file_exists($file)) {
          unlink($file);
        }

        $file_thumb = site_url . "/uploaded-files/category/images/thumbs/" . $filename;
        if (file_exists($file_thumb)) {
          unlink($file_thumb);
        }
      }
      // $cat = str_replace(" ", "-", $catname);
      // $img_name = $cat;
  $cat = str_replace(" ", "-", $catname);
        $original_name = pathinfo($_FILES['image']['name'], PATHINFO_FILENAME);
        $original_name = str_replace(" ", "-", strtolower(trim($original_name)));
        $img_name = $cat . '-' . $original_name;

      $img = upload_file($img_name, "image", "uploaded-files/category/images");
      updateTable($table_name, " catImage='$img' where catID='$catID'");
    }
  }

  if ($_FILES['catIcon']['name'] != "") {
    $file_extension = strtolower(getExtension($_FILES['catIcon']['name']));
    if ($file_extension != "jpg" && $file_extension != "gif" && $file_extension != "jpeg" && $file_extension != "png" && $file_extension != "webp") {
      $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg,.gif,.png,.webp Format Only) </div>';
      header("Location: " . SITE_ADMIN_URL . "/" . $script_name);
      exit;
    }
    if ($_FILES['catIcon']['name'] != "") {
      $categoryRes = getResult($table_name, " where catID='$catID'", "catIcon");
      $filename = $categoryRes['catIcon'];
      if ($filename != "") {
        $file = site_url . "/uploaded-files/category/caticon/" . $filename;
        if (file_exists($file)) {
          unlink($file);
        }
      }
      $cat = str_replace(" ", "-", $catname);
      $img_name = $cat;
      $img1 = upload_file($img_name, "catIcon", "uploaded-files/category/caticon");
      if ($catID == 7) {
        $width = "221";
        $height = "417";
        $source_folder = SITE_DIR_PATH . "/uploaded-files/category/caticon";
        $destination_folder = SITE_DIR_PATH . "/uploaded-files/category/caticon/thumbs/";
        saveResizedPhoto($img1, $width, $height, $source_folder, $destination_folder);
      } else {
        $width = "281";
        $height = "284";
        $source_folder = SITE_DIR_PATH . "/uploaded-files/category/caticon";
        $destination_folder = SITE_DIR_PATH . "/uploaded-files/category/caticon/thumbs/";
        saveResizedPhoto($img1, $width, $height, $source_folder, $destination_folder);
      }



      updateTable($table_name, " catIcon='$img1' where catID='$catID'");
    }
  }


  if ($_FILES['header_icon_image']['name'] != "") {
    $file_extension = strtolower(getExtension($_FILES['header_icon_image']['name']));
    if ($file_extension != "jpg" && $file_extension != "gif" && $file_extension != "jpeg" && $file_extension != "png" && $file_extension != "webp") {
      $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg,.gif,.png,.webp Format Only) </div>';
      header("Location: " . SITE_ADMIN_URL . "/" . $script_name);
      exit;
    }
    if ($_FILES['header_icon_image']['name'] != "") {
      $categoryRes = getResult($table_name, " where catID='$catID'", "header_icon_image");
      $filename = $categoryRes['header_icon_image'];
      if ($filename != "") {
        $file = site_url . "/uploaded-files/category/caticon/" . $filename;
        if (file_exists($file)) {
          unlink($file);
        }
      }
      $cat = str_replace(" ", "-", $catname);
      $img_name = $cat . uniqid();
      $img1 = upload_file($img_name, "header_icon_image", "uploaded-files/category/caticon");

      $width = "50";
      $height = "50";
      $source_folder = SITE_DIR_PATH . "/uploaded-files/category/caticon";
      $destination_folder = SITE_DIR_PATH . "/uploaded-files/category/caticon/thumbs/";
      saveResizedPhoto($img1, $width, $height, $source_folder, $destination_folder);

      updateTable($table_name, " header_icon_image='$img1' where catID='$catID'");
    }
  }


  if ($_FILES['cat_home_image']['name'] != "") {
    $file_extension = strtolower(getExtension($_FILES['cat_home_image']['name']));
    if ($file_extension != "jpg" && $file_extension != "gif" && $file_extension != "jpeg" && $file_extension != "png" && $file_extension != "webp") {
      $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg,.gif,.png,.webp Format Only) </div>';
      header("Location: " . SITE_ADMIN_URL . "/" . $script_name);
      exit;
    }
    if ($_FILES['cat_home_image']['name'] != "") {
      $categoryRes = getResult($table_name, " where catID='$catID'", "cat_home_image");
      $filename = $categoryRes['cat_home_image'];
      if ($filename != "") {
        $file = site_url . "/uploaded-files/category/images/" . $filename;
        if (file_exists($file)) {
          unlink($file);
        }
      }
      $cat = str_replace(" ", "-", $catname);
      $img_name = $cat . uniqid();
      $img1 = upload_file($img_name, "cat_home_image", "uploaded-files/category/images");

      $width = "242";
      $height = "242";

      $source_folder = SITE_DIR_PATH . "/uploaded-files/category/images";
      $destination_folder = SITE_DIR_PATH . "/uploaded-files/category/images/thumbs/";
      saveResizedPhoto($img1, $width, $height, $source_folder, $destination_folder);

      updateTable($table_name, " cat_home_image='$img1' where catID='$catID'");
    }
  }
  $prod_sql = mysqli_query($dbconn,"SELECT * FROM $table_name where catID='$catID'");
  $prod_res = mysqli_fetch_array($prod_sql);
if(count($prod_res) > 0){
  $file_name_array = [];
$image11 = $_FILES['m_image'];
if($image11['size'][0]!=0){
foreach($_FILES["m_image"]["tmp_name"] as $key=>$tmp_name) {
    $file_name=$_FILES["m_image"]["name"][$key];
    $file_tmp=$_FILES["m_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["m_image"]["tmp_name"][$key],"../uploaded-files/category/images/".$newFileName);
    array_push($file_name_array, $newFileName);
}
$file_name1 = implode(',', $file_name_array);
$file_array = explode(',',$prod_res['multi_image']);
  // $new_array = array_merge($file_array, $file_name_array);
  $new_array = array_diff($file_name_array, $file_array);
    $file_name = implode(',',$new_array);
  $file_name1 = implode(',', $new_array);	
  mysqli_query($dbconn,"UPDATE $table_name SET multi_image='$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['catHeadingImage']['name'] != "") {
    $file_extension = strtolower(getExtension($_FILES['catHeadingImage']['name']));
    if ($file_extension != "jpg" && $file_extension != "gif" && $file_extension != "jpeg" && $file_extension != "png" && $file_extension != "webp") {
      $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg,.gif,.png,.webp Format Only) </div>';
      header("Location: " . SITE_ADMIN_URL . "/" . $script_name);
      exit;
    }
    if ($_FILES['catHeadingImage']['name'] != "") {
      $categoryRes = getResult($table_name, " where catID='$catID'", "catHeadingImage");
      $filename = $categoryRes['catHeadingImage'];
      if ($filename != "") {
        $file = site_url . "/uploaded-files/category/images/" . $filename;
        if (file_exists($file)) {
          unlink($file);
        }
      }
      $cat = str_replace(" ", "-", $catname);
      $img_name = $cat . uniqid();
      $img3 = upload_file($img_name, "catHeadingImage", "uploaded-files/category/images");

      $width = "636";
      $height = "380";

      $source_folder = SITE_DIR_PATH . "/uploaded-files/category/images";
      $destination_folder = SITE_DIR_PATH . "/uploaded-files/category/images/thumbs/";
      saveResizedPhoto($img1, $width, $height, $source_folder, $destination_folder);

      updateTable($table_name, " catHeadingImage='$img3' where catID='$catID'");
    }
  }

  $catName = htmlentitiesDecode($catName);
  $catDname = htmlentitiesDecode($catDname);
  $keyword1 = htmlentitiesDecode($keyword1);
  $keyword2 = htmlentitiesDecode($keyword2);
  $keyword3 = htmlentitiesDecode($keyword3);
  $shortdesc = htmlentitiesDecode($shortdesc);
  $catDesc = htmlentitiesDecode($catDesc);
  //update meta tags
  mysqli_query($GLOBALS['dbconn'], "UPDATE wps_meta_tags SET 
page_url='$catUrl',
entity_type='index/category',
entity_name='category',
meta_title='$metatitle',
meta_description='$metadesc',
meta_keyword='$metakeyword',
keyword_1='$keyword1',
keyword_2='$keyword2'
where entity_id='$catID' AND entity_name='category' AND  page_table='$table_name'");

  $q = updateTable($table_name, " pageDescription='" . $metadesc . "', catName='" . $catname . "',catUrl='" . $catUrl . "',catOldUrl='" . $catOldUrlUp . "', displayName='" . $catDname . "', catDesc='" . $shortdesc . "',catDesc1='" . $fulldesc . "', heading1='" . $heading1 . "',heading2='" . $heading2 . "',heading3='" . $heading3 . "',pageTitle='" . $metatitle . "', pageKeywords='" . $metakeyword . "',alt='" . $alt . "',title='" . $title . "',is_redirect='" . $is_redirect . "',redirect_link='" . $redirect_link . "',catHeading1='$catHeading1',catHeading2='$catHeading2',catHeading3='$catHeading3',catHeadingButton='$catHeadingButton',catHeadingLink='$catHeadingLink',catHeadingImageAlt='$catHeadingImageAlt',catHeadingImageTitle='$catHeadingImageTitle',keyword1='$keyword1',keyword2='$keyword2',keyword3='$keyword3',catDesc2='$fulldesc2' where catID='$catID'");

  $_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been added successfully  </div>';

  //echo mysqli_error($db);

  //header("Location: " . SITE_ADMIN_URL . "/" . $redirect_script_name);

  header("Location: " . SITE_ADMIN_URL . "/" . $redirect_script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
  exit;
}
########################################################
admin_header();
$res = getResult($table_name, " where catID='$catID'");

$qryTool = db_query("select * from category_tooltip_tbl where cat_id='$catID'");


?>
<div class="content-wrapper">
    <div class="page-header">
        <h3 class="page-title">
            <?= $heading; ?>
        </h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="nav-item d-none d-lg-flex">
                    <a class="nav-link" href="<?= admin_url ?>manage-category.php?parentID=<?= $parentID; ?>">
                        <span class="btn btn-primary">Go Back</span>
                    </a>
                </li>
            </ol>
        </nav>
    </div>
    <div class="row">

        <div class="col-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <form class="forms-sample" id="formSample" method="post" action="" enctype="multipart/form-data"
                        onsubmit="return validate(this);">
                        <div class="form-group row">
                            <div class="col">
                                <label>Category Name *</label>
                                <div id="the-basics">
                                    <input class="typeahead" type="text" id="catName" name="catname"
                                        placeholder="Category Name" value="<?= $res['catName'] ?>" required>
                                </div>
                            </div>
                            <div class="col">
                                <label>Category Display Name</label>
                                <div id="bloodhound">
                                    <input class="typeahead" type="text" name="catDname"
                                        value="<?= $res['displayName'] ?>" placeholder="Category Display Name" required>
                                </div>
                            </div>
                        </div>
                        <!-- <div class="form-group row">
              <div class="col">
                <label>Heading 1</label>
                <div id="the-basics">
                  <input class="typeahead" type="text" name="heading1" value="<?= $res['heading1'] ?>"
                    placeholder="Heading 1">
                </div>
              </div>
              <div class="col">
                <label>Heading 2</label>
                <div id="bloodhound">
                  <input class="typeahead" type="text" name="heading2" value="<?= $res['heading2'] ?>"
                    placeholder="Heading 2">
                </div>
              </div>
            </div> -->
                        <div class="form-group">
                            <label for="exampleTextarea1">Category URL*</label>
                            <input class="typeahead" type="text" id="catUrl" name="catUrl" readonly
                                value="<?= $res['catUrl']; ?>" placeholder="Category URL">

                            <input class="typeahead" type="hidden" id="catOldUrl" name="catOldUrl" readonly
                                value="<?= $res['catUrl']; ?>" placeholder="Category Old URL">

                            <input class="typeahead" type="hidden" id="catOldUrlCheck" name="catOldUrlCheck" readonly
                                value="<?= $res['catOldUrl']; ?>" placeholder="Category Old URL Pass">
                        </div>



                       





                      

                     

                        <div class="cmmt_nav mb-5">
                            <ul class="nav nav-tabs" id="myTab" role="tablist">
                                <li class="nav-item">
                                    <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab"
                                        aria-controls="home" aria-selected="true">Category Header section</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab"
                                        aria-controls="profile" aria-selected="false">Standard Meta Keywords</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab"
                                        aria-controls="contact" aria-selected="false">Manual Meta titles, Description, Keywords</a>
                                </li>
                            </ul>
                            <div class="tab-content" id="myTabContent">
                                <div class="tab-pane fade show active" id="home" role="tabpanel"
                                    aria-labelledby="home-tab">
                                
                                        <div class="form-row">
                                            <div class="form-group col-md-6">
                                                <label for="inputEmail4">Heading 1 </label>
                                                <input type="text" class="form-control" id="catHeading1" placeholder=""
                                                    name="catHeading1" value="<?= $res['catHeading1'] ?>">
                                            </div>
                                            <div class="form-group col-md-6">
                                                <label for="inputPassword4">Heading 2 </label>
                                                <input type="text" class="form-control" id="catHeading2"
                                                    placeholder="" name="catHeading2" value="<?= $res['catHeading2'] ?>">
                                            </div>
                                        </div>
                                       

                                     
                                       
                                </div>
                                <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
                                <div class="form-row">
                                            <div class="form-group col-md-4">
                                                <label for="inputEmail4">Keyword 1 </label>
                                                <input type="text" class="form-control" id="keyword1" placeholder=""
                                                    name="keyword1" value="<?= $res['keyword1'] ?>">
                                            </div>
                                            <div class="form-group col-md-4">
                                                <label for="inputPassword4">Keyword 2 </label>
                                                <input type="text" class="form-control" id="keyword2"
                                                    placeholder="" name="keyword2" value="<?= $res['keyword2'] ?>">
                                            </div>
                                            <div class="form-group col-md-4">
                                                <label for="inputPassword4">Keyword 3 </label>
                                                <input type="text" class="form-control" id="keyword3"
                                                    placeholder="" name="keyword3" value="<?= $res['keyword3'] ?>">
                                            </div>
                                        </div>
                                </div>
                                <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
                                <div class="form-group ">
                            <label for="exampleTextarea1">Meta Title</label>
                            <input class="typeahead" type="text" name="metatitle" value="<?= $res['pageTitle'] ?>"
                                placeholder="Meta Title">
                        </div>
                        <div class="form-group">
                            <label for="exampleTextarea1">Meta Keyword</label>
                            <input class="typeahead" type="text" name="metakeyword" value="<?= $res['pageKeywords'] ?>"
                                placeholder="Meta Keyword">
                        </div>
                        <div class="form-group">
                            <label for="exampleTextarea1">Meta Description</label>
                            <textarea class="form-control" name="metadesc"><?= $res['pageDescription'] ?></textarea>
                        </div>
                                </div>
                            </div>
                        </div>

                      

                        <div class="form-group">
                            <label for="exampleTextarea1">Category Short Description</label>
                            <textarea class="form-control" name="shortdesc"
                                rows="6"><?= $res['catDesc'] ?></textarea>
                        </div>
                        <div class="form-group">
                            <label for="exampleTextarea1">Category Description</label>
                            <textarea class="form-control editor" name="fulldesc"
                                rows="4"><?= $res['catDesc1'] ?></textarea>
                        </div>
                        <div class="form-group">
                            <label for="exampleTextarea1">Category Description 2</label>
                            <textarea class="form-control editor" name="fulldesc2"
                                rows="4"><?= $res['catDesc2'] ?></textarea>
                        </div>
                        <!-- <div class="form-group">
              <label for="exampleTextarea1">Uses of Certificate</label>
              <textarea class="form-control editor" name="certificateUsed"
                rows="4"><?= $res['certificateUsed'] ?></textarea>
            </div> -->

                        <?php
            if ($res['catID'] == "") { ?>
                        <div class="form-group row">
                            <div class="col">
                                <label for="exampleTextarea1">Category Image</label>
                                <input type="file" class="dropify" name="image">
                            </div>


                            <div class="col">
                                <label>Alt </label>

                                <input class="typeahead" type="text" name="alt" placeholder="Image Alt"
                                    value="<?= $res['alt'] ?>">
                            </div>
                            <div class="col">
                                <label>Title </label>

                                <input class="typeahead" type="text" name="title" placeholder="Image Title"
                                    value="<?= $res['title'] ?>">
                            </div>



                        </div>
                        <?php } else { ?>
                        <div class="form-group row">
                            <div class="col">
                                <label>Category Image</label>
                                <input type="file" class="dropify" name="image">
                            </div>
                            <div class="col">
                                <label>Alt </label>

                                <input class="typeahead" type="text" name="alt" placeholder="Image Alt"
                                    value="<?= $res['alt'] ?>">
                            </div>
                            <div class="col">
                                <label>Title </label>

                                <input class="typeahead" type="text" name="title" placeholder="Image Title"
                                    value="<?= $res['title'] ?>">
                            </div>

<?php if($res['catImage']!='')
{?>
                            <div class="col">
                                <img src="<?= site_url . "/uploaded-files/category/images/" . $res['catImage'] ?>"
                                    alt="image" width="200" height="200">
                            </div>
                            <?php }?>


                        </div>
                        <?php   } ?>

                        <?php
            if ($res['catID'] == "") { ?>
                        <div class="form-group">
                            <label for="exampleTextarea1">Category Home Image (500 X 500 Px)</label>
                            <input type="file" class="dropify" name="cat_home_image">
                        </div>
                        <?php } else { ?>
                        <div class="form-group row">
                            <div class="col">
                                <label>Category Home Image</label>
                                <input type="file" class="dropify" name="cat_home_image">
                            </div>
                            <?php if($res['cat_home_image']!='')
                            {?>
                            <div class="col">
                                <img src="<?= site_url . "/uploaded-files/category/images/" . $res['cat_home_image'] ?>"
                                    alt="image" width="200" height="200">
                            </div>
                            <?php }?>
                        </div>
                        <?php   } ?>

                        <?php
            if ($res['catID'] == "") { ?>
                        <div class="form-group">
                            <label for="exampleTextarea1">Category Banner Image</label>
                            <input type="file" class="dropify" name="banner">
                        </div>
                        <?php } else { ?>
                        <div class="form-group row">
                            <div class="col">
                                <label>Category Banner Image</label>
                                <input type="file" class="dropify" name="banner">
                            </div>
                            <?php if($res['catBanner']!='')
                            {?>
                            <div class="col">
                                <img src="<?= site_url . "/uploaded-files/category/banners/" . $res['catBanner'] ?>"
                                    alt="image" width="800" height="400">
                            </div>
                            <?php }?>
                        </div>
                        <?php   } ?>

                        <?php
            if ($parentID == 0) {
              if ($res['catID'] == "") { ?>
                        <div class="form-group">
                            <label for="exampleTextarea1">Category Icon</label>
                            <input type="file" class="dropify" name="catIcon">
                        </div>
                        <?php } else { ?>
                        <div class="form-group row">
                            <div class="col">
                                <label>Category Icon</label>
                                <input type="file" class="dropify" name="catIcon">
                            </div>
                        <?php if($res['catIcon']!='')
                        {?>
                            <div class="col">
                                <img src="<?= site_url . "/uploaded-files/category/caticon/" . $res['catIcon'] ?>"
                                    alt="image" width="200" height="200">
                            </div>
                            <?php }?>
                        </div>
                        <?php  }
            } ?>
<div class="form-group">
        <label for="email">Category Multiple Images *:</label>
          <input type="file" name="m_image[]" class="form-control" multiple size="60" value="" id="NOBLANK~Please enter Person Name.~DM~" />
    </div>
  <?php
if($res['multi_image']!=""){
	$image_array = explode(',', $res['multi_image']);?>
	<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="<?= SITE_ADMIN_URL ?>/addeditcategory.php?id=delete&name=<?= $image ?>&cat_id=<?= $catID ?>" onclick="confirm('Do you want to delete the image?')">Delete</a>
						</div>
				</li>
			<?php } ?>
	</ul>
</div>
<?php } ?>



                    


                        <?php
            if ($res['catID'] == "") {
            ?>
                        <button type="submit" class="btn btn-primary mr-2" name="add_record">Submit</button>
                        <input type="hidden" name="action" value="add_record">
                        <?php
            } else {
            ?>
                        <button type="submit" class="btn btn-primary mr-2" name="update_record" id="idsUp">Update</button>
                        <input type="hidden" name="action" value="update_record">
                        <?php
            }
            ?>
                        <button class="btn btn-light"
                            onclick="javascript: window.location.href = '<?= SITE_ADMIN_URL; ?>/<?= $redirect_script_name; ?>?parentID=<?= $parentID; ?>&catID=<?= $catID; ?>&start=<?= $start; ?>&pagesize=<?= $pagesize; ?>'">Cancel</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- content-wrapper ends -->

<!-- Modal -->
 
<?php
admin_footer();
?>

<script>
$(document).ready(function() {
    var autocheck = $("input[type='radio'][name='is_redirect']:checked").val();
    if (autocheck == '1') {
        $('#redirectL').show();
    }

    $("input[type='radio'][name='is_redirect']").click(function() {

        var checkedVal = $(this).val();

        if (checkedVal == '1') {
            $('#redirectL').show();
        } else {
            $('#redirectL').hide();
        }

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

        $('#catUrl').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>
var sll = 1;
$('#addMore').click(function() {
    // alert(sll);

    $('#dynamicField').append('<div id="dataLoad'+sll +'"><div class="form-row"> <div class="form-group col-md-6"> <label for="Heading">Tooltip Heading '+sll +'</label> <input type="text" class="form-control" id="toolipHeading" name="toolipHeading[]"> </div> <div class="form-group col-md-6"> <label for="Image">Tooltip Image '+sll +' </label> <input type="file" class="form-control" id="toolipImage" name="toolipImage[]"> </div> </div> <div class="form-row"> <div class="form-group col-md-10"> <label for="Heading">Tooltip Content '+sll +'</label> <textarea class="form-control" name="toolTipContent[]" rows="2"></textarea> </div> <div class="form-group col-md-2"> <button type="button" name="remove" id="' + sll + '" class="btn btn-danger btn_remove">X</button> </div> </div></div>'
    );
    sll++;
});

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

$('#addMoreUpdate').click(function() {
    // alert(sll);

    $('#dynamicField').append('<div id="dataLoad'+sll +'"><div class="form-row"> <div class="form-group col-md-6"> <label for="Heading">Tooltip Heading '+sll +'</label> <input type="text" class="form-control" id="toolipHeading" name="toolipHeadingUp[]"> </div> <div class="form-group col-md-6"> <label for="Image">Tooltip Image '+sll +' </label> <input type="file" class="form-control" id="toolipImage" name="toolipImageUp[]"> </div> </div> <div class="form-row"> <div class="form-group col-md-10"> <label for="Heading">Tooltip Content '+sll +'</label> <textarea class="form-control" name="toolTipContentUp[]" rows="2"></textarea> </div> <div class="form-group col-md-2"> <button type="button" name="remove" id="' + sll + '" class="btn btn-danger btn_remove">X</button> </div> </div></div>'
    );
    sll++;
});

$(document).on('click', '.btn_remove', function() {
    var button_id = $(this).attr("id");
    $('#dataLoad' + button_id + '').remove();
});
</script>
<!-- <script>
$(document).ready(function () {
    $("#formSample").on('submit', function (e) {
        e.preventDefault();
        
        var formData = new FormData(this);
        
        formData.append('catID', '<?=$catID;?>')

        $.ajax({
            url: "addToolTip.php",
            type: "POST",
            data: formData,
            contentType: false,
            cache: false,
            processData: false,
            success: function (response) {
                $("#message").html(response);
            },
            error: function () {
                $("#message").html("<p>An error has occurred</p>");
            }
        });
    });
});

</script> -->
