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(); }
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']); } } }
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 set($array) { if (CACHE_ON && self::$cache_file) { if (MEMCACHE_ON) { AZMemcache::do_put("acache:" . self::$cache_file, $array, self::$expire); } else { @file_put_contents(self::$cache_file, addslashes(serialize($array))); } self::$arr_cache = $array; } return true; }
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 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 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 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 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 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 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 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'); } }
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.")"); */ }
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; } }
static function set($value) { if (MEMCACHE_ON) { AZMemcache::do_put('qcache:' . self::_my_file(), $value, self::$expire); } else { @file_put_contents(DIR_CACHE . 'db/' . self::_my_file(), addslashes(serialize($value))); } return true; }
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 getProvinces($update_cache = 0, $delcache = false) { if (!CGlobal::$provinces || $delcache || $update_cache) { if (AZArrCache::is_not_cached('provinces_arr', 0, '', $delcache)) { if (!$delcache) { $re = DB::query('SELECT id, name, brief_name, status, area FROM province ORDER BY position', __LINE__ . __FILE__); $topProvinces = array(); $ortherProvinces = array(); if ($re) { while ($province = mysql_fetch_assoc($re)) { $province['ebname'] = AZLib::safe_title($province['name']); if ($province['status'] == "HOME") { $topProvinces[$province['id']] = $province; } else { $ortherProvinces[$province['id']] = $province; } } } $topProvinces[0] = array('id' => 0, 'name' => 'Toàn quốc', 'brief_name' => 'Toàn quốc', 'status' => 'SHOW', 'area' => '1', 'ebname' => 'Toan-Quoc'); CGlobal::$provinces = $topProvinces + $ortherProvinces; AZArrCache::set(CGlobal::$provinces); } else { foreach (CGlobal::$my_server as $server) { //Tạo lại file js cho city @fopen("http://{$server}/citygen.php", "r"); } $js_ver = rand(1, 1000); AZMemcache::do_put("city_ver:", $js_ver); } } else { CGlobal::$provinces = AZArrCache::$arr_cache; AZArrCache::$arr_cache = array(); } } }
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; }