Пример #1
0
 function draw()
 {
     global $display;
     AZLib::getCats();
     $this->beginForm();
     $item = Item::get_item($this->booking_vip['item_id']);
     if (!$item || $item && $item['status'] == -1) {
         $this->setFormError("item_id", "Tin không tồn tại!");
     } else {
         $display->add('item_name', stripslashes($item['name']));
         $display->add('item_link', Url::build('item_detail', array('id' => $item['id'], 'ebname' => AZLib::safe_title($item['name']))));
     }
     $top_catid = $item['level_1_catid'];
     $cat_id = $item['category_id'];
     $display->add('msg', $this->showFormErrorMessages(1));
     $display->add('item_id', $this->booking_vip['item_id']);
     if ($this->booking_vip['top_cat']) {
         $display->add('category', 1);
     } else {
         if ($this->booking_vip['cat_id']) {
             $display->add('category', 2);
         }
     }
     $display->add('num_contract', $this->booking_vip['num_contract']);
     $display->add('top_cat_name', CGlobal::$allCategories[$top_catid]['name']);
     $display->add('cat_name', CGlobal::$allCategories[$cat_id]['name']);
     $display->add('note', stripslashes(Url::get("note", $this->booking_vip['note'])));
     $display->add('time_start', Url::get("time_start", date('d-m-Y', $this->booking_vip['time_start'])));
     if ($this->booking_vip['time_end']) {
         $display->add('time_end', Url::get("time_end", date('d-m-Y', $this->booking_vip['time_end'])));
     } else {
         $display->add('time_end', Url::get("time_end", ''));
     }
     $display->output('EditBookingVip');
     $this->endForm();
 }
Пример #2
0
 static function mod_have_cat_permit($catid)
 {
     if (User::is_login()) {
         if (User::have_permit(ADMIN_ITEM)) {
             return TRUE;
         }
         AZLib::getCats();
         if (!isset(CGlobal::$allCategories[$catid])) {
             return FALSE;
         }
         if (isset(User::$current->groups['4'])) {
             //Nếu đã phân nhóm
             self::get_permits();
             if (User::$permit_cats) {
                 if (CGlobal::$allCategories[$catid]['parent_id']) {
                     return preg_match("/(" . User::$permit_cats . ")/is", $catid) || preg_match("/(" . User::$permit_cats . ")/is", CGlobal::$allCategories[$catid]['parent_id']);
                 }
                 return preg_match("/(" . User::$permit_cats . ")/is", $catid);
             }
         }
     }
     return FALSE;
 }
Пример #3
0
 function Category($row)
 {
     Module::Module($row);
     if (User::have_permit(ADMIN_CATEGORY)) {
         $cmd = Url::get('cmd');
         $mod = Url::get('mod');
         switch ($mod) {
             case 'zone':
                 switch ($cmd) {
                     case 'delete':
                         //							AZLib::del_cache_zone_cat();
                         $id = (int) Url::get('id', 0);
                         if ($id) {
                             $cat_zone = DB::select('category_zone', 'id=' . $id);
                             if ($cat_zone) {
                                 DB::delete('category_zone', "id = {$cat_zone['id']}");
                                 DB::delete('category_zone_cat', "zoneid = {$cat_zone['id']}");
                             }
                             AZLib::getCats(0, 1);
                         }
                         Url::redirect_current(array("mod"));
                         break;
                     case 'add':
                     case 'edit':
                         require_once 'forms/ZoneEdit.php';
                         $this->add_form(new ZoneEditForm());
                         break;
                         /*case 'move_zonecat_up':
                         		case 'move_zonecat_down':
                         				$id=(int)Url::get('id',0);
                         				if($id){
                         					$zonecat=DB::select('category_zone_cat','catid='.(int)Url::get('catid',0).' AND zoneid='.$id);
                         					if($zonecat){
                         						if($cmd=='move_zonecat_up'){
                         							$nearest_zonecat=DB::select('category_zone_cat','position<'.$zonecat['position'].' AND zoneid='.$id.' ORDER BY position DESC');
                         						}
                         						else{
                         							$nearest_zonecat=DB::select('category_zone_cat','position>'.$zonecat['position'].' AND zoneid='.$id.' ORDER BY position ASC');
                         						}
                         						if($nearest_zonecat){
                         							// Vị trí của category trong zone đã được chuẩn hóa
                         							DB::update('category_zone_cat',array('position'=>$nearest_zonecat['position']),'id='.$zonecat['id']);
                         							DB::update('category_zone_cat',array('position'=>$zonecat['position']),'id='.$nearest_zonecat['id']);	
                         						}
                         						else
                         						{
                         							//Vị trí không chuẩn, vị trí tiếp theo bằng đúng vị trí của category hiện tại
                         							$nearest_zonecat=DB::select('category_zone_cat','position='.$zonecat['position'].' AND catid<>'.$zonecat['catid'].' AND zoneid='.$id.' ORDER BY position ASC');
                         							if($nearest_zonecat){
                         								if($cmd=='move_zonecat_up')
                         								{
                         									$zonecat['position']++;
                         								}
                         								elseif($zonecat['position'] > 0)
                         								{
                         									$zonecat['position']--;
                         								}
                         								DB::update('category_zone_cat',array('position'=>$zonecat['position']),'id='.$nearest_zonecat['id']);
                         							}
                         						}
                         					}
                         				}
                         				Url::redirect_current(array('mod'=>'zone','cmd'=>'edit','id'=>$id));
                         				break;*/
                     /*case 'move_zonecat_up':
                     		case 'move_zonecat_down':
                     				$id=(int)Url::get('id',0);
                     				if($id){
                     					$zonecat=DB::select('category_zone_cat','catid='.(int)Url::get('catid',0).' AND zoneid='.$id);
                     					if($zonecat){
                     						if($cmd=='move_zonecat_up'){
                     							$nearest_zonecat=DB::select('category_zone_cat','position<'.$zonecat['position'].' AND zoneid='.$id.' ORDER BY position DESC');
                     						}
                     						else{
                     							$nearest_zonecat=DB::select('category_zone_cat','position>'.$zonecat['position'].' AND zoneid='.$id.' ORDER BY position ASC');
                     						}
                     						if($nearest_zonecat){
                     							// Vị trí của category trong zone đã được chuẩn hóa
                     							DB::update('category_zone_cat',array('position'=>$nearest_zonecat['position']),'id='.$zonecat['id']);
                     							DB::update('category_zone_cat',array('position'=>$zonecat['position']),'id='.$nearest_zonecat['id']);	
                     						}
                     						else
                     						{
                     							//Vị trí không chuẩn, vị trí tiếp theo bằng đúng vị trí của category hiện tại
                     							$nearest_zonecat=DB::select('category_zone_cat','position='.$zonecat['position'].' AND catid<>'.$zonecat['catid'].' AND zoneid='.$id.' ORDER BY position ASC');
                     							if($nearest_zonecat){
                     								if($cmd=='move_zonecat_up')
                     								{
                     									$zonecat['position']++;
                     								}
                     								elseif($zonecat['position'] > 0)
                     								{
                     									$zonecat['position']--;
                     								}
                     								DB::update('category_zone_cat',array('position'=>$zonecat['position']),'id='.$nearest_zonecat['id']);
                     							}
                     						}
                     					}
                     				}
                     				Url::redirect_current(array('mod'=>'zone','cmd'=>'edit','id'=>$id));
                     				break;*/
                     case 'move_up':
                     case 'move_down':
                         //								AZLib::del_cache_zone_cat();
                         $id = (int) Url::get('id', 0);
                         if ($id) {
                             $cat_zone = DB::select('category_zone', 'id=' . $id);
                             if ($cat_zone) {
                                 if ($cmd == 'move_up') {
                                     $nearest_cat_zone = DB::select('category_zone', 'position<' . $cat_zone['position'] . ' ORDER BY position DESC');
                                 } else {
                                     $nearest_cat_zone = DB::select('category_zone', 'position>' . $cat_zone['position'] . ' ORDER BY position ASC');
                                 }
                                 if ($nearest_cat_zone) {
                                     DB::update('category_zone', array('position' => $nearest_cat_zone['position']), 'id=' . $cat_zone['id']);
                                     DB::update('category_zone', array('position' => $cat_zone['position']), 'id=' . $nearest_cat_zone['id']);
                                 }
                                 AZLib::getCats(0, 1);
                             }
                         }
                         Url::redirect_current(array("mod"));
                         break;
                     case 'show':
                     case 'hide':
                         //AZLib::del_cache_zone_cat();
                         $id = (int) Url::get('id', 0);
                         if ($id) {
                             $cat_zone = DB::select('category_zone', 'id=' . $id);
                             if ($cat_zone) {
                                 if ($cmd == 'hide') {
                                     $status = 0;
                                 } else {
                                     $status = 1;
                                 }
                                 DB::update('category_zone', array('status' => $status), "id={$id}");
                                 AZLib::getCats(0, 1);
                             }
                         }
                         Url::redirect_current(array("mod"));
                         break;
                     default:
                         require_once 'forms/Zone.php';
                         $this->add_form(new ZoneForm());
                 }
                 break;
             default:
                 switch ($cmd) {
                     case 'del_image':
                         $id = (int) Url::get('id', 0);
                         //Xoá file ảnh
                         if ($id) {
                             $cat = DB::select('category', "id={$id}");
                             if ($cat) {
                                 AZLib::ftp_image_delete_file('category/' . $id . '.gif', $cat['img_server']);
                                 //@fopen('http://'.IMAGE_PATH.'?del_cat=1',"r");//Xoá cache file ảnh
                             }
                             Url::redirect_current();
                         }
                         break;
                     case 'delete':
                         $selected_ids = Url::get('selected_ids');
                         if ($selected_ids) {
                             $ids = implode(',', $selected_ids);
                             if ($ids != '') {
                                 //									AZLib::del_cache_zone_cat();
                                 DB::delete('category', 'id IN(' . $ids . ')');
                             }
                             AZLib::getCats(0, 1);
                         }
                         Url::redirect_current();
                         break;
                     case 'del_cache':
                         //							AZLib::del_cache_zone_cat();
                         AZLib::getCats(0, 1);
                         Url::redirect_current();
                         break;
                     case 'add':
                     case 'edit':
                         require_once 'forms/CategoryEdit.php';
                         $this->add_form(new EditCategoryForm());
                         break;
                     case 'move_up':
                     case 'move_down':
                         $id = (int) Url::get('id', 0);
                         if ($id) {
                             $cat = DB::select('category', 'id=' . $id);
                             if ($cat) {
                                 //										AZLib::del_cache_zone_cat();
                                 if ($cmd == 'move_up') {
                                     $nearest_cat = DB::select('category', 'position<' . $cat['position'] . ' AND parent_id=' . $cat['parent_id'] . ' ORDER BY position DESC');
                                 } else {
                                     $nearest_cat = DB::select('category', 'position>' . $cat['position'] . ' AND parent_id=' . $cat['parent_id'] . ' ORDER BY position ASC');
                                 }
                                 if ($nearest_cat) {
                                     DB::update('category', array('position' => $nearest_cat['position']), 'id=' . $cat['id']);
                                     DB::update('category', array('position' => $cat['position']), 'id=' . $nearest_cat['id']);
                                 }
                                 AZLib::getCats(0, 1);
                             }
                         }
                         Url::redirect_current();
                         break;
                     case 'set_home':
                     case 'show':
                     case 'hide':
                         $id = (int) Url::get('id', 0);
                         if ($id) {
                             $cat = DB::select('category', 'id=' . $id);
                             if ($cat) {
                                 //									AZLib::del_cache_zone_cat();
                                 if ($cmd == 'set_home') {
                                     $status = 'HOME';
                                 } elseif ($cmd == 'hide') {
                                     $status = 'HIDE';
                                 } else {
                                     $status = 'SHOW';
                                 }
                                 DB::update('category', array('status' => $status), "id={$id}");
                                 AZLib::getCats(0, 1);
                             }
                         }
                         Url::redirect_current();
                         break;
                     case 'validated':
                     case 'un_validated':
                         $id = (int) Url::get('id', 0);
                         if ($id) {
                             $cat = DB::select('category', 'id=' . $id);
                             if ($cat) {
                                 if ($cmd == 'validated') {
                                     $must_validated = 1;
                                 } elseif ($cmd == 'hide') {
                                     $must_validated = 0;
                                 }
                                 if ($cat['parent_id']) {
                                     DB::update('category', array('must_validated' => $must_validated), "id={$id}");
                                 } else {
                                     DB::update('category', array('must_validated' => $must_validated), "parent_id={$id} OR id={$id}");
                                 }
                                 AZLib::getCats(0, 1);
                             }
                         }
                         Url::redirect_current();
                         break;
                     case 'phone_verified':
                     case 'un_phone_verified':
                         $id = (int) Url::get('id', 0);
                         if ($id) {
                             $cat = DB::select('category', 'id=' . $id);
                             if ($cat) {
                                 if ($cmd == 'phone_verified') {
                                     $must_phone_verified = 1;
                                 } elseif ($cmd == 'hide') {
                                     $must_phone_verified = 0;
                                 }
                                 if ($cat['parent_id']) {
                                     DB::update('category', array('must_phone_verified' => $must_phone_verified), "id={$id}");
                                 } else {
                                     DB::update('category', array('must_phone_verified' => $must_phone_verified), "parent_id={$id} OR id={$id}");
                                 }
                                 AZLib::getCats(0, 1);
                             }
                         }
                         Url::redirect_current();
                         break;
                     case 'optimize':
                         $this->optimize();
                         AZLib::getCats(0, 1);
                         Url::redirect_current();
                         break;
                     case 'filter':
                         require_once 'forms/Filter.php';
                         $this->add_form(new FilterForm());
                         break;
                     case 'filter_list':
                         require_once 'forms/FilterList.php';
                         $this->add_form(new FilterListForm());
                         break;
                     case '':
                         require_once 'forms/Category.php';
                         $this->add_form(new ListCategoryForm());
                         break;
                     default:
                         Url::redirect_current();
                         break;
                 }
                 break;
         }
     } else {
         Url::access_denied();
     }
 }
Пример #4
0
 function on_submit()
 {
     $name = Url::get('name');
     $brief_name = Url::get('brief_name');
     $status = (int) Url::get('status', 'HIDE');
     $position = (int) Url::get('position');
     $class = Url::get('class');
     $catids = Url::get('catids');
     $this->checkFormInput('Tên Danh mục', 'name', $name, 'str', true, '', 1, 255);
     $this->checkFormInput('Tên vắn tắt', 'brief_name', $brief_name, 'str', false, '', 1, 255);
     //$this->checkFormInput('Mô tả','description',$description,'str',false,'',0,250);
     if (!$this->errNum) {
         $new_row = array('name' => $name, 'brief_name' => $brief_name ? $brief_name : $name, 'status' => $status, 'class' => $class);
         $update_orther_pos = false;
         if (Url::get('cmd') == 'edit') {
             if ($position > 0 && $position != $this->cat_zone['position']) {
                 $max_pos = (int) DB::fetch("SELECT max(position) AS max_pos FROM category_zone", 'max_pos');
                 if ($position > $max_pos) {
                     $position = $max_pos + 1;
                 }
                 $new_row['position'] = $position;
             } else {
                 $position = $this->cat_zone['position'];
             }
             $id = $this->cat_zone['id'];
             DB::update('category_zone', $new_row, 'id=' . $this->cat_zone['id']);
         } else {
             $max_pos = (int) DB::fetch("SELECT max(position) AS max_pos FROM category_zone", 'max_pos');
             if ($position > $max_pos || $position == 0) {
                 $position = $max_pos + 1;
             }
             $new_row['position'] = $position;
             $id = DB::insert('category_zone', $new_row);
         }
         if ($id && DB::select('category_zone', "position={$position} AND id!={$id}")) {
             DB::query("UPDATE category_zone SET position=position+1 WHERE position>={$position} AND id!={$id}");
         }
         $all_cats = $this->cats;
         $sql_inset = "";
         $position = 0;
         $arrCatIDs = split(',', $catids);
         foreach ($arrCatIDs as $catid) {
             //if(isset($all_cats[$catid])){
             //	unset($all_cats[$catid]);
             //}
             //else{
             $position++;
             $sql_inset .= ($sql_inset != '' ? ',' : '') . "({$id},{$catid},{$position})";
             //}
         }
         if ($all_cats) {
             //$catids = implode(",",array_keys($all_cats));
             //if($catids){
             //echo "DELETE FROM category_zone_cat WHERE zoneid=$id AND catid IN($all_cats)";
             DB::query("DELETE FROM category_zone_cat WHERE zoneid={$id} AND catid IN({$all_cats})");
             //}
         }
         if ($sql_inset) {
             $sql_inset = "INSERT INTO category_zone_cat (zoneid, catid,position) VALUES " . $sql_inset;
             //echo $sql_inset;
             DB::query($sql_inset);
         }
         //AZLib::del_cache_zone_cat();
         AZLib::getCats(1, true);
         //Url::redirect_current(array('mod'));
     }
 }
