|
From: Benjamin C. <bc...@us...> - 2002-03-21 13:44:58
|
Update of /cvsroot/phpbt/phpbt
In directory usw-pr-cvs1:/tmp/cvs-serv21944
Modified Files:
bug.php config-dist.php config.php upgrade.php user.php
Log Message:
The first user preference: Whether to receive email notifications of bug changes
Index: bug.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/bug.php,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -r1.86 -r1.87
--- bug.php 20 Mar 2002 15:59:24 -0000 1.86
+++ bug.php 21 Mar 2002 13:44:54 -0000 1.87
@@ -216,11 +216,13 @@
// Reporter never changes;
$reporter = $db->getOne('select email from '.TBL_AUTH_USER
- ." where user_id = {$buginfo['created_by']}");
+ ." u, ".TBL_USER_PREF." p where u.user_id = {$buginfo['created_by']} ".
+ "and u.user_id = p.user_id and email_notices = 1");
$reporterstat = ' ';
- $assignedto = $db->getOne('select email from '.TBL_AUTH_USER
- .' where user_id = '
- .(!empty($cf['assigned_to']) ? $cf['assigned_to'] : $buginfo['assigned_to']));
+ $assignedto = $db->getOne('select email from '.TBL_AUTH_USER." u, ".
+ TBL_USER_PREF.' p where u.user_id = '
+ .(!empty($cf['assigned_to']) ? $cf['assigned_to'] : $buginfo['assigned_to']).
+ " and u.user_id = p.user_id and email_notices = 1");
$assignedtostat = !empty($cf['assigned_to']) ? '!' : ' ';
// If there are new comments grab the comments immediately before the latest
@@ -262,39 +264,45 @@
$t->set_var('cblock', '');
}
+ $maillist = array();
// Don't email the person who just made the changes (later, make this
// behavior toggable by the user)
- if ($userid != $buginfo['created_by'])
+ if ($userid != $buginfo['created_by'] and !empty($reporter))
$maillist[] = $reporter;
- if ($userid != (!empty($cf['assigned_to']) ? $cf['assigned_to'] : $buginfo['assigned_to']))
+ if ($userid != (!empty($cf['assigned_to']) ? $cf['assigned_to'] : $buginfo['assigned_to'])
+ and !empty($assignedto))
$maillist[] = $assignedto;
// Collect the CCs
if ($ccs = $db->getCol('select email from '.TBL_BUG_CC.' left join '.
- TBL_AUTH_USER." using(user_id) where bug_id = {$buginfo['bug_id']}")) {
+ TBL_AUTH_USER." u using(user_id), ".TBL_USER_PREF." p ".
+ "where bug_id = {$buginfo['bug_id']} and u.user_id = p.user_id ".
+ "and email_notices = 1")) {
array_push($maillist, $ccs);
}
// Later add a watcher (such as QA person) check here
- $toemail = delimit_list(', ',$maillist);
+ if (count($maillist)) {
+ if ($toemail = delimit_list(', ',$maillist)) {
- $t->set_var(array(
- 'bugid' => $buginfo['bug_id'],
- 'bugurl' => INSTALL_URL."/bug.php?op=show&bugid={$buginfo['bug_id']}",
- 'priority' => $select['priority'][(!empty($cf['priority']) ? $cf['priority'] : $buginfo['priority'])],
- 'priority_stat' => !empty($cf['priority']) ? '!' : ' ',
- 'reporter' => $reporter,
- 'reporter_stat' => $reporterstat,
- 'assignedto' => $assignedto,
- 'assignedto_stat' => $assignedtostat
- ));
- if ($toemail) {
- mail($toemail,"[Bug {$buginfo['bug_id']}] ".($newbug ? 'New' : 'Changed').
- ' - '.(!empty($cf['title']) ? $cf['title'] : $buginfo['title']),
- $t->parse('main','emailout'),
- sprintf("From: %s\nReply-To: %s\nErrors-To: %s\nContent-Type: text/plain; charset=%s\nContent-Transfer-Encoding: 8bit\n", ADMIN_EMAIL, ADMIN_EMAIL,
- ADMIN_EMAIL, $STRING['lang_charset']));
- }
+ $t->set_var(array(
+ 'bugid' => $buginfo['bug_id'],
+ 'bugurl' => INSTALL_URL."/bug.php?op=show&bugid={$buginfo['bug_id']}",
+ 'priority' => $select['priority'][(!empty($cf['priority']) ? $cf['priority'] : $buginfo['priority'])],
+ 'priority_stat' => !empty($cf['priority']) ? '!' : ' ',
+ 'reporter' => $reporter,
+ 'reporter_stat' => $reporterstat,
+ 'assignedto' => $assignedto,
+ 'assignedto_stat' => $assignedtostat
+ ));
+
+ mail($toemail,"[Bug {$buginfo['bug_id']}] ".($newbug ? 'New' : 'Changed').
+ ' - '.(!empty($cf['title']) ? $cf['title'] : $buginfo['title']),
+ $t->parse('main','emailout'),
+ sprintf("From: %s\nReply-To: %s\nErrors-To: %s\nContent-Type: text/plain; charset=%s\nContent-Transfer-Encoding: 8bit\n", ADMIN_EMAIL, ADMIN_EMAIL,
+ ADMIN_EMAIL, $STRING['lang_charset']));
+ }
+ }
}
function update_bug($bugid = 0) {
@@ -692,8 +700,8 @@
"and {$_sv['queryinfo']['query']} and bug_id <> $bugid
order by {$_sv['queryinfo']['order']} {$_sv['queryinfo']['sort']}, bug_id asc", $offset, $limit);
- $firstid = $db->getOne();
- $secondid = $db->getOne();
+ list($firstid, $chunks) = $rs->fetchRow(DB_FETCHMODE_ORDERED);
+ list($secondid, $chunks) = $rs->fetchRow(DB_FETCHMODE_ORDERED);
if ($pos) {
if ($firstid) {
Index: config-dist.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/config-dist.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- config-dist.php 18 Mar 2002 18:01:53 -0000 1.9
+++ config-dist.php 21 Mar 2002 13:44:54 -0000 1.10
@@ -56,6 +56,7 @@
define ('TBL_STATUS', TBL_PREFIX.'status');
define ('TBL_USER_GROUP', TBL_PREFIX.'user_group');
define ('TBL_USER_PERM', TBL_PREFIX.'user_perm');
+define ('TBL_USER_PREF', TBL_PREFIX.'user_pref');
define ('TBL_VERSION', TBL_PREFIX.'version');
define ('TBL_PROJECT_GROUP', TBL_PREFIX.'project_group');
Index: config.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/config.php,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- config.php 18 Mar 2002 18:00:38 -0000 1.25
+++ config.php 21 Mar 2002 13:44:54 -0000 1.26
@@ -58,6 +58,7 @@
define ('TBL_STATUS', TBL_PREFIX.'status');
define ('TBL_USER_GROUP', TBL_PREFIX.'user_group');
define ('TBL_USER_PERM', TBL_PREFIX.'user_perm');
+define ('TBL_USER_PREF', TBL_PREFIX.'user_pref');
define ('TBL_VERSION', TBL_PREFIX.'version');
define ('TBL_PROJECT_GROUP', TBL_PREFIX.'project_group');
Index: upgrade.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/upgrade.php,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- upgrade.php 20 Mar 2002 20:10:09 -0000 1.14
+++ upgrade.php 21 Mar 2002 13:44:54 -0000 1.15
@@ -38,11 +38,17 @@
}
$rs = $db->query("select * from ".TBL_DB_SEQUENCE);
if (DB_TYPE == 'pgsql') {
+ // Set up the user prefs table
+ $db->query("CREATE TABLE ".TBL_USER_PREF." ( user_id INT4 NOT NULL DEFAULT '0', email_notices INT2 NOT NULL DEFAULT '1', PRIMARY KEY (user_id) )");
+ $db->query("insert into ".TBL_USER_PREF." (user_id) select user_id from ".TBL_AUTH_USER);
// Move the sequences
while ($rs->fetchInto($row)) {
$db->query("create sequence {$row['seq_name']}_seq start {$row['nextid']}");
}
} else {
+ // Set up the user prefs table
+ $db->query("CREATE TABLE ".TBL_USER_PREF." ( user_id int(11) NOT NULL default '0', email_notices tinyint(1) NOT NULL default '1', PRIMARY KEY (user_id) )");
+ $db->query("insert into ".TBL_USER_PREF." (user_id) select user_id from ".TBL_AUTH_USER);
// Move the sequences
while ($rs->fetchInto($row)) {
$db->query("create table {$row['seq_name']}_seq (id int unsigned auto_increment not null primary key)");
Index: user.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/user.php,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- user.php 20 Mar 2002 20:04:04 -0000 1.21
+++ user.php 21 Mar 2002 13:44:54 -0000 1.22
@@ -62,11 +62,36 @@
$t->set_file('content', 'passwordchanged.html');
}
+// Save changes to a user's preferences
+function change_preferences($prefs) {
+ global $db, $u, $t;
+
+ $updates = array();
+
+ $old_prefs = $db->getRow("select * from ".TBL_USER_PREF." where user_id = $u");
+ array_shift($old_prefs); // Drop the user_id field
+ $updates = array();
+ foreach ($old_prefs as $pref => $val) {
+ if (in_array($pref, $prefs) and !$val) {
+ $updates[] = "set $pref = 1";
+ } elseif (!in_array($pref, $prefs) and $val) {
+ $updates[] = "set $pref = 0";
+ }
+ }
+ if (count($updates)) {
+ $db->query("update ".TBL_USER_PREF.' '.@join(', ', $updates).
+ " where user_id = $u");
+ }
+ $t->set_file('content', 'preferenceschanged.html');
+}
+
+
function show_preferences_form($error = '') {
global $t, $pass1, $pass2, $all_db_fields, $default_db_fields, $_sv, $db, $u;
$t->set_file('content', 'user.html');
$t->set_block('content', 'column_list_row', 'list_rows');
+ $t->set_block('content', 'pref_row', 'pref_rows');
$t->set_block('content', 'votesblock', 'votesb');
$t->set_block('votesblock', 'vote_row', 'vote_rows');
@@ -107,6 +132,22 @@
}
$t->parse('votesb', 'votesblock', true);
}
+
+ // Display current preference settings
+ $pref_labels = array(
+ 'email_notices' => 'Receive notifications of bug changes via email'
+ );
+ $prefs = $db->getRow("select * from ".TBL_USER_PREF." where user_id = $u");
+ array_shift($prefs);
+
+ foreach ($prefs as $pref => $val) {
+ $t->set_var(array(
+ 'pref_label' => $pref_labels[$pref],
+ 'pref' => $pref,
+ 'checked' => $val ? 'checked' : ''
+ ));
+ $t->parse('pref_rows', 'pref_row', true);
+ }
}
$t->set_file('wrap', 'wrap.html');
@@ -118,6 +159,7 @@
elseif (isset($_pv['do'])) switch ($_pv['do']) {
case 'changepassword' : change_password($_pv['pass1'], $_pv['pass2']); break;
case 'changecolumnlist' : change_bug_list_columns($_pv['column_list']); break;
+ case 'changeprefs' : change_preferences(isset($_pv['preferences']) ? $_pv['preferences'] : array()); break;
default : show_preferences_form();
}
else show_preferences_form();
|