Exemple #1
0
    static function Send_pm($sender_id, $sender_name, $receiver_user, $title, $content, $once_way = false, $ref_id = 0)
    {
        $num_send = 0;
        $new_row_msg = array('msg_date' => TIME_NOW, 'msg_post' => htmlspecialchars_decode($content), 'msg_author_id' => $sender_id, 'msg_author_name' => $sender_name, 'msg_ip_address' => AZLib::ip());
        // ***** CHÚ Ý *****
        // Newest = 0 - Mới nhất, = 1 - Cũ hơn (Do lỗi tạo giá trị mặc định trường này là 0, nên quy ước hơi bị ngược, để đỡ mất công chạy lệnh update database
        // ***** CHÚ Ý *****
        $msg_id = DB::insert('message_text', $new_row_msg);
        $inbox_ref_id = 0;
        if ($ref_id) {
            $msgText = DB::select('message_topics', 'mt_id = ' . $ref_id . ' AND mt_owner_id = ' . $sender_id);
            if ($msgText['mt_msg_id']) {
                // Kiểm tra xem người nhận còn tin nhắn gốc hay không
                $mtTopic = DB::select('message_topics', 'mt_msg_id = ' . $msgText['mt_msg_id'] . ' AND mt_id <> ' . $ref_id . ' AND mt_owner_id = ' . $receiver_user['id'] . ' AND mt_from_id <> ' . $receiver_user['id']);
                // Nế còn tin nhắn gốc
                if ($mtTopic['mt_id']) {
                    // Gán tin nhắn sắp gửi là tin nhắn mới nhất
                    // Lấy id tin nhắn gốc của người gửi làm ref_id cho tin nhắn sắp gửi
                    $inbox_ref_id = $mtTopic['mt_id'];
                }
            }
        }
        // Đặt cờ tin nhắn mới nhất (inbox) của các tin trong luồng của người nhận = 0
        if ($inbox_ref_id) {
            DB::query('UPDATE message_topics SET mt_newest = 1 WHERE mt_newest = 0 AND mt_vid_folder = \'inbox\' AND (mt_ref_id = ' . $inbox_ref_id . ' OR mt_id = ' . $inbox_ref_id . ') AND mt_owner_id = ' . $receiver_user["id"]);
        }
        // Đặt cờ tin nhắn mới nhất (sent) của các tin trong luồng của người gửi = 0
        if ($ref_id) {
            DB::query('UPDATE message_topics SET mt_newest = 1 WHERE mt_newest = 0 AND mt_vid_folder = \'sent\' AND (mt_ref_id = ' . $ref_id . ' OR mt_id = ' . $ref_id . ') AND mt_owner_id = ' . $sender_id);
        }
        $new_row_msg = array('mt_msg_id' => $msg_id, 'mt_date' => TIME_NOW, 'mt_title' => $title, 'mt_ref_id' => $inbox_ref_id, 'mt_newest' => 0, 'mt_to_name' => $receiver_user["user_name"], 'mt_read' => 0);
        $arrID = array($sender_id, $sender_name, $receiver_user["id"], $receiver_user["user_name"]);
        // Tạo tiêu đề tin nhắn mới
        $msg_id_inbox = AZLib::InserMessage($new_row_msg, $arrID, $status = 'inbox');
        if ($msg_id_inbox) {
            $num_send++;
            //insert vao bang feed
            $feed_sql = "(4,{$receiver_user['id']},{$msg_id_inbox},{$new_row_msg['mt_date']},{$sender_id},0)";
            $feed_sql = "INSERT INTO feed (`type`,`user_id`,`ref_id`,`time`,`act_user_id`,`item_id`) VALUES " . $feed_sql;
            DB::query($feed_sql);
        }
        if ($once_way == false) {
            $new_row_msg['mt_read'] = 1;
            $new_row_msg['mt_ref_id'] = $ref_id;
            $msg_id_sent = AZLib::InserMessage($new_row_msg, $arrID, $status = 'sent');
            $num_send++;
        } else {
            $msg_id_sent = true;
        }
        // Nếu tin được tạo mới là tin nhắn trả lời
        //if($inbox_ref_id)
        //{
        // Đặt cờ đã có tin nhắn trả lời cho tin nhắn gốc trong cả "inbox" và "sent"
        //DB::query('	UPDATE message_topics SET mt_has_reply = 1 WHERE mt_id = ' . $ref_id . ' AND mt_vid_folder = \'inbox\'');
        //	DB::query('	UPDATE message_topics SET mt_has_reply = 1 WHERE mt_id = ' . $inbox_ref_id);
        //}
        if ($msg_id_inbox && $msg_id_sent) {
            $count_pm = true;
            // Đối với tin trả lời, chỉ đếm những tin trả lời mới cho tin thuộc các luồng tin khác nhau
            if ($ref_id) {
                // Kiểm tra xem trong luồng tin hiện tại có tin trả lời nào chưa đọc hay không
                $re = DB::query('SELECT COUNT(*) AS unreadCount FROM message_topics
								WHERE mt_ref_id = ' . $ref_id . ' 
									AND mt_vid_folder = \'inbox\' AND mt_owner_id = ' . $receiver_user["id"] . '
									AND mt_read = 0');
                if ($re) {
                    $row = mysql_fetch_assoc($re);
                    // Nếu có thì không tính thêm tin này vào tổng pm
                    if ($row['unreadCount'] > 1) {
                        $count_pm = false;
                    }
                }
            }
            if ($count_pm) {
                DB::query('UPDATE user SET total_pm = total_pm + 1 WHERE id=' . $receiver_user["id"]);
            }
            User::getUser($receiver_user["id"], 0, 1);
            DB::query("UPDATE message_text SET msg_sent_to_count = {$num_send} WHERE msg_id = {$msg_id}");
            if ($receiver_user['email'] && $receiver_user['email_alert']) {
                $link = WEB_ROOT . Url::build('message');
                $content = trim(addslashes(AZLib::parseBBCode($title . ' - ' . $content, true)));
                AZLib::addCronJob('pm', $content, $receiver_user['id'], User::user_name(), '', 0, '', $link);
            }
            return true;
        } else {
            return false;
        }
    }
 function action_reply_entry_comment()
 {
     $act_ = Url::get('act_');
     $comment_id = (int) Url::get('re_c_entry_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('user_entry_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['parent_id'] == 0 || $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!
         $json = '({"msg":"success"})';
         echo $json;
         exit;
     }
     $entry_id = $comment_row['entry_id'];
     $entry = DB::select('user_entry', "id={$entry_id}");
     if (!$entry || $entry && $entry['status'] == 0) {
         $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 />', '&nbsp;', $content);
         $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;
         }
         $comment = array('time' => time(), 'post_ip' => AZLib::ip(), 'content' => $content, 'entry_id' => $entry['id'], 'order_time' => time(), 'parent_id' => $parent_id, 'receiver_user_id' => $entry['user_id'], 'receiver_user_name' => $entry['user_name'], 'display' => 1, 'status' => 1);
         $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'];
         }
         $id = DB::insert('user_entry_comment', $comment);
         if ($id) {
             $re = DB::query("SELECT id FROM user_entry_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 user_entry_comment SET display = 0 WHERE parent_id = {$parent_id} AND display = 1 AND id<={$row['id']}");
                     }
                 }
             }
             if ($comment_id == $parent_id) {
                 DB::query("UPDATE user_entry_comment SET replied_status = 1,have_child = have_child + 1, order_time = " . time() . " WHERE id = {$comment_id}");
             } else {
                 DB::query("UPDATE user_entry_comment SET have_child = have_child + 1, order_time = " . time() . " WHERE id = {$parent_id}");
                 DB::query("UPDATE user_entry_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=6");
         }
         //Cập nhật cron job
         $user_item = User::getUser($entry['user_id']);
         if ($user_item['email'] && $user_item['email_alert'] && $user_item['id'] != User::id()) {
             $link = WEB_ROOT . '?page=user_entry&user_name=' . $entry['user_name'] . '&cmd_entry=view&entry_id=' . $entry['id'] . '&ebname=' . AZLib::safe_title($entry['title']);
             $link = AZRewrite::formatUrl($link);
             $title = "<a href='{$link}' target='_blank' style='text-decoration:none;color:#003399;'><font color='#003399'>{$entry['title']}</font></a>";
             AZLib::addCronJob('entry_comment', AZLib::parseBBCode($content, true), $user_item['id'], User::user_name(), '', $entry['id'], $title, $link);
         }
     } else {
         if ($comment_row['replied_status'] == 0) {
             DB::query("UPDATE user_entry_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=6");
     }
     $json .= "})";
     echo $json;
     exit;
 }
