Example #1
0
 function getCommentSubItem()
 {
     global $display;
     $winner = array();
     global $user_id_arr, $stt, $item_per_page;
     $stt = 0;
     $is_admin_mod = array();
     $user_arr = array();
     $user_id_arr = array();
     $items = array();
     $limit = '';
     $subItemId = Url::get('subItemId');
     $divID = 'comment_list';
     $cmd = 'pagging_comment';
     $url_path = WEB_DIR . "ajax.php?act=comment&code=getCommentSubItem&show_all=1&id={$subItemId}&cmd=" . $cmd;
     $item_per_page = 100;
     $display->add('show_all', true);
     $pagging = ECPagging::fb_pagging($limit, $item_per_page, true, 'fb_page', $url_path, $divID);
     $sql = "SELECT id, time, content, item_id, sender_email, sender_user_name, sender_user_id, have_child,receiver_user_id,sub_item_id FROM comment WHERE sub_item_id=" . $subItemId . "  AND parent_id = 0 ORDER BY order_time DESC {$limit}";
     /*Đếm tổng số comment cho SubItem*/
     $select_comment_count = "SELECT comment_count FROM item_sub WHERE id={$subItemId} LIMIT 1";
     $subItemResult = DB::fetch($select_comment_count);
     $comment_count = 0;
     if (isset($subItemResult['comment_count']) && $subItemResult['comment_count'] > 0) {
         $comment_count = $subItemResult['comment_count'];
     }
     $display->add('comment_count', $comment_count);
     /*End comment count*/
     $allItems = $this->get_comment_thoitrang($sql);
     if ($allItems) {
         $items = $allItems['item'];
         if ($allItems['id_parent']) {
             $sql_sub = "SELECT id, time, content, item_id, sender_email, sender_user_name, sender_user_id,parent_id,receiver_user_id,sub_item_id FROM comment WHERE parent_id IN({$allItems['id_parent']})  ORDER BY order_time DESC";
             $subComment_all = $this->get_comment_thoitrang($sql_sub, 1);
             if ($subComment_all) {
                 $sub_comments = $subComment_all['item'];
                 foreach ($sub_comments as $id => $subs) {
                     if (isset($items[$id])) {
                         $items[$id]['sub_comment'] = $subs;
                     }
                 }
             }
         }
         unset($allItems);
     }
     if ($stt <= $item_per_page) {
         $pagging = ECPagging::fb_pagging($limit, $item_per_page, false, 'fb_page', $url_path, $divID);
         $display->add('show_fb_page', false);
     } else {
         $display->add('show_fb_page', true);
     }
     if ($user_id_arr) {
         $uid = implode(',', $user_id_arr);
         if ($uid != '') {
             $re = DB::query("SELECT id, avatar_url, gids, block_time, img_server FROM account WHERE id IN({$uid})");
             if ($re) {
                 while ($user = mysql_fetch_assoc($re)) {
                     $user_arr[$user['id']] = $user;
                 }
             }
         }
     }
     if ($items && $user_arr) {
         foreach ($items as &$item) {
             $item['content'] = $this->process_description($item['content']);
             if (isset($item['sub_comment']) && $item['sub_comment']) {
                 foreach ($item['sub_comment'] as &$sub_item) {
                     if ($sub_item['sender_user_id']) {
                         if (isset($user_arr[$sub_item['sender_user_id']])) {
                             $sub_item['avatar_url'] = $user_arr[$sub_item['sender_user_id']]['avatar_url'];
                             $sub_item['block_time'] = $user_arr[$sub_item['sender_user_id']]['block_time'];
                             $sub_item['gids'] = $user_arr[$sub_item['sender_user_id']]['gids'];
                             $sub_item['img_server'] = $user_arr[$sub_item['sender_user_id']]['img_server'];
                         }
                         if ($sub_item['avatar_url']) {
                             $sub_item['sender_avatar_url'] = EClassApi::getImageThumb($sub_item['avatar_url'], 60, 0, 1, $sub_item['img_server']);
                             if ($sub_item['parent_id'] > 0) {
                                 $html_content = '<a href="' . $sub_item['sender_link'] . '"><img src="' . $sub_item['sender_avatar_url'] . '" width="40" class="lazyload"/></a>';
                             } else {
                                 $html_content = '<a href="' . $sub_item['sender_link'] . '"><img src="' . $sub_item['sender_avatar_url'] . '" width="40" class="lazyload"/></a>';
                             }
                         } else {
                             $sub_item['sender_avatar_url'] = 'style/avatar/1.png';
                             $html_content = '<a href="' . $sub_item['sender_link'] . '"><img src="style/avatar/1.png" width="40" height="40" class="lazyload"/></a>';
                         }
                         if ($sub_item['block_time'] > TIME_NOW) {
                             $sub_item['is_block'] = 1;
                         } else {
                             $sub_item['is_block'] = 0;
                         }
                         $sub_item['htmlContent'] = $html_content;
                         //set quyen quan tri
                         if ($sub_item['gids']) {
                             $is_admin_mod = CGlobal::$group[User::check_admin($sub_item['gids'])];
                         } else {
                             $is_admin_mod = array();
                         }
                         $sub_item['is_admin_mod'] = $is_admin_mod;
                     }
                 }
             }
             if ($item['sender_user_id']) {
                 if (isset($user_arr[$item['sender_user_id']])) {
                     $item['avatar_url'] = $user_arr[$item['sender_user_id']]['avatar_url'];
                     $item['block_time'] = $user_arr[$item['sender_user_id']]['block_time'];
                     $item['gids'] = $user_arr[$item['sender_user_id']]['gids'];
                     $item['img_server'] = $user_arr[$item['sender_user_id']]['img_server'];
                 }
                 if ($item['avatar_url']) {
                     $item['sender_avatar_url'] = EClassApi::getImageThumb($item['avatar_url'], 60, 0, 1, $item['img_server']);
                     $html_content = '<a href="' . $item['sender_link'] . '"><img src="' . $item['sender_avatar_url'] . '" width="40"/></a>';
                 } else {
                     $item['sender_avatar_url'] = 'style/avatar/1.png';
                     $html_content = '<a href="' . $item['sender_link'] . '"><img src="style/avatar/1.png" width="40" height="40" /></a>';
                 }
                 $item['htmlContent'] = $html_content;
                 if ($item['block_time'] > TIME_NOW) {
                     $item['is_block'] = 1;
                 } else {
                     $item['is_block'] = 0;
                 }
                 //set quyen quan tri
                 if ($item['gids']) {
                     $is_admin_mod = CGlobal::$group[User::check_admin($item['gids'])];
                 } else {
                     $is_admin_mod = array();
                 }
                 $item['is_admin_mod'] = $is_admin_mod;
             }
         }
     }
     $account = null;
     if (User::is_login() && Item::$item['user_id'] == User::id()) {
         $account = User::$current->data;
     } else {
         if (isset(Item::$item['user_id'])) {
             $account = User::getUser(Item::$item['user_id']);
         }
         if (!$account) {
             $account = array('id' => 0, 'user_name' => '', 'create_time' => '', 'blast' => '', 'email' => '', 'show_email' => '', 'skype_id' => '', 'yahoo_id' => '');
         }
     }
     if (User::is_login()) {
         if (User::$current->data['mobile_phone'] != '') {
             $display->add('user_phone', true);
             $user_phone = User::$current->data['mobile_phone'];
         } elseif (User::$current->data['home_phone'] != '') {
             $display->add('user_phone', true);
             $user_phone = User::$current->data['home_phone'];
         } else {
             $display->add('user_phone', false);
             $user_phone = '';
         }
         $display->add('cur_user_name', User::$current->data['user_name']);
         $display->add('cur_created_time', User::$current->data['create_time']);
         $cur_user_name = User::$current->data['user_name'];
         $cur_created_time = User::$current->data['create_time'];
         if (User::$current->data['avatar_url'] == '') {
             $cur_avatar_url = 'style/avatar/1.png';
         } else {
             $cur_avatar_url = EClassApi::getImageThumb(User::$current->data['avatar_url'], 60, 0, 1, User::$current->data['img_server']);
         }
     } else {
         $cur_user_name = '';
         $cur_created_time = '';
         $user_phone = '';
         $cur_avatar_url = 'style/avatar/1.png';
         $display->add('cur_user_name', '');
         $display->add('cur_created_time', '');
         $display->add('check_user_name', '');
         $display->add('user_phone', false);
     }
     $guest_name = 'Số điện thoại';
     $guest_email = 'Email';
     if (isset($_COOKIE['guest_name'])) {
         if ($_COOKIE['guest_name'] == 'undefined' || $_COOKIE['guest_email'] == 'undefined') {
             $guest_name = 'Số điện thoại';
             $guest_email = 'Email';
         } else {
             $guest_name = $_COOKIE['guest_name'];
             $guest_email = $_COOKIE['guest_email'];
         }
     }
     $display->add('cur_user_name', $cur_user_name);
     $display->add('guest_name', $guest_name);
     $display->add('guest_email', $guest_email);
     $display->add('check_user_name', $account['user_name']);
     $display->add('cur_id', (int) User::id());
     $display->add('pagging', $pagging);
     $display->add('item_comments', $items);
     $display->add('item_id', Item::$item['id']);
     $display->add('category_id', Item::$item['category_id']);
     $display->add('item_name', Item::$item['name']);
     //rewrite URL
     $display->add('name_url', EClassApi::safe_title(Item::$item['name']));
     //End rewrite URL
     if (strtolower(Url::get('page')) == 'allfeedback' || Url::get('cmd') == $cmd) {
         echo '<div id="totalReplyCount" style="display:none;">' . @Item::$item['reply_count'] . '</div>';
     }
     $display->output('AllFeedbackList', false, 'AllFeedback');
 }