function draw() { //xoa 1 id if (Url::get("act") == "del" && Url::get('id')) { DB::query('DELETE FROM ban_ip WHERE id=' . Url::get('id')); Url::redirect_url(Url::build_all(array('chk_id', 'del_all', 'act', 'id'))); } global $display; //list $this->beginForm(); $items = array(); $sql = "SELECT * FROM ban_ip Order by id desc"; $result = DB::query($sql); while ($row = mysql_fetch_assoc($result)) { $row['create_time'] = date('d/m - h:i', $row['create_time']); $items[$row['id']] = $row; $arr_mem_cache[$row['ip']] = $row; } // cho mang vao memcache AZMemcache::do_put('list_ban_ip', $arr_mem_cache); $display->add('items', $items); $display->add('items_json', json_encode($items)); $display->output('ManageBanIp'); $this->endForm(); }
function draw() { global $display; $cmd = Url::get('cmd'); if ($cmd == 'update') { AZMemcache::do_put("prhot_ver:", 0); Url::redirect_current(); } $this->beginForm(); $list_cat = array(999999999 => 'Mặc định', 0 => 'Trang chủ'); $list_cat += AZLib::getTopCats(); $item = DB::fetch_all('SELECT item_id,status,product_hot_cat_id,end_time,start_time FROM product_hot'); $items_tmp = array(); foreach ($item as $values) { if (isset($list_cat[$values['product_hot_cat_id']])) { $items_tmp[$values['product_hot_cat_id']]['cat_name'] = $list_cat[$values['product_hot_cat_id']]; if ($values['status'] == 1) { $items_tmp[$values['product_hot_cat_id']]['item_vip'][$values['item_id']]['cat_id'] = $values['product_hot_cat_id']; $items_tmp[$values['product_hot_cat_id']]['item_vip'][$values['item_id']]['start_time'] = date("d/m/Y", $values['start_time']); $items_tmp[$values['product_hot_cat_id']]['item_vip'][$values['item_id']]['end_time'] = date("d/m/Y", $values['end_time']); } else { $items_tmp[$values['product_hot_cat_id']]['item'][$values['item_id']] = $values['product_hot_cat_id']; } } } $items = array(); foreach ($list_cat as $key => $values) { if (isset($items_tmp[$key])) { $items[$key] = $items_tmp[$key]; } } $display->add('items', $items); $display->output('ManageProductHot'); $this->endForm(); }
static function delete_images($id) { $row = DB::select('item_image', 'id=' . $id); if ($row) { if ($row['root_id']) { //Ảnh gốc DB::delete('item_image', 'root_id=' . $row['root_id']); } else { DB::delete('item_image', 'id=' . $id); } //update memcache IMG $sql = "SELECT item_id FROM item_image WHERE (id = {$id} OR root_id = {$id}) " . (User::have_permit(ADMIN_IMAGE) ? '' : " AND user_id=" . User::id()); $re = DB::query($sql); if ($re) { $item = mysql_fetch_assoc($re); if ($item["item_id"]) { require_once ROOT_PATH . 'core/Item.php'; Item::get_item_images($item["item_id"], 1); } } //update memcache IMG if ($row['img_url']) { if (DB::query("UPDATE item SET img_url='' WHERE img_url='" . $row['img_url'] . "'") && MEMCACHE_ON) { $sql = "SELECT * FROM item WHERE img_url = '{$row['img_url']}'"; $re = DB::query($sql); while ($item_memcache = mysql_fetch_assoc($re)) { $item_memcache['img_server'] = 0; $item_memcache['img_url'] = ''; AZMemcache::do_put("item:" . $item_memcache['id'], $item_memcache); } } AZLib::ftp_image_delete_file($row['img_url'], $row['img_server']); } } }
static function connect() { if (!CGlobal::$memcache_connect_id && !AZMemcache::$crashed) { if (!function_exists('memcache_connect')) { //dl("php_memcache.dll"); //dl("php_xdebug.dll"); AZMemcache::$crashed = 1; return FALSE; } AZMemcache::$identifier = MEMCACHE_ID; if (!CGlobal::$memcache_server || !count(CGlobal::$memcache_server)) { AZMemcache::$crashed = 1; return FALSE; } if (DEBUG) { $rtime = microtime(); $rtime = explode(" ", $rtime); $rtime = $rtime[1] + $rtime[0]; $start_rb = $rtime; } for ($i = 0, $n = count(CGlobal::$memcache_server); $i < $n; $i++) { $server = CGlobal::$memcache_server[$i]; if ($i < 1) { CGlobal::$memcache_connect_id = memcache_connect($server['host'], $server['port']); } else { memcache_add_server(CGlobal::$memcache_connect_id, $server['host'], $server['port']); } if (DEBUG) { $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $end_rb = $mtime; $load_time = round($end_rb - $start_rb, 5) . "s"; CGlobal::$conn_debug .= " <b>Connect to Memcache server : {$server['host']} : {$server['port']} </b> [in {$load_time}]<br>\n"; } } if (!CGlobal::$memcache_connect_id) { AZMemcache::$crashed = 1; return FALSE; } if (function_exists('memcache_set_compress_threshold')) { memcache_set_compress_threshold(CGlobal::$memcache_connect_id, 20000, 0.2); } memcache_debug(AZMemcache::$debug); } return CGlobal::$memcache_connect_id; }
function ManageBookingVip($row) { Module::Module($row); if (User::have_permit(ADMIN_VIP_ITEM) || User::have_permit(ADMICRO_BOOKING_VIP)) { $cmd = Url::get('cmd'); switch ($cmd) { case '': require_once 'forms/ManageBookingVip.php'; $this->add_form(new ManageBookingVipForm()); break; case 'add': require_once 'forms/AddBookingVip.php'; $this->add_form(new AddBookingVipForm()); break; case 'active': if (User::have_permit(ADMIN_VIP_ITEM)) { $id = (int) Url::get("id", 0); if ($id) { $booking_vip = DB::select("bookings_vip", "id={$id}"); } $booking_vip['top_cat'] != 0 ? $cat_id = $booking_vip['top_cat'] : ($cat_id = $booking_vip['cat_id']); $item_vip = DB::select_all('item_vip', "(catid = {$cat_id} OR level_1_catid = {$cat_id}) AND status = 1"); $i = 0; $sa = $booking_vip['time_start']; $ea = $booking_vip['time_end']; foreach ($item_vip as $itemv) { if ($sa > $itemv['time_start'] && $sa < $itemv['time_end']) { $i++; } elseif ($ea > $itemv['time_start'] && $ea < $itemv['time_end']) { $i++; } elseif ($sa < $itemv['time_start'] && $ea > $itemv['time_end']) { $i++; } } $priority = 1; $arrItemVip = array('item_id' => $booking_vip['item_id'], 'note' => "Add từ bảng booking vip cho [{$booking_vip['user_add']}]", 'time_start' => $booking_vip['time_start'], 'time_end' => $booking_vip['time_end'], 'time_add' => TIME_NOW, 'user_add' => User::user_name(), 'time_modify' => TIME_NOW, 'user_modify' => User::user_name(), 'catid' => $booking_vip['cat_id'], 'level_1_catid' => $booking_vip['top_cat'], 'num_contract' => $booking_vip['num_contract'], 'priority' => $priority); //insert $idVip = DB::insert("item_vip", $arrItemVip); if ($idVip) { $item_id = $booking_vip['item_id']; $item = Item::get_item($item_id); if ($booking_vip['time_start'] >= TIME_NOW || $booking_vip['time_end'] <= TIME_NOW) { $priority = 0; } DB::update("item", array("sticky" => $priority), "id={$item_id}"); if (MEMCACHE_ON) { $item['sticky'] = $priority; AZMemcache::do_put("item:{$item_id}", $item); AZMemcache::do_remove("id_vip:{$item['category_id']}"); AZMemcache::do_remove("id_vip:{$item['level_1_catid']}"); } } //update status DB::update('bookings_vip', array("status" => 1, "time_update_status" => TIME_NOW, "user_update_status" => User::user_name()), "id={$id}"); } Url::redirect_current(); break; case 'update_status': if (User::have_permit(ADMIN_VIP_ITEM)) { $id = (int) Url::get("id", 0); DB::update('bookings_vip', array("status" => 1, "time_update_status" => TIME_NOW, "user_update_status" => User::user_name()), "id={$id}"); } Url::redirect_current(); break; case 'edit': require_once 'forms/EditBookingVip.php'; $this->add_form(new EditBookingVipForm()); break; case 'delete': $id = (int) Url::get("id", 0); $booking_vip = array(); if ($id) { $booking_vip = DB::select("bookings_vip", "id={$id}"); } if ($booking_vip && $booking_vip['status'] != 1) { if (User::user_name() == $booking_vip['user_add'] || User::have_permit(ADMIN_VIP_ITEM)) { DB::update('bookings_vip', array("status" => -1, "time_del" => TIME_NOW, "user_del" => User::user_name()), "id={$id}"); } } Url::redirect_current(); break; default: Url::redirect_current(); break; } } else { Url::access_denied(); } }
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')); } } }
function set_schedule_up() { $item_id = (int) Url::get('item_id', 0); $response = array(); if ($item_id > 0 && User::is_login() && !User::is_block()) { $user = array(); $item = array(); $up_item = array(); $up_items = array(); $user = array(); $item = Item::get_item($item_id); if ($item && $item['status'] != -1) { $response['item_id'] = $item_id; $response['reload_page'] = (int) Url::get('reload_page', 0); if (User::id() == $item['user_id']) { $up_rows = array(); //Bản ghi up lịch $user = DB::select('user', "id={$item['user_id']}"); $re = DB::query("SELECT * FROM up_item_schedule WHERE item_id={$item_id} ORDER BY run_order"); if ($re) { while ($s_item = mysql_fetch_assoc($re)) { $up_rows[] = $s_item; } } if ($up_rows) { $up_exist = true; $up_item = $up_rows[0]; foreach ($up_rows as $u_item) { if ($u_item['up_remain'] > $up_item['up_remain']) { $up_item['up_remain'] = $u_item['up_remain']; } } if ($up_item['up_remain'] < 0) { $up_item['up_remain'] = 0; } } else { $up_exist = false; $up_item = array("up_remain" => 0, "time_add" => TIME_NOW); /*$response['msg'] = "not_exist"; echo json_encode($response); exit;*/ } ################################################################################## #Ngày up trong tuần $week_day_arr = Url::get('week_day'); if ($week_day_arr) { $week_day_tmp = array(2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0); foreach ($week_day_arr as $wday => $val) { if (isset($week_day_tmp[$wday])) { $week_day_tmp[$wday] = (int) (bool) $val; } } $week_day = implode('|', $week_day_tmp); } else { $response['msg'] = "choose_wday"; echo json_encode($response); //'Bạn phải chọn ngày up trong tuần!' exit; } ################################################################################## ################################################################################## #Thời điểm up mỗi ngày $string_up_time = Url::get('string_up_time'); if ($string_up_time != '') { $arr_time = explode('|', $string_up_time); $run_hours = array(); //Giờ từng lượt up $run_mins = array(); //Phút từng lượt up $time_temp = array(); //Thời điểm up tính từ mốc 0 của thời gian foreach ($arr_time as $value) { $arr_temp = explode(':', $value); $uTime = mktime($arr_temp[0], $arr_temp[1], 0, 0, 0, 0); $complain = false; /*foreach ($time_temp as $time_val) { if ($uTime == $time_val) { $complain = true; } else { $complain = false; } } if(!$complain) { $time_temp[] = $uTime; } */ if (!in_array($uTime, $time_temp)) { $time_temp[] = $uTime; //Cho vào mảng thời điểm up tạm } } sort($time_temp); //Sắp xếp thứ tự foreach ($time_temp as $val) { $run_hours[] = date('H', $val); $run_mins[] = date('i', $val); } ################################################################################## $up_remain = (int) Url::get('up_remain', 0); //Tổng số lần up cho cả lịch up if ($up_remain < 0) { $up_remain = 0; } $run_times = array(); $last_time = 0; $i = 1; $first_time = 1; //lần up đầu tiên if ($run_hours) { $wday_now = date('N', time()) - 1; foreach ($run_hours as $stt => $hour) { if (isset($run_mins[$stt])) { $cur_time = mktime($hour, $run_mins[$stt], 0, date('m', TIME_NOW), date('d', TIME_NOW), date('Y', TIME_NOW)); if ($last_time) { if ($cur_time <= $last_time + 899) { continue; //Bỏ qua /*$response['msg'] = "run_hour_error"; $response['alert'] = "Thời gian lượt up thứ $i phải muộn hơn lần up thứ ".($i-1)." ít nhất 15 phút!"; echo json_encode($response); exit;*/ } } $last_time = $cur_time; $arr = explode('|', $week_day); $wday_up = $wday_now; //Tính thời gian up kế tiếp của bản ghi $time_next_run = $cur_time; if ($time_next_run <= TIME_NOW + 5 || !isset($arr[$wday_up]) || isset($arr[$wday_up]) && !$arr[$wday_up]) { $first_time++; //$wday_up = $wday_now; $w_temp = $wday_up++; while ($wday_up < 7) { if (isset($arr[$wday_up]) && $arr[$wday_up]) { $time_next_run = $cur_time + 86400 * ($wday_up - $wday_now); if ($time_next_run > TIME_NOW + 5) { //nếu thời gian up kế tiếp lớn hơn thời gian hiện tại + 5 giây break; } } $wday_up++; } if (!isset($arr[$wday_up]) || isset($arr[$wday_up]) && !$arr[$wday_up]) { $wday_up = 0; //while ($wday_up<7){ while ($wday_up < $w_temp) { if (isset($arr[$wday_up]) && $arr[$wday_up]) { $time_next_run = $cur_time + 86400 * (7 - $wday_now + $wday_up); if ($time_next_run > TIME_NOW + 5) { //nếu thời gian up kế tiếp lớn hơn thời gian hiện tại + 5 giây break; } } $wday_up++; } } } $run_times[] = array('time_run' => str_pad($hour, 2, "0", STR_PAD_LEFT) . '-' . str_pad($run_mins[$stt], 2, "0", STR_PAD_LEFT), 'time_next_run' => $time_next_run); $i++; } } } if ($run_times) { $up_per_day = count($run_times); foreach ($run_times as $stt => $time) { $stt++; $up_items[] = array('run_order' => $stt, 'time_run' => $time['time_run'], 'time_next_run' => $time['time_next_run']); } } else { $response['msg'] = "run_hour"; echo json_encode($response); //'Bạn phải chọn ít nhất 1 lần up / ngày!' exit; } if ($first_time > $up_per_day) { $first_time = 1; } $up_item['status'] = (int) Url::get('status', 0); //0:tat,1:bat if ($up_remain <= 0) { $response['msg'] = "up_zero"; echo json_encode($response); //Chưa nhập lượt up exit; } if ($up_item['up_remain'] != $up_remain) { if ($user['up_item'] + $up_item['up_remain'] < $up_remain) { //Tài khoản ko đủ để tăng tổng số lượt up sẽ dùng cho tin $up_remain = $user['up_item'] + $up_item['up_remain']; if ($up_remain <= 0) { $response['msg'] = "up_over"; echo json_encode($response); //Chưa nhập lượt up exit; } } $user_up_remain = $user['up_item'] + $up_item['up_remain'] - $up_remain; if ($user_up_remain < 0) { $user_up_remain = 0; } DB::query("UPDATE user SET up_item={$user_up_remain} WHERE id=" . $user['id']); User::getUser($user['id'], 0, 1); } if ($up_item['status'] && $up_remain <= 0) { $status = 2; } elseif ($item["status"] == -1 || $item["status"] == 0 || $item["status"] == 2 || $item["status"] == 3) { $status = 3; } else { $status = $up_item['status']; } ############################################################################# #Cập nhật cho tin if ($item['is_up_auto'] != 1) { DB::query("UPDATE item SET is_up_auto = 1 WHERE id= {$item_id}"); if (MEMCACHE_ON) { $item['is_up_auto'] = 1; AZMemcache::do_put("item:{$item_id}", $item); } } ############################################################################# $del_ids = ''; $add_sql = ''; $up_total = $up_remain; $up_item['up_remain'] = $up_remain; if ($up_items) { foreach ($up_items as $key => $u_item) { if ($u_item['run_order'] < $first_time) { $up_remain = $up_total - ($up_per_day - $first_time) - $u_item['run_order']; } else { $up_remain = $up_total - ($u_item['run_order'] - $first_time); } if (isset($up_rows[$key])) { DB::update('up_item_schedule', array('user_id' => $user['id'], 'user_name' => $user['user_name'], 'item_id' => $item['id'], 'des' => $item['name'], 'time_modify' => TIME_NOW, 'run_order' => $u_item['run_order'], 'up_per_day' => $up_per_day, 'week_day' => $week_day, 'time_run' => $u_item['time_run'], 'time_next_run' => $u_item['time_next_run'], 'up_remain' => $up_remain, 'up_total' => $up_total, 'status' => $status), "id={$up_rows[$key]['id']}"); unset($up_rows[$key]); } else { //$add_sql="INSERT INTO up_item_schedule (user_id,user_name,item_id,des,time_add,time_modify,run_order,week_day,time_run,time_next_run,up_remain,up_total,status) VALUES ".$add_sql; $add_sql .= ($add_sql ? ",\n" : "") . "({$user['id']},'{$user['user_name']}',{$item['id']},\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$item['name']}',{$up_item['time_add']}," . TIME_NOW . ",{$u_item['run_order']},{$up_per_day},\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$week_day}','{$u_item['time_run']}',{$u_item['time_next_run']},\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$up_remain},{$up_total},{$status})"; } } } if ($up_rows) { foreach ($up_rows as $u_item) { $del_ids .= ($del_ids ? ',' : '') . $u_item['id']; } } if ($add_sql) { $add_sql = "INSERT INTO up_item_schedule (user_id,user_name,item_id,des,time_add,time_modify,run_order,up_per_day,week_day,time_run,time_next_run,up_remain,up_total,status) VALUES " . $add_sql; DB::query($add_sql); } if ($del_ids) { DB::delete("up_item_schedule", "id IN({$del_ids})"); } $response['msg'] = "success"; echo json_encode($response); exit; } else { $response['msg'] = "run_hour"; echo json_encode($response); //'Bạn phải chọn ít nhất 1 lần up / ngày!' exit; } } } else { //delete schedule here... DB::query("UPDATE up_item_schedule SET status=3 WHERE item_id={$item_id}"); echo "item_not_exist"; exit; } } $response['msg'] = "invalid"; echo json_encode($response); exit; }
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('"'), 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('"'), 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)); } } }
function update_user_online() { $user_id = isset($_SESSION['user_id']) ? (int) $_SESSION['user_id'] : 0; $session_id = session_id(); $page = ''; $page_id = 0; $user_name = isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 0; $login_type = isset($_SESSION['openid_url']) && $_SESSION['openid_url'] != '' ? 1 : 0; $open_id = isset($_SESSION['openid_url']) && $_SESSION['openid_url'] != '' ? $_SESSION['openid_url'] : ''; if (class_exists('AZNet')) { $page = AZNet::$page['name']; $page_id = (int) AZNet::$page['id']; } if (($page == 'ItemDetail' || $page == 'item_detail') && isset($_GET['id']) && $_GET['id']) { $item_id = (int) $_GET['id']; } else { $item_id = 0; } if (in_array(basename($_SERVER['PHP_SELF']), array('ebxml.php', 'ajax.php', 'captcha.php'))) { $ref_url = ''; } else { AZLib::check_uri(); $ref_url = CGlobal::$query_string; } $sql = "SELECT session_referer, page, page_id, item_id FROM " . _SESS_TABLE . " WHERE session_id = '{$session_id}'"; $result = DB::query($sql, __LINE__ . __FILE__); if (mysql_num_rows($result)) { $s_row = mysql_fetch_assoc($result); } else { $s_row = array(); } if ($s_row) { if ($ref_url == '' || in_array(basename($_SERVER['PHP_SELF']), array('ebxml.php', 'ajax.php', 'captcha.php'))) { $ref_url = stripslashes($s_row['session_referer']); } if (!$page) { $page = $s_row['page']; } if (!$page_id) { $page_id = (int) $s_row['page_id']; } if (!$item_id) { $item_id = (int) $s_row['item_id']; } $sql = "UPDATE " . _SESS_TABLE . " SET\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tsession_expires = " . time() . ", \r\n\t\t\t\t\t\t\t\t\t\t\t\t \tsession_referer = '" . addslashes($ref_url) . "',\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tsession_ip \t\t= '" . $_SERVER['SERVER_ADDR'] . '::' . $_SERVER['REMOTE_ADDR'] . "', \r\n\t\t\t\t\t\t\t\t\t\t\t\t \tpage \t\t\t= '{$page}',\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tpage_id \t\t= {$page_id},\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tcategory_id \t= " . CGlobal::$curCategory . ",\r\n\t\t\t\t\t\t\t\t\t\t\t\t \titem_id \t\t= {$item_id},\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tuser_id \t\t= '{$user_id}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tuser_name\t\t= '{$user_name}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tlogin_type\t\t= '{$login_type}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t \topen_id\t\t\t= '{$open_id}'\r\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE session_id \t= '{$session_id}'"; } else { $sql = "INSERT INTO " . _SESS_TABLE . " \r\n\t\t\t\t\t\t\t\t (\r\n\t\t\t\t\t\t\t\t \tsession_id, \r\n\t\t\t\t\t\t\t\t \tsession_expires, \r\n\t\t\t\t\t\t\t\t \tsession_referer, \r\n\t\t\t\t\t\t\t\t \tsession_ip, \r\n\t\t\t\t\t\t\t\t \tpage, \r\n\t\t\t\t\t\t\t\t \tpage_id, \r\n\t\t\t\t\t\t\t\t \tcategory_id, \r\n\t\t\t\t\t\t\t\t \titem_id, \r\n\t\t\t\t\t\t\t\t \tuser_id, \r\n\t\t\t\t\t\t\t\t \tuser_name,\r\n\t\t\t\t\t\t\t\t \tlogin_type,\r\n\t\t\t\t\t\t\t\t \topen_id\r\n\t\t\t\t\t\t\t\t \t) \r\n\t\t VALUES (\r\n\t\t \t\t\t'{$session_id}', \t\t\t\t\r\n\t\t \t\t\t" . time() . ", \t\t\t\r\n\t\t \t\t\t'" . addslashes($ref_url) . "', \t \r\n\t\t \t\t\t'" . $_SERVER['SERVER_ADDR'] . '::' . $_SERVER['REMOTE_ADDR'] . "',\t\r\n\t\t \t\t\t'{$page}',\t \r\n\t\t \t\t\t{$page_id},\t\t \r\n\t\t \t\t\t" . CGlobal::$curCategory . ", \t\t \r\n\t\t \t\t\t{$item_id}, \t \r\n\t\t \t\t\t{$user_id} ,\t\t\r\n\t\t \t\t\t'{$user_name}' ,\t\t\r\n\t\t \t\t\t{$login_type} ,\t\t\r\n\t\t \t\t\t'{$open_id}')"; } DB::query($sql, __LINE__ . __FILE__); if (User::is_login() && MEMCACHE_ON) { $user = User::$current->data; if ($user && !isset($user['last_login']) || isset($user['last_login']) && $user['last_login'] < TIME_NOW - 300) { DB::query("UPDATE user SET last_login="******" WHERE id={$user['id']}"); $user_memcache = AZMemcache::do_get("user:{$user['id']}"); if ($user_memcache) { $user_memcache['last_login'] = TIME_NOW; AZMemcache::do_put("user:{$user['id']}", $user_memcache); } } } if (StaticCache::notExistCache('del_exs', 1)) { //Run 1 cronjob/15s StaticCache::startCache(); StaticCache::endCache(); DB::query("DELETE FROM " . _SESS_TABLE . " WHERE session_expires <= " . (time() - _SESS_TIME_EXPIRE)); } }
function remove_mem() { if (!User::is_login()) { echo "not_login"; exit; } if (User::is_block()) { echo "no_permission"; exit; } if (User::have_permit(ADMIN_ITEM)) { $item_id = AZLib::getParam('item_id'); $id = "item:{$item_id}"; AZMemcache::do_remove($id); echo "success"; } else { die("no_permission"); } }
function del_comment() { if (!User::is_login() || User::is_block()) { echo "not_perm"; exit; } $id = (int) Url::get("id"); if ($id) { $comment = DB::fetch("SELECT item_id,sender_user_id,display,receiver_user_id,have_child,parent_id FROM comment WHERE id={$id}"); /*$current_user = User::$current->data; if($current_user['up_item'] == 0){ echo "not_up_item"; exit(); }*/ if (User::have_permit(ADMIN_ITEM) || User::id() == $comment['receiver_user_id'] && $comment['sender_user_id'] == 0) { if (DB::delete('comment', 'id=' . $id)) { if ($comment['have_child'] > 0) { DB::delete('comment', 'parent_id=' . $id); } if ($comment['item_id'] > 0) { $item_id = $comment['item_id']; if ($comment['parent_id'] > 0) { DB::query('UPDATE comment SET have_child = have_child-1 WHERE id=' . $comment['parent_id'] . ' '); if ($comment['display'] == 1) { DB::query('UPDATE comment SET display = 1 where item_id = ' . $comment['item_id'] . ' AND parent_id = ' . $comment['parent_id'] . ' AND display = 0 order by id DESC limit 1'); } } if ($item_id) { $item = Item::get_item($item_id); $item_memcache = $item; if ($item) { $item_memcache['reply_count'] = $item['reply_count'] - (1 + $comment['have_child']); if (MEMCACHE_ON) { AZMemcache::do_put("item:{$item_id}", $item_memcache); } DB::query('UPDATE item SET reply_count = ' . $item_memcache['reply_count'] . ' WHERE id="' . $comment['item_id'] . '" '); } } } //del cache html $caheFile = 'fb_' . $item['id']; StaticCache::delCache($caheFile); /*if(!User::have_permit(ADMIN_ITEM)){ DB::query('UPDATE user set up_item = up_item-1 WHERE id='.$comment['receiver_user_id'].' AND up_item>0');// tru luot up User::getUser($comment['receiver_user_id'],0,1); }*/ echo AZLib::getParam('id'); exit; } else { echo "unsuccess"; exit; } } else { echo "not_perm"; exit; } } else { echo "not_perm"; exit; } }
function lockItemWhenLockAccount($value = array(), $is_lock = 1) { // $is_lock = 1: lock, $is_lock = 0: Unlock $user_id = $value["user_id"]; $reason_invalid = isset($value["reason_invalid"]) ? $value["reason_invalid"] : ""; if ($user_id) { $user = User::getUser($user_id); } if ($is_lock == 0 && User::have_permit(array(ADMIN_USER))) { $sql = 'SELECT id, admin_id, time FROM user_lock WHERE user_id = ' . $user_id . ' AND type = 0 ORDER BY id DESC LIMIT 1'; $user_invalid = DB::fetch($sql); if (isset($user_invalid["id"])) { $sql = "SELECT * FROM item WHERE user_id = {$user_id} AND state = 1"; $re = DB::query($sql); while ($item = mysql_fetch_assoc($re)) { $sql = "SELECT user_id, lock_time FROM item_lock WHERE item_id = {$item['id']} ORDER BY id DESC LIMIT 1"; $re_lock = DB::query($sql); $item_lock = mysql_fetch_assoc($re_lock); if ($item_lock["lock_time"] == $user_invalid["time"] && $item_lock["user_id"] == $user_invalid["admin_id"]) { if (MEMCACHE_ON) { $item_memcache = AZMemcache::do_get("item:{$item['id']}"); $item_memcache['state'] = 0; AZMemcache::do_put("item:" . $item_memcache['id'], $item_memcache); } DB::update('item', array('state' => 0), "id={$item['id']}"); } } } } elseif ($is_lock == 1) { // chi thuc hien voi khoa theo ngay $sql_item = 'SELECT id FROM item WHERE user_id = ' . $user_id . ' AND status = 1 AND state=0'; $re_item = DB::query($sql_item); while ($item = mysql_fetch_assoc($re_item)) { $sql_insert = "INSERT INTO item_lock (item_id, user_id \t,user_name, lock_time, reason_lock) VALUES ({$item['id']}," . User::id() . ",'" . User::user_name() . "'," . TIME_NOW . ",'" . $reason_invalid . "')"; DB::query($sql_insert); } if (MEMCACHE_ON) { $sql = "SELECT * FROM item WHERE user_id = {$user_id} AND status = 1"; $re = DB::query($sql); while ($item_memcache = mysql_fetch_assoc($re)) { $item_memcache['state'] = 1; AZMemcache::do_put("item:" . $item_memcache['id'], $item_memcache); } } DB::update('item', array('state' => "1"), 'user_id = ' . $user_id . ' AND status = 1'); $receiver_user = User::getUser($user_id); $link_help = 'http://help.enbac.com/index.php/Quy_%C4%91%E1%BB%8Bnh_%C4%91%C4%83ng_tin'; $title_pm = 'Thông báo từ EnBac'; $content_pm = 'Tất cả tin đăng của bạn đã bị khóa với lý do: ' . $reason_invalid . ' Đề nghị bạn hãy thực hiện đúng các quy định của Én Bạc. Xin cảm ơn bạn. 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); } }
function process_description($item_detail) { if (!isset($item_detail["filter_des"]) || $item_detail["filter_des"] == "") { ################################################################################################################################ //$filter_des = preg_replace('#(<[/]?img.*>)#iU', '', html_entity_decode($item_detail['description'])); $filter_des = preg_replace('#(<[/]?img.*>)#iU', '', html_entity_decode($item_detail['description'], ENT_QUOTES, "UTF-8")); $filter_des = preg_replace('#(<[/]?iframe.*>.*</iframe>)#iU', '', $filter_des); //$filter_des = preg_replace('#(<[/]?script.*>.*</script>)#iU', '', $filter_des); //$filter_des = preg_replace('#(<[/]?style.*>.*</style>)#iU', '', $filter_des); //Loại bỏ thẻ CDATA // <![CDATA[ //window.location='http://otothegioi.vn/raovat/HOT/Honda%20Accord%202.0%20Model%202011/re.html'; // ]]> //$filter_des = str_replace(array('<![CDATA[',']]>'), "", $filter_des); //$filter_des = str_replace(array('window.location'), "", $filter_des); //TuanNK edit 2010.08.17 //$filter_des = str_replace(array('>','<'), array(">","<"), $filter_des); $filter_des = strip_tags($filter_des, '<p><a><span><table><tr><td><th><br><strong><b><i><em><li><ol><ul><hr><u><font><strike>'); $filter_des = preg_replace("/\\[([\\s]*[0-9]{1,2}|100[\\s]*)\\]/eis", "\$this->embeded('\$1')", $filter_des); $filter_des = preg_replace('/<a[\\s]*(.*)[\\s]*href=[\'"](.*)[\'"][\\s]*[^>]*[\\s]*>(.*)<\\/a>/eisU', "\$this->filter_link('\$2','\$3')", $filter_des); ################################################################################################################################ ################################################################################################################################ $filter_brief = preg_replace('#(<[/]?img.*>)#iU', '', html_entity_decode($item_detail['brief'], ENT_QUOTES, "UTF-8")); $filter_brief = preg_replace('#(<[/]?iframe.*>.*</iframe>)#iU', '', $filter_brief); $filter_brief = strip_tags($filter_brief, '<p><a><span><table><tr><td><th><br><strong><b><i><em><li><ol><ul><hr><u><font><strike>'); $filter_brief = preg_replace("/\\[([\\s]*[0-9]{1,2}|100[\\s]*)\\]/eis", "\$this->embeded('\$1')", $filter_brief); $filter_brief = preg_replace('/<a[\\s]*(.*)[\\s]*href=[\'"](.*)[\'"][\\s]*[^>]*[\\s]*>(.*)<\\/a>/eisU', "\$this->filter_link('\$2','\$3')", $filter_brief); ################################################################################################################################ if (MEMCACHE_ON) { $item_memcache = AZMemcache::do_get("item:{$item_detail["id"]}"); $item_memcache["filter_brief"] = $filter_brief; $item_memcache["filter_des"] = $filter_des; AZMemcache::do_put("item:{$item_detail["id"]}", $item_memcache); } return array('filter_brief' => $filter_brief, 'filter_des' => $filter_des); } else { return array('filter_brief' => $item_detail["filter_brief"], 'filter_des' => $item_detail["filter_des"]); } }
function on_submit() { $ids = isset($_POST['chk_id']) ? $_POST['chk_id'] : array(); if (count($ids) > 0) { if (Url::get('hd_ac') == 'block_all') { $user_ids = ''; for ($i = 0; $i < count($ids); $i++) { if ($ids[$i] && $ids[$i] != User::id() && $ids[$i] != 1) { $user_ids .= ($user_ids ? ',' : '') . $ids[$i]; } } if ($user_ids) { $time_expire = TIME_NOW + BAN_NICK_DATE * 24 * 3600; DB::update('user', array('block_time' => $time_expire), 'id IN(' . $user_ids . ')'); $re = DB::query('SELECT id,user_name FROM user WHERE id IN(' . $user_ids . ')'); if ($re) { while ($user = mysql_fetch_assoc($re)) { DB::insert('user_lock', array('time' => TIME_NOW, 'time_expire' => $time_expire, 'user_id' => $user['id'], 'user_name' => $user['user_name'], 'type' => 0, 'note' => 'admin khóa', 'admin_id' => User::id(), 'admin_name' => User::user_name())); User::getUser($user['id'], 0, 1); } } } } if (Url::get('hd_ac') == 'lock_die_all') { //Khoá vĩnh viễn + khoá cookies $user_ids = ''; for ($i = 0; $i < count($ids); $i++) { if ($ids[$i] && $ids[$i] != User::id() && $ids[$i] != 1) { $user_ids .= ($user_ids ? ',' : '') . $ids[$i]; } } if ($user_ids) { $this->lock_user($user_ids); DB::update('user', array('block_time' => -1), 'id IN(' . $user_ids . ')'); $re = DB::query('SELECT id, user_name FROM user WHERE id IN(' . $user_ids . ')'); if ($re) { while ($user = mysql_fetch_assoc($re)) { DB::insert('user_lock', array('time' => TIME_NOW, 'user_id' => $user['id'], 'user_name' => $user['user_name'], 'type' => 3, 'admin_id' => User::id(), 'admin_name' => User::user_name())); User::getUser($user['id'], 0, 1); } } } } elseif (Url::get('hd_ac') == 'lock_die_all_not_cookies') { //Khoá vĩnh viễn nhiều thành viên không khóa cookies $user_ids = ''; for ($i = 0; $i < count($ids); $i++) { if ($ids[$i] && $ids[$i] != User::id() && $ids[$i] != 1) { $user_ids .= ($user_ids ? ',' : '') . $ids[$i]; } } if ($user_ids) { $this->lock_user($user_ids); DB::update('user', array('block_time' => -1), 'id IN(' . $user_ids . ')'); $re = DB::query('SELECT id, user_name FROM user WHERE id IN(' . $user_ids . ')'); if ($re) { while ($user = mysql_fetch_assoc($re)) { DB::insert('user_lock', array('time' => TIME_NOW, 'user_id' => $user['id'], 'user_name' => $user['user_name'], 'type' => 1, 'admin_id' => User::id(), 'admin_name' => User::user_name())); User::getUser($user['id'], 0, 1); } } } } elseif (Url::get('hd_ac') == 'invalid_all') { //Kiểm duyệt nhiều thành viên $user_ids = ''; for ($i = 0; $i < count($ids); $i++) { if ($ids[$i] && $ids[$i] != User::id() && $ids[$i] != 1) { $user_ids .= ($user_ids ? ',' : '') . $ids[$i]; } } if ($user_ids) { $time_expire = TIME_NOW + 7 * 24 * 3600; DB::update('user', array('invalid_time' => $time_expire), 'id IN(' . $user_ids . ')'); $re = DB::query('SELECT id,user_name FROM user WHERE id IN(' . $user_ids . ')'); if ($re) { while ($user = mysql_fetch_assoc($re)) { DB::insert('user_lock', array('time' => TIME_NOW, 'time_expire' => $time_expire, 'user_id' => $user['id'], 'user_name' => $user['user_name'], 'type' => 2, 'note' => 'Kiểm duyệt nhiều thành viên', 'admin_id' => User::id(), 'admin_name' => User::user_name())); User::getUser($user['id'], 0, 1); } } $sql_item = 'SELECT id FROM item where user_id IN (' . $user_ids . ') AND status = 1'; $re_item = DB::query($sql_item); if ($re_item) { while ($item = mysql_fetch_assoc($re_item)) { $sql_insert = "INSERT INTO bad_content (`type`,`id_item`,`user_id`,`user_name`,`reason`,`time_post`) VALUES (2,{$item['id']}," . User::id() . ",'" . User::user_name() . "','Kiểm duyệt do thành viên bị kiểm duyệt'," . time() . ")"; DB::query($sql_insert); } if (MEMCACHE_ON) { $sql = "SELECT * FROM item WHERE user_id IN({$user_ids}) AND status = 1"; $re = DB::query($sql); while ($item_memcache = mysql_fetch_assoc($re)) { $item_memcache['status'] = 2; $item_memcache['modify_time'] = TIME_NOW; $item_memcache['modify_user_name'] = User::user_name(); AZMemcache::do_put("item:" . $item_memcache['id'], $item_memcache); } } DB::update('item', array('status' => "2", 'modify_time' => time(), 'modify_user_name' => User::user_name()), 'user_id IN(' . $user_ids . ') AND status = 1'); } } } elseif (Url::get('hd_ac') == 'del_all') { //Xoá nhiều thành viên if (User::is_root()) { $user_ids = ''; for ($i = 0; $i < count($ids); $i++) { if ($ids[$i] && $ids[$i] != User::id() && $ids[$i] != 1) { $user_ids .= ($user_ids ? ',' : '') . $ids[$i]; } } //Xoá users: if ($user_ids) { $this->del_user($user_ids); } } } elseif (Url::get('hd_ac') == 'unlock_die_all') { // Mở khoá nhiều thành viên $user_ids = ''; for ($i = 0; $i < count($ids); $i++) { if ($ids[$i] && $ids[$i] != User::id() && $ids[$i] != 1) { $user_ids .= ($user_ids ? ',' : '') . $ids[$i]; } } if ($user_ids) { DB::update('user', array('block_time' => 0), 'id IN(' . $user_ids . ')'); User::getUser($id, 1, true); } } Url::redirect_url(Url::build_all(array('chk_id', 'del_all', 'cmd', 'id', 'lock_die_all', 'hd_ac'))); } }
/** * Write the session * @param int session id * @param string data of the session */ function write($session_id, $data) { $page = ''; $page_id = 0; $user_id = isset($_SESSION['user_id']) ? (int) $_SESSION['user_id'] : 0; $user_name = isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 0; $login_type = isset($_SESSION['openid_url']) && $_SESSION['openid_url'] != '' ? 1 : 0; $open_id = isset($_SESSION['openid_url']) && $_SESSION['openid_url'] != '' ? $_SESSION['openid_url'] : ''; if (class_exists('AZNet')) { $page = AZNet::$page['name']; $page_id = (int) AZNet::$page['id']; } if (($page == 'ItemDetail' || $page == 'item_detail') && isset($_GET['id']) && $_GET['id']) { $item_id = (int) $_GET['id']; } else { $item_id = 0; } if (in_array(basename($_SERVER['PHP_SELF']), array('ebxml.php', 'ajax.php', 'captcha.php'))) { $ref_url = ''; } else { AZLib::check_uri(); $ref_url = CGlobal::$query_string; } if ($this->data) { if ($ref_url == '' || in_array(basename($_SERVER['PHP_SELF']), array('ebxml.php', 'ajax.php', 'captcha.php'))) { $ref_url = stripslashes($this->data['session_referer']); } if (!$page) { $page = $this->data['page']; } if (!$page_id) { $page_id = (int) $this->data['page_id']; } if (!$item_id) { $item_id = (int) $this->data['item_id']; } $sql = "UPDATE " . _SESS_TABLE . " SET\r\n\t\t\t\t\t\t\t\t\t\t\t \tsession_expires = " . TIME_NOW . ", \r\n\t\t\t\t\t\t\t\t\t\t\t \tsession_data \t= '{$data}',\r\n\t\t\t\t\t\t\t\t\t\t\t \tsession_referer = '" . addslashes($ref_url) . "',\r\n\t\t\t\t\t\t\t\t\t\t\t \tsession_ip \t\t= '" . $_SERVER['SERVER_ADDR'] . '::' . $_SERVER['REMOTE_ADDR'] . "', \r\n\t\t\t\t\t\t\t\t\t\t\t \tpage \t\t\t= '{$page}',\t\r\n\t\t\t\t\t\t\t\t\t\t\t \tpage_id \t\t= {$page_id},\r\n\t\t\t\t\t\t\t\t\t\t\t \tcategory_id \t= " . CGlobal::$curCategory . ",\r\n\t\t\t\t\t\t\t\t\t\t\t \titem_id \t\t= {$item_id},\r\n\t\t\t\t\t\t\t\t\t\t\t \tuser_id \t\t= '{$user_id}',\r\n\t\t\t\t\t\t\t\t\t\t\t \tuser_name\t\t= '{$user_name}',\r\n\t\t\t\t\t\t\t\t\t\t\t \tlogin_type\t\t= '{$login_type}',\r\n\t\t\t\t\t\t\t\t\t\t\t \topen_id\t\t\t= '{$open_id}'\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE session_id \t= '{$session_id}'"; } else { $sql = "INSERT INTO " . _SESS_TABLE . " \r\n \t\t\t\t\t\t (\r\n \t\t\t\t\t\t \tsession_id, \r\n \t\t\t\t\t\t \tsession_expires, \r\n \t\t\t\t\t\t \tsession_data, \r\n \t\t\t\t\t\t \tsession_referer, \r\n \t\t\t\t\t\t \tsession_ip, \r\n \t\t\t\t\t\t \tpage, \r\n \t\t\t\t\t\t \tpage_id, \r\n \t\t\t\t\t\t \tcategory_id, \r\n \t\t\t\t\t\t \titem_id, \r\n \t\t\t\t\t\t \tuser_id, \r\n \t\t\t\t\t\t \tuser_name,\r\n\t\t\t\t\t\t\t \tlogin_type,\r\n\t\t\t\t\t\t\t \topen_id\r\n \t\t\t\t\t\t \t) \r\n VALUES (\r\n \t\t\t'{$session_id}', \t\t\t\t\r\n \t\t\t" . TIME_NOW . ", \t\t\t\r\n \t\t\t'{$data}', \t\t\t \r\n \t\t\t'" . addslashes($ref_url) . "', \t \r\n \t\t\t'" . $_SERVER['SERVER_ADDR'] . '::' . $_SERVER['REMOTE_ADDR'] . "',\t\r\n \t\t\t'{$page}',\t \r\n \t\t\t{$page_id},\t\t \r\n \t\t\t" . CGlobal::$curCategory . ", \t\t \r\n \t\t\t{$item_id}, \t \r\n \t\t\t{$user_id} ,\t\t\r\n \t\t\t'{$user_name}',\t\t\r\n\t \t\t\t{$login_type} ,\t\t\r\n\t \t\t\t'{$open_id}')"; } $this->query($sql, __LINE__ . __FILE__); if (User::is_login() && MEMCACHE_ON) { //Nếu đã đăng nhập $user = User::$current->data; if ($user && !isset($user['last_login']) || isset($user['last_login']) && $user['last_login'] < TIME_NOW - 300) { DB::query("UPDATE user SET last_login="******" WHERE id={$user['id']}"); $user_memcache = AZMemcache::do_get("user:{$user['id']}"); if ($user_memcache) { $user_memcache['last_login'] = TIME_NOW; AZMemcache::do_put("user:{$user['id']}", $user_memcache); } } } if ($this->effect_rows) { //if row was created, return true return true; } return false; //an unknown error occured }
static function update_read_count() { if (Item::$item) { Item::$item['read_count']++; if (MEMCACHE_ON) { AZMemcache::do_put("item:" . Item::$item['id'], Item::$item); if (Item::$item['read_count'] % 10 == 0) { $sql_str = "UPDATE item SET read_count = read_count + 10 WHERE id = " . Item::$item['id']; DB::query($sql_str); } } else { $sql_str = "UPDATE item SET read_count = read_count + 1 WHERE id = " . Item::$item['id']; DB::query($sql_str); } } /* DB::query("INSERT INTO eb_views(eb_id,eb_type,view_time) VALUES(".Item::$id.",0,".TIME_NOW.")"); */ }
static function del_cache($cache_key = '') { if ($cache_key != '') { if (MEMCACHE_ON) { AZMemcache::do_remove("acache:{$cache_key}"); } else { if (is_array(CGlobal::$my_server)) { foreach (CGlobal::$my_server as $server) { $link = "http://{$server}/?trigger=1&cache_arr={$cache_key}"; if (@fopen($link, "r")) { //if(DEBUG){echo "run service in $link <br>";} } else { if (DEBUG) { echo "error in {$link} <br>"; } } } } } return true; } elseif (isset($_REQUEST['trigger'], $_REQUEST['cache_arr']) && $_REQUEST['trigger'] && $_REQUEST['cache_arr']) { $cache_arr = $_REQUEST['cache_arr']; @unlink(DIR_CACHE . "arr/{$cache_arr}.eb"); if (MEMCACHE_ON) { AZMemcache::do_remove('acache:' . $cache_arr); } if (DEBUG) { echo "Deleted Array cache file : {$cache_arr}"; } exit; } }
function action_reply_item_comment() { $act_ = Url::get('act_'); $comment_id = (int) Url::get('re_c_item_id', 0); $content = ''; $json = ""; if (!User::is_login()) { $json = '({"msg":"no_login"})'; echo $json; exit; } if (User::is_block() || !$comment_id || $act_ != 'skip' && $act_ != 'reply') { $json = '({"msg":"no_perm"})'; echo $json; exit; } $comment_row = DB::select('comment', "id={$comment_id}"); if (!$comment_row || $comment_row && $comment_row['replied_user_id'] != User::id()) { $json = '({"msg":"no_perm"})'; echo $json; exit; } //if($comment_row['receiver_user_id'] == User::id() || $comment_row['sender_user_id'] == User::id() || ($act_=='reply' && $comment_row['replied_status']==1)){//Không được trả lời cho chính mình! hoặc trả lời phản hồi đã đc trả lời rồi! if ($comment_row['receiver_user_id'] == User::id() || $comment_row['sender_user_id'] == User::id()) { //Không được trả lời cho chính mình! $json = '({"msg":"success"})'; echo $json; exit; } $item_id = $comment_row['item_id']; $item = Item::get_item($item_id); $item_memcache = $item; if (!$item || $item && $item == -1) { $json = '({"msg":"no_perm"})'; echo $json; exit; } if ($item["state"] == 1 && !User::have_permit(ADMIN_ITEM)) { $json = '({"msg":"no_perm"})'; echo $json; exit; } $json = '({"msg":"success"'; if ($act_ == 'reply') { $content = trim(AZLib::getParam('content')); if (!$content) { $json = '({"msg":"short_content"})'; echo $json; exit; } if (AZLib::checkBadWord($content)) { $json = '({"msg":"bad_word"})'; echo $json; exit; } $content = preg_replace("/\n/", "<br />", $content); $content = str_replace('<br /><br />', ' ', $content); if ($comment_row['parent_id']) { $parent_id = $comment_row['parent_id']; if ($comment_row['sender_user_id']) { $content = '@<a href="' . WEB_DIR . $comment_row['sender_user_name'] . '" class="fast_reply_link" title="' . $comment_row['sender_user_name'] . '">' . $comment_row['sender_user_name'] . '</a>: ' . $content; } else { $content = '<font color="#999">@<span style="text-decoration:underline">' . $comment_row['sender_user_name'] . '</span> </font>: ' . $content; } } else { $parent_id = $comment_row['id']; } $comment = array('content' => $content, 'item_id' => $item['id'], 'time' => time(), 'order_time' => time(), 'post_ip' => AZLib::ip(), 'parent_id' => $parent_id, 'receiver_user_id' => $item['user_id'], 'receiver_user_name' => $item['user_name'], 'display' => 1, 'status' => 0); $comment['sender_user_id'] = User::id(); $comment['sender_user_name'] = User::user_name(); if ($comment_row['sender_user_id']) { $comment['replied_user_id'] = $comment_row['sender_user_id']; $comment['replied_user_name'] = $comment_row['sender_user_name']; } if ($comment_row['sender_user_id'] == $item['user_id']) { $comment['replied_status'] = 1; } $id = DB::insert('comment', $comment); if ($id) { $re = DB::query("SELECT id FROM comment WHERE parent_id = {$parent_id} AND display = 1 ORDER BY id DESC LIMIT 3,1"); if ($re) { if ($row = mysql_fetch_assoc($re)) { if ($row) { DB::query("UPDATE comment SET display = 0 WHERE parent_id = {$parent_id} AND display = 1 AND id<={$row['id']}"); } } } if ($comment_id == $parent_id) { DB::query("UPDATE comment SET replied_status = 1,have_child = have_child + 1, order_time = " . time() . " WHERE id = {$comment_id}"); } else { DB::query("UPDATE comment SET have_child = have_child + 1, order_time = " . time() . " WHERE id = {$parent_id}"); DB::query("UPDATE comment SET replied_status = 1 WHERE id = {$comment_id}"); } //Cập nhật đã đọc - trả lời cho feed DB::query("UPDATE feed SET status=1 WHERE ref_id = {$comment_id} AND type=2"); DB::query('UPDATE user SET total_new_comment = total_new_comment + 1 WHERE id=' . $item['user_id']); User::getUser($item['user_id'], 0, 1); if ($comment_row['sender_user_id'] && $comment_row['sender_user_id'] != $item['user_id']) { DB::query('UPDATE user SET total_new_comment = total_new_comment + 1 WHERE id=' . $comment_row['sender_user_id']); User::getUser($comment_row['sender_user_id'], 0, 1); } } $total_feedback = DB::count('comment', 'item_id="' . $item['id'] . '"'); DB::update_id('item', array('reply_count' => $total_feedback), $item['id']); if (MEMCACHE_ON) { $item_memcache['reply_count'] = $total_feedback; AZMemcache::do_put("item:{$item['id']}", $item_memcache); } $receiver_user = User::getUser($item['user_id'], 1); //Cập nhật cron job if ($receiver_user && $receiver_user['email'] && $receiver_user['email_alert']) { $link = WEB_ROOT . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . AZLib::safe_title($item['name'])); $link = AZRewrite::formatUrl($link); $title = "<a href='{$link}' target='_blank' style='text-decoration:none;color:#003399;'><font color='#003399'>{$item['name']}</font></a>"; AZLib::addCronJob('item_comment', AZLib::parseBBCode($content, true), $receiver_user['id'], User::user_name(), '', $item['id'], $title, $link); } } else { if ($comment_row['replied_status'] == 0) { DB::query("UPDATE comment SET replied_status = 1 WHERE id = {$comment_id}"); } //Cập nhật đã đọc - trả lời cho feed DB::query("UPDATE feed set status=1 WHERE ref_id = {$comment_id} AND type=2"); } DB::query('UPDATE user SET total_new_comment = total_new_comment - 1 WHERE id=' . User::id() . ' AND total_new_comment>0'); User::getUser(User::id(), 0, 1); $json .= "})"; echo $json; exit; }
function delete_register_service() { if (!User::is_login()) { echo "not_login"; exit; } if (User::is_block()) { echo "no_permission"; exit; } $user = User::$current->data; $id = (int) Url::get('service_id', 0); $aryOrderService = array(); if ($id) { $aryOrderService = DB::select("order_services", "id={$id}"); } if ($aryOrderService) { if ($aryOrderService['active'] != -2) { DB::update('order_services', array('active' => -2, 'time_del' => TIME_NOW, 'user_del' => User::user_name()), "id={$aryOrderService['id']}"); DB::update('payment_scs', array('del_status' => -1), "order_service_id={$aryOrderService['id']}"); //tra lai so tien khong su dung cho user $user_onDB = DB::select('user', "id={$user['id']}"); $last_money_used = $user_onDB['money_used'] - $aryOrderService['price'] / 1000; DB::update('user', array('money_used' => $last_money_used), "user_name='{$user['user_name']}'"); DB::update('payment_premium', array('status' => 2), "log_id={$aryOrderService['id']}"); if (MEMCACHE_ON) { $user['money_used'] = $last_money_used; AZMemcache::do_put("user:{$user['id']}", $user); } } echo "success"; exit; } echo "error"; exit; }
function add_edit_ban_ip() { if (!User::have_permit(ADMIN_ITEM)) { echo "no_perm"; exit; } $user_name = User::user_name(); $create_time = TIME_NOW; $ban_id = Url::get('ban_id', 0); $ban_ip = Url::get('ban_ip', 0); $ban_reason = AZLib::getParam('ban_reason', ""); if ($ban_ip) { $ban_ip = str_replace(' ', '', $ban_ip); $item_array = array('ip' => $ban_ip, 'reason' => $ban_reason, 'create_time' => $create_time, 'user_name' => $user_name); if (!$ban_id) { DB::insert('ban_ip', $item_array); $ban_id = mysql_insert_id(); } else { DB::update('ban_ip', $item_array, 'id = ' . $ban_id); } $item_array += array('id' => $ban_id); $item_array['create_time'] = date('d/m - h:i', $item_array['create_time']); // cho mang vao memcache $sql = "SELECT * FROM ban_ip Order by id desc"; $result = DB::query($sql); while ($row = mysql_fetch_assoc($result)) { $row['create_time'] = date('d/m - h:i', $row['create_time']); $arr_mem_cache[$row['ip']] = $row; } AZMemcache::do_put('list_ban_ip', $arr_mem_cache); echo json_encode($item_array); } else { echo "not_ip"; } exit; }
function ManageItem($row) { if (User::have_permit(array(ADMIN_ITEM, ADMIN_DEL_ITEM))) { Module::Module($row); $cmd = Url::get('cmd'); switch ($cmd) { case 'delete': $id = (int) Url::get('id', 0); if ($id) { $item = Item::get_item($id); Item::delete_item($id); } Url::redirect_url(Url::build_all(array('selected_ids', 'cmd', 'id', 'product_item'))); break; case 'del_cache': $id = (int) Url::get('id', 0); if ($id) { Item::get_item($id, 1); } Url::redirect_url(Url::build_all(array('selected_ids', 'cmd', 'id', 'product_item'))); break; case 'del_forever': if (User::have_permit(ADMIN_DEL_ITEM)) { $id = (int) Url::get('id', 0); if ($id) { Item::delete_item_physical($id); } } Url::redirect_url(Url::build_all(array('selected_ids', 'cmd', 'id', 'product_item'))); break; case 'show': case 're_post': $id = (int) Url::get('id', 0); if ($id) { if (MEMCACHE_ON) { $item_memcache = Item::get_item($id); $item_memcache['status'] = 1; $item_memcache['modify_user_name'] = User::user_name(); $item_memcache['modify_time'] = TIME_NOW; AZMemcache::do_put("item:{$id}", $item_memcache); } DB::update('item', array('status' => 1, 'modify_user_name' => User::user_name(), 'modify_time' => TIME_NOW), 'id=' . $id); } Url::redirect_url(Url::build_all(array('selected_ids', 'cmd', 'id', 'product_item'))); break; case 'hide': $id = (int) Url::get('id', 0); if ($id) { if (MEMCACHE_ON) { $item_memcache = Item::get_item($id); $item_memcache['status'] = 2; $item_memcache['modify_user_name'] = User::user_name(); $item_memcache['modify_time'] = TIME_NOW; AZMemcache::do_put("item:{$id}", $item_memcache); } DB::update('item', array('status' => 2, 'modify_user_name' => User::user_name(), 'modify_time' => TIME_NOW), 'id=' . $id); } Url::redirect_url(Url::build_all(array('selected_ids', 'cmd', 'id', 'product_item'))); break; default: require_once 'forms/ManageItem.php'; $this->add_form(new ManageItemForm()); break; } } else { Url::redirect('sign_in'); } }
static function get() { if (isset($_GET['delcache']) && (int) $_GET['delcache'] == 1) { self::auto_delete(self::_my_file()); return false; } if (MEMCACHE_ON) { $arr = AZMemcache::do_get("qcache:" . self::_my_file()); if ($arr !== false) { return $arr; } } else { $cfile = DIR_CACHE . 'db/' . self::_my_file(); if (file_exists($cfile)) { self::$createdTime = filemtime($cfile); if (self::$expire > 0 && TIME_NOW < self::$createdTime + self::$expire || self::$expire == 0) { return unserialize(stripslashes(@file_get_contents($cfile))); } } } return false; }
<?php require_once '../includes/auth.php'; //Auth... require_once '../core/Debug.php'; //System Debug... require_once '../core/config.php'; //System Config... require_once '../core/Init.php'; //System Init... $act = Url::get('act'); $id = Url::get('id'); switch ($act) { case 'remove': if ($id) { AZMemcache::do_remove($id); echo "Đã xóa xong {$id}"; exit; } break; case 'clear': if (AZMemcache::clear()) { echo "done"; exit; } break; default: echo ":D hehe"; exit; break; }
static function getUser($user_id, $update_cache = FALSE, $delcache = FALSE) { $user = array(); if ($user_id) { if (MEMCACHE_ON) { if ($delcache) { //Xoá cache if (MEMCACHE_ON) { AZMemcache::do_remove("user:{$user_id}"); } return TRUE; } else { if (!$update_cache && MEMCACHE_ON) { $user = AZMemcache::do_get("user:{$user_id}"); } if (!$user) { $sql = "SELECT * FROM user WHERE id=" . (int) $user_id . " LIMIT 1"; $user = mysql_fetch_assoc(DB::query($sql)); $user['is_block'] = $user['block_time'] > TIME_NOW || $user['block_time'] == -1 ? TRUE : FALSE; if (MEMCACHE_ON && $user) { AZMemcache::do_put("user:{$user_id}", $user); } } } } else { //cache file $subDir = 'user/' . floor($user_id / 1000); $user = AZCache::cache('SELECT * FROM user WHERE id=' . (int) $user_id . ' LIMIT 0,1', __LINE__ . __FILE__, 2592000, $update_cache, '', $subDir, $delcache); if ($user && !$delcache) { $user[0]['is_block'] = $user[0]['block_time'] > TIME_NOW || $user[0]['block_time'] == -1 ? TRUE : FALSE; return $user[0]; } } } return $user; }
static function get_list_ban_ip() { $list_ip = array(); if (MEMCACHE_ON) { $list_ip = AZMemcache::do_get('list_ban_ip'); } if (!$list_ip) { $sql = "select * from ban_ip"; $list_ip_temp = DB::fetch_all_array($sql); foreach ($list_ip_temp as $value) { $list_ip[$value['ip']] = $value; } } return $list_ip; }
function on_submit() { if (Url::get('item_update') == 'Cập nhật') { $name_arr = $_POST['names']; $sku_arr = $_POST['skus']; $offer_arr = $_POST['offers']; $list_brief_arr = $_POST['list_briefs']; $price_arr = $_POST['prices']; $price_out_arr = $_POST['price_outs']; $currency_id_arr = $_POST['currency_ids']; $quantity_arr = $_POST['quantitys']; $item_order_arr = $_POST['item_orders']; $made_in_arr = $_POST['made_ins']; $warranty_arr = $_POST['warrantys']; $sql = array(); foreach ($price_arr as $id => $price) { if (strlen($name_arr[$id]) < 1) { $this->setFormError("name" . $id, "Tên sản phẩm có mã " . $id . " phải có độ dài từ 1 ký tự trở lên !"); return; } if (URL::cdouble($price_arr[$id]) < 0) { $this->setFormError("price" . $id, "Đơn giá sản phẩm có mã " . $id . " phải là giá trị >=0 !"); return; } if (URL::cdouble($price_out_arr[$id]) < 0) { $this->setFormError("price_out" . $id, "Giá thị trường sản phẩm có mã " . $id . " phải là giá trị >=0 !"); return; } $sql[] = "UPDATE item SET name='" . addslashes($name_arr[$id]) . "' ,sku='" . addslashes($sku_arr[$id]) . "' ,list_brief='" . addslashes($list_brief_arr[$id]) . "' ,offer='" . addslashes($offer_arr[$id]) . "' ,\r\n\t\t\t\t\t\t\t\t\t\tprice='" . URL::cdouble($price_arr[$id]) . "' ,price_out='" . URL::cdouble($price_out_arr[$id]) . "', \r\n\t\t\t\t\t\t\t\t\t\tcurrency_id=" . (int) $currency_id_arr[$id] . " , quantity=" . (int) $quantity_arr[$id] . " ,`item_order`='" . (int) $item_order_arr[$id] . "',`warranty`='" . $warranty_arr[$id] . "',`made_in`='" . $made_in_arr[$id] . "' , \r\n\t\t\t\t\t\t\t\t\t\tmodify_time=" . TIME_NOW . ", modify_user_name='" . User::user_name() . "' WHERE id=" . $id; } foreach ($sql as $query) { DB::query($query, __LINE__ . __FILE__); } Url::redirect_url(Url::build_all(array('cmd'))); } if (Url::get('cmd') == 'move_content') { $str_ids = trim(AZLib::getParam('product_item'), ','); $catid = (int) Url::get('id_cats', 0); if ($catid != 0 && $str_ids) { $result = DB::fetch("SELECT parent_id FROM category WHERE id={$catid}"); $parent_id = $result['parent_id']; $l1_id = 0; $l2_id = 0; if ($parent_id) { $result = DB::fetch("SELECT parent_id FROM category WHERE id={$parent_id}"); $l1_id = $parent_id; $l2_id = $catid; $sql = 'UPDATE item SET category_id= ' . $catid . ',level_1_catid = ' . $parent_id . ' ,level_2_catid = ' . $catid . ' WHERE id IN(' . $str_ids . ')'; } else { $l1_id = $catid; $l2_id = 0; $sql = 'UPDATE item SET category_id= ' . $catid . ',level_1_catid = ' . $catid . ',level_2_catid = 0 WHERE id IN(' . $str_ids . ')'; } DB::query($sql); if (MEMCACHE_ON) { $arr = explode(',', $str_ids); if ($arr) { foreach ($arr as $item_id) { $item_memcache = AZMemcache::do_get("item:{$item_id}"); if ($item_memcache) { $item_memcache['category_id'] = $catid; $item_memcache['level_1_catid'] = $l1_id; $item_memcache['level_2_catid'] = $l2_id; AZMemcache::do_put("item:{$item_id}", $item_memcache); } } } } } Url::redirect_url(Url::build_all(array('cmd'))); } if (Url::get('cmd') == 'delete_item') { if (isset($_REQUEST['selected_ids'])) { $this->delete_multi($_REQUEST['selected_ids']); } else { if (isset($_REQUEST['product_item'])) { $product_item = array(0 => $_REQUEST['product_item']); $this->delete_multi($product_item); } } } }
function gallery_update() { //Cập nhật ảnh cho thư viện if (User::have_permit(ADMIN_IMAGE) && (int) Url::get('user_id', 0) && (int) Url::get('user_id', 0) != User::id()) { $user_id = (int) Url::get('user_id', 0); } else { $user_id = User::id(); } $image_id = (int) $_GET['image_id']; $json['error'] = 'not_updated'; //not_uploaded $json['url_error'] = ''; $json['img_url'] = ''; if (User::is_login()) { if (User::is_az_team() || User::level() > 0) { if ($image_id) { $des = substr(AZLib::trimSpace(AZLib::cleanHtml($_POST['des_update'])), 0, 50); $image = DB::select('item_image', 'id=' . $image_id . ' AND root_id=0 AND user_id=' . $user_id); if ($image) { $upload_path = AZLib::folderUpload($user_id); if (AZLib::ftp_check_dir($upload_path, true, IMAGE_SERVER_NO)) { //Check dir for upload if (isset($_FILES['img_upload_update']) && !$_FILES['img_upload_update']['error'] && $_FILES['img_upload_update']['name']) { if (getimagesize($_FILES['img_upload_update']['tmp_name']) && $_FILES['img_upload_update']['size'] <= Item::MAX_UPLOAD_SIZE) { $file_name = $_FILES['img_upload_update']['name']; $sourceName = $_FILES['img_upload_update']['tmp_name']; $file_ext = AZLib::getExtension($file_name); if (in_array($file_ext, array('.jpg', '.jpeg', '.gif', '.png'))) { $img_url = $upload_path . date("YmdHis", TIME_NOW) . '_' . substr(AZLib::make_safe_name(basename(strtolower($file_name), $file_ext)), 0, 36) . $file_ext; if (AZLib::ftp_image_put_file($img_url, $sourceName, IMAGE_SERVER_NO)) { if (DB::update('item_image', array('des' => $des, 'img_server' => IMAGE_SERVER_NO, 'img_url' => $img_url), 'id=' . $image_id . ' OR root_id=' . $image_id)) { if ($image['img_url']) { AZLib::ftp_image_delete_file($image['img_url'], $image['img_server']); if (MEMCACHE_ON) { $sql = "SELECT * FROM item\tWHERE img_url='{$image['img_url']}' AND status IN(1,2) AND user_id=" . $user_id; $re = DB::query($sql); while ($item_memcache = mysql_fetch_assoc($re)) { $item_memcache['img_server'] = IMAGE_SERVER_NO; $item_memcache['img_url'] = $img_url; AZMemcache::do_put("item:" . $item_memcache['id'], $item_memcache); } } DB::query("UPDATE item SET img_server = " . (int) IMAGE_SERVER_NO . ", img_url='{$img_url}' WHERE img_url='{$image['img_url']}' AND status IN(1,2) AND user_id=" . $user_id); } $json['img_server'] = IMAGE_SERVER_NO; $json['img_url'] = $img_url; $json['error'] = 'success'; } else { $json['error'] = 'not_updated'; } } } else { $json['error'] = 'ext_invalid'; //Sai định dạng file } } else { $json['error'] = 'over_max_size'; //Sai định dạng file hoặc upload dung lượng quá lớn } } elseif ($_POST['url_update']) { $url = $_POST['url_update']; $tem_cache_dir = DIR_CACHE . 'user_images/'; AZLib::CheckDir($tem_cache_dir); $tem_cache_file = User::user_name() . md5($url) . '.gif'; $image_content = disguise_curl($url); if ($image_content) { if (@file_put_contents($tem_cache_dir . $tem_cache_file, $image_content)) { if (getimagesize($tem_cache_dir . $tem_cache_file) && filesize($tem_cache_dir . $tem_cache_file) <= Item::MAX_UPLOAD_SIZE) { $sourceName = $tem_cache_dir . $tem_cache_file; $img_url = $upload_path . TIME_NOW . '_' . $tem_cache_file; if (AZLib::ftp_image_put_file($img_url, $sourceName, IMAGE_SERVER_NO)) { if (DB::update('item_image', array('des' => $des, 'img_server' => IMAGE_SERVER_NO, 'img_url' => $img_url), 'id=' . $image_id . ' OR root_id=' . $image_id)) { if ($image['img_url']) { AZLib::ftp_image_delete_file($image['img_url'], $image['imng_server']); if (MEMCACHE_ON) { $sql = "SELECT * FROM item\tWHERE img_url='{$image['img_url']}' AND status IN(1,2) AND user_id=" . $user_id; $re = DB::query($sql); while ($item_memcache = mysql_fetch_assoc($re)) { $item_memcache['img_server'] = IMAGE_SERVER_NO; $item_memcache['img_url'] = $img_url; AZMemcache::do_put("item:" . $item_memcache['id'], $item_memcache); } } DB::query("UPDATE item SET img_url='{$img_url}' WHERE img_url='{$image['img_url']}' AND status IN(1,2) AND user_id=" . $user_id); } $json['url_error'] = 'success'; $json['img_server'] = IMAGE_SERVER_NO; $json['img_url'] = $img_url; } else { $json['url_error'] = 'not_updated'; } } else { $json['url_error'] = 'not_uploaded'; } } else { $json['url_error'] = 'over_max_size'; } @unlink($tem_cache_dir . $tem_cache_file); } else { $json['url_error'] = 'not_cache_file'; } } else { $json['url_error'] = 'not_get_img'; } } else { if ($des != $image['des']) { if (DB::update('item_image', array('des' => $des), 'id=' . $image_id)) { $json['error'] = 'success'; } else { $json['error'] = 'not_updated'; } } else { $json['error'] = 'success'; } } } $json['des'] = $des; //get Item_id $sql = "SELECT item_id FROM item_image WHERE (id = {$image_id} OR root_id = {$image_id}) " . (User::have_permit(ADMIN_IMAGE) ? '' : " AND user_id=" . User::id()); $re = DB::query($sql); if ($re) { $item = mysql_fetch_assoc($re); if ($item["item_id"]) { require_once ROOT_PATH . 'core/Item.php'; Item::get_item_images($item["item_id"], 1); } } } else { $json['error'] = 'not_exit'; } //get Item_id $sql = "SELECT item_id FROM item_image WHERE id = {$image_id}"; $re = DB::query($sql); if ($re) { $item = mysql_fetch_assoc($re); require_once ROOT_PATH . 'core/Item.php'; Item::get_item_images($item["item_id"], 1); } } } } else { $json['error'] = 'not_login'; } echo json_encode($json); exit; }
static function endCache($return = false) { //if(!CACHE_ON) //return ; self::$curentContent = ob_get_contents(); ob_end_clean(); if (CACHE_ON) { if (MEMCACHE_ON) { if (self::$curentCacheFilePath != '') { AZMemcache::do_put("scache:" . self::$curentCacheFilePath, self::$curentContent, self::$curentExpTime); if (DEBUG) { self::$pNum++; if (class_exists('Module')) { if (class_exists('Module') && Module::$name != '') { $module_name = Module::$name; } else { $module_name = "-- Enbac system"; } } $info = "<b>" . $module_name . "</b><br /><font color=red><b>scache:" . self::$curentCacheFilePath . "</b></font><br /><b>Created:</b> " . date('d/m/Y H:i:s', TIME_NOW) . " <b>Expire:</b> " . (self::$curentExpTime ? self::$curentExpTime . ' sec ' : 'Forever'); self::$cacheFilesList .= "<li>" . $info . "</li>"; } self::$curentCacheFilePath = ''; self::$curentExpTime = 0; } else { if (DEBUG) { self::$pNum++; if (class_exists('Module') && Module::$name != '') { $module_name = Module::$name; } else { $module_name = "-- Enbac system"; } $info = "<b>" . $module_name . "</b><br /><font color=red><b>No file</b></font><br />"; self::$cacheFilesList .= "<li>" . $info . "</li>"; } self::$curentExpTime = 0; } } else { if (self::$curentCacheFilePath != '') { @file_put_contents(self::$curentCacheFilePath, self::$curentContent); if (DEBUG) { self::$pNum++; if (class_exists('Module') && Module::$name != '') { $module_name = Module::$name; } else { $module_name = "-- Enbac system"; } $info = "<b>" . $module_name . "</b><br /><font color=red><b>" . self::$curentCacheFilePath . "</b></font><br /><b>Created:</b> " . date('d/m/Y H:i:s', TIME_NOW) . " <b>Expire:</b> " . (self::$curentExpTime ? date('d/m/Y H:i:s', self::$curentExpTime + TIME_NOW) : 'Forever'); self::$cacheFilesList .= "<li>" . $info . "</li>"; } self::$curentCacheFilePath = ''; self::$curentExpTime = 0; } else { if (DEBUG) { self::$pNum++; if (class_exists('Module') && Module::$name != '') { $module_name = Module::$name; } else { $module_name = "-- Enbac system"; } $info = "<b>" . $module_name . "</b><br /><font color=red><b>No file</b></font><br />"; self::$cacheFilesList .= "<li>" . $info . "</li>"; } self::$curentExpTime = 0; } } } if ($return) { return self::$curentContent; } elseif (!self::$handleContent) { echo self::$curentContent; } return true; }