<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->headerData = array();
        $this->footerData = array();
        $this->load->helper("text");
        $this->load->helper('form');
        $this->load->model('Func', '', TRUE); 
        $this->load->model('Checkdata', '', TRUE);
        $this->load->model('DateTimeFunc', '', TRUE);
        $this->load->model('Get_Lang', '', TRUE);
        $this->lang->load('site', "turkish");
        
        if ($this->session->userdata("username") == "" && $this->uri->segment(2) != "login") {
            header("Location: /admin/login");
            die();
        }

        if (!ini_get('date.timezone')) {
            date_default_timezone_set('GMT');
        }
        
        $companyName = $this->db->query("SELECT coId, companyName FROM contact_us WHERE coId = 1")->result_object();
        if(isset($companyName[0]->companyName)){
            $this->headerData['companyName'] = $companyName[0]->companyName;
        }else{
            $this->headerData['companyName'] = "";
        }
        $this->footerData['theColor'] = $this->db->query("SELECT theValue FROM site_setting")->result_object();
        $this->headerData['theColor'] = $this->db->query("SELECT theValue FROM site_setting")->result_object();
        $this->headerData['theLogo'] = $this->db->query("SELECT theValue FROM site_setting WHERE seId = 3")->result_object();
        
        $adminLang = $this->session->userdata("adminLang");        
        if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}
        
        $this->headerData['categories'] = $this->db->query("SELECT caId, $theTitle FROM categories WHERE isDeleted = 0 AND parentId = 0 ORDER BY langId ASC")->result_object();
        
        if ($this->session->userdata("adminLang") == NULL) {
            $session = array('adminLang' => 2);
            $this->session->set_userdata($session);
        }
        $this->headerData['adminLang'] = $this->session->userdata("adminLang");
        
        if($this->headerData['adminLang'] == 1){
            $this->headerData['tlang'] = 'ar';
            $this->headerData['alang'] = 'Arabic';            
        }elseif($this->headerData['adminLang'] == 3){
            $this->headerData['tlang'] = 'tr';
            $this->headerData['alang'] = 'Turkish';            
        }else{
            $this->headerData['tlang'] = 'en';
            $this->headerData['alang'] = 'English';            
        }
        $this->headerData['databaseLang'] =  $this->db->query("SELECT laId, theName, shortName FROM lang WHERE isDeleted = '0' ORDER BY laId ASC")->result_object();                    
    }

    public function index() {
        header("Location: /admin/login/");
    }

    public function home() {
        header("Location: /admin/users/");
    }

    // Login
    public function login() {
        $pageData = array();
        $pageData["status"] = 0;
        $pageData['theColor'] = $this->db->query("SELECT theValue FROM site_setting")->result_object();
        $pageData['theLogo'] = $this->db->query("SELECT theValue FROM site_setting WHERE seId = 3")->result_object();

        if ($this->input->post()) {
            $username = $this->Checkdata->checkInputData($this->input->post("username"));
            $password = $this->input->post("password");
            $check = $this->db->query("select count(1) as cnt from users where username = '" . $username . "' and thePassword = '" . sha1($password) . "' AND isDeleted = 0")->result();
            if ($check[0]->cnt > 0) {
                $memberData = $this->db->query("select usId from users where username = '" . $username . "' and thePassword = '" . sha1($password) . "' AND isDeleted = 0")->result_array();
                $session = array(
                    'username' => $username,
                    'lastlogin' => Date("Y-m-d H:i:s"),
                    'usId' => $memberData[0]["usId"]
                );
                $this->session->set_userdata($session);
                header("Location: /admin/home/");
            } else {
                $pageData["status"] = 1;
                $this->load->view("admin/login", $pageData);
            }
        } else {
            $this->load->view("admin/login", $pageData);
        }
    }

    
    function logout() {
//        $this->session->sess_destroy();
        unset($_SESSION['username']);

        header("Location: /admin/login");
    }

    
     // atranslate
    public function atranslate($isAdmin = 0) {
        $pageData = array();
        $pageData['isAdmin'] = $isAdmin;
        
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/atranslate", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    public function add_edit_atranslate($isAdmin = 0,$id = 0) {
        $pageData = array();
        $pageData['isAdmin'] = $isAdmin;
        $adminLang = $this->session->userdata("adminLang");

        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $atranslate = $this->db->query("SELECT * FROM atranslate WHERE laId = $id")->result_object();
            if (empty($atranslate)) {
                header("Location: /admin/atranslate/");
                exit();
            }
            $atranslate = $atranslate[0];
            $pageData['pageTitle'] = $atranslate->define.' '. $this->Get_Lang->gl("edit",$adminLang);
            
            $column = $this->db->list_fields('atranslate');            
            foreach($column as $key => $name) {
                $returner["$name"] = $atranslate->$name;
            }

            $pageData['values'] = json_encode($returner);
        } else {            
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang);
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditAtranslate', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    
    // Users
    public function users() {
        $pageData["users"] = $this->db->query("SELECT usId, username, lastlogin from users WHERE isDeleted = 0 AND usId != 1 ORDER BY usId")->result_array();
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/users", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    function addEditUsers($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        if ($id) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);
        if ($id == 1) {  header("Location: /admin/users");  exit(); }
            $pageData['id'] = $id;
            $returner = array();
            $userData = $this->db->query("SELECT username,thePassword FROM users WHERE usId = $id AND isDeleted = 0 AND usId != 1")->result_object();
            if (empty($userData)) {
                header("Location: /admin/users");
                exit();
            }
            $userData = $userData[0];
            $pageData['pageTitle'] = $this->Get_Lang->gl('edit',$adminLang).': '.$this->Get_Lang->gl('username',$adminLang);

            $returner["username"] = $userData->username;
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl('addNew',$adminLang).': '.$this->Get_Lang->gl('username',$adminLang);
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditUsers', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
  
    // About Us
    public function aboutUs() {
        $pageData = array();

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/aboutUs", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    public function edit_aboutUs($id =0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $pageData['id'] = $id;
        $returner = array();

        $aboutUs = $this->db->query("SELECT * FROM about_us WHERE abId = '$id'")->result_object();
        
        if (empty($aboutUs)) {
            header("Location: /admin/aboutUs/");
            exit();
        }
        $aboutUs = $aboutUs[0];

        $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$aboutUs->theTitle1;
        
        if($id != 1){
        $column = $this->db->list_fields('about_us');            
            foreach($column as $key => $name) {
                $returner["$name"] = $aboutUs->$name;
            }

        }
        $pageData["thePhoto"] = $aboutUs->thePhoto;

        $pageData['values'] = json_encode($returner);

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/editAboutUs', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }    

    // homeSlider
    public function homeSlider() {
        $pageData = array();
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/homeSlider", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    public function add_edit_home_slider($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $homeSlider = $this->db->query("SELECT * FROM home_slider WHERE hoId = $id")->result_object();
            if (empty($homeSlider)) {
                header("Location: /admin/homeSlider/");
                exit();
            }
            $homeSlider = $homeSlider[0];
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$this->Get_Lang->gl("home_slider",$adminLang);

            $column = $this->db->list_fields('home_slider');            
            foreach($column as $key => $name) {
                $returner["$name"] = $homeSlider->$name;
            }

            $pageData["thePhoto"] = $homeSlider->thePhoto;

            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang).': '.$this->Get_Lang->gl("home_slider",$adminLang);
            $pageData["thePhoto"] = NULL;
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditHomeSlider', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    
       // blog_categories
    public function blog_categories() {
        $pageData = array();
       
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/blogCategories", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);        
    }
    
    
     public function add_edit_blog_categories($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
                
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $array = $this->db->query("SELECT * FROM blog_categories WHERE caId = $id")->result_object();
            if (empty($array)) {
                header("Location: /admin/blog/");
                exit();
            }
            $array = $array[0];
            if($adminLang == 1){$tagName = $array->theTitle1;}
            elseif($adminLang == 3){$tagName = $array->theTitle3;}
            else{$tagName = $array->theTitle2;}
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$tagName;

            $column = $this->db->list_fields('blog_categories');            
            foreach($column as $key => $name) {
                $returner["$name"] = $array->$name;
            }
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang);
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditBlogCategories', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

     // Blog
    public function blog($categoryId = 0) {
   $pageData = array();
        $pageData['categoryId'] = $categoryId;
            $array = $this->db->query("SELECT * FROM blog_categories WHERE caId = '$categoryId'")->result_object();
            if (empty($array)) {
                header("Location: /admin/blog_categories");
                exit();
            }
       
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/blog", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

   
     public function add_edit_blog($categoryId = 0, $id = 0) {
        $pageData = array();
        $pageData['categoryId'] = $categoryId;        
        $adminLang = $this->session->userdata("adminLang");
               
        $array2 = $this->db->query("SELECT * FROM blog_categories WHERE caId = '$categoryId'")->result_object();
        $links = $this->db->query("SELECT url FROM links WHERE content_id = '$id' AND page = 'blog' ")->result_object();        
            if (empty($array2)) {
                header("Location: /admin/blog_categories");
                exit();
            }
            if($adminLang == 1){ if(isset($array2[0]->theTitle1)){$tagName2 = $array2[0]->theTitle1;}else{$tagName2 = "";}
            }elseif($adminLang == 3){if(isset($array2[0]->theTitle3)){$tagName2 = $array2[0]->theTitle3;}else{$tagName2 = "";}}
            else{if(isset($array2[0]->theTitle2)){$tagName2 = $array2[0]->theTitle2;}else{$tagName2 = "";}}    
            
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $array = $this->db->query("SELECT * FROM blog WHERE blId = '$id'")->result_object();
            if (empty($array)) {
                header("Location: /admin/blog/".$categoryId);
                exit();
            }
            $array = $array[0];
            if($adminLang == 1){$tagName = $array->theTitle1;}
            elseif($adminLang == 3){$tagName = $array->theTitle3;}
            else{$tagName = $array->theTitle2;}
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$tagName;

            $column = $this->db->list_fields('blog');            
            foreach($column as $key => $name) {
                $returner["$name"] = $array->$name;
            }
            
            if($links){
            $returner["url"] = urldecode($links[0]->url);
            }
            
            $pageData['thePhoto'] = $array->thePhoto;
           
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang).' - '.$tagName2;
            $pageData['thePhoto'] = NULL;
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditBlog', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    
    

    // brands
    public function brands() {
        $pageData = array();      
            
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/brands", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);        
    }
    
    
    public function add_edit_brand($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");                        
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $array = $this->db->query("SELECT * FROM brands WHERE brId = '$id' AND isDeleted = 0")->result_object();
            if (empty($array)) {
                header("Location: /admin/brands");
                exit();
            }
            $array = $array[0];
            if($adminLang == 1){$tagName = $array->theTitle1;}
            elseif($adminLang == 3){$tagName = $array->theTitle3;}
            else{$tagName = $array->theTitle2;}
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$tagName;

            $column = $this->db->list_fields('brands');            
            foreach($column as $key => $name) {
                $returner["$name"] = $array->$name;
            }
            $pageData['thePhoto'] = $array->thePhoto;
            
           
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang);
            $pageData['thePhoto'] = NULL;
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditBrand', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    
    // Tags Categories
    public function tags_categories() {
        $pageData = array();      
            
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/tagsCategories", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);        
    }
    
    
    public function add_edit_tags_categories($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");                        
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $array = $this->db->query("SELECT * FROM tag_categories WHERE taId = '$id'")->result_object();
            if (empty($array)) {
                header("Location: /admin/tags_categories");
                exit();
            }
            $array = $array[0];
            if($adminLang == 1){$tagName = $array->theTitle1;}
            elseif($adminLang == 3){$tagName = $array->theTitle3;}
            else{$tagName = $array->theTitle2;}
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$tagName;

            $column = $this->db->list_fields('tag_categories');            
            foreach($column as $key => $name) {
                $returner["$name"] = $array->$name;
            }
           
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang);
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditTagsCategories', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    

    // Tags
    public function tags($productId = 0) {
        $pageData = array();
        $pageData['productId'] = $productId;
        $adminLang = $this->session->userdata("adminLang");

        $array2 = $this->db->query("SELECT taId, theTitle1, theTitle2, theTitle3 FROM tag_categories WHERE taId = '$productId' ")->result_object();
            if (empty($array2)) {
                header("Location: /admin/dashboard");
                exit();
            } else{   
            if($adminLang == 1){$tagName = $array2[0]->theTitle1;}
            elseif($adminLang == 3){$tagName = $array2[0]->theTitle3;}
            else{$tagName = $array2[0]->theTitle2;}
                $pageData['theName'] = $tagName;
            }
            
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/tags", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);        
    }
    
    
    public function add_edit_tags($productId = 0, $id = 0) {
        $pageData = array();
        $pageData['productId'] = $productId;
        $adminLang = $this->session->userdata("adminLang");

        $array2 = $this->db->query("SELECT taId, theTitle1, theTitle2, theTitle3 FROM tag_categories WHERE taId = '$productId' ")->result_object();
            if (empty($array2)) {
                header("Location: /admin/dashboard");
                exit();
            } else{   
            if($adminLang == 1){$tagName = $array2[0]->theTitle1;}
            elseif($adminLang == 3){$tagName = $array2[0]->theTitle3;}
            else{$tagName = $array2[0]->theTitle2;}
                $pageData['theName'] = $tagName;                
            }
                
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $array = $this->db->query("SELECT * FROM tags WHERE taId = '$id'")->result_object();
            if (empty($array)) {
                header("Location: /admin/tags/");
                exit();
            }
            $array = $array[0];
            if($adminLang == 1){$tagName = $array->theTitle1;}
            elseif($adminLang == 3){$tagName = $array->theTitle3;}
            else{$tagName = $array->theTitle2;}
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$tagName;

            $column = $this->db->list_fields('tags');            
            foreach($column as $key => $name) {
                $returner["$name"] = $array->$name;
            }
           
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang);
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditTags', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    

    // sizes
    public function sizes() {
        $pageData = array();
       
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/sizes", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);        
    }
    
    
     public function add_edit_sizes($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
                
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $array = $this->db->query("SELECT * FROM sizes WHERE siId = $id")->result_object();
            if (empty($array)) {
                header("Location: /admin/sizes");
                exit();
            }
            $array = $array[0];
            if($adminLang == 1){$tagName = $array->theTitle1;}
            elseif($adminLang == 3){$tagName = $array->theTitle3;}
            else{$tagName = $array->theTitle2;}
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$tagName;

            $column = $this->db->list_fields('sizes');            
            foreach($column as $key => $name) {
                $returner["$name"] = $array->$name;
            }
           
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang);
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditSizes', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    // colors
    public function colors() {
        $pageData = array();
       
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/colors", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);        
    }
    
    
     public function add_edit_colors($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
                
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $array = $this->db->query("SELECT * FROM colors WHERE coId = $id")->result_object();
            if (empty($array)) {
                header("Location: /admin/colors");
                exit();
            }
            $array = $array[0];
            if($adminLang == 1){$tagName = $array->theTitle1;}
            elseif($adminLang == 3){$tagName = $array->theTitle3;}
            else{$tagName = $array->theTitle2;}
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$tagName;

            $column = $this->db->list_fields('colors');            
            foreach($column as $key => $name) {
                $returner["$name"] = $array->$name;
            }
           
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang);
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditColors', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    

    // Gallery
    public function gallery($tagId = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $tags = $this->db->query("SELECT * FROM tags WHERE taId = '$tagId'")->result_object();
        if (empty($tags)) {
            header("Location: /admin/tags/");                
            }
            if($adminLang == 1){$tagName = $tags[0]->theTitle1;}
            elseif($adminLang == 3){$tagName = $tags[0]->theTitle3;}
            else{$tagName = $tags[0]->theTitle2;}
           
            if($tags){
                $pageData['tagName'] = $tagName;
            }else{
                $pageData['tagName'] = " ";
            }     
            
        $pageData['productId'] = $tagId;
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/gallery", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
        
    }
    
    public function add_gallery($tagId = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $pageData["thePhoto"] = NULL;
        $pageData['productId'] = $tagId;
        $tags = $this->db->query("SELECT theTitle, theTitleAr, theTitleTr FROM tags WHERE taId = '$tagId'")->result_object();
        if (empty($tags)) {
            header("Location: /admin/tags/");                
            }
            if($adminLang == 1){$tagName = $tags[0]->theTitleAr;}
            elseif($adminLang == 3){$tagName = $tags[0]->theTitleTr;}
            else{$tagName = $tags[0]->theTitle;}        if (empty($tags)) {
            header("Location: /admin/gallery/".$tagId);                
            }
        
        $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang).' : '.$tagName;

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addGallery', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
   
    
        // faq_categories
    public function faq_categories() {
        $pageData = array();
       
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/faqCategories", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);        
    }
    
    
     public function add_edit_faq_categories($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
                
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $array = $this->db->query("SELECT* FROM faq_categories WHERE caId = $id")->result_object();
            if (empty($array)) {
                header("Location: /admin/faq_categories/");
                exit();
            }
            $array = $array[0];
            if($adminLang == 1){$tagName = $array->theTitle1;}
            elseif($adminLang == 3){$tagName = $array->theTitle3;}
            else{$tagName = $array->theTitle2;}
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$tagName;

            $column = $this->db->list_fields('faq_categories');            
            foreach($column as $key => $name) {
                $returner["$name"] = $array->$name;
            }
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang);
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditFaqCategories', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    

    // faq
    public function faq($categoryId = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");        
        $pageData['categoryId'] = $categoryId;
            $array = $this->db->query("SELECT * FROM faq_categories WHERE caId = '$categoryId'")->result_object();
            if (empty($array)) {
                header("Location: /admin/faq_categories");
                exit();
            }
            if($adminLang == 1){$tagName = $array[0]->theTitle1;}
            elseif($adminLang == 3){$tagName = $array[0]->theTitle3;}
            else{$tagName = $array[0]->theTitle2;}
        $pageData['theName'] = $tagName;
       
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/faq", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);        
    }
    
    
     public function add_edit_faq($categoryId = 0, $id = 0) {
        $pageData = array();
        $pageData['categoryId'] = $categoryId;        
        $adminLang = $this->session->userdata("adminLang");
               
        $array2 = $this->db->query("SELECT * FROM faq_categories WHERE caId = '$categoryId'")->result_object();
            if (empty($array2)) {
                header("Location: /admin/faq_categories");
                exit();
            }
            if($adminLang == 1){ if(isset($array2[0]->theTitle1)){$tagName2 = $array2[0]->theTitle1;}else{$tagName2 = "";}
            }elseif($adminLang == 3){if(isset($array2[0]->theTitle3)){$tagName2 = $array2[0]->theTitle3;}else{$tagName2 = "";}}
            else{if(isset($array2[0]->theTitle2)){$tagName2 = $array2[0]->theTitle2;}else{$tagName2 = "";}}    
            
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $array = $this->db->query("SELECT * FROM faq WHERE coId = '$id'")->result_object();
            if (empty($array)) {
                header("Location: /admin/faq/".$categoryId);
                exit();
            }
            $array = $array[0];
            if($adminLang == 1){$tagName = $array->theTitle1;}
            elseif($adminLang == 3){$tagName = $array->theTitle3;}
            else{$tagName = $array->theTitle2;}
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$tagName .' ('.$tagName2.')';

            $column = $this->db->list_fields('faq');            
            foreach($column as $key => $name) {
                $returner["$name"] = $array->$name;
            }
           
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("addNew",$adminLang).' - '.$tagName2;
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditFaq', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    
    
    
    // contact US
    public function ContactUs() {
        $pageData = array();

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/ContactUs", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    public function add_edit_contact_us($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $pageData ['id'] = $id;
        $returner = array();

        $array = $this->db->query("SELECT * FROM contact_us WHERE coId = '$id'")->result_object();
        if (empty($array)) {
            header("Location: /admin/contactUs/");
            exit();
        }
        $array = $array[0];
        $pageData['pageTitle'] = $this->Get_Lang->gl('edit',$adminLang).': '.$this->Get_Lang->gl('contact_us',$adminLang);

            $column = $this->db->list_fields('contact_us');            
            foreach($column as $key => $name) {
                $returner["$name"] = $array->$name;
            }
        $pageData["latitude"] = $array->latitude;
        $pageData["longitude"] = $array->longitude;
           
        $pageData['values'] = json_encode($returner);


        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditContactUs', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    
        // socialMedia
    public function socialMedia() {
        $pageData = array();

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/socialMedia", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    public function add_edit_social_media($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $pageData ['id'] = 1;
        $returner = array();

        $socialMedia = $this->db->query("SELECT * FROM contact_us WHERE coId = 1")->result_object();
        if (empty($socialMedia)) {
            header("Location: /admin/socialMedia/");
            exit();
        }
        $socialMedia = $socialMedia[0];
        $pageData['pageTitle'] = $this->Get_Lang->gl('edit',$adminLang).': '.$this->Get_Lang->gl('social_media',$adminLang);

        $column = $this->db->list_fields('contact_us');            
            foreach($column as $key => $name) {
                $returner["$name"] = $socialMedia->$name;
            }

        $pageData['values'] = json_encode($returner);


        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditSocialMedia', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    // contact Us Form
    public function contactUsForm() {
        $pageData = array();

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/contactUsForm", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }   
    
        // subscribers
    public function subscribers() {
        $pageData = array();

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/subscribers", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    
    
    // setting
    public function setting() {
        $pageData = array();

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/setting", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    public function add_edit_setting($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        $this->Checkdata->isNotNumeric($id);
        $this->Checkdata->ifEmptyOrZero($id);

        $pageData['id'] = $id;
        $returner = array();

        $setting = $this->db->query("SELECT * FROM site_setting WHERE seId = $id AND seId < 4")->result_object();
        if (empty($setting)) {
            header("Location: /admin/setting/");
            exit();
        }
        $setting = $setting[0];
        $pageData['pageTitle'] = $setting->theName;

        $returner["theName"] = $setting->theName;
        if ($id == 4 || $id == 5) {
            $returner["theData"] = $setting->theValue;
        } elseif ($id == 6) {
            $returner["theData2"] = $setting->theValue;
        } elseif ($id == 3) {
            $pageData["thePhoto"] = $setting->theValue;
        } else {
            $returner["theColor"] = $setting->theValue;
        }


        $pageData['values'] = json_encode($returner);


        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditSetting', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    
        // Categories
    public function categories($mainId = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $pageData['lang'] = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
        $pageData['theParentId'] = $this->theParentMain($mainId);
        $pageData['id'] = $mainId;

        if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}        
        $categorylang = $this->db->query("SELECT caId, $theTitle FROM categories WHERE isDeleted = 0 AND caId = '$mainId' ")->result_object();
        $pageData['checkChild'] = $this->db->query("SELECT caId, $theTitle FROM categories WHERE isDeleted = 0 AND parentId = '$mainId' ")->result_object();
        if($categorylang){
        $pageData['theName'] = $categorylang[0]->theTitle;
        $pageData['pageName'] = $this->theCategoriesSeries($categorylang[0]->caId," ");

        }else{
             header("Location: /admin/users");
                exit();
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/categories", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
    // delete category
    public function delete_category($mainId = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");

        $this->Checkdata->isNotNumeric($mainId);
        $this->Checkdata->ifEmptyOrZero($mainId);

                $processArr = Array();
                $processArr['isDeleted'] = 1;
                if($this->db->update("categories",$processArr,array('caId' => $mainId))){
                $var =  header("Location:/admin/ajax/deleteUrlLink/$mainId/categories");
                    header("Location: /admin/users");
                    exit();
                }
    }

    public function add_edit_categories($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();

        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $categories = $this->db->query("SELECT * FROM categories WHERE caId = $id AND isDeleted = 0 ")->result_object();
            $links = $this->db->query("SELECT url FROM links WHERE content_id = $id AND page = 'categories' ")->result_object();

            if (empty($categories)) {
                header("Location: /admin/users/");
                exit();
            }
        if($adminLang == 1){$theTitle = "theTitle1";}elseif($adminLang == 3){$theTitle = "theTitle3";}else{$theTitle = "theTitle2";}
            
            $categories = $categories[0];
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).': '.$categories->$theTitle;
            
            $column = $this->db->list_fields('categories');            
            foreach($column as $key => $name) {
                $returner["$name"] = $categories->$name;
            }

            if($links){
            $returner["url"] = urldecode($links[0]->url);
            }

            $pageData['thePhoto'] = $categories->thePhoto;

            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("add_main_category",$adminLang);
            $pageData['thePhoto'] = Null;
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditCategories', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    public  function theParentMain($caId = 0){
        $adminLang = $this->session->userdata("adminLang");
        
        $parent = $this->db->query("SELECT caId, parentId FROM categories WHERE caId = '$caId'")->result_object();
     if($parent){
        if($parent[0]->parentId > 0){
            return $this->theParentMain($parent[0]->parentId);
        }else {
            return $parent[0]->caId;
        }
     }
    }

    public  function theCategoriesSeries($caId = 0, $title = " "){
        $adminLang = $this->session->userdata("adminLang");
        
        if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}
        $parent = $this->db->query("SELECT caId, parentId, $theTitle FROM categories WHERE caId = '$caId'")->result_object();
        if($parent[0]->parentId > 0){
            $title .=  $parent[0]->theTitle." <- ";
            return $this->theCategoriesSeries($parent[0]->parentId, $title);
        }else {
            $title .=  $parent[0]->theTitle;
            return $title;
        }
    }
    
    

    public function add_edit_sub_categories($parentId = 0, $id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $pageData['parentId'] =$parentId;
        $pageData['theParentId'] = $this->theParentMain($parentId);
        if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}
        $categorylang = $this->db->query("SELECT caId, $theTitle FROM categories WHERE isDeleted = 0 AND caId = '$parentId' ")->result_object();
        $pageName = $this->theCategoriesSeries($categorylang[0]->caId," ");

        if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}
        
        $parent = $this->db->query("SELECT $theTitle FROM categories WHERE caId = '$parentId'")->result_object();
        if (empty($parent)) {
                header("Location: /admin/users/");
                exit();
            }
        $parentName = $parent[0]->theTitle;

        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();
            if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}
            $categories = $this->db->query("SELECT * FROM categories WHERE caId = $id AND isDeleted = 0 ")->result_object();
            $links = $this->db->query("SELECT url FROM links WHERE content_id = $id AND page = 'categories' ")->result_object();

            if (empty($categories)) {
                header("Location: /admin/categories/".$parentId);
                exit();
            }
            $categories = $categories[0];
            if($adminLang == 1){$theTitlePage = "theTitle1";}elseif($adminLang == 3){$theTitlePage = "theTitle3";}else{$theTitlePage = "theTitle2";}
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang).' <br>('.$categories->$theTitlePage.')  <- '.$pageName;

            $column = $this->db->list_fields('categories');            
            foreach($column as $key => $name) {
                $returner["$name"] = $categories->$name;
            }

            if($links){
            $returner["url"] = urldecode($links[0]->url);
            }

            $pageData['thePhoto'] = $categories->thePhoto;

            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("add_new_category_to",$adminLang).' ( '.$parentName. ' ) ';
            $pageData['thePhoto'] = Null;
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditSubCategories', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }


    // category_details
    public function category_details($categoryId = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}
        $category = $this->db->query("SELECT caId, langId, $theTitle, parentId FROM categories WHERE caId = $categoryId")->result_object();
        if (empty($category)) {
                header("Location: /admin/users");
                exit();
        }else{
            $products = $this->db->query("SELECT caId FROM category_details WHERE categoryId = $categoryId AND isDeleted = 0")->result_object();
            if($products){
                
            $langId = $category[0]->langId;
            $pageData['categoryName'] = $this->Get_Lang->gl("details",$adminLang)." : ".$category[0]->theTitle." <br>";
            $pageData['pageName'] = " ( ".$this->theCategoriesSeries($categoryId," ")." )";

            $pageData['categoryId'] = $category[0]->caId;
            $pageData['parentId'] = $category[0]->parentId;
            $pageData['langId'] = $category[0]->langId;

            $pageData['categoryId'] = $categoryId;
            $pageData['theParentId'] = $this->theParentMain($categoryId);

        

        $pageData['lang'] = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/categoryDetails", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }else{
        $this->add_edit_category_details($categoryId,0);
            }
        }
    }
    


    public function add_edit_category_details($categoryId = 0, $id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $pageData['caId'] = $categoryId;
        if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}
        
        $pageData['categories'] = $this->db->query("SELECT caId, $theTitle FROM categories WHERE isDeleted = 0")->result_object();
        $pageData['tags'] = $this->db->query("SELECT taId, $theTitle FROM tag_categories WHERE isDeleted = 0")->result_object();
        $pageData['marka'] = $this->db->query("SELECT brId, $theTitle FROM brands WHERE isDeleted = 0")->result_object();
        $pageData['colors'] = $this->db->query("SELECT coId, $theTitle FROM colors WHERE isDeleted = 0")->result_object();
        $pageData['sizes'] = $this->db->query("SELECT siId, $theTitle FROM sizes WHERE isDeleted = 0")->result_object();


        $category = $this->db->query("SELECT caId, $theTitle, parentId FROM categories WHERE caId = '$categoryId' ")->result_object();
         if (empty($category)) {
                header("Location: /admin/users");
                exit();
            }else{
                $pageData['pageName'] = " ( ".$this->theCategoriesSeries($categoryId," ")." )";

            $pageData['categoryName'] = $category[0]->theTitle;
            $pageData['categoryId'] = $category[0]->caId;
            $pageData['parentId'] = $category[0]->parentId;
            

        }
            $pageData['theParentId'] = $this->theParentMain($categoryId);
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $products = $this->db->query("SELECT * FROM category_details WHERE caId = $id AND isDeleted = 0")->result_object();
            if (empty($products)) {
                header("Location: /admin/category_details/".$categoryId);
                exit();
            }
            $products = $products[0];
            $pageData['pageTitle'] = $this->Get_Lang->gl("edit",$adminLang)." ".$this->Get_Lang->gl("details",$adminLang).' :<br> ('.$pageData['categoryName'].') ';

            $column = $this->db->list_fields('category_details');            
            foreach($column as $key => $name) {
                $returner["$name"] = $products->$name;
            }
            $pageData["theColorsId"] = json_decode($products->colorId);
            $pageData["theSizesId"] = json_decode($products->sizeId);
            $pageData["theTagsId"] = json_decode($products->tagId);
            if($pageData["theTagsId"]){
                $tagCategId = $pageData["theTagsId"][0];
                $tagsCa = $this->db->query("SELECT taId FROM tag_categories WHERE isDeleted = 0 AND taId = '$tagCategId'")->result_object();
                if($tagsCa){
                    $pageData['tagCategId'] = $tagsCa[0]->taId;
                    $tagCategId = $tagsCa[0]->taId;
                    $pageData["getTagData"] = $this->db->query("SELECT taId, $theTitle FROM tags WHERE isDeleted = 0 AND productId = '$tagCategId'")->result_object();
                }else{
                    $pageData['tagCategId'] = 0;
                    $pageData["getTagData"] = NULL;
                }
            }else{
            $pageData['tagCategId'] = 0;
            $pageData["getTagData"] = NULL;
            }
            
            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl("Add_New_Details_for",$adminLang)." <br> ".$pageData['pageName'];
            $pageData['thePhoto'] = Null;
            $pageData["theColorsId"] = Null;
            $pageData["theSizesId"] = Null;
            $pageData["theTagsId"] = Null;
            $pageData['tagCategId'] = 0;
            $pageData['id'] = 0;
            $pageData["getTagData"] = NULL;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditCategoryDetails', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

      // Options
    public function add_options($detailsId = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $categoryDetails = $this->db->query("SELECT CA.theTitle, CA.caId FROM category_details DE INNER JOIN categories CA ON CA.caId = DE.categoryID WHERE DE.caId = $detailsId")->result_object();
        if($categoryDetails){
            $pageData['pageTitle'] = 'Options For '.$categoryDetails[0]->theTitle;
        }else{
            header("Location: /admin/users");
                exit();
        }
        $pageData['detailsId'] = $detailsId;
        $pageData['theParentId'] = $this->theParentMain($categoryDetails[0]->caId);

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/addOptions", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    public function add_edit_options($detailsId = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $categoryDetails = $this->db->query("SELECT CA.theTitle, CA.caId FROM category_details DE INNER JOIN categories CA ON CA.caId = DE.categoryID WHERE DE.caId = $detailsId")->result_object();

        if($categoryDetails){
            $pageData['pageTitle'] = 'Add New Option For '.$categoryDetails[0]->theTitle;
            $pageData['detailsId'] = $detailsId;
        }else{
            header("Location: /admin/users");
                exit();
        }
        $pageData['theParentId'] = $this->theParentMain($categoryDetails[0]->caId);

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditOptions', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

            // details slider
    public function details_slider($detailsId = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}
        $categoryDetails = $this->db->query("SELECT CA.$theTitle, CA.caId FROM category_details DE INNER JOIN categories CA ON CA.caId = DE.categoryID WHERE DE.caId = $detailsId")->result_object();
            if($categoryDetails){
                $pageData['pageTitle'] = $categoryDetails[0]->theTitle;
            }else if (empty($categoryDetails)) {
            header("Location: /admin/users");
            }
        $pageData['theParentId'] = $this->theParentMain($categoryDetails[0]->caId);

        $pageData['detailsId'] = $detailsId;
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/detailsSlider", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);

    }

    public function add_details_slider($detailsId = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}
        $categoryDetails = $this->db->query("SELECT CA.$theTitle, CA.caId FROM category_details DE INNER JOIN categories CA ON CA.caId = DE.categoryID WHERE DE.caId = $detailsId")->result_object();
        $pageData["thePhoto"] = NULL;
        $pageData['detailsId'] = $detailsId;
        if (empty($categoryDetails)) {
            header("Location: /admin/users");
            }else{
            $pageData['pageTitle'] = $this->Get_Lang->gl('add_photo_to',$adminLang).': '.$categoryDetails[0]->theTitle;
            }
        $pageData['theParentId'] = $this->theParentMain($categoryDetails[0]->caId);


        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addDetailsSlider', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
     
    // Panner Photos
    public function panner_photos() {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/pannerPhotos", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);

    }

    public function edit_panner_photos($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        $pageData["id"] = $id;
        $Details = $this->db->query("SELECT paId, theTitle, thePhoto, theLink, photoSize FROM panner_photos WHERE paId = '$id'")->result_object();
        $pageData["thePhoto"] = NULL;
        if (empty($Details)) {
            header("Location: /admin/panner_photos");
            }else{        
            $pageData["thePhoto"] = $Details[0]->thePhoto;
            $pageData['pageTitle'] = ': '.$this->Get_Lang->gl("edit",$adminLang).' <br>'.$Details[0]->theTitle;
            $pageData['theLink'] = $Details[0]->theLink;
            $pageData['photoSize'] = $Details[0]->photoSize;
            }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/editPannerPhotos', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    
    
         // catalog
    public function catalog() {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view("admin/catalog", $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }

    public function add_edit_catalog($id = 0) {
        $pageData = array();
        $adminLang = $this->session->userdata("adminLang");
        if ($id != 0) {
            $this->Checkdata->isNotNumeric($id);
            $this->Checkdata->ifEmptyOrZero($id);

            $pageData['id'] = $id;
            $returner = array();

            $catalog = $this->db->query("SELECT theTitle, theFile FROM catalog WHERE caId = $id")->result_object();
            if (empty($catalog)) {
                header("Location: /admin/catalog/");
                exit();
            }
            $catalog = $catalog[0];
            $pageData['pageTitle'] = $this->Get_Lang->gl('file_upload',$adminLang);

            $pageData['theTitle'] = $catalog->theTitle;            
            $pageData['theFile'] = $catalog->theFile;            

            $pageData['values'] = json_encode($returner);
        } else {
            $pageData['pageTitle'] = $this->Get_Lang->gl('file_upload',$adminLang);
            $pageData['theFile'] = NULL;
            $pageData['id'] = 0;
        }

        $this->load->view("admin/common/header", $this->headerData);
        $this->load->view('admin/addEditCatalog', $pageData);
        $this->load->view("admin/common/footer", $this->footerData);
    }
  
    
    
    function productsExcelExport($categoryId = 0){
        
      $this->load->model("excel_export_model");
      $this->load->library("excel/excel");
      $object = new PHPExcel();

      $object->setActiveSheetIndex(0);
      // $object->getActiveSheet()->setTitle('Countries');


       $object->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
       $object->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
       $object->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
      // $object->getActiveSheet()->getStyle('D1')->getFont()->setBold(true);

      $object->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $object->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $object->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      // $object->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      // $object->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->setARGB('#333');
       //$object->getActiveSheet()->getStyle('B1')->getFill()->getStartColor()->setARGB('#333');
      // $object->getActiveSheet()->getStyle('C1')->getFill()->getStartColor()->setARGB('#333');
      // $object->getActiveSheet()->getStyle('D1')->getFill()->getStartColor()->setARGB('#333');

      $table_columns = array("plan Id", "Plan Code", "Plan Name");

      $column = 0;

      foreach($table_columns as $field){
        $object->getActiveSheet()->setCellValueByColumnAndRow($column, 1, $field);
        $column++;
      }



      // $employee_data = $this->excel_export_model->fetch_data();

      $getPlans = $this->db->query("SELECT plId, code, theTitle FROM plans WHERE categoryId = $categoryId")->result_object();

      $excel_row = 2;

      foreach($getPlans as $row){

        // $object->getActiveSheet()->getStyle('A'.$excel_row)->getFont()->setBold(true);
        // $object->getActiveSheet()->getStyle('B'.$excel_row)->getFont()->setBold(true);
        // $object->getActiveSheet()->mergeCells("A1.$excel_row:D1.$excel_row");

        $object->getActiveSheet()->setCellValueByColumnAndRow(0, $excel_row, $row->plId)->getStyle('A'.$excel_row)->getFont()->setBold(true);
        $object->getActiveSheet()->setCellValueByColumnAndRow(1, $excel_row, $row->code)->getStyle('B'.$excel_row)->getFont()->setBold(true);
        $object->getActiveSheet()->setCellValueByColumnAndRow(2, $excel_row, $row->theTitle)->getStyle('c'.$excel_row)->getFont()->setBold(true);
        $excel_row++;

      }
                $results = $this->db->query("SELECT theTitle FROM categories WHERE caId = $categoryId")->result();
                if($results){
                    $name = $results[0]->theTitle;
                }else{
                    $name = "Category's Plans";
                }
      $object_writer = PHPExcel_IOFactory::createWriter($object, 'Excel5');
      header('Content-Type: application/vnd.ms-excel');
      header("Content-Disposition: attachment;filename='$name.xls'");
      $object_writer->save('php://output');
    }

    function ajax($param1, $param2 = 0, $param3 = NULL, $param4 = NULL) {
        $adminLang = $this->session->userdata("adminLang");
        switch ($param1) {

            case "changeLanguage":
                $lang = $this->Checkdata->checkInputData($this->input->post("adminLang"));
                if ($lang == 'ar') {
                    $session = array(
                        'adminLang' => '1'
                    );
                    $this->session->set_userdata($session);
                } else if ($lang == 'tr') {
                    $session = array(
                        'adminLang' => '3'
                    );
                    $this->session->set_userdata($session);                
                } else {
                    $session = array(
                        'adminLang' => '2'
                    );
                    $this->session->set_userdata($session);
                }
                echo 1;
                break;

            // Atranslate
            case "getAtranslate":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");
                if($param2 == 1){
                    $addHaber = " AND isAdmin = 1";
                }else{
                    $addHaber = " AND isAdmin = 0 ";
                }
                
                $result = $this->db->query("SELECT laId, isAdmin, define, ar, en, tr FROM atranslate WHERE (define LIKE '%" . $sSearch . "%' OR ar LIKE '%" . $sSearch . "%' OR en LIKE '%" . $sSearch . "%' OR tr LIKE '%" . $sSearch . "%') $addHaber ORDER BY laId DESC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM atranslate WHERE (define LIKE '%" . $sSearch . "%' OR ar LIKE '%" . $sSearch . "%' OR en LIKE '%" . $sSearch . "%' OR tr LIKE '%" . $sSearch . "%') $addHaber ")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_atranslate/{$dt->isAdmin}/{$dt->laId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                    $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteAtranslate/{$dt->laId}' data-name='{$dt->define}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";

                    $returnToServer["aaData"][] = array(
                        $dt->define,
                        $dt->ar,
                        $dt->en,
                        $dt->tr,
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditAtranslate":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $this->form_validation->set_rules('define', 'Define Word', 'required');
                $this->form_validation->set_rules('ar', 'Arabic', 'required');
                $this->form_validation->set_rules('en', 'English', 'required');
                $this->form_validation->set_rules('tr', 'Turkish', 'required');

                $id = $this->Checkdata->checkInputData($this->input->post("id"));

                $define = $this->input->post("define");
                    $atranslate = $this->db->query("SELECT isAdmin, ar, en ,tr FROM atranslate WHERE define = '$define' AND laId != '$id'")->result_object();                        
                    if($atranslate){
                        $hata = $this->Get_Lang->gl('define_word_already_exists',$adminLang);
                        $this->form_validation->set_rules('ss',"$hata",'required');
                        echo $hata;
                        break;
                    }
                    
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();      
                    $processArr["isAdmin"] = $this->input->post("isAdmin");
                    
                    $processArr["define"] = $this->input->post("define");
                    $processArr["ar"] = $this->input->post("ar");
                    $processArr["en"] = $this->input->post("en");
                    $processArr["tr"] = $this->input->post("tr");

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);
                    
                        $this->db->update("atranslate", $processArr, array('laId' => $id));
                    } else {
                        $this->db->insert("atranslate", $processArr);

                    }
                    echo 1;
                }
                break;

            case "deleteAtranslate":
                $id = $param2;
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);

                $this->db->delete("atranslate", array('laId' => $id));
                echo 1;
                break;
             
                
            //Users
            case "getUsers":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT usId, username, lastlogin FROM users WHERE usId != 1 AND (username LIKE '%" . $sSearch . "%')AND isDeleted = 0 ORDER BY usId DESC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM users WHERE isDeleted = 0 AND usId != 1")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon'><a href='/admin/addEditUsers/{$dt->usId}' title='".$this->Get_Lang->gl('edit',$adminLang)."'><i class='glyphicon glyphicon-pencil'></i></a></div>";
//                    $actions .= "<div class='actionsIcon delete'><a href='javascript:;' data-href='/admin/ajax/deleteUser/{$dt->usId}' data-name='{$dt->username}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                    $date = Date("d/m/Y", strtotime($dt->lastlogin));
                    $returnToServer["aaData"][] = array(
                        $dt->username,
                        $date,
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditUsers":

                $this->load->helper('form');
                $this->load->library('form_validation');

                $this->form_validation->set_rules('username', $this->Get_Lang->gl('username',$adminLang), 'required');
                $this->form_validation->set_rules('thePassword', $this->Get_Lang->gl('password',$adminLang), 'required');

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                    $processArr = array();

                    $processArr["username"] = $this->Checkdata->checkInputData($this->input->post("username"));
                    $processArr["thePassword"] = $this->Checkdata->checkInputData(sha1($this->input->post("thePassword")));
                    $processArr["lastlogin"] = Date("Y-m-d H:i:s");

                    if ($id != 0) {
                        // check password
                        $checkPassword = $this->db->query('SELECT thePassword FROM users WHERE username = "' . $processArr["username"] . '" AND isDeleted = 0')->result_object();
                        if ($checkPassword) {
                            if ($checkPassword[0]->thePassword == $this->input->post("thePassword")) {
                                unset($processArr["thePassword"]);
                            }
                        }

                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);
                        $this->db->update("users", $processArr, array('usId' => $id));
                    } else {

                        $this->db->insert("users", $processArr);
                    }
                    echo 1;
                }

                break;

            case "deleteUser":
                $id = $param2;
                $processArr = array();
                $processArr["isDeleted"] = 1;
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);
                $this->db->where('usId', $id);
                $this->db->update("users", $processArr, array('usId' => $id));
                echo 1;
                break;                          
             
//         case "changeProducerActive":
//                $producers = $param2;
//                $processArr = array();
//                $this->Checkdata->isNotNumeric($producers);
//                $this->Checkdata->ifEmptyOrZero($producers);
//
//                $check = $this->db->query("SELECT isActive FROM producers WHERE prId = '$producers'")->result();
//                if ($check[0]->isActive == 1) {
//                    $processArr['isActive'] = 0;
//                }else{
//                    $processArr['isActive'] = 1;
//                }
//                $this->db->update("producers", $processArr, array('prId' => $producers));
//
//                echo 1;
//                break;   
            
            case "addUrlLink":
                $processArr2 = array();
                
                    $processArr2['content_id'] = $param2;
                    $processArr2['page'] = "$param3";
                    $url = str_replace(" ","-", $param4);
                    $processArr2['url'] = "$url";
                    $this->db->insert("links", $processArr2);                
                echo 1;       
                break;
                
            case "editUrlLink":
                $processArr2 = array();
                
                    $url = str_replace(" ","-", $param4);
                    $processArr2['url'] = "$url";
                    $this->db->where('page',"$param3")->where('content_id',$param2);
                    $this->db->update("links", $processArr2);
                echo 1;
                break;
                
            case "deleteUrlLink":
                $processArr2 = array();
                
                    $this->db->where('page',"$param3")->where('content_id',$param2);
                    $this->db->delete("links");
                echo 1;
                break;

            // About Us
            case "getAboutUs":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT * FROM about_us WHERE (theText1 LIKE '%" . $sSearch . "%' OR theText2 LIKE '%" . $sSearch . "%' OR theText3 LIKE '%" . $sSearch . "%' ) ORDER BY abId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM about_us WHERE (theText1 LIKE '%" . $sSearch . "%' OR theText2 LIKE '%" . $sSearch . "%' OR theText3 LIKE '%" . $sSearch . "%' )")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {
                    
                    $actions = "<div class='actionsIcon'><a href='/admin/edit_aboutUs/".$dt->abId."' title='".$this->Get_Lang->gl('edit',$adminLang)."'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                    if($dt->abId == 1){
                        $theText = '<img src="/public/uploads/php/files/aboutUs/' . $dt->thePhoto . '" width="280">';
                    }else{
                        $theText = strip_tags(word_limiter($dt->theText1, 40));
                    }
                    $returnToServer["aaData"][] = array(
                        $dt->theTitle1.'<br>'.$dt->theTitle2.'<br>'.$dt->theTitle3,
                        $theText,
                        strip_tags(word_limiter($dt->theText2, 40)),
                        strip_tags(word_limiter($dt->theText3, 40)),
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "editAboutUs":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $id = $this->Checkdata->checkInputData($this->input->post("id"));
                $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theText$value->laId", $this->Get_Lang->gl('the_text',$adminLang)." ".$value->theName, 'required');
                }
                
                $this->form_validation->set_rules('id', 'id', 'required');

                $thePhoto = $this->Checkdata->checkInputData($this->input->post("file"));
                
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();                     
                            

                    foreach ($lang as $key => $value) {
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                        $processArr["theText$value->laId"] = $this->input->post("theText$value->laId");
                    }                    

                    if ($thePhoto && $id == 1)
                        $processArr["thePhoto"] = $thePhoto;
                    
                    if($thePhoto && $id == 1){
                          $checkPhoto = $this->db->query("SELECT thePhoto FROM about_us WHERE abId = 1")->result();
                          $photoExist = "public/uploads/php/files/aboutUs/".$checkPhoto[0]->thePhoto;  
                          if ($checkPhoto && (file_exists($photoExist))) {
                                    unlink('public/uploads/php/files/aboutUs/'. $checkPhoto[0]->thePhoto);
                                    unlink('public/uploads/php/files/aboutUs/thumbnail/'. $checkPhoto[0]->thePhoto);
                                    unlink('public/uploads/php/files/aboutUs/medium/'. $checkPhoto[0]->thePhoto);
                            }
                    } 

                    $this->db->update("about_us", $processArr, array('abId' => $id));                  
                    echo 1;
                }
                break;
       
            // Home Slider
            case "getHomeSlider":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");
                
                $result = $this->db->query("SELECT * FROM home_slider ORDER BY hoId DESC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM home_slider")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {                   
                    
                    $actions = "<div class='actionsIcon'><a href='/admin/add_edit_home_slider/{$dt->hoId}' title='".$this->Get_Lang->gl('edit',$adminLang)."'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                    $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteHomeSlider/{$dt->hoId}' data-name='".$this->Get_Lang->gl('the_photo',$adminLang)."' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";

                    $returnToServer["aaData"][] = array(
                        '<img src="'.$dt->thePhoto.'" height="90">',
                        $dt->theText1,
                        $dt->theText2,
                        $dt->theText3,
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditHomeSlider":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $this->form_validation->set_rules('id', 'Photo', 'required');


                $thePhoto = $this->input->post("file");

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                    $processArr = array();
                    $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();

                    foreach ($lang as $key => $value) {
                        $processArr["theText$value->laId"] = $this->input->post("theText$value->laId");
                    }
                    $processArr["theLink"] = $this->input->post("theLink");
                

                    // new photo code 
//                $thePhoto = $this->input->post("file");$thePhoto = str_replace("[","",$thePhoto);
//                $thePhoto = str_replace("]","",$thePhoto);$thePhoto = str_replace('"','',$thePhoto);
//                $files = explode(',', $thePhoto);
//                if(is_array($files)){
//                    foreach ($files as $value) {
//                        if ($value != "") {
//                    $processArr = array('thePhoto' => $value,'productId'=> $ProductId);
//                    $this->db->insert("blog_gallery", $processArr);
//                        }
//                    }  
//                }else{
//                    $processArr = array('thePhoto' => $thePhoto,'productId'=> $ProductId);
//                   $this->db->insert("blog_gallery", $processArr);
//                }           
 
                    if ($thePhoto)
                        $processArr["thePhoto"] = $thePhoto;

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);

                        $this->db->update("home_slider", $processArr, array('hoId' => $id));
                    } else {
                        $this->db->insert("home_slider", $processArr);
                    }
                    echo 1;
                }
                break;

            case "deleteHomeSlider":
                $id = $param2;
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);
                    
                $this->db->delete("home_slider", array('hoId' => $id));
                echo 1;
                break;  
            

            