Exemple #3
0
 function transaction()
 {
     // viet luu but
     header("Content-type: application/xml");
     if (!User::is_login()) {
         echo "<comments><content>no_login</content></comments>";
         exit;
     } else {
         if (User::is_block()) {
             echo "<comments><content>no_perm</content></comments>";
             exit;
         }
         if (AZLib::isBlackList(User::$current->data['id'], AZLib::getParam('user_id'))) {
             echo "<comments><content>blacklist</content></comments>";
             exit;
         }
         if (AZLib::checkBadWord(AZLib::getParam('content'))) {
             echo "<comments><content>bad_word</content></comments>";
             exit;
         }
         $user_id = AZLib::getParam('user_id');
         if (!($user = User::getUser($user_id))) {
             echo "<comments><content>no_perm</content></comments>";
             exit;
         }
         $content = preg_replace("/\n/", "<br />", Url::get('content'));
         $content = str_replace('<br /><br />', '&nbsp;', $content);
         $comment_content = $content;
         $id = DB::insert('comment_user', array('content' => $comment_content, 'time' => TIME_NOW, 'post_ip' => AZLib::ip(), 'sender_user_id' => User::id(), 'sender_user_name' => User::user_name(), 'receiver_user_id' => $user['id'], 'receiver_user_name' => $user['user_name'], 'is_read' => 0));
         if ($id) {
             DB::query('UPDATE user set total_comment_user=total_comment_user+1 WHERE id=' . $user['id']);
             // so luu but
             User::getUser($user['id'], 0, 1);
             if ($user['email'] && $user['email_alert'] && $user['id'] != User::id()) {
                 //Add to cron job:
                 $link = WEB_ROOT . AZRewrite::formatUrl('?page=shop&user_name=' . $user['user_name'] . '&mode=comment');
                 AZLib::addCronJob('user_comment', AZLib::parseBBCode($comment_content, true), $user['id'], User::user_name(), '', 0, '', $link);
             }
         }
         $time = $up_time = date('H:i | ');
         $xml = "<comments><content><![CDATA[" . AZLib::parseBBCode($comment_content) . "]]></content><post_time>{$time}</post_time></comments>";
         echo $xml;
         System::halt();
     }
 }
