function pm_process_result(mysqli_result $result, $message_count) { $message_array = array(); while (($pm_data = $result->fetch_assoc()) !== null) { if (!isset($pm_data['FROM_LOGON'])) { $pm_data['FROM_LOGON'] = gettext("Unknown user"); } if (!isset($pm_data['FROM_NICKNAME'])) { $pm_data['FROM_NICKNAME'] = ""; } $message_array[$pm_data['MID']] = array('CREATED' => $pm_data['CREATED'], 'FROM_UID' => $pm_data['FROM_UID'], 'FROM_LOGON' => $pm_data['FROM_LOGON'], 'FROM_NICKNAME' => $pm_data['FROM_NICKNAME'], 'MID' => $pm_data['MID'], 'RECIPIENTS' => array(), 'REPLY_TO_MID' => $pm_data['REPLY_TO_MID'], 'SUBJECT' => $pm_data['SUBJECT'], 'TYPE' => $pm_data['TYPE']); } pms_get_recipients($message_array); pms_have_attachments($message_array); return array('message_count' => $message_count, 'message_array' => $message_array); }
function pm_fetch_search_results($sort_by = 'CREATED', $sort_dir = 'DESC', $page = 1, $limit = 10) { if (!($db = db::get())) { return false; } $sort_by_array = array('PM.SUBJECT', 'TYPE', 'PM.FROM_UID', 'PM.TO_UID', 'CREATED'); $sort_dir_array = array('ASC', 'DESC'); if (!is_numeric($page) || $page < 1) { $page = 1; } if (!is_numeric($limit)) { $limit = 10; } $limit = abs($limit); $offset = calculate_page_offset($page, $limit); if (!in_array($sort_by, $sort_by_array)) { $sort_by = 'CREATED'; } if (!in_array($sort_dir, $sort_dir_array)) { $sort_dir = 'DESC'; } if (($uid = session::get_value('UID')) === false) { return false; } $message_array = array(); $sql = "SELECT SQL_CALC_FOUND_ROWS PM_SEARCH_RESULTS.MID, PM_SEARCH_RESULTS.TYPE, "; $sql .= "PM_SEARCH_RESULTS.FROM_UID, PM_SEARCH_RESULTS.TO_UID, PM_SEARCH_RESULTS.RECIPIENTS, "; $sql .= "PM_SEARCH_RESULTS.SUBJECT, UNIX_TIMESTAMP(PM_SEARCH_RESULTS.CREATED) AS CREATED, "; $sql .= "FUSER.LOGON AS FLOGON, FUSER.NICKNAME AS FNICK, "; $sql .= "TUSER.LOGON AS TLOGON, TUSER.NICKNAME AS TNICK FROM PM_SEARCH_RESULTS "; $sql .= "LEFT JOIN PM ON (PM.MID = PM_SEARCH_RESULTS.MID) "; $sql .= "LEFT JOIN USER FUSER ON (PM_SEARCH_RESULTS.FROM_UID = FUSER.UID) "; $sql .= "LEFT JOIN USER TUSER ON (PM_SEARCH_RESULTS.TO_UID = TUSER.UID) "; $sql .= "WHERE PM_SEARCH_RESULTS.UID = '{$uid}' AND PM.MID IS NOT NULL "; $sql .= "ORDER BY {$sort_by} {$sort_dir} LIMIT {$offset}, {$limit}"; if (!($result = $db->query($sql))) { return false; } $sql = "SELECT FOUND_ROWS() AS ROW_COUNT"; if (!($result_count = $db->query($sql))) { return false; } list($message_count) = $result_count->fetch_row(); if ($result->num_rows == 0 && $message_count > 0 && $page > 1) { return pm_fetch_search_results($sort_by, $sort_dir, $page - 1, $limit); } while ($pm_data = $result->fetch_assoc()) { if (isset($pm_data['FLOGON']) && isset($pm_data['PFNICK'])) { if (!is_null($pm_data['PFNICK']) && strlen($pm_data['PFNICK']) > 0) { $pm_data['FNICK'] = $pm_data['PFNICK']; } } if (isset($pm_data['TLOGON']) && isset($pm_data['PTNICK'])) { if (!is_null($pm_data['PTNICK']) && strlen($pm_data['PTNICK']) > 0) { $pm_data['TNICK'] = $pm_data['PTNICK']; } } if (!isset($pm_data['FLOGON'])) { $pm_data['FLOGON'] = gettext("Unknown user"); } if (!isset($pm_data['FNICK'])) { $pm_data['FNICK'] = ""; } if (!isset($pm_data['TLOGON'])) { $pm_data['TLOGON'] = gettext("Unknown user"); } if (!isset($pm_data['TNICK'])) { $pm_data['TNICK'] = ""; } $message_array[$pm_data['MID']] = $pm_data; } pms_have_attachments($message_array); return array('message_count' => $message_count, 'message_array' => $message_array); }