public function getCategoryOrderedapiArray($data)
 {
     $db = $this->db;
     $db->select('cat_id,cat_image,cat_name,cat_title');
     $db->from(CATEGORY);
     $db->where(array("cat_active" => "1"));
     if (isset($data['lastrequesttime']) && isset($data['isinitialrequest'])) {
         $time = $data['lastrequesttime'];
         if ($data['isinitialrequest'] == 0) {
             $db->where(array("cat_modified_date >" => $time));
         }
     }
     if (isset($data['location']) && $data['location'] != '' && stripos($data['location'], "gujarat") === false) {
         $location = $data['location'];
     } else {
         $location = '';
     }
     $query = $db->get();
     $categories = $query->result_array();
     $cat_array = array();
     foreach ($categories as $category) {
         $category['cat_thumb_image'] = image(category_img_path() . @$category['cat_image'], 'cat_icon');
         $category['cat_main_image'] = category_img_path() . @$category['cat_image'];
         $cat_id = $category['cat_id'] . "-";
         $category['cat_ad_count'] = $this->common_model->getAdscount($cat_id, $location);
         $cat_array[$category['cat_id']] = $category;
     }
     $order = json_decode(getSetting("cat_order", true), true);
     return $this->orderCategoriesapi($cat_array, $order, $location);
 }
    ?>
		<div class="col-lg-12">
		  <h3>Sub Categories</h3>
		  <?php 
    foreach ($subcategory as $cat) {
        if (@$cat['category']['cat_name'] != '') {
            ?>
            <div class="col-lg-3 col-sm-6 col-xs-4 subcategory-grid">
			
			 <a href="<?php 
            echo base_url() . "classified/search?location=" . $_COOKIE['gujjucity'] . "&category=" . urlencode($pagecategory['cat_id'] . "-" . @$cat['category']['cat_id'] . "-") . "&q=" . create_slug(@$cat['category']['cat_name']);
            ?>
">
              <div class="thumbnail">
                <img src="<?php 
            echo image(category_img_path() . @$cat['category']['cat_image'], "cat_icon");
            ?>
" style="height:80px; width:80px;" />
                <div class="caption">
                  <p class="subcategory-name" style="margin-bottom:2px;"><?php 
            echo @$cat['category']['cat_name'];
            ?>
</p>
                  <p class="subcategory-name"><small><?php 
            echo @$cat['category']['cat_ad_count'];
            ?>
 Ads</small></p>
                </div>
              </div>
			</a>
			
										<input type="text" placeholder="Enter ..." class="form-control validate[required]" name="cat_name" id="cat_name" value="<?php 
echo @$category[0]->cat_name;
?>
" >
									</div>

									<div class='form-group'>
										<label for="username">Category Image: </label> 
										<input type="file" name="cat_image">
									</div>
									<div class='form-group'>
										<?php 
if (file_exists(DOC_ROOT_CATEGORY_IMG . @$category[0]->cat_image) && @$category[0]->cat_image != "") {
    ?>
											<img src="<?php 
    echo image(category_img_path() . @$category[0]->cat_image, 'cat_icon');
    ?>
" style="height:80px; width:80px;">
										<?php 
}
?>
	
									</div>
										
									<div class="form-group">
										<label>Category Detail:</label>
										<textarea type="text" placeholder="Category detail here" class="form-control validate[required]" name="cat_title" id="cat_title"><?php 
echo @$category[0]->cat_title;
?>
</textarea>
									</div>
 public function search()
 {
     $post = $this->input->get();
     if ($post) {
         $cats = array();
         if (isset($post["p_id"]) && $post["p_id"] != "") {
             $this->common_model->db->select("c.cat_name,c.cat_image", FALSE);
             $this->common_model->db->from(CATEGORY_C);
             $this->common_model->db->join(CATEGORY_CA, "c.cat_parentid = ca.cat_id", 'left');
             $where = array("ca.cat_name" => $post["p_id"]);
             $this->common_model->db->where($where);
             $where = "c.cat_name LIKE '%" . $post['term'] . "%'";
             $this->common_model->db->where($where);
             $query = $this->common_model->db->get();
             $ret = $query->result();
             $query->free_result();
         } else {
             $where = "cat_name LIKE '%" . $post['term'] . "%' AND cat_parentid = 0";
             $ret = $this->common_model->selectData(CATEGORY, "cat_name,cat_image", $where);
         }
         foreach ($ret as $r) {
             //$cats[] = '{"c_id":"te","label":"<img src="'.image(category_img_path().$r->cat_image,'cat_icon').'" width="30" height="30"/> '.$r->cat_name.'","value":"'.$r->cat_name.'"}';
             $cats[] = '{"c_id":"te","label":"<img src=\'' . image(category_img_path() . $r->cat_image, 'cat_icon') . '\' width=\'30\' height=\'30\'/> ' . $r->cat_name . '","value":"' . $r->cat_name . '"}';
         }
         echo '[' . implode(",", $cats) . ']';
         exit;
     }
 }
function displayCategory($categories, $order, $root = true)
{
    if ($root) {
        $html = "<ol id='categoryList' class='products-list product-list-in-box'>";
    } else {
        $html = "<ol>";
    }
    foreach ($order as $o) {
        $category = $categories[$o['id']];
        $html .= '<li class="item" id ="cat-' . $category['cat_id'] . '"><div class="clearfix" >
												<div class="product-img">
													<img alt="Product Image" src="' . image(category_img_path() . $category['cat_image'], 'cat_icon') . '">
												</div>
												<div class="product-info">
													<a class="product-title" href="javascript:void(0);">' . $category['cat_name'] . '</a>
														<span class="pull-right">
															<a href="' . site_url('/admin/category/edit/' . $category['cat_id']) . '" class="fa fa-edit"></a>
															<a href="javascript:void(0);" onclick="delete_category(' . $category['cat_id'] . ')" class="fa fa-trash-o"></a>
														</span>
													<span class="product-description">' . character_limiter($category['cat_title'], 54) . '</span>
												</div>
										  </div>';
        if (isset($o['children'])) {
            $html .= displayCategory($categories, $o['children'], false);
        }
        $html .= '</li>';
    }
    $html .= "</ol>";
    return $html;
}
 public function getCategoryOrderedArray($active = false, $selectOpt = false, $locFilter = false)
 {
     $db = $this->db;
     $db->select('*');
     $db->from(CATEGORY);
     if ($active) {
         $db->where(array("cat_active" => "1"));
     }
     $query = $db->get();
     $categories = $query->result_array();
     $cat_array = array();
     if ($locFilter == true && isset($_COOKIE['gujjucity']) && $_COOKIE['gujjucity'] != '' && strtolower($_COOKIE['gujjucity']) != 'all gujarat') {
         $location = $_COOKIE['gujjucity'];
     } else {
         $location = '';
     }
     foreach ($categories as $category) {
         $category['cat_thumb_image'] = image(category_img_path() . @$category['cat_image'], 'cat_icon');
         $category['cat_main_image'] = category_img_path() . @$category['cat_image'];
         $cat_id = $category['cat_id'] . "-";
         $category['cat_ad_count'] = $this->common_model->getAdscount($cat_id, $location);
         $cat_array[$category['cat_id']] = $category;
     }
     $order = json_decode(getSetting("cat_order", true), true);
     if (!$selectOpt) {
         return $this->orderCategories($cat_array, $order, $location);
     } else {
         return $this->orderSelectBoxCategories($cat_array, $order);
     }
 }