fixes bug #28 (thanks Brian Engert!)

This commit is contained in:
Ryan Walberg 2012-12-01 03:33:31 +00:00
parent 39183035fc
commit 409929d526
2 changed files with 12 additions and 5 deletions

View file

@ -63,8 +63,13 @@ $action = isset($_GET["action"]) ? $_GET["action"] : "";
if ($action == "insert" || $action == "update") { if ($action == "insert" || $action == "update") {
/* validate the data. */ /* validate the data. */
$description = trim($_GET["description"]); $description = trim($_GET["description"]);
$eventdate = $_GET["eventdate"]; try {
$ts = strtotime($eventdate); $eventdate = new DateTime($_GET["eventdate"]);
}
catch (Exception $e) {
echo $e->getMessage();
$eventdate = FALSE;
}
$recurring = (strtoupper($_GET["recurring"]) == "ON" ? 1 : 0); $recurring = (strtoupper($_GET["recurring"]) == "ON" ? 1 : 0);
$systemevent = (strtoupper($_GET["systemevent"]) == "ON" ? 1 : 0); $systemevent = (strtoupper($_GET["systemevent"]) == "ON" ? 1 : 0);
@ -73,7 +78,7 @@ if ($action == "insert" || $action == "update") {
$haserror = true; $haserror = true;
$description_error = "A description is required."; $description_error = "A description is required.";
} }
if ($ts < 0 || $ts == FALSE) { if ($eventdate == FALSE) {
$haserror = true; $haserror = true;
$eventdate_error = "Date is out of range for this server."; $eventdate_error = "Date is out of range for this server.";
} }
@ -123,7 +128,7 @@ else if ($action == "insert") {
$stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}events(userid,description,eventdate,recurring) VALUES(?, ?, ?, ?)"); $stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}events(userid,description,eventdate,recurring) VALUES(?, ?, ?, ?)");
$stmt->bindValue(1, $systemevent ? NULL : $userid, PDO::PARAM_BOOL); $stmt->bindValue(1, $systemevent ? NULL : $userid, PDO::PARAM_BOOL);
$stmt->bindParam(2, $description, PDO::PARAM_STR); $stmt->bindParam(2, $description, PDO::PARAM_STR);
$stmt->bindValue(3, strftime("%Y-%m-%d", $ts), PDO::PARAM_STR); $stmt->bindValue(3, $eventdate->format("Y-m-d"), PDO::PARAM_STR);
$stmt->bindParam(4, $recurring, PDO::PARAM_BOOL); $stmt->bindParam(4, $recurring, PDO::PARAM_BOOL);
$stmt->execute(); $stmt->execute();
@ -147,7 +152,7 @@ else if ($action == "update") {
"WHERE eventid = ?"); "WHERE eventid = ?");
$stmt->bindValue(1, $systemevent ? NULL : $userid, PDO::PARAM_BOOL); $stmt->bindValue(1, $systemevent ? NULL : $userid, PDO::PARAM_BOOL);
$stmt->bindParam(2, $description, PDO::PARAM_STR); $stmt->bindParam(2, $description, PDO::PARAM_STR);
$stmt->bindValue(3, strftime("%Y-%m-%d", $ts), PDO::PARAM_STR); $stmt->bindValue(3, $eventdate->format("Y-m-d"), PDO::PARAM_STR);
$stmt->bindParam(4, $recurring, PDO::PARAM_BOOL); $stmt->bindParam(4, $recurring, PDO::PARAM_BOOL);
$stmt->bindParam(5, $eventid, PDO::PARAM_INT); $stmt->bindParam(5, $eventid, PDO::PARAM_INT);

View file

@ -7,6 +7,8 @@ require_once(dirname(__FILE__) . "/config.php");
class MySmarty extends Smarty { class MySmarty extends Smarty {
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
date_default_timezone_set("GMT+0");
} }
public function dbh() { public function dbh() {