Exemple #4
0
 function on_submit()
 {
     if (User::checkLock4Ever(1)) {
         Url::redirect_current();
     }
     //check bảo mật
     $just_registed_s = 0;
     $just_registed_c = 0;
     if (isset($_SESSION['just_registed'])) {
         $just_registed_s = $_SESSION['just_registed'];
     }
     if (isset($_COOKIE['just_registed'])) {
         $just_registed_c = $_COOKIE['just_registed'];
     }
     if ($just_registed_s > TIME_NOW - 120 || $just_registed_c > TIME_NOW - 120 || !REG_ON) {
         Url::redirect_current();
     }
     //END check bảo mật
     // check de ban IP
     $ip = AZLib::ip();
     $arr_badwords = AZLib::checkBadWord($ip, true);
     if ($arr_badwords["bad"] != "" && $arr_badwords["bad_key"] != "") {
         $this->setFormError('ban_ip', "Có lỗi xẩy ra");
     }
     // end check de ban IP
     $full_name = Url::get('full_name');
     $email = Url::get('email');
     $user_name = Url::get('register_user_name');
     $mobile_phone = AZLib::trimSpace(Url::get('mobile_phone'));
     $password = AZLib::trimSpace(Url::get('register_password'));
     $confirm_password = AZLib::trimSpace(Url::get('confirm_password'));
     $this->checkFormInput('Tên đầy đủ', 'full_name', $full_name, 'str', false, '', 0, 50);
     $this->checkFormInput('Email', 'email', $email, 'email', true, '', 6, 50);
     $this->checkFormInput('Tên truy cập', 'user_name', $user_name, 'uname', true, '', 4, 50);
     $this->checkFormInput('Điện thoại di động', 'mobile_phone', $mobile_phone, 'str', false, '', 0, 50);
     $this->checkFormInput('Mật khẩu truy cập', 'register_password', $password, 'str', true, '', 6, 50);
     $this->checkFormInput('Nhập lại mật khẩu', 'confirm_password', $confirm_password, 'str', true, '', 6, 50);
     if (!$this->errNum) {
         if ($password != $confirm_password) {
             $this->setFormError('captcha_register', "Nhập lại Mật khẩu truy cập không khớp!");
             return;
         }
     }
     $captcha_register = Url::get('captcha_register');
     if ($mobile_phone && !AZLib::is_mobile($mobile_phone)) {
         $mobile_phone = "";
     }
     if ($captcha_register == '') {
         $this->setFormError('captcha_register', "Bạn chưa nhập <b>Mã bảo mật</b>!");
     } else {
         if (!isset($_SESSION["enbac_validate"]) || $captcha_register != $_SESSION["enbac_validate"]) {
             $this->setFormError('captcha_register', "<b>Mã bảo mật</b> không chính xác!");
         }
     }
     if ((int) Url::get('confirm_register') != 1) {
         $this->setFormError('confirm_register', "Bạn phải đọc và đồng ý với những <a target=\"_blank\" href=\"http://help.enbac.com/content/4/5/en/Quy-che-thanh-vien.html\" >điều khoản của Enbac.com</a>!");
     }
     if (!$this->errNum) {
         if (DB::exists('SELECT id FROM `user` WHERE `email`="' . $email . '"')) {
             $this->setFormError('email', "<b>Email</b> bạn chọn đã tồn tại, hãy chọn lại một <b>Email</b> khác!");
         } elseif (DB::exists('SELECT id FROM `user` WHERE `user_name`="' . $user_name . '"')) {
             $this->setFormError('email', "<b>Tên truy cập</b> bạn chọn đã tồn tại, hãy chọn lại một <b>Tên truy cập</b> khác!");
         } else {
             $user_info = array('user_name' => $user_name, 'email' => $email, 'password' => User::encode_password($password), 'full_name' => $full_name, 'mobile_phone' => $mobile_phone, 'create_time' => TIME_NOW, 'is_active' => (int) (bool) USER_ACTIVE_ON, 'reg_ip' => AZLib::ip());
             $id = DB::insert('user', $user_info);
             if ($id) {
                 $_SESSION['just_registed'] = TIME_NOW;
                 AZLib::my_setcookie('just_registed', TIME_NOW);
                 if (USER_ACTIVE_ON && $user_info['is_active'] == 1) {
                     global $display;
                     $active = DB::select('user_active', 'user_id=' . $id);
                     $active_code = md5(TIME_NOW . $user_info['password']);
                     if ($active) {
                         $active = array('id' => $active['id'], 'user_id' => $id, 'active_code' => $active_code, 'time' => TIME_NOW);
                     } else {
                         $active = array('user_id' => $id, 'active_code' => $active_code, 'time' => TIME_NOW);
                     }
                     DB::insert('user_active', $active, true);
                     $display->add('eb_url', WEB_ROOT);
                     $display->add('user_id', $id);
                     $display->add('user_name', $user_info['user_name']);
                     $display->add('active_code', $active_code);
                     $display->add('WEB_NAME', WEB_NAME);
                     $display->add('MAIL_FOOTER', MAIL_FOOTER);
                     $content_email = $display->output('send_active_mail', 1, 'RegisterSuccess');
                     //Send email here;
                     if (System::sendEBEmail($user_info['email'], 'Kích hoạt tài khoản!', $content_email)) {
                         //$this->setFormSucces('','<b>Chúc mừng bạn đã đăng ký tài khoản thành công!</b><br /><br />Mã kích hoạt đã được gửi đi tới E-mail: "'.$user_info['email'].'"<br />Bạn hãy check lại Email để kích hoạt tài khoản của mình!');
                         Url::redirect('reg_success', array('cmd' => 'notify'));
                     } else {
                         $this->setFormError('', '<b>Chúc mừng bạn đã đăng ký tài khoản thành công!</b><br /><br />Tuy nhiên hệ thống chưa gửi được Mã kích hoạt tới E-mail: "' . $user_info['email'] . '"!<br />Bạn có thể <a href="' . Url::build('reg_success', array('cmd' => 'active')) . '">click vào đây</a> để hệ thống gửi lại mã kích hoạt vào Email của mình!');
                     }
                     $this->show_form = false;
                 } else {
                     User::Login($id);
                     Url::redirect('reg_success');
                 }
             } else {
                 $this->setFormError('', "Chưa đăng ký được, mời bạn thử lại!");
             }
         }
     }
 }
Exemple #5
0
 static function LogOut()
 {
     if ((int) $_SESSION['user_id']) {
         DB::query("UPDATE user SET last_ip='" . AZLib::ip() . "' WHERE id=" . (int) $_SESSION['user_id'], __LINE__ . __FILE__);
     }
     $_SESSION['user_id'] = 0;
     $_SESSION['user_name'] = '';
     if (isset($_SESSION['user_lock'])) {
         $_SESSION['user_lock'] = NULL;
         unset($_SESSION['user_lock']);
     }
     #########################################
     if (isset($_SESSION['load_wish_list'])) {
         $_SESSION['load_wish_list'] = NULL;
         unset($_SESSION['load_wish_list']);
     }
     if (isset($_SESSION['wish_item'])) {
         $_SESSION['wish_item'] = NULL;
         unset($_SESSION['wish_item']);
     }
     #########################################
     if (isset($_SESSION['openid_url'])) {
         $_SESSION['openid_url'] = NULL;
         unset($_SESSION['openid_url']);
     }
     //Remove remember password cookies:
     if (isset($_COOKIE['az_id']) || isset($_COOKIE['password'])) {
         AZLib::my_setcookie('az_id', "", TIME_NOW - 3600);
         AZLib::my_setcookie('password', "", TIME_NOW - 3600);
     }
     AZLib::my_setcookie('user_wish_list_items', "", TIME_NOW - 3600);
 }