// FAQ CAtegories
        case "getFaqCategories":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT * FROM faq_categories WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%' )  ORDER BY caId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM faq_categories  WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%' )")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                $actions = " ";
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon'><a href='/admin/add_edit_faq_categories/{$dt->caId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                $checkData = $this->db->query("SELECT coId FROM faq WHERE categoryId = '$dt->caId'")->result();
                if($checkData){}else{
                    $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteFaqCategories/{$dt->caId}' data-name='".$dt->theTitle2."' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                }
                
                    $returnToServer["aaData"][] = array(                        
                       $dt->theTitle1,
                       $dt->theTitle2,
                       $dt->theTitle3,
                       '<div class="btn-group" role="group" aria-label="..."><a href="/admin/faq/'.$dt->caId.'" class="btn btn-primary right">
                        <i class="fa fa-plus" aria-hidden="true"></i> '.$this->Get_Lang->gl("details",$adminLang).' </a></div>',
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;            
         
        case "addEditFaqCategories":
                $this->load->helper('form');
                $this->load->library('form_validation');
                $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                
                $id = $this->Checkdata->checkInputData($this->input->post("id"));
               
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                   
                    foreach ($lang as $key => $value) {
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                    } 

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);
                    
                        $this->db->update("faq_categories", $processArr, array('caId' => $id));
                    } else {
                        $this->db->insert("faq_categories", $processArr);

                    }
                    echo 1;
                }
                break;
                
        case "deleteFaqCategories":
                $id = $param2;
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);
       
                $this->db->delete("faq_categories", array('caId' => $id));

                echo 1;
                break;    
            
