Ejemplo n.º 1
0
 function search()
 {
     global $display;
     $catid = (int) Url::get('catid', 0);
     $total = (int) Url::get('total', 0);
     $page = (int) Url::get('page', 0);
     $tt = (int) Url::get('tt', 0);
     $keywords = Url::get('keywords');
     require "./includes/sphinxapi.class.php";
     AZLib::getCats();
     foreach (CGlobal::$allCategories as $value) {
         if ($value['parent_id'] == 0) {
             $cat_list[$value['id']] = $value['brief_name'];
         }
     }
     $category = $this->getCategory($keywords);
     foreach ($category as $row) {
         $row['brief_name'] = isset($cat_list[$row['level_1_catid']]) && $cat_list[$row['level_1_catid']] ? $cat_list[$row['level_1_catid']] : "Khác";
         $listCat[$row['level_1_catid']] = array("level_1_catid" => $row["level_1_catid"], "brief_name" => $row['brief_name'], "count_ad" => $row['@count']);
     }
     $catActive = '';
     $total_cat = 0;
     if ($listCat) {
         $catActive = $listCat[$catid]['brief_name'];
         $total_cat = count($listCat);
     }
     $i = 0;
     $allrecord = 0;
     $otherCat = '';
     $cat_content = "";
     foreach ($listCat as $cat) {
         $allrecord = $allrecord + $cat['count_ad'];
     }
     $display->add("cat_content", $cat_content);
     $display->add("CatActiveId", $catid);
     $display->add("catActive", $catActive);
     $display->add("listCat", $listCat);
     $display->add("allrecord", $allrecord);
     $display->add("total_cat", $total_cat);
     $pager = new Pager();
     $limit = SEARCH_LIMIT;
     $pager->type = "search";
     $pager->catid = $catid;
     $pager->total = $total;
     $pager->limit = $limit;
     $pager->page_param = 'page';
     $pager->page = $page;
     $offset = $pager->get_offset();
     $limit_from = $pager->limit_from();
     $limit_to = $pager->limit_to();
     //Sphinx search by Nova
     $q = $keywords;
     //$mode = SPH_MATCH_ALL;
     $mode = SPH_MATCH_EXTENDED2;
     //Init config
     $host = SPHINX_SERVER;
     $port = SPHINX_PORT;
     $index = 'enbac';
     $filtervals = array();
     //$ranker = SPH_RANK_PROXIMITY_BM25;
     $ranker = SPH_RANK_WORDCOUNT;
     $cl = new SphinxClient();
     $cl->SetServer($host, $port);
     $cl->SetConnectTimeout(1);
     $cl->SetWeights(array(100, 1));
     $cl->SetMatchMode($mode);
     $cl->SetFilter('level_1_catid', array($catid));
     $cl->SetFilter('status', array('1'));
     $cl->SetFieldWeights(array('user_name' => 10000, 'name' => 1000, 'description' => 1));
     //$cl->SetSortMode( SPH_SORT_EXTENDED, 'up_time DESC' );
     //$cl->SetSortMode( SPH_SORT_RELEVANCE);//Sort theo kq chính xác nhất
     //$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + ( user_karma + ln(pageviews) )*0.1");
     $cl->SetSortMode(SPH_SORT_EXPR, "@weight");
     //Sort theo trọng số
     $cl->SetLimits($offset, $limit, 10000);
     $cl->SetRankingMode($ranker);
     $cl->SetArrayResult(true);
     $res = $cl->Query($q, $index);
     if ($res && isset($res["matches"])) {
         if (is_array($res["matches"])) {
             foreach ($res["matches"] as $results) {
                 $list_item_id[] = $results['id'];
             }
         }
         $comma_separated = join(",", $list_item_id);
     }
     if ($total) {
         if ($limit_to > $total) {
             $limit_to = $total;
         }
         $comma_separated = join(",", $list_item_id);
         if ($comma_separated) {
             //$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_catid,category_id,description,img_url, img_server FROM item WHERE id IN ($comma_separated) AND status=1 ORDER BY up_time DESC";
             $sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_catid,category_id,description,img_url, img_server FROM item WHERE id IN ({$comma_separated}) AND status=1 ORDER BY find_in_set(id,'{$comma_separated}')";
             $search_result = DB::query($sql);
             $pager->total = $total;
             $paging = $pager->page_link();
         }
     }
     $item_array = array();
     if ($search_result) {
         AZLib::getCats();
         $highlight = '';
         if ($keywords) {
             $highlight = $str_search = str_replace(array('+', '/', '|', '-', '*'), "", $keywords);
             $highlight = AZLib::trimSpace($highlight);
             $highlight = str_replace("'", '', $highlight);
             $highlight = str_replace("'", '', $highlight);
             $highlight = str_replace(""", '', $highlight);
         }
         $highlight1 = '';
         if ($highlight) {
             $arr = explode(' ', $highlight);
             if ($arr) {
                 $highlight = "";
                 foreach ($arr as $word) {
                     $highlight = ($highlight ? $highlight . ', ' : '') . "'{$word}'";
                     $highlight1 = ($highlight1 ? $highlight1 . ',' : '') . $word;
                 }
             }
         }
         while ($item = mysql_fetch_assoc($search_result)) {
             $item['profile_url'] = WEB_DIR . $item['user_name'];
             //$item['name'] = AZLib::subString(strip_tags(AZLib::filter_title($item['name'])), 0, 115, true);
             $item['name_hl'] = AZLib::HighLightKeyword(strip_tags(AZLib::filter_title($item['name'])), $highlight1);
             $item_time = TIME_NOW - $item['up_time'];
             //neu nho hon 1h thi tinh ra phut
             if ($item_time < 3600) {
                 $item['item_time'] = floor($item_time / 60) . " phút trước đây";
             } elseif ($item_time < 86400) {
                 $item['item_time'] = floor($item_time / 3600) . " giờ trước đây";
             } else {
                 $item['item_time'] = date('\\n\\gà\\y j \\t\\há\\n\\g n', $item['up_time']);
             }
             //$item['description'] = String::display_sort_title(AZLib::delDoubleSpace(AZLib::trimSpace(strip_tags(AZLib::post_db_parse_html($item['description'])))), 35);
             $item['description'] = AZLib::HighLightKeyword(AZLib::delDoubleSpace(AZLib::trimSpace(strip_tags(AZLib::post_db_parse_html(preg_replace('/\\[[0-9]{1,3}\\]/', '', $item['description']))))), $highlight1, 35, "background:yellow;font-size:14px;font-weight:bold;color:blue;");
             $ebname = AZLib::safe_title($item['name']);
             $ebname_tmp = substr(AZLib::safe_title($item['name']), 0, 20);
             if (isset(CGlobal::$allCategories[$item['category_id']])) {
                 $item['item_url'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . $ebname . '&nice_name=' . CGlobal::$allCategories[$item['category_id']]['nice_name']);
                 $item['item_url_tmp'] = WEB_ROOT . CGlobal::$allCategories[$item['category_id']]['nice_name'] . '/p' . $item['id'] . '/' . $ebname_tmp . '...';
             } else {
                 $item['item_url'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . $ebname);
                 $item['item_url_tmp'] = WEB_ROOT . 'p' . $item['id'] . '/' . $ebname_tmp . '...';
             }
             if ($item['img_url']) {
                 $item['img_url'] = AZLib::getImageThumb($item['img_url'], 110, 0, 1, $item['img_server']);
             }
             $item['price'] = number_format($item['price'], 0, ',', '.');
             $item_array[] = $item;
         }
     }
     $display->add('total_item_cat', $total);
     $display->add('name_item_cat', $catActive);
     $display->add('paging', $paging);
     $display->add('keywords', $keywords);
     $display->add('items', $item_array);
     $display->output('sphinx_search_ajax', false, 'sphinx_search');
 }
Ejemplo n.º 2
0
 function draw()
 {
     $this->beginForm();
     global $display;
     $display->add('created_time_from', Url::get('created_time_from'));
     $display->add('created_time_to', Url::get('created_time_to'));
     $display->add('sender_user_name', Url::get('sender_user_name'));
     $display->add('processed', Url::get('processed'));
     //search theo ngay thang nam
     $created_time_from = 0;
     $created_time_to = 0;
     if (Url::get('created_time_from')) {
         $date_arr = explode('-', Url::get('created_time_from'));
         if (isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2])) {
             $created_time_from = mktime(0, 0, 0, (int) $date_arr[1], (int) $date_arr[0], (int) $date_arr[2]);
         }
     }
     if (Url::get('created_time_to')) {
         $date_arr = explode('-', Url::get('created_time_to'));
         if (isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2])) {
             $created_time_to = mktime(23, 59, 59, (int) $date_arr[1], (int) $date_arr[0], (int) $date_arr[2]);
         }
     }
     $search_value = ' 1 ';
     if ($created_time_from) {
         $search_value .= ' AND time_post >= ' . $created_time_from;
     }
     if ($created_time_to) {
         $search_value .= ' AND time_post <= ' . $created_time_to;
     }
     // search ô textbox
     if (Url::get('sender_user_name') != '') {
         $search_value .= ' AND b.user_name like "%' . Url::get('sender_user_name') . '%" ';
     }
     if (Url::get('processed') == 1) {
         $search_value .= ' AND b.status = 0';
     }
     $item_per_page = 50;
     $sql_count = 'SELECT COUNT(*) AS total_item FROM `bad_content` AS b WHERE b.type = 1 AND ' . $search_value;
     $total = DB::fetch($sql_count, 'total_item', 0);
     $items = array();
     if ($total) {
         $limit = '';
         $paging = AZPagging::pagingSE($limit, $total, $item_per_page, 10, 'page_no', true, 'Phản hồi', 'Trang');
         $sql = 'SELECT i.name,i.transaction_type,i.category_id, b.id, b.admin_name, b.status, b.type,b.id_item, b.reason,b.user_id,b.user_name, b.note, b.time_post FROM `bad_content` b LEFT JOIN item i ON i.id = b.id_item WHERE b.type = 1 AND ' . $search_value . ' ORDER BY b.status, b.time_post DESC, b.type ASC ' . $limit;
         $result = DB::query($sql);
         if ($result) {
             while ($row = mysql_fetch_assoc($result)) {
                 $row['content'] = $row['name'];
                 $row['time_post'] = date('d/m/y H:i', $row['time_post']);
                 $row['content_tooltip'] = AZLib::remove_4_js(AZLib::filter_title($row['content']));
                 $row['content'] = AZLib::word_limit($row['content'], 12, '...');
                 $row['reason_tooltip'] = AZLib::remove_4_js(AZLib::filter_title($row['reason']));
                 $row['reason'] = AZLib::word_limit($row['reason'], 12, '...');
                 $row['note_tooltip'] = AZLib::remove_4_js(AZLib::filter_title($row['note']));
                 $row['note'] = AZLib::word_limit($row['note'], 12, '...');
                 $row['href'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $row['id_item'] . '&ebname=' . AZLib::safe_title($row['name']));
                 $row['del_link'] = Url::build_all(array('chk_id', 'del_all', 'cmd', 'id'), 'cmd=delete&id=' . $row['id']);
                 $items[$row['id']] = $row;
             }
         }
     } else {
         $paging = '';
     }
     $display->add('items', $items);
     $display->add('paging', $paging);
     $display->output('list');
     $this->endForm();
 }
Ejemplo n.º 3
0
 function draw2()
 {
     $keywords = AZLib::getParam('keywords');
     $total_item = 0;
     $search_result = false;
     $items = array();
     $paging = '';
     $cmd = '';
     $cat_search_id = 0;
     $item_array = array();
     $listCat = array();
     if ($keywords) {
         //AZLib::getCats();
         require "./includes/sphinxapi.class.php";
         foreach (CGlobal::$allCategories as $value) {
             if ($value['parent_id'] == 0) {
                 $cat_list[$value['id']] = $value['brief_name'];
             }
         }
         $category = $this->getTotalPerCategory($keywords);
         foreach ($category as $row) {
             $row['brief_name'] = isset($cat_list[$row['level_1_catid']]) && $cat_list[$row['level_1_catid']] ? $cat_list[$row['level_1_catid']] : "Khác";
             $listCat[$row['level_1_catid']] = array("level_1_catid" => $row["level_1_catid"], "brief_name" => $row['brief_name'], "count_ad" => $row['@count']);
         }
         $total = 0;
         $catid = 0;
         $catActive = '';
         $total_cat = 0;
         if ($listCat) {
             $first_val = array_slice($listCat, 0, 1);
             $total = $first_val[0]['count_ad'];
             $catid = $first_val[0]['level_1_catid'];
             $catActive = $first_val[0]['brief_name'];
             $total_cat = count($listCat);
         }
         $i = 0;
         $allrecord = 0;
         $otherCat = '';
         $cat_content = "";
         foreach ($listCat as $cat) {
             if ($i < 3) {
                 $active = $i == 0 ? "class=\"active\"" : "";
                 $cat_content .= "<li id=\"tab_{$i}\" {$active} onclick=\"javascript:acive_tab_cat(this);\"><a href=\"javascript:void(0);\" onclick=\"javascript:search_cat({$cat['level_1_catid']},{$cat['count_ad']},1,0);\"><span id=\"kby_{$cat['level_1_catid']}\">" . $cat['brief_name'] . " <font style=\"color: #5a7e92;font-weight: normal;\">(" . $cat['count_ad'] . ")</font></span></a></li>";
             } else {
                 $otherCat .= "<div class=\"other\"><a href=\"javascript:void(0);\" onclick=\"javascript:search_cat({$cat['level_1_catid']},{$cat['count_ad']},1,0);acive_tab_cat(this);\" id=\"tab_{$i}\"><span id=\"kby_{$cat['level_1_catid']}\">" . $cat['brief_name'] . " <font style=\"color: #5a7e92;font-weight: normal;\">(" . $cat['count_ad'] . ")</font></span></a></div>";
             }
             $i++;
             $allrecord = $allrecord + $cat['count_ad'];
         }
         $display->add("cat_content", $cat_content);
         $display->add("CatActiveId", $catid);
         $display->add("catActive", $catActive);
         $display->add("listCat", $listCat);
         $display->add("allrecord", $allrecord);
         $display->add("otherCat", str_replace(array(chr(13), chr(10)), "", $otherCat));
         $display->add("total_cat", $total_cat);
         //Init for sphinx search paging
         $pager = new Pager();
         //config
         $limit = SEARCH_LIMIT;
         $pager->type = "search";
         $pager->catid = $catid;
         $pager->total = $total;
         $pager->limit = $limit;
         $pager->page_param = 'page';
         $pager->page = 1;
         $offset = $pager->get_offset();
         $limit_from = $pager->limit_from();
         $limit_to = $pager->limit_to();
         //Sphinx search by Nova
         $q = $keywords;
         $mode = SPH_MATCH_EXTENDED2;
         //Init config
         $host = SPHINX_SERVER;
         $port = SPHINX_PORT;
         //$index 		= SPHINX_INDEX;
         $index = "enbac delta";
         $filtervals = array();
         $ranker = SPH_RANK_WORDCOUNT;
         $cl = new SphinxClient();
         $cl->SetServer($host, $port);
         $cl->SetConnectTimeout(1);
         $cl->SetWeights(array(100, 1));
         $cl->SetMatchMode($mode);
         //filter
         if ($catid) {
             $cl->SetFilter('level_1_catid', array($catid));
         }
         $cl->SetFilter('status', array('1'));
         $cl->SetFieldWeights(array('user_name' => 10000, 'name' => 1000, 'description' => 1));
         //$cl->SetSortMode( SPH_SORT_EXTENDED, 'up_time DESC' );
         //$cl->SetSortMode( SPH_SORT_RELEVANCE);//Sort theo kq chính xác nhất
         //$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + ( user_karma + ln(pageviews) )*0.1");
         $cl->SetSortMode(SPH_SORT_EXPR, "@weight");
         //Sort theo trọng số
         //SPH_RANK_WORDCOUNT
         //SPH_MATCH_EXTENDED2
         //end filter
         $cl->SetLimits($offset, $limit, 10000);
         $cl->SetRankingMode($ranker);
         $cl->SetArrayResult(true);
         $res = $cl->Query($q, $index);
         /*echo '<pre>';
         		print_r($res["matches"]);*/
         if ($res && isset($res["matches"])) {
             if (is_array($res["matches"])) {
                 foreach ($res["matches"] as $results) {
                     $list_item_id[] = $results['id'];
                 }
             }
             $comma_separated = join(",", $list_item_id);
         }
         if ($total) {
             if ($limit_to > $total) {
                 $limit_to = $total;
             }
             $comma_separated = join(",", $list_item_id);
             if ($comma_separated) {
                 //$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_catid,category_id,description,img_url, img_server FROM item WHERE id IN($comma_separated) AND status=1 ORDER BY up_time DESC";
                 //$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_catid,category_id,description,img_url, img_server FROM item WHERE id IN($comma_separated) AND status=1  AND state=0 ORDER BY find_in_set(id,'$comma_separated')";
                 $sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_catid,category_id,description,img_url, img_server FROM item WHERE id IN({$comma_separated}) AND status=1 ORDER BY find_in_set(id,'{$comma_separated}')";
                 $search_result = DB::query($sql);
                 $pager->total = $total;
                 $paging = $pager->page_link();
             }
         }
     }
     $highlight = '';
     if ($keywords) {
         $highlight = $str_search = str_replace(array('+', '/', '|', '-', '*'), "", $keywords);
         $highlight = AZLib::trimSpace($highlight);
         $highlight = str_replace("'", '', $highlight);
         $highlight = str_replace("&#39;", '', $highlight);
         $highlight = str_replace("&quot;", '', $highlight);
     }
     $highlight1 = '';
     if ($highlight) {
         $arr = explode(' ', $highlight);
         if ($arr) {
             $highlight = "";
             foreach ($arr as $word) {
                 $highlight = ($highlight ? $highlight . ', ' : '') . "'{$word}'";
                 $highlight1 = ($highlight1 ? $highlight1 . ',' : '') . $word;
             }
         }
     }
     if ($keywords && $search_result) {
         while ($item = mysql_fetch_assoc($search_result)) {
             $item['profile_url'] = WEB_DIR . $item['user_name'];
             $item['name_hl'] = AZLib::HighLightKeyword(strip_tags(AZLib::filter_title($item['name'])), $highlight1);
             $item_time = TIME_NOW - $item['up_time'];
             //neu nho hon 1h thi tinh ra phut
             if ($item_time < 3600) {
                 $item['item_time'] = floor($item_time / 60) . " phút trước đây";
             } elseif ($item_time < 86400) {
                 $item['item_time'] = floor($item_time / 3600) . " giờ trước đây";
             } else {
                 $item['item_time'] = date('\\n\\gà\\y j \\t\\há\\n\\g n', $item['up_time']);
             }
             $item['description'] = AZLib::HighLightKeyword(AZLib::delDoubleSpace(AZLib::trimSpace(strip_tags(AZLib::post_db_parse_html(preg_replace('/\\[[0-9]{1,3}\\]/', '', $item['description']))))), $highlight1, 35, "background:yellow;font-size:14px;font-weight:bold;color:blue;");
             $ebname = AZLib::safe_title($item['name']);
             $ebname_tmp = substr(AZLib::safe_title($item['name']), 0, 20);
             if (isset(CGlobal::$allCategories[$item['category_id']])) {
                 $item['item_url'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . $ebname . '&nice_name=' . CGlobal::$allCategories[$item['category_id']]['nice_name']);
                 $item['item_url_tmp'] = WEB_ROOT . CGlobal::$allCategories[$item['category_id']]['nice_name'] . '/p' . $item['id'] . '/' . $ebname_tmp . '...';
             } else {
                 $item['item_url'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . $ebname);
                 $item['item_url_tmp'] = WEB_ROOT . 'p' . $item['id'] . '/' . $ebname_tmp . '...';
             }
             if ($item['img_url']) {
                 $item['img_url'] = AZLib::getImageThumb($item['img_url'], 110, 0, 1, $item['img_server']);
             }
             $item['price'] = number_format($item['price'], 0, ',', '.');
             $item_array[] = $item;
         }
     }
     global $start_rb;
     $mtime = microtime();
     $mtime = explode(" ", $mtime);
     $mtime = $mtime[1] + $mtime[0];
     $end_rb = $mtime;
     $search_time = round($end_rb - $start_rb, 3);
     $display->add('limit_from', $limit_from);
     $display->add('limit_to', $limit_to);
     $display->add('search_time', $search_time);
     $display->add('keywords', $keywords);
     $display->add('base_url', WEB_ROOT);
     $display->add('highlight', $highlight);
     $display->add('total_item_cat', $total);
     $display->add('name_item_cat', $catActive);
     $display->add('block_id', Module::$block_id);
     $display->add('paging', $paging);
     $display->add('items', $item_array);
     $display->output('sphinx_search');
 }
Ejemplo n.º 4
0
 function draw()
 {
     global $display;
     AZLib::getCats();
     $this->beginForm(false, 'post', false, Url::build_current());
     $created_time_from = 0;
     $created_time_to = 0;
     $time_from = "";
     $time_to = "";
     $phrase_checked = "";
     $free_cat_checked = "";
     $up_checked = "";
     $pagging = "";
     $limit = "";
     $lock_checked = '';
     $select_subcat_checked = '';
     $items = array();
     $id_search = (int) Url::get("id_search");
     $censor = Url::get("censor", 1);
     $user_name = AZLib::getParam("user_name");
     $zone_id = Url::get("zone_id");
     $searchByCat = Url::get("searchByCat");
     $searchByCatType = Url::get("searchByCatType", 0);
     $searchBySubCat = Url::get("searchBySubCat");
     $searchBySubCatType = Url::get("searchBySubCatType", 0);
     $sort_type = Url::get("sort_type", 1);
     $keywords = Url::get("keywords");
     $have_img = Url::get("have_img", 0);
     $lock_item = Url::get("lock");
     $phrase_selected = Url::get("phrase");
     $free_cat_selected = Url::get("free_cat");
     $up = Url::get("up");
     $select_subcat = Url::get("select_subcat", "");
     $opt_have_img = AZLib::getOption(array(0 => "-Tìm theo ảnh-", 1 => "-Có ảnh-", 2 => "-Không ảnh-"), $have_img);
     if (isset($_REQUEST["created_time"]) && $_REQUEST["created_time"]) {
         $time_from = Url::get("created_time");
     }
     if (isset($_REQUEST["created_time_to"]) && $_REQUEST["created_time_to"]) {
         $time_to = Url::get("created_time_to");
     }
     if ($time_from) {
         $date_arr = explode("-", $time_from);
         if (isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2])) {
             $created_time_from = mktime(0, 0, 0, (int) $date_arr[1], (int) $date_arr[0], (int) $date_arr[2]);
         }
     }
     if ($time_to) {
         $date_arr = explode("-", $time_to);
         if (isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2])) {
             $created_time_to = mktime(23, 59, 59, (int) $date_arr[1], (int) $date_arr[0], (int) $date_arr[2]);
         }
     }
     $search_value = "";
     $where = "";
     //$order_by   	= "ORDER BY del_time DESC";
     $order_by = "";
     $total_item = 0;
     if ($keywords) {
         $search_value = ($search_value == "" ? " WHERE " : " AND ") . "id IN (0)";
     }
     if ($sort_type == 1) {
         $order_by = "ORDER BY id DESC";
     } elseif ($sort_type == 2) {
         $order_by = "ORDER BY modify_time DESC";
     } elseif ($sort_type == 3) {
         $order_by = "ORDER BY item_order ASC";
     }
     if ($free_cat_selected) {
         $free_cat_checked = "checked";
         $catids = implode(",", array_keys(CGlobal::$allCategories));
         $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "category_id NOT IN({$catids})";
         $order_by = $order_by != "" ? $order_by : "ORDER BY id DESC";
     } else {
         if ($searchBySubCat) {
             if ($searchBySubCatType) {
                 // Nếu chỉ tìm trong danh mục con của danh mục cấp 2
                 $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "level_2_catid = " . $searchBySubCat;
                 // Lọc những item có trường level_2_catid là danh mục cấp 2
             } else {
                 $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "category_id = " . $searchBySubCat;
                 // Ngược lại, lấy các bản ghi thuộc chính danh mục cấp 2
             }
         } elseif ($searchByCat) {
             // Nếu chỉ tìm trong danh mục con của danh mục cấp 1
             if ($searchByCatType) {
                 // Lọc những item có trường level_1_catid là danh mục cấp 1
                 $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "level_1_catid = " . $searchByCat;
             } else {
                 // Ngược lại, lấy các bản ghi thuộc chính danh mục cấp 1
                 $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "category_id = " . $searchByCat;
             }
         }
     }
     if ($censor != 9) {
         $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "status=" . $censor;
     }
     if ($user_name != "") {
         $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "user_name ='{$user_name}'";
     }
     if ($select_subcat) {
         $select_subcat_checked = "checked";
     }
     if ($up) {
         if ($created_time_from) {
             $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "created_time >= " . $created_time_from;
         }
         if ($created_time_to) {
             $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "created_time <= " . $created_time_to;
         }
         $up_checked = "checked";
     } else {
         if ($created_time_from) {
             $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "modify_time >= " . $created_time_from;
         }
         if ($created_time_to) {
             $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "modify_time <= " . $created_time_to;
         }
     }
     if ($have_img == 1) {
         //có ảnh
         $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "have_image=1";
     } elseif ($have_img == 2) {
         //ko có ảnh
         $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "have_image=0";
     }
     if ($id_search) {
         //ID sản phẩm
         $search_value .= ($search_value == "" ? " WHERE " : " AND ") . "id={$id_search}";
     }
     if (Url::get("up")) {
         $order_by = $order_by != "" ? $order_by : "ORDER BY created_time DESC";
     } else {
         $order_by = $order_by != "" ? $order_by : "ORDER BY modify_time DESC";
     }
     $sql = "SELECT * FROM item {$search_value} {$order_by}";
     $sql_count = "SELECT count(*) AS total_row FROM item {$search_value}";
     $total_item = (int) DB::fetch($sql_count, "total_row");
     if ($total_item) {
         $pagging = AZPagging::pagingSE($limit, $total_item, 50, 10, 'page_no', true, 'Sản phẩm', 'Trang');
         $sql .= $limit;
     }
     $re = DB::query($sql);
     if ($re) {
         $index_temp = 0;
         while ($item = mysql_fetch_assoc($re)) {
             //trạng thái sản phẩm:
             if ($item['status'] == -1) {
                 $item['bgcolor'] = "bgcolor=\"#FF6633\"";
             } elseif ($index_temp) {
                 $item['bgcolor'] = "bgcolor=\"#EFEFEF\"";
             } else {
                 $item['bgcolor'] = "";
             }
             $index_temp = 1 - $index_temp;
             $item['created_time'] = 'Đăng: <b>' . date("d/m/Y H:i", $item['created_time']) . '</b>';
             if ($item['del_time'] && $item['del_user'] && $item['status'] == -1) {
                 $item['del_time'] = '<br /><font color=red>Xoá: <b>' . date("d/m/Y H:i", $item['del_time']) . '</font></b> ( <a target="_blank" href="' . WEB_DIR . $item['del_user'] . '"><strong>' . $item['del_user'] . '</strong></a>)';
             } else {
                 $item['del_time'] = '';
             }
             if ($item['modify_user_name'] && $item['status'] != -1) {
                 $item['is_modify'] = '<br><font color=gray>Sửa: <b>' . date("d/m/Y H:i", $item['modify_time']) . '</font></b>';
                 $item['is_modify'] .= ' ( <a target="_blank" href="' . WEB_DIR . $item['modify_user_name'] . '"><strong>' . $item['modify_user_name'] . '</strong></a>)';
             } else {
                 $item['is_modify'] = '';
             }
             $item['name'] = AZLib::filter_title($item['name']);
             $item['description'] = AZLib::remove_4_js(AZLib::plainText($item['description']));
             $item['price'] = number_format($item['price'], 0, ',', '.');
             $item['price_out'] = number_format($item['price_out'], 0, ',', '.');
             $item['currency_option'] = AZLib::getOption(array(1 => "VNĐ", 2 => "\$"), $item['currency_id']);
             //$item['price']	=  "Giá bán: ".AZLib::priceFomart($item['price'],$item['currency_id']);
             //$item['price_out']	=  "<br /><font color='#999999'>Giá TT: ".AZLib::priceFomart($item['price_out'],$item['currency_id']).'</font>';
             if ($item['level_1_catid'] > 0) {
                 if (isset(CGlobal::$allCategories[$item['level_1_catid']])) {
                     $item['cat_name'] = '<b>' . CGlobal::$allCategories[$item['level_1_catid']]['name'] . ' (' . $item['level_1_catid'] . ')</b>';
                 } else {
                     $item['cat_name'] = '<b><font color=red>(' . $item['level_1_catid'] . ')</font></b>';
                 }
                 if ($item['category_id'] > 0 && $item['category_id'] != $item['level_1_catid'] || $item['cat_name'] == '') {
                     if (isset(CGlobal::$allCategories[$item['category_id']])) {
                         $item['cat_name'] .= ' - <i>' . CGlobal::$allCategories[$item['category_id']]['name'] . ' (' . $item['category_id'] . ')</i>';
                     } else {
                         $item['cat_name'] .= ' - <i><b><font color=red>(' . $item['category_id'] . ')</font></b></i>';
                     }
                 }
             }
             if ($item['img_url']) {
                 $item['image_src'] = 'http://' . CGlobal::$img_server[$item['img_server']] . $item['img_url'];
                 $item['image'] = AZLib::getImageThumb($item['img_url'], 110, 0, 1, $item["img_server"]);
             } else {
                 $item['image_src'] = '';
                 $item['image'] = '';
             }
             $item['href'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . AZLib::safe_title($item['name']));
             $item['edit'] = Url::build('post_item', array('cmd' => 'edit', 'id' => $item['id']));
             if ($item['status'] == -1) {
                 $item['del_link'] = Url::build_all(array('cmd', 'id'), 'cmd=del_forever&id=' . $item['id']);
                 $item['re_post'] = Url::build_all(array('cmd', 'id'), 'cmd=re_post&id=' . $item['id']);
             } elseif ($item['status'] == 2) {
                 $item['del_link'] = Url::build_all(array('cmd', 'id'), 'cmd=delete&id=' . $item['id']);
                 $item['show_link'] = Url::build_all(array('cmd', 'id'), 'cmd=show&id=' . $item['id']);
             } else {
                 $item['del_link'] = Url::build_all(array('cmd', 'id'), 'cmd=delete&id=' . $item['id']);
                 $item['hide_link'] = Url::build_all(array('cmd', 'id'), 'cmd=hide&id=' . $item['id']);
             }
             $item['del_cache'] = Url::build_all(array('cmd', 'id'), 'cmd=del_cache&id=' . $item['id']);
             $items[$item['id']] = $item;
         }
     }
     $display->add('items', $items);
     $type_arr = array(1 => "-Sản phẩm không ẩn-", 2 => "-Sản phẩm ẩn-");
     if (User::have_permit(ADMIN_DEL_ITEM)) {
         $type_arr[-1] = "-Sản phẩm đã xoá-";
         $type_arr[9] = "-Tất cả các sản phẩm (Cả sản phẩm xóa)-";
     }
     $option_censor = AZLib::getOption($type_arr, Url::get('censor', 1));
     $display->add('censor', $censor);
     $display->add('option_censor', $option_censor);
     $display->add('have_img_option', $opt_have_img);
     $display->add('lock_checked', $lock_checked);
     $display->add('user_name', $user_name);
     $display->add('created_time', $time_from);
     $display->add('created_time_to', $time_to);
     $display->add('phrase_checked', $phrase_checked);
     $display->add('free_cat_checked', $free_cat_checked);
     $display->add('up_checked', $up_checked);
     $display->add('select_subcat_checked', $select_subcat_checked);
     $display->add('id_search', $id_search);
     $item_cat_search = $this->GetCatTree();
     $display->add('list_top_cat_js', AZLib::getOption(AZLib::getTopCats(), 999999999));
     $display->add('IS_ADMIN', User::is_admin());
     $display->add('page_no', Url::get('page_no'));
     $display->add('paging', $pagging);
     $display->add('total_item', $total_item);
     $display->add('item_cat', AZLib::getOption($this->getOtionCats(), Url::get('id_cats')));
     $display->add('category_tree', json_encode($item_cat_search));
     $display->add('catSelected', Url::get('searchByCat', 0));
     $display->add('catSelectedType', Url::get('searchByCatType', 0));
     $display->add('subCatSelected', Url::get('searchBySubCat', 0));
     $display->add('subCatSelectedType', Url::get('searchBySubCatType', 0));
     $display->add('keywords', $keywords);
     $display->add('sort_type', $sort_type);
     $display->output('ManageItem');
     $this->endForm();
 }
Ejemplo n.º 5
0
 function draw()
 {
     global $display;
     $this->beginForm(false, "POST", false, Url::build_current());
     //search theo ngay thang nam
     $display->add('created_time_from', Url::get('created_time_from'));
     $display->add('created_time_to', Url::get('created_time_to'));
     $created_time_from = 0;
     $created_time_to = 0;
     if (Url::get('created_time_from')) {
         $date_arr = explode('-', Url::get('created_time_from'));
         if (isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2])) {
             $created_time_from = mktime(0, 0, 0, (int) $date_arr[1], (int) $date_arr[0], (int) $date_arr[2]);
         }
     }
     if (Url::get('created_time_to')) {
         $date_arr = explode('-', Url::get('created_time_to'));
         if (isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2])) {
             $created_time_to = mktime(23, 59, 59, (int) $date_arr[1], (int) $date_arr[0], (int) $date_arr[2]);
         }
     }
     $search_value = 1;
     $last_log = (int) Url::get('last_log');
     if ($last_log) {
         if ($created_time_from) {
             $search_value .= ' AND last_login >= ' . $created_time_from;
         }
         if ($created_time_to) {
             $search_value .= ' AND last_login <= ' . $created_time_to;
         }
     } else {
         if ($created_time_from) {
             $search_value .= ' AND create_time >= ' . $created_time_from;
         }
         if ($created_time_to) {
             $search_value .= ' AND create_time <= ' . $created_time_to;
         }
     }
     $display->add('last_log', $last_log);
     if (Url::get('active') == 1) {
         $search_value .= ' AND (is_active=1)';
         $display->add('active_checked', 'checked');
     } else {
         $display->add('active_checked', '');
     }
     if (Url::get('tracking') == 1) {
         $search_value .= ' AND (tracking=1)';
         $display->add('tracking_checked', 'checked');
     } else {
         $display->add('tracking_checked', '');
     }
     if (Url::get('block') == 1) {
         $search_value .= ' AND (block_time >= ' . TIME_NOW . ' OR block_time = -1)';
         $order_by = ' ORDER BY block_time DESC ';
         $display->add('block_checked', 'checked');
     } else {
         $order_by = ' ORDER BY id DESC ';
         //$search_value .= ' AND block_time!=-1 AND block_time <= '.TIME_NOW;
         $display->add('block_checked', '');
     }
     $od_by = Url::get('order_by');
     $od_dir = Url::get('order_dir', 'DESC');
     if ($od_by == 'name') {
         $order_by = ' ORDER BY user_name ' . $od_dir;
     } elseif ($od_by == 'id') {
         $order_by = ' ORDER BY id ' . $od_dir;
     } elseif ($od_by == 'time') {
         $order_by = ' ORDER BY create_time ' . $od_dir;
     } elseif ($last_log) {
         $order_by = ' ORDER BY last_login ' . $od_dir;
     }
     if (Url::get('ava')) {
         $search_value .= ' AND avatar_url != ""';
         $display->add('ava_checked', 'checked');
     } else {
         $display->add('ava_checked', '');
     }
     // search ô textbox	 ID
     $id_search = (int) Url::get('id_search', 0);
     if ($id_search) {
         $search_value .= ' AND id=' . $id_search;
     }
     if ($id_search == 0) {
         $id_search = '';
     }
     $display->add('id_search', $id_search);
     // search ô textbox	tài khoản
     if (Url::get('text_value') != '') {
         $text_value = Url::get('text_value');
         $display->add('text_value', $text_value);
         $str_search = str_replace("'", '"', $text_value);
         $str_search = str_replace("&#39;", '"', $str_search);
         $str_search = str_replace("&quot;", '"', $str_search);
         $search_value .= " AND (user_name LIKE '%" . $str_search . "%'  OR email LIKE '%" . $str_search . "%')";
     }
     // search so dien thoai
     if (Url::get('id_phone') != '') {
         $id_phone = Url::get('id_phone');
         $search_value .= " AND (home_phone LIKE '%" . $id_phone . "%'  OR mobile_phone LIKE '%" . $id_phone . "%')";
     }
     $display->add('id_phone', Url::get('id_phone'));
     $item_per_page = Url::get('item_per_page', 50);
     $sql_count = 'SELECT COUNT(id) AS total_item FROM user WHERE ' . $search_value;
     $total = DB::fetch($sql_count, 'total_item', 0);
     $items = array();
     $str_id = '';
     $uids = '';
     if ($total) {
         $limit = '';
         $paging = AZPagging::pagingSE($limit, $total, $item_per_page, 10, 'page_no', true, 'Thành viên', 'Trang');
         $sql = 'SELECT * FROM user WHERE ' . $search_value . ' ' . $order_by . $limit;
         $result = DB::query($sql);
         if ($result) {
             AZLib::getProvinces();
             while ($row = mysql_fetch_assoc($result)) {
                 if ($row['block_time'] > TIME_NOW || $row['block_time'] == -1 || $row['invalid_time'] > 0 || $row['invalid_time'] == -1) {
                     $str_id .= ($str_id == '' ? '' : ',') . $row['id'];
                 }
                 $row['create_time'] = date('d/m/y H:i', $row['create_time']);
                 if ($row['last_login']) {
                     $row['last_login'] = date('d/m/y H:i', $row['last_login']);
                 } else {
                     $row['last_login'] = false;
                 }
                 if ($row['block_time'] > TIME_NOW || $row['block_time'] == -1) {
                     if ($row['block_time'] != -1) {
                         $row['status'] = "<font color=red><b>" . date('H:i d/m/y', $row['block_time']) . '</b></font>';
                     } else {
                         $row['status'] = '<font color=red><b>Khóa vĩnh viễn</b></font>';
                     }
                     $row['bgcolor'] = 'bgcolor="#CCCCCC"';
                     $row['is_block'] = true;
                     $display->add('type_reason', 'Khóa');
                 } else {
                     $row['status'] = "";
                     $row['bgcolor'] = '';
                     $row['is_block'] = false;
                 }
                 if ($row['invalid_time'] > 0 || $row['invalid_time'] == -1) {
                     $row['status'] = $row['invalid_time'] == -1 ? "<font color=red><b>kiểm duyệt vĩnh viễn</b></font>" : "<font color=red><b>" . date('H:i d/m/y', $row['invalid_time']) . '</b></font>';
                     $row['is_invalid'] = true;
                     $display->add('type_reason', 'Kiểm duyệt');
                 } else {
                     //$row['status'] = "";
                     //$row['bgcolor'] = '';
                     $row['is_invalid'] = false;
                 }
                 if ($row['province_id'] && isset(CGlobal::$provinces[$row['province_id']])) {
                     $row['city'] = CGlobal::$provinces[$row['province_id']]['name'];
                 } else {
                     $row['city'] = '';
                 }
                 $row['gender'] = '';
                 if ($row['website'] && strpos($row['website'], 'http://') === false) {
                     $row['website'] = 'http://' . $row['website'];
                 }
                 if ($row['avatar_url']) {
                     $row['avatar_preview'] = AZLib::getImageThumb($row['avatar_url'], 60, 0, 1, $row['img_server']);
                     $row['avatar_src'] = 'http://' . CGlobal::$img_server[$row['img_server']] . $row['avatar_url'];
                     $row['del_avatar'] = Url::build_all(array('chk_id', 'del_all', 'cmd', 'id', 'lock_die_all', 'hd_ac'), 'cmd=del_avatar&id=' . $row['id']);
                 } else {
                     $row['avatar_preview'] = '';
                     $row['avatar_src'] = '';
                     $row['del_avatar'] = '';
                 }
                 $row['unban_nick'] = Url::build_all(array('chk_id', 'del_all', 'cmd', 'id', 'lock_die_all', 'hd_ac'), 'cmd=unban_nick&id=' . $row['id']);
                 if (User::is_root()) {
                     $row['del_link'] = Url::build_all(array('chk_id', 'del_all', 'cmd', 'id', 'lock_die_all', 'hd_ac'), 'cmd=del_user&id=' . $row['id']);
                 }
                 $row['detail'] = Url::build_current(array('cmd' => 'detail', 'id' => $row['id']));
                 $row['edit'] = Url::build_current(array('cmd' => 'edit', 'id' => $row['id']));
                 $row['openids'] = array();
                 $row['del_cache'] = Url::build_all(array('cmd', 'id'), 'cmd=del_cache&id=' . $row['id']);
                 $uids .= ($uids ? ',' : '') . $row['id'];
                 $items[$row['id']] = $row;
             }
         }
     } else {
         $paging = '';
     }
     if ($uids) {
         $re = DB::query("SELECT openid_url,user_id FROM openid WHERE user_id IN({$uids})");
         if ($re) {
             while ($oid = mysql_fetch_assoc($re)) {
                 $items[$oid['user_id']]['openids'][] = $oid['openid_url'];
             }
         }
     }
     //lay ly do khoa nicks hoac kiem duyet nick
     $arr_reason = array();
     if ($str_id) {
         $where = '';
         if (Url::get('block') == 1) {
             $where = ' AND type IN (0,1) ';
         } else {
             if (Url::get('invalid') == 1) {
                 $where = ' AND type = 2 ';
             }
         }
         $sql = 'SELECT user_id, time, note, type,admin_id, admin_name FROM user_lock WHERE user_id IN(' . $str_id . ') ' . $where . ' ORDER BY id ASC';
         $result = DB::query($sql);
         while ($row = mysql_fetch_assoc($result)) {
             $arr_reason[$row['user_id']] = $row;
         }
     }
     foreach ($items as $value) {
         if (isset($arr_reason[$value['id']]['user_id']) && $value['id'] == $arr_reason[$value['id']]['user_id']) {
             $items[$value['id']]['lock_reason'] = AZLib::filter_title($arr_reason[$value['id']]['note']);
             $items[$value['id']]['lock_type'] = $arr_reason[$value['id']]['type'];
             $items[$value['id']]['time_lock'] = date("d/m/y H:i", $arr_reason[$value['id']]['time']);
             $items[$value['id']]['create_time_lock'] = $arr_reason[$value['id']]['time'];
             $items[$value['id']]['admin_name'] = $arr_reason[$value['id']]['admin_name'];
         } else {
             $items[$value['id']]['lock_reason'] = '';
             $items[$value['id']]['lock_type'] = '';
             $items[$value['id']]['time_lock'] = '';
             $items[$value['id']]['create_time_lock'] = 0;
             $items[$value['id']]['admin_name'] = '';
         }
     }
     //end lay ly do khoa nick
     if ($od_dir == 'ASC') {
         $od_dir = 'DESC';
     } else {
         $od_dir = 'ASC';
     }
     $href_id = Url::build_all(array('chk_id', 'del_all', 'cmd', 'id', 'lock_die_all', 'hd_ac'), 'order_by=id&order_dir=' . $od_dir);
     $href_name = Url::build_all(array('chk_id', 'del_all', 'cmd', 'id', 'lock_die_all', 'hd_ac'), 'order_by=name&order_dir=' . $od_dir);
     $href_up = Url::build_all(array('chk_id', 'del_all', 'cmd', 'id', 'lock_die_all', 'hd_ac'), 'order_by=up&order_dir=' . $od_dir);
     $href_time = Url::build_all(array('chk_id', 'del_all', 'cmd', 'id', 'lock_die_all', 'hd_ac'), 'order_by=time&order_dir=' . $od_dir);
     $img_id = '<img src="style/images/admin/downarrow.png" alt="">';
     //default
     $img_name = '';
     $img_up = '';
     $img_time = '';
     if ($od_by == 'id') {
         $img_id = '<img src="style/images/admin/' . ($od_dir != 'DESC' ? 'down' : 'up') . 'arrow.png" alt="">';
     }
     if ($od_by == 'name') {
         $img_name = '<img src="style/images/admin/' . ($od_dir != 'DESC' ? 'down' : 'up') . 'arrow.png" alt="">';
         $img_id = '';
     }
     if ($od_by == 'up') {
         $img_up = '<img src="style/images/admin/' . ($od_dir != 'DESC' ? 'down' : 'up') . 'arrow.png" alt="">';
         $img_id = '';
     }
     if ($od_by == 'time') {
         $img_time = '<img src="style/images/admin/' . ($od_dir != 'DESC' ? 'down' : 'up') . 'arrow.png" alt="">';
         $img_id = '';
     }
     // neu show cac thanh vien bi khoa, se sap xep theo thoi diem khoa hien tai giam dan
     if (Url::get('block') == 1) {
         usort($items, array("ListUserAdminForm", "cmp"));
     }
     $display->add('img_id', $img_id);
     $display->add('img_name', $img_name);
     $display->add('img_up', $img_up);
     $display->add('img_time', $img_time);
     $display->add('href_id', $href_id);
     $display->add('href_name', $href_name);
     $display->add('href_up', $href_up);
     $display->add('href_time', $href_time);
     $display->add('total_user', $total);
     $display->add('limit_date', BAN_NICK_DATE);
     $display->add('items', $items);
     $display->add('paging', $paging);
     $display->add('is_root', User::is_root());
     $display->output('list');
     $this->endForm();
 }
Ejemplo n.º 6
0
 function processItem($item, $admin_item)
 {
     if (isset(CGlobal::$allCategories[$item['category_id']])) {
         $item['href'] = WEB_DIR . CGlobal::$allCategories[$item['category_id']]['nice_name'] . "/p{$item['id']}/" . AZLib::safe_title($item['name']) . ".html";
     } else {
         $item['href'] = WEB_DIR . "p{$item['id']}/" . AZLib::safe_title($item['name']) . ".html";
     }
     $item['modify_time'] = date('H:i | d.m.y', $item['modify_time']);
     $item['price'] = AZLib::convertCurrency($item['price'], $item['currency_id']);
     $item['price_out'] = AZLib::convertCurrency($item['price_out'], $item['currency_id']);
     $item['currency_id'] = 1;
     $item['price_num'] = (int) $item['price'];
     if ($item['price']) {
         $item['price'] = number_format($item['price'], 0, ',', '.');
     } else {
         $item['price'] = '';
     }
     $item['price_title'] = 'Giá bán';
     if ($item['price_out'] > 0) {
         $item['price_out'] = number_format($item['price_out'], 0, ',', '.') . ($item['currency_id'] == ' ' ? ' ' . CGlobal::$currency[$item['currency_id']] : '');
     } else {
         $item['price_out'] = '0';
     }
     //$item['price'] 			= AZLib::convertCurrency($item['price'],			$item['currency_id']);
     //$item['price_out'] 		= AZLib::convertCurrency($item['price_out'],		$item['currency_id']);
     if ($admin_item) {
         $item['description'] = AZLib::remove_4_js(AZLib::plainText(AZLib::parseBBCode(html_entity_decode($item['description'], ENT_QUOTES, "UTF-8"))));
         $item['description'] = preg_replace("/\\[([\\s]*[0-9]{1,2}[\\s]*)\\]/eis", " ", $item['description']);
         $item['description'] = str_replace(array("'", "\""), array("", " "), $item['description']);
         $item['description'] = AZLib::word_limit($item['description'], 200, '');
     }
     $item['name'] = AZLib::filter_title($item['name']);
     if ($item['img_url']) {
         $item['img_thumb_wl'] = AZLib::getImageThumb($item['img_url'], 180, 0, 1, $item['img_server']);
     } else {
         $item['img_url'] = '';
     }
     if (!CGlobal::$curLevel2Cat) {
         if (isset(CGlobal::$allCategories[$item['category_id']])) {
             $item['cat_name'] = CGlobal::$allCategories[$item['category_id']]['name'];
         } else {
             $item['cat_name'] = "ID: {$item['category_id']}";
         }
     }
     return $item;
 }
Ejemplo n.º 7
0
    function load_shop_label()
    {
        if (!CGlobal::$user_profile) {
            User::check_get_user();
        }
        if (CGlobal::$user_profile) {
            $mode_default = 'comment';
            if (!CGlobal::$shop_setting) {
                if (CGlobal::$user_profile['shop_setting']) {
                    CGlobal::$shop_setting = unserialize(stripslashes(CGlobal::$user_profile['shop_setting']));
                }
                if (!CGlobal::$shop_setting) {
                    CGlobal::$shop_setting = array('shop_name' => CGlobal::$user_profile['full_name'] ? CGlobal::$user_profile['full_name'] : CGlobal::$user_profile['user_name'], 'default_mode' => 1, 'default_layout' => 1, 'item_list_mode' => 0, 'adv_banner' => '');
                }
            }
            if (CGlobal::$shop_setting && !isset(CGlobal::$shop_setting['default_layout'])) {
                CGlobal::$shop_setting['default_layout'] = 1;
            }
            if (Url::get("mode") == "comment" || CGlobal::$shop_setting['default_mode'] == 2) {
                CGlobal::$website_title = 'Lưu bút - Shop ' . CGlobal::$user_profile['user_name'];
            }
            if (!CGlobal::$shop_setting['default_mode']) {
                if (Url::get('mode') == 'shop' || DB::select('item', 'user_id=' . CGlobal::$user_profile['id'] . ' AND status=1')) {
                    //Nếu có sp, mặc định là vào shop
                    CGlobal::$shop_setting['default_mode'] = 1;
                    $mode_default = 'shop';
                } else {
                    //Nếu ko có sản phẩm, mặc định vào lưu bút
                    CGlobal::$shop_setting['default_mode'] = 2;
                    $mode_default = 'comment';
                }
            } else {
                if (CGlobal::$shop_setting['default_mode'] == 1) {
                    $mode_default = 'shop';
                } else {
                    $mode_default = 'comment';
                }
            }
        }
        if (CGlobal::$shop_label) {
            CGlobal::$website_title .= ' | ' . CGlobal::$shop_label['name'];
            $this->label_id = CGlobal::$shop_label['id'];
        } else {
            $this->label_id = (int) Url::get('label_id', 0);
            if ($this->label_id) {
                CGlobal::$shop_label = DB::select("label", "id=" . $this->label_id);
            }
            if (!CGlobal::$shop_label) {
                $this->label_id = 0;
            }
        }
        $page_shop_item = (int) Url::get('page_shop_item', 1);
        $label_id = (int) Url::get("label_id", 0);
        $list_type = (int) Url::get("list_type", 0);
        global $display;
        $display->add('top_level_id', $label_id);
        $display->add('list_type', $list_type);
        $display->add('can_edit', User::have_permit(ADMIN_ITEM) || User::id() == CGlobal::$user_profile['id']);
        $status_check = User::id() == CGlobal::$user_profile['id'] || User::have_permit(ADMIN_ITEM) ? ' status IN(0,1,2,3,4,5)' : ' status =1';
        if ($label_id) {
            $total_item = DB::fetch('SELECT count(*) AS total_row FROM label_item AS L JOIN item AS I ON L.item_id=I.id AND I.' . $status_check . ' AND I.user_id=' . CGlobal::$user_profile['id'] . ' WHERE L.user_id=' . CGlobal::$user_profile['id'] . ' AND L.label_id=' . $label_id, 'total_row', 0);
        } else {
            $total_item = DB::fetch('SELECT count(*) AS total_row FROM item WHERE ' . $status_check . ' AND user_id=' . CGlobal::$user_profile['id'], 'total_row', 0);
        }
        $pagging = '';
        $items = array();
        $divID = 'shop_item';
        $item_per_page = 0;
        if ($total_item) {
            $item_per_page = 9;
            $limit = '';
            $url_path = WEB_DIR . 'ajax.php?act=shop&code=load_shop_label&user_id=' . CGlobal::$user_profile['id'] . '&label_id=' . $label_id . (!$list_type ? '' : '&list_type=' . $list_type);
            $pagging = AZPagging::AjaxPaging($limit, $total_item, $item_per_page, 5, 'page_shop_item', '', false, false, $url_path, $divID, true);
            if ($label_id) {
                $display->add('label_name', CGlobal::$shop_label['name']);
                $select = 'SELECT I.id, I.name,I.sapo, I.user_name, I.user_id,I.description,I.category_id, I.read_count, I.reply_count, I.currency_id, I.price, I.province_id, I.up_time,I.price_out, I.brief, I.img_url, I.status, I.state, I.img_server
				FROM label_item AS L JOIN item AS I ON L.item_id=I.id AND I.' . $status_check . ' AND I.user_id=' . CGlobal::$user_profile['id'] . ' WHERE L.user_id=' . CGlobal::$user_profile['id'] . ' AND L.label_id=' . $label_id . ' ORDER BY shop_order, up_time DESC' . $limit;
            } else {
                $select = 'SELECT id, name, sapo, user_name, user_id, description, category_id, read_count, reply_count, currency_id, price, brief, img_url, province_id, up_time, price_out, status, state, img_server,sticky FROM item WHERE ' . $status_check . ' AND user_id=' . CGlobal::$user_profile['id'] . ' ORDER BY shop_order, up_time DESC' . $limit;
            }
            $re = DB::query($select);
            if (User::is_login()) {
                $wids = User::get_wishlist('wish_list_items');
                $w_items = array();
                if ($wids) {
                    $w_items = explode(',', $wids);
                }
            }
            if ($re) {
                AZLib::getProvinces();
                AZLib::getCats();
                $item_ids = '';
                while ($item = mysql_fetch_assoc($re)) {
                    $item['price'] = AZLib::convertCurrency($item['price'], $item['currency_id']);
                    $item['price_out'] = AZLib::convertCurrency($item['price_out'], $item['currency_id']);
                    $item['currency_id'] = 1;
                    if ($item['img_url']) {
                        $item['image_url'] = AZLib::getImageThumb($item['img_url'], 200, 200, 0, $item['img_server']);
                    }
                    if (isset(CGlobal::$allCategories[$item['category_id']])) {
                        $item['href'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . AZLib::safe_title(AZLib::word_limit($item['name'], 12, '')) . '&nice_name=' . CGlobal::$allCategories[$item['category_id']]['nice_name']);
                    } else {
                        $item['href'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . AZLib::safe_title(AZLib::word_limit($item['name'], 12, '')));
                    }
                    $tooltip = '';
                    $tooltip .= 'Xem: ' . $item['read_count'] . ' - Phản hồi: ' . $item['reply_count'];
                    $item['time_label'] = '';
                    $up_time = date('H:i | ', $item['up_time']);
                    if (date('d.m.y', $item['up_time']) == date('d.m.y', TIME_NOW)) {
                        $up_time .= '<font color="green">H&#244;m nay</font>';
                    } else {
                        $up_time .= date('d.m.y', $item['up_time']);
                    }
                    //$item['created_time'] = 'đăng '.AZLib::duration_time($item['up_time']);
                    $item['created_time'] = $up_time;
                    if ($item['price']) {
                        $item['price'] = number_format($item['price'], 0, ',', '.');
                        $item['currency_id'] = CGlobal::$currency[$item['currency_id']];
                    } else {
                        $item['price'] = '';
                        $item['currency_id'] = '';
                    }
                    $item['price_title'] = 'Giá bán';
                    if ($item['price_out'] > 0) {
                        $item['price_out'] = number_format($item['price_out'], 0, ',', '.') . ($item['currency_id'] == ' ' ? ' ' . CGlobal::$currency[$item['currency_id']] : '');
                    } else {
                        $item['price_out'] = '0';
                    }
                    $item['no_base_source'] = AZLib::remove_4_js(str_replace(array("<br>", "<br />"), '', $item['brief']));
                    $item['description'] = AZLib::plainText(AZLib::parseBBCode(html_entity_decode($item['description'], ENT_QUOTES, "UTF-8")));
                    $item['description'] = preg_replace("/\\[([\\s]*[0-9]{1,2}[\\s]*)\\]/eis", " ", $item['description']);
                    $item['description'] = str_replace(array("'", "\""), array("", " "), $item['description']);
                    $item['description'] = AZLib::word_limit($item['description'], 250, '');
                    /* if($item['sapo']!=''){
                       $item['brief'] = $item['sapo'];
                       $item['brief'] = AZLib::subString(AZLib::filter_title($item['brief']),0,255,true);
                       $item['brief'] = AZLib::word_limit($item['brief'],30,'');
                       }
                       else{
                       $item['brief'] = String::display_sort_title($item['description'],30);
                       } */
                    $item['brief'] = '';
                    $item['parent_name'] = '';
                    if (isset(CGlobal::$allCategories[$item['category_id']]) && CGlobal::$allCategories[$item['category_id']]['parent_id']) {
                        $parent_id = CGlobal::$allCategories[$item['category_id']]['parent_id'];
                        if (isset(CGlobal::$allCategories[$parent_id])) {
                            $item['parent_name'] = CGlobal::$allCategories[$parent_id]['name'] . ' - ';
                        }
                    }
                    if (isset(CGlobal::$allCategories[$item['category_id']]['name'])) {
                        $item['category_name'] = $item['parent_name'] . CGlobal::$allCategories[$item['category_id']]['name'];
                    } else {
                        $item['category'] = '';
                        $item['category_name'] = '';
                    }
                    $item['safe_title'] = AZLib::safe_title($item['parent_name'] . $item['category_name']);
                    $item['category_href'] = WEB_DIR . AZRewrite::formatUrl('?page=list_detail&category_id=' . $item['category_id'] . '&ebname=' . $item['safe_title']);
                    $item['name'] = AZLib::subString(AZLib::filter_title($item['name']), 0, 115, true);
                    $item['name'] = AZLib::word_limit($item['name'], 12, '');
                    $item['user_name'] = $item['user_name'];
                    $item['profile_url'] = WEB_DIR . $item['user_name'];
                    $item['city'] = CGlobal::$provinces[$item['province_id']]['name'];
                    if ($item['img_url']) {
                        $item['img_url'] = AZLib::getImageThumb($item['img_url'], 110, 0, 1, $item['img_server']);
                    } else {
                        $item['img_url'] = 'style/images/no-images-69x53.jpg';
                    }
                    if (isset($_GET['ebname'])) {
                        $item['up_url'] = Url::build_current(array('action' => 'up', 'id' => $item['id'], 'category_id' => CGlobal::$curCategory, 'type' => Url::get('type'), 'ebname' => $_GET['ebname']));
                        $item['down_url'] = Url::build_current(array('action' => 'down', 'id' => $item['id'], 'category_id' => CGlobal::$curCategory, 'type' => Url::get('type'), 'ebname' => $_GET['ebname']));
                    } else {
                        $item['up_url'] = Url::build_current(array('action' => 'up', 'id' => $item['id'], 'category_id' => CGlobal::$curCategory, 'type' => Url::get('type')));
                        $item['down_url'] = Url::build_current(array('action' => 'down', 'id' => $item['id'], 'category_id' => CGlobal::$curCategory, 'type' => Url::get('type')));
                    }
                    $item['in_wish_list'] = false;
                    if (User::is_login()) {
                        if (in_array($item['id'], $w_items)) {
                            $item['in_wish_list'] = true;
                        } else {
                            $item['in_wish_list'] = false;
                        }
                    } else {
                        if (isset($_COOKIE['wish_list_item_ids'])) {
                            $arr = explode(',', $_COOKIE['wish_list_item_ids']);
                            foreach ($arr as $k => $v) {
                                if ($v == $item['id']) {
                                    $item['in_wish_list'] = true;
                                }
                            }
                        }
                    }
                    if (CGlobal::$user_profile['id'] == User::id()) {
                        $tooltip .= ' - <strong>ID tin: ' . $item['id'] . '</strong>';
                    }
                    $item['invalid'] = '';
                    if ($item['status'] == 2) {
                        $tooltip .= '<div style=\\\'color:red\\\'>(Đang kiểm duyệt)</div>';
                        $item['invalid'] = '<font color="red">(Đang kiểm duyệt)</font>';
                    } elseif ($item['status'] == 3) {
                        $tooltip .= '<div style=\\\'color:red\\\'>(Tin theo dõi lừa đảo)</div>';
                        $item['invalid'] = '<font color="red">(Theo dõi lừa đảo)</font>';
                    } elseif ($item['status'] == 0) {
                        $tooltip .= '<div style=\\\'color:red\\\'>(Đang ẩn)</div>';
                        $item['invalid'] = '<font color="red">(Đang ẩn)</font>';
                    } elseif ($item['status'] == 5) {
                        $tooltip .= '<div style=\\\'color:red\\\'>(Đang kiểm duyệt chờ chứng thực)</div>';
                        $item['invalid'] = '<font color="red">(KD chờ chứng thực)</font>';
                    } elseif ($item['status'] == 4) {
                        $tooltip .= '<div style=\\\'color:red\\\'>(Tin trùng)</div>';
                        $item['invalid'] = '<font color="red">(Tin trùng)</font>';
                    } elseif ($item['state'] == 1) {
                        $tooltip .= '<div style=\\\'color:red\\\'>(Đang khóa)</div>';
                        $item['invalid'] = '<font color="red">(Đang khóa)</font>';
                    }
                    $item['tooltip'] = $tooltip;
                    $item['lids'] = '';
                    $item_ids .= ($item_ids != '' ? ',' : '') . $item['id'];
                    $items[$item['id']] = $item;
                }
            }
            if ($item_ids) {
                $item_labels = array();
                //Label của tất cả sp đang đc hiển thị
                $re = DB::query("SELECT id, label_id, item_id FROM label_item WHERE item_id IN({$item_ids})");
                if ($re) {
                    while ($l_item = mysql_fetch_assoc($re)) {
                        if (isset($items[$l_item['item_id']])) {
                            $items[$l_item['item_id']]['lids'] .= ($items[$l_item['item_id']]['lids'] != '' ? ',' : '') . $l_item['label_id'];
                        }
                    }
                }
            }
        }
        $display->add('loading_ajax', true);
        $display->add('is_admin', (int) User::have_permit(ADMIN_ITEM));
        $display->add('cur_id', (int) User::id());
        $display->add('total_sp', (int) $total_item);
        $display->add('items', $items);
        $display->add('paging', $pagging);
        $display->add('item_per_page', $item_per_page);
        $display->add('page_num', $page_shop_item);
        $display->add('shop_user_id', CGlobal::$user_profile['id']);
        $display->add('shop_user_name', CGlobal::$user_profile['user_name']);
        $display->output($list_type != 1 ? 'ShopItem' : 'ShopItemListDetail', false, 'Shop');
    }