Exemple #6
0
    function on_submit()
    {
        if (User::checkLock4Ever(1)) {
            Url::redirect_current();
        }
        $user_name = AZLib::getParam('user_name_this');
        $password = AZLib::getParam('password_this');
        $this->checkFormInput('Tên truy cập', 'user_name', $user_name, 'uname', true, '', 4, 50);
        $this->checkFormInput('Mật khẩu truy cập', 'password', $password, 'str', true, '', 6, 50);
        // check de ban IP
        $ip = AZLib::ip();
        $arr_badwords = AZLib::checkBadWord($ip, true);
        if ($arr_badwords["bad"] != "" && $arr_badwords["bad_key"] != "") {
            $this->setFormError('ban_ip', "Có lỗi xẩy ra. Hãy kiểm tra lại");
        }
        // end check de ban IP
        if (!$this->errNum) {
            $user_data = DB::fetch('SELECT id, user_name, password, is_active, block_time FROM user WHERE user_name="' . $user_name . '"');
            if (!USER_ACTIVE_ON && $user_data && $user_data['is_active']) {
                DB::query("UPDATE user SET is_active=0 WHERE id=" . $user_data['id']);
                DB::delete('user_active', 'user_id=' . $user_data['id']);
                User::getUser($user_data['id'], 0, 1);
            }
            if ($user_data && $user_data['password'] == User::encode_password($password)) {
                if (USER_ACTIVE_ON && $user_data['is_active']) {
                    //Chưa kích hoạt
                    $this->setFormError('user_name', "Bạn chưa kích hoạt tài khoản!<br /><br />Bạn hãy check lại mail để kích hoạt lại tài khoản<br />\r\n\t\t\t\t\thoặc <a href=''>click vào đây</a> để hệ thống gửi lại email kích hoạt!");
                } else {
                    $alert = '';
                    $href = base64_decode(Url::get('href'));
                    if (!$href) {
                        $href = Url::build('home');
                    }
                    if ($user_data['block_time'] == -1) {
                        $this->setFormError('user_name', "Tài khoản hoặc mật khẩu không đúng!");
                    } elseif ($user_data['block_time'] > TIME_NOW) {
                        $user_lock = DB::select('user_lock', 'user_id=' . $user_data['id']);
                        if ($user_lock) {
                            if ($user_lock['type'] == 1) {
                                //Khoá vĩnh viễn
                                User::LogOut();
                                DB::delete(_SESS_TABLE, 'user_id=' . $user_id, __LINE__ . __FILE__);
                                Url::access_denied();
                            } elseif ($user_lock['type'] == 3) {
                                //Khoá vĩnh viễn + cookie
                                User::lock4Ever(true, $user_data['id']);
                                Url::access_denied();
                            } else {
                                if ($user_lock['note']) {
                                    $user_lock['note'] = '\\nLý do: ' . str_replace(array('"', "'"), '', $user_lock['note']);
                                }
                                $alert = '<script>
											alert("Tài khoản của bạn đang tạm khoá tới ' . date('h:i, d/m/Y', $user_data['block_time']) . '!' . $user_lock['note'] . '");
											window.location="' . $href . '";
										</script>';
                                //$this->setFormError('user_name',"Tài khoản của bạn đang tạm khoá tới ".date('d/m/Y H:i',$user_data['block_time'])."!".$user_lock['note']);
                            }
                        }
                        $_SESSION['user_lock'] = true;
                    }
                    if (Url::get('set_cookie') == 'on') {
                        $year = 60 * 60 * 24 * 365 + TIME_NOW;
                        AZLib::my_setcookie("az_id", $user_data['id'], $year);
                        AZLib::my_setcookie("password", $user_data['password'], $year);
                    }
                    $_SESSION['is_load_page_first'] = 1;
                    // dung jQueryUI de load bang thong bao
                    User::LogIn($user_data['id']);
                    if (isset($_SESSION['user_lock']) && $_SESSION['user_lock']) {
                        echo $alert;
                        exit;
                    } else {
                        Url::redirect_url($href);
                    }
                }
            } else {
                $this->setFormError('user_name', "Tài khoản hoặc mật khẩu không đúng!");
            }
        }
    }
 function feedback()
 {
     header("Content-type: application/xml");
     $pattern = '/^xe360/i';
     $content = trim(AZLib::getParam('content'));
     $comment_id = (int) Url::get('comment_id', 0);
     $sender_user_name = trim(AZLib::getParam('user_name'));
     $sender_email = trim(AZLib::getParam('sender_email'));
     $comment_row = array();
     if (isset($_COOKIE['setTimeOutComment'])) {
         if (time() - $_COOKIE['setTimeOutComment'] <= 30) {
             // 30 giay
             echo "<comments><content>time_out</content></comments>";
             exit;
         }
     } else {
         AZLib::my_setcookie("setTimeOutComment", time(), 30 + TIME_NOW);
         // 30 giay
     }
     if (preg_match($pattern, $sender_user_name) || preg_match($pattern, $sender_email) || preg_match($pattern, $content)) {
         echo "<comments><content>bad_word</content></comments>";
         exit;
     }
     if (User::is_login() && User::is_block()) {
         echo "<comments><content>no_perm</content></comments>";
         exit;
     }
     if ($comment_id) {
         $comment_row = DB::select('comment', "id={$comment_id}");
         if (!$comment_row) {
             echo "<comments><content>no_perm</content></comments>";
             exit;
         }
         if (User::is_login() && $comment_row['sender_user_id'] == User::id()) {
             //Không được trả lời cho chính mình!
             echo "<comments><content>no_perm</content></comments>";
             exit;
         }
         if (!($item = Item::get_item($comment_row['item_id']))) {
             echo "<comments><content>no_perm</content></comments>";
             exit;
         }
     } else {
         $item_id = (int) Url::get('item_id', 0);
         if (!$item_id || !($item = Item::get_item($item_id))) {
             echo "<comments><content>no_perm</content></comments>";
             exit;
         }
     }
     $item_memcache = $item;
     if (AZLib::isBlackList(User::id(), $item['user_id'])) {
         echo "<comments><content>blacklist</content></comments>";
         exit;
     }
     if (!User::is_login() && AZLib::checkBadWord($sender_user_name)) {
         echo "<comments><content>bad_word</content></comments>";
         exit;
     }
     if ($item["state"] == 1 && !User::have_permit(ADMIN_ITEM)) {
         echo "<comments><content>no_perm</content></comments>";
         exit;
     }
     $username = strtolower($sender_user_name);
     if (!User::is_login() && (strlen($username) < 3 || strlen($sender_email) < 3 || $username == 'admin' || $username == 'administrator' || $username == 'moderator' || $username == 'enbac')) {
         echo "<comments><content>bad_word</content></comments>";
         exit;
     }
     if (AZLib::checkBadWord($content)) {
         echo "<comments><content>bad_word</content></comments>";
         exit;
     }
     if (!User::is_login()) {
         $captcha = AZLib::getParam('captcha');
         if (!isset($_SESSION["enbac_validate"]) || $captcha == '' || $captcha != $_SESSION["enbac_validate"]) {
             echo "<comments><content>false_captcha</content></comments>";
             exit;
         }
     }
     $content = preg_replace("/\n/", "<br />", $content);
     $content = str_replace('<br /><br />', '&nbsp;', $content);
     $receiver_user_id = 0;
     $receiver_username = '';
     if ($comment_id) {
         if ($comment_row['parent_id']) {
             $receiver_user_id = $comment_row['sender_user_id'];
             $receiver_username = $comment_row['sender_user_name'];
             if ($receiver_user_id) {
                 $content = '@<a href="' . WEB_DIR . $receiver_username . '" class="fast_reply_link" title="' . $receiver_username . '">' . $receiver_username . '</a>: ' . $content;
             } else {
                 $content = '<font color="#999">@<span style="text-decoration:underline">' . $receiver_username . '</span> </font>: ' . $content;
             }
             $parent_id = $comment_row['parent_id'];
         } else {
             $parent_id = $comment_row['id'];
         }
     } else {
         $parent_id = 0;
     }
     $user_item = User::getUser($item['user_id']);
     if ($user_item) {
         if (User::id()) {
             $sender_user_name = User::user_name();
         } else {
             // set guest cookie
             $week = 60 * 60 * 24 * 365 + TIME_NOW;
             AZLib::my_setcookie("guest_name", $sender_user_name, $week);
             AZLib::my_setcookie("guest_email", $sender_email, $week);
         }
         $up_up_count = '';
         if ($content != '') {
             $comment = array('content' => $content, 'item_id' => $item['id'], 'time' => TIME_NOW, 'order_time' => TIME_NOW, 'post_ip' => AZLib::ip(), 'parent_id' => $parent_id, 'receiver_user_id' => $item['user_id'], 'receiver_user_name' => $item['user_name'], 'display' => 1);
             if (User::id()) {
                 if ($item['user_id'] == User::id()) {
                     //Chuyển trạng thái đã trả lời khi comment chính topic của mình!
                     $comment['status'] = 1;
                 }
                 $comment['sender_user_id'] = User::id();
                 $comment['sender_user_name'] = User::user_name();
             } else {
                 $comment['sender_user_id'] = 0;
                 $comment['sender_user_name'] = $sender_user_name;
                 $comment['sender_email'] = $sender_email;
             }
             if ($comment_row && $comment_row['sender_user_id'] && $comment_row['sender_user_id'] != $item['user_id']) {
                 $comment['replied_user_id'] = $comment_row['sender_user_id'];
                 $comment['replied_user_name'] = $comment_row['sender_user_name'];
             } elseif ($comment_row && $comment_row['sender_user_id'] == $item['user_id']) {
                 $comment['replied_status'] = 1;
             }
             $id = DB::insert('comment', $comment);
             if ($id) {
                 if (!User::id()) {
                     AZLib::reload_captcha();
                 }
                 if ($parent_id) {
                     $re = DB::query("SELECT id FROM comment WHERE item_id = {$item['id']} AND 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) {
                         if (User::is_login() && $item['user_id'] == User::id()) {
                             DB::query("UPDATE comment SET have_child = have_child + 1, order_time = " . time() . ", status=1 WHERE id = {$parent_id}");
                         } else {
                             DB::query("UPDATE comment SET have_child = have_child + 1, order_time = " . time() . " WHERE id = {$parent_id}");
                         }
                     } else {
                         DB::query("UPDATE comment SET have_child = have_child + 1, order_time = " . time() . " WHERE id = {$parent_id}");
                         if (User::is_login() && $item['user_id'] == User::id()) {
                             DB::query("UPDATE comment SET 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=1");
                         }
                     }
                     if (User::is_login()) {
                         //Nếu là thành viên
                         //Cập nhật lại replied_status nếu chưa được check!
                         if ($item['user_id'] != User::id() && $comment_row['replied_user_id'] == User::id() && $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");
                             //Cập nhật comment mới cho chính mình
                             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);
                         }
                         if ($item['user_id'] != User::id()) {
                             //Nếu ko fải giao dịch của mình
                             //Cập nhật comment mới cho chủ topic
                             DB::query('UPDATE user SET total_new_comment = total_new_comment + 1 WHERE id=' . $item['user_id']);
                             User::getUser($item['user_id'], 0, 1);
                         } elseif ($comment_row && $comment_row['status'] == 0) {
                             //Cập nhật comment mới cho chính mình
                             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);
                         }
                         //Cập nhật comment mới cho người có comment được trả lời
                         if ($comment_row['sender_user_id'] && $comment_row['sender_user_id'] != $item['user_id'] && $comment_row['sender_user_id'] != User::id() && $comment_row['sender_user_id'] != $item['user_id']) {
                             //Nếu trả lời comment cho 1 người nào đó ko fải chủ topic
                             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);
                         }
                     } else {
                         //Nếu là khách vãng lai
                         //Cập nhật comment mới cho chủ topic
                         DB::query('UPDATE user SET total_new_comment = total_new_comment + 1 WHERE id=' . $item['user_id']);
                         User::getUser($item['user_id'], 0, 1);
                         //Cập nhật comment mới cho người có comment được trả lời
                         if ($comment_row['sender_user_id'] && $comment_row['sender_user_id'] != $item['user_id'] && $comment_row['sender_user_id'] != $item['user_id']) {
                             //Nếu trả lời comment cho 1 người nào đó ko fải chủ topic
                             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']}");
             $up_up_count = '<up_count>';
             $up_up_count .= $user_item['up_item'];
             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);
             }
             $up_up_count .= '</up_count>';
             //Cập nhật cron job
             if ($user_item && $user_item['email'] && $user_item['email_alert'] && $user_item['id'] != User::id()) {
                 if (User::id()) {
                     $sender_email = '';
                 }
                 $link = WEB_ROOT . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . AZLib::safe_title($item['name']));
                 $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), $user_item['id'], User::id() ? User::user_name() : $sender_user_name, $sender_email, $item['id'], $title, $link);
             }
         } else {
             $id = 0;
         }
         $time = date('H:i - d/m');
         $xml = "<comments><content><![CDATA[" . AZLib::parseBBCode($content) . "]]></content><post_time>" . date('H:i') . "</post_time>";
         $action = 'item_comment';
         if (User::id() != $item['user_id']) {
             require_once ROOT_PATH . 'includes/enbac/comment.php';
             Comment::addNewComment($item['user_id']);
         }
         $xml .= $up_up_count . "<id>" . $id % 3 . "</id></comments>";
         //del cache html
         $caheFile = 'fb_' . $item['id'];
         StaticCache::delCache($caheFile);
         echo $xml;
         System::halt();
     }
 }
