Example #1
0
    if (CmnFns::getGlobalVar('search_action', GET) == translate('Clear search results')) {
        CmnFns::redirect_js($_SERVER['PHP_SELF'] . '?searchOnly=' . $conf['app']['searchOnly']);
    }
    $search_array1 = $db->convertSearch2SQL('msgs.from_addr', CmnFns::getGlobalVar('f_criterion', GET), CmnFns::getGlobalVar('f_string', GET));
    $search_array2 = $db->convertSearch2SQL('msgs.subject', CmnFns::getGlobalVar('s_criterion', GET), CmnFns::getGlobalVar('s_string', GET));
    $search_array3 = $db->convertSearch2SQL('recip.email', CmnFns::getGlobalVar('t_criterion', GET), CmnFns::getGlobalVar('t_string', GET));
    $search_array4 = $db->convertSearch2SQL('msgs.mail_id', CmnFns::getGlobalVar('m_criterion', GET), CmnFns::getGlobalVar('m_string', GET));
    $search_array = array_merge($search_array1, $search_array2, $search_array3, $search_array4);
    $order = array('msgs.time_num', 'from_addr', 'msgs.subject', 'spam_level', 'recip.email', 'msgs.content', 'mail_id');
    // Arbitrary type for Admin
    //$content_type = (CmnFns::get_ctype() ? CmnFns::get_ctype() : 'A');
    //echo "Before query: " . date("l dS of F Y h:i:s A") . "<br><br>";
    if (CmnFns::getGlobalVar('searchOnly', GET) != 1) {
        // Print a loading message until database returns...
        printMessage(translate('Retrieving Messages...'));
        $messages = $db->get_user_messages($content_type, $_SESSION['sessionMail'], CmnFns::get_value_order($order), CmnFns::get_vert_order(), $search_array, 1, 0, $requestedPage);
    }
    // Compute maximum number of pages
    $maxPage = ceil($db->numRows / $sizeLimit) - 1;
    // If $requestedPage > $maxPage, then redirect to $maxPage instead of $requestedPage
    if ($requestedPage > $maxPage) {
        $query_string = CmnFns::array_to_query_string($_GET, array('page'));
        $query_string = str_replace('&amp;', '&', $query_string);
        CmnFns::redirect_js($_SERVER['PHP_SELF'] . '?' . $query_string . '&page=' . $maxPage);
    }
    if (CmnFns::getGlobalVar('searchOnly', GET) != 1) {
        showMessagesTable($content_type, $messages, $requestedPage, CmnFns::get_value_order($order), CmnFns::get_vert_order(), $db->numRows);
        // Hide the message after the table loads.
        hideMessage(translate('Retrieving Messages...'));
    }
}
Example #2
0
/**
* Update messages function
* @param string $content_type 'B', 'S', ...
* @param array $emailaddresses recipient email address(es)
* @param array $mail_id_array containing mail_id of messages to be deleted
* @param bool $all false (default) or true, if true all messages will be deleted
* @result return array of messages whose release failed
*/
function updateMessages($flag, $content_type, $emailaddresses, $mail_id_array, $all = false)
{
    $result_array = array();
    $db = new DBEngine();
    // Set autocommit to false to improve speed of $flag set
    $result = $db->db->autoCommit(false);
    $db->check_for_error($result, 'PEAR DB autoCommit(false)');
    if ($all) {
        $res = $db->get_user_messages($content_type, $emailaddresses, 'msgs.time_num', 'DESC', '', false, 0, 0, true);
        for ($i = 0; is_array($res) && $i < count($res); $i++) {
            $rs = $res[$i];
            if (Auth::isMailAdmin() || in_array($rs['email'], $emailaddresses)) {
                if (!$db->update_msgrcpt_rs($rs['mail_id'], $rs['email'], $flag)) {
                    $rs = $result[0];
                    $result_array[$i] = array("mail_id" => $mail_id, "from_addr" => $rs['from_addr'], "subject" => $rs['subject'], "time_num" => $rs['time_num'], "spam_level" => $rs['spam_level'], "status" => "Error: " . $db->get_err());
                }
            } else {
                continue;
            }
        }
    } else {
        $i = 0;
        foreach ($mail_id_array as $mail_id_recip) {
            // Get mail_id and recipient email address
            //$temp = preg_split('/_/', $mail_id_recip, 2);
            //$mail_id = $temp[0];
            //$recip_email = $temp[1];
            $mail_id = substr($mail_id_recip, 0, 12);
            $recip_email = substr($mail_id_recip, 13);
            // Check if logged in user is admin or logged in user is trying to delete his own messages
            if (Auth::isMailAdmin() || in_array($recip_email, $emailaddresses)) {
                $result = $db->get_message($recip_email, $mail_id);
            } else {
                continue;
            }
            if (!$db->update_msgrcpt_rs($mail_id, $recip_email, $flag)) {
                $rs = $result[0];
                $result_array[$i] = array("mail_id" => $mail_id, "from_addr" => $rs['from_addr'], "subject" => $rs['subject'], "time_num" => $rs['time_num'], "spam_level" => $rs['spam_level'], "status" => "Error: " . $db->get_err());
                $i++;
            }
        }
    }
    // Commit, then set autocommit back to true
    $result = $db->db->commit();
    $db->check_for_error($result, 'PEAR DB commit()');
    $result = $db->db->autoCommit(true);
    $db->check_for_error($result, 'PEAR DB autoCommit(true)');
    // Return array of messages whose release failed
    return $result_array;
}