Error # $errno $errmsg";
print "
SQL Statement: $statement";
exit ($errno);
} // DBError
function OpenDB () {
$db = mysql_connect ("localhost", "mapsadmin", "mapsadmin")
or DBError ("OpenDB: Unable to connect to database server", "Connect");
mysql_select_db ("MAPS")
or DBError ("OpenDB: Unable to select MAPS database", "adefaria_maps");
} // OpenDB
function SetContext ($new_userid) {
global $userid;
$userid = $new_userid;
} // SetContext
function Encrypt ($password, $userid) {
$statement = "select encode(\"$password\",\"$userid\")";
$result = mysql_query ($statement)
or DBError ("Encrypt: Unable to execute statement", $statement);
// Get return value, which should be the encoded password
$row = mysql_fetch_array ($result);
return $row [0];
} // Encrypt
function UserExists ($userid) {
$statement = "select userid, password from user where userid = \"$userid\"";
$result = mysql_query ($statement)
or DBError ("UserExists: Unable to execute statement", $statement);
$row = mysql_fetch_array ($result);
$dbuserid = $row ["userid"];
$dbpassword = $row ["password"];
if ($dbuserid != $userid) {
return -1;
} else {
return $dbpassword;
} # if
} // UserExists
function Login ($userid, $password) {
$password = Encrypt ($password, $userid);
// Check if user exists
$dbpassword = UserExists ($userid);
// Return -1 if user doesn't exist
if ($dbpassword == -1) {
return -1;
} // if
// Return -2 if password does not match
if ($password != $dbpassword) {
return -2;
} else {
setcookie ("MAPSUser", $userid, time()+60*60*24*30, "/maps");
SetContext ($userid);
return 0;
} // if
} // Login
function CountList ($type) {
global $userid;
$statement = "select count(*) as count from list where type=\"$type\" and userid=\"$userid\"";
$result = mysql_query ($statement)
or DBError ("CountList: Unable to count list: ", $statement);
// How many rows are there?
$row = mysql_fetch_array ($result);
return $row ["count"];
} // CountList
function FindList ($type, $next, $lines) {
global $db;
global $userid;
global $lines;
$statement = "select * from list where type=\"$type\" and userid=\"$userid\" order by sequence limit $next, $lines";
$result = mysql_query ($statement)
or DBError ("FindList: Unable to execute query: ", $statement);
$count = mysql_num_rows ($result);
return array ($count, $result);
} // FindList
function Today2SQLDatetime () {
return date ("Y-m-d H:i:s");
} // Today2SQLDatetime
function countem ($table, $condition) {
$statement = "select count(distinct sender) as count from $table where $condition";
$result = mysql_query ($statement)
or DBError ("countem: Unable to perform query: ", $statement);
// How many rows are there?
$row = mysql_fetch_array ($result);
return $row ["count"];
} // countem
function countlog ($condition="") {
global $userid;
if ($condition != "") {
return countem ("log", "userid=\"$userid\" and " . $condition);
} else {
return countem ("log", "userid=\"$userid\"");
} // if
} // countlog
function SubtractDays ($date, $nbr_days) {
} // SubtractDays
function GetStats ($nbr_days, $date = "") {
global $Types;
if ($date == "") {
$date = Today2SQLDatetime ();
} // if
while ($nbr_days > 0) {
$ymd = substr ($date, 0, 10);
$sod = $ymd . " 00:00:00";
$eod = $ymd . " 23:59:59";
foreach ($Types as $type) {
$condition = "type=\"$type\" and (timestamp > \"$sod\" and timestamp < \"$eod\")";
$stats[$type] = countlog ($condition);
} # foreach
$dates[$ymd] = &$stats;
$date = SubtractDays ($date, 1);
$nbr_days--;
} # while
return $dates;
} # GetStats
function displayquickstats () {
$today = substr (Today2SQLDatetime (), 0, 10);
$dates = getquickstats ($today);
$current_time = date ("g:i a");
// Start quickstats
print "
as of $current_time
"; $processed = $dates[$today]["processed"]; $returned = $dates[$today]["returned"]; $returned_pct = $processed == 0 ? 0 : number_format ($returned / $processed * 100, 1, ".", ""); $whitelist = $dates[$today]["whitelist"]; $whitelist_pct = $processed == 0 ? 0 : number_format ($whitelist / $processed * 100, 1, ".", ""); $blacklist = $dates[$today]["blacklist"]; $blacklist_pct = $processed == 0 ? 0 : number_format ($blacklist / $processed * 100, 1, ".", ""); $registered = $dates[$today]["registered"]; $mailloop = $dates[$today]["mailloop"]; $nulllist = $dates[$today]["nulllist"]; $nulllist_pct = $processed == 0 ? 0 : number_format ($nulllist / $processed * 100, 1, ".", ""); $returned_link = $returned == 0 ? 0 : "$returned"; $whitelist_link = $whitelist == 0 ? 0 : "$whitelist"; $blacklist_link = $blacklist == 0 ? 0 : "$blacklist"; $registered_link = $registered == 0 ? 0 : "$registered"; $mailloop_link = $mailloop == 0 ? 0 : "$mailloop"; $nulllist_link = $nulllist == 0 ? 0 : "$nulllist"; print <<