Exemple #8
0
 function on_submit()
 {
     $full_name = Url::get('full_name');
     $email = Url::get('email');
     $user_name = Url::get('register_user_name');
     $mobile_phone = AZLib::trimSpace(Url::get('mobile_phone'));
     $home_phone = AZLib::trimSpace(Url::get('home_phone'));
     $password = AZLib::trimSpace(Url::get('register_password'));
     $confirm_password = AZLib::trimSpace(Url::get('confirm_password'));
     $gender = (int) Url::get('gender');
     $yahoo_id = AZLib::trimSpace(Url::get('yahoo_id'));
     $skype_id = AZLib::trimSpace(Url::get('skype_id'));
     $address = AZLib::trimSpace(Url::get('address'));
     $website = AZLib::trimSpace(Url::get('website'));
     $this->checkFormInput('Tên đầy đủ', 'full_name', $full_name, 'str', false, '', 0, 50);
     $this->checkFormInput('Email', 'email', $email, 'email', true, '', 6, 50);
     $this->checkFormInput('Tên truy cập', 'user_name', $user_name, 'uname', true, '', 4, 50);
     $this->checkFormInput('Điện thoại di động', 'mobile_phone', $mobile_phone, 'str', false, '', 0, 50);
     $this->checkFormInput('Điện thoại bàn', 'home_phone', $home_phone, 'str', false, '', 0, 50);
     $this->checkFormInput('Mật khẩu truy cập', 'register_password', $password, 'str', true, '', 6, 50);
     $this->checkFormInput('Nhập lại mật khẩu', 'confirm_password', $confirm_password, 'str', true, '', 6, 50);
     if ($password != $confirm_password) {
         $this->setFormError('confirm_password', "Nhập lại Mật khẩu truy cập không khớp!");
         return;
     }
     if ($mobile_phone && !AZLib::is_mobile($mobile_phone)) {
         $mobile_phone = "";
     }
     if (!$this->errNum) {
         if (DB::exists('SELECT id FROM `user` WHERE `email`="' . $email . '"')) {
             $this->setFormError('email', "<b>Email</b> bạn chọn đã tồn tại, hãy chọn lại một <b>Email</b> khác!");
         } elseif (DB::exists('SELECT id FROM `user` WHERE `user_name`="' . $user_name . '"')) {
             $this->setFormError('email', "<b>Tên truy cập</b> bạn chọn đã tồn tại, hãy chọn lại một <b>Tên truy cập</b> khác!");
         } else {
             $user_info = array('user_name' => $user_name, 'email' => $email, 'password' => User::encode_password($password), 'full_name' => $full_name, 'mobile_phone' => $mobile_phone, 'home_phone' => $home_phone, 'create_time' => TIME_NOW, 'gender' => $gender == 1 ? 0 : 1, 'yahoo_id' => $yahoo_id, 'skype_id' => $skype_id, 'address' => $address, 'website' => $website, 'is_active' => (int) (bool) USER_ACTIVE_ON, 'reg_ip' => AZLib::ip());
             $id = DB::insert('user', $user_info);
             if ($id) {
                 if (USER_ACTIVE_ON && $user_info['is_active'] == 1) {
                     global $display;
                     $active = DB::select('user_active', 'user_id=' . $id);
                     $active_code = md5(TIME_NOW . $user_info['password']);
                     if ($active) {
                         $active = array('id' => $active['id'], 'user_id' => $id, 'active_code' => $active_code, 'time' => TIME_NOW);
                     } else {
                         $active = array('user_id' => $id, 'active_code' => $active_code, 'time' => TIME_NOW);
                     }
                     DB::insert('user_active', $active, true);
                     $display->add('eb_url', WEB_ROOT);
                     $display->add('user_id', $id);
                     $display->add('user_name', $user_info['user_name']);
                     $display->add('active_code', $active_code);
                     $content_email = $display->output('send_active_mail', 1, 'RegisterSuccess');
                     //Send email here;
                     if (System::sendEBEmail($user_info['email'], 'Kích hoạt tài khoản!', $content_email)) {
                         Url::redirect_current();
                     } else {
                         $this->setFormError('', '<b>Tạo mới tài khoản thành công!</b><br /><br />Tuy nhiên hệ thống chưa gửi được Mã kích hoạt tới E-mail: "' . $user_info['email'] . '"!');
                     }
                     $this->show_form = false;
                 } else {
                     Url::redirect_current();
                 }
             } else {
                 $this->setFormError('', "Chưa đăng ký được, mời bạn thử lại!");
             }
         }
     }
 }
