function set_item_confirmations($message_type, $user_id, $mail_id)
{
    global $dbh;
    if (substr(get_database_type($dbh), 0, 5) == "mysql") {
        $token_code = "CONCAT('expired-', recipient_id, '-', mail_id)";
    } else {
        $token_code = "'expired-' || recipient_id || '-' || mail_id";
    }
    $update = "UPDATE maia_mail_recipients SET type = ?, token=" . $token_code . " WHERE recipient_id = ? AND mail_id IN (";
    $update .= '?' . str_repeat(',?', count($mail_id) - 1);
    $update .= ")";
    $sth = $dbh->prepare($update);
    $res = $sth->execute(array_merge((array) $message_type, (array) $user_id, (array) $mail_id));
    if (PEAR::isError($sth)) {
        die($sth->getMessage());
    }
}
Example #2
0
} else {
    $type = "";
}
if (isset($_GET["raw"])) {
    $raw = trim($_GET["raw"]) == "y";
} else {
    $raw = false;
}
if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] == 'true') {
    $ajax = true;
} else {
    $ajax = false;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    require_once "cache.php";
    $cache = new MessageCache($cache_type, $dbh, get_database_type($dbh), $smarty);
    $message = $cache->confirm_cache($euid);
    if ($ajax) {
        //this section should be moved to a template somewhere.
        ?>
	        tb_remove();
	        <?php 
        if ($cache->confirmed_actions('resent') == 0) {
            // if a single message was resent we don't delete it from the list
            ?>
	        $('#row_<?php 
            echo $id;
            ?>
').fadeOut("slow");
	        $('#row_<?php 
            echo $id;
Example #3
0
function create_table($dbh, $table_name, $table_schema)
{
    $db_type = get_database_type($dbh);
    // FIXME ned to traverse schema.php to generate table.
    $create = "CREATE TABLE {$table_name} (";
    foreach ($table_schema['tabledef'] as $name => $def) {
        $row = $name . " ";
        switch ($db_type) {
            case "mysql":
            case "mysqli":
                switch ($def['type']) {
                    case "int":
                        $row .= " INT";
                        break;
                    case "bigint":
                        $row .= " BIGINT";
                        break;
                    case "uint":
                        $row .= " INT UNSIGNED";
                        break;
                    case "ubigint":
                        $row .= " BIGINT UNSIGNED";
                        break;
                    case "char":
                        $row .= " CHAR(" . $def['size'] . ")";
                        break;
                    case "varchar":
                        $row .= " VARCHAR(" . $def['size'] . ")";
                        break;
                    case "float":
                        $row .= " FLOAT";
                        break;
                    case "timestamp":
                        $row .= " DATETIME";
                        break;
                    case "text":
                        $row .= " TEXT";
                        break;
                    case "ltext":
                        $row .= " LONGTEXT";
                        break;
                    case "mtext":
                        $row .= " MEDIUMTEXT";
                        break;
                }
                break;
            case "pgsql":
                switch ($def['type']) {
                    case "int":
                    case "uint":
                        $row .= " INTEGER";
                        break;
                    case "bigint":
                    case "ubigint":
                        $row .= " BIGINT";
                        break;
                    case "char":
                        $row .= " CHAR(" . $def['size'] . ")";
                        break;
                    case "varchar":
                        $row .= " VARCHAR(" . $def['size'] . ")";
                        break;
                    case "float":
                        $row .= " NUMERIC(" . $def['size'] . ")";
                        break;
                    case "timestamp":
                        $row .= " TIMESTAMP";
                        break;
                    case "text":
                    case "ltext":
                    case "mtext":
                        $row .= " TEXT";
                        break;
                }
                break;
        }
        if (!empty($def['default'])) {
            $row .= " DEFAULT '" . $def['default'] . "'";
        }
        if (!$def['null']) {
            $row .= " NOT NULL";
        }
        $select_cols[] = $row;
    }
    $create .= join(', ', $select_cols);
    $create .= ") TYPE=INNODB";
    //print $create;
    $db_result = $dbh->query($create);
    if (DB::isError($db_result)) {
        $msg .= "error on create: {$table_name} " . $db_result->getMessage() . "<br>";
    } else {
        $msg .= "Added table: {$table_name}<br>";
    }
    foreach ($table_schema['indexes'] as $index => $def) {
        $db_result = create_index($dbh, $table_name, $def['rows'], $def['type']);
        if (DB::isError($db_result)) {
            $msg .= "error on index: {$index} " . $db_result->getMessage() . "<br>";
        } else {
            $msg .= "Added index: {$index}<br>";
        }
    }
    // add initial data
    foreach ($table_schema['alterations'] as $index => $actions) {
        foreach ($actions as $action) {
            //print_r($action);
            if ($action['action'] == "add_data") {
                $insert = "INSERT INTO " . $action['params']['table'] . " SET ";
                $cols = array();
                foreach ($action['params']['params'] as $col => $value) {
                    $cols[] = $col . "='" . $value . "'";
                }
                $insert .= join(", ", $cols);
                $db_result = $dbh->query($insert);
                if (DB::isError($db_result)) {
                    $msg .= "error on insert: {$index} " . $db_result->getMessage() . "<br>";
                } else {
                    $msg .= "inserted default data: {$insert}<br>";
                }
            }
        }
    }
    return $msg;
}
Example #4
0
function get_domain_wb_rows($dbh, $maia_user_id)
{
    global $logger;
    if (substr(get_database_type($dbh), 0, 5) == "mysql") {
        $query = <<<EOQ
      SELECT mailaddr.email, wb, user_name
        FROM mailaddr LEFT JOIN wblist ON mailaddr.id = wblist.sid
             LEFT JOIN maia_users ON wblist.rid=maia_users.id
        WHERE maia_users.user_name
          IN (SELECT DISTINCT substring(email,locate('@',email))
                 FROM maia_users left join users on users.maia_user_id = maia_users.id
                     WHERE maia_users.id=?)
        ORDER BY mailaddr.email ASC
EOQ;
    } else {
        $query = <<<EOQ
      SELECT mailaddr.email, wb, user_name
        FROM mailaddr LEFT JOIN wblist ON mailaddr.id = wblist.sid
             LEFT JOIN maia_users ON wblist.rid=maia_users.id
        WHERE maia_users.user_name
          IN (SELECT DISTINCT substr(email,strpos(email,'@'))
                 FROM maia_users left join users on users.maia_user_id = maia_users.id
                     WHERE maia_users.id=?)
        ORDER BY mailaddr.email ASC
EOQ;
    }
    $rows = array();
    $sth = $dbh->query($query, array($maia_user_id));
    if (PEAR::isError($sth)) {
        $logger->err("Error getting domain wblist: " . $sth->getMessage() . " Query: " . $query . "USer: " . $maia_user_id);
        return $rows;
    }
    if ($sth->numRows() > 0) {
        $count = 0;
        while ($row = $sth->fetchRow()) {
            $rows[$count]['email'] = $row['email'];
            $rows[$count]['domain'] = $row['user_name'];
            $rows[$count]['type'] = $row['wb'];
            $count++;
        }
    }
    $sth->free();
    return $rows;
}
Example #5
0
require_once "cache.php";
// Admins (including the superadmin) should not be looking at
// other people's mail!
if (!ok_to_impersonate($euid, $uid)) {
    header("Location: stats.php" . $sid);
    exit;
}
// Establish which type of cache we are looking at
if (isset($_GET["cache_type"])) {
    $cache_type = $_GET["cache_type"];
    //FIXME need to check incoming data
} else {
    header("Location: list-cache.php" . $msid . "cache_type=ham");
    exit;
}
$dbtype = get_database_type($dbh);
$cache = new MessageCache($cache_type, $dbh, $dbtype, $smarty);
if (isset($_POST["submit"])) {
    $message = $cache->confirm_cache($euid);
    $_SESSION["message"] = $message;
    header("Location: list-cache.php" . $msid . "cache_type={$cache_type}");
    exit;
}
//redirect if we are setting new search order
if (isset($_GET["sort"])) {
    $cache->set_sort_order($_GET["sort"], $euid, $msid);
    // function does not return - page redirects
}
$offset = $cache->get_offset();
/*notes about caches
  spam and ham have opposite sort orders for score
function set_item_confirmations($message_type, $user_id, $mail_id)
{
    global $dbh;
    if (substr(get_database_type($dbh), 0, 5) == "mysql") {
        $token_code = "CONCAT('expired-', recipient_id, '-', mail_id)";
    } else {
        $token_code = "'expired-' || recipient_id || '-' || mail_id";
    }
    $update = "UPDATE maia_mail_recipients SET type = ?, token=" . $token_code . " WHERE recipient_id = ? AND mail_id IN (";
    $update .= '?' . str_repeat(',?', count($mail_id) - 1);
    $update .= ")";
    $res = $dbh->query($update, array_merge((array) $message_type, (array) $user_id, (array) $mail_id));
    sql_check($res, "set_item_confirmations", $update);
}