// FAQ
        case "getFaq":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT * FROM faq WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theText1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theText2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%' OR theText3 LIKE '%" . $sSearch . "%')"
                        . "  AND categoryId = '$param2' ORDER BY coId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM faq  WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theText1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theText2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%' OR theText3 LIKE '%" . $sSearch . "%')"
                        . " AND categoryId = '$param2'")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                $actions = " ";
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon'><a href='/admin/add_edit_faq/{$dt->categoryId}/{$dt->coId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                    $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteFaq/{$dt->coId}' data-name='".$dt->theTitle2."' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                
                
                    $returnToServer["aaData"][] = array(                        
                       $dt->theTitle1,
                       $dt->theTitle2,
                       $dt->theTitle3,                      
                       $actions
                    );
                }
                echo json_encode($returnToServer);
                break;            
         
        case "addEditFaq":
                $this->load->helper('form');
                $this->load->library('form_validation');
                $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                
                $id = $this->Checkdata->checkInputData($this->input->post("id"));
               
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                    $processArr['categoryId'] = $this->Checkdata->checkInputData($this->input->post("categoryId"));

                    foreach ($lang as $key => $value) {
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                        $processArr["theText$value->laId"] = $this->input->post("theText$value->laId");                        
                    } 

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);
                    
                        $this->db->update("faq", $processArr, array('coId' => $id));
                    } else {
                        $this->db->insert("faq", $processArr);

                    }
                    echo 1;
                }
                break;
                
        case "deleteFaq":
                $id = $param2;
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);
       
                $this->db->delete("faq", array('coId' => $id));

                echo 1;
                break;    

            
            
