From 121baf21f0045189e3cd61a045610bbda2bca6d7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 31 Aug 2008 11:02:53 -0400 Subject: [PATCH] - Get the email system to work for register.php - Fix includes/functions_datastore.php --- global.php | 3 ++ includes/api_user.php | 4 +- includes/emails.php | 4 +- includes/functions_datastore.php | 82 ++++++++++++++++---------------- register.php | 33 ++++++++----- 5 files changed, 68 insertions(+), 58 deletions(-) diff --git a/global.php b/global.php index eefd2dd..86677eb 100755 --- a/global.php +++ b/global.php @@ -36,6 +36,9 @@ BSTemplate::$templatePath = 'templates/%s.tpl'; require_once ISSO . '/Mail.php'; require_once 'includes/emails.php'; +define('MAIL_FROM_ADDRESS', bugdar::$options['webmasteremail']); +define('MAIL_FROM_NAME', bugdar::$options['trackertitle']); + // ################################################################### // global template variables diff --git a/includes/api_user.php b/includes/api_user.php index a78c07e..acc45f7 100644 --- a/includes/api_user.php +++ b/includes/api_user.php @@ -82,7 +82,7 @@ class UserAPI extends BSApi */ function set_salt() { - $this->set('salt', BSFunctions::random(array(1, 15))); + $this->set('salt', BSFunctions::random(rand(3, 15))); } // ################################################################### @@ -115,7 +115,7 @@ class UserAPI extends BSApi */ function post_insert() { - $this->registry->db->query(" + BSApp::$db->query(" INSERT INTO " . TABLE_PREFIX . "useremail (userid, mask, relation) VALUES diff --git a/includes/emails.php b/includes/emails.php index e9b1fd1..98743be 100644 --- a/includes/emails.php +++ b/includes/emails.php @@ -49,7 +49,7 @@ If you have any questions, please don\'t hesitate to contact the webmaster.') You requested this lost password email at the %2$s bug tracker. To reset your password, simply click the link below (or paste it into your browser window exactly) and enter a new password. -%3$s/login.php?do=recoverpw&activator=%4$s +%3$s/login.php?do=recoverpw&activator=%4$s If you did not request this, do not worry as this notice will expire in 24 hours.') ), @@ -73,7 +73,7 @@ If you have any questions, please don\'t hesitate to contact the webmaster.') Welcome to the %2$s tracker. Before you can begin posting bug reports, you\'ll need to activate your account. To do this, please click this link: -%3$s/register.php?do=activate&userid=%4$d&activator=%5$s') +%3$s/register.php?do=activate&userid=%4$d&activator=%5$s') ), // bug notification diff --git a/includes/functions_datastore.php b/includes/functions_datastore.php index 113c21a..4d6a7f3 100755 --- a/includes/functions_datastore.php +++ b/includes/functions_datastore.php @@ -24,16 +24,16 @@ function build_languages() { global $bugsys; - $languages = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "language"); + $languages = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "language"); foreach ($languages as $language) { $tempstore["$language[languageid]"] = $language; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing the language cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('language', '" . $bugsys->escape(serialize($tempstore)) . "')" + VALUES ('language', '" . BSApp::$input->escape(serialize($tempstore)) . "')" ); bugdar::$datastore['language'] = $tempstore; @@ -44,16 +44,16 @@ function build_settings() { global $bugsys; - $settings = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "setting"); + $settings = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "setting"); foreach ($settings as $setting) { $options["$setting[varname]"] = $setting['value']; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing the setting cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('setting', '" . $bugsys->escape(serialize($options)) . "')" + VALUES ('setting', '" . BSApp::$input->escape(serialize($options)) . "')" ); bugdar::$datastore['setting'] = $options; @@ -64,16 +64,16 @@ function build_usergroups() { global $bugsys; - $usergroups = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup"); + $usergroups = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup"); foreach ($usergroups as $usergroup) { $groups["$usergroup[usergroupid]"] = $usergroup; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing usergroup cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('usergroup', '" . $bugsys->escape(serialize($groups)) . "')" + VALUES ('usergroup', '" . BSApp::$input->escape(serialize($groups)) . "')" ); bugdar::$datastore['usergroup'] = $groups; @@ -84,16 +84,16 @@ function build_statuses() { global $bugsys; - $statuses = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "status ORDER BY displayorder ASC"); + $statuses = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "status ORDER BY displayorder ASC"); foreach ($statuses as $status) { $tempstore["$status[statusid]"] = $status; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing status cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('status', '" . $bugsys->escape(serialize($tempstore)) . "')" + VALUES ('status', '" . BSApp::$input->escape(serialize($tempstore)) . "')" ); bugdar::$datastore['status'] = $tempstore; @@ -104,16 +104,16 @@ function build_severities() { global $bugsys; - $severities = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "severity ORDER BY displayorder ASC"); + $severities = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "severity ORDER BY displayorder ASC"); foreach ($severities as $severity) { $tempstore["$severity[severityid]"] = $severity; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing severity cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('severity', '" . $bugsys->escape(serialize($tempstore)) . "')" + VALUES ('severity', '" . BSApp::$input->escape(serialize($tempstore)) . "')" ); bugdar::$datastore['severity'] = $tempstore; @@ -124,16 +124,16 @@ function build_priorities() { global $bugsys; - $priorities = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "priority ORDER BY displayorder ASC"); + $priorities = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "priority ORDER BY displayorder ASC"); foreach ($priorities as $priority) { $tempstore["$priority[priorityid]"] = $priority; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing priority cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('priority', '" . $bugsys->escape(serialize($tempstore)) . "')" + VALUES ('priority', '" . BSApp::$input->escape(serialize($tempstore)) . "')" ); bugdar::$datastore['priority'] = $tempstore; @@ -157,7 +157,7 @@ function build_assignedto() $ids = implode(',', $ids); $exprs = implode(' OR ', $exprs); - $users = $bugsys->db->query(" + $users = BSApp::$db->query(" SELECT email, displayname, userid, showemail FROM " . TABLE_PREFIX . "user AS user WHERE usergroupid IN ($ids) OR $exprs" @@ -167,10 +167,10 @@ function build_assignedto() $devs["$user[userid]"] = $user; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing developer / assign to cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('assignto', '" . $bugsys->escape(serialize($devs)) . "')" + VALUES ('assignto', '" . BSApp::$input->escape(serialize($devs)) . "')" ); bugdar::$datastore['assignto'] = $devs; @@ -181,16 +181,16 @@ function build_resolutions() { global $bugsys; - $resolutions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "resolution ORDER BY displayorder ASC"); + $resolutions = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "resolution ORDER BY displayorder ASC"); foreach ($resolutions as $resolution) { $tempstore["$resolution[resolutionid]"] = $resolution; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing resolution cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('resolution', '" . $bugsys->escape(serialize($tempstore)) . "')" + VALUES ('resolution', '" . BSApp::$input->escape(serialize($tempstore)) . "')" ); bugdar::$datastore['resolution'] = $tempstore; @@ -201,16 +201,16 @@ function build_versions() { global $bugsys; - $versions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC"); + $versions = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC"); foreach ($versions as $version) { $tempstore["$version[versionid]"] = $version; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing version cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('version', '" . $bugsys->escape(serialize($tempstore)) . "')" + VALUES ('version', '" . BSApp::$input->escape(serialize($tempstore)) . "')" ); bugdar::$datastore['version'] = $tempstore; @@ -221,7 +221,7 @@ function build_products() { global $bugsys; - $products = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC"); + $products = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC"); foreach ($products as $product) { if ($product['parentid']) @@ -234,12 +234,12 @@ function build_products() } } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing product / component cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) VALUES - ('product', '" . $bugsys->escape(serialize($tempstore['product'])) . "'), - ('component', '" . $bugsys->escape(serialize($tempstore['component'])) . "')" + ('product', '" . BSApp::$input->escape(serialize($tempstore['product'])) . "'), + ('component', '" . BSApp::$input->escape(serialize($tempstore['component'])) . "')" ); bugdar::$datastore['product'] = $tempstore['product']; @@ -251,16 +251,16 @@ function build_permissions() { global $bugsys; - $permissions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "permission ORDER BY usergroupid, productid"); + $permissions = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "permission ORDER BY usergroupid, productid"); foreach ($permissions as $permission) { $tempstore["$permission[usergroupid]"]["$permission[productid]"] = $permission['mask']; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing permissions cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('permission', '" . $bugsys->escape(serialize($tempstore)) . "')" + VALUES ('permission', '" . BSApp::$input->escape(serialize($tempstore)) . "')" ); bugdar::$datastore['permission'] = $tempstore; @@ -271,16 +271,16 @@ function build_automations() { global $bugsys; - $automations = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "automation ORDER BY name ASC"); + $automations = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "automation ORDER BY name ASC"); foreach ($automations as $automation) { $actions["$automation[actionid]"] = $automation; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing automation cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('automation', '" . $bugsys->escape(serialize($actions)) . "')" + VALUES ('automation', '" . BSApp::$input->escape(serialize($actions)) . "')" ); bugdar::$datastore['automation'] = $actions; @@ -292,23 +292,23 @@ function build_user_help() global $bugsys; // custom field descriptions - $descriptions = $bugsys->db->query("SELECT fieldid, name, description FROM " . TABLE_PREFIX . "bugfield"); + $descriptions = BSApp::$db->query("SELECT fieldid, name, description FROM " . TABLE_PREFIX . "bugfield"); foreach ($descriptions as $field) { $help["field$field[fieldid]"] = array('title' => $field['name'], 'body' => $field['description']); } // standard help texts - $texts = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "fieldhelp"); + $texts = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "fieldhelp"); foreach ($texts as $field) { $help["$field[keystring]"] = $field; } - $bugsys->db->query(" + BSApp::$db->query(" ### replacing user help cache ### REPLACE INTO " . TABLE_PREFIX . "datastore (title, data) - VALUES ('help', '" . $bugsys->escape(serialize($help)) . "')" + VALUES ('help', '" . BSApp::$input->escape(serialize($help)) . "')" ); bugdar::$datastore['help'] = $help; diff --git a/register.php b/register.php index ffb4790..4ff905d 100755 --- a/register.php +++ b/register.php @@ -93,11 +93,12 @@ if ($_POST['do'] == 'insert') $db->query("INSERT INTO " . TABLE_PREFIX . "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW . ", 2)"); - eval('$email = "' . $template->fetch(FetchEmailPath('activateaccount.xml', bugdar::$datastore['language'][$input->in['languageid']]['langcode'])) . '";'); - $email = $bugsys->xml->parse($email); - $mail->setSubject($email['email']['subject']['value']); - $mail->setBodyText($email['email']['bodyText']['value']); - + $email = get_email_text('activate_account'); + $mail = new BSMail(); + $mail->setSubject($email['subject']); + $mail->setBodyText(sprintf($email['bodyText'], $input->in['displayname'], bugdar::$options['trackertitle'], bugdar::$options['trackerurl'], $userid, $activationid)); + $mail->setFromAddress(MAIL_FROM_ADDRESS); + $mail->setFromName(MAIL_FROM_NAME); $mail->send($input->in['email'], $input->in['displayname']); $message->message(T('You now need to activate your account via email.')); @@ -107,10 +108,13 @@ if ($_POST['do'] == 'insert') if (bugdar::$options['sendwelcomemail']) { $displayName = $input->in['displayname']; - eval('$email = "' . $template->fetch(FetchEmailPath('welcome.xml', bugdar::$datastore['language'][$input->in['languageid']]['langcode'])) . '";'); - $email = $bugsys->xml->parse($email); - $mail->setSubject($email['email']['subject']['value']); - $mail->setBodyText($email['email']['bodyText']['value']); + + $email = get_email_text('welcome'); + $mail = new BSMail(); + $mail->setSubject($email['subject']); + $mail->setBodyText(sprintf($email['bodyText'], $input->in['displayname'], bugdar::$options['trackertitle'])); + $mail->setFromAddress(MAIL_FROM_ADDRESS); + $mail->setFromName(MAIL_FROM_NAME); $mail->send($input->in['email'], $input->in['displayname']); } @@ -177,10 +181,13 @@ if ($_REQUEST['do'] == 'activate') if (bugdar::$options['sendwelcomemail']) { $displayName = $user['displayname']; - eval('$email = "' . $template->fetch(FetchEmailPath('welcome.xml', bugdar::$datastore['language'][$user['languageid']]['langcode'])) . '";'); - $email = $bugsys->xml->parse($email); - $mail->setSubject($email['email']['subject']['value']); - $mail->setBodyText($email['email']['bodyText']['value']); + + $email = get_email_text('welcome'); + $mail = new BSMail(); + $mail->setSubject($email['subject']); + $mail->setBodyText(sprintf($email['bodyText'], $user['displayname'], bugdar::$options['trackertitle'])); + $mail->setFromAddress(MAIL_FROM_ADDRESS); + $mail->setFromName(MAIL_FROM_NAME); $mail->send($user['email'], $user['displayname']); } -- 2.22.5