Exemple #9
0
 function on_submit()
 {
     $title = AZLib::getParam('subject');
     $content = AZLib::getParam('content');
     $id_cats = AZLib::getParam('id_cats');
     $send_all = AZLib::getParam('send_all');
     $usernames = Url::get('user_names');
     $start_date = Url::get('start_date');
     $end_date = Url::get('end_date');
     $start_date_a = Url::get('start_date_a');
     $end_date_a = Url::get('end_date_a');
     $is_active = Url::get('user_active');
     set_time_limit(0);
     if ($id_cats != 0) {
         //gửi cho thành viên bán theo chuyên mục
         $sql_user_sell = 'SELECT user_id, user_name FROM item ';
         AZLib::getCats();
         if (CGlobal::$allCategories[$id_cats]['parent_id'] > 0) {
             $condition = ' category_id = "' . $id_cats . '"';
         } else {
             $condition = ' level_1_catid = "' . $id_cats . '"';
         }
         $num_row = mysql_fetch_assoc(DB::query("SELECT count(*) as num_total FROM (SELECT count(*) FROM item WHERE status=1 AND {$condition} GROUP BY user_id) AS i"));
         if ($num_row) {
             $num_row = (int) $num_row['num_total'];
         } else {
             $num_row = 0;
         }
         if ($num_row) {
             $num_record = 100;
             $num_query = ceil($num_row / $num_record);
             $new_row_msg = array('msg_date' => TIME_NOW, 'msg_post' => htmlspecialchars_decode(addslashes($content)), 'msg_sent_to_count' => $num_row, 'msg_deleted_count' => 0, 'msg_author_id' => User::$current->data['id'], 'msg_author_name' => User::$current->data['user_name'], 'msg_ip_address' => AZLib::ip());
             if ($title && $content && $num_row > 0) {
                 $msg_id = DB::insert('message_text', $new_row_msg);
                 for ($j = 0; $j < $num_query; $j++) {
                     $value_sql = '';
                     $update_sql = '';
                     $user = array();
                     $sql = 'SELECT user_id, item.user_name FROM item WHERE status=1 AND ' . $condition . ' GROUP BY user_id LIMIT ' . $j * $num_record . "," . $num_record;
                     $re = DB::query($sql);
                     if ($re) {
                         while ($user = mysql_fetch_assoc($re)) {
                             $value_sql .= ($value_sql ? "," : "") . "('" . $msg_id . "','" . TIME_NOW . "','" . $title . "','" . User::id() . "','" . User::user_name() . "','inbox','" . $user['user_id'] . "','" . $user['user_name'] . "')";
                             $update_sql .= ($update_sql ? "," : "") . $user['user_id'];
                             $this->total_record++;
                         }
                         $insert_sql = "INSERT INTO `message_topics` (`mt_msg_id`,`mt_date`,`mt_title`, `mt_from_id`, `mt_to_name`, `mt_vid_folder`, `mt_owner_id`, `mt_owner_name`) VALUES " . $value_sql;
                         DB::query($insert_sql);
                         DB::query('UPDATE user SET total_pm = total_pm + 1 WHERE id IN(' . $update_sql . ')');
                     }
                 }
             }
         }
     } elseif ($usernames != '' || $start_date != '' || $end_date != '' || $is_active) {
         $where = 'WHERE is_active = 0 AND block_time <= ' . TIME_NOW;
         if ($usernames != '') {
             //theo danh sách tài khoản thành viên
             $usernames = str_replace(' ', '', $usernames);
             $usernames = str_replace('"', '', $usernames);
             $usernames = str_replace("'", '', $usernames);
             $usernames = str_replace(',', "','", $usernames);
             $where .= " AND user_name IN ('" . $usernames . "') ";
         } else {
             if ($is_active) {
                 // gửi cho thành viên chính thức
                 $where .= " AND level>0";
                 if ($start_date_a != '' && strtotime($start_date_a)) {
                     $where .= " AND create_time>=" . strtotime($start_date_a);
                 }
                 if ($end_date_a != '' && strtotime($end_date_a)) {
                     $where .= " AND create_time<" . strtotime($end_date_a);
                 }
             } else {
                 //theo ngay thang nam
                 if ($start_date != '' && strtotime($start_date)) {
                     $where .= " AND create_time>=" . strtotime($start_date);
                 }
                 if ($end_date != '' && strtotime($end_date)) {
                     $where .= " AND create_time<" . strtotime($end_date);
                 }
             }
         }
         $count_total_user = '******' . $where;
         // echo $count_total_user;
         // exit;
         $num_row = DB::fetch($count_total_user);
         $num_record = 1000;
         $num_query = ceil($num_row['total'] / $num_record);
         $new_row_msg = array('msg_date' => TIME_NOW, 'msg_post' => htmlspecialchars_decode(addslashes($content)), 'msg_sent_to_count' => $num_row['total'], 'msg_deleted_count' => 0, 'msg_author_id' => User::$current->data['id'], 'msg_author_name' => User::$current->data['user_name'], 'msg_ip_address' => AZLib::ip());
         if ($title && $content && $num_row['total'] > 0) {
             $msg_id = DB::insert('message_text', $new_row_msg);
             for ($j = 0; $j < $num_query; $j++) {
                 $value_sql = '';
                 $update_sql = '';
                 $user = array();
                 $sql = "SELECT id, user_name FROM user " . $where . " ORDER BY id DESC LIMIT " . $j * $num_record . "," . $num_record;
                 $re = DB::query($sql);
                 if ($re) {
                     while ($user = mysql_fetch_assoc($re)) {
                         $value_sql .= ($value_sql ? "," : "") . "('" . $msg_id . "','" . TIME_NOW . "','" . $title . "','" . User::id() . "','" . User::user_name() . "','inbox','" . $user['id'] . "','" . $user['user_name'] . "')";
                         $update_sql .= ($update_sql ? "," : "") . $user['id'];
                         User::getUser($user['id'], 0, 1);
                         $this->total_record++;
                     }
                     $insert_sql = "INSERT INTO `message_topics` (`mt_msg_id`,`mt_date`,`mt_title`, `mt_from_id`, `mt_to_name`, `mt_vid_folder`, `mt_owner_id`, `mt_owner_name`) VALUES " . $value_sql;
                     DB::query($insert_sql);
                     DB::query('UPDATE user SET total_pm = total_pm + 1 WHERE id IN(' . $update_sql . ')');
                 }
             }
         }
     }
     Url::redirect('send_multi', array('action' => 'send', 'total' => $this->total_record));
 }
