forgot to add includes/MySmarty.class.php :(

moved a couple of things into an override of Smarty::display()
This commit is contained in:
Ryan Walberg 2012-11-26 02:30:26 +00:00
parent 137d715568
commit db7808688f
17 changed files with 61 additions and 53 deletions

View file

@ -13,9 +13,10 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
include("config.php"); require_once(dirname(__FILE__) . "/includes/funcLib.php");
include("db.php"); require_once(dirname(__FILE__) . "/includes/MySmarty.class.php");
include("funcLib.php"); $smarty = new MySmarty();
$opt = $smarty->opt();
session_start(); session_start();
if (!isset($_SESSION["userid"])) { if (!isset($_SESSION["userid"])) {
@ -32,46 +33,51 @@ else {
$action = $_GET["action"]; $action = $_GET["action"];
if ($action == "approve") { if ($action == "approve") {
$pwd = generatePassword(); $pwd = generatePassword($opt);
if ($_GET["familyid"] != "") { if ($_GET["familyid"] != "") {
$query = "INSERT INTO {$OPT["table_prefix"]}memberships(userid,familyid) VALUES(" . $_GET["userid"] . "," . $_GET["familyid"] . ")"; $stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}memberships(userid,familyid) VALUES(?, ?)");
mysql_query($query) or die("Could not query: " . mysql_error()); $stmt->bindValue(1, (int) $_GET["userid"], PDO::PARAM_INT);
$stmt->bindValue(2, (int) $_GET["familyid"], PDO::PARAM_INT);
$stmt->execute();
} }
$query = "UPDATE {$OPT["table_prefix"]}users SET approved = 1, password = {$OPT["password_hasher"]}('$pwd') WHERE userid = " . $_GET["userid"]; $stmt = $smarty->dbh()->prepare("UPDATE {$opt["table_prefix"]}users SET approved = 1, password = {$opt["password_hasher"]}(?) WHERE userid = ?");
mysql_query($query) or die("Could not query: " . mysql_error()); $stmt->bindParam(1, $pwd, PDO::PARAM_INT);
$stmt->bindValue(2, (int) $_GET["userid"], PDO::PARAM_INT);
$stmt->execute();
// send the e-mails // send the e-mails
$query = "SELECT username, email FROM {$OPT["table_prefix"]}users WHERE userid = " . $_GET["userid"]; $stmt = $smarty->dbh()->prepare("SELECT username, email FROM {$opt["table_prefix"]}users WHERE userid = ?");
$rs = mysql_query($query) or die("Could not query: " . mysql_error()); $stmt->bindValue(1, (int) $_GET["userid"], PDO::PARAM_INT);
if ($row = mysql_fetch_array($rs,MYSQL_ASSOC)) { $stmt->execute();
if ($row = $stmt->fetch()) {
mail( mail(
$row["email"], $row["email"],
"Gift Registry application approved", "Gift Registry application approved",
"Your Gift Registry application was approved by " . $_SESSION["fullname"] . ".\r\n" . "Your Gift Registry application was approved by " . $_SESSION["fullname"] . ".\r\n" .
"Your username is " . $row["username"] . " and your password is $pwd.", "Your username is " . $row["username"] . " and your password is $pwd.",
"From: {$OPT["email_from"]}\r\nReply-To: {$OPT["email_reply_to"]}\r\nX-Mailer: {$OPT["email_xmailer"]}\r\n" "From: {$opt["email_from"]}\r\nReply-To: {$opt["email_reply_to"]}\r\nX-Mailer: {$opt["email_xmailer"]}\r\n"
) or die("Mail not accepted for " . $row["email"]); ) or die("Mail not accepted for " . $row["email"]);
} }
mysql_free_result($rs);
header("Location: " . getFullPath("index.php")); header("Location: " . getFullPath("index.php"));
exit; exit;
} }
else if ($action == "reject") { else if ($action == "reject") {
// send the e-mails // send the e-mails
$query = "SELECT email FROM {$OPT["table_prefix"]}users WHERE userid = " . $_GET["userid"]; $stmt = $smarty->dbh()->prepare("SELECT email FROM {$opt["table_prefix"]}users WHERE userid = ?");
$rs = mysql_query($query) or die("Could not query: " . mysql_error()); $stmt->bindValue(1, (int) $_GET["userid"], PDO::PARAM_INT);
if ($row = mysql_fetch_array($rs,MYSQL_ASSOC)) { $stmt->execute();
if ($row = $stmt->fetch()) {
mail( mail(
$row["email"], $row["email"],
"Gift Registry application denied", "Gift Registry application denied",
"Your Gift Registry application was denied by " . $_SESSION["fullname"] . ".", "Your Gift Registry application was denied by " . $_SESSION["fullname"] . ".",
"From: {$OPT["email_from"]}\r\nReply-To: {$OPT["email_reply_to"]}\r\nX-Mailer: {$OPT["email_xmailer"]}\r\n" "From: {$opt["email_from"]}\r\nReply-To: {$opt["email_reply_to"]}\r\nX-Mailer: {$opt["email_xmailer"]}\r\n"
) or die("Mail not accepted for " . $row["email"]); ) or die("Mail not accepted for " . $row["email"]);
} }
mysql_free_result($rs);
$query = "DELETE FROM {$OPT["table_prefix"]}users WHERE userid = " . $_GET["userid"]; $stmt = $smarty->dbh()->prepare("DELETE FROM {$opt["table_prefix"]}users WHERE userid = ?");
mysql_query($query) or die("Could not query: " . mysql_error()); $stmt->bindValue(1, (int) $_GET["userid"], PDO::PARAM_INT);
$stmt->execute();
header("Location: " . getFullPath("index.php")); header("Location: " . getFullPath("index.php"));
exit; exit;

View file

@ -203,8 +203,6 @@ try {
$smarty->assign('eventid', $eventid); $smarty->assign('eventid', $eventid);
} }
$smarty->assign('userid', $userid); $smarty->assign('userid', $userid);
$smarty->assign('isadmin', $_SESSION['admin']);
$smarty->assign('opt', $smarty->opt());
$smarty->display('event.tpl'); $smarty->display('event.tpl');
} }
catch (PDOException $e) { catch (PDOException $e) {

View file

@ -185,8 +185,6 @@ try {
if (isset($message)) { if (isset($message)) {
$smarty->assign('message', $message); $smarty->assign('message', $message);
} }
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $smarty->opt());
$smarty->display('families.tpl'); $smarty->display('families.tpl');
} }
catch (PDOException $e) { catch (PDOException $e) {

View file

@ -57,7 +57,6 @@ if (isset($_POST["action"]) && $_POST["action"] == "forgot") {
} }
$smarty->assign('action', $_POST["action"]); $smarty->assign('action', $_POST["action"]);
$smarty->assign('username', $username); $smarty->assign('username', $username);
$smarty->assign('opt', $smarty->opt());
$smarty->display('forgot.tpl'); $smarty->display('forgot.tpl');
} }
catch (PDOException $e) { catch (PDOException $e) {
@ -65,7 +64,6 @@ if (isset($_POST["action"]) && $_POST["action"] == "forgot") {
} }
} }
else { else {
$smarty->assign('opt', $smarty->opt());
$smarty->display('forgot.tpl'); $smarty->display('forgot.tpl');
} }
?> ?>

