cvs: php-master-web /include functions.inc login.inc /manage event.php mirrors.php user-notes.php users.php
| From: | Gabor Hojtsy | Date: | Thu, 10 Jun 2004 09:08:41 +0000 |
| Subject: | cvs: php-master-web /include functions.inc login.inc /manage event.php mirrors.php user-notes.php users.php | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-24915@lists.php.net to get a copy of this message | ||
goba Thu Jun 10 05:08:41 2004 EDT
Modified files:
/php-master-web/include functions.inc login.inc
/php-master-web/manage event.php mirrors.php user-notes.php
users.php
Log:
use db_query() instead of mysql_query(), since the former includes sql error handling code, so we
don't need to do it on every query; also introduced db_connect()
http://cvs.php.net/diff.php/php-master-web/include/functions.inc?r1=1.9&r2=1.10&ty=u Index: php-master-web/include/functions.inc diff -u php-master-web/include/functions.inc:1.9 php-master-web/include/functions.inc:1.10 --- php-master-web/include/functions.inc:1.9 Thu Jun 10 04:28:47 2004 +++ php-master-web/include/functions.inc Thu Jun 10 05:08:41 2004 @@ -1,34 +1,7 @@ <?php -// $Id: functions.inc,v 1.9 2004/06/10 08:28:47 goba Exp $ +// $Id: functions.inc,v 1.10 2004/06/10 09:08:41 goba Exp $ -// Shorthand function for htmlspecialchars -function hsc($str) { - return htmlspecialchars($str); -} - -function clean($var) { - return htmlspecialchars(get_magic_quotes_gpc() ? stripslashes($var) : $var); -} - -function warn($message) { - echo "<p class=\"warning\">$message</p>"; -} - -function query($query) { - $res = @mysql_query($query); - if (!$res) { - die("<p class=\"warning\">query failed: " . mysql_error() . "<tt>\n$query</tt></p>"); - } - return $res; -} - -function mysql_get_one($query) { - $res = mysql_query($query); - if ($res && mysql_num_rows($res)) { - return mysql_result($res,0); - } - return false; -} +// ----------------------------------------------------------------------------------- function head($title="") {?> <html> @@ -58,6 +31,41 @@ echo "</body></html>"; } +// ----------------------------------------------------------------------------------- + +function hsc($str) { return htmlspecialchars($str); } +function strip($var) { return (get_magic_quotes_gpc() ? stripslashes($var) : $var); } +function clean($var) { return hsc(strip($var)); } +function format_warn($message) { return "<p class=\"warning\">$message</p>"; } +function warn($message) { echo format_warn($message); } + +// ----------------------------------------------------------------------------------- + +function db_query($query) +{ + $res = @mysql_query($query); + if (!$res) { + die(format_warn("Query failed: " . hsc(mysql_error()) . "<tt>\n" . hsc($query) . "</tt>")); + } + return $res; +} + +function db_connect() +{ + @mysql_connect("localhost", "nobody", "") + or die(format_warn("Unable to connect to database!")); + @mysql_select_db("php3") + or die(format_warn("Unable to select database!")); +} + +function mysql_get_one($query) { + $res = mysql_query($query); + if ($res && mysql_num_rows($res)) { + return mysql_result($res,0); + } + return false; +} + function array_to_url($array,$overlay=0) { if ($overlay) $array = array_merge($array,$overlay); $out = ""; @@ -67,15 +75,15 @@ return substr($out,5); # skip first & } -function show_prev_next($begin,$rows,$skip,$total,$extra=array()) { - global $PHP_SELF;?> +function show_prev_next($begin, $rows, $skip, $total, $extra = array()) +{?> <table border="0" cellspacing="1" width="100%"> <tr bgcolor="#eeeeee"> <td align="left" width="33%"> <?php if ($begin > 0) { printf("<a href=\"%s?%s\">« Previous %d", - $PHP_SELF, + $_SERVER['PHP_SELF'], array_to_url($extra, array("begin" => max(0,$begin-$skip))), min($skip,$begin)); } @@ -90,7 +98,7 @@ <?php if ($begin+$rows < $total) { printf("<a href=\"%s?%s\">Next %d »", - $PHP_SELF, + $_SERVER['PHP_SELF'], array_to_url($extra, array("begin" => $begin+$skip)), min($skip,$total-($begin+$skip))); } @@ -101,10 +109,10 @@ <?php } -function show_country_options($cc = "") { - $res = @mysql_query("SELECT id,name FROM country ORDER BY name"); - while ($row = mysql_fetch_array($res,MYSQL_ASSOC)) { - echo "<option value=\"$row[id]\"", $cc == $row['id'] ? " selected" : "", ">$row[name]</option>"; - } +function show_country_options($cc = "") +{ + $res = db_query("SELECT id, name FROM country ORDER BY name"); + while ($row = mysql_fetch_assoc($res)) { + echo "<option value=\"{$row['id']}\"", $cc == $row['id'] ? " selected" : "", ">{$row['name']}</option>"; + } } - http://cvs.php.net/diff.php/php-master-web/include/login.inc?r1=1.4&r2=1.5&ty=u Index: php-master-web/include/login.inc diff -u php-master-web/include/login.inc:1.4 php-master-web/include/login.inc:1.5 --- php-master-web/include/login.inc:1.4 Thu Jun 10 04:38:30 2004 +++ php-master-web/include/login.inc Thu Jun 10 05:08:41 2004 @@ -1,5 +1,5 @@ <?php -/* $Id: login.inc,v 1.4 2004/06/10 08:38:30 goba Exp $ */ +/* $Id: login.inc,v 1.5 2004/06/10 09:08:41 goba Exp $ */ include_once 'cvs-auth.inc'; http://cvs.php.net/diff.php/php-master-web/manage/event.php?r1=1.9&r2=1.10&ty=u Index: php-master-web/manage/event.php diff -u php-master-web/manage/event.php:1.9 php-master-web/manage/event.php:1.10 --- php-master-web/manage/event.php:1.9 Sat Sep 6 01:09:09 2003 +++ php-master-web/manage/event.php Thu Jun 10 05:08:41 2004 @@ -30,7 +30,7 @@ $id = (int)$id; switch ($action) { case 'approve': - if (mysql_query("UPDATE phpcal SET approved=1,app_by='$user' WHERE id=$id") + if (db_query("UPDATE phpcal SET approved=1,app_by='$user' WHERE id=$id") && mysql_affected_rows()) { $event = fetch_event($id); $message = "This event has been approved. It will appear on the PHP website shortly."; @@ -45,7 +45,7 @@ break; case 'reject': $event = fetch_event($id); - if (mysql_query("DELETE FROM phpcal WHERE id=$id") + if (db_query("DELETE FROM phpcal WHERE id=$id") && mysql_affected_rows()) { $message = $event['approved'] ? "This event has been deleted." : "This event has been rejected."; $did = $event['approved'] ? 'Deleted' : 'Rejected'; @@ -91,7 +91,7 @@ . "country='$in[country]'," . "category='$in[category]'" . " WHERE id=$id"; - query($query); + db_query($query); warn("record $id updated"); unset($id); @@ -252,15 +252,13 @@ $query = "SELECT COUNT(id) FROM phpcal"; if ($searchby) $query .= " $searchby"; -$res = mysql_query($query) - or die("query '$query' failed: ".mysql_error()); +$res = db_query($query); $total = mysql_result($res,0); $query = "SELECT phpcal.*,country.name AS cname FROM phpcal LEFT JOIN country ON phpcal.country = country.id $searchby $orderby $limit"; #echo "<pre>$query</pre>"; -$res = mysql_query($query) - or die("query '$query' failed: ".mysql_error()); +$res = db_query($query); $extra = array( "search" => stripslashes($search), @@ -316,7 +314,7 @@ function fetch_event($id) { $query = "SELECT * FROM phpcal WHERE id=$id"; - if ($res = query($query)) { + if ($res = db_query($query)) { return mysql_fetch_array($res,MYSQL_ASSOC); } http://cvs.php.net/diff.php/php-master-web/manage/mirrors.php?r1=1.85&r2=1.86&ty=u Index: php-master-web/manage/mirrors.php diff -u php-master-web/manage/mirrors.php:1.85 php-master-web/manage/mirrors.php:1.86 --- php-master-web/manage/mirrors.php:1.85 Thu Dec 25 13:06:41 2003 +++ php-master-web/manage/mirrors.php Thu Jun 10 05:08:41 2004 @@ -5,18 +5,14 @@ // This page is for mirror administration head("mirror administration"); - -// Connect to database and select php3 db -mysql_connect("localhost","nobody","") - or die("unable to connect to database"); -mysql_select_db("php3"); +db_connect(); // Get boolean values from form $active = isset($active) ? 1 : 0; $has_stats = isset($has_stats) ? 1 : 0; // Select last mirror check time from table -$lct = mysql_query("SELECT UNIX_TIMESTAMP(lastchecked) FROM mirrors ORDER BY lastchecked DESC LIMIT 1"); +$lct = db_query("SELECT UNIX_TIMESTAMP(lastchecked) FROM mirrors ORDER BY lastchecked DESC LIMIT 1"); list($checktime) = mysql_fetch_row($lct); // We have something to update in the database @@ -60,13 +56,8 @@ // If there is any query to execute if ($query) { - // Try to execute query, and provide failure information if unable to - if (!mysql_query($query)) { - echo "<h2 class=\"error\">Query failed: ", mysql_error(), "</h2>"; - } - - // Else provide update message - else { + // Try to execute query, and provide information if successfull + if (db_query($query)) { echo "<h2>$msg</h2>"; } @@ -98,7 +89,7 @@ // The $id is not zero, so get mirror information if (intval($id) !== 0) { - $res = mysql_query( + $res = db_query( "SELECT *, " . "UNIX_TIMESTAMP(created) AS ucreated, " . "UNIX_TIMESTAMP(lastedited) AS ulastedited, " . @@ -263,7 +254,7 @@ // Query the whole mirror list and display all mirrors. The query is // similar to the one in the mirror fetch script. We need to get mirror // status data to show proper icons and need to order by country too - $res = mysql_query(" + $res = db_query(" SELECT mirrors.*, UNIX_TIMESTAMP(lastupdated) AS ulastupdated, UNIX_TIMESTAMP(lastchecked) AS ulastchecked, @@ -272,7 +263,7 @@ country.name as countryname FROM mirrors LEFT JOIN country ON mirrors.cc = country.id ORDER BY country.name, hostname" - ) or die("query failed"); + ); // Start table $summary = '<div align="center"> http://cvs.php.net/diff.php/php-master-web/manage/user-notes.php?r1=1.41&r2=1.42&ty=u Index: php-master-web/manage/user-notes.php diff -u php-master-web/manage/user-notes.php:1.41 php-master-web/manage/user-notes.php:1.42 --- php-master-web/manage/user-notes.php:1.41 Thu Jun 10 04:38:30 2004 +++ php-master-web/manage/user-notes.php Thu Jun 10 05:08:41 2004 @@ -1,5 +1,5 @@ <?php -// $Id: user-notes.php,v 1.41 2004/06/10 08:38:30 goba Exp $ +// $Id: user-notes.php,v 1.42 2004/06/10 09:08:41 goba Exp $ // Force login before action can be taken include_once 'login.inc'; @@ -34,6 +34,8 @@ Your note has been removed from the online manual.'; +db_connect(); + if (!isset($action)) { // search ! head(); @@ -62,12 +64,8 @@ $sql .= ' OR id = ' . (int)$keyword; } $sql .= ' LIMIT 20'; - @mysql_connect("localhost","nobody","") - or die("unable to connect to database"); - @mysql_select_db("php3") - or die("unable to select database"); - if ($result = mysql_query($sql)) { + if ($result = db_query($sql)) { if (mysql_num_rows($result) != 0) { while ($row = mysql_fetch_assoc($result)) { $id = $row['id']; @@ -85,10 +83,6 @@ } else { echo "no results<br />"; } - } else { - echo "<p>An unknown error occured. Try again later.</p><pre>",mysql_error(),"</pre>"; - foot(); - exit; } } @@ -122,15 +116,10 @@ $action = $m[1]; $id = $m[2]; } -@mysql_connect("localhost","nobody","") - or die("unable to connect to database"); -@mysql_select_db("php3") - or die("unable to select database"); - switch($action) { case 'approve': if ($id) { - if ($result = mysql_query("SELECT * FROM note WHERE id=$id")) { + if ($result = db_query("SELECT * FROM note WHERE id=$id")) { if (!mysql_num_rows ($result)) { die ("Note #$id doesn't exist. It has probably been deleted/rejected already"); } @@ -141,29 +130,24 @@ die ("Note #$id has already been approved"); } - if ($row['id'] && mysql_query ("UPDATE note SET status=NULL WHERE id=$id")) { + if ($row['id'] && db_query("UPDATE note SET status=NULL WHERE id=$id")) { mail ($mailto, "note $row[id] approved from $row[sect] by $user", "This note has been approved and will appear in the manual\n\n----\n\n".$row['note'], "From: $user@php.net\r\nIn-Reply-To: <note-$id@php.net>"); } print "Note #$id has been approved and will appear in the manual"; exit; - } else { - head(); - echo "<p>An unknown error occured. Try again later.</p><pre>",mysql_error(),"</pre>"; - foot(); - exit; } } case 'reject': case 'delete': if ($id) { - if ($result = mysql_query("SELECT * FROM note WHERE id=$id")) { + if ($result = db_query("SELECT * FROM note WHERE id=$id")) { if (!mysql_num_rows ($result)) { die ("Note #$id doesn't exist. It has probably been deleted/rejected already"); } $row = mysql_fetch_array($result); - if ($row['id'] && mysql_query("DELETE FROM note WHERE id=$id")) { + if ($row['id'] && db_query("DELETE FROM note WHERE id=$id")) { // ** alerts ** //$mailto .= get_emails_for_sect($row["sect"]); mail($mailto,"note $row[id] ".($action == "reject" ? "rejected" : "deleted")." from $row[sect] by $user","Note Submitter: $row[user]\n\n----\n\n".$row['note'],"From: $user@php.net\r\nIn-Reply-To: <note-$id@php.net>"); @@ -182,10 +166,6 @@ } exit; } - head(); - echo "<p>An unknown error occured. Try again later.</p><pre>",mysql_error(),"</pre>"; - foot(); - exit; } /* falls through, with id not set. */ case 'preview': @@ -195,7 +175,7 @@ head(); } - if ($result = @mysql_query("SELECT *,UNIX_TIMESTAMP(ts) AS ts FROM note WHERE id=$id")) { + if ($result = db_query("SELECT *,UNIX_TIMESTAMP(ts) AS ts FROM note WHERE id=$id")) { if (!mysql_num_rows ($result)) { die ("Note #$id doesn't exist. It has probably been deleted/rejected already"); } @@ -206,7 +186,7 @@ $sect = isset($sect) ? $sect : addslashes($row['sect']); if (isset($note) && $action == "edit") { - if (@mysql_query("UPDATE note SET note='$note',user='$email',sect='$sect',updated=NOW() WHERE id=$id")) { + if (db_query("UPDATE note SET note='$note',user='$email',sect='$sect',updated=NOW() WHERE id=$id")) { // ** alerts ** //$mailto .= get_emails_for_sect($row["sect"]); @@ -215,11 +195,6 @@ mail_user($email, $mailfrom, "note $id moved from $row[sect] to $sect by notes editor $user", "----- Copy of your note below -----\n\n".stripslashes($note)); } header('Location: user-notes.php?id=' . $id . '&was=' . $action); - exit; - } - else { - echo "<p>An unknown error occured. Try again later.</p><pre>",mysql_error(),"</pre>"; - foot(); exit; } } http://cvs.php.net/diff.php/php-master-web/manage/users.php?r1=1.32&r2=1.33&ty=u Index: php-master-web/manage/users.php diff -u php-master-web/manage/users.php:1.32 php-master-web/manage/users.php:1.33 --- php-master-web/manage/users.php:1.32 Wed Feb 4 22:26:46 2004 +++ php-master-web/manage/users.php Thu Jun 10 05:08:41 2004 @@ -22,7 +22,7 @@ if (isset($username) && !isset($id)) { $query = "SELECT userid FROM users" . " WHERE username='$username' OR email='$username'"; - $res = query($query); + $res = db_query($query); if (!($id = @mysql_result($res,0))) { warn("wasn't able to find user matching '".clean($username)."'"); } @@ -36,7 +36,7 @@ $id = (int)$id; switch ($action) { case 'approve': - if (mysql_query("UPDATE users SET cvsaccess=1 WHERE userid=$id") + if (db_query("UPDATE users SET cvsaccess=1 WHERE userid=$id") && mysql_affected_rows()) { $userinfo = fetch_user($id); $message = @@ -63,7 +63,7 @@ break; case 'remove': $userinfo = fetch_user($id); - if (mysql_query("DELETE FROM users WHERE userid=$id") + if (db_query("DELETE FROM users WHERE userid=$id") && mysql_affected_rows()) { $message = $userinfo[cvsaccess] ? "Your CVS account ($userinfo[username]) was deleted. @@ -81,7 +81,7 @@ to send us a note at group@php.net."; mail($userinfo[email],"CVS Account Request: $userinfo[username]",$message,"From: PHP Group <group@php.net>"); mail($mailto,$userinfo[cvsaccess] ? "CVS Account Deleted: $userinfo[username] deleted by $user" : "CVS Account Rejected: $userinfo[username] rejected by $user","Nuked $userinfo[username]","From: PHP Group <group@php.net>\nIn-Reply-To: <cvs-account-$id-admin@php.net>"); - mysql_query("DELETE FROM users_note WHERE userid=$id"); + db_query("DELETE FROM users_note WHERE userid=$id"); if (!$noclose) { echo '<script language="javascript">window.close();</script>'; exit; @@ -123,11 +123,11 @@ . ",spamprotect=$spamprotect" . ",verified=$verified" . " WHERE userid=$id"; - query($query); + db_query($query); if(strlen($in['purpose'])) { $purpose = addslashes($in['purpose']); $query = "INSERT INTO users_note (userid, note, entered) VALUES ($id, '$purpose', NOW())"; - query($query); + db_query($query); } } @@ -141,7 +141,7 @@ . (is_admin($user) ? ",cvsaccess=$cvsaccess" : "") . ",spamprotect=$spamprotect" . ",verified=$verified"; - query($query); + db_query($query); $nid = mysql_insert_id(); @@ -154,7 +154,7 @@ if ($id) { $query = "SELECT * FROM users" . " WHERE users.userid=$id"; - $res = query($query); + $res = db_query($query); $row = mysql_fetch_array($res); if (!$row) unset($id); } @@ -234,7 +234,7 @@ </table> <?php if ($id) { - $res = mysql_query("SELECT note,UNIX_TIMESTAMP(entered) AS ts FROM users_note WHERE userid=$id"); + $res = db_query("SELECT note,UNIX_TIMESTAMP(entered) AS ts FROM users_note WHERE userid=$id"); echo "<b>notes</b>"; while ($res && $row = mysql_fetch_array($res,MYSQL_ASSOC)) { echo "<div>",date("r",$row['ts']),"<br />$row[note]</div>"; @@ -279,15 +279,13 @@ $query = "SELECT DISTINCT COUNT(users.userid) FROM users"; if ($searchby) $query .= " LEFT JOIN users_note USING(userid) $searchby"; -$res = mysql_query($query) - or die("query '$query' failed: ".mysql_error()); +$res = db_query($query); $total = mysql_result($res,0); $query = "SELECT DISTINCT users.userid,cvsaccess,username,name,email,note FROM users LEFT JOIN users_note USING (userid) $searchby group by userid $orderby $limit"; #echo "<pre>$query</pre>"; -$res = mysql_query($query) - or die("query '$query' failed: ".mysql_error()); +$res = db_query($query); $extra = array( "search" => stripslashes($search), @@ -362,7 +360,7 @@ . " WHERE userid=$userid" . " AND (email='$quser' OR username='$quser')"; - $res = mysql_query($query); + $res = db_query($query); return $res ? mysql_num_rows($res) : false; } @@ -376,7 +374,7 @@ $query .= " WHERE username='$quser' OR email='$quser'"; } - if ($res = query($query)) { + if ($res = db_query($query)) { return mysql_fetch_array($res); }
http://cvs.php.net/diff.php/php-master-web/include/functions.inc?r1=1.9&r2=1.10&ty=u Index: php-master-web/include/functions.inc diff -u php-master-web/include/functions.inc:1.9 php-master-web/include/functions.inc:1.10 --- php-master-web/include/functions.inc:1.9 Thu Jun 10 04:28:47 2004 +++ php-master-web/include/functions.inc Thu Jun 10 05:08:41 2004 @@ -1,34 +1,7 @@ <?php -// $Id: functions.inc,v 1.9 2004/06/10 08:28:47 goba Exp $ +// $Id: functions.inc,v 1.10 2004/06/10 09:08:41 goba Exp $ -// Shorthand function for htmlspecialchars -function hsc($str) { - return htmlspecialchars($str); -} - -function clean($var) { - return htmlspecialchars(get_magic_quotes_gpc() ? stripslashes($var) : $var); -} - -function warn($message) { - echo "<p class=\"warning\">$message</p>"; -} - -function query($query) { - $res = @mysql_query($query); - if (!$res) { - die("<p class=\"warning\">query failed: " . mysql_error() . "<tt>\n$query</tt></p>"); - } - return $res; -} - -function mysql_get_one($query) { - $res = mysql_query($query); - if ($res && mysql_num_rows($res)) { - return mysql_result($res,0); - } - return false; -} +// ----------------------------------------------------------------------------------- function head($title="") {?> <html> @@ -58,6 +31,41 @@ echo "</body></html>"; } +// ----------------------------------------------------------------------------------- + +function hsc($str) { return htmlspecialchars($str); } +function strip($var) { return (get_magic_quotes_gpc() ? stripslashes($var) : $var); } +function clean($var) { return hsc(strip($var)); } +function format_warn($message) { return "<p class=\"warning\">$message</p>"; } +function warn($message) { echo format_warn($message); } + +// ----------------------------------------------------------------------------------- + +function db_query($query) +{ + $res = @mysql_query($query); + if (!$res) { + die(format_warn("Query failed: " . hsc(mysql_error()) . "<tt>\n" . hsc($query) . "</tt>")); + } + return $res; +} + +function db_connect() +{ + @mysql_connect("localhost", "nobody", "") + or die(format_warn("Unable to connect to database!")); + @mysql_select_db("php3") + or die(format_warn("Unable to select database!")); +} + +function mysql_get_one($query) { + $res = mysql_query($query); + if ($res && mysql_num_rows($res)) { + return mysql_result($res,0); + } + return false; +} + function array_to_url($array,$overlay=0) { if ($overlay) $array = array_merge($array,$overlay); $out = ""; @@ -67,15 +75,15 @@ return substr($out,5); # skip first & } -function show_prev_next($begin,$rows,$skip,$total,$extra=array()) { - global $PHP_SELF;?> +function show_prev_next($begin, $rows, $skip, $total, $extra = array()) +{?> <table border="0" cellspacing="1" width="100%"> <tr bgcolor="#eeeeee"> <td align="left" width="33%"> <?php if ($begin > 0) { printf("<a href=\"%s?%s\">« Previous %d", - $PHP_SELF, + $_SERVER['PHP_SELF'], array_to_url($extra, array("begin" => max(0,$begin-$skip))), min($skip,$begin)); } @@ -90,7 +98,7 @@ <?php if ($begin+$rows < $total) { printf("<a href=\"%s?%s\">Next %d »", - $PHP_SELF, + $_SERVER['PHP_SELF'], array_to_url($extra, array("begin" => $begin+$skip)), min($skip,$total-($begin+$skip))); } @@ -101,10 +109,10 @@ <?php } -function show_country_options($cc = "") { - $res = @mysql_query("SELECT id,name FROM country ORDER BY name"); - while ($row = mysql_fetch_array($res,MYSQL_ASSOC)) { - echo "<option value=\"$row[id]\"", $cc == $row['id'] ? " selected" : "", ">$row[name]</option>"; - } +function show_country_options($cc = "") +{ + $res = db_query("SELECT id, name FROM country ORDER BY name"); + while ($row = mysql_fetch_assoc($res)) { + echo "<option value=\"{$row['id']}\"", $cc == $row['id'] ? " selected" : "", ">{$row['name']}</option>"; + } } - http://cvs.php.net/diff.php/php-master-web/include/login.inc?r1=1.4&r2=1.5&ty=u Index: php-master-web/include/login.inc diff -u php-master-web/include/login.inc:1.4 php-master-web/include/login.inc:1.5 --- php-master-web/include/login.inc:1.4 Thu Jun 10 04:38:30 2004 +++ php-master-web/include/login.inc Thu Jun 10 05:08:41 2004 @@ -1,5 +1,5 @@ <?php -/* $Id: login.inc,v 1.4 2004/06/10 08:38:30 goba Exp $ */ +/* $Id: login.inc,v 1.5 2004/06/10 09:08:41 goba Exp $ */ include_once 'cvs-auth.inc'; http://cvs.php.net/diff.php/php-master-web/manage/event.php?r1=1.9&r2=1.10&ty=u Index: php-master-web/manage/event.php diff -u php-master-web/manage/event.php:1.9 php-master-web/manage/event.php:1.10 --- php-master-web/manage/event.php:1.9 Sat Sep 6 01:09:09 2003 +++ php-master-web/manage/event.php Thu Jun 10 05:08:41 2004 @@ -30,7 +30,7 @@ $id = (int)$id; switch ($action) { case 'approve': - if (mysql_query("UPDATE phpcal SET approved=1,app_by='$user' WHERE id=$id") + if (db_query("UPDATE phpcal SET approved=1,app_by='$user' WHERE id=$id") && mysql_affected_rows()) { $event = fetch_event($id); $message = "This event has been approved. It will appear on the PHP website shortly."; @@ -45,7 +45,7 @@ break; case 'reject': $event = fetch_event($id); - if (mysql_query("DELETE FROM phpcal WHERE id=$id") + if (db_query("DELETE FROM phpcal WHERE id=$id") && mysql_affected_rows()) { $message = $event['approved'] ? "This event has been deleted." : "This event has been rejected."; $did = $event['approved'] ? 'Deleted' : 'Rejected'; @@ -91,7 +91,7 @@ . "country='$in[country]'," . "category='$in[category]'" . " WHERE id=$id"; - query($query); + db_query($query); warn("record $id updated"); unset($id); @@ -252,15 +252,13 @@ $query = "SELECT COUNT(id) FROM phpcal"; if ($searchby) $query .= " $searchby"; -$res = mysql_query($query) - or die("query '$query' failed: ".mysql_error()); +$res = db_query($query); $total = mysql_result($res,0); $query = "SELECT phpcal.*,country.name AS cname FROM phpcal LEFT JOIN country ON phpcal.country = country.id $searchby $orderby $limit"; #echo "<pre>$query</pre>"; -$res = mysql_query($query) - or die("query '$query' failed: ".mysql_error()); +$res = db_query($query); $extra = array( "search" => stripslashes($search), @@ -316,7 +314,7 @@ function fetch_event($id) { $query = "SELECT * FROM phpcal WHERE id=$id"; - if ($res = query($query)) { + if ($res = db_query($query)) { return mysql_fetch_array($res,MYSQL_ASSOC); } http://cvs.php.net/diff.php/php-master-web/manage/mirrors.php?r1=1.85&r2=1.86&ty=u Index: php-master-web/manage/mirrors.php diff -u php-master-web/manage/mirrors.php:1.85 php-master-web/manage/mirrors.php:1.86 --- php-master-web/manage/mirrors.php:1.85 Thu Dec 25 13:06:41 2003 +++ php-master-web/manage/mirrors.php Thu Jun 10 05:08:41 2004 @@ -5,18 +5,14 @@ // This page is for mirror administration head("mirror administration"); - -// Connect to database and select php3 db -mysql_connect("localhost","nobody","") - or die("unable to connect to database"); -mysql_select_db("php3"); +db_connect(); // Get boolean values from form $active = isset($active) ? 1 : 0; $has_stats = isset($has_stats) ? 1 : 0; // Select last mirror check time from table -$lct = mysql_query("SELECT UNIX_TIMESTAMP(lastchecked) FROM mirrors ORDER BY lastchecked DESC LIMIT 1"); +$lct = db_query("SELECT UNIX_TIMESTAMP(lastchecked) FROM mirrors ORDER BY lastchecked DESC LIMIT 1"); list($checktime) = mysql_fetch_row($lct); // We have something to update in the database @@ -60,13 +56,8 @@ // If there is any query to execute if ($query) { - // Try to execute query, and provide failure information if unable to - if (!mysql_query($query)) { - echo "<h2 class=\"error\">Query failed: ", mysql_error(), "</h2>"; - } - - // Else provide update message - else { + // Try to execute query, and provide information if successfull + if (db_query($query)) { echo "<h2>$msg</h2>"; } @@ -98,7 +89,7 @@ // The $id is not zero, so get mirror information if (intval($id) !== 0) { - $res = mysql_query( + $res = db_query( "SELECT *, " . "UNIX_TIMESTAMP(created) AS ucreated, " . "UNIX_TIMESTAMP(lastedited) AS ulastedited, " . @@ -263,7 +254,7 @@ // Query the whole mirror list and display all mirrors. The query is // similar to the one in the mirror fetch script. We need to get mirror // status data to show proper icons and need to order by country too - $res = mysql_query(" + $res = db_query(" SELECT mirrors.*, UNIX_TIMESTAMP(lastupdated) AS ulastupdated, UNIX_TIMESTAMP(lastchecked) AS ulastchecked, @@ -272,7 +263,7 @@ country.name as countryname FROM mirrors LEFT JOIN country ON mirrors.cc = country.id ORDER BY country.name, hostname" - ) or die("query failed"); + ); // Start table $summary = '<div align="center"> http://cvs.php.net/diff.php/php-master-web/manage/user-notes.php?r1=1.41&r2=1.42&ty=u Index: php-master-web/manage/user-notes.php diff -u php-master-web/manage/user-notes.php:1.41 php-master-web/manage/user-notes.php:1.42 --- php-master-web/manage/user-notes.php:1.41 Thu Jun 10 04:38:30 2004 +++ php-master-web/manage/user-notes.php Thu Jun 10 05:08:41 2004 @@ -1,5 +1,5 @@ <?php -// $Id: user-notes.php,v 1.41 2004/06/10 08:38:30 goba Exp $ +// $Id: user-notes.php,v 1.42 2004/06/10 09:08:41 goba Exp $ // Force login before action can be taken include_once 'login.inc'; @@ -34,6 +34,8 @@ Your note has been removed from the online manual.'; +db_connect(); + if (!isset($action)) { // search ! head(); @@ -62,12 +64,8 @@ $sql .= ' OR id = ' . (int)$keyword; } $sql .= ' LIMIT 20'; - @mysql_connect("localhost","nobody","") - or die("unable to connect to database"); - @mysql_select_db("php3") - or die("unable to select database"); - if ($result = mysql_query($sql)) { + if ($result = db_query($sql)) { if (mysql_num_rows($result) != 0) { while ($row = mysql_fetch_assoc($result)) { $id = $row['id']; @@ -85,10 +83,6 @@ } else { echo "no results<br />"; } - } else { - echo "<p>An unknown error occured. Try again later.</p><pre>",mysql_error(),"</pre>"; - foot(); - exit; } } @@ -122,15 +116,10 @@ $action = $m[1]; $id = $m[2]; } -@mysql_connect("localhost","nobody","") - or die("unable to connect to database"); -@mysql_select_db("php3") - or die("unable to select database"); - switch($action) { case 'approve': if ($id) { - if ($result = mysql_query("SELECT * FROM note WHERE id=$id")) { + if ($result = db_query("SELECT * FROM note WHERE id=$id")) { if (!mysql_num_rows ($result)) { die ("Note #$id doesn't exist. It has probably been deleted/rejected already"); } @@ -141,29 +130,24 @@ die ("Note #$id has already been approved"); } - if ($row['id'] && mysql_query ("UPDATE note SET status=NULL WHERE id=$id")) { + if ($row['id'] && db_query("UPDATE note SET status=NULL WHERE id=$id")) { mail ($mailto, "note $row[id] approved from $row[sect] by $user", "This note has been approved and will appear in the manual\n\n----\n\n".$row['note'], "From: $user@php.net\r\nIn-Reply-To: <note-$id@php.net>"); } print "Note #$id has been approved and will appear in the manual"; exit; - } else { - head(); - echo "<p>An unknown error occured. Try again later.</p><pre>",mysql_error(),"</pre>"; - foot(); - exit; } } case 'reject': case 'delete': if ($id) { - if ($result = mysql_query("SELECT * FROM note WHERE id=$id")) { + if ($result = db_query("SELECT * FROM note WHERE id=$id")) { if (!mysql_num_rows ($result)) { die ("Note #$id doesn't exist. It has probably been deleted/rejected already"); } $row = mysql_fetch_array($result); - if ($row['id'] && mysql_query("DELETE FROM note WHERE id=$id")) { + if ($row['id'] && db_query("DELETE FROM note WHERE id=$id")) { // ** alerts ** //$mailto .= get_emails_for_sect($row["sect"]); mail($mailto,"note $row[id] ".($action == "reject" ? "rejected" : "deleted")." from $row[sect] by $user","Note Submitter: $row[user]\n\n----\n\n".$row['note'],"From: $user@php.net\r\nIn-Reply-To: <note-$id@php.net>"); @@ -182,10 +166,6 @@ } exit; } - head(); - echo "<p>An unknown error occured. Try again later.</p><pre>",mysql_error(),"</pre>"; - foot(); - exit; } /* falls through, with id not set. */ case 'preview': @@ -195,7 +175,7 @@ head(); } - if ($result = @mysql_query("SELECT *,UNIX_TIMESTAMP(ts) AS ts FROM note WHERE id=$id")) { + if ($result = db_query("SELECT *,UNIX_TIMESTAMP(ts) AS ts FROM note WHERE id=$id")) { if (!mysql_num_rows ($result)) { die ("Note #$id doesn't exist. It has probably been deleted/rejected already"); } @@ -206,7 +186,7 @@ $sect = isset($sect) ? $sect : addslashes($row['sect']); if (isset($note) && $action == "edit") { - if (@mysql_query("UPDATE note SET note='$note',user='$email',sect='$sect',updated=NOW() WHERE id=$id")) { + if (db_query("UPDATE note SET note='$note',user='$email',sect='$sect',updated=NOW() WHERE id=$id")) { // ** alerts ** //$mailto .= get_emails_for_sect($row["sect"]); @@ -215,11 +195,6 @@ mail_user($email, $mailfrom, "note $id moved from $row[sect] to $sect by notes editor $user", "----- Copy of your note below -----\n\n".stripslashes($note)); } header('Location: user-notes.php?id=' . $id . '&was=' . $action); - exit; - } - else { - echo "<p>An unknown error occured. Try again later.</p><pre>",mysql_error(),"</pre>"; - foot(); exit; } } http://cvs.php.net/diff.php/php-master-web/manage/users.php?r1=1.32&r2=1.33&ty=u Index: php-master-web/manage/users.php diff -u php-master-web/manage/users.php:1.32 php-master-web/manage/users.php:1.33 --- php-master-web/manage/users.php:1.32 Wed Feb 4 22:26:46 2004 +++ php-master-web/manage/users.php Thu Jun 10 05:08:41 2004 @@ -22,7 +22,7 @@ if (isset($username) && !isset($id)) { $query = "SELECT userid FROM users" . " WHERE username='$username' OR email='$username'"; - $res = query($query); + $res = db_query($query); if (!($id = @mysql_result($res,0))) { warn("wasn't able to find user matching '".clean($username)."'"); } @@ -36,7 +36,7 @@ $id = (int)$id; switch ($action) { case 'approve': - if (mysql_query("UPDATE users SET cvsaccess=1 WHERE userid=$id") + if (db_query("UPDATE users SET cvsaccess=1 WHERE userid=$id") && mysql_affected_rows()) { $userinfo = fetch_user($id); $message = @@ -63,7 +63,7 @@ break; case 'remove': $userinfo = fetch_user($id); - if (mysql_query("DELETE FROM users WHERE userid=$id") + if (db_query("DELETE FROM users WHERE userid=$id") && mysql_affected_rows()) { $message = $userinfo[cvsaccess] ? "Your CVS account ($userinfo[username]) was deleted. @@ -81,7 +81,7 @@ to send us a note at group@php.net."; mail($userinfo[email],"CVS Account Request: $userinfo[username]",$message,"From: PHP Group <group@php.net>"); mail($mailto,$userinfo[cvsaccess] ? "CVS Account Deleted: $userinfo[username] deleted by $user" : "CVS Account Rejected: $userinfo[username] rejected by $user","Nuked $userinfo[username]","From: PHP Group <group@php.net>\nIn-Reply-To: <cvs-account-$id-admin@php.net>"); - mysql_query("DELETE FROM users_note WHERE userid=$id"); + db_query("DELETE FROM users_note WHERE userid=$id"); if (!$noclose) { echo '<script language="javascript">window.close();</script>'; exit; @@ -123,11 +123,11 @@ . ",spamprotect=$spamprotect" . ",verified=$verified" . " WHERE userid=$id"; - query($query); + db_query($query); if(strlen($in['purpose'])) { $purpose = addslashes($in['purpose']); $query = "INSERT INTO users_note (userid, note, entered) VALUES ($id, '$purpose', NOW())"; - query($query); + db_query($query); } } @@ -141,7 +141,7 @@ . (is_admin($user) ? ",cvsaccess=$cvsaccess" : "") . ",spamprotect=$spamprotect" . ",verified=$verified"; - query($query); + db_query($query); $nid = mysql_insert_id(); @@ -154,7 +154,7 @@ if ($id) { $query = "SELECT * FROM users" . " WHERE users.userid=$id"; - $res = query($query); + $res = db_query($query); $row = mysql_fetch_array($res); if (!$row) unset($id); } @@ -234,7 +234,7 @@ </table> <?php if ($id) { - $res = mysql_query("SELECT note,UNIX_TIMESTAMP(entered) AS ts FROM users_note WHERE userid=$id"); + $res = db_query("SELECT note,UNIX_TIMESTAMP(entered) AS ts FROM users_note WHERE userid=$id"); echo "<b>notes</b>"; while ($res && $row = mysql_fetch_array($res,MYSQL_ASSOC)) { echo "<div>",date("r",$row['ts']),"<br />$row[note]</div>"; @@ -279,15 +279,13 @@ $query = "SELECT DISTINCT COUNT(users.userid) FROM users"; if ($searchby) $query .= " LEFT JOIN users_note USING(userid) $searchby"; -$res = mysql_query($query) - or die("query '$query' failed: ".mysql_error()); +$res = db_query($query); $total = mysql_result($res,0); $query = "SELECT DISTINCT users.userid,cvsaccess,username,name,email,note FROM users LEFT JOIN users_note USING (userid) $searchby group by userid $orderby $limit"; #echo "<pre>$query</pre>"; -$res = mysql_query($query) - or die("query '$query' failed: ".mysql_error()); +$res = db_query($query); $extra = array( "search" => stripslashes($search), @@ -362,7 +360,7 @@ . " WHERE userid=$userid" . " AND (email='$quser' OR username='$quser')"; - $res = mysql_query($query); + $res = db_query($query); return $res ? mysql_num_rows($res) : false; } @@ -376,7 +374,7 @@ $query .= " WHERE username='$quser' OR email='$quser'"; } - if ($res = query($query)) { + if ($res = db_query($query)) { return mysql_fetch_array($res); }