// getBlogCategories
        case "getBlogCategories":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT * FROM blog_categories WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%' )  ORDER BY caId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM blog_categories  WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%' )")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                $actions = " ";
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon'><a href='/admin/add_edit_blog_categories/{$dt->caId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                $checkData = $this->db->query("SELECT blId FROM blog WHERE categoryId = '$dt->caId'")->result();
                if($checkData){}else{
                    $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteBlogCategories/{$dt->caId}' data-name='".$dt->theTitle2."' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                }
                
                    $returnToServer["aaData"][] = array(                        
                       $dt->theTitle1,
                       $dt->theTitle2,
                       $dt->theTitle3,
                       '<div class="btn-group" role="group" aria-label="..."><a href="/admin/blog/'.$dt->caId.'" class="btn btn-primary right">
                        <i class="fa fa-plus" aria-hidden="true"></i> '.$this->Get_Lang->gl("details",$adminLang).' </a></div>',
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;            
         
        case "addEditBlogCategories":
                $this->load->helper('form');
                $this->load->library('form_validation');
                $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                
                $id = $this->Checkdata->checkInputData($this->input->post("id"));
               
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                   
                    foreach ($lang as $key => $value) {
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                    } 

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);
                    
                        $this->db->update("blog_categories", $processArr, array('caId' => $id));
                    } else {
                        $this->db->insert("blog_categories", $processArr);

                    }
                    echo 1;
                }
                break;
                
        case "deleteBlogCategories":
                $id = $param2;
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);
       
                $this->db->delete("blog_categories", array('caId' => $id));

                echo 1;
                break;    

                
         // Blog
            case "getBlog":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");               
                
                $result = $this->db->query("SELECT * FROM blog WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theText1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theText2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%' OR theText3 LIKE '%" . $sSearch . "%') "
                        . " AND categoryId = '$param2' ORDER BY blId DESC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM blog WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theText1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theText2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%' OR theText3 LIKE '%" . $sSearch . "%') AND categoryId = '$param2' ")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_blog/{$dt->categoryId}/{$dt->blId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                    $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteBlog/{$dt->blId}' data-name='{$dt->theTitle2}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";

                    $returnToServer["aaData"][] = array(
                        '<img src="'.$dt->thePhoto.'" width="80">',
                        $dt->theTitle1,
                        $dt->theTitle2,
                        $dt->theTitle3,
                        Date("d/m/Y", strtotime($dt->dateTime)),
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;
 case "addEditFaq":
                $this->load->helper('form');
                $this->load->library('form_validation');
                $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                
                $id = $this->Checkdata->checkInputData($this->input->post("id"));
               
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                    $processArr['categoryId'] = $this->Checkdata->checkInputData($this->input->post("categoryId"));

                    foreach ($lang as $key => $value) {
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                        $processArr["theText$value->laId"] = $this->input->post("theText$value->laId");                        
                    } 

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);
                    
                        $this->db->update("faq", $processArr, array('coId' => $id));
                    } else {
                        $this->db->insert("faq", $processArr);

                    }
                    echo 1;
                }
                break;
          
            case "addEditBlog":
                $this->load->helper('form');
                $this->load->library('form_validation');

                 $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                    $this->form_validation->set_rules("theText$value->laId", $this->Get_Lang->gl('the_text',$adminLang)." ".$value->theName, 'required');
                }
                $id = $this->Checkdata->checkInputData($this->input->post("id"));
                $this->form_validation->set_rules('url', 'URL', 'required');
                $url = urlencode(str_replace(" ","-",$this->input->post("url")));
                $page = 'blog';
                $theURL = $this->db->query("SELECT id FROM links WHERE url = '$url' ")->result();
                if($id > 0){$theURL = $this->db->query("SELECT id FROM links WHERE url = '$url' AND content_id != '$id' ")->result();}
                if($theURL){
                    $this->form_validation->set_rules('url2', 'Girdiğiniz URL kullanılmaktadır', 'required');
                }
                
                $thePhoto = $this->Checkdata->checkInputData($this->input->post("file"));

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                    $processArr['categoryId'] = $this->Checkdata->checkInputData($this->input->post("categoryId"));
                    foreach ($lang as $key => $value) {
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                        $processArr["theText$value->laId"] = $this->input->post("theText$value->laId");                        
                    } 
                    
                    if ($thePhoto)
                        $processArr["thePhoto"] = $thePhoto;

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);

                        $this->db->update("blog", $processArr, array('blId' => $id));
                        echo  header("Location:/admin/ajax/editUrlLink/$id/$page/$url");

                    } else {
                        $processArr["dateTime"] = Date("Y-m-d H:i:s");                          
                        $this->db->insert("blog", $processArr);
                        $id = $this->db->insert_id();
                        echo  header("Location:/admin/ajax/addUrlLink/$id/$page/$url");

                    }
                    echo 1;
                }
                break;

            case "deleteBlog":
                $id = $param2;
                $page = 'blog';
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);
    
                $this->db->delete("blog", array('blId' => $id));
                echo  header("Location:/admin/ajax/deleteUrlLink/$id/$page");

                echo 1;
                break;
        
         
         
         // Brands
            case "getBrands":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");
             
                
                $result = $this->db->query("SELECT brId, theTitle1, theTitle2, theTitle3, thePhoto FROM brands WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND isDeleted = 0 ORDER BY brId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM brands WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND isDeleted = 0")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {
                    if($adminLang == 1){$tagName = $dt->theTitle1;}elseif($adminLang == 3){$tagName = $dt->theTitle3;}else{$tagName = $dt->theTitle2;}
                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_brand/{$dt->brId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                     $check = $this->db->query("SELECT caId FROM category_details WHERE markaId = '$dt->brId' ")->result();
                    if($check){}else{
                        $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteBrands/{$dt->brId}' data-name='{$tagName}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                    }

                    $returnToServer["aaData"][] = array(
                        '<img src="'.$dt->thePhoto.'" width="80">',
                        $dt->theTitle1,
                        $dt->theTitle2,
                        $dt->theTitle3,
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditBrand":
                $this->load->helper('form');
                $this->load->library('form_validation');

                  $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                $id = $this->Checkdata->checkInputData($this->input->post("id"));
                if ($id == 0) {
                    $this->form_validation->set_rules("file", $this->Get_Lang->gl('the_photo',$adminLang), 'required');
                }
                
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                    
                foreach ($lang as $key => $value) {                
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                 }
                    $thePhoto = $this->Checkdata->checkInputData($this->input->post("file"));
                    
                        if ($thePhoto)
                        $processArr["thePhoto"] = $thePhoto;
                 

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);

                        $this->db->update("brands", $processArr, array('brId' => $id));

                    } else {
                        $this->db->insert("brands", $processArr);

                    }
                    echo 1;
                }
                break;

            case "deleteBrands":
                $id = $param2;
                $processArr = array();
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);             
                      $processArr['isDeleted'] = 1;      
                $this->db->update("brands",$processArr, array('brId' => $id));

                echo 1;
                break;
         
         
         // Tags Categories
            case "getTagsCategories":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");
             
                
                $result = $this->db->query("SELECT taId, theTitle1, theTitle2, theTitle3 FROM tag_categories WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND isDeleted = 0 ORDER BY taId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM tag_categories WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND isDeleted = 0")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {
                    if($adminLang == 1){$tagName = $dt->theTitle1;}elseif($adminLang == 3){$tagName = $dt->theTitle3;}else{$tagName = $dt->theTitle2;}
                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_tags_categories/{$dt->taId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                     $check = $this->db->query("SELECT taId FROM tags WHERE productId = '$dt->taId' ")->result();
                    if($check){}else{
                        $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteTagsCategories/{$dt->taId}' data-name='{$tagName}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                    }

                    $returnToServer["aaData"][] = array(
                        $dt->theTitle1,
                        $dt->theTitle2,
                        $dt->theTitle3,
                        '<div class="btn-group" role="group" aria-label="..."><a href="/admin/tags/'.$dt->taId.'" class="btn btn-primary right">
                        <i class="fa fa-tag" aria-hidden="true"></i> '.$this->Get_Lang->gl("tags",$adminLang).' '.$tagName.' </a></div>',
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditTagsCategories":
                $this->load->helper('form');
                $this->load->library('form_validation');

                  $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                foreach ($lang as $key => $value) {                
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                 }

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);

                        $this->db->update("tag_categories", $processArr, array('taId' => $id));

                    } else {
                        $this->db->insert("tag_categories", $processArr);

                    }
                    echo 1;
                }
                break;

            case "deleteTagsCategories":
                $id = $param2;
                $processArr = array();
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);             
                      $processArr['isDeleted'] = 1;      
                $this->db->update("tag_categories",$processArr, array('taId' => $id));

                echo 1;
                break;
                    
         // Tags
            case "getTags":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");
             
                
                $result = $this->db->query("SELECT taId, theTitle1, theTitle2, theTitle3, productId FROM tags WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND productId = '$param2' AND isDeleted = 0 ORDER BY taId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM tags WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND productId = '$param2' AND isDeleted = 0")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {
                    if($adminLang == 1){$tagName = $dt->theTitle1;}elseif($adminLang == 3){$tagName = $dt->theTitle3;}else{$tagName = $dt->theTitle2;}
                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_tags/{$dt->productId}/{$dt->taId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                    $check = $this->db->query("SELECT caId FROM category_details WHERE (tagId LIKE '%\"$dt->taId\"%') ")->result();
                    if($check){}else{
                        $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteTags/{$dt->taId}' data-name='{$tagName}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                    }

                    $returnToServer["aaData"][] = array(
                        $dt->theTitle1,
                        $dt->theTitle2,
                        $dt->theTitle3,
//                        '<div class="btn-group" role="group" aria-label="..."><a href="/admin/gallery/'.$dt->taId.'" class="btn btn-primary right">
//                        <i class="fa fa-plus" aria-hidden="true"></i> '.$this->Get_Lang->gl("add_photo_to",$adminLang).' '.$tagName.' </a></div>',
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditTags":
                $this->load->helper('form');
                $this->load->library('form_validation');

                  $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                foreach ($lang as $key => $value) {                
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                 }
                    $processArr["productId"] = $this->Checkdata->checkInputData($this->input->post("productId"));

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);

                        $this->db->update("tags", $processArr, array('taId' => $id));

                    } else {
                        $this->db->insert("tags", $processArr);

                    }
                    echo 1;
                }
                break;

            case "deleteTags":
                $id = $param2;
                $processArr = array();
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);             
                      $processArr['isDeleted'] = 1;      
                $this->db->update("tags",$processArr, array('taId' => $id));

                echo 1;
                break;
         
          
         
         // sizes
            case "getSizes":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");
             
                
                $result = $this->db->query("SELECT siId, theTitle1, theTitle2, theTitle3, symbol FROM sizes WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND isDeleted = 0 ORDER BY siId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM sizes WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND isDeleted = 0")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {
                    if($adminLang == 1){$tagName = $dt->theTitle1;}elseif($adminLang == 3){$tagName = $dt->theTitle3;}else{$tagName = $dt->theTitle2;}
                    
                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_sizes/{$dt->siId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                    $check = $this->db->query("SELECT caId FROM category_details WHERE (sizeId LIKE '%\"$dt->siId\"%') ")->result();
                    if($check){}else{
                        $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteSizes/{$dt->siId}' data-name='{$tagName}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                    }

                    $returnToServer["aaData"][] = array(
                        $dt->symbol,
                        $dt->theTitle1,
                        $dt->theTitle2,
                        $dt->theTitle3,
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditSizes":
                $this->load->helper('form');
                $this->load->library('form_validation');

                  $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                foreach ($lang as $key => $value) {                
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                 }
                        $processArr["symbol"] = $this->input->post("symbol");

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);

                        $this->db->update("sizes", $processArr, array('siId' => $id));

                    } else {
                        $this->db->insert("sizes", $processArr);

                    }
                    echo 1;
                }
                break;

            case "deleteSizes":
                $id = $param2;
                $processArr = array();
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);             
                      $processArr['isDeleted'] = 1;      
                $this->db->update("sizes",$processArr, array('siId' => $id));

                echo 1;
                break;
         
            
            
             
         // colors
            case "getColors":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");
             
                
                $result = $this->db->query("SELECT coId, theTitle1, theTitle2, theTitle3, theColor FROM colors WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND isDeleted = 0 ORDER BY coId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM colors WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND isDeleted = 0")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {
                    if($adminLang == 1){$tagName = $dt->theTitle1;}elseif($adminLang == 3){$tagName = $dt->theTitle3;}else{$tagName = $dt->theTitle2;}
                    
                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_colors/{$dt->coId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                     $check = $this->db->query("SELECT caId FROM category_details WHERE (colorId LIKE '%\"$dt->coId\"%') ")->result();
                    if($check){}else{
                        $actions .= "<div class='actionsIcon delete'><a title='".$this->Get_Lang->gl('delete',$adminLang)."' href='javascript:;' data-href='/admin/ajax/deleteColors/{$dt->coId}' data-name='{$tagName}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                    }
                    
                    $returnToServer["aaData"][] = array(
                        $dt->theTitle1,
                        $dt->theTitle2,
                        $dt->theTitle3,
                        '<div class="btn btn-primary color" style=" background-color:'.$dt->theColor.';"> Color </div>',
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditColors":
                $this->load->helper('form');
                $this->load->library('form_validation');

                  $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();
                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                
                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                foreach ($lang as $key => $value) {                
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                 }
                        $processArr["theColor"] = $this->input->post("theColor");

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);

                        $this->db->update("colors", $processArr, array('coId' => $id));

                    } else {
                        $this->db->insert("colors", $processArr);

                    }
                    echo 1;
                }
                break;

            case "deleteColors":
                $id = $param2;
                $processArr = array();
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);             
                      $processArr['isDeleted'] = 1;      
                $this->db->update("colors",$processArr, array('coId' => $id));

                echo 1;
                break;
         
           
            // Gallery
            case "getGallery":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");
                $ProductId = $param2;

                $result = $this->db->query("SELECT gaId, productId, thePhoto FROM gallery WHERE productId = '$ProductId' ORDER BY gaId DESC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM gallery  WHERE productId = '$ProductId'")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                $actions = " ";
                $mainPhoto = ' ';
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon delete'><a href='javascript:;' data-href='/admin/ajax/deleteGallery/{$dt->gaId}' data-name='".$this->Get_Lang->gl('the_photo',$adminLang)."' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                    if ($dt->gaId == 1) {
                        $mainPhoto = "<div class='actionsIcon published'><a href='javascript:;' data-name='".$this->Get_Lang->gl('the_photo',$adminLang)."'><i class='glyphicon glyphicon-ok-sign' style='color:#4cae4c;'></i></a> </div>";
                    } else {
                        $mainPhoto = "<div class='actionsIcon unPublished'><a href='javascript:;'  data-href='/admin/ajax/changeMainPhoto/{$dt->gaId}/{$dt->productId}' data-name='".$this->Get_Lang->gl('the_photo',$adminLang)."' title='".$this->Get_Lang->gl('active',$adminLang)."' class='publishButton'><i class='glyphicon glyphicon-remove-sign'></i></a> </div>";
                    }
                    $returnToServer["aaData"][] = array(
                        '<img src="/public/uploads/php/files/gallery/thumbnail/' . $dt->thePhoto . '" width="80">',
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;
                
            case "addGallery":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $this->form_validation->set_rules('file', 'Photo ', 'required');

                $thePhoto = $this->Checkdata->checkInputData($this->input->post("file"));
                $files = explode("|", $thePhoto);

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $ProductId = $this->Checkdata->checkInputData($this->input->post("menuId"));

            foreach ($files as $value) {

                if ($value != "") {
                    $processArr = array(
                        'thePhoto' => $value,
                        'productId'=> $ProductId
                    );
                   $this->db->insert("gallery", $processArr);
                }
            }                          

                    echo 1;
                }
                break;

            case "deleteGallery":
                $id = $param2;
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);

                $checkPhoto = $this->db->query("SELECT thePhoto FROM gallery WHERE gaId = $id")->result();
                if ($checkPhoto) {
                    unlink('public/uploads/php/files/gallery/' . $checkPhoto[0]->thePhoto);
                    unlink('public/uploads/php/files/gallery/thumbnail/' . $checkPhoto[0]->thePhoto);
                    unlink('public/uploads/php/files/gallery/medium/' . $checkPhoto[0]->thePhoto);
                }

                $this->db->delete("gallery", array('gaId' => $id));
                echo 1;
                break;             
      
            // Contact Us
            case "getContactUs":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT * FROM contact_us ")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM contact_us")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_contact_us/".$dt->coId."'><i class='glyphicon glyphicon-pencil'></i></a></div>";

                    $returnToServer["aaData"][] = array(
                        $dt->companyName,
                        $dt->emailAddress.'<br>'.$dt->emailAddress2,
                        $dt->phoneNumber.'/ '.$dt->phoneNumber2,
                        strip_tags(word_limiter($dt->theText1, 20)),
                        strip_tags(word_limiter($dt->theText2, 20)),
                        strip_tags(word_limiter($dt->theText3, 20)),
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;
                                                            
            case "addEditContactUs":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $this->form_validation->set_rules('emailAddress', 'E-posta', 'required');
                $this->form_validation->set_rules('phoneNumber', 'Telephone Numarası', 'required');
                $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();

                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theText$value->laId", $this->Get_Lang->gl('the_text',$adminLang)." ".$value->theName, 'required');
                }

                $id = $this->Checkdata->checkInputData($this->input->post("id"));

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                    $processArr["companyName"] = $this->Checkdata->checkInputData($this->input->post("companyName"));
                    $processArr["emailAddress"] = $this->Checkdata->checkInputData($this->input->post("emailAddress"));
                    $processArr["emailAddress2"] = $this->Checkdata->checkInputData($this->input->post("emailAddress2"));
                    $processArr["phoneNumber"] = $this->Checkdata->checkInputData($this->input->post("phoneNumber"));
                    $processArr["phoneNumber2"] = $this->Checkdata->checkInputData($this->input->post("phoneNumber2"));
                     foreach ($lang as $key => $value) {
                        $processArr["theText$value->laId"] = $this->input->post("theText$value->laId");
                     }
                    $processArr["latitude"] = $this->input->post("latitude");
                    $processArr["longitude"] = $this->input->post("longitude");

                    $this->db->update("contact_us", $processArr, array('coId' => $id));
                    echo 1;
                }
                break;
                
            
            // Social Media
            case "getSocialMedia":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT coId, facebook, instagram, twitter, youtube, whatsapp1, whatsapp2, whatsapp3, linkedin FROM contact_us WHERE coId = 1")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM contact_us")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_social_media'><i class='glyphicon glyphicon-pencil'></i></a></div>";

                    $returnToServer["aaData"][] = array(
                        '<a href="' . $dt->facebook . '" target="_blank">' . $dt->facebook . '</a>',
                        '<a href="' . $dt->instagram . '" target="_blank">' . $dt->instagram . '</a>',
                        '<a href="' . $dt->twitter . '" target="_blank">' . $dt->twitter . '</a>',
                        '<a href="' . $dt->youtube . '" target="_blank">' . $dt->youtube . '</a>',
//                        '<a href="' . $dt->linkedin . '" target="_blank">' . $dt->linkedin . '</a>',
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditSocialMedia":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $this->form_validation->set_rules('id', 'id', 'required');


                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                    $processArr = array();
                    $processArr["facebook"] = $this->Checkdata->checkInputData($this->input->post("facebook"));
                    $processArr["instagram"] = $this->Checkdata->checkInputData($this->input->post("instagram"));
                    $processArr["twitter"] = $this->Checkdata->checkInputData($this->input->post("twitter"));
                    $processArr["youtube"] = $this->Checkdata->checkInputData($this->input->post("youtube"));
                    $processArr["whatsapp1"] = $this->Checkdata->checkInputData($this->input->post("whatsapp1"));
                    $processArr["whatsapp2"] = $this->Checkdata->checkInputData($this->input->post("whatsapp2"));
                    $processArr["whatsapp3"] = $this->Checkdata->checkInputData($this->input->post("whatsapp3"));
                    $processArr["messanger"] = $this->Checkdata->checkInputData($this->input->post("messanger"));
                    $processArr["linkedin"] = $this->Checkdata->checkInputData($this->input->post("linkedin"));

                    $this->db->update("contact_us", $processArr, array('coId' => 1));

                    echo 1;
                }
                break;
                            

      // setting
            case "getSetting":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT seId, theName, theValue FROM site_setting WHERE seId < 4 ORDER BY FIELD(seId,'3')DESC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM site_setting ")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {
                    if ($dt->seId < 7) {
                    if ($dt->seId == 3) {
                        $theValue = '<img src="/public/uploads/php/files/logos/thumbnail/' . $dt->theValue . '" width="80">';
                    } elseif ($dt->seId == 1 || $dt->seId == 2 || $dt->seId == 7 || $dt->seId == 8) {
                        $theValue = '<div  class="btn btn-primary color" style=" background-color:' . $dt->theValue . ';"> Color </div>';
                    } else {
                        $theValue = strip_tags(word_limiter($dt->theValue, 20));
                    }
                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_setting/{$dt->seId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
//                    $actions .= "<div class='actionsIcon delete'><a href='javascript:;' data-href='/admin/ajax/deleteMenuList/{$dt->meId}' data-name='{$dt->arName}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";

                    $returnToServer["aaData"][] = array(
                        $dt->theName,
                        $theValue,
                        $actions
                    );
                    }
                }
                echo json_encode($returnToServer);
                break;

            case "addEditSetting":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $id = $this->Checkdata->checkInputData($this->input->post("id"));
                if ($id == 1 || $id == 2 || $id == 7 || $id == 8) {
                    $this->form_validation->set_rules('theColor', 'Color', 'required');
                }
                $this->form_validation->set_rules('id', 'id', 'required');
                $thePhoto = $this->Checkdata->checkInputData($this->input->post("file"));

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {

                    $processArr = array();
                    $prcessArr["seId"] = $id;
                    if ($id == 3) {
                        if ($thePhoto) {
                            $processArr["theValue"] = $thePhoto;
                        }
                    } elseif ($id == 1 || $id == 2 || $id == 7 || $id == 8) {
                        $processArr["theValue"] = $this->input->post("theColor");
                    } elseif ($id == 4 || $id == 5) {
                        $processArr["theValue"] = $this->input->post("theData");
                    } elseif ($id == 6) {
                        $processArr["theValue"] = $this->input->post("theData2");
                    }
                    
                    if($thePhoto && $id == 3){
                          $checkPhoto = $this->db->query("SELECT theValue as thePhoto FROM site_setting WHERE seId = $id")->result();
                          $photoExist = "public/uploads/php/files/logos/".$checkPhoto[0]->thePhoto;  
                          if ($checkPhoto && (file_exists($photoExist))) {
                                    unlink('public/uploads/php/files/logos/'. $checkPhoto[0]->thePhoto);
                                    unlink('public/uploads/php/files/logos/thumbnail/'. $checkPhoto[0]->thePhoto);
                                    unlink('public/uploads/php/files/logos/medium/'. $checkPhoto[0]->thePhoto);
                            }
                    } 
                    $this->Checkdata->isNotNumeric($id);
                    $this->Checkdata->ifEmptyOrZero($id);
                    $this->db->update("site_setting", $processArr, array('seId' => $id));

                    echo 1;
                }
                break;

     // Contact Us Form
            case "getContactUsForm":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT * FROM contactus_form WHERE (theName LIKE '%" . $sSearch . "%' OR emailAddress LIKE '%" . $sSearch . "%') ORDER BY coId DESC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM contactus_form")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {

                    $returnToServer["aaData"][] = array(
                        $dt->theName,
//                        $dt->companyName,
//                        $dt->phoneNumber,
                        $dt->emailAddress,
//                        str_replace("_"," ","$dt->howToContact"),
                        $dt->note,
                        
                    );
                }
                echo json_encode($returnToServer);
                break; 
                
    // subscribers
            case "getSubscribers":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT * FROM subscribers WHERE (emailAddress LIKE '%" . $sSearch . "%') ORDER BY suId DESC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM subscribers")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $key =>$dt) {

                    $returnToServer["aaData"][] = array(
                        $key+1,
                        $dt->emailAddress,

                    );
                }
                echo json_encode($returnToServer);
                break;

                
      //  Categories
            case "getCategories":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");
                
                if($adminLang == 1){$theTitle = "theTitle1, theTitle1 as theTitle, theTitle2, theTitle3 ";}elseif($adminLang == 3){$theTitle = "theTitle3, theTitle3 as theTitle, theTitle1, theTitle2";}else{$theTitle = "theTitle2, theTitle2 as theTitle, theTitle1, theTitle3";}        
                $result = $this->db->query("SELECT caId, $theTitle, thePhoto ,theLike FROM categories WHERE (theTitle1 LIKE '%" . $sSearch . "%' OR theTitle2 LIKE '%" . $sSearch . "%' OR theTitle3 LIKE '%" . $sSearch . "%') AND parentId = '$param2' AND isDeleted = 0 ORDER BY caId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM categories WHERE isDeleted = 0 AND parentId = '$param2'")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();

                foreach ($result as$key => $dt) {
     
                    $excel = "<div class='btn-group' role='group' aria-label='...'>
                    <a href='/admin/productsExcelExport/".$dt->caId."' class='btn btn-primary right'> Export Excel </a></div>";
                    $actions = "<div class='actionsIcon'><a title='".$this->Get_Lang->gl('edit',$adminLang)."' href='/admin/add_edit_sub_categories/$param2/{$dt->caId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";

                    $checkCategory = $this->db->query("SELECT caId FROM categories WHERE parentId = $dt->caId AND isDeleted = 0")->result_object();

                    $checkCategoryDetails = $this->db->query("SELECT caId FROM category_details WHERE categoryId = $dt->caId AND isDeleted = 0")->result_object();

                    if($checkCategory){
                            $actions .= " ";
                            $categoryDetails = " ";
                            $categoryAdd ='<a href="/admin/categories/'.$dt->caId.'" class="btn btn-primary right">'.$dt->theTitle.' '.$this->Get_Lang->gl('categories',$adminLang).'</a>';

                    }elseif($checkCategoryDetails){
                            $actions .= " ";
                            $categoryDetails ='<a href="/admin/category_details/'.$dt->caId.'" class="btn btn-primary right">'.$dt->theTitle.' '.$this->Get_Lang->gl('details',$adminLang).'</a>';
                            $categoryAdd = " ";
                    }else{
                            $actions .= "<div class='actionsIcon delete'><a href='javascript:;' data-href='/admin/ajax/deleteCategories/{$dt->caId}' data-name='{$dt->theTitle}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                            $categoryDetails ='<a href="/admin/category_details/'.$dt->caId.'" class="btn btn-primary right">'.$dt->theTitle.' '.$this->Get_Lang->gl('details',$adminLang).'</a>';
                            $categoryAdd ='<a href="/admin/categories/'.$dt->caId.'" class="btn btn-primary right">'.$dt->theTitle.' '.$this->Get_Lang->gl('categories',$adminLang).'</a>';
                    }
                    $returnToServer["aaData"][] = array(
                        '<img src="'.$dt->thePhoto.'" width="100">',                        
                        $dt->theTitle1,
                        $dt->theTitle2,
                        $dt->theTitle3,
                        $categoryAdd,
                        $categoryDetails,
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditCategories":
                $this->load->helper('form');
                $this->load->library('form_validation');
                $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();

                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                $id = $this->Checkdata->checkInputData($this->input->post("id"));

                $this->form_validation->set_rules('url', 'URL', 'required');
                $url = urlencode(str_replace(" ","-",$this->input->post("url")));$page = 'categories';
                $theURL = $this->db->query("SELECT id FROM links WHERE url = '$url' ")->result();
                if($id > 0){$theURL = $this->db->query("SELECT id FROM links WHERE url = '$url' AND content_id != '$id' ")->result();}
                if($theURL){$this->form_validation->set_rules('url2', 'URL', 'required');}

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $processArr = array();
                    foreach ($lang as $key => $value) {
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                        $processArr["PageTitle$value->laId"] = $this->Checkdata->checkInputData($this->input->post("PageTitle$value->laId"));
                        $processArr["pageDesc$value->laId"] = $this->input->post("pageDesc$value->laId");
                    }                    
//                    $processArr["traceCode"] = $this->input->post("traceCode");

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);

                        $this->db->update("categories", $processArr, array('caId' => $id));
                         header("Location:/admin/ajax/editUrlLink/$id/$page/$url");

                    } else {
                        $this->db->insert("categories", $processArr);
                        $id = $this->db->insert_id();
                         header("Location:/admin/ajax/addUrlLink/$id/$page/$url");
                    }
                    echo $id;
                }
                break;


        case "deleteCategories":
                $id = $param2;
                $page = 'categories';                
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);

                $processArr = Array();
                $processArr['isDeleted'] = 1;
                $this->db->update("categories",$processArr,array('caId' => $id));
                echo  header("Location:/admin/ajax/deleteUrlLink/$id/$page");

                echo 1;
                break;

            case "addEditSubCategories":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();

                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theTitle$value->laId", $this->Get_Lang->gl('the_title',$adminLang)." ".$value->theName, 'required');
                }
                
                $id = $this->Checkdata->checkInputData($this->input->post("id"));

                $this->form_validation->set_rules('url', 'URL', 'required');
                $url = urlencode(str_replace(" ","-",$this->input->post("url")));
                $page = 'categories';
                $theURL = $this->db->query("SELECT id FROM links WHERE url = '$url' ")->result();
                if($id > 0){$theURL = $this->db->query("SELECT id FROM links WHERE url = '$url' AND content_id != '$id' ")->result();}
                if($theURL){
                    $this->form_validation->set_rules('url2', 'URL', 'required');
                }

                $thePhoto = $this->Checkdata->checkInputData($this->input->post("file"));

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                    $processArr = array();
                    
                    foreach ($lang as $key => $value) {
                        $processArr["theTitle$value->laId"] = $this->input->post("theTitle$value->laId");
                        $processArr["PageTitle$value->laId"] = $this->Checkdata->checkInputData($this->input->post("PageTitle$value->laId"));
                        $processArr["pageDesc$value->laId"] = $this->input->post("pageDesc$value->laId");
                    } 
                    
                    $processArr["theLike"] = $this->input->post("theLike");
                    $processArr["parentId"] = $this->Checkdata->checkInputData($this->input->post("parentId"));