Пример #5
0
 function draw()
 {
     global $display;
     $this->beginForm();
     AZLib::getCats();
     $items = array();
     $item_bookings = array();
     $where = '';
     $order = 'id DESC';
     $catid = Url::get('catid', 0);
     $item_id = Url::get('item_id', 0);
     $user_add = Url::get('user_add', '');
     $num_contract = Url::get('num_contract', '');
     $status = Url::get('status', 0);
     $time_start = 0;
     $time_end = 0;
     $date_start = Url::get('date_start');
     $date_end = Url::get('date_end');
     if ($date_start) {
         $arr = explode('-', $date_start);
         $time_start = mktime(0, 0, 0, $arr[1], $arr[0], $arr[2]);
     }
     if ($date_end) {
         $arr = explode('-', $date_end);
         $time_end = mktime(23, 59, 59, $arr[1], $arr[0], $arr[2]);
     }
     if ($time_start >= $time_end) {
         $date_end = '';
         $time_end = 0;
     }
     if ($time_start) {
         $where .= ($where != '' ? ' AND ' : 'WHERE ') . " time_start >= {$time_start}";
         $order = 'time_start ASC, id DESC';
     }
     if ($time_end) {
         $where .= ($where != '' ? ' AND ' : 'WHERE ') . " time_start <= {$time_end}";
     }
     $display->add('date_start', $date_start);
     $display->add('date_end', $date_end);
     $time_start2 = 0;
     $time_end2 = 0;
     $date_start2 = Url::get('date_start2');
     $date_end2 = Url::get('date_end2');
     if ($date_start2) {
         $arr = explode('-', $date_start2);
         $time_start2 = mktime(0, 0, 0, $arr[1], $arr[0], $arr[2]);
     }
     if ($date_end2) {
         $arr = explode('-', $date_end2);
         $time_end2 = mktime(23, 59, 59, $arr[1], $arr[0], $arr[2]);
     }
     if ($time_start2 >= $time_end2) {
         $date_end2 = '';
         $time_end2 = 0;
     }
     if ($time_start2) {
         $where .= ($where != '' ? ' AND ' : 'WHERE ') . " time_end >= {$time_start2}";
         if ($order != 'time_start ASC, id DESC') {
             $order = 'time_end ASC, id DESC';
         }
     }
     if ($time_end2) {
         $where .= ($where != '' ? ' AND ' : 'WHERE ') . " time_end <= {$time_end2}";
     }
     $display->add('date_start2', $date_start2);
     $display->add('date_end2', $date_end2);
     if ($status != 3) {
         $where .= ($where != '' ? ' AND ' : 'WHERE ') . " status = {$status}";
     } elseif ($status == 3) {
         $where .= ($where != '' ? ' AND ' : 'WHERE ') . " status in (0,1)";
     }
     if ($item_id) {
         $where .= ($where != '' ? ' AND ' : 'WHERE ') . " item_id = {$item_id}";
     }
     if ($user_add != '') {
         $where .= ($where != '' ? ' AND ' : 'WHERE ') . " user_add = '{$user_add}'";
     }
     if ($num_contract != '') {
         $where .= ($where != '' ? ' AND ' : 'WHERE ') . " num_contract = '{$num_contract}'";
     }
     $zone_id = Url::get("zone_id", 0);
     $arr = array(0 => "-- Tất cả Zone --");
     foreach (CGlobal::$allZones as $zone) {
         $arr[$zone['id']] = $zone['name'];
     }
     $display->add('zone_option', AZLib::getOption($arr, $zone_id));
     $arr = array(0 => "-- Tất cả Danh mục --");
     if (isset(CGlobal::$allCategories[$catid])) {
         if (CGlobal::$allCategories[$catid]['parent_id']) {
             $where .= ($where != '' ? ' AND ' : 'WHERE ') . " cat_id = {$catid}";
         } else {
             if (isset(CGlobal::$subCategories[$catid]) && CGlobal::$subCategories[$catid]) {
                 $where .= ($where != '' ? ' AND ' : 'WHERE ') . " (top_cat = {$catid} OR cat_id IN(" . implode(",", array_keys(CGlobal::$subCategories[$catid])) . "))";
             } else {
                 $where .= ($where != '' ? ' AND ' : 'WHERE ') . " top_cat = {$catid}";
             }
         }
     }
     if (CGlobal::$allCategories && CGlobal::$subCategories) {
         foreach (CGlobal::$subCategories as $topid => $subcats) {
             if (!$zone_id || $zone_id && isset(CGlobal::$allCategories[$topid]) && in_array($zone_id, CGlobal::$allCategories[$topid]['zones'])) {
                 if (isset(CGlobal::$allCategories[$topid])) {
                     $arr[$topid] = CGlobal::$allCategories[$topid]['name'] . " ({$topid})";
                 } else {
                     $arr[$topid] = "({$topid})";
                 }
                 foreach ($subcats as $cid => $cat) {
                     $arr[$cid] = "--------{$cat['name']} ({$cid})";
                 }
             }
         }
     }
     $display->add('cat_option', AZLib::getOption($arr, $catid));
     $display->add('item_id', $item_id);
     $display->add('status', $status);
     $display->add('user_add', $user_add);
     $display->add('num_contract', $num_contract);
     $re = DB::query("SELECT * FROM bookings_vip {$where} ORDER BY {$order}");
     $item_ids = '';
     if ($re) {
         while ($v_item = mysql_fetch_assoc($re)) {
             $zid = 0;
             $zone_name = 0;
             $topcid = 0;
             $cid = 0;
             if ($v_item['cat_id']) {
                 $cid = $v_item['cat_id'];
                 if (isset(CGlobal::$allCategories[$cid])) {
                     $topcid = CGlobal::$allCategories[$cid]['parent_id'];
                 }
             } elseif ($v_item['top_cat']) {
                 $topcid = $v_item['top_cat'];
             }
             if (!$topcid && $cid) {
                 if (isset(CGlobal::$allCategories[$cid])) {
                     $topcid = CGlobal::$allCategories[$cid]['parent_id'];
                 }
             }
             if ($topcid) {
                 if (isset(CGlobal::$allCategories[$topcid])) {
                     foreach (CGlobal::$allCategories[$topcid]['zones'] as $zoneid) {
                         if ($zoneid) {
                             $zid = $zoneid;
                             break;
                         }
                     }
                 }
             }
             $zone_name = "[{$zid}] ";
             if ($zid && isset(CGlobal::$allZones[$zid])) {
                 $zone_name .= CGlobal::$allZones[$zid]['name'];
             }
             if (!$zone_id || $zone_id && $zid == $zone_id) {
                 $v_item['zone'] = $zone_name;
                 $v_item['time'] = "<b>Tạo:</b> " . date("d/m/Y H:i", $v_item['time_add']) . " bởi <b>" . $v_item['user_add'] . "</b>";
                 if ($v_item['time_add'] != $v_item['time_edit']) {
                     $v_item['time'] .= "<br /><b>Sửa:</b> " . date("d/m/Y H:i", $v_item['time_edit']) . " bởi <b>" . $v_item['user_edit'] . "</b>";
                 }
                 if ($v_item['user_update_status'] != '' && $v_item['time_update_status'] != 0) {
                     $v_item['time'] .= "<br /><b>Update:</b> " . date("d/m/Y H:i", $v_item['time_update_status']) . " bởi <b>" . $v_item['user_update_status'] . "</b>";
                 }
                 switch ($v_item['status']) {
                     case -1:
                         $v_item['str_status'] = "<font color=red><b>Đã xóa <br/>{$v_item['user_del']}</b></font>";
                         break;
                     case 1:
                         $v_item['str_status'] = "<font color=black><b>Đã xử lý</b></font>";
                         break;
                     default:
                         $v_item['str_status'] = "<font color=green><b>Chưa xử lý</b></font>";
                         $v_item['permis'] = 0;
                         if (User::have_permit(ADMIN_VIP_ITEM)) {
                             $v_item['permis'] = 1;
                             $v_item['update_status'] = Url::build_current(array('cmd' => 'update_status', 'id' => $v_item['id']));
                             $v_item['active'] = Url::build_current(array('cmd' => 'active', 'id' => $v_item['id']));
                         }
                         $v_item['edit'] = Url::build_current(array('cmd' => 'edit', 'id' => $v_item['id']));
                         $v_item['delete'] = Url::build_current(array('cmd' => 'delete', 'id' => $v_item['id']));
                         break;
                 }
                 if ($v_item['time_start'] > TIME_NOW) {
                     $v_item['time_start'] = '<font color="#c00"><b>' . date("d/m/Y", $v_item['time_start']) . '</b></font>';
                 } else {
                     $v_item['time_start'] = date("d/m/Y", $v_item['time_start']);
                 }
                 if ($v_item['time_end']) {
                     if ($v_item['time_end'] < TIME_NOW) {
                         $v_item['time_end'] = '<font color="#f00"><b>' . date("d/m/Y", $v_item['time_end']) . '</b></font>';
                     } else {
                         $v_item['time_end'] = date("d/m/Y", $v_item['time_end']);
                     }
                 } else {
                     $v_item['time_end'] = '';
                 }
                 $item_ids .= ($item_ids != '' ? ',' : '') . $v_item['item_id'];
                 //check vi tri vip
                 $v_item['top_cat'] != 0 ? $cat_id = $v_item['top_cat'] : ($cat_id = $v_item['cat_id']);
                 $item_vip = DB::select_all('item_vip', "(catid = {$cat_id} OR level_1_catid = {$cat_id}) AND status = 1 AND time_end >" . TIME_NOW);
                 $i = 0;
                 $sa = $v_item['time_start'];
                 $ea = $v_item['time_end'];
                 foreach ($item_vip as $item) {
                     if ($sa > $item['time_start'] && $sa < $item['time_end']) {
                         $i++;
                     } elseif ($ea > $item['time_start'] && $ea < $item['time_end']) {
                         $i++;
                     } elseif ($sa < $item['time_start'] && $ea > $item['time_end']) {
                         $i++;
                     }
                 }
                 $v_item['over_slot'] = 0;
                 if ($i >= 2) {
                     $v_item['over_slot'] = 1;
                 }
                 //end check vi tri
                 //check trung ID
                 $v_item['exist_id'] = 0;
                 foreach ($item_vip as $item) {
                     if ($v_item['item_id'] == $item['item_id']) {
                         $v_item['exist_id'] = 1;
                     }
                 }
                 //end check trung ID
                 $item_bookings[$v_item['id']] = $v_item;
             }
         }
     }
     if ($item_ids != '') {
         $re = DB::query("SELECT * FROM item WHERE id IN({$item_ids})");
         if ($re) {
             while ($item = mysql_fetch_assoc($re)) {
                 $item['item_link'] = Url::build('item_detail', array('id' => $item['id'], 'ebname' => AZLib::safe_title($item['name'])));
                 $items[$item['id']] = $item;
             }
         }
     }
     foreach ($item_bookings as &$v_item) {
         if (isset($items[$v_item['item_id']])) {
             $v_item['item_link'] = $items[$v_item['item_id']]['item_link'];
             $v_item['item_name'] = stripslashes($items[$v_item['item_id']]['name']);
             if ($items[$v_item['item_id']]['status'] == -1) {
                 $v_item['item_name'] .= ' <font color="#c00">Tin xoá</font>';
             } elseif ($items[$v_item['item_id']]['status'] != 1) {
                 $v_item['item_name'] .= ' <font color="#c00">KD</font>';
             }
             $top_catid = $items[$v_item['item_id']]['level_1_catid'];
             $catid = $items[$v_item['item_id']]['category_id'];
             $v_item['top_cat_name'] = $v_item['top_cat'] ? CGlobal::$allCategories[$v_item['top_cat']]['name'] : '';
             $v_item['cat_name'] = $v_item['cat_id'] ? CGlobal::$allCategories[$v_item['cat_id']]['name'] : '';
             if ($v_item['cat_id'] && $v_item['cat_id'] != $catid) {
                 $v_item['wrong_cat'] = '<font color="red">(sai chủng loại)</font>';
             }
             $v_item['item_cat_name'] = "<font color=blue>" . CGlobal::$allCategories[$top_catid]['name'] . '</font> /<br /><font color=green>' . CGlobal::$allCategories[$catid]['name'] . '</font>';
             if (isset(CGlobal::$allCategories[$v_item['cat_id']])) {
                 $v_item['cat_vip'] = CGlobal::$allCategories[$v_item['cat_id']]['name'];
             } else {
                 $v_item['cat_vip'] = '';
             }
         } else {
             $v_item['item_name'] = 'Tin không tồn tại';
             $v_item['cat_name'] = '';
         }
     }
     $display->add('items', $item_bookings);
     $display->output('ManageBookingVip');
     $this->endForm();
 }
Пример #6
0
 function on_submit()
 {
     $title = AZLib::getParam('subject');
     $content = AZLib::getParam('content');
     $id_cats = AZLib::getParam('id_cats');
     $send_all = AZLib::getParam('send_all');
     $usernames = Url::get('user_names');
     $start_date = Url::get('start_date');
     $end_date = Url::get('end_date');
     $start_date_a = Url::get('start_date_a');
     $end_date_a = Url::get('end_date_a');
     $is_active = Url::get('user_active');
     set_time_limit(0);
     if ($id_cats != 0) {
         //gửi cho thành viên bán theo chuyên mục
         $sql_user_sell = 'SELECT user_id, user_name FROM item ';
         AZLib::getCats();
         if (CGlobal::$allCategories[$id_cats]['parent_id'] > 0) {
             $condition = ' category_id = "' . $id_cats . '"';
         } else {
             $condition = ' level_1_catid = "' . $id_cats . '"';
         }
         $num_row = mysql_fetch_assoc(DB::query("SELECT count(*) as num_total FROM (SELECT count(*) FROM item WHERE status=1 AND {$condition} GROUP BY user_id) AS i"));
         if ($num_row) {
             $num_row = (int) $num_row['num_total'];
         } else {
             $num_row = 0;
         }
         if ($num_row) {
             $num_record = 100;
             $num_query = ceil($num_row / $num_record);
             $new_row_msg = array('msg_date' => TIME_NOW, 'msg_post' => htmlspecialchars_decode(addslashes($content)), 'msg_sent_to_count' => $num_row, 'msg_deleted_count' => 0, 'msg_author_id' => User::$current->data['id'], 'msg_author_name' => User::$current->data['user_name'], 'msg_ip_address' => AZLib::ip());
             if ($title && $content && $num_row > 0) {
                 $msg_id = DB::insert('message_text', $new_row_msg);
                 for ($j = 0; $j < $num_query; $j++) {
                     $value_sql = '';
                     $update_sql = '';
                     $user = array();
                     $sql = 'SELECT user_id, item.user_name FROM item WHERE status=1 AND ' . $condition . ' GROUP BY user_id LIMIT ' . $j * $num_record . "," . $num_record;
                     $re = DB::query($sql);
                     if ($re) {
                         while ($user = mysql_fetch_assoc($re)) {
                             $value_sql .= ($value_sql ? "," : "") . "('" . $msg_id . "','" . TIME_NOW . "','" . $title . "','" . User::id() . "','" . User::user_name() . "','inbox','" . $user['user_id'] . "','" . $user['user_name'] . "')";
                             $update_sql .= ($update_sql ? "," : "") . $user['user_id'];
                             $this->total_record++;
                         }
                         $insert_sql = "INSERT INTO `message_topics` (`mt_msg_id`,`mt_date`,`mt_title`, `mt_from_id`, `mt_to_name`, `mt_vid_folder`, `mt_owner_id`, `mt_owner_name`) VALUES " . $value_sql;
                         DB::query($insert_sql);
                         DB::query('UPDATE user SET total_pm = total_pm + 1 WHERE id IN(' . $update_sql . ')');
                     }
                 }
             }
         }
     } elseif ($usernames != '' || $start_date != '' || $end_date != '' || $is_active) {
         $where = 'WHERE is_active = 0 AND block_time <= ' . TIME_NOW;
         if ($usernames != '') {
             //theo danh sách tài khoản thành viên
             $usernames = str_replace(' ', '', $usernames);
             $usernames = str_replace('"', '', $usernames);
             $usernames = str_replace("'", '', $usernames);
             $usernames = str_replace(',', "','", $usernames);
             $where .= " AND user_name IN ('" . $usernames . "') ";
         } else {
             if ($is_active) {
                 // gửi cho thành viên chính thức
                 $where .= " AND level>0";
                 if ($start_date_a != '' && strtotime($start_date_a)) {
                     $where .= " AND create_time>=" . strtotime($start_date_a);
                 }
                 if ($end_date_a != '' && strtotime($end_date_a)) {
                     $where .= " AND create_time<" . strtotime($end_date_a);
                 }
             } else {
                 //theo ngay thang nam
                 if ($start_date != '' && strtotime($start_date)) {
                     $where .= " AND create_time>=" . strtotime($start_date);
                 }
                 if ($end_date != '' && strtotime($end_date)) {
                     $where .= " AND create_time<" . strtotime($end_date);
                 }
             }
         }
         $count_total_user = '******' . $where;
         // echo $count_total_user;
         // exit;
         $num_row = DB::fetch($count_total_user);
         $num_record = 1000;
         $num_query = ceil($num_row['total'] / $num_record);
         $new_row_msg = array('msg_date' => TIME_NOW, 'msg_post' => htmlspecialchars_decode(addslashes($content)), 'msg_sent_to_count' => $num_row['total'], 'msg_deleted_count' => 0, 'msg_author_id' => User::$current->data['id'], 'msg_author_name' => User::$current->data['user_name'], 'msg_ip_address' => AZLib::ip());
         if ($title && $content && $num_row['total'] > 0) {
             $msg_id = DB::insert('message_text', $new_row_msg);
             for ($j = 0; $j < $num_query; $j++) {
                 $value_sql = '';
                 $update_sql = '';
                 $user = array();
                 $sql = "SELECT id, user_name FROM user " . $where . " ORDER BY id DESC LIMIT " . $j * $num_record . "," . $num_record;
                 $re = DB::query($sql);
                 if ($re) {
                     while ($user = mysql_fetch_assoc($re)) {
                         $value_sql .= ($value_sql ? "," : "") . "('" . $msg_id . "','" . TIME_NOW . "','" . $title . "','" . User::id() . "','" . User::user_name() . "','inbox','" . $user['id'] . "','" . $user['user_name'] . "')";
                         $update_sql .= ($update_sql ? "," : "") . $user['id'];
                         User::getUser($user['id'], 0, 1);
                         $this->total_record++;
                     }
                     $insert_sql = "INSERT INTO `message_topics` (`mt_msg_id`,`mt_date`,`mt_title`, `mt_from_id`, `mt_to_name`, `mt_vid_folder`, `mt_owner_id`, `mt_owner_name`) VALUES " . $value_sql;
                     DB::query($insert_sql);
                     DB::query('UPDATE user SET total_pm = total_pm + 1 WHERE id IN(' . $update_sql . ')');
                 }
             }
         }
     }
     Url::redirect('send_multi', array('action' => 'send', 'total' => $this->total_record));
 }
