예제 #1
0
 function autocomplete()
 {
     $q = $_GET["q"];
     if (!$q) {
         return;
     }
     $md5_keyword = md5($q);
     $aryData = array();
     $aryData = eb_memcache::do_get("Auto_complete:" . $md5_keyword);
     if (empty($aryData)) {
         $solr = new Solr_Search();
         $response = $solr->autocomplete($q);
         $items = $response['terms']['name'];
         foreach ($items as $key => $value) {
             if ($key % 2 == 0) {
                 $aryData[] = array('keyword' => $value);
                 if (strpos($value, $q) !== false) {
                     echo "{$value}\n";
                 }
             }
         }
         if (is_array($aryData) && count($aryData) > 0) {
             eb_memcache::do_put("Auto_complete:" . $md5_keyword, $aryData);
         }
     } else {
         foreach ($aryData as $key => $value) {
             if (strpos($value['keyword'], $q) !== false) {
                 $vl = $value['keyword'];
                 echo "{$vl}\n";
             }
         }
     }
 }
예제 #2
0
    function del_comment()
    {
        $json['msg'] = '';
        if (!User::is_login() || User::is_block()) {
            $json['msg'] = "not_perm";
            die(json_encode($json));
        }
        $id = (int) Url::get("id");
        if ($id) {
            $comment = DB::fetch("SELECT * FROM comment WHERE id={$id} LIMIT 1");
            if (count($comment) == 0) {
                exit;
            }
            if (User::have_permit(ADMIN_ITEM) || User::id() == $comment['receiver_user_id'] && $comment['sender_user_id'] == 0) {
                EClassApi::update_cache_comment($comment['item_id']);
                if (DB::delete('comment', 'id=' . $id)) {
                    $subItemId = $comment['sub_item_id'];
                    $itemId = $comment['item_id'];
                    if (MEMCACHE_ON) {
                        //eb_memcache::do_put('update_comment_sub_' . $itemId . '_' . $subItemId, 1); /*ngannv #update_comment_sub tìm thêm trong ajax_item_detai.ajax*/
                        eb_memcache::do_remove('comment_sub_' . $itemId . '_' . $subItemId);
                    }
                    $countChild = $comment['have_child'];
                    if ($countChild > 0) {
                        DB::delete('comment', 'parent_id=' . $id);
                    }
                    $countChildDel = $countChild + 1;
                    if ($subItemId > 0) {
                        DB::query("UPDATE item_sub SET comment_count=comment_count-{$countChildDel} WHERE id={$subItemId} LIMIT 1");
                        /*SubItem chưa có cache nên tạm thời truy vấn lại để lấy số comment*/
                        $subCommentRes = DB::fetch("SELECT comment_count FROM item_sub WHERE id={$subItemId} LIMIT 1");
                        if (!empty($subCommentRes)) {
                            $json['countCommentSubItem'] = $subCommentRes['comment_count'];
                        }
                    } else {
                        DB::query("UPDATE item SET reply_count=reply_count-{$countChildDel} WHERE id={$itemId} LIMIT 1");
                        $itemReset = Item::get_item($itemId);
                        $item_memcache = $itemReset;
                        if ($itemReset) {
                            $item_memcache['reply_count'] = $itemReset['reply_count'] - $countChildDel;
                            if (SORL_FILTER_ON) {
                                $solr = new Solr_Search();
                                $solr->doUpdateItem($itemId);
                            }
                            if (MEMCACHE_ON) {
                                eb_memcache::do_put("item:{$itemId}", $item_memcache);
                            }
                            $caheFile = 'fb_' . $itemReset['id'];
                            StaticCache::delCache($caheFile);
                            $json['countCommentItem'] = $item_memcache['reply_count'];
                        }
                    }
                    if ($comment['parent_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');
                            }
                        }
                    }
                    /*Đếm lại commemnt*/
                    $json['msg'] = EClassApi::getParam('id');
                    exit(json_encode($json));
                } else {
                    $json['msg'] = "unsuccess";
                    exit(json_encode($json));
                }
            } else {
                $json['msg'] = "not_perm";
                exit(json_encode($json));
            }
        } else {
            $json['msg'] = "not_perm";
            exit(json_encode($json));
        }
    }
예제 #3
0
 function refress_item()
 {
     if (!User::is_login()) {
         echo "not_login";
         exit;
     }
     if (!User::have_permit(ADMIN_ITEM)) {
         echo "no_permission";
         exit;
     }
     $id = Url::get("id", 0);
     if ($id) {
         if (SORL_FILTER_ON) {
             $solr = new Solr_Search();
             $solr->doUpdateItem($id);
         }
     } else {
         echo "invalid";
         exit;
     }
     exit;
 }