//                    $processArr["traceCode"] = $this->input->post("traceCode");

                    if ($thePhoto) {
                            $processArr["thePhoto"] = $thePhoto;
                    }

                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);

                     if ($thePhoto) {
                        $checkPhoto = $this->db->query("SELECT thePhoto FROM categories WHERE caId = $id")->result();
                        $photoExist = "public/uploads/php/files/categories/".$checkPhoto[0]->thePhoto;
                        if ($checkPhoto && (file_exists($photoExist))) {
                            unlink('public/uploads/php/files/categories/'. $checkPhoto[0]->thePhoto);
                            unlink('public/uploads/php/files/categories/thumbnail/'. $checkPhoto[0]->thePhoto);
                            unlink('public/uploads/php/files/categories/medium/'. $checkPhoto[0]->thePhoto);
                        }
                     }
                        $this->db->update("categories", $processArr, array('caId' => $id));
                         header("Location:/admin/ajax/editUrlLink/$id/$page/$url");

                    } else {
                        $this->db->insert("categories", $processArr);
                        $id = $this->db->insert_id();
                         header("Location:/admin/ajax/addUrlLink/$id/$page/$url");
                    }
                    echo 1;
                }
                break;

            


          // Category Details
            case "getCategoryDetails":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");
            
                if($param2 > 0){
                    $addtional = " AND DE.categoryId = $param2 ";
                    $addtional2 = " AND categoryId = $param2 ";
                }else{
                    $addtional = " ";
                    $addtional2 = " ";
                    $param2 = 0;
                }
                if($adminLang == 1){$theTitle = "theTitle1";}elseif($adminLang == 3){$theTitle = "theTitle3";}else{$theTitle = "theTitle2";}        
                $result = $this->db->query("SELECT DE.*, CA.$theTitle as categoryName FROM category_details DE INNER JOIN categories CA ON CA.caId= DE.categoryId "
                        . " WHERE (DE.theText1 LIKE '%" . $sSearch . "%' OR DE.theText2 LIKE '%" . $sSearch . "%' OR DE.theText3 LIKE '%" . $sSearch . "%') AND DE.isDeleted = 0 $addtional  ORDER BY DE.caId DESC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM category_details DE INNER JOIN categories CA ON CA.caId = DE.categoryId WHERE (theText1 LIKE '%" . $sSearch . "%' OR theText2 LIKE '%" . $sSearch . "%' OR theText3 LIKE '%" . $sSearch . "%') AND DE.isDeleted = 0 $addtional2")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                foreach ($result as $dt) {
                if($adminLang == 1){$theTitle = "theTitle1";}elseif($adminLang == 3){$theTitle = "theTitle3";}else{$theTitle = "theTitle2";}        
                    if ($dt->isActive == 1) {
                        $isActive = "<div class='actionsIcon published'> <a href='javascript:;' data-href='/admin/ajax/changeProductsActive/{$dt->caId}' data-name='{$theTitle}'  title='Activation' class='publishButton'><i class='glyphicon glyphicon-ok-sign' style='color:#4cae4c;'></i></a> </div>";
                    } else {
                        $isActive = "<div class='actionsIcon unPublished'><a href='javascript:;'  data-href='/admin/ajax/changeProductsActive/{$dt->caId}' data-name='{$theTitle}'  title='Activation' class='publishButton'><i class='glyphicon glyphicon-remove-sign'></i></a> </div>";
                    }

                    if ($dt->isPopular == 1) {
                        $isPopular = "<div class='actionsIcon published'> <a href='javascript:;' data-href='/admin/ajax/changeProductsPopular/{$dt->caId}' data-name='{$theTitle}'  title='Population' class='publishButton'><i class='glyphicon glyphicon-ok-sign' style='color:#4cae4c;'></i></a> </div>";
                    } else {
                        $isPopular = "<div class='actionsIcon unPublished'><a href='javascript:;'  data-href='/admin/ajax/changeProductsPopular/{$dt->caId}' data-name='{$theTitle}'  title='Population' class='publishButton'><i class='glyphicon glyphicon-remove-sign'></i></a> </div>";
                    }

                    $actions = "<div class='actionsIcon'><a href='/admin/add_edit_category_details/".$param2."/{$dt->caId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                    $actions .= "<div class='actionsIcon delete'><a href='javascript:;' data-href='/admin/ajax/deleteCategoryDetails/{$dt->caId}' data-name='{$theTitle}' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";

                    $returnToServer["aaData"][] = array(
                        $dt->categoryName,
                        strip_tags(word_limiter($dt->theText1, 20)),
                        strip_tags(word_limiter($dt->theText2, 20)),
                        strip_tags(word_limiter($dt->theText3, 20)),
//                        '<div class="btn-group" role="group" aria-label="..."><a href="/admin/add_options/'.$dt->caId.'" class="btn btn-primary right">
//                        <i class="fa fa-plus" aria-hidden="true"></i> Add Options </a></div>',
                        '<div class="btn-group" role="group" aria-label="..."><a href="/admin/details_slider/'.$dt->caId.'" class="btn btn-primary right">
                        <i class="fa fa-plus" aria-hidden="true"></i> '.$this->Get_Lang->gl("add_slider",$adminLang).' </a></div>',
                        $isPopular,
                      //  $isActive,
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditCategoryDetails":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $lang = $this->db->query("SELECT * FROM lang WHERE isDeleted = 0")->result_object();

                foreach ($lang as $key => $value) {
                    $this->form_validation->set_rules("theText$value->laId", $this->Get_Lang->gl('the_text',$adminLang)." ".$value->theName, 'required');
                }
                
                $this->form_validation->set_rules('categoryId', $this->Get_Lang->gl('Category',$adminLang), 'required');
                $this->form_validation->set_rules('thePrice', $this->Get_Lang->gl('Price',$adminLang), 'required');
                $this->form_validation->set_rules('markaId', $this->Get_Lang->gl('Brand',$adminLang), 'required');
                $this->form_validation->set_rules('quantity', $this->Get_Lang->gl('Quantity',$adminLang), 'required');
//                $this->form_validation->set_rules('colorId[]', $this->Get_Lang->gl('Color',$adminLang), 'required');
//                $this->form_validation->set_rules('sizeId[]', $this->Get_Lang->gl('size',$adminLang), 'required');



                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                    $processArr = array();


                    $processArr["categoryId"] = $this->input->post("categoryId");
                    $processArr["markaId"] = $this->input->post("markaId");
                    foreach ($lang as $key => $value) {
                        $processArr["theText$value->laId"] = $this->input->post("theText$value->laId");
                        $processArr["text$value->laId"] = $this->input->post("text$value->laId");
                    } 
                    $processArr["thePrice"] = $this->input->post("thePrice");
                    $processArr["sale"] = $this->input->post("sale");
                    $processArr["quantity"] = $this->input->post("quantity");
                    $processArr["tagId"] = json_encode($this->input->post("tagId[]"));
                    $processArr["colorId"] = json_encode($this->input->post("colorId[]"));
                    $processArr["sizeId"] = json_encode($this->input->post("sizeId[]"));
                    


                    if ($id != 0) {
                        $this->Checkdata->isNotNumeric($id);
                        $this->Checkdata->ifEmptyOrZero($id);

                        $this->db->update("category_details", $processArr, array('caId' => $id));

                    } else {
                        $processArr["date"] = Date("Y-m-d H:i:s");                        
                        $this->db->insert("category_details", $processArr);

                    }
                    echo 1;
                }
                break;

            case "changeProductsActive":
                 $id = $param2;
                $processArr = array();
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);

                $check = $this->db->query("SELECT isActive FROM category_details WHERE caId = '$id' ")->result();
                if ($check[0]->isActive == 1) {
                    $processArr['isActive'] = 0;
                }else{
                    $processArr['isActive'] = 1;
                }
                $this->db->update("category_details", $processArr, array('caId' => $id));

                echo 1;
                break;

            case "changeProductsPopular":
                 $id = $param2;
                $processArr = array();
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);

                $check = $this->db->query("SELECT isPopular FROM category_details WHERE caId = '$id'")->result();
                if ($check[0]->isPopular == 1) {
                    $processArr['isPopular'] = 0;
                }else{
                    $processArr['isPopular'] = 1;
                }
                $this->db->update("category_details", $processArr, array('caId' => $id));

                echo 1;
                break;

            case "deleteCategoryDetails":
                $id = $param2;
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);
                $processArr['isDeleted'] = 1;
                $this->db->update("category_details", $processArr, array('caId' => $id));

                echo 1;
                break;


         // Details Slider
            case "getDetailsSlider":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT slId, detailsId, thePhoto FROM sliders WHERE detailsId = '$param2' ORDER BY slId DESC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM sliders WHERE detailsId = '$param2'")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                $actions = " ";
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon delete'><a href='javascript:;' data-href='/admin/ajax/deleteDetailsSlider/{$dt->slId}' data-name='This Photo' class='deleteButton'><i class='glyphicon glyphicon-trash'></i></a> </div>";
                    $returnToServer["aaData"][] = array(
                        '<img src="'.$dt->thePhoto.'" width="180">',
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addDetailsSlider":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $this->form_validation->set_rules('file', 'Photo ', 'required');

                $thePhoto = $this->Checkdata->checkInputData($this->input->post("file"));
                $files = explode("|", $thePhoto);

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $detailsId = $this->Checkdata->checkInputData($this->input->post("detailsId"));

            foreach ($files as $value) {

                if ($value != "") {
                    $processArr = array(
                        'thePhoto' => $value,
                        'detailsId'=> $detailsId
                    );
                   $this->db->insert("sliders", $processArr);
                }
            }
                    echo 1;
                }
                break;

            case "deleteDetailsSlider":
                $id = $param2;
                $this->Checkdata->isNotNumeric($id);
                $this->Checkdata->ifEmptyOrZero($id);

                $this->db->delete("sliders", array('slId' => $id));
                echo 1;
                break;
  
                