Пример #7
0
//TuấnNK add (20080617_10h):
//Xử lý cập nhật lại category js:
require_once 'core/Debug.php';
//System Debug...
require_once 'core/config.php';
//System Config...
require_once ROOT_PATH . 'core/CGlobal.php';
require_once ROOT_PATH . 'core/DB.php';
//Khởi tạo các biến hệ thống:
global $server_list;
CGlobal::$my_server = $server_list;
unset($server_list);
if (MEMCACHE_ON) {
    require_once ROOT_PATH . 'core/AZMemcache.php';
}
require_once ROOT_PATH . 'core/AZLib.php';
require_once ROOT_PATH . 'core/AZArrCache.php';
require_once ROOT_PATH . 'core/System.php';
require_once ROOT_PATH . 'core/Url.php';
// Disable ALL magic_quote
set_magic_quotes_runtime(0);
register_shutdown_function(array("DB", "close"));
$cat_file = ROOT_PATH . "javascript/categories.js";
AZLib::getCats();
foreach (CGlobal::$allCategories as $cat) {
    $header_eb[] = array('id' => $cat['id'], 'pid' => $cat['parent_id'], 'name' => $cat['name'], 'path' => "c{$cat['id']}/" . ($cat['parent_id'] && isset(CGlobal::$allCategories[$cat['parent_id']]) ? CGlobal::$allCategories[$cat['parent_id']]['ebname'] . "-" : "") . $cat['ebname']);
}
$header_eb_str = "header_eb = " . json_encode($header_eb) . ";";
file_put_contents($cat_file, $header_eb_str);
echo $header_eb_str;
echo "<br /><br /><br />Done!";
Пример #8
0
 function on_submit()
 {
     $gfsubmit = Url::get("gfsubmit");
     if ($gfsubmit) {
         $fgroup_id = (int) implode(array_keys($gfsubmit));
         if ($fgroup_id) {
             $fgroup = DB::select("filter_group", "id={$fgroup_id}");
             if ($fgroup) {
                 $gf_name = Url::get('gf_name');
                 $gf_pos = Url::get('gf_pos');
                 if (isset($gf_name[$fgroup_id], $gf_pos[$fgroup_id]) && $gf_name[$fgroup_id] && $gf_pos[$fgroup_id]) {
                     $gf_name = $gf_name[$fgroup_id];
                     $gf_pos = $gf_pos[$fgroup_id];
                     if ($fgroup['name'] != $gf_name || $fgroup['pos'] != $gf_pos) {
                         $max_pos = (int) DB::fetch("SELECT max(pos) AS max_pos FROM filter_group", 'max_pos', 0);
                         if ($gf_pos > $max_pos) {
                             $gf_pos = $max_pos;
                         } elseif ($gf_pos <= 0) {
                             $gf_pos = $fgroup['pos'];
                         }
                         DB::update('filter_group', array("name" => $gf_name, "pos" => $gf_pos), "id={$fgroup_id}");
                         if (DB::select('filter_group', "pos={$gf_pos} AND id!={$fgroup_id}")) {
                             DB::query("UPDATE filter_group SET pos=pos+1 WHERE pos>={$gf_pos} AND pos<={$fgroup['pos']} AND id!={$fgroup_id}");
                         }
                         AZLib::getFilters(1);
                     }
                 }
             }
         }
         Url::redirect_current(array('cmd', 'id'));
     }
     $submit = Url::get("submit");
     if ($submit == "Thêm nhóm thuộc tính") {
         $gfilter_name = Url::get('gfilter_name');
         $gfilter_pos = Url::get('gfilter_pos');
         if ($gfilter_name != '' && $gfilter_pos) {
             $gfilter_group = array('name' => $gfilter_name, 'catids' => $this->cat['id'], 'pos' => $gfilter_pos);
             $max_pos = (int) DB::fetch("SELECT max(pos) AS max_pos FROM filter_group", 'max_pos', 0);
             if ($gfilter_pos > $max_pos || $gfilter_pos <= 0) {
                 $gfilter_pos = $max_pos + 1;
             }
             $gfilter_group['pos'] = $gfilter_pos;
             $id = DB::insert('filter_group', $gfilter_group);
             if ($id && DB::select('filter_group', 'pos="' . $gfilter_pos . '" AND id!=' . $id)) {
                 DB::query('UPDATE filter_group SET pos=pos+1 WHERE pos>=' . $gfilter_pos . ' AND id!=' . $id);
             }
         }
         AZLib::getFilters(1);
         Url::redirect_current(array('cmd', 'id'));
     }
     $name = Url::get('name');
     $brief_name = Url::get('brief_name');
     $keywords = Url::get('keywords');
     $description = Url::get('description');
     $parent_id = Url::get('parent_id');
     $zoneids = Url::get('zoneids');
     $ref_id = Url::get('ref_id');
     $status = Url::get('status', 'HIDE');
     $position = Url::get('position');
     $tag_search = Url::get('tag_search');
     $price_str = trim(Url::get('price_str'));
     $recomend = trim(Url::get('recomend'));
     if ($price_str) {
         function check_price_str($price)
         {
             return Url::cdouble(trim($price));
         }
         $price_ar = array_unique(array_map('check_price_str', explode(",", $price_str)));
         $price_str = '';
         if ($price_ar) {
             asort($price_ar);
             foreach ($price_ar as $price) {
                 if ($price > 0) {
                     $price_str .= ($price_str != '' ? ',' : '') . $price;
                 }
             }
         }
     }
     $this->checkFormInput('Tên Danh mục', 'name', $name, 'str', true, '', 1, 255);
     $this->checkFormInput('Tên vắn tắt', 'brief_name', $brief_name, 'str', false, '', 1, 255);
     //$this->checkFormInput('Từ khoá','keywords',$keywords,'str',false,'',0,20);
     $this->checkFormInput('Mô tả', 'description', $description, 'str', false, '', 0, 250);
     if (Url::get('cmd') == 'edit' && $this->cat['parent_id'] == 0 && $parent_id && DB::select("category", 'parent_id=' . $this->cat['id'])) {
         $this->setFormError("parent_id", 'Không thể chuyển "Danh mục có danh mục con" thành một "Danh mục con" của "Danh mục khác" được!');
     }
     if (!$this->errNum) {
         $new_row = array('name' => $name, 'brief_name' => $brief_name ? $brief_name : $name, 'keywords' => AZLib::word_limit($keywords, 20, ''), 'description' => $description, 'parent_id' => $parent_id, 'ref_id' => $ref_id, 'status' => $status, 'tag_search' => $tag_search, 'img_server' => IMAGE_SERVER_NO, 'price_str' => $price_str, 'recomend' => $recomend);
         if (Url::get('cmd') == 'edit') {
             if ($position > 0 && $position != $this->cat['position']) {
                 $max_pos = (int) DB::fetch("SELECT max(position) AS max_pos FROM category WHERE parent_id=" . $parent_id, 'max_pos');
                 if ($position > $max_pos) {
                     $position = $max_pos + 1;
                 }
                 $new_row['position'] = $position;
             } else {
                 $position = $this->cat['position'];
             }
             $id = $this->cat['id'];
             DB::update('category', $new_row, 'id=' . $this->cat['id']);
             /*if($this->cat['parent_id']==0 && $parent_id){
             			DB::update('category', array('parent_id'=>0),'parent_id='.$this->cat['parent_id']);
             		}*/
         } else {
             $max_pos = (int) DB::fetch("SELECT max(position) AS max_pos FROM category WHERE parent_id=" . $parent_id, 'max_pos');
             if ($position > $max_pos || $position == 0) {
                 $position = $max_pos + 1;
             }
             $new_row['position'] = $position;
             $id = DB::insert('category', $new_row);
         }
         if ($_FILES['cat_image']['tmp_name']) {
             if (Url::get('cmd') == 'edit') {
                 AZLib::ftp_image_delete_file('category/' . $this->cat['id'] . '.gif', $this->cat['img_server']);
             }
             /*if(AZLib::ftp_image_connect(IMAGE_SERVER_NO)){
             			if(!AZLib::ftp_check_dir('category/',true,IMAGE_SERVER_NO)){
             				break ;
             			}
             				
             			$file_name	='category/'.$id.'.gif';
             			$sourceName =$_FILES['cat_image']['tmp_name'];
             			AZLib::ftp_image_put_file($file_name,$sourceName,IMAGE_SERVER_NO);
             			//@fopen('http://'.IMAGE_PATH.'?del_cat=1',"r");
             		}*/
             if (AZLib::ftp_check_dir('category/', true, IMAGE_SERVER_NO)) {
                 $file_name = 'category/' . $id . '.gif';
                 $sourceName = $_FILES['cat_image']['tmp_name'];
                 AZLib::ftp_image_put_file($file_name, $sourceName, IMAGE_SERVER_NO);
                 //@fopen('http://'.IMAGE_PATH.'?del_cat=1',"r");
             }
         }
         if ($id && DB::select('category', 'position="' . $position . '" AND id!="' . $id . '" AND parent_id="' . $parent_id . '"')) {
             DB::query('UPDATE category SET position=position+1 WHERE position>=' . $position . ' AND position<=' . $this->cat['position'] . ' AND parent_id="' . $parent_id . '" AND id!=' . $id);
         }
         $all_zones = $this->zones;
         $sql_inset = "";
         if ($zoneids) {
             foreach ($zoneids as $zoneid) {
                 if (isset($all_zones[$zoneid])) {
                     unset($all_zones[$zoneid]);
                 } else {
                     $sql_inset .= ($sql_inset != '' ? ',' : '') . "({$zoneid},{$id})";
                 }
             }
         }
         if ($sql_inset) {
             $sql_inset = "INSERT INTO category_zone_cat (zoneid, catid) VALUES " . $sql_inset;
             DB::query($sql_inset);
         }
         if ($all_zones) {
             $zoneids = implode(",", array_keys($all_zones));
             if ($zoneids) {
                 DB::query("DELETE FROM category_zone_cat WHERE catid={$id} AND zoneid IN({$zoneids})");
             }
         }
         //AZLib::del_cache_zone_cat();
         AZLib::getCats(1, true);
         if (Url::get('cmd') == 'edit' && $this->cat['parent_id'] != $parent_id) {
             //đổi danh mục cha => cập nhật lại tin
             $catid = $this->cat['id'];
             $level_1 = 0;
             $level_2 = 0;
             if ($parent_id) {
                 if (CGlobal::$allCategories[$parent_id]['parent_id']) {
                     $level_1 = CGlobal::$allCategories[$parent_id]['parent_id'];
                     $level_2 = $parent_id;
                 } else {
                     $level_1 = $parent_id;
                     $level_2 = $catid;
                 }
             } else {
                 $level_1 = $catid;
                 $level_2 = 0;
             }
             DB::update("item", array("level_1_catid" => $level_1, "level_2_catid" => $level_2), "category_id={$catid}");
             if (MEMCACHE_ON) {
                 AZMemcache::clear();
             }
         }
         if ($this->cat) {
             Url::redirect_current();
         } else {
             Url::redirect_current(array('cmd'));
         }
     }
 }