Exemple #10
0
 function fn_comment()
 {
     header("Content-type: application/xml");
     $content = trim(AZLib::getParam('content'));
     $comment_id = (int) Url::get('comment_id', 0);
     $comment_row = array();
     if ($content == '') {
         echo "<comments><content>no_perm</content></comments>";
         exit;
     }
     if (User::is_login()) {
         if (User::is_block()) {
             echo "<comments><content>no_perm</content></comments>";
             exit;
         }
         $sender_user_name = User::user_name();
         $sender_email = '';
     } else {
         $sender_user_name = AZLib::getParam('user_name');
         $sender_email = AZLib::getParam('sender_email', '');
         $username_lower = strtolower($sender_user_name);
         if (strlen($username_lower) < 3 || $username_lower == 'admin' || $username_lower == 'administrator' || $username_lower == 'moderator' || $username_lower == 'enbac') {
             echo "<comments><content>bad_word</content></comments>";
             exit;
         }
     }
     if ($comment_id) {
         $comment_row = DB::select("user_entry_comment", "id={$comment_id}");
         if (!$comment_row || $comment_row && User::is_login() && $comment_row['sender_user_id'] == User::id()) {
             //Không được trả lời cho chính mình!
             echo "<comments><content>no_perm</content></comments>";
             exit;
         }
         $entry_id = $comment_row['entry_id'];
     } else {
         $entry_id = (int) Url::get('entry_id', 0);
     }
     if (!$entry_id || !($user_entry = DB::select('user_entry', "id={$entry_id}"))) {
         echo "<comments><content>no_perm</content></comments>";
         exit;
     }
     if (User::is_login() && AZLib::isBlackList(User::id(), $user_entry['user_id'])) {
         echo "<comments><content>blacklist</content></comments>";
         exit;
     }
     if (!User::is_login() && AZLib::checkBadWord($sender_user_name) || AZLib::checkBadWord($content)) {
         echo "<comments><content>bad_word</content></comments>";
         exit;
     }
     if (AZLib::checkBadWord($content)) {
         echo "<comments><content>bad_word</content></comments>";
         exit;
     }
     if (!User::is_login()) {
         $captcha = AZLib::getParam('captcha');
         if (!isset($_SESSION["enbac_validate"]) || $captcha == '' || $captcha != $_SESSION["enbac_validate"]) {
             echo "<comments><content>false_captcha</content></comments>";
             exit;
         }
     }
     $content = preg_replace("/\n/", "<br />", $content);
     $content = str_replace('<br /><br />', '&nbsp;', $content);
     if ($comment_row) {
         if ($comment_row['parent_id']) {
             $parent_id = $comment_row['parent_id'];
             //$sender_user_name 	= $comment_row['sender_user_name'];
             $sender_user_name = User::user_name();
             if ($comment_row['sender_user_id']) {
                 $content = '@<a href="' . WEB_DIR . $comment_row['sender_user_name'] . '" class="fast_reply_link" title="' . $sender_user_name . '">' . $comment_row['sender_user_name'] . '</a>: ' . $content;
             } else {
                 $content = '<font color="#999">@<span style="text-decoration:underline">' . $sender_user_name . '</span> </font>: ' . $content;
             }
         } else {
             $parent_id = $comment_row['id'];
         }
     } else {
         $parent_id = 0;
     }
     // set guest cookie
     if (!User::id()) {
         $week = 60 * 60 * 24 * 365 + TIME_NOW;
         AZLib::my_setcookie("guest_name", $sender_user_name, $week);
         AZLib::my_setcookie("guest_email", $sender_email, $week);
     }
     $user_entry_comment = array('content' => $content, 'entry_id' => $user_entry['id'], 'time' => TIME_NOW, 'order_time' => TIME_NOW, 'post_ip' => AZLib::ip(), 'parent_id' => $parent_id, 'receiver_user_id' => $user_entry['user_id'], 'display' => 1, 'receiver_user_name' => $user_entry['user_name']);
     if (User::id()) {
         $user_entry_comment['sender_user_id'] = User::id();
     } else {
         $user_entry_comment['sender_user_id'] = 0;
         $user_entry_comment['sender_email'] = $sender_email;
     }
     $user_entry_comment['sender_user_name'] = $sender_user_name;
     if ($comment_row && $comment_row['sender_user_id'] && $comment_row['sender_user_id'] != $user_entry['user_id']) {
         //Lưu lại người được trả lời
         $user_entry_comment['replied_user_id'] = $comment_row['sender_user_id'];
         $user_entry_comment['replied_user_name'] = $comment_row['sender_user_name'];
     } elseif ($comment_row && $comment_row['sender_user_id'] == $user_entry['user_id']) {
         $user_entry_comment['replied_status'] = 1;
     }
     $id = DB::insert('user_entry_comment', $user_entry_comment);
     if ($id) {
         if (!User::id()) {
             AZLib::reload_captcha();
         }
         if ($parent_id) {
             $re = DB::query("SELECT id FROM user_entry_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 user_entry_comment SET display = 0 WHERE parent_id = {$comment_id} AND display = 1 AND id<={$row['id']}");
                     }
                 }
             }
             if ($comment_id == $parent_id) {
                 if (User::is_login() && $user_entry['user_id'] == User::id()) {
                     DB::query("UPDATE user_entry_comment SET have_child = have_child + 1, order_time = " . time() . ", status=1 WHERE id = {$parent_id}");
                 } else {
                     DB::query("UPDATE user_entry_comment SET have_child = have_child + 1, order_time = " . time() . " WHERE id = {$parent_id}");
                 }
             } else {
                 DB::query("UPDATE user_entry_comment SET have_child = have_child + 1, order_time = " . time() . " WHERE id = {$parent_id}");
                 if (User::is_login() && $user_entry['user_id'] == User::id()) {
                     DB::query("UPDATE user_entry_comment SET 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=5");
             //Cập nhật lại replied_status nếu chưa được check!
             if (User::is_login() && $comment_row['replied_user_id'] == User::id() && $comment_row['replied_status'] == 0) {
                 DB::query("UPDATE user_entry_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=6");
             }
         }
     }
     $total_feedback = DB::count('user_entry_comment', 'entry_id="' . $user_entry['id'] . '"');
     DB::update_id('user_entry', array('reply_count' => $total_feedback), $user_entry['id']);
     $xml = "<comments><content><![CDATA[" . AZLib::parseBBCode($content) . "]]></content><post_time>vài giây trước</post_time>";
     $xml .= "<id>" . $id % 3 . "</id><parent_id>{$parent_id}</parent_id></comments>";
     echo $xml;
     $user_item = User::getUser($user_entry['user_id']);
     if ($user_item && $user_item['email'] && $user_item['email_alert'] && $user_item['id'] != User::id()) {
         if (User::id()) {
             $sender_email = '';
         }
         $link = WEB_ROOT . '?page=user_entry&user_name=' . $user_entry['user_name'] . '&cmd_entry=view&entry_id=' . $user_entry['id'] . '&ebname=' . AZLib::safe_title($user_entry['title']);
         $link = AZRewrite::formatUrl($link);
         $title = "<a href='{$link}' target='_blank' style='text-decoration:none;color:#003399;'><font color='#003399'>{$user_entry['title']}</font></a>";
         AZLib::addCronJob('entry_comment', AZLib::parseBBCode($content, true), $user_item['id'], User::id() ? User::user_name() : $sender_user_name, $sender_email, $user_entry['id'], $title, $link);
     }
     System::halt();
 }