Beispiel #1
0
function pm_get_message_count(&$pm_new_count, &$pm_outbox_count, &$pm_unread_count)
{
    // Default the variables to return 0 even on error.
    $pm_new_count = 0;
    $pm_outbox_count = 0;
    $pm_unread_count = 0;
    // Connect to the database.
    if (!($db = db::get())) {
        return false;
    }
    // Check the user UID.
    if (!isset($_SESSION['UID']) || !is_numeric($_SESSION['UID'])) {
        return false;
    }
    // PM folder types we'll be using.
    $pm_unread = PM_UNREAD;
    $pm_outbox = PM_OUTBOX;
    // Get the user's free space.
    $pm_free_space = pm_get_free_space($_SESSION['UID']);
    // Get a list of messages we have received.
    if (($message_array = pm_get_new_messages($pm_free_space)) !== false) {
        // Convert the array keys into a comma separated list.
        $mid_list = implode(',', array_filter(array_keys($message_array), 'is_numeric'));
        // Mark the selected messages as unread and notified.
        $sql = "UPDATE LOW_PRIORITY PM_TYPE INNER JOIN PM_RECIPIENT ";
        $sql .= "ON (PM_TYPE.MID = PM_RECIPIENT.MID AND PM_TYPE.UID = PM_RECIPIENT.TO_UID) ";
        $sql .= "SET PM_TYPE.TYPE = '{$pm_unread}', PM_RECIPIENT.NOTIFIED = 'Y' ";
        $sql .= "WHERE PM_TYPE.MID in ({$mid_list}) AND PM_TYPE.UID = '{$_SESSION['UID']}' ";
        $sql .= "AND (PM_TYPE.TYPE & {$pm_outbox}) ";
        if (!($result = $db->query($sql))) {
            return false;
        }
        // Number of new messages we've received for popup.
        $pm_new_count = sizeof($message_array);
    }
    // Unread message count.
    $sql = "SELECT COUNT(MID) FROM PM_TYPE WHERE (TYPE & {$pm_unread}) ";
    $sql .= "AND UID = '{$_SESSION['UID']}'";
    if (!($result = $db->query($sql))) {
        return false;
    }
    list($pm_unread_count) = $result->fetch_row();
    // Check for any undelivered messages waiting for the user.
    $sql = "SELECT COUNT(MID) AS OUTBOX_COUNT FROM PM_TYPE ";
    $sql .= "WHERE (TYPE & {$pm_outbox}) AND UID = '{$_SESSION['UID']}' ";
    if (!($result = $db->query($sql))) {
        return false;
    }
    list($pm_outbox_count) = $result->fetch_row();
    return true;
}
Beispiel #2
0
function pm_get_message_count(&$pm_new_count, &$pm_outbox_count, &$pm_unread_count)
{
    // Default the variables to return 0 even on error.
    $pm_new_count = 0;
    $pm_outbox_count = 0;
    $pm_unread_count = 0;
    // Connect to the database.
    if (!($db = db::get())) {
        return false;
    }
    // Check the user UID.
    if (($uid = session::get_value('UID')) === false) {
        return false;
    }
    // PM folder types we'll be using.
    $pm_unread = PM_UNREAD;
    $pm_outbox = PM_OUTBOX;
    $pm_sent_item = PM_SENT;
    // Get the user's free space.
    $pm_free_space = pm_get_free_space($uid);
    // Get a list of messages we have received.
    if ($messages_array = pm_get_new_messages($pm_free_space)) {
        // Convert the array keys into a comma separated list.
        $mid_list = implode(',', array_filter(array_keys($messages_array), 'is_numeric'));
        // Mark the selected messages as unread / received and make the
        // sent items visible to the sender.
        $sql = "UPDATE LOW_PRIORITY PM SET TYPE = '{$pm_unread}' WHERE MID in ({$mid_list}) ";
        $sql .= "AND TO_UID = '{$uid}'";
        if (!($result = $db->query($sql))) {
            return false;
        }
        $sql = "UPDATE LOW_PRIORITY PM SET SMID = 0 WHERE SMID IN ({$mid_list}) ";
        $sql .= "AND TYPE = '{$pm_sent_item}' AND TO_UID = '{$uid}'";
        if (!($result = $db->query($sql))) {
            return false;
        }
        // Number of new messages we've received for popup.
        $pm_new_count = sizeof($messages_array);
    }
    // Unread message count.
    $sql = "SELECT COUNT(MID) FROM PM WHERE (TYPE & {$pm_unread} > 0) ";
    $sql .= "AND TO_UID = '{$uid}'";
    if (!($result = $db->query($sql))) {
        return false;
    }
    list($pm_unread_count) = $result->fetch_row();
    // Check for any undelivered messages waiting for the user.
    $sql = "SELECT COUNT(MID) AS OUTBOX_COUNT FROM PM ";
    $sql .= "WHERE TYPE = '{$pm_outbox}' AND TO_UID = '{$uid}'";
    if (!($result = $db->query($sql))) {
        return false;
    }
    list($pm_outbox_count) = $result->fetch_row();
    return true;
}