Пример #9
0
 function draw()
 {
     AZLib::getCats();
     global $display;
     $this->beginForm();
     $page_arr = array();
     $page_arr['home'] = 'Trang chủ';
     $page_arr['list_detail'] = 'Danh sách sản phẩm';
     $page_arr['profile'] = 'Profile thành viên';
     $page_arr['sign_in'] = 'Đăng nhập';
     $page_arr['item_detail'] = 'Chi tiết sản phẩm';
     $page_arr['online'] = 'Thành viên online';
     $page_arr['message'] = 'Tin nhắn cá nhân';
     $page_arr['post_item'] = 'Đăng sản phẩm';
     $page_arr['personal'] = 'Trang cá nhân';
     $page_arr['edit_page'] = 'Cấu hình page';
     $page_arr['admin'] = 'Trang quản trị';
     $page_arr['user'] = '******';
     $page_arr['manage_item'] = 'Quản trị Tin';
     $page_arr['manage_image'] = 'Quản trị Ảnh';
     $page_arr['manage_comment'] = 'Quản Comment';
     $page_arr['manage_comment_user'] = '******';
     $page_arr['manage_bad_content'] = 'Quản trị tin xấu';
     $page_arr['manage_badword'] = 'Quản trị Từ xấu';
     $page_arr['partner'] = 'Quản trị Đối tác, ADV';
     $page_arr['send_multi'] = 'Gửi tin nhắn cho tất cả Thành viên';
     $page_arr['page'] = 'Quản trị Page';
     $page_arr['module'] = 'Quản trị Modules';
     $page_arr['shop'] = 'Trang cá nhân';
     $page_arr['sph_search '] = 'Tìm kiếm';
     $not_permit_view = array('edit_page', 'admin', 'user', 'manage_item', 'manage_comment', 'manage_image', 'manage_comment', 'manage_comment_user', 'manage_bad_content', 'manage_badword', 'partner', 'send_multi', 'page', 'module');
     $cond = '';
     $item_type = Url::get('item_type');
     $item_id = Url::get('item_id');
     $o_name = Url::get('o_name');
     $o_id = (int) Url::get('o_id');
     $where = 'site';
     if ($item_type && $item_id && in_array($item_type, array(1, 2, 3))) {
         $cond = ' AND page="ItemDetail" AND item_id=' . $item_id . ' AND item_type=' . $item_type;
         if ($item_type == 3) {
             $where = '<font color=red>Sản phẩm đấu giá</font>';
         } elseif ($item_type == 1) {
             $where = '<font color=red>Giao dịch mua</font>';
         } else {
             $where = '<font color=red>Sản phẩm  bán</font>';
         }
     }
     if ($o_name != '') {
         $str_search = str_replace("'", '"', $o_name);
         $str_search = str_replace("&#39;", '"', $str_search);
         $str_search = str_replace("&quot;", '"', $str_search);
         $cond .= ' AND session_referer LIKE "%' . $str_search . '%"';
     }
     if ($o_id) {
         $cond .= ' AND user_id =' . $o_id;
     } else {
         $o_id = '';
     }
     $open_id_login = (int) Url::get('open_id_login', 0);
     if ($open_id_login) {
         $display->add('open_id_login_check', 'checked="checked"');
         $cond .= " AND login_type = 1 ";
     } else {
         $display->add('open_id_login_check', '');
     }
     $display->add('o_name', $o_name);
     $display->add('o_id', $o_id);
     $total_ss = DB::fetch('SELECT count(*) as total_ss FROM ' . _SESS_TABLE, 'total_ss', 0);
     $display->add('total_ss', $total_ss);
     $total = DB::fetch('SELECT count(*) as total FROM ' . _SESS_TABLE . ' WHERE session_expires >' . (TIME_NOW - 900) . ' ' . $cond);
     if ($total) {
         $total = (int) $total['total'];
     } else {
         $total = 0;
     }
     $sql = 'SELECT count(total) as total FROM ( SELECT count(user_id) as total FROM ' . _SESS_TABLE . ' WHERE session_expires >' . (TIME_NOW - 900) . ' AND user_id !=0 ' . $cond . ' GROUP BY user_id) as t';
     $total_mem = DB::fetch($sql, 'total');
     $paging = AZPagging::paging($limit, $total_mem, 25, 10, 'page_view');
     DB::query('SELECT session_id, session_expires as time, session_ip as ip, user_id, user_name, session_referer, page, category_id, item_type, item_id, open_id FROM ' . _SESS_TABLE . ' WHERE session_expires >' . (TIME_NOW - 900) . ' AND user_id>0 ' . $cond . ' GROUP BY user_id  ORDER BY time DESC' . $limit);
     $user_onlines = array();
     $i = 1;
     while ($item = DB::fetch_row()) {
         //$item['viewing_time'] = AZLib::duration(TIME_NOW-$item['time']);
         if (date('d', TIME_NOW) != date('d', $item['time'])) {
             $item['viewing_time'] = date('H:i d/m/y', $item['time']);
         } else {
             $item['viewing_time'] = date('H:i', $item['time']);
         }
         $item['user_name'] = stripslashes($item['user_name']);
         $item['title'] = 'Thành viên';
         $item['link'] = WEB_DIR . $item['user_name'];
         if (isset($page_arr[$item['page']]) && (User::is_admin() || !in_array($item['page'], $not_permit_view))) {
             $detail = '';
             if ($item['page'] == 'list_detail' && isset(CGlobal::$allCategories[$item['category_id']])) {
                 $detail = ' - ' . stripslashes(CGlobal::$allCategories[$item['category_id']]['name']);
                 $parent_id = CGlobal::$allCategories[$item['category_id']]['parent_id'];
                 if ($parent_id && isset(CGlobal::$allCategories[$parent_id])) {
                     $detail = ' - ' . stripslashes(CGlobal::$allCategories[$parent_id]['name']) . $detail;
                 }
             }
             $item['viewing_page_name'] = $page_arr[$item['page']] . $detail;
         } elseif ($item['page'] && (User::is_admin() || !in_array($item['page'], $not_permit_view))) {
             $item['viewing_page_name'] = $item['page'];
         } else {
             $item['viewing_page_name'] = 'enbac.com';
         }
         if (!$item['session_referer'] || !User::is_admin() && in_array($item['page'], $not_permit_view)) {
             $item['viewing_page_url'] = WEB_ROOT;
         } else {
             $item['viewing_page_url'] = WEB_ROOT . stripslashes($item['session_referer']);
         }
         if (User::is_admin() && $item['ip']) {
             $ip_arr = explode('::', $item['ip']);
             $item['ip'] = 'S_IP: <b>' . $ip_arr[0] . '</b>';
             $item['ip'] .= ' - C_IP: <b>' . $ip_arr[1] . '</b>';
         } else {
             $item['ip'] = '';
         }
         if (User::is_admin()) {
             $item['del_s'] = '<a href="' . Url::build_current(array('kick_out' => $item['session_id'])) . '">Kick Out</a>';
         } else {
             $item['del_s'] = '';
         }
         $user_onlines[$i++] = $item;
     }
     $display->add('where', $where);
     $display->add('total', $total);
     $display->add('total_mem', $total_mem);
     $display->add('user_onlines', $user_onlines);
     $display->add('paging', $paging);
     $total_guest = 0;
     $paging_guest = '';
     $guest_onlines = array();
     if (User::is_admin()) {
         $sql = 'SELECT  count(*) as total FROM 	' . _SESS_TABLE . ' WHERE session_expires >' . (TIME_NOW - 900) . ' AND user_id=0 ' . $cond . ' ';
         $total_guest = DB::fetch($sql, 'total');
         $paging_guest = AZPagging::paging($limit, $total_guest, 25, 10, 'guest_view');
         DB::query('SELECT session_id, session_expires as time, session_ip as ip, session_referer, page, category_id, item_type, item_id FROM ' . _SESS_TABLE . ' WHERE session_expires >' . (TIME_NOW - 900) . ' AND user_id=0 ' . $cond . ' ORDER BY time DESC' . $limit);
         $i = 1;
         while ($item = DB::fetch_row()) {
             //$item['viewing_time'] = AZLib::duration(TIME_NOW-$item['time']);
             if (date('d', TIME_NOW) != date('d', $item['time'])) {
                 $item['viewing_time'] = date('H:i d/m/y', $item['time']);
             } else {
                 $item['viewing_time'] = date('H:i', $item['time']);
             }
             $item['user_name'] = '<font color="green">guest</font>';
             $item['viewing_page_url'] = WEB_ROOT;
             $item['link'] = WEB_ROOT;
             if (isset($page_arr[$item['page']]) && (User::is_admin() || !in_array($item['page'], $not_permit_view))) {
                 $detail = '';
                 if ($item['page'] == 'list_detail' && isset(CGlobal::$allCategories[$item['category_id']])) {
                     $detail = ' - ' . stripslashes(CGlobal::$allCategories[$item['category_id']]['name']);
                     $parent_id = CGlobal::$allCategories[$item['category_id']]['parent_id'];
                     if ($parent_id && isset(CGlobal::$allCategories[$parent_id])) {
                         $detail = ' - ' . stripslashes(CGlobal::$allCategories[$parent_id]['name']) . $detail;
                     }
                 }
                 $item['viewing_page_name'] = $page_arr[$item['page']] . $detail;
             } elseif ($item['page'] && (User::is_admin() || !in_array($item['page'], $not_permit_view))) {
                 $item['viewing_page_name'] = $item['page'];
             } else {
                 $item['viewing_page_name'] = 'enbac.com';
             }
             if (!$item['session_referer'] || !User::is_admin() && in_array($item['page'], $not_permit_view)) {
                 $item['viewing_page_url'] = WEB_ROOT;
             } else {
                 $item['viewing_page_url'] = WEB_ROOT . stripslashes($item['session_referer']);
             }
             if (User::is_admin() && $item['ip']) {
                 $ip_arr = explode('::', $item['ip']);
                 $item['ip'] = 'S_IP: <b>' . $ip_arr[0] . '</b>';
                 $item['ip'] .= ' - C_IP: <b>' . $ip_arr[1] . '</b>';
             } else {
                 $item['ip'] = '';
             }
             if (User::is_admin()) {
                 $item['del_s'] = '<a href="' . Url::build_current(array('kick_out' => $item['session_id'])) . '">Kick Out</a>';
             } else {
                 $item['del_s'] = '';
             }
             $guest_onlines[$i++] = $item;
         }
     }
     $display->add('total_guest', $total_guest);
     $display->add('guest_onlines', $guest_onlines);
     $display->add('paging_guest', $paging_guest);
     $display->output('OnlineUser');
     $this->endForm();
 }
Пример #10
0
 function draw()
 {
     global $display;
     AZLib::getCats();
     $display->add('msg', $this->showFormErrorMessages(1));
     $display->add('msgs', $this->showFormSuccesMessages(1));
     $this->beginForm(true, 'post', false, Url::build_current());
     $display->output('ImportExcel');
     $this->endForm();
 }
Пример #11
0
 function draw()
 {
     $this->beginForm();
     global $display;
     AZLib::getCats();
     $acc_groups = CGlobal::$group;
     $user_permits = array();
     $user_cats = array();
     $all_users = array();
     $allist_users = array();
     $gids = '';
     foreach ($acc_groups as $group) {
         $acc_groups[$group['id']]['users'] = array();
         $acc_groups[$group['id']]['pids'] = array();
         $acc_groups[$group['id']]['pid_str'] = '';
         if (!in_array($group['id'], array(1, 9))) {
             $gids .= ($gids ? ',' : '') . $group['id'];
         }
     }
     if ($gids) {
         //			$sql = "SELECT pids,ref_id FROM user_permit WHERE ref_id IN(".$gids.") AND type=0";//lấy quyền của nhóm
         $sql = "SELECT type, ref_id, pids, cids FROM user_permit";
         //lấy quyền của nhóm
         $result = DB::query($sql);
         if ($result) {
             while ($row = mysql_fetch_assoc($result)) {
                 if ($row['type'] == 0) {
                     //group
                     $acc_groups[$row['ref_id']]['pid_str'] .= ($acc_groups[$row['ref_id']]['pid_str'] ? '|' : '') . $row['pids'];
                     $pids = explode('|', $row['pids']);
                     $acc_groups[$row['ref_id']]['pids'] = array();
                     foreach ($pids as $pid) {
                         $acc_groups[$row['ref_id']]['pids'][$pid] = CGlobal::$permit[$pid];
                     }
                 } else {
                     //user
                     $user_permits[$row['ref_id']] = $row['pids'];
                     $user_cats[$row['ref_id']] = $row['cids'];
                 }
             }
         }
     }
     $sql = 'SELECT id, user_name, full_name, gids FROM user AS a WHERE a.gids!="0"';
     $result = DB::query($sql);
     if ($result) {
         while ($row = mysql_fetch_assoc($result)) {
             $row['full_name'] = AZLib::trimSpace($row['full_name']);
             $all_users[$row['id']] = $row;
             $row['pid_str'] = isset($user_permits[$row['id']]) ? $user_permits[$row['id']] : '';
             $row['cid_str'] = isset($user_cats[$row['id']]) ? $user_cats[$row['id']] : '';
             $groups = explode('|', $row['gids']);
             foreach ($groups as $gid) {
                 if (isset($acc_groups[$gid])) {
                     if (!User::is_root() && $gid == 9) {
                         $row['del_enable'] = 0;
                     } else {
                         $row['del_enable'] = 1;
                     }
                     $acc_groups[$gid]['users'][] = $row;
                 }
             }
             $pid_str = isset($user_permits[$row['id']]) ? $user_permits[$row['id']] : '';
             $cid_str = isset($user_cats[$row['id']]) ? $user_cats[$row['id']] : '';
             $pid_arr = explode('|', $pid_str);
             $cid_arr = explode(',', $cid_str);
             $row['pids'] = array();
             $row['cids'] = array();
             if ($pid_arr) {
                 foreach ($pid_arr as $pid) {
                     if (isset(CGlobal::$permit[$pid])) {
                         $row['pids'][$pid] = CGlobal::$permit[$pid];
                     }
                 }
             }
             if ($pid_arr) {
                 foreach ($cid_arr as $cid) {
                     if (isset(CGlobal::$allCategories[$cid])) {
                         $row['cids'][$cid] = CGlobal::$allCategories[$cid];
                     }
                 }
             }
             if ($row['pids'] || $row['cids']) {
                 $allist_users[$row['id']] = $row;
             }
         }
     }
     $display->add('acc_groups', $acc_groups);
     $display->add('all_users', json_encode($all_users));
     $display->add('allist_users', $allist_users);
     $all_groups = CGlobal::$group;
     if (!User::is_root()) {
         unset($all_groups[9]);
     }
     $display->add('all_groups', json_encode($all_groups));
     $display->add('all_permits', json_encode(CGlobal::$permit));
     $display->output('ListAdmin');
     $this->endForm();
 }
