converted from the mysql_ API to the PDO library
This commit is contained in:
parent
75aefbd9e3
commit
246232f0a3
31 changed files with 1460 additions and 1217 deletions
130
src/signup.php
130
src/signup.php
|
@ -13,70 +13,67 @@
|
|||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
include("config.php");
|
||||
include("db.php");
|
||||
include("funcLib.php");
|
||||
require_once(dirname(__FILE__) . "/includes/funcLib.php");
|
||||
require_once(dirname(__FILE__) . "/includes/MySmarty.class.php");
|
||||
$smarty = new MySmarty();
|
||||
$opt = $smarty->opt();
|
||||
|
||||
if (isset($_POST["action"])) {
|
||||
if ($_POST["action"] == "signup") {
|
||||
$username = $_POST["username"];
|
||||
$fullname = $_POST["fullname"];
|
||||
$email = $_POST["email"];
|
||||
$familyid = $_POST["familyid"];
|
||||
if (!get_magic_quotes_gpc()) {
|
||||
$username = addslashes($username);
|
||||
$fullname = addslashes($fullname);
|
||||
$email = addslashes($email);
|
||||
$familyid = addslashes($familyid);
|
||||
}
|
||||
if ($familyid == "")
|
||||
$familyid = "NULL";
|
||||
if (isset($_POST["action"]) && $_POST["action"] == "signup") {
|
||||
$username = $_POST["username"];
|
||||
$fullname = $_POST["fullname"];
|
||||
$email = $_POST["email"];
|
||||
$familyid = $_POST["familyid"];
|
||||
|
||||
// make sure that username isn't taken.
|
||||
$query = "SELECT userid FROM {$OPT["table_prefix"]}users WHERE username = '$username'";
|
||||
$rs = mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
if (mysql_num_rows($rs) > 0) {
|
||||
$error = "The username '" . stripslashes($username) . "' is already taken. Please choose another.";
|
||||
mysql_free_result($rs);
|
||||
// make sure that username isn't taken.
|
||||
$stmt = $smarty->dbh()->prepare("SELECT userid FROM {$opt["table_prefix"]}users WHERE username = ?");
|
||||
$stmt->bindParam(1, $username, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
if ($stmt->fetch()) {
|
||||
$error = "The username '" . $username . "' is already taken. Please choose another.";
|
||||
}
|
||||
else {
|
||||
// generate a password and insert the row.
|
||||
// NOTE: if approval is required, this password will be replaced
|
||||
// when the account is approved.
|
||||
$pwd = generatePassword($opt);
|
||||
|
||||
$stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}users(username,fullname,password,email,approved,initialfamilyid) VALUES(?, ?, {$opt["password_hasher"]}(?), ?, ?, ?)");
|
||||
$stmt->bindParam(1, $username, PDO::PARAM_STR);
|
||||
$stmt->bindParam(2, $fullname, PDO::PARAM_STR);
|
||||
$stmt->bindParam(3, $pwd, PDO::PARAM_STR);
|
||||
$stmt->bindParam(4, $email, PDO::PARAM_STR);
|
||||
$stmt->bindValue(5, !$opt["newuser_requires_approval"], PDO::PARAM_BOOL);
|
||||
$stmt->bindParam(6, $familyid, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
if ($opt["newuser_requires_approval"]) {
|
||||
// send the e-mails to the administrators.
|
||||
$stmt = $smarty->dbh()->prepare("SELECT fullname, email FROM {$opt["table_prefix"]}users WHERE admin = 1 AND email IS NOT NULL");
|
||||
$stmt->execute();
|
||||
while ($row = $stmt->fetch()) {
|
||||
mail(
|
||||
$row["email"],
|
||||
"Gift Registry approval request for " . $fullname,
|
||||
$fullname . " <" . $email . "> would like you to approve him/her for access to the Gift Registry.",
|
||||
"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"]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
mysql_free_result($rs);
|
||||
|
||||
// generate a password and insert the row.
|
||||
// NOTE: if approval is required, this password will be replaced
|
||||
// when the account is approved.
|
||||
$pwd = generatePassword();
|
||||
$query = "INSERT INTO {$OPT["table_prefix"]}users(username,fullname,password,email,approved,initialfamilyid) VALUES('$username','$fullname',{$OPT["password_hasher"]}('$pwd'),'$email'," . ($OPT["newuser_requires_approval"] ? "0" : "1") . ",$familyid)";
|
||||
mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
|
||||
if ($OPT["newuser_requires_approval"]) {
|
||||
// send the e-mails to the administrators.
|
||||
$query = "SELECT fullname, email FROM {$OPT["table_prefix"]}users WHERE admin = 1 AND email IS NOT NULL";
|
||||
$rs = mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
while ($row = mysql_fetch_assoc($rs)) {
|
||||
mail(
|
||||
$row["email"],
|
||||
"Gift Registry approval request for " . stripslashes($fullname),
|
||||
stripslashes($fullname) . " <" . stripslashes($email) . "> would like you to approve him/her for access to the Gift Registry.",
|
||||
"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"]);
|
||||
}
|
||||
mysql_free_result($rs);
|
||||
}
|
||||
else {
|
||||
// we don't require approval,
|
||||
// so immediately send them their initial password.
|
||||
// also, join them up to their initial family (if requested).
|
||||
if ($familyid != "NULL") {
|
||||
$query = "SELECT userid FROM {$OPT["table_prefix"]}users WHERE username = '$username'";
|
||||
$rs = mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
$row = mysql_fetch_assoc($rs);
|
||||
// we don't require approval,
|
||||
// so immediately send them their initial password.
|
||||
// also, join them up to their initial family (if requested).
|
||||
if ($familyid != NULL) {
|
||||
$stmt = $smarty->dbh()->prepare("SELECT userid FROM {$opt["table_prefix"]}users WHERE username = ?");
|
||||
$stmt->bindParam(1, $username, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
if ($row = $stmt->fetch()) {
|
||||
$userid = $row["userid"];
|
||||
mysql_free_result($rs);
|
||||
|
||||
$query = "INSERT INTO {$OPT["table_prefix"]}memberships(userid,familyid) VALUES($userid,$familyid)";
|
||||
echo $query;
|
||||
mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
$stmt = $smarty->dbh()->prepare("INSERT INTO {$opt["table_prefix"]}memberships(userid,familyid) VALUES(?, ?)");
|
||||
$stmt->bindParam(1, $userid, PDO::PARAM_INT);
|
||||
$stmt->bindParam(2, $familyid, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
mail(
|
||||
|
@ -84,25 +81,20 @@ if (isset($_POST["action"])) {
|
|||
"Gift Registry account created",
|
||||
"Your Gift Registry account was created.\r\n" .
|
||||
"Your username is $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 $email");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$query = "SELECT familyid, familyname FROM {$OPT["table_prefix"]}families ORDER BY familyname";
|
||||
$rs = mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
|
||||
$stmt = $smarty->dbh()->prepare("SELECT familyid, familyname FROM {$opt["table_prefix"]}families ORDER BY familyname");
|
||||
$stmt->execute();
|
||||
$families = array();
|
||||
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
|
||||
while ($row = $stmt->fetch()) {
|
||||
$families[] = $row;
|
||||
}
|
||||
mysql_free_result($rs);
|
||||
|
||||
define('SMARTY_DIR',str_replace("\\","/",getcwd()).'/includes/Smarty-3.1.12/libs/');
|
||||
require_once(SMARTY_DIR . 'Smarty.class.php');
|
||||
$smarty = new Smarty();
|
||||
$smarty->assign('families', $families);
|
||||
$smarty->assign('username', $username);
|
||||
$smarty->assign('fullname', $fullname);
|
||||
|
@ -113,6 +105,6 @@ if (isset($error)) {
|
|||
$smarty->assign('error', $error);
|
||||
}
|
||||
$smarty->assign('isadmin', $_SESSION['admin']);
|
||||
$smarty->assign('opt', $OPT);
|
||||
$smarty->assign('opt', $smarty->opt());
|
||||
$smarty->display('signup.tpl');
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue