Exemple #1
0
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_TYPE.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 (!isset($_SESSION['UID']) || !is_numeric($_SESSION['UID'])) {
        return false;
    }
    $sql = "SELECT SQL_CALC_FOUND_ROWS PM.MID, PM.REPLY_TO_MID, PM.FROM_UID, PM_TYPE.TYPE, ";
    $sql .= "PM.SUBJECT, UNIX_TIMESTAMP(PM.CREATED) AS CREATED, USER.LOGON AS FROM_LOGON, ";
    $sql .= "USER.NICKNAME AS FROM_NICKNAME FROM PM INNER JOIN PM_TYPE ";
    $sql .= "ON (PM_TYPE.MID = PM.MID) INNER JOIN PM_SEARCH_RESULTS ";
    $sql .= "ON (PM_SEARCH_RESULTS.MID = PM.MID) LEFT JOIN USER ON (USER.UID = PM.FROM_UID) ";
    $sql .= "WHERE PM_SEARCH_RESULTS.UID = '{$_SESSION['UID']}' ";
    $sql .= "GROUP BY PM.MID 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);
    }
    return pm_process_result($result, $message_count);
}
    $pm_messages_array = pm_get_inbox($sort_by, $sort_dir, $page, 10);
} else {
    if ($current_folder == PM_FOLDER_SENT) {
        $pm_messages_array = pm_get_sent($sort_by, $sort_dir, $page, 10);
    } else {
        if ($current_folder == PM_FOLDER_OUTBOX) {
            $pm_messages_array = pm_get_outbox($sort_by, $sort_dir, $page, 10);
        } else {
            if ($current_folder == PM_FOLDER_SAVED) {
                $pm_messages_array = pm_get_saved_items($sort_by, $sort_dir, $page, 10);
            } else {
                if ($current_folder == PM_FOLDER_DRAFTS) {
                    $pm_messages_array = pm_get_drafts($sort_by, $sort_dir, $page, 10);
                } else {
                    if ($current_folder == PM_SEARCH_RESULTS) {
                        $pm_messages_array = pm_fetch_search_results($sort_by, $sort_dir, $page, 10);
                    }
                }
            }
        }
    }
}
echo "<h1>", gettext("Private Messages"), "<img src=\"", html_style_image('separator.png'), "\" alt=\"\" border=\"0\" />{$pm_folder_names_array[$current_folder]}</h1>\n";
if (isset($error_msg_array) && sizeof($error_msg_array) > 0) {
    html_display_error_array($error_msg_array, '96%', 'center');
} else {
    if (isset($_GET['message_sent'])) {
        html_display_success_msg(gettext("Message sent successfully."), '96%', 'center');
    } else {
        if (isset($_GET['message_saved'])) {
            html_display_success_msg(gettext("Message was successfully saved to 'Drafts' folder"), '96%', 'center');
Exemple #3
0
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);
}