/** * Cnews::dosearch() * * @param string $st * @param integer $offset * @param integer $limit * @return */ function dosearch($st = "", $offset = 0, $limit = 5) { $this->load->helper('text'); $separate = "aaaaaaa23423dddeeeeee838234eeeeefffffff99923ffffffsdfsdfsdfsdf"; $sep = "239847293dlkfaslf::sdflksdf::sdkfjsldf"; $this->load->helper('remove_vn'); $logged_role = $this->logged_in_user->adminrole->id; if ($_SERVER['REQUEST_METHOD'] == "GET") { $key_list = explode($sep, $st); $news = new article(); if ($key_list[0] != $separate) { $news->like('title_vietnamese', $key_list[0]); } if ($key_list[1] != $separate) { $news->where('newscatalogue_id', $key_list[1]); } else { $news->where_related_newscatalogue('parentcat_id', 7); } if ($key_list[2] != $separate) { $news->where('created >', $key_list[2]); $news->where('created <', $key_list[3]); } if ($key_list[4] != 3) { $news->where('active', $key_list[4]); } if ($key_list[5] != 3) { $news->where('hot', $key_list[5]); } if ($key_list[6] != 3) { $news->where('home_hot', $key_list[6]); } $news->where('recycle', $key_list[7]); //arrange by switch ($key_list[8]) { case "thoigian": $news->order_by('id', $key_list[9]); break; case "docnhieu": $news->order_by('view_count', $key_list[9]); break; } $news->get_paged($offset, $key_list[10], TRUE); // $this->firephp->log($news->check_last_query()); setPagination($this->admin . 'cnews/dosearch/' . $st, $news->paged->total_rows, $key_list[10], 5); $dis['base_url'] = base_url(); $dis['view'] = 'news/search'; $dis['news'] = $news; $dis['search_result'] = 1; $dis['menu_active'] = "Tìm kiếm"; $dis['title_table'] = "Trang hiện tại:" . $news->paged->current_page . '/' . $news->paged->total_pages; $dis['title'] = "Kết quả tìm kiếm"; $dis['searchkey'] = $key_list[0] != $separate ? $key_list[0] : ""; $dis['catalogue_id'] = $key_list[1]; $dis['date_start'] = $key_list[2] != $separate ? $key_list[2] : ""; $dis['date_end'] = $key_list[3] != $separate ? $key_list[3] : ""; $dis['active'] = $key_list[4]; $dis['hot_cat'] = $key_list[5]; $dis['hot_home'] = $key_list[6]; $dis['recycle'] = $key_list[7]; $dis['arrange_by'] = $key_list[8]; $dis['arrange_direct'] = $key_list[9]; $dis['showperpage'] = $key_list[10]; $newscatalogue = new Newscatalogue(); $newscatalogue->where('parentcat_id', 7); $newscatalogue->order_by('position', 'asc'); $newscatalogue->get(); $dis['newscatalogue'] = $newscatalogue; $this->viewadmin($dis); } else { $searchkey = trim($this->input->post('searchkey')); $catalogue_id = $this->input->post('newscatalogue'); $date_start = $this->input->post('date_start'); $date_end = $this->input->post('date_end'); $active = $this->input->post('active'); $hot_cat = $this->input->post('hot_cat'); $hot_home = $this->input->post('hot_home'); $arrange_by = $this->input->post('arrange_by'); $arrange_direct = $this->input->post('arrange_direct'); $showperpage = $this->input->post('showperpage'); $recycle = $this->input->post('recycle') == 1 ? $this->input->post('recycle') : 0; //create string uri query $search_string = ""; $search_string .= $searchkey == "" ? $separate : $searchkey; $search_string .= $sep . ($catalogue_id ? $catalogue_id : $separate); $search_string .= $sep . ($date_start != "" ? $date_start : $separate); $search_string .= $sep . ($date_end != "" ? $date_end : $separate); $search_string .= $sep . $active; $search_string .= $sep . $hot_cat; $search_string .= $sep . $hot_home; $search_string .= $sep . $recycle; $search_string .= $sep . $arrange_by; $search_string .= $sep . $arrange_direct; $search_string .= $sep . $showperpage; $this->firephp->log($search_string); redirect($this->admin . 'cnews/dosearch/' . $search_string . '/0/' . $showperpage); } }
function search() { if ($_SERVER['REQUEST_METHOD'] == "POST") { $searchKey = $this->input->post('searchKey'); redirect("tim-kiem/" . urlencode(htmlentities($searchKey))); } $searchKey = $this->uri->segment(2, ""); $viewType = $this->uri->segment(3, "all"); $page = $this->uri->segment(4, "trang-1"); $limitProduct = 50; $limitNews = 10; $dis['page'] = $page; //$searchKey = urldecode($searchKey); $searchKeyEncode = $searchKey; $searchKey = html_entity_decode(urldecode($searchKey)); if ($searchKey == "") { $resultStatus = false; } if ($viewType == "all") { $resultStatus = true; //find dien thoai & mtb $phoneCat = new productcat($this->config->item('catPhoneId')); $phoneChildCat = $this->getListId($phoneCat->getAllChildCat()); $tabletCat = new productcat($this->config->item('catTabletId')); $tabletChildCat = $this->getListId($tabletCat->getAllChildCat()); $phoneTabletCat = array_merge($phoneChildCat, $tabletChildCat); $phoneTabletProduct = new product(); $phoneTabletProduct->distinct(); $phoneTabletProduct->group_start(); $phoneTabletProduct->like('name', $searchKey); $phoneTabletProduct->or_like('searchKey', $searchKey); $phoneTabletProduct->group_end(); $phoneTabletProduct->where_in_related_productcat('id', $phoneTabletCat); $phoneTabletProduct->where('active', 1); $phoneTabletProduct->order_by('id', 'desc'); $phoneTabletProduct->group_by('id'); $phoneTabletProduct->get_iterated(10); $dis['phoneTabletProduct'] = $phoneTabletProduct; //find accessory with the searchkey condition $accessoryCat = new productcat(); $accessoryCat->where_in('id', $this->config->item('allAccessoriesId')); $accessoryCat->get_iterated(); $accessoryChildCat = array(); foreach ($accessoryCat as $row) { $accessoryChildCat = array_merge($accessoryChildCat, $this->getListId($row->getAllChildCat())); } $accessoryProduct = new product(); $accessoryProduct->distinct(); $accessoryProduct->group_start(); $accessoryProduct->like('name', $searchKey); $accessoryProduct->or_like('searchKey', $searchKey); $accessoryProduct->group_end(); $accessoryProduct->where_in_related_productcat('id', $accessoryChildCat); $accessoryProduct->where('active', 1); $accessoryProduct->group_by('id'); $accessoryProduct->order_by('id', 'desc'); $accessoryProduct->get_iterated(10); $dis['accessoryProduct'] = $accessoryProduct; //find the new by keyword $newCat = array(58, 59, 60, 61, 62, 64); $newsResult = new article(); $newsResult->where_in('newscatalogue_id', $newCat); $newsResult->like('title_vietnamese', $searchKey); $newsResult->where('active', 1); $newsResult->where('recycle', 0); $newsResult->order_by('id', 'desc'); $newsResult->get_iterated(10); $dis['newsResult'] = $newsResult; $dis['view'] = 'product/search_all'; } if ($viewType == "dien-thoai-may-tinh-bang") { $resultStatus = true; //find dien thoai & mtb $phoneCat = new productcat($this->config->item('catPhoneId')); $phoneChildCat = $this->getListId($phoneCat->getAllChildCat()); $tabletCat = new productcat($this->config->item('catTabletId')); $tabletChildCat = $this->getListId($tabletCat->getAllChildCat()); $phoneTabletCat = array_merge($phoneChildCat, $tabletChildCat); $offset = ($this->getPageNumber($page) - 1) * $limitProduct; $phoneTabletProduct = new product(); $phoneTabletProduct->distinct(); $phoneTabletProduct->group_start(); $phoneTabletProduct->like('name', $searchKey); $phoneTabletProduct->or_like('searchKey', $searchKey); $phoneTabletProduct->group_end(); $phoneTabletProduct->where_in_related_productcat('id', $phoneTabletCat); $phoneTabletProduct->where('active', 1); $phoneTabletProduct->order_by('id', 'desc'); $phoneTabletProduct->group_by('id'); $phoneTabletProduct->get_paged_iterated($offset, $limitProduct); $dis['phoneTabletProduct'] = $phoneTabletProduct; $dis['view'] = 'product/search_product'; $url = "tim-kiem/" . $searchKeyEncode . '/dien-thoai-may-tinh-bang'; $dis['url'] = $url; $config['base_url'] = site_url($url . "/trang-"); $config['total_rows'] = $phoneTabletProduct->paged->total_rows; $config['per_page'] = $limitProduct; $config['use_page_numbers'] = TRUE; $config['uri_segment'] = 4; $config['num_links'] = 3; $config['full_tag_open'] = '<span class="pagin">'; $config['full_tag_close'] = "</span>"; $config['first_link'] = FALSE; $config['first_tag_open'] = ''; $config['first_tag_close'] = ''; $config['last_link'] = FALSE; $config['last_tag_open'] = ''; $config['last_tag_close'] = ''; $config['next_link'] = '<img src="' . base_url() . 'images/pagination_next.png" />'; $config['next_tag_open'] = ''; $config['next_tag_close'] = ''; $config['prev_link'] = '<img src="' . base_url() . 'images/pagination_pre.png" /'; $config['prev_tag_open'] = ''; $config['prev_tag_close'] = ''; $config['num_tag_open'] = ''; $config['num_tag_close'] = ''; $config['cur_tag_open'] = '<span class="active fl">'; $config['cur_tag_close'] = '</span>'; $this->pagination->initialize($config); } if ($viewType == "phu-kien") { $resultStatus = true; //find dien thoai & mtb $phoneCat = new productcat($this->config->item('catPhoneId')); $phoneChildCat = $this->getListId($phoneCat->getAllChildCat()); $tabletCat = new productcat($this->config->item('catTabletId')); $tabletChildCat = $this->getListId($tabletCat->getAllChildCat()); $phoneTabletCat = array_merge($phoneChildCat, $tabletChildCat); $offset = ($this->getPageNumber($page) - 1) * $limitProduct; //find accessory with the searchkey condition $accessoryCat = new productcat(); $accessoryCat->where_in('id', $this->config->item('allAccessoriesId')); $accessoryCat->get_iterated(); $accessoryChildCat = array(); foreach ($accessoryCat as $row) { $accessoryChildCat = array_merge($accessoryChildCat, $this->getListId($row->getAllChildCat())); } //$this->firephp->log($accessoryChildCat); $accessoryProduct = new product(); $accessoryProduct->distinct(); $accessoryProduct->group_start(); $accessoryProduct->like('name', $searchKey); $accessoryProduct->or_like('searchKey', $searchKey); $accessoryProduct->group_end(); $accessoryProduct->where_in_related_productcat('id', $accessoryChildCat); $accessoryProduct->where('active', 1); $accessoryProduct->group_by('id'); $accessoryProduct->order_by('id', 'desc'); $accessoryProduct->get_paged_iterated($offset, $limitProduct); $dis['accessoryProduct'] = $accessoryProduct; $dis['view'] = 'product/search_accessory'; $url = "tim-kiem/" . $searchKeyEncode . '/phu-kien'; $dis['url'] = $url; $config['base_url'] = site_url($url . "/trang-"); $config['total_rows'] = $accessoryProduct->paged->total_rows; $config['per_page'] = $limitProduct; $config['use_page_numbers'] = TRUE; $config['uri_segment'] = 4; $config['num_links'] = 3; $config['full_tag_open'] = '<span class="pagin">'; $config['full_tag_close'] = "</span>"; $config['first_link'] = FALSE; $config['first_tag_open'] = ''; $config['first_tag_close'] = ''; $config['last_link'] = FALSE; $config['last_tag_open'] = ''; $config['last_tag_close'] = ''; $config['next_link'] = '<img src="' . base_url() . 'images/pagination_next.png" />'; $config['next_tag_open'] = ''; $config['next_tag_close'] = ''; $config['prev_link'] = '<img src="' . base_url() . 'images/pagination_pre.png" /'; $config['prev_tag_open'] = ''; $config['prev_tag_close'] = ''; $config['num_tag_open'] = ''; $config['num_tag_close'] = ''; $config['cur_tag_open'] = '<span class="active fl">'; $config['cur_tag_close'] = '</span>'; $this->pagination->initialize($config); } if ($viewType == "tin-tuc") { $resultStatus = true; //find dien thoai & mtb $phoneCat = new productcat($this->config->item('catPhoneId')); $phoneChildCat = $this->getListId($phoneCat->getAllChildCat()); $tabletCat = new productcat($this->config->item('catTabletId')); $tabletChildCat = $this->getListId($tabletCat->getAllChildCat()); $phoneTabletCat = array_merge($phoneChildCat, $tabletChildCat); $offset = ($this->getPageNumber($page) - 1) * $limitProduct; //find the new by keyword $newCat = array(58, 59, 60, 61, 62, 64); $newsResult = new article(); $newsResult->where_in('newscatalogue_id', $newCat); $newsResult->like('title_vietnamese', $searchKey); $newsResult->where('active', 1); $newsResult->where('recycle', 0); $newsResult->order_by('id', 'desc'); $newsResult->get_paged_iterated($offset, $limitNews); $dis['newsResult'] = $newsResult; $dis['view'] = 'product/search_news'; $url = "tim-kiem/" . $searchKeyEncode . '/tin-tuc'; $dis['url'] = $url; $config['base_url'] = site_url($url . "/trang-"); $config['total_rows'] = $newsResult->paged->total_rows; $config['per_page'] = $limitNews; $config['use_page_numbers'] = TRUE; $config['uri_segment'] = 4; $config['num_links'] = 3; $config['full_tag_open'] = '<span class="pagin">'; $config['full_tag_close'] = "</span>"; $config['first_link'] = FALSE; $config['first_tag_open'] = ''; $config['first_tag_close'] = ''; $config['last_link'] = FALSE; $config['last_tag_open'] = ''; $config['last_tag_close'] = ''; $config['next_link'] = '<img src="' . base_url() . 'images/pagination_next.png" />'; $config['next_tag_open'] = ''; $config['next_tag_close'] = ''; $config['prev_link'] = '<img src="' . base_url() . 'images/pagination_pre.png" /'; $config['prev_tag_open'] = ''; $config['prev_tag_close'] = ''; $config['num_tag_open'] = ''; $config['num_tag_close'] = ''; $config['cur_tag_open'] = '<span class="active fl">'; $config['cur_tag_close'] = '</span>'; $this->pagination->initialize($config); } $dis['searchKey'] = $searchKey; $dis['base_url'] = base_url(); $this->viewfront($dis); }