FIX: changemotd.php

1 view
Skip to first unread message

Ronald MacDonald

unread,
Mar 27, 2011, 9:26:34 PM3/27/11
to GrinnellPlans Development

Proposed fixes for changemotd.php on trunk
* nested db functions
* added title/cleaned html
* removed redundant input


--- ./.svn/text-base/changemotd.php.svn-base 2011-03-27 19:11:24.000000000 +0100
+++ ./changemotd.php 2011-03-28 02:24:17.000000000 +0100
@@ -2,39 +2,28 @@
require_once ("../Plans.php");
require ("auth.php");
?>
-
-<html>
<html>
+<head>
+ <title>Change Message of the Day</title>
+</head>
<body>
<?php
-require ("dbfunctions.php");
-$dbh = db_connect();
-if ($mysubmit) {
- $motd = preg_replace("/\n/s", "<br>", $motd);
- $motd = addslashes($motd);
- mysql_query("UPDATE system SET motd = '$motd'");
- echo $motd;
-} //if a username
-{ //if no username
- //$addrow = array("My message","");
- //add_row($dbh, "system", $addrow);
- //$motd = get_item($dbh,"motd","system","username", $username);
- $my_result = mysql_query("Select motd From system");
- $my_row = mysql_fetch_array($my_result);
- $motd = $my_row[0];
- $motd = ereg_replace("<br>", "", $motd);
- $motd = stripslashes($motd);
+ require ("dbfunctions.php");
+ $dbh = db_connect();
+ if (isset($_POST['submit'])) {
+ $motd = addslashes(preg_replace("/\n/s", "<br>", $_POST['motd']));
+ mysql_query(sprintf("UPDATE `system` SET motd = '%s'", mysql_real_escape_string($motd)));
+ }
+ $row = mysql_fetch_array(mysql_query("SELECT motd FROM system"));
+ $motd = preg_replace("/<br>/", "\n", stripslashes($row[0]));
?>
<form action="changemotd.php" method="POST">
<textarea name="motd" cols="100" rows="40" >
-<?php echo $motd
-?>
+<?php echo $motd ?>
</textarea>
-<input type="hidden" name="mysubmit" value="1">
-<input type="submit" value="Change MOTD">
+<input type="submit" name="submit" value="Change MOTD">
</form>
<?php
-}
db_disconnect($dbh);
?>
</html>

R MacDonald : http://www.rmacd.com/
ron...@rmacd.com : +44-777-2351655


changemotd.php.patch
PGP.sig

Ian Young

unread,
Mar 31, 2011, 1:01:00 AM3/31/11
to grinnellplan...@googlegroups.com, Ronald MacDonald
Looks great, committed. Thanks!

Ian
Reply all
Reply to author
Forward
0 new messages