Пример #1
0
 function action_pm()
 {
     $act_ = Url::get('act_');
     $pm_id = (int) Url::get('pm_id', 0);
     $content = trim(AZLib::getParam('content'));
     $title_pm = '';
     $json = "";
     if (!User::is_login()) {
         $json = '({"msg":"no_login"})';
         echo $json;
         exit;
     }
     if (User::is_block()) {
         $json = '({"msg":"no_perm"})';
         echo $json;
         exit;
     }
     if ($pm_id) {
         $message_topic = DB::select('message_topics', "mt_id={$pm_id}");
         if ($message_topic && User::id() == $message_topic['mt_owner_id']) {
             $message_text = DB::select('message_text', "msg_id={$message_topic['mt_msg_id']}");
             if (!$message_text) {
                 DB::delete('message_topics', "mt_id={$pm_id}");
                 $json = '({"msg":"no_perm"})';
                 echo $json;
                 exit;
             }
         } else {
             $json = '({"msg":"no_perm"})';
             echo $json;
             exit;
         }
         if ($act_ == 'reply' && $content || $act_ == 'skip' || $act_ == 'delete') {
             $json = '({"msg":"success"';
             if ($act_ == 'reply' && $content) {
                 if (AZLib::checkBadWord($content)) {
                     $json = '({"msg":"bad_word"})';
                     echo $json;
                     exit;
                 }
                 $title_pm = $message_topic['mt_title'];
                 if ($message_topic['mt_ref_id']) {
                     $ref_id = $message_topic['mt_ref_id'];
                 } else {
                     $ref_id = $pm_id;
                 }
                 //if(strpos($title_pm,'Re:')!==0){
                 //	$title_pm="Re: $title_pm";
                 //}
                 if (AZLib::isBlackList(User::id(), $message_topic['mt_from_id'])) {
                     if ($message_topic['mt_read'] == 0) {
                         DB::query("UPDATE message_topics SET mt_read=1 WHERE mt_id={$pm_id}");
                     }
                     $json = '({"msg":"blacklist"})';
                     echo $json;
                     exit;
                 }
                 $user = User::getUser($message_topic['mt_from_id']);
                 if ($user) {
                     $id_mess = AZLib::Send_pm(User::id(), User::user_name(), $user, $title_pm, $content, 0, $ref_id);
                     if (!$id_mess) {
                         $json = '({"msg":"unsuccess"})';
                         echo $json;
                         exit;
                     }
                 }
                 if ($message_topic['mt_read'] == 0) {
                     DB::query("UPDATE message_topics SET mt_read=1 WHERE mt_id={$pm_id}");
                     //Cập nhật đã đọc - trả lời cho feed
                     DB::query("UPDATE feed SET status = 1 WHERE ref_id = {$pm_id} AND type=4");
                     DB::query('UPDATE user SET total_pm = total_pm-1 WHERE id=' . User::id() . ' AND total_pm>0');
                     User::getUser(User::id(), 0, 1);
                 }
             } elseif ($act_ == 'delete') {
                 AZLib::delete_messages($pm_id);
                 //Cập nhật đã đọc - trả lời cho feed
                 DB::query("DELETE FROM feed WHERE ref_id = {$pm_id} AND type=4");
             } else {
                 if ($message_topic['mt_read'] == 0) {
                     DB::query("UPDATE message_topics SET mt_read=1 WHERE mt_id={$pm_id}");
                     DB::query('UPDATE user SET total_pm = total_pm-1 WHERE id=' . User::id() . ' AND total_pm>0');
                     User::getUser(User::id(), 0, 1);
                 }
                 //Cập nhật đã đọc - trả lời cho feed
                 DB::query("UPDATE feed SET status = 1 WHERE ref_id = {$pm_id} AND type=4");
             }
             DB::query('UPDATE user SET total_pm = total_pm-1 WHERE id=' . User::id() . ' AND total_pm>0');
             User::getUser(User::id(), 0, 1);
             $json .= "})";
             echo $json;
             exit;
         } else {
             $json = '({"msg":"short_content"})';
             exit;
         }
     }
     $json = "({'msg':'no_perm'})";
     echo $json;
 }