00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: change_notifications.php 4977 2005-11-15 17:38:40Z yeupou $
00006 #
00007 # Copyright 2001-2002 (c) Laurent Julliard, CodeX Team, Xerox
00008 #
00009 # Copyright 2002-2004 (c) Mathieu Roy <yeupou--at--gnu.org>
00010 #
00011 # The Savane project is free software; you can redistribute it and/or
00012 # modify it under the terms of the GNU General Public License
00013 # as published by the Free Software Foundation; either version 2
00014 # of the License, or (at your option) any later version.
00015 #
00016 # The Savane project is distributed in the hope that it will be useful,
00017 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 # GNU General Public License for more details.
00020 #
00021 # You should have received a copy of the GNU General Public License
00022 # along with the Savane project; if not, write to the Free Software
00023 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024
00025 require "../../include/pre.php";
00026 require "../../include/account.php";
00027 require_directory("trackers");
00028
00029
00030
00031
00032
00033
00034 $user_id = user_getid();
00035 # get notification roles
00036 # get notification roles
00037 $res_roles = trackers_data_get_notification_roles();
00038 $num_roles = db_numrows($res_roles);
00039 $i=0;
00040 while ($arr = db_fetch_array($res_roles))
00041 {
00042 $arr_roles[$i] = $arr; $i++;
00043 }
00044
00045 # get notification events
00046 $res_events = trackers_data_get_notification_events();
00047 $num_events = db_numrows($res_events);
00048 $i=0;
00049 while ($arr = db_fetch_array($res_events))
00050 {
00051 $arr_events[$i] = $arr; $i++;
00052 }
00053
00054 # build the default notif settings in case the user has not yet defined her own
00055 # By default it's all 'yes'
00056 for ($i=0; $i<$num_roles; $i++)
00057 {
00058 $role_id = $arr_roles[$i]['role_id'];
00059 for ($j=0; $j<$num_events; $j++)
00060 {
00061 $event_id = $arr_events[$j]['event_id'];
00062 $arr_notif[$role_id][$event_id] = 1;
00063 }
00064 }
00065
00066 # Overwrite with user settings if any
00067 $res_notif = trackers_data_get_notification($user_id);
00068 while ($arr = db_fetch_array($res_notif))
00069 {
00070 $arr_notif[$arr['role_id']][$arr['event_id']] = $arr['notify'];
00071 }
00072
00073
00074
00075
00076
00077 if ($submit)
00078 {
00079 ######### Event/Role specific settings
00080 for ($i=0; $i<$num_roles; $i++)
00081 {
00082 $role_id = $arr_roles[$i]['role_id'];
00083 for ($j=0; $j<$num_events; $j++)
00084 {
00085 $event_id = $arr_events[$j]['event_id'];
00086 $cbox_name = 'cb-'.$role_id.'-'.$event_id;
00087 #print "DBG $cbox_name -> '".$$cbox_name."'<br />";
00088 $arr_notif[$role_id][$event_id] = ( $$cbox_name ? 1 : 0);
00089 }
00090 }
00091 trackers_data_delete_notification($user_id);
00092 $res_notif = trackers_data_insert_notification($user_id, $arr_roles, $arr_events, $arr_notif);
00093
00094 # Give Feedback
00095 if ($res_notif)
00096 { fb(_("Successfully updated notification by role settings")); }
00097 else
00098 { fb(_("Failed to update notification by role settings"), 1); }
00099
00100 ######### Reminder
00101 if (user_set_preference("batch_frequency", addslashes($form_frequency)))
00102 { fb(_("Successfully Updated Reminder Settings")); }
00103 else
00104 { fb(_("Failed to Update Reminder Setting"), 1); }
00105
00106 if (user_get_preference("batch_lastsent") == "")
00107 {
00108 if (user_set_preference("batch_lastsent", "0"))
00109 { fb(_("Successfully set Timestamp of the Latest Reminder")); }
00110 else
00111 { fb(_("Failed to Reset Timestamp of the Latest Reminder"), 1); }
00112 }
00113
00114 ####### Subject line
00115 # First test content: to avoid people entering white space and being in
00116 # trouble at a later point, first check if we can find something else than
00117 # white space
00118 if (preg_replace("/ /", "", $form_subject_line))
00119 {
00120 # Some characters cannot be allowed
00121 if (strspn($form_subject_line,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_[]()&יטא=$ש*:!,;?./%$ <>|") == strlen($form_subject_line))
00122 {
00123 user_set_preference("subject_line", $form_subject_line);
00124 fb(_("Successfully configured subject line"));
00125 }
00126 else
00127 { fb(_("Non alphanumeric characters in the proposed subject line, subject line configuration skipped."), 1); }
00128 }
00129 else
00130 {
00131 # Empty? Check if there is a configuration already. If so, kill it.
00132 if (user_get_preference("subject_line"))
00133 {
00134 user_unset_preference("subject_line");
00135 }
00136
00137 }
00138
00139
00140
00141 }
00142 # end submit
00143
00144
00145
00146
00147
00148
00149 site_user_header(array('title'=>_("Mail Notification Settings"),'context'=>'account'));
00150
00151
00152 print '<h3>'._("Role related notification settings").'</h3>';
00153 print '<p>'._("You can tune your notification settings and decide what item changes you want to be aware of, depending on your role.").'</p>
00154 ';
00155
00156
00157 print '
00158 <form action="'.$PHP_SELF.'" method="post">';
00159
00160 # Build Role/Event table
00161 # Rk: Can't use html_build_list_table_top because of the specific layout
00162
00163
00164 print '
00165 <table class="box">
00166 <tr>
00167 <td colspan="'.$num_roles.'" align="center" width="50%" class="boxtitle">'._("If my role in an item is:").'</td>
00168 <td rowspan="2" width="50%" class="boxtitle">'._("I want to be notified when:").'</td>
00169 </tr>';
00170
00171 for ($i=0; $i<$num_roles; $i++)
00172 {
00173 print '<td align="center" width="10%" class="boxtitle"><span class="smaller">'.$arr_roles[$i]['short_description']."</span></td>\n";
00174 }
00175 print "</tr>\n";
00176
00177 for ($j=0; $j<$num_events; $j++)
00178 {
00179 $event_id = $arr_events[$j]['event_id'];
00180 $event_label = $arr_events[$j]['event_label'];
00181 print '<tr class="'.utils_get_alt_row_color($j)."\">\n";
00182 for ($i=0; $i<$num_roles; $i++)
00183 {
00184 $role_id = $arr_roles[$i]['role_id'];
00185 $role_label = $arr_roles[$i]['role_label'];
00186 $cbox_name = 'cb-'.$role_id.'-'.$event_id;
00187 if ((($event_label == 'NEW_ITEM') && ($role_label != 'ASSIGNEE') && ($role_label != 'SUBMITTER')) )
00188 {
00189 # if the user is not an assignee or a submitter the new_item event is meaningless
00190 print ' <td align="center"><input type="hidden" name="'.$cbox_name.'" value="1" />-</td>'."\n";
00191 }
00192 else
00193 {
00194 print ' <td align="center"><input type="checkbox" name="'.$cbox_name.'" value="1" '.
00195 ($arr_notif[$role_id][$event_id] ? 'checked="checked"':'')." /></td>\n";
00196 }
00197 }
00198 print ' <td>'.$arr_events[$j]['description']."</td>\n";
00199 print "</tr>\n";
00200 }
00201
00202 print'
00203 </table>
00204 ';
00205
00206 print '<br /><h3>'._("Reminder").'</h3>';
00207 print '<p>'._("You can also receive reminders about opened items assigned to you, when their priority is higher than 5. Note that projects administrators can also set reminders for you, out of your control, for your activities on the project they administer.").'</p>
00208 ';
00209 $frequency = array("0" => _("None"),
00210 "1" => _("Daily"),
00211 "2" => _("Weekly"),
00212 "3" => _("Monthly"));
00213
00214 print '<span class="preinput">'._("Frequency of reminders:").'</span> ';
00215 print html_build_select_box_from_array($frequency,
00216 "form_frequency",
00217 user_get_preference("batch_frequency"));
00218
00219
00220 print '<br /><h3>'._("Subject Line Configuration").'</h3>';
00221 print '<p>'.sprintf(_('The header "%s" will always be included, and when applicable, so will "%s", "%s", and/or "%s".'), "X-Savane-Server", "X-Savane-Project", "X-Savane-Tracker", "X-Savane-Item-ID").'</p><p>'.sprintf(_('Another option for message filtering is to configure the prefix of the subject line with the following form. In this form, you can use the strings "%s", "%s", "%s", and "%s". They will be replaced by the appropriate values. If you leave this form empty, you will receive the default subject line.'), "%SERVER", "%PROJECT", "%TRACKER", "%ITEM").'
00222 </p>
00223 ';
00224
00225 $frequency = array("0" => _("None"),
00226 "1" => _("Daily"),
00227 "2" => _("Weekly"),
00228 "3" => _("Monthly"));
00229
00230 print '<span class="preinput">'._("Subject Line:").'</span> ';
00231 print '<input name="form_subject_line" size="50" type="text" value="'.user_get_preference("subject_line").'" />';
00232
00233
00234 print '
00235 <p align="center"><input type="submit" name="submit" value="'._("Update").'" /></p>
00236 </form>';
00237
00238 site_user_footer(array());
00239
00240 ?>