Пример #12
0
    function fn_lock_topic()
    {
        if (!User::is_login()) {
            echo "no_perm";
            exit;
        }
        if (!User::have_permit(ADMIN_ITEM) && !User::is_mod()) {
            echo "no_perm";
            exit;
        }
        $id = (int) Url::get('id', 0);
        $type = AZLib::getParam('type');
        $reason_lock = AZLib::getParam('reason_lock');
        $value = $type == 'lock' ? 1 : 0;
        if ($id > 0) {
            $item = Item::get_item($id);
            $item_memcache = $item;
            if ($item) {
                if (!User::have_permit(ADMIN_ITEM) && !User::have_cat_permit($item['category_id'])) {
                    echo "no_perm";
                    exit;
                }
                DB::query("UPDATE item SET state={$value}, valid_time = " . TIME_NOW . ", valid_user = '******', up_time = " . ($item["up_time"] - TIME_DOWN) . " WHERE id=" . $id);
                if (MEMCACHE_ON) {
                    $item_memcache['state'] = $value;
                    $item_memcache['valid_time'] = TIME_NOW;
                    $item_memcache['valid_user'] = User::user_name();
                    AZMemcache::do_put("item:{$id}", $item_memcache);
                }
                if ($type == 'lock') {
                    AZLib::getCats();
                    $link_help = 'http://help.enbac.com/index.php/Quy_%C4%91%E1%BB%8Bnh_%C4%91%C4%83ng_tin';
                    if (CGlobal::$allCategories[$item['category_id']]['link_help']) {
                        $link_help = CGlobal::$allCategories[$item['category_id']]['link_help'];
                    } elseif (isset(CGlobal::$allCategories[$item['category_id']]['parent_id']) && CGlobal::$allCategories[CGlobal::$allCategories[$item['category_id']]['parent_id']]['link_help']) {
                        $link_help = CGlobal::$allCategories[CGlobal::$allCategories[$item['category_id']]['parent_id']]['link_help'];
                    }
                    $receiver_user = DB::select('user', 'id = ' . $item["user_id"]);
                    $title_pm = 'Thông báo từ EnBac';
                    $content_pm = 'Tin [url=' . WEB_ROOT . AZRewrite::formatUrl('?page=item_detail&id=' . $id . '&ebname=' . AZLib::safe_title($item['name'])) . ']' . $item['name'] . '[/url] của bạn đã bị khóa với lý do: ' . $reason_lock . '
					
					Bạn click [url=' . $link_help . '][b]vào đây[/b][/url] để xem quy định đăng tin! Hoặc [url=http://blog.enbac.com/?p=28] [b]vào đây[/b][/url] để xem hướng dẫn đăng tin. 
					
					Ban quản trị Én bạc.
					
					Vui lòng không trả lời tin nhắn này!';
                    AZLib::Send_pm(User::id(), User::user_name(), $receiver_user, $title_pm, $content_pm, true);
                    $item_array = array('item_id' => $id, 'user_id' => User::id(), 'user_name' => User::user_name(), 'lock_time' => TIME_NOW, 'reason_lock' => $reason_lock);
                    DB::insert('item_lock', $item_array);
                } elseif ($type == 'unlock') {
                    DB::delete('item_lock', 'item_id=' . $id);
                }
                echo $type;
                exit;
            } else {
                echo "unsuccess";
                exit;
            }
        } else {
            echo "unsuccess";
            exit;
        }
    }
Пример #13
0
 function on_submit()
 {
     AZLib::getCats();
     $sku = AZLib::trimSpace(str_replace("\n", " ", Url::get('sku')));
     ###############################################################################################
     $name = AZLib::trimSpace(str_replace("\n", " ", Url::get('name')));
     mb_internal_encoding("UTF-8");
     $name = mb_strtoupper(mb_substr($name, 0, 1)) . mb_substr($name, 1);
     ###############################################################################################
     ###############################################################################################
     $offer = AZLib::trimSpace(str_replace("\n", " ", Url::get('offer')));
     mb_internal_encoding("UTF-8");
     $offer = mb_strtoupper(mb_substr($offer, 0, 1)) . mb_substr($offer, 1);
     ###############################################################################################
     ###############################################################################################
     $list_brief = AZLib::trimSpace(str_replace("\n", " ", Url::get('list_brief')));
     mb_internal_encoding("UTF-8");
     $list_brief = mb_strtoupper(mb_substr($list_brief, 0, 1)) . mb_substr($list_brief, 1);
     ###############################################################################################
     ###############################################################################################
     //$item_description 	= AZLib::getParam('item_description');
     $item_description = Url::get('item_description');
     $brief = Url::get('brief');
     if (get_magic_quotes_gpc()) {
         $item_description = stripslashes($item_description);
         $brief = stripslashes($brief);
     }
     require_once ROOT_PATH . 'includes/htmLawed.php';
     $config = array('safe' => 1, 'elements' => '*', 'deny_attribute' => 'class, id');
     $spec = 'a = title, href;';
     // The 'a' element can have only these attributes
     $item_description = htmLawed($item_description, $config, $spec);
     $item_description = AZLib::clean_value($item_description);
     $brief = htmLawed($brief, $config, $spec);
     $brief = AZLib::clean_value($brief);
     ###############################################################################################
     $category_id = 0;
     $level_1_catid = 0;
     $first_combo = (int) Url::get('first_combo');
     $second_combo = (int) Url::get('second_combo');
     $price = Url::cdouble(Url::get('price'));
     $price_out = Url::cdouble(Url::get('price_out'));
     $currency_id = (int) Url::get('currency_id', 1);
     $quantity = Url::cdouble(Url::get('quantity', 0));
     if ($quantity < 0) {
         $quantity = 0;
     }
     $item_order = (int) Url::get('item_order');
     $made_in = Url::get('made_in');
     $warranty = Url::get('warranty');
     if (!isset(CGlobal::$currency[$currency_id])) {
         $currency_id = 1;
     }
     $item_category = false;
     if ($first_combo && $second_combo) {
         $category_id = $second_combo;
         $level_1_catid = $first_combo;
         $level_2_catid = $second_combo;
         if (isset(CGlobal::$allCategories[$category_id])) {
             //Kiểm tra sự tồn tai của danh mục
             $item_category = CGlobal::$allCategories[$category_id];
             if (isset(CGlobal::$subCategories[$category_id]) && CGlobal::$subCategories[$category_id] && $item_category['parent_id'] == 0 || $item_category['parent_id'] != $first_combo) {
                 //Nếu danh mục của sản phẩm là danh mục cấp 1 và có danh mục con => chọn lại
                 $this->setFormError('category_id', 'Hãy chọn lại <b>Chủng loại</b> cho sản phẩm!');
             }
         }
     } elseif ($first_combo) {
         //Nếu chọn danh mục cấp 1
         $category_id = $first_combo;
         $level_1_catid = $first_combo;
         $level_2_catid = $first_combo;
         if (isset(CGlobal::$allCategories[$category_id])) {
             //Kiểm tra sự tồn tai của danh mục
             $item_category = CGlobal::$allCategories[$category_id];
             if (isset(CGlobal::$subCategories[$category_id]) && CGlobal::$subCategories[$category_id] && $item_category['parent_id'] == 0) {
                 //Nếu danh mục có danh mục con => Chọn lại!
                 $this->setFormError('category_id', 'Hãy chọn lại <b>Chủng loại</b> cho sản phẩm!');
             } elseif ($item_category['parent_id'] != 0) {
                 //Nếu không fải là danh mục cấp 1
                 $this->setFormError('category_id', 'Hãy chọn lại <b>Chủng loại</b> cho sản phẩm!');
             }
         }
     }
     if (!$item_category) {
         $this->setFormError('category_id', 'Bạn chưa chọn <b>Danh mục</b> cho sản phẩm!');
     }
     /*if($price<=0)
     		{
     			$this->setFormError('price','Với tin rao bán bạn phải nhập <b>Giá</b>');	
     		}
     		else*/
     if ($price > 0) {
         if ($currency_id == 1) {
             $this->checkFormInput("Giá bán", 'price', $price, 'double', false, '', 1, 50000000000);
         } else {
             $this->checkFormInput("Giá bán", 'price', $price, 'double', false, '', 1, 1000000);
         }
     }
     if ($price_out != '' && $price_out != '0') {
         if ($currency_id == 1) {
             $this->checkFormInput("Giá thị trường", 'price_out', $price_out, 'double', false, '', 1, 50000000000);
         } else {
             $this->checkFormInput("Giá thị trường", 'price_out', $price_out, 'double', false, '', 1, 1000000);
         }
     }
     $this->checkFormInput('Tên sản phẩm', 'name', $name, 'str', true, '', 5, 120);
     $this->checkFormInput('Mô tả vắn tắt', 'brief', $brief, 'str', false, '', 15, 500000);
     $this->checkFormInput('Mô tả sản phẩm', 'item_description', $item_description, 'str', true, '', 15, 500000);
     //Check kiểm duyệt
     $status = 1;
     //Cho hiển thị
     $user_item = User::getUser($this->item['user_id']);
     $status = $this->item['status'];
     //Giữ nguyên giá trị
     $have_image_up = false;
     foreach ($this->item_images as $page => $page_images) {
         //trang
         foreach ($page_images as $image) {
             if ($image['img_new_id'] || $image['id']) {
                 $have_image_up = true;
                 break;
             }
         }
     }
     $form_img_server = Url::get('avatar_img_server', 0);
     $this->img_url = Url::get('avatar_img_url', '');
     if (!$this->errNum) {
         $id = $this->item['id'];
         $item_array = array('category_id' => $category_id, 'level_1_catid' => $level_1_catid, 'level_2_catid' => $level_2_catid, 'currency_id' => $currency_id, 'price' => $price, 'price_out' => $price_out, 'sku' => $sku, 'name' => $name, 'offer' => $offer, 'list_brief' => $list_brief, 'brief' => $brief, 'description' => $item_description, 'status' => $status, 'quantity' => $quantity, 'item_order' => $item_order, 'made_in' => $made_in, 'warranty' => $warranty, 'modify_time' => TIME_NOW, 'modify_user_name' => User::user_name(), 'have_image' => (int) (bool) $this->img_url, 'img_server' => $form_img_server, 'img_url' => $this->img_url);
         /*DB::update('item',$item_array,'id='.$id);
         
         			if(MEMCACHE_ON){
         				AZMemcache::do_remove("item:$id");
         			}*/
         $image_err = false;
         //$img_url				='';
         $item_images = array();
         $item_check_images = array();
         $item_insert_temp_images = array();
         $item_insert_images = array();
         $item_update_images = array();
         $item_delete_ids = '';
         $unused_ids = '';
         $img_ids = '';
         $item_have_image = 0;
         //$pos=0;
         foreach ($this->item_images as $page => $page_images) {
             //10 trang
             foreach ($page_images as $image) {
                 if ($image['img_new_id']) {
                     //nếu chọn hoặc thay ảnh mới
                     $item_have_image = 1;
                     $img = array();
                     $title = $image['title'] && $image['title'] != 'Ghi chú ảnh' ? $image['title'] : '';
                     $title = str_replace(array('"'), array('&quot;'), stripslashes($title));
                     $title = $title && !AZLib::checkBadWord($title) ? $title : '';
                     if (isset($this->images[$image['img_new_id']])) {
                         //Nếu chọn mới hoặc thay 1 ảnh đã có
                         if ($this->images[$image['img_new_id']]['position'] == $image['stt']) {
                             //lấy lại chính ảnh cũ
                             if ($title != $this->images[$image['img_new_id']]['title']) {
                                 //Nếu Tên sản phẩm ảnh thay đổi thì cập nhật Tên sản phẩm cho ảnh!
                                 $this->images[$image['img_new_id']]['title'] = addslashes($title);
                                 $item_update_images[$image['img_new_id']] = $this->images[$image['img_new_id']];
                             }
                         } else {
                             //Nếu ảnh được chọn lại ở vị trí khác
                             $img['title'] = addslashes($title);
                             $img['item_id'] = $id;
                             $img['img_server'] = $this->images[$image['img_new_id']]['img_server'];
                             $img['img_url'] = $this->images[$image['img_new_id']]['img_url'];
                             $img['root_id'] = $this->images[$image['img_new_id']]['root_id'];
                             $img['time'] = $this->images[$image['img_new_id']]['time'];
                             $img['user_id'] = $this->images[$image['img_new_id']]['user_id'];
                             $img['user_name'] = $this->images[$image['img_new_id']]['user_name'];
                             $img['item_id'] = $id;
                             $img['position'] = $image['stt'];
                             if ($image['img_del_id'] && isset($this->images[$image['img_del_id']])) {
                                 //Loại bỏ ảnh cũ
                                 if ($this->images[$image['img_del_id']]['root_id']) {
                                     $item_delete_ids .= ($item_delete_ids ? ',' : '') . (int) $image['img_del_id'];
                                 } else {
                                     $unused_ids .= ($unused_ids ? ',' : '') . (int) $image['img_del_id'];
                                 }
                             }
                             if (!$img['root_id']) {
                                 $img['root_id'] = $image['img_new_id'];
                             }
                             $item_insert_images[$image['img_new_id']] = $img;
                         }
                     } else {
                         $img_ids .= ($img_ids ? ',' : '') . $image['img_new_id'];
                         $img['title'] = addslashes($title);
                         $img['item_id'] = $id;
                         $img['img_server'] = $image['img_server'];
                         $img['img_url'] = '';
                         $img['root_id'] = 0;
                         $img['time'] = TIME_NOW;
                         $img['user_id'] = $this->item['user_id'];
                         $img['user_name'] = $this->item['user_name'];
                         $img['item_id'] = $id;
                         $img['position'] = $image['stt'];
                         if ($image['img_del_id'] && isset($this->images[$image['img_del_id']])) {
                             //Loại bỏ ảnh cũ
                             if ($this->images[$image['img_del_id']]['root_id']) {
                                 $item_delete_ids .= ($item_delete_ids ? ',' : '') . (int) $image['img_del_id'];
                             } else {
                                 $unused_ids .= ($unused_ids ? ',' : '') . (int) $image['img_del_id'];
                             }
                         }
                         if (!isset($item_images[$image['img_new_id']])) {
                             $item_images[$image['img_new_id']] = $img;
                         } else {
                             $img['root_id'] = $image['img_new_id'];
                             $item_insert_temp_images[$image['img_new_id']] = $img;
                             //Đúp bản ghi trong trường hợp 1 ảnh được chọn tại nhiều vị trí
                         }
                     }
                 } elseif ($image['id'] && $image['id'] == $_POST['image_deleted'][$image['stt']]) {
                     //Loại bỏ ảnh
                     if ($this->images[$image['id']]['root_id']) {
                         $item_delete_ids .= ($item_delete_ids ? ',' : '') . (int) $image['id'];
                     } else {
                         $unused_ids .= ($unused_ids ? ',' : '') . (int) $image['id'];
                     }
                 } elseif ($image['id'] && $_POST['image_title'][$image['stt']]) {
                     $item_have_image = 1;
                     $title = $_POST['image_title'][$image['stt']] != 'Ghi chú ảnh' ? $_POST['image_title'][$image['stt']] : '';
                     $title = str_replace(array('"'), array('&quot;'), stripslashes($title));
                     $title = $title && !AZLib::checkBadWord($title) ? $title : '';
                     if ($title != $this->images[$image['id']]['title']) {
                         //Nếu Tên sản phẩm ảnh thay đổi thì cập nhật Tên sản phẩm cho ảnh!
                         $this->images[$image['id']]['title'] = addslashes($title);
                         $item_update_images[$image['id']] = $this->images[$image['id']];
                     }
                 } else {
                     $item_have_image = 1;
                 }
             }
         }
         if ($img_ids) {
             //$re=DB::query('SELECT id, item_id, img_server, img_url, time FROM item_image WHERE id IN('.$img_ids.') AND user_id='.$this->item['user_id']);
             $re = DB::query('SELECT id, item_id, user_id, img_server, img_url, time FROM item_image WHERE id IN(' . $img_ids . ')');
             if ($re) {
                 while ($img = mysql_fetch_assoc($re)) {
                     if ($img['user_id'] == $this->item['user_id']) {
                         if (isset($item_insert_temp_images[$img['id']])) {
                             $item_insert_temp_images[$img['id']]['img_server'] = $img['img_server'];
                             $item_insert_temp_images[$img['id']]['img_url'] = $img['img_url'];
                             $item_insert_temp_images[$img['id']]['root_id'] = $img['id'];
                             $item_insert_temp_images[$img['id']]['time'] = $img['time'];
                             $item_insert_images[] = $item_insert_temp_images[$img['id']];
                         }
                         $item_images[$img['id']]['time'] = $img['time'];
                         $item_images[$img['id']]['img_url'] = $img['img_url'];
                         if ($img['item_id']) {
                             //Đã có item_id rồi, đúp bản ghi
                             $image = $item_images[$img['id']];
                             if ($img['root_id']) {
                                 $image['root_id'] = $img['root_id'];
                             } else {
                                 $image['root_id'] = $img['id'];
                             }
                             $item_insert_images[] = $image;
                         } else {
                             //Chưa có item_id, cập nhật
                             $img['item_id'] = $id;
                             $item_update_images[$img['id']] = $item_images[$img['id']];
                         }
                     }
                 }
             }
         }
         if ($item_insert_images) {
             $inser_sql = '';
             foreach ($item_insert_images as $item_image) {
                 $inser_sql .= ($inser_sql ? "," : "") . "\r\n\t\t\t\t\t\t('" . addslashes($item_image['title']) . "',\r\n\t\t\t\t\t\t'" . $item_image['position'] . "','" . $item_image['item_id'] . "','" . $item_image['img_server'] . "','" . $item_image['img_url'] . "','" . $item_image['root_id'] . "',\r\n\t\t\t\t\t\t'" . $item_image['time'] . "','" . $item_image['user_id'] . "','" . $item_image['user_name'] . "')";
             }
             $inser_sql = "INSERT INTO `item_image` (`title`,`position`,`item_id`,`img_server`,`img_url`,`root_id`,`time`,`user_id`,`user_name`) \r\n\t\t\t\t\t\t\tVALUES " . $inser_sql;
             DB::query($inser_sql);
         }
         if ($item_update_images) {
             foreach ($item_update_images as $img_id => $item_image) {
                 if (!DB::update('item_image', $item_image, 'id=' . $img_id)) {
                     $image_err = true;
                 }
             }
         }
         //if($item_delete_ids && !DB::delete('item_image','id IN('.$item_delete_ids.') AND user_id='.$this->item['user_id'].' AND root_id!=0')){
         if ($item_delete_ids && !DB::delete('item_image', 'id IN(' . $item_delete_ids . ') AND root_id!=0')) {
             $image_err = true;
         }
         if ($unused_ids && !DB::update('item_image', array('item_id' => '0', 'title' => '', 'position' => '0'), 'id IN(' . $unused_ids . ') AND user_id=' . $this->item['user_id'] . ' AND root_id=0')) {
             $image_err = true;
         }
         //$main_img = DB::select('item_image','item_id='.$id.' AND user_id='.$this->item['user_id'].' ORDER BY position ASC');
         $main_img = DB::select('item_image', 'item_id=' . $id . ' ORDER BY position ASC');
         if ($main_img) {
             $img_url = $main_img['img_url'];
             $i_server = $main_img['img_server'];
         } else {
             $img_url = '';
             $i_server = 0;
         }
         if ($item_insert_images || $item_update_images || $item_delete_ids || $unused_ids) {
             Item::get_item_images($id, 1);
         }
         //tuannk 2010.07.26
         //end tuannk 2010.07.26
         /*if($this->img_url == '' && $img_url !='' )
         		{
         			DB::update('item',array( 'img_server'=>$i_server, 'img_url'=>$img_url,'have_image'=>1),'id='.$id);
         		}
         		elseif($item_have_image){
         			DB::update('item',array( 'have_image'=>1),'id='.$id);
         		}*/
         ##############################################################################
         #Filters
         $filters = Url::get('filter');
         $filter_search = "";
         $filter_ids = "";
         foreach ($filters as $fgid => $fils) {
             foreach ($fils as $fid) {
                 $filter_search .= ($filter_search != '' ? " " : '') . "g{$fgid}f{$fid}f";
                 $filter_ids .= ($filter_ids != '' ? "," : '') . $fid;
             }
         }
         #Filters
         ##############################################################################
         $item_array['filter_search'] = $filter_search;
         $item_array['filter_ids'] = $filter_ids;
         if ($this->img_url == '' && $img_url != '') {
             $item_array['img_server'] = $i_server;
             $item_array['img_url'] = $img_url;
             $item_array['have_image'] = 1;
         } elseif ($item_have_image) {
             $item_array['have_image'] = 1;
         }
         //DB::update('item',array( 'have_image'=>1),'id='.$id);
         DB::update('item', $item_array, 'id=' . $id);
         if (MEMCACHE_ON) {
             AZMemcache::do_remove("item:{$id}");
         }
         if (Url::get('ref')) {
             Url::redirect("manage_item");
         } else {
             Url::redirect("item_detail", array("id" => $id));
         }
     }
 }
Пример #14
0
 function getOtionCats($mod_cat_id = 0)
 {
     AZLib::getCats();
     foreach (CGlobal::$allCategories as $cat) {
         if ($mod_cat_id) {
             $arr_mod_cat_id = split(",", $mod_cat_id);
             if ($cat['parent_id'] && in_array($cat['id'], $arr_mod_cat_id)) {
                 $subCategories[$cat['parent_id']][$cat['id']] = $cat;
             } elseif (!isset($subCategories[$cat['id']]) && in_array($cat['id'], $arr_mod_cat_id)) {
                 $subCategories[$cat['id']] = array();
             }
             if (in_array($cat['id'], $arr_mod_cat_id)) {
                 $allCategories[$cat['id']] = $cat;
             } else {
                 $allCategories[$cat['id']] = array();
             }
         } else {
             if ($cat['parent_id']) {
                 $subCategories[$cat['parent_id']][$cat['id']] = $cat;
             } elseif (!isset($subCategories[$cat['id']])) {
                 $subCategories[$cat['id']] = array();
             }
             $allCategories[$cat['id']] = $cat;
         }
     }
     $arr = array();
     if ($subCategories) {
         foreach ($subCategories as $pid => $subCats) {
             if (isset($allCategories[$pid])) {
                 $arr[$pid] = $allCategories[$pid]['name'];
             }
             if (isset($allCategories[$pid]) && $subCats) {
                 foreach ($subCats as $sid => $subCat) {
                     $arr[$sid] = '-----' . $subCat['name'];
                 }
             }
         }
     }
     return $arr;
 }
Пример #15
0
 function on_submit()
 {
     AZLib::getCats();
     $sku = AZLib::trimSpace(str_replace("\n", " ", Url::get('sku')));
     ###############################################################################################
     $name = AZLib::trimSpace(str_replace("\n", " ", Url::get('name')));
     mb_internal_encoding("UTF-8");
     $name = mb_strtoupper(mb_substr($name, 0, 1)) . mb_substr($name, 1);
     ###############################################################################################
     ###############################################################################################
     $offer = AZLib::trimSpace(str_replace("\n", " ", Url::get('offer')));
     mb_internal_encoding("UTF-8");
     $offer = mb_strtoupper(mb_substr($offer, 0, 1)) . mb_substr($offer, 1);
     ###############################################################################################
     ###############################################################################################
     $list_brief = AZLib::trimSpace(str_replace("\n", " ", Url::get('list_brief')));
     mb_internal_encoding("UTF-8");
     $list_brief = mb_strtoupper(mb_substr($list_brief, 0, 1)) . mb_substr($list_brief, 1);
     ###############################################################################################
     ###############################################################################################
     //$item_description 	= AZLib::getParam('item_description');
     $item_description = Url::get('item_description');
     $brief = Url::get('brief');
     if (get_magic_quotes_gpc()) {
         $item_description = stripslashes($item_description);
         $brief = stripslashes($brief);
     }
     require_once ROOT_PATH . 'includes/htmLawed.php';
     $config = array('safe' => 1, 'elements' => '*', 'deny_attribute' => 'class, id');
     $spec = 'a = title, href;';
     // The 'a' element can have only these attributes
     $item_description = htmLawed($item_description, $config, $spec);
     $item_description = AZLib::clean_value($item_description);
     $brief = htmLawed($brief, $config, $spec);
     $brief = AZLib::clean_value($brief);
     ###############################################################################################
     $category_id = 0;
     $level_1_catid = 0;
     $first_combo = (int) Url::get('first_combo');
     $second_combo = (int) Url::get('second_combo');
     $price = Url::cdouble(Url::get('price', 0));
     $price_out = Url::cdouble(Url::get('price_out', 0));
     $currency_id = (int) Url::get('currency_id', 1);
     $quantity = Url::cdouble(Url::get('quantity', 0));
     if ($quantity < 0) {
         $quantity = 0;
     }
     $item_order = (int) Url::get('item_order');
     $made_in = Url::get('made_in');
     $warranty = Url::get('warranty');
     if (!isset(CGlobal::$currency[$currency_id])) {
         $currency_id = 1;
     }
     $item_category = false;
     if ($first_combo && $second_combo) {
         //Nếu chọn danh mục cấp 2
         $category_id = $second_combo;
         $level_1_catid = $first_combo;
         $level_2_catid = $second_combo;
         if (isset(CGlobal::$allCategories[$category_id])) {
             //Kiểm tra sự tồn tai của danh mục
             $item_category = CGlobal::$allCategories[$category_id];
             //Nếu danh mục của sản phẩm là danh mục cấp 1 và có danh mục con => chọn lại
             if (isset(CGlobal::$subCategories[$category_id]) && CGlobal::$subCategories[$category_id] && $item_category['parent_id'] == 0 || $item_category['parent_id'] != $first_combo) {
                 $this->setFormError('category_id', 'Hãy chọn lại <b>Chủng loại</b> cho sản phẩm!');
             }
         }
     } elseif ($first_combo) {
         //Nếu chọn danh mục cấp 1
         $category_id = $first_combo;
         $level_1_catid = $first_combo;
         $level_2_catid = $first_combo;
         if (isset(CGlobal::$allCategories[$category_id])) {
             //Kiểm tra sự tồn tai của danh mục
             $item_category = CGlobal::$allCategories[$category_id];
             if (isset(CGlobal::$subCategories[$category_id]) && CGlobal::$subCategories[$category_id] && $item_category['parent_id'] == 0) {
                 //Nếu danh mục có danh mục con => Chọn lại!
                 $this->setFormError('category_id', 'Hãy chọn lại <b>Chủng loại</b> cho sản phẩm!');
             } elseif ($item_category['parent_id'] != 0) {
                 //Nếu không fải là danh mục cấp 1
                 $this->setFormError('category_id', 'Hãy chọn lại <b>Chủng loại</b> cho sản phẩm!');
             }
         }
     }
     if (!$item_category) {
         $this->setFormError('category_id', 'Bạn chưa chọn <b>Danh mục</b> cho sản phẩm!');
     }
     $this->checkFormInput('Tên sản phẩm', 'name', $name, 'str', true, '', 5, 255);
     $this->checkFormInput('Mô tả vắn tắt', 'brief', $brief, 'str', false, '', 15, 500000);
     $this->checkFormInput('Mô tả sản phẩm', 'item_description', $item_description, 'str', true, '', 15, 500000);
     //Check kiểm duyệt
     $status = 1;
     //Cho hiển thị
     $have_image_up = false;
     $form_img_server = Url::get('avatar_img_server', 0);
     $this->img_url = Url::get('avatar_img_url', '');
     foreach ($this->item_images as $page => $page_images) {
         //trang
         foreach ($page_images as $image) {
             if ($image['img_new_id']) {
                 $have_image_up = true;
                 break;
             }
         }
     }
     if (!$this->errNum) {
         $item_array = array('category_id' => $category_id, 'level_1_catid' => $level_1_catid, 'level_2_catid' => $level_2_catid, 'currency_id' => $currency_id, 'quantity' => $quantity, 'item_order' => $item_order, 'made_in' => $made_in, 'warranty' => $warranty, 'price' => $price, 'price_out' => $price_out, 'sku' => $sku, 'name' => $name, 'offer' => $offer, 'list_brief' => $list_brief, 'brief' => $brief, 'description' => $item_description, 'status' => $status, 'created_time' => TIME_NOW, 'user_id' => User::id(), 'user_name' => User::user_name(), 'modify_time' => TIME_NOW, 'modify_user_name' => User::user_name(), 'img_server' => $form_img_server, 'have_image' => (int) (bool) $this->img_url, 'img_url' => $this->img_url);
         $id = DB::insert('item', $item_array);
         if (!$id) {
             $this->setFormError('', "Không đăng được Sản phẩm! Mời bạn thử lại!");
         }
         $image_err = false;
         $i_server = 0;
         $img_url = '';
         $item_images = array();
         $item_insert_temp_images = array();
         $item_insert_images = array();
         $item_update_images = array();
         $img_ids = '';
         foreach ($this->item_images as $page => $page_images) {
             //trang
             foreach ($page_images as $image) {
                 if ($image['img_new_id']) {
                     $img = array();
                     $img_ids .= ($img_ids ? ',' : '') . $image['img_new_id'];
                     $img['item_id'] = $id;
                     $img['title'] = $image['title'] && $image['title'] != 'Ghi chú ảnh' && !AZLib::checkBadWord($image['title']) ? addslashes($image['title']) : '';
                     $img['position'] = $image['stt'];
                     $img['img_server'] = $image['img_server'];
                     $img['img_url'] = '';
                     $img['root_id'] = 0;
                     $img['time'] = TIME_NOW;
                     $img['user_id'] = User::id();
                     $img['user_name'] = User::user_name();
                     if (!isset($item_images[$image['img_new_id']])) {
                         $item_images[$image['img_new_id']] = $img;
                     } else {
                         $img['root_id'] = $image['img_new_id'];
                         $item_insert_temp_images[$image['img_new_id']] = $img;
                         //Đúp bản ghi trong trường hợp 1 ảnh được chọn tại nhiều vị trí
                     }
                 }
             }
         }
         if ($img_ids) {
             $re = DB::query('SELECT id, item_id, user_id, img_server, img_url,root_id, time FROM item_image WHERE id IN(' . $img_ids . ')');
             if ($re) {
                 $pos = 0;
                 while ($img = mysql_fetch_assoc($re)) {
                     if (isset($item_insert_temp_images[$img['id']])) {
                         $item_insert_temp_images[$img['id']]['img_server'] = $img['img_server'];
                         $item_insert_temp_images[$img['id']]['img_url'] = $img['img_url'];
                         $item_insert_temp_images[$img['id']]['root_id'] = $img['id'];
                         $item_insert_temp_images[$img['id']]['time'] = $img['time'];
                         $item_insert_images[] = $item_insert_temp_images[$img['id']];
                     }
                     $item_images[$img['id']]['time'] = $img['time'];
                     $item_images[$img['id']]['img_server'] = $img['img_server'];
                     $item_images[$img['id']]['img_url'] = $img['img_url'];
                     if ($img['item_id']) {
                         //Đã có item_id rồi, đúp bản ghi
                         $image = $item_images[$img['id']];
                         if ($img['root_id']) {
                             $image['root_id'] = $img['root_id'];
                         } else {
                             $image['root_id'] = $img['id'];
                         }
                         $item_insert_images[] = $image;
                     } else {
                         //Chưa có item_id, cập nhật
                         $img['item_id'] = $id;
                         $item_update_images[$img['id']] = $item_images[$img['id']];
                     }
                     if ($img_url == '' || $pos == 0 || $item_images[$img['id']]['position'] <= $pos) {
                         $pos = $item_images[$img['id']]['position'];
                         $i_server = $img['img_server'];
                         $img_url = $img['img_url'];
                     }
                 }
             }
         }
         if ($item_insert_images) {
             $inser_sql = '';
             foreach ($item_insert_images as $item_image) {
                 $inser_sql .= ($inser_sql ? "," : "") . "\r\n\t\t\t\t\t\t('" . addslashes($item_image['title']) . "',\r\n\t\t\t\t\t\t'" . $item_image['position'] . "','" . $item_image['item_id'] . "'," . $item_image['img_server'] . ",'" . $item_image['img_url'] . "','" . $item_image['root_id'] . "',\r\n\t\t\t\t\t\t'" . $item_image['time'] . "','" . $item_image['user_id'] . "','" . $item_image['user_name'] . "')";
             }
             $inser_sql = "INSERT INTO `item_image` (`title`,`position`,`item_id`,`img_server`,`img_url`,`root_id`,`time`,`user_id`,`user_name`) \r\n\t\t\t\t\t\t\tVALUES " . $inser_sql;
             DB::query($inser_sql);
         }
         if ($item_update_images) {
             foreach ($item_update_images as $img_id => $item_image) {
                 if (!DB::update('item_image', $item_image, 'id=' . $img_id)) {
                     $image_err = true;
                 }
             }
         }
         #Filters
         ##############################################################################
         $item_array = array('filter_search' => $filter_search, 'filter_ids' => $filter_ids);
         if ($this->img_url == '' && $img_url != '') {
             $item_array['img_server'] = $i_server;
             $item_array['img_url'] = $img_url;
             $item_array['have_image'] = 1;
         } elseif ($item_have_image) {
             $item_array['have_image'] = 1;
         }
         $item_array['filter_search'] = $filter_search;
         $item_array['filter_ids'] = $filter_ids;
         if ($this->img_url == '' && $img_url != '') {
             $item_array['img_server'] = $i_server;
             $item_array['img_url'] = $img_url;
             $item_array['have_image'] = 1;
         } elseif ($item_insert_images || $item_update_images) {
             //tuannk 2010.07.26
             $item_array['have_image'] = 1;
         }
         DB::update('item', $item_array, 'id=' . $id);
         if (Url::get('ref')) {
             Url::redirect("manage_item");
         } else {
             Url::redirect("item_detail", array("id" => $id));
         }
     }
 }
Пример #16
0
 function show_all_notify()
 {
     global $display;
     AZLib::getCats();
     $feed_follows = array();
     //hoạt động của các thành viên mà mình theo đuôi
     $follow_ids = '';
     //hoạt động của các thành viên mà mình theo đuôi
     $action = Url::get('action');
     $num_per_page = 20;
     $ajax_mod = (int) (Url::get('act') == 'shop_giaodich');
     $page_no = 1;
     $cur_group = 0;
     $all_feeds = array();
     //Lưu mảng tất cả các cập nhật
     $all_feed_ars = array();
     //mảng các cập nhật đã đc sắp xếp, xử lý
     $user_arr = array();
     //Mảng các user
     $item_arr = array();
     //Mảng các Giao dịch
     $entry_arr = array();
     //Mảng các Bài viết
     $item_ids_ar = array();
     //Mảng id các Giao dịch
     $user_ids_ar = array();
     //Mảng id các user
     $entry_ids_ar = array();
     //Mảng id các Bài viết
     $item_comment_ids = "";
     //Id các phản hồi giao dịch
     $item_comment_arr = array();
     //các phản hồi giao dịch
     $user_comment_ids = "";
     //Id các lưu bút
     $user_comment_arr = array();
     //các lưu bút
     $pm_ids = "";
     //Id các tin nhắn
     $pm_arr = array();
     //các tin nhắn
     $entry_comment_ids = "";
     //Id các bài viết
     $entry_comment_arr = array();
     //các bài viết
     $this->show_more = false;
     //các bài viết
     $where = "WHERE user_id = " . User::id();
     $limit = " LIMIT " . $num_per_page * ($page_no - 1) . "," . ($num_per_page + 1);
     $where .= " AND type IN(1,2,3,4,5,6)";
     $total_unread = 0;
     $sql = "SELECT * FROM feed {$where} ORDER BY time DESC {$limit}";
     $re = DB::query($sql);
     $stt = 0;
     if ($re) {
         while ($feed = mysql_fetch_assoc($re)) {
             if ($stt < $num_per_page) {
                 if ($feed['type'] == 1 || $feed['type'] == 2) {
                     $item_comment_ids .= ($item_comment_ids != '' ? ',' : '') . $feed['ref_id'];
                     if (!in_array($feed['item_id'], $item_ids_ar)) {
                         $item_ids_ar[$feed['item_id']] = $feed['item_id'];
                     }
                 } elseif ($feed['type'] == 3) {
                     $user_comment_ids .= ($user_comment_ids != '' ? ',' : '') . $feed['ref_id'];
                 } elseif ($feed['type'] == 4) {
                     $pm_ids .= ($pm_ids != '' ? ',' : '') . $feed['ref_id'];
                 } elseif ($feed['type'] == 5 || $feed['type'] == 6) {
                     $entry_comment_ids .= ($entry_comment_ids != '' ? ',' : '') . $feed['ref_id'];
                     if ($feed['item_id']) {
                         $entry_ids_ar[$feed['item_id']] = $feed['item_id'];
                     }
                 }
                 if ($feed['act_user_id'] && !in_array($feed['act_user_id'], $user_ids_ar)) {
                     $user_ids_ar[$feed['act_user_id']] = $feed['act_user_id'];
                 }
                 $all_feeds[$feed['id']] = $feed;
                 $stt++;
             } else {
                 $this->show_more = true;
             }
         }
     }
     if ($item_ids_ar) {
         $item_ids = implode(',', $item_ids_ar);
         if ($item_ids != '') {
             $re = DB::query("SELECT  id, name ,up_time, status, state, currency_id, category_id, img_server, img_url AS image_url FROM item WHERE id IN({$item_ids})");
             if ($re) {
                 while ($item = mysql_fetch_assoc($re)) {
                     if (isset(CGlobal::$allCategories[$item['category_id']])) {
                         $item['link_view'] = Url::build('item_detail', array('id' => $item['id'], 'ebname' => AZLib::safe_title($item['name']), 'nice_name' => CGlobal::$allCategories[$item['category_id']]['nice_name']));
                     } else {
                         $item['link_view'] = Url::build('item_detail', array('id' => $item['id'], 'ebname' => AZLib::safe_title($item['name'])));
                     }
                     if (!$item['status']) {
                         $total_unread++;
                     }
                     $item_arr[$item['id']] = $item;
                 }
             }
         }
     }
     if (!empty($entry_ids_ar)) {
         $entry_ids = implode(',', $entry_ids_ar);
         if ($entry_ids != '') {
             $re = DB::query("SELECT id, title, status, user_name, time_modify, image_url FROM user_entry WHERE id IN({$entry_ids})");
             if ($re) {
                 while ($entry = mysql_fetch_assoc($re)) {
                     $entry['link_view'] = WEB_DIR . AZRewrite::formatUrl('?page=user_entry&user_name=' . $entry['user_name'] . '&cmd_entry=view&entry_id=' . $entry['id'] . '&ebname=' . AZLib::safe_title($entry['title']));
                     if (!$entry['status']) {
                         $total_unread++;
                     }
                     $entry_arr[$entry['id']] = $entry;
                 }
             }
         }
     }
     if ($user_ids_ar) {
         $user_ids = implode(',', $user_ids_ar);
         if ($user_ids != '') {
             $re = DB::query("SELECT id, user_name, blast, avatar_url,img_server FROM user WHERE id IN({$user_ids})");
             if ($re) {
                 while ($user = mysql_fetch_assoc($re)) {
                     if ($user['avatar_url']) {
                         $user['avatar_url'] = 'http://' . CGlobal::$img_server[$user['img_server']] . 'thumb/50_50/' . $user['avatar_url'];
                     } else {
                         $user['avatar_url'] = 'style/images/54x54.gif';
                     }
                     $user_arr[$user['id']] = $user;
                 }
             }
         }
     }
     //Phản hồi giao dịch
     if ($item_comment_ids != '') {
         $re = DB::query("SELECT * FROM comment WHERE id IN({$item_comment_ids})");
         if ($re) {
             while ($comment = mysql_fetch_assoc($re)) {
                 $comment['content'] = AZLib::parseBBCode(stripslashes($comment['content']));
                 $comment['s_content'] = AZLib::plainText($comment['content']);
                 if (strlen($comment['s_content']) > 20) {
                     $comment['s_content'] = AZLib::word_limit($comment['s_content'], 10, '..');
                 }
                 $comment['time'] = AZLib::duration_time($comment['time']);
                 if (!$comment['status']) {
                     $total_unread++;
                 }
                 $item_comment_arr[$comment['id']] = $comment;
             }
         }
     }
     //Lưu bút
     if ($user_comment_ids != '') {
         $re = DB::query("SELECT * FROM comment_user WHERE id IN({$user_comment_ids})");
         if ($re) {
             while ($comment = mysql_fetch_assoc($re)) {
                 $comment['content'] = AZLib::parseBBCode(stripslashes($comment['content']));
                 $comment['s_content'] = AZLib::plainText($comment['content']);
                 if (strlen($comment['s_content']) > 20) {
                     $comment['s_content'] = AZLib::word_limit($comment['s_content'], 10, '..');
                 }
                 $comment['time'] = AZLib::duration_time($comment['time']);
                 if (!$comment['status']) {
                     $total_unread++;
                 }
                 $user_comment_arr[$comment['id']] = $comment;
             }
         }
     }
     if ($pm_ids != '' && $pm_ids != 0) {
         //Tin nhắn
         $re = DB::query("SELECT mt.*, msg.msg_post as content FROM (SELECT mt_id AS id, mt_msg_id, mt_title, mt_ref_id , mt_from_id AS sender_user_id, mt_date AS time, mt_read AS status FROM message_topics WHERE mt_id IN({$pm_ids})) AS mt LEFT JOIN message_text AS msg ON mt.mt_msg_id = msg.msg_id");
         if ($re) {
             while ($comment = mysql_fetch_assoc($re)) {
                 $comment['content'] = AZLib::parseBBCode(stripslashes($comment['content']));
                 $comment['s_content'] = AZLib::plainText($comment['content']);
                 if (strlen($comment['s_content']) > 20) {
                     $comment['s_content'] = AZLib::word_limit($comment['s_content'], 10, '..');
                 }
                 $comment['time'] = AZLib::duration_time($comment['time']);
                 if (!$comment['status']) {
                     $total_unread++;
                 }
                 $pm_arr[$comment['id']] = $comment;
             }
         }
     }
     if ($entry_comment_ids != '') {
         //Phản hồi bài viết
         $re = DB::query("SELECT id, entry_id, content, time, sender_user_id, sender_user_name, sender_email, status FROM user_entry_comment WHERE id IN({$entry_comment_ids})");
         if ($re) {
             while ($comment = mysql_fetch_assoc($re)) {
                 $comment['content'] = AZLib::parseBBCode(stripslashes($comment['content']));
                 $comment['s_content'] = AZLib::plainText($comment['content']);
                 if (strlen($comment['s_content']) > 20) {
                     $comment['s_content'] = AZLib::word_limit($comment['s_content'], 10, '..');
                 }
                 $comment['time'] = AZLib::duration_time($comment['time']);
                 if (!$comment['status']) {
                     $total_unread++;
                 }
                 $entry_comment_arr[$comment['id']] = $comment;
             }
         }
     }
     $item_ids_ar = array();
     //Mảng item_id cập nhật bỏ qua cho các feed chủ thể tương ứng khi giao dịch bị xoá hoặc khoá!
     $item_ids_ar2 = array();
     //Mảng item_id cập nhật bỏ qua cho các feed khách thể tương ứng khi giao dịch bị xoá hoặc khoá!
     $entry_ids_ar = array();
     $entry_ids_ar2 = array();
     $c_user_ids_ar = array();
     $pm_ids_ar = array();
     $unread_feed_ids = '';
     $del_feed_ids = '';
     if ($all_feeds) {
         foreach ($all_feeds as $feed) {
             if ($feed['type'] == 4) {
                 //Tin nhắn
                 if (isset($user_arr[$feed['act_user_id']])) {
                     $feed['sender_user_name'] = $user_arr[$feed['act_user_id']]['user_name'];
                 } else {
                     $feed['sender_user_name'] = '';
                 }
             }
             if ($feed['type'] == 1 || $feed['type'] == 2) {
                 //Phản hồi giao dịch hoặc Trả lời phản hồi giao dịch
                 if (isset($item_comment_arr[$feed['ref_id']])) {
                     $feed['item_id'] = $item_comment_arr[$feed['ref_id']]['item_id'];
                     $feed['content'] = $item_comment_arr[$feed['ref_id']]['content'];
                     $feed['s_content'] = $item_comment_arr[$feed['ref_id']]['s_content'];
                     $feed['time'] = $item_comment_arr[$feed['ref_id']]['time'];
                     $feed['sender_user_id'] = $item_comment_arr[$feed['ref_id']]['sender_user_id'];
                     $feed['sender_user_name'] = $item_comment_arr[$feed['ref_id']]['sender_user_name'];
                     $feed['sender_email'] = $item_comment_arr[$feed['ref_id']]['sender_email'];
                     $status = $feed['status'];
                     if ($feed['type'] == 1) {
                         $feed['status'] = $item_comment_arr[$feed['ref_id']]['status'];
                     } else {
                         $feed['status'] = $item_comment_arr[$feed['ref_id']]['replied_status'];
                     }
                     if ($feed['status'] == 0 || $status == 0) {
                         $unread_feed_ids .= ($unread_feed_ids != '' ? ',' : '') . $feed['id'];
                         if ($feed['type'] == 1 && $feed['status'] == 0) {
                             //Mảng item_id cập nhật bỏ qua cho các feed chủ thể tương ứng khi giao dịch bị xoá hoặc khoá!
                             $item_ids_ar[$feed['item_id']] = $feed['item_id'];
                         } elseif ($feed['type'] == 2 && $feed['status'] == 0) {
                             //Mảng item_id cập nhật bỏ qua cho các feed khách thể tương ứng khi giao dịch bị xoá hoặc khoá!
                             $item_ids_ar2[$feed['item_id']] = $feed['item_id'];
                         }
                     }
                     if (isset($item_arr[$feed['item_id']]) && $item_arr[$feed['item_id']]['state'] == 0 && $item_arr[$feed['item_id']]['status'] != -1) {
                         $feed['item'] = $item_arr[$feed['item_id']];
                         $all_feed_ars[$feed['id']] = $feed;
                     } else {
                         $del_feed_ids .= ($del_feed_ids != '' ? ',' : '') . $feed['id'];
                     }
                 } else {
                     $del_feed_ids .= ($del_feed_ids != '' ? ',' : '') . $feed['id'];
                 }
             } elseif ($feed['type'] == 3) {
                 //Lưu bút
                 if (isset($user_comment_arr[$feed['ref_id']])) {
                     $feed['content'] = $user_comment_arr[$feed['ref_id']]['content'];
                     $feed['s_content'] = $user_comment_arr[$feed['ref_id']]['s_content'];
                     $feed['time'] = $user_comment_arr[$feed['ref_id']]['time'];
                     $feed['sender_user_id'] = $user_comment_arr[$feed['ref_id']]['sender_user_id'];
                     $feed['sender_user_name'] = $user_comment_arr[$feed['ref_id']]['sender_user_name'];
                     $status = $feed['status'];
                     $feed['status'] = $user_comment_arr[$feed['ref_id']]['status'];
                     if ($feed['status'] == 0 || $status == 0) {
                         $unread_feed_ids .= ($unread_feed_ids != '' ? ',' : '') . $feed['id'];
                         if ($feed['status'] == 0) {
                             //
                             $c_user_ids_ar[$feed['ref_id']] = $feed['ref_id'];
                         }
                     }
                     $all_feed_ars[$feed['id']] = $feed;
                 } else {
                     $del_feed_ids .= ($del_feed_ids != '' ? ',' : '') . $feed['id'];
                 }
             } elseif ($feed['type'] == 4) {
                 //Tin nhắn
                 if (isset($pm_arr[$feed['ref_id']])) {
                     $feed['content'] = $pm_arr[$feed['ref_id']]['content'];
                     $feed['s_content'] = $pm_arr[$feed['ref_id']]['s_content'];
                     $feed['time'] = $pm_arr[$feed['ref_id']]['time'];
                     $feed['sender_user_id'] = $pm_arr[$feed['ref_id']]['sender_user_id'];
                     $feed['mt_title'] = $pm_arr[$feed['ref_id']]['mt_title'];
                     $id = $pm_arr[$feed['ref_id']]['mt_ref_id'] ? $pm_arr[$feed['ref_id']]['mt_ref_id'] : $pm_arr[$feed['ref_id']]['id'];
                     $feed['mt_title_link'] = "message.html#inbox/{$id}";
                     $status = $feed['status'];
                     $feed['status'] = $pm_arr[$feed['ref_id']]['status'];
                     if ($feed['status'] == 0 || $status == 0) {
                         $unread_feed_ids .= ($unread_feed_ids != '' ? ',' : '') . $feed['id'];
                         if ($feed['status'] == 0) {
                             //
                             $pm_ids_ar[$feed['ref_id']] = $feed['ref_id'];
                         }
                     }
                     $all_feed_ars[$feed['id']] = $feed;
                 } else {
                     $del_feed_ids .= ($del_feed_ids != '' ? ',' : '') . $feed['id'];
                 }
             } elseif ($feed['type'] == 5 || $feed['type'] == 6) {
                 //Phản hồi Bài viết
                 if (isset($entry_comment_arr[$feed['ref_id']])) {
                     $feed['entry_id'] = $entry_comment_arr[$feed['ref_id']]['entry_id'];
                     $feed['content'] = $entry_comment_arr[$feed['ref_id']]['content'];
                     $feed['s_content'] = $entry_comment_arr[$feed['ref_id']]['s_content'];
                     $feed['time'] = $entry_comment_arr[$feed['ref_id']]['time'];
                     $feed['sender_user_id'] = $entry_comment_arr[$feed['ref_id']]['sender_user_id'];
                     $feed['sender_user_name'] = $entry_comment_arr[$feed['ref_id']]['sender_user_name'];
                     $feed['sender_email'] = $entry_comment_arr[$feed['ref_id']]['sender_email'];
                     $status = $feed['status'];
                     if ($feed['type'] == 5) {
                         $feed['status'] = $entry_comment_arr[$feed['ref_id']]['status'];
                     } else {
                         $feed['status'] = $entry_comment_arr[$feed['ref_id']]['replied_status'];
                     }
                     if ($feed['status'] == 0 || $status == 0) {
                         $unread_feed_ids .= ($unread_feed_ids != '' ? ',' : '') . $feed['id'];
                         if ($feed['type'] == 5 && $feed['status'] == 0) {
                             //Mảng entrry_id cập nhật bỏ qua cho các feed chủ thể tương ứng khi giao dịch bị xoá hoặc khoá!
                             $entry_ids_ar[$feed['entry_id']] = $feed['entry_id'];
                         }
                         if ($feed['type'] == 6 && $feed['status'] == 0) {
                             //Mảng entrry_id cập nhật bỏ qua cho các feed khách thể tương ứng khi giao dịch bị xoá hoặc khoá!
                             $entry_ids_ar2[$feed['entry_id']] = $feed['entry_id'];
                         }
                     }
                     if (isset($entry_arr[$feed['entry_id']])) {
                         $feed['entry'] = $entry_arr[$feed['entry_id']];
                         $all_feed_ars[$feed['id']] = $feed;
                     } else {
                         $del_feed_ids .= ($del_feed_ids != '' ? ',' : '') . $feed['id'];
                     }
                 } else {
                     $del_feed_ids .= ($del_feed_ids != '' ? ',' : '') . $feed['id'];
                 }
             }
         }
     }
     $display->add('all_feed_ars', $all_feed_ars);
     $display->add('image_path', 'http://' . IMAGE_PATH);
     $display->add('get_page', AZNet::$page['name']);
     $display->add('get_cmd', Url::get('cmd', 'office'));
     $display->add('get_act', $action);
     $display->add('user_name', User::user_name());
     $this->total_group = count($all_feed_ars);
     $display->add('total_group', $this->total_group);
     $display->add('cur_group', $cur_group);
     $display->add('show_more', $this->show_more);
     $display->add('cur_user_name', User::user_name());
     $display->add('more_notify', WEB_DIR . AZRewrite::formatUrl('?page=personal'));
     $transact_office = $display->output('tbl_notify_ajax', true, 'Personal');
     $display->add('transact_office', $transact_office);
     $display->add('total_comment_user', User::$current->data['total_comment_user']);
     $display->add('total_new_comment', User::$current->data['total_new_comment']);
     $display->add('total_pm', User::$current->data['total_pm']);
     $display->add('can_edit_blast', User::is_admin() || !User::is_block());
     $blast = User::$current->data['blast'];
     $avatar_link = '';
     $avatar_url = 'style/images/no_avatar_item.gif';
     if (User::$current->data['avatar_url'] != '') {
         $avatar_link = "http://" . CGlobal::$img_server[User::$current->data['img_server']] . User::$current->data['avatar_url'];
         $avatar_url = AZLib::getImageThumb(User::$current->data['avatar_url'], 80, 80, 0, User::$current->data['img_server']);
     }
     if ($blast == '') {
         $blast = '...';
     } else {
         $blast = ' ' . $blast;
         if (strpos($blast, 'http://')) {
             $user_blast = $blast;
             while (strpos($user_blast, 'http://')) {
                 $tmp = substr($user_blast, strpos($user_blast, 'http://'));
                 if (strpos($tmp, ' ') || strpos($tmp, '<')) {
                     if (strpos($tmp, ' ') && strpos($tmp, '<') && strpos($tmp, ' ') > strpos($tmp, '<')) {
                         $blast_url = substr($tmp, 0, strpos($tmp, '<'));
                     } else {
                         $blast_url = substr($tmp, 0, strpos($tmp, ' '));
                     }
                 } else {
                     $blast_url = $tmp;
                 }
                 $user_blast = str_replace($blast_url, '', $user_blast);
             }
             $new_blast_url = ' <a rel="nofollow" href="' . $blast_url . '" target="_blank">Click here</a>';
             $blast = substr($user_blast . $new_blast_url, 1);
         }
     }
     $display->add('avatar_link', $avatar_link);
     $display->add('avatar_url', $avatar_url);
     $display->add('blast', $blast);
     $display->add('user_id', User::id());
     //Cập nhật sách theo đuôi
     if (isset($user_arr[$feed['act_user_id']]) && $user_arr[$feed['act_user_id']]['avatar_url']) {
         $feed['avatar_url'] = $user_arr[$feed['act_user_id']]['avatar_url'];
     } else {
         $feed['avatar_url'] = 'style/images/54x54.gif';
     }
     if ($feed_follows) {
         $tmp_feed_follows = $feed_follows;
         $feed_follows = array();
         foreach ($tmp_feed_follows as $feed) {
             if (isset($user_arr[$feed['user_id']])) {
                 if ($user_arr[$feed['user_id']]['avatar_url']) {
                     $avatar_url = $user_arr[$feed['user_id']]['avatar_url'];
                 } else {
                     $avatar_url = 'style/images/54x54.gif';
                 }
                 $user_name = $user_arr[$feed['user_id']]['user_name'];
                 if ($feed['type'] == 7) {
                     //entry
                     if (isset($entry_arr[$feed['item_id']])) {
                         $feed_follows[$feed['user_id']]['user_name'] = $user_name;
                         $feed_follows[$feed['user_id']]['avatar_url'] = $avatar_url;
                         $feed['entry_name'] = $entry_arr[$feed['item_id']]['title'];
                         $feed['entry_link'] = WEB_DIR . AZRewrite::formatUrl('?page=user_entry&user_name=' . $user_name . '&cmd_entry=view&entry_id=' . $feed['item_id'] . '&ebname=' . AZLib::safe_title($feed['entry_name']));
                         $feed['time'] = date('H:i d/m/Y', $feed['time']);
                         $feed_follows[$feed['user_id']]['feeds'][$feed['id']] = $feed;
                     }
                 } else {
                     $feed_follows[$feed['user_id']]['user_name'] = $user_name;
                     $feed_follows[$feed['user_id']]['avatar_url'] = $avatar_url;
                     $feed['blast'] = $user_arr[$feed['user_id']]['blast'];
                     $feed['time'] = date('H:i d/m/Y', $feed['time']);
                     $feed_follows[$feed['user_id']]['feeds'][$feed['id']] = $feed;
                 }
             }
         }
     }
     $json = array();
     $active_notify = array();
     $active_notify['item_ids_ar'] = $item_ids_ar;
     $active_notify['item_ids_ar2'] = $item_ids_ar2;
     $active_notify['c_user_ids_ar'] = $c_user_ids_ar;
     $active_notify['pm_ids_ar'] = $pm_ids_ar;
     $json['active_notify'] = $active_notify;
     $json['total_unread'] = $total_unread;
     $json['total_notify'] = User::$current->data['total_comment_user'] + User::$current->data['total_new_comment'] + User::$current->data['total_pm'];
     $json['content'] = $display->output('tb_notify', true, 'Personal');
     echo json_encode($json);
     exit;
 }
Пример #17
0
 function draw()
 {
     if (Item::$item && isset(Item::$item['display']) && Item::$item['display']) {
         global $display;
         AZLib::getCats();
         $item_detail = Item::$item;
         $item_detail['name_url'] = AZLib::safe_title($item_detail['name']);
         //rewrite URL
         $item_detail['modify_time'] = date('Y') != date('Y', $item_detail['modify_time']) ? date('H:i, d/m/Y', $item_detail['modify_time']) : date('H:i, d/m', $item_detail['modify_time']);
         $item_detail['created_time'] = date('Y') != date('Y', $item_detail['created_time']) ? date('H:i, d/m/Y', $item_detail['created_time']) : date('H:i, d/m', $item_detail['created_time']);
         $item_detail['price'] = AZLib::convertCurrency($item_detail['price'], $item_detail['currency_id']);
         $item_detail['price_out'] = AZLib::convertCurrency($item_detail['price_out'], $item_detail['currency_id']);
         if (isset(CGlobal::$allCategories[$item_detail['category_id']])) {
             $item_detail['item_url'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item_detail['id'] . '&ebname=' . AZLib::safe_title($item_detail['name']) . '&nice_name=' . CGlobal::$allCategories[$item_detail['category_id']]['nice_name']);
         } else {
             $item_detail['item_url'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item_detail['id'] . '&ebname=' . AZLib::safe_title($item_detail['name']));
         }
         //$display->add('currency_id',$item_detail['price']?CGlobal::$currency[$item_detail['currency_id']]:'');
         $display->add('currency_id', $item_detail['price'] ? 'VNĐ' : '');
         $item_detail['price'] = $item_detail['price'] ? number_format($item_detail['price'], 0, ',', '.') : 'Liên hệ';
         $item_detail['price_out'] = $item_detail['price_out'] ? number_format($item_detail['price_out'], 0, ',', '.') : '';
         //item images
         $display->add("item_images", $item_detail['images']);
         $display->add("count_img", count($item_detail['images']));
         $display->add("images_url_root", isset($item_detail['img_server']) ? 'http://' . CGlobal::$img_server[(int) $item_detail['img_server']] : '');
         //END item images
         $this->admin_links($item_detail);
         //Highlight keyword search
         $this->highlight_searchword($item_detail);
         //END Highlight keyword search
         $show_error = false;
         if ($item_detail['status'] == 2) {
             $show_error = true;
             if (User::have_permit(ADMIN_ITEM)) {
                 $display->add('modify_by', ' (bởi <b>' . $item_detail['modify_user_name'] . '</b> lúc <b>' . date('d/m/Y H:i', $item_detail['modify_time']) . '</b>)');
             }
         }
         $display->add("show_error", $show_error);
         $link_item = "p" . $item_detail['id'] . "/" . AZLib::safe_title($item_detail['name']) . ".html";
         if (isset(CGlobal::$allCategories[$item_detail['category_id']])) {
             $link_item = CGlobal::$allCategories[$item_detail['category_id']]['nice_name'] . '/' . $link_item;
         }
         $first_img = false;
         if (Item::$item['images']) {
             foreach (Item::$item['images'] as $img) {
                 $first_img = $img;
                 break;
             }
         } elseif (Item::$item['img_url']) {
             $first_img['i'] = 1;
             $first_img['img_server'] = Item::$item['img_server'];
             $first_img['thumb316'] = AZLib::getImageThumb(Item::$item['img_url'], 316, 0, 0, Item::$item['img_server']);
             $first_img['img_full_url'] = "http://" . CGlobal::$img_server[Item::$item['img_server']] . Item::$item['img_url'];
             $first_img['max_path'] = AZLib::getImageThumbMax(Item::$item['img_url'], '', 1, Item::$item['img_server']);
         }
         $display->add('first_img', $first_img);
         if ($item_detail['status'] == 1) {
             $display->add('json_item', $item_detail['id']);
         } else {
             $display->add('json_item', 0);
         }
         //end list ly do khoa topic
         //for view images
         $display->add("request_uri", CGlobal::$request_uri);
         //Current url
         $display->add("url_flash_xml", urlencode('ebxml.php?act=item&code=tiltviewer_gallery&item_id=' . $item_detail['id']));
         //END for view images
         $display->add("msg", $this->showFormErrorMessages(1, "THÔNG BÁO"));
         $arr = $this->process_description($item_detail);
         $item_detail['brief'] = $arr['filter_brief'];
         $item_detail['description'] = $arr['filter_des'];
         /*
         			$item_detail['description'] = preg_replace('#(<[/]?img.*>)#iU', '', html_entity_decode($item_detail['description']));
         			$item_detail['description'] = preg_replace("/\\[([\s]*[0-9]{1,2}[\s]*)\]/eis", "\$this->embeded('$1')",$item_detail['description']);
         			
         			$item_detail['description'] = preg_replace('/<a[\s]*(.*)[\s]*href=[\'"](.*)[\'"][\s]*[^>]*[\s]*>(.*)<\/a>/eisU', "\$this->filter_link('$2','$3')",   $item_detail['description']);*/
         $display->add('is_admin', (int) (!User::is_block() && User::have_permit(ADMIN_USER)));
         $display->add("item_info", $item_detail);
         $display->add("item_id", $item_detail['id']);
         //$display->add("share_url", urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']));
         $cat_url = '';
         $cat_name = '';
         if (CGlobal::$curLevel2Cat) {
             $cat_url = "c" . CGlobal::$curLevel2Cat['id'] . "/" . CGlobal::$curMainCat['ebname'] . "-" . CGlobal::$curLevel2Cat['ebname'];
             $cat_name = CGlobal::$curLevel2Cat['name'];
         } elseif (CGlobal::$curMainCat) {
             $cat_url = "c" . CGlobal::$curMainCat['id'] . "/" . CGlobal::$curMainCat['ebname'];
             $cat_name = CGlobal::$curMainCat['name'];
         }
         $display->add("cat_url", $cat_url);
         $display->add("cat_name", $cat_name);
         $display->add("cat_name", $cat_name);
         if (isset($_SERVER['REQUEST_URI'])) {
             $display->add("http_referer", $_SERVER['REQUEST_URI']);
         } else {
             $display->add("http_referer", "");
         }
         /*//if(isset($_SERVER['HTTP_REFERER']) && eregi('enbac.com/c', $_SERVER['HTTP_REFERER'])){
         		if(isset($_SERVER['HTTP_REFERER']) && eregi(WEB_ROOT.'c', $_SERVER['HTTP_REFERER'])){
         			$display->add("ref_url", $_SERVER['HTTP_REFERER']);
         		}
         		else{
         			$display->add("ref_url", $cat_url);
         		}
         		
         		//$display->add("go_back", (isset($_SERVER['HTTP_REFERER']) && eregi('enbac.com/c', $_SERVER['HTTP_REFERER'])));
         		$display->add("go_back", (isset($_SERVER['HTTP_REFERER']) && eregi(WEB_ROOT.'c', $_SERVER['HTTP_REFERER'])));*/
         ####################################################################################################################################################################################
         //Rating product
         $display->add('ranking', AZLib::getRank($item_detail, true));
         $display->add('login', (int) User::is_login());
         $display->add('rate_num', $item_detail['rate_num']);
         $display->add('_rank', number_format($item_detail['rank'], 1, '.', ','));
         $display->add('_f_rank', number_format($item_detail['f_rank'], 1, '.', ','));
         $display->add('_d_rank', number_format($item_detail['d_rank'], 1, '.', ','));
         $display->add('_u_rank', number_format($item_detail['u_rank'], 1, '.', ','));
         if ($item_detail['f_rank']) {
             $f_rank = number_format($item_detail['f_rank'], 1, '.', ',');
         } else {
             $f_rank = 0;
         }
         $display->add('f_rank_', round($item_detail['f_rank']));
         $display->add('f_rank', $f_rank);
         $display->add('f_rate_num', $item_detail['f_rate_num']);
         if (User::have_permit(ADMIN_ITEM) || User::is_login() && !DB::select("item_rating", "type=0 AND user_id=" . User::id() . " AND item_id=" . $item_detail['id'])) {
             $display->add('block_f_rank', 1);
         } else {
             $display->add('block_f_rank', 0);
         }
         if ($item_detail['d_rank']) {
             $d_rank = number_format($item_detail['d_rank'], 1, '.', ',');
         } else {
             $d_rank = 0;
         }
         $display->add('d_rank_', round($item_detail['d_rank']));
         $display->add('d_rank', $d_rank);
         $display->add('d_rate_num', $item_detail['d_rate_num']);
         if (User::have_permit(ADMIN_ITEM) || User::is_login() && !DB::select("item_rating", "type=1 AND user_id=" . User::id() . " AND item_id=" . $item_detail['id'])) {
             $display->add('block_d_rank', 1);
         } else {
             $display->add('block_d_rank', 0);
         }
         if ($item_detail['u_rank']) {
             $u_rank = number_format($item_detail['u_rank'], 1, '.', ',');
         } else {
             $u_rank = 0;
         }
         $display->add('u_rank_', round($item_detail['u_rank']));
         $display->add('u_rank', $u_rank);
         $display->add('u_rate_num', $item_detail['u_rate_num']);
         if (User::have_permit(ADMIN_ITEM) || User::is_login() && !DB::select("item_rating", "type=2 AND user_id=" . User::id() . " AND item_id=" . $item_detail['id'])) {
             $display->add('block_u_rank', 1);
         } else {
             $display->add('block_u_rank', 0);
         }
         //End Rating product
         ####################################################################################################################################################################################
         $display->output("ItemDetail");
     } else {
         $content = 'Sản phẩm này hiện không tồn tại.';
         if (Item::$item && isset(Item::$item['status']) && isset(Item::$item['category_id']) && Item::$item['category_id'] && isset(CGlobal::$allCategories[Item::$item['category_id']])) {
             $ebname = CGlobal::$allCategories[Item::$item['category_id']]['ebname'];
             $pid = CGlobal::$allCategories[Item::$item['category_id']]['parent_id'];
             if ($pid && isset(CGlobal::$allCategories[$pid])) {
                 $ebname = CGlobal::$allCategories[$pid]['ebname'] . "-" . $ebname;
                 $pid = CGlobal::$allCategories[$pid]['parent_id'];
                 if ($pid && isset(CGlobal::$allCategories[$pid])) {
                     $ebname = CGlobal::$allCategories[$pid]['ebname'] . "-" . $ebname;
                 }
             }
             //header("HTTP/1.0 404 Not Found");
             $content .= " Click <a href='" . WEB_DIR . "c" . Item::$item['category_id'] . "/{$ebname}'>vào đây</a> để xem các sản phẩm liên quan.";
         } elseif (Item::$item && isset(Item::$item['status']) && isset(Item::$item['level_1_catid']) && Item::$item['level_1_catid'] && isset(CGlobal::$allCategories[Item::$item['level_1_catid']])) {
             $ebname = CGlobal::$allCategories[Item::$item['level_1_catid']]['ebname'];
             //header("HTTP/1.0 404 Not Found");
             $content .= " Click <a href='" . WEB_DIR . "c" . Item::$item['level_1_catid'] . "/{$ebname}'>vào đây</a> để xem các sản phẩm liên quan.";
         } else {
             $content .= " Click <a href='" . WEB_DIR . "'>vào đây</a> để trở về Trang chủ.";
         }
         AZLib::show_error_mes($content);
     }
 }
Пример #18
0
 function get_feed_notify_bar()
 {
     AZLib::getCats();
     $json = "";
     if (!User::is_login()) {
         $json = '({"msg":"no_login"})';
         echo $json;
         exit;
     }
     $item_comment_ids = "";
     //Id các phản hồi giao dịch
     $user_comment_ids = "";
     //Id các lưu bút
     $entry_comment_ids = "";
     //Id các bài viết
     /*$follow_ids			= "";//Id các theo đuôi*/
     $blast_user_ids = "";
     // Id các balst
     $arr_data = array();
     $user = User::getUser(User::id());
     if ($user["total_pm"]) {
         // neu co PM moi
         $arr_data = array("new_pm" => $user["total_pm"]);
     }
     $where = "WHERE user_id = " . User::id();
     $limit = " LIMIT 20";
     $sql = "SELECT * FROM feed {$where} ORDER BY time DESC {$limit}";
     $re = DB::query($sql);
     if ($re) {
         while ($feed = mysql_fetch_assoc($re)) {
             if ($feed['type'] == 1 || $feed['type'] == 2) {
                 // phan hoi
                 $item_comment_ids .= ($item_comment_ids != '' ? ',' : '') . $feed['ref_id'];
             } elseif ($feed['type'] == 3) {
                 // luu but
                 $user_comment_ids .= ($user_comment_ids != '' ? ',' : '') . $feed['ref_id'];
             } elseif ($feed['type'] == 5 || $feed['type'] == 6) {
                 // bai viet
                 $entry_comment_ids .= ($entry_comment_ids != '' ? ',' : '') . $feed['ref_id'];
             }
             /*elseif($feed['type']==7){// theo duoi						
             			$follow_ids.=($follow_ids!=''?',':'').$feed['ref_id'];
             		}*/
         }
     }
     //Phản hồi giao dịch
     $item_comment_arr = array();
     if ($item_comment_ids != '') {
         $item_ids = "";
         $re = DB::query("SELECT time, item_id, parent_id, COUNT(item_id) AS total_comment FROM comment WHERE id IN({$item_comment_ids}) GROUP BY item_id");
         if ($re) {
             while ($comment = mysql_fetch_assoc($re)) {
                 $item_ids .= ($item_ids != '' ? ',' : '') . $comment['item_id'];
                 $comment['time'] = AZLib::duration_time($comment['time']);
                 $item_comment_arr[$comment['item_id']] = $comment;
             }
             if ($item_comment_arr && $item_ids) {
                 // Query de lay ID va Tieu de tin
                 $re = DB::query("SELECT id, name, level_1_catid FROM item WHERE id IN({$item_ids})");
                 while ($item = mysql_fetch_assoc($re)) {
                     if ($item["id"] == $item_comment_arr[$item["id"]]["item_id"]) {
                         $item_comment_arr[$item["id"]]["item_name"] = AZLib::word_limit($item["name"], 7, '...');
                         $ebname = AZLib::safe_title($item['name']);
                         if (isset(CGlobal::$allCategories[$item['level_1_catid']])) {
                             $cat_name = CGlobal::$allCategories[$item['level_1_catid']]['name'];
                             $item_comment_arr[$item["id"]]["url_link"] = WEB_DIR . AZLib::safe_title($cat_name) . "/p{$item['id']}/{$ebname}.html";
                         } else {
                             $item_comment_arr[$item["id"]]["url_link"] = WEB_DIR . "/p{$item['id']}/{$ebname}.html";
                         }
                     }
                 }
             }
         }
         if ($item_comment_arr) {
             $item_comment_arrs["comment"] = $item_comment_arr;
             $arr_data += $item_comment_arrs;
         }
     }
     // End Phan hoi giao dich
     //Luu but
     $total_comment_arr = array();
     if ($user_comment_ids != '') {
         $re = DB::query("SELECT time, COUNT(id) AS total_comment_user FROM comment_user WHERE id IN({$user_comment_ids}) GROUP BY receiver_user_id ORDER BY time DESC");
         if ($re) {
             $comment_user = mysql_fetch_assoc($re);
             $total_comment_arr["total"] = $comment_user["total_comment_user"];
             $total_comment_arr['time'] = AZLib::duration_time($comment_user['time']);
             $total_comment_arr["url_link"] = WEB_DIR . 'Shop/' . User::user_name() . '/Luu-but';
         }
         if ($total_comment_arr) {
             $total_comment_arrs["comment_user"] = $total_comment_arr;
             $arr_data += $total_comment_arrs;
         }
     }
     //End Luu but
     // Theo duoi
     /*$follow_arr = array();
     		if($follow_ids!=''){
     			$re = DB::query("SELECT id, follower_name, time FROM follow WHERE id IN($follow_ids) ORDER BY time DESC");			
     			if($re){				
     				while ($follow = mysql_fetch_assoc($re)){										
     					$follow['time'] = AZLib::duration_time($follow['time']);
     					$follow["url_link"] = WEB_DIR.$follow['follower_name'];
     					$follow_arr[$follow['id']] = $follow;
     				}														
     			}							
     			if($follow_arr){
     				$follow_arrs["follow"] = $follow_arr;
     				$arr_data += $follow_arrs;
     			}
     		}*/
     // end Theo duoi
     // Phản hồi bài viết
     $entry_comment_arr = array();
     if ($entry_comment_ids != '') {
         $entry_ids = "";
         $re = DB::query("SELECT time, entry_id, parent_id FROM user_entry_comment WHERE id IN({$entry_comment_ids})");
         if ($re) {
             while ($comment_entry = mysql_fetch_assoc($re)) {
                 $entry_ids .= ($entry_ids != '' ? ',' : '') . $comment_entry['entry_id'];
                 $comment_entry['time'] = AZLib::duration_time($comment_entry['time']);
                 $comment_entry['total_comment_entry'] = count(explode(',', $entry_comment_ids));
                 $entry_comment_arr[$comment_entry['entry_id']] = $comment_entry;
             }
             if ($entry_comment_arr && $entry_ids) {
                 // Query de lay ID va Tieu de bai viet
                 $re = DB::query("SELECT id, title FROM user_entry WHERE id IN({$entry_ids})");
                 while ($entry = mysql_fetch_assoc($re)) {
                     if ($entry["id"] == $entry_comment_arr[$entry["id"]]["entry_id"]) {
                         $entry_comment_arr[$entry["id"]]["title"] = AZLib::word_limit($entry["title"], 7, '...');
                         $ebname = AZLib::safe_title($entry['title']);
                         $entry_comment_arr[$entry["id"]]["url_link"] = WEB_DIR . "Bai-viet/" . User::user_name() . "/e{$entry['id']}/{$ebname}";
                     }
                 }
             }
         }
         if ($entry_comment_arr) {
             $item_comment_arrs["entry"] = $entry_comment_arr;
             $arr_data += $item_comment_arrs;
         }
     }
     // End Phan hoi bài viết
     $json = json_encode($arr_data);
     echo $json;
     exit;
 }
Пример #19
0
 function build_rss()
 {
     $arr_cat = array(293);
     // dinh nghia mang cho cac danh muc co so luong tin nhieu
     $limit = 100;
     // mac dinh ban dau
     $limits = 200;
     // so luong ban ghi cho danh muc co nhieu tin
     $category_name = AZLib::getParam('ebname');
     $category_id = AZLib::getParam('cat_id');
     AZLib::getCats();
     if ($category_name != "" && $category_id == "") {
         foreach (CGlobal::$allCategories as $cat) {
             if ($cat['parent_id'] == 0 && AZLib::safe_title($cat['name']) == $category_name) {
                 $category = $cat;
                 break;
             }
         }
         header("Location:" . WEB_ROOT . "rss/c" . $category['id'] . "_" . $category_name . ".rss");
     }
     foreach (CGlobal::$allCategories as $cat) {
         if ($cat['parent_id'] == 0 && $cat['id'] == $category_id) {
             $category = $cat;
             break;
         }
     }
     if ($category) {
         $cat_id = $category['id'];
         $cat_name = trim(XMLLib::_xml_encode_attribute($category['name']));
         $subDir = 'rss1';
         $cachefile = 'rss1_' . $cat_id;
         header("content-type: text/xml");
         if (StaticCache::notExistCache($cachefile, 3600, false, $subDir)) {
             if (in_array($cat_id, $arr_cat)) {
                 $limit = $limits;
             }
             StaticCache::startCache();
             $rss = $this->build_rss_cat($cat_id, $cat_name, $limit);
             echo $rss;
             StaticCache::endCache();
         }
         //echo 'a';
     } else {
         REWRITE_ON ? header("Location:" . WEB_ROOT . "rss/") : header("Location:" . WEB_ROOT . "?page=rss");
     }
     System::halt();
 }
Пример #20
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("&#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;
                 }
             }
         }
         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');
 }
Пример #21
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');
    }