예제 #4
0
    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['original_image_url'] = '';

        if (User::is_login()) {
            if (User::is_foodnet_team() || User::level() > 0) {
                if ($image_id) {
                    $des = substr(EClassApi::trimSpace(EClassApi::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 = EClassApi::folderUpload($user_id);

                        if (EClassApi::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 = EClassApi::getExtension($file_name);

                                    if (in_array($file_ext, array('.jpg', '.jpeg', '.gif', '.png'))) {
                                        $original_image_url = $upload_path . date("YmdHis", TIME_NOW) . '_' . substr(EClassApi::make_safe_name(basename(strtolower($file_name), $file_ext)), 0, 36) . $file_ext;

                                        if (EClassApi::ftp_image_put_file($original_image_url, $sourceName, IMAGE_SERVER_NO)) {
                                            if (DB::update('item_image', array(
                                                        'des' => $des,
                                                        'img_server' => IMAGE_SERVER_NO,
                                                        'original_image_url' => $original_image_url
                                                            ), 'id=' . $image_id . ' OR root_id=' . $image_id)) {
                                                if ($image['original_image_url']) {
                                                    EClassApi::ftp_image_delete_file($image['original_image_url'], $image['img_server']);

                                                    if (MEMCACHE_ON) {

                                                        $sql = "SELECT * FROM item	WHERE original_image_url='{$image['original_image_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['original_image_url'] = $original_image_url;
                                                            eb_memcache::do_put("item:" . $item_memcache['id'], $item_memcache);
                                                             if(SORL_FILTER_ON){
                                                               $solr = new Solr_Search();
                                                               $solr->doUpdateItem($item_memcache['id']);
                                                               }
                                                        }
                                                    }

                                                    DB::query("UPDATE item SET img_server = " . (int) IMAGE_SERVER_NO . ", original_image_url='{$original_image_url}' WHERE original_image_url='{$image['original_image_url']}' AND status IN(1,2)  AND user_id=" . $user_id);

                                                }
                                                $json['img_server'] = IMAGE_SERVER_NO;
                                                $json['original_image_url'] = $original_image_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/';
                                EClassApi::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;
                                            $original_image_url = $upload_path . TIME_NOW . '_' . $tem_cache_file;

                                            if (EClassApi::ftp_image_put_file($original_image_url, $sourceName, IMAGE_SERVER_NO)) {
                                                if (DB::update('item_image', array(
                                                            'des' => $des,
                                                            'img_server' => IMAGE_SERVER_NO,
                                                            'original_image_url' => $original_image_url)
                                                                , 'id=' . $image_id . ' OR root_id=' . $image_id)) {
                                                    if ($image['original_image_url']) {
                                                        EClassApi::ftp_image_delete_file($image['original_image_url'], $image['imng_server']);
                                                        if (MEMCACHE_ON) {
                                                            $sql = "SELECT * FROM item	WHERE original_image_url='{$image['original_image_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['original_image_url'] = $original_image_url;
                                                                eb_memcache::do_put("item:" . $item_memcache['id'], $item_memcache);
                                                                if(SORL_FILTER_ON){
                                                                   $solr = new Solr_Search();
                                                                   $solr->doUpdateItem($item_memcache['id']);
                                                                   }
                                                            }
                                                        }

                                                        DB::query("UPDATE item SET original_image_url='{$original_image_url}' WHERE original_image_url='{$image['original_image_url']}' AND status IN(1,2) AND user_id=" . $user_id);

                                                    }
                                                    $json['url_error'] = 'success';
                                                    $json['img_server'] = IMAGE_SERVER_NO;
                                                    $json['original_image_url'] = $original_image_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();
    }
예제 #5
0
 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('account', "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 account 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 (SORL_FILTER_ON) {
                             $solr = new Solr_Search();
                             $solr->doUpdateItem($item_id);
                         }
                         if (MEMCACHE_ON) {
                             $item['is_up_auto'] = 1;
                             eb_memcache::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']},\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},\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']},\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;
 }
예제 #6
0
    function fn_invalid_user()
    {
        if (!User::is_login() || !User::have_permit(array(ADMIN_USER, MOD_VALID_USER))) {
            echo "no_perm";
            exit;
        }
        $user_id = (int) Url::get('user_id', 0);
        $invalid_time = (int) Url::get('invalid_time', 0);
        $date_invalid = (int) Url::get('date_invalid', 0);
        $type_invalid = (int) Url::get('type_invalid', 0);
        $reason_invalid = EnbacLib::getParam('reason_invalid', '');
        $reason_invalid = $reason_invalid ? $reason_invalid : 'Không nhập lý do kiểm duyệt';
        $user = User::getUser($user_id);
        if ($user['invalid_time'] > 0 || $user['invalid_time'] == -1) {
            if (DB::update('account', array('invalid_time' => "0"), 'id =' . $user_id)) {
                $sql_select_reason = 'SELECT id,admin_name,time FROM acc_lock WHERE user_id = ' . $user_id . ' AND type = 2 ORDER BY id DESC LIMIT 1';
                $user_invalid = DB::fetch($sql_select_reason);
                if (MEMCACHE_ON) {
                    $sql = "SELECT * FROM item\t\n\t\t\t\t\t\t\t   WHERE user_id = {$user_id} AND status = 2 AND valid_time = {$user_invalid['time']} AND modify_time_user = 0 AND valid_user ='******'admin_name']}'";
                    $re = DB::query($sql);
                    while ($item_memcache = mysql_fetch_assoc($re)) {
                        $item_memcache['status'] = 1;
                        $item_memcache['valid_time'] = TIME_NOW;
                        $item_memcache['valid_user'] = User::user_name();
                        eb_memcache::do_put("item:" . $item_memcache['id'], $item_memcache);
                        //update realtime
                        if (SORL_FILTER_ON) {
                            $solr = new Solr_Search();
                            $solr->doUpdateItem($item_memcache['id']);
                        }
                        //-----
                    }
                }
                if (User::have_permit(array(ADMIN_USER))) {
                    // chi admin quyen User moi duoc mo kiem duyet thanh vien
                    DB::update('item', array('status' => 1, 'valid_time' => TIME_NOW, 'valid_user' => User::user_name()), 'user_id = ' . $user_id . ' AND status = 2 AND valid_time = ' . $user_invalid['time'] . ' AND modify_time_user = 0 AND valid_user ="******"');
                    DB::update('acc_lock', array('unlock_time' => TIME_NOW, 'unlock_user' => User::user_name()), 'id = ' . $user_invalid['id']);
                }
                User::getUser($user_id, 1, 0);
                // update lai cache user
                echo $user['id'];
                exit;
            }
        } elseif ($user['invalid_time'] == 0) {
            if ($type_invalid == 1 && $date_invalid) {
                //$timeInvalid = TIME_NOW+($date_invalid*3600*24);
                $time_start = mktime(24, 0, 0, date('m'), date('d'), date('Y'));
                $timeInvalid = $time_start + $date_invalid * 24 * 3600;
            } elseif ($type_invalid == 2) {
                $timeInvalid = -1;
            } else {
                echo 'fail_valid';
                exit;
            }
            if (DB::update('account', array('invalid_time' => $timeInvalid), 'id =' . $user_id)) {
                $user = DB::fetch('SELECT id,user_name FROM account WHERE id  = ' . $user_id);
                if ($user) {
                    DB::insert('acc_lock', array('time' => TIME_NOW, 'time_expire' => $timeInvalid, 'user_id' => $user['id'], 'user_name' => $user['user_name'], 'type' => 2, 'note' => $reason_invalid, 'admin_id' => User::id(), 'admin_name' => User::user_name()));
                }
                $sql_item = 'SELECT id FROM item where user_id = ' . $user_id . ' AND status = 1';
                $re_item = DB::query($sql_item);
                while ($item = mysql_fetch_assoc($re_item)) {
                    $reason = "KDTV : {$reason_invalid}";
                    $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() . "','" . $reason . "'," . TIME_NOW . ")";
                    DB::query($sql_insert);
                }
                if (MEMCACHE_ON) {
                    $sql = "SELECT * FROM item\t\n\t\t\t\t\t\t\t   WHERE user_id = {$user_id} AND status = 1";
                    $re = DB::query($sql);
                    while ($item_memcache = mysql_fetch_assoc($re)) {
                        $item_memcache['status'] = 2;
                        $item_memcache['valid_time'] = TIME_NOW;
                        $item_memcache['valid_user'] = User::user_name();
                        eb_memcache::do_put("item:" . $item_memcache['id'], $item_memcache);
                        //update realtime
                        if (SORL_FILTER_ON) {
                            $solr = new Solr_Search();
                            $solr->doUpdateItem($item_memcache['id']);
                        }
                        //-----
                    }
                }
                $receiver_user = User::getUser($user_id);
                $title_pm = 'Thông báo kiểm duyệt thành viên từ EClass';
                $content_pm = 'Bạn đã bị kiểm duyệt với lý do: ' . $reason . '
				
				Tất cả các tin đăng của bạn cũng sẽ bị kiểm duyệt.
				
				Đề 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!';
                EClassApi::Send_pm(User::id(), User::user_name(), $receiver_user, $title_pm, $content_pm, true);
                DB::update('item', array('status' => "2", 'valid_time' => TIME_NOW, 'valid_user' => User::user_name()), 'user_id = ' . $user_id . ' AND status = 1');
                User::getUser($user_id, 1, 0);
                // update lai cache user
                echo $user['id'];
                exit;
            }
        } else {
            echo 'fail_valid';
            exit;
        }
    }