View file

@ -0,0 +1,34 @@
<?php
define('SMARTY_DIR', dirname(__FILE__) . "/Smarty-3.1.12/libs/");
require_once(SMARTY_DIR . "Smarty.class.php");
require_once(dirname(__FILE__) . "/config.php");
class MySmarty extends Smarty {
public function __construct() {
parent::__construct();
}
public function dbh() {
$opt = $this->opt();
return new PDO(
$opt["pdo_connection_string"],
$opt["pdo_username"],
$opt["pdo_password"]);
}
public function opt() {
static $opt;
if (!isset($opt)) {
$opt = getGlobalOptions();
}
return $opt;
}
public function display($t) {
parent::assign('isadmin', $_SESSION['admin']);
parent::assign('opt', $this->opt());
parent::display($t);
}
}
?>

View file

@ -283,7 +283,5 @@ if (isset($approval)) {
$smarty->assign('approval', $approval); $smarty->assign('approval', $approval);
} }
$smarty->assign('userid', $userid); $smarty->assign('userid', $userid);
$smarty->assign('isadmin', $_SESSION['admin']);
$smarty->assign('opt', $smarty->opt());
$smarty->display('home.tpl'); $smarty->display('home.tpl');
?> ?>

View file

@ -293,7 +293,5 @@ $smarty->assign('image_filename', $image_filename);
$smarty->assign('comment', $comment); $smarty->assign('comment', $comment);
$smarty->assign('categories', $categories); $smarty->assign('categories', $categories);
$smarty->assign('ranks', $ranks); $smarty->assign('ranks', $ranks);
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $smarty->opt());
$smarty->display('item.tpl'); $smarty->display('item.tpl');
?> ?>

View file

@ -50,11 +50,9 @@ if (!empty($_POST["username"])) {
} }
$smarty->assign('username', $username); $smarty->assign('username', $username);
$smarty->assign('opt', $smarty->opt());
$smarty->display('login.tpl'); $smarty->display('login.tpl');
} }
else { else {
$smarty->assign('opt', $smarty->opt());
$smarty->display('login.tpl'); $smarty->display('login.tpl');
} }
?> ?>

