{@ $is_search = in_array($search_target, ['title', 'content', 'title_content']) && $search_keyword; if ( $target_member_srl || $is_search ): if ( $is_search ): $_search_keyword = trim(utf8_normalize_spaces($search_keyword)); $_search_keyword = str_replace(' ', '%', $_search_keyword); $_search_keyword = '%' . $_search_keyword . '%'; endif; $total_count = $total_page = 0; $list_count = 20; $page_count = 10; $page = Context::get('page') ? intval($page) : 1; $message_list = []; $oDB = DB::getInstance(); $cond_args = []; $from = ' FROM member_message AS message'; $left_join = ' LEFT JOIN member ON member.member_srl = message.'; $left_join .= ( $message_type !== 'S' ) ? 'sender_srl' : 'receiver_srl'; $where = ' WHERE message.'; $where .= ( $message_type !== 'S' ) ? 'receiver_srl = ?' : 'sender_srl = ?'; $cond_args[] = $logged_info->member_srl; if ( $message_type !== 'N' ): $where .= ' AND message.message_type = ?'; $cond_args[] = $message_type; else: $where .= ' AND message.readed = ?'; $cond_args[] = 'N'; endif; if ( $target_member_srl ): $where .= ' AND message.'; $where .= ( $message_type !== 'S' ) ? 'sender_srl = ?' : 'receiver_srl = ?'; $cond_args[] = $target_member_srl; endif; if ( $is_search ): if ( $search_target === 'title_content' ): $where .= ' AND (title LIKE ? OR content LIKE ?)'; $cond_args[] = $_search_keyword; $cond_args[] = $_search_keyword; else: $where .= ' AND (' . $search_target . ' LIKE ?)'; $cond_args[] = $_search_keyword; endif; endif; $select_count = 'SELECT COUNT(*) AS count'; $select_rows = 'SELECT message_srl, message_type, related_srl, readed, title, member.member_srl, member.nick_name, message.regdate, readed_date'; $limit = ($page > 1) ? $list_count * ($page-1) . ', ' . $list_count : $list_count; $count_query = $select_count . $from . $left_join . $where; $list_query = $select_rows . $from . $left_join . $where . ' ORDER BY message.list_order ASC LIMIT ' . $limit; $stmt = $oDB->prepare($count_query); $stmt->execute($cond_args); $result = $stmt->fetchAll(); $total_count = $result[0]->count; $total_page = max(1, ceil($total_count / $list_count)); $page_navigation = new PageHandler($total_count, $total_page, $page, $page_count); if ( $total_count ): $stmt = $oDB->prepare($list_query); $stmt->execute($cond_args); $result = $stmt->fetchAll(); if ( !empty($result) ): foreach ( $result as $key => $val ): if ( !$val->member_srl ): $val->member_srl = ($val->sender_srl == $logged_info->member_srl) ? $val->receiver_srl : $val->sender_srl; $val->user_id = ''; $val->nick_name = lang('communication.cmd_message_from_non_member'); $val->user_name = $val->nick_name; endif; $no = $total_count - ($list_count * ($page-1)) - $key; $message_list[$no] = $val; endforeach; endif; endif; endif; }