// Panner Photos
            case "getPannerPhotos":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT paId, theTitle, thePhoto FROM panner_photos ORDER BY paId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM panner_photos")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                $actions = " ";
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon'><a href='/admin/edit_panner_photos/{$dt->paId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                    $returnToServer["aaData"][] = array(
                        '<img src="'.$dt->thePhoto.'" height="70">',
                        $dt->theTitle,                       
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "editPannerPhotos":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $this->form_validation->set_rules('file', 'Photo ', 'required');

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                    $processArr['thePhoto'] = $this->input->post("file");
                    $processArr['theLink'] = $this->input->post("theLink");

                    if($this->db->update("panner_photos", $processArr, array('paId' => $id)))
                    echo 1;
                }
                break;
                

// catalog
            case "getCatalog":
                $sEcho = $this->input->post("sEcho");
                $sSearch = $this->input->post("sSearch");
                $iDisplayStart = $this->input->post("iDisplayStart");
                $iDisplayLength = $this->input->post("iDisplayLength");

                $result = $this->db->query("SELECT caId, theTitle, theFile FROM catalog ORDER BY caId ASC LIMIT $iDisplayStart, $iDisplayLength")->result();
                $resultCount = $this->db->query("SELECT COUNT(1) as cnt FROM catalog")->row()->cnt;
                $returnToServer = array();
                $returnToServer["sEcho"] = $sEcho;
                $returnToServer["iTotalRecords"] = $resultCount;
                $returnToServer["iTotalDisplayRecords"] = $resultCount;
                $returnToServer["aaData"] = array();
                $actions = " ";
                foreach ($result as $dt) {

                    $actions = "<div class='actionsIcon'><a href='/admin/add_edit_catalog/{$dt->caId}'><i class='glyphicon glyphicon-pencil'></i></a></div>";
                    $returnToServer["aaData"][] = array(
                        $this->Get_Lang->gl('the_file',$adminLang).' '.$dt->theTitle,
                        '<a target="_blank" href="/public/uploads/php/files/catalog/' . $dt->theFile . '" width="80">'.$this->Get_Lang->gl('open_file',$adminLang).'</a>',                        
                        $actions
                    );
                }
                echo json_encode($returnToServer);
                break;

            case "addEditCatalog":
                $this->load->helper('form');
                $this->load->library('form_validation');

                $this->form_validation->set_rules('file', 'Photo ', 'required');

                $thePhoto = $this->Checkdata->checkInputData($this->input->post("file"));
                $files = explode("|", $thePhoto);

                if ($this->form_validation->run() === FALSE) {
                    echo validation_errors();
                } else {
                    $id = $this->Checkdata->checkInputData($this->input->post("id"));
                    $processArr['theFile'] = $files[0];
                    
                   if($thePhoto){
                        $checkPhoto = $this->db->query("SELECT theFile FROM catalog WHERE caId = $id")->result();
                          $photoExist = "public/uploads/php/files/catalog/".$checkPhoto[0]->theFile;  
                          if ($checkPhoto && (file_exists($photoExist))) {
                                    unlink('public/uploads/php/files/catalog/'. $checkPhoto[0]->theFile);
                            }
                    } 
                    
                    if($this->db->update("catalog", $processArr, array('caId' => $id)))
                    echo 1;
                }
                break;                 

                
        case "getTagsData":
                $tagId = $this->Checkdata->checkInputData($this->input->post("tagId"));
               
            $adminLang = $this->session->userdata("adminLang");        
            if($adminLang == 1){$theTitle = "theTitle1 as theTitle ";}elseif($adminLang == 3){$theTitle = "theTitle3 as theTitle";}else{$theTitle = "theTitle2 as theTitle";}
            $array = $this->db->query("SELECT taId, $theTitle FROM tags WHERE productId = '$tagId'")->result_object();
                    
                    echo json_encode($array);                
                break;                 
                        
                
              
                
//                $insertedId = $this->db->insert_id();
//                        $session = array(
//                            'memberFirstName' => $processArr['firstName'],
//                            'memberId' => $insertedId
//                        );
        }
    }

}

//$medicalEquipmentsSubCategories = $this->db->query("SELECT meSubCatId, theTitle, categoryId, theDetails FROM medical_equipments_sub_categories WHERE meSubCatId = $id")->result_object();