View file

@ -58,8 +58,6 @@ try {
$smarty->assign('recipients', $recipients); $smarty->assign('recipients', $recipients);
$smarty->assign('rcount', $rcount); $smarty->assign('rcount', $rcount);
$smarty->assign('userid', $userid); $smarty->assign('userid', $userid);
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $smarty->opt());
$smarty->display('message.tpl'); $smarty->display('message.tpl');
} }
catch (PDOException $e) { catch (PDOException $e) {

View file

@ -81,8 +81,6 @@ try {
$smarty->assign('totalprice', formatPrice($totalprice, $opt)); $smarty->assign('totalprice', formatPrice($totalprice, $opt));
$smarty->assign('itemcount', $itemcount); $smarty->assign('itemcount', $itemcount);
$smarty->assign('userid', $userid); $smarty->assign('userid', $userid);
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $smarty->opt());
$smarty->display('mylist.tpl'); $smarty->display('mylist.tpl');
} }
catch (PDOException $e) { catch (PDOException $e) {

View file

@ -89,8 +89,6 @@ try {
$smarty->assign('email', $row["email"]); $smarty->assign('email', $row["email"]);
$smarty->assign('email_msgs', $row["email_msgs"]); $smarty->assign('email_msgs', $row["email_msgs"]);
$smarty->assign('comment', $row["comment"]); $smarty->assign('comment', $row["comment"]);
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $smarty->opt());
$smarty->display('profile.tpl'); $smarty->display('profile.tpl');
} }
else { else {

View file

@ -162,7 +162,5 @@ if (isset($rendered_error)) {
} }
$smarty->assign('ranking', $_GET["ranking"]); $smarty->assign('ranking', $_GET["ranking"]);
$smarty->assign('haserror', $haserror); $smarty->assign('haserror', $haserror);
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $smarty->opt());
$smarty->display('ranks.tpl'); $smarty->display('ranks.tpl');
?> ?>

View file

@ -105,8 +105,6 @@ try {
$smarty->assign('quantity', $quantity); $smarty->assign('quantity', $quantity);
$smarty->assign('itemid', $itemid); $smarty->assign('itemid', $itemid);
$smarty->assign('userid', $userid); $smarty->assign('userid', $userid);
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $smarty->opt());
$smarty->display('receive.tpl'); $smarty->display('receive.tpl');
} }
catch (PDOException $e) { catch (PDOException $e) {

View file

@ -223,7 +223,5 @@ $smarty->assign('userid', $userid);
if (isset($message)) { if (isset($message)) {
$smarty->assign('message', $message); $smarty->assign('message', $message);
} }
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $smarty->opt());
$smarty->display('shop.tpl'); $smarty->display('shop.tpl');
?> ?>

View file

@ -82,8 +82,6 @@ try {
$smarty->assign('totalprice', formatPrice($totalprice, $opt)); $smarty->assign('totalprice', formatPrice($totalprice, $opt));
$smarty->assign('itemcount', $itemcount); $smarty->assign('itemcount', $itemcount);
$smarty->assign('userid', $userid); $smarty->assign('userid', $userid);
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $smarty->opt());
$smarty->display('shoplist.tpl'); $smarty->display('shoplist.tpl');
} }
catch (PDOException $e) { catch (PDOException $e) {

View file

@ -104,7 +104,5 @@ $smarty->assign('action', $_POST["action"]);
if (isset($error)) { if (isset($error)) {
$smarty->assign('error', $error); $smarty->assign('error', $error);
} }
$smarty->assign('isadmin', $_SESSION['admin']);
$smarty->assign('opt', $smarty->opt());
$smarty->display('signup.tpl'); $smarty->display('signup.tpl');
?> ?>

View file

@ -109,7 +109,6 @@ else if ($action == "edit") {
$approved = $row["approved"]; $approved = $row["approved"];
$userisadmin = $row["admin"]; $userisadmin = $row["admin"];
} }
mysql_free_result($rs);
} }
else if ($action == "") { else if ($action == "") {
$username = ""; $username = "";
@ -197,7 +196,6 @@ $users = array();
while ($row = $stmt->fetch()) { while ($row = $stmt->fetch()) {
$users[] = $row; $users[] = $row;
} }
mysql_free_result($rs);
$smarty->assign('action', $action); $smarty->assign('action', $action);
$smarty->assign('username', $username); $smarty->assign('username', $username);
@ -223,7 +221,5 @@ if (isset($message)) {
$smarty->assign('message', $message); $smarty->assign('message', $message);
} }
$smarty->assign('userid', $userid); $smarty->assign('userid', $userid);
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $smarty->opt());
$smarty->display('users.tpl'); $smarty->display('users.tpl');
?> ?>