function displayNotificationForm($user_id) { global $Language; $hp = Codendi_HTMLPurifier::instance(); // By default it's all 'yes' for ($i = 0; $i < $this->num_roles; $i++) { $role_label = $this->arr_roles[$i]['role_label']; for ($j = 0; $j < $this->num_events; $j++) { $event_label = $this->arr_events[$j]['event_label']; $arr_notif[$role_label][$event_label] = 1; //echo "[$role_label][$event_label] = 1<br>"; } } $res_notif = $this->getNotificationWithLabels($user_id); while ($arr = db_fetch_array($res_notif)) { $arr_notif[$arr['role_label']][$arr['event_label']] = $arr['notify']; } $group = $this->getGroup(); $group_artifact_id = $this->getID(); $group_id = $group->getGroupId(); echo '<H2>' . $Language->getText('tracker_import_admin', 'tracker') . ' \'<a href="/tracker/admin/?group_id=' . (int) $group_id . '&atid=' . $group_artifact_id . '">' . $hp->purify(SimpleSanitizer::unsanitize($this->getName()), CODENDI_PURIFIER_CONVERT_HTML) . '</a>\' - ' . $Language->getText('tracker_include_type', 'mail_notif') . '</h2>'; // Build Wachees UI $res = $this->getWatchees($user_id); $arr_watchees = array(); while ($row_watchee = db_fetch_array($res)) { $arr_watchees[] = user_getname($row_watchee['watchee_id']); } $watchees = join(',', $arr_watchees); echo ' <FORM action="/tracker/admin" method="get"> <INPUT type="hidden" name="func" value="notification"> <INPUT type="hidden" name="atid" value="' . (int) $this->getID() . '"> <INPUT type="hidden" name="group_id" value="' . (int) $group_id . '">'; if ($this->userIsAdmin()) { echo '<h3><a name="ToggleEmailNotification"></a>' . $Language->getText('tracker_include_type', 'toggle_notification') . ' ' . help_button('TrackerAdministration.html#ToggleEmailNotification') . '</h3>'; echo ' <P>' . $Language->getText('tracker_include_type', 'toggle_notif_note') . '<BR> <BR><INPUT TYPE="checkbox" NAME="stop_notification" VALUE="1" ' . ($this->getStopNotification() ? 'CHECKED' : '') . '> ' . $Language->getText('tracker_include_type', 'stop_notification'); } else { if ($this->getStopNotification()) { echo '<h3><a name="ToggleEmailNotification"></a>' . $Language->getText('tracker_include_type', 'notification_suspended') . ' ' . help_button('TrackerAdministration.html#ToggleEmailNotification') . '</h3>'; echo ' <P><b>' . $Language->getText('tracker_include_type', 'toggle_notif_warn') . '</b><BR>'; } } echo '<h3><a name="GlobalEmailNotification"></a>' . $Language->getText('tracker_include_type', 'global_mail_notif') . ' ' . help_button('TrackerAdministration.html#TrackerGlobalEmailNotification') . '</h3>'; $agnf = new ArtifactGlobalNotificationFactory(); $notifs = $agnf->getGlobalNotificationsForTracker($this->getID()); if ($this->userIsAdmin()) { echo '<p>' . $Language->getText('tracker_include_type', 'admin_note') . '</p>'; if (count($notifs)) { echo '<div id="global_notifs">'; foreach ($notifs as $key => $nop) { echo '<div>'; echo '<a href="?func=notification&group_id=' . (int) $group_id . '&atid=' . (int) $this->getId() . '&action=remove_global&global_notification_id=' . (int) $notifs[$key]->getId() . '">' . $GLOBALS['Response']->getimage('ic/trash.png') . '</a> '; //addresses echo '<input type="text" name="global_notification[' . (int) $notifs[$key]->getId() . '][addresses]" value="' . $hp->purify($notifs[$key]->getAddresses(), CODENDI_PURIFIER_CONVERT_HTML) . '" size="55" />'; //all_updates echo ' ' . $Language->getText('tracker_include_type', 'send_all') . ' '; echo '<input type="hidden" name="global_notification[' . (int) $notifs[$key]->getId() . '][all_updates]" value="0" />'; echo '<input type="checkbox" name="global_notification[' . (int) $notifs[$key]->getId() . '][all_updates]" value="1" ' . ($notifs[$key]->isAllUpdates() ? 'checked="checked"' : '') . ' />'; //check_permissions echo ' ' . $Language->getText('tracker_include_type', 'check_perms') . ' '; echo '<input type="hidden" name="global_notification[' . (int) $notifs[$key]->getId() . '][check_permissions]" value="0" />'; echo '<input type="checkbox" name="global_notification[' . (int) $notifs[$key]->getId() . '][check_permissions]" value="1" ' . ($notifs[$key]->isCheckPermissions() ? 'checked="checked"' : '') . ' />'; echo '</div>'; } echo '</div>'; } echo '<p><a href="?func=notification&group_id=' . (int) $group_id . '&atid=' . (int) $this->getId() . '&action=add_global" id="add_global">' . $Language->getText('tracker_include_type', 'add') . '</a></p>'; echo '<script type="text/javascript">' . "\n document.observe('dom:loaded', function() {\n \$('add_global').observe('click', function (evt) {\n var self = arguments.callee;\n if (!self.counter) {\n self.counter = 0;\n }\n var number = self.counter++;\n \n var div = new Element('div');\n div.insert('<a href=\"#\" onclick=\"this.parentNode.remove(); return false;\">" . $GLOBALS['Response']->getimage('ic/trash.png') . "</a> '+\n //addresses\n '<input type=\"text\" name=\"add_global_notification['+number+'][addresses]\" size=\"55\" />'+\n //all_updates\n ' " . addslashes($Language->getText('tracker_include_type', 'send_all')) . " '+\n '<input type=\"hidden\" name=\"add_global_notification['+number+'][all_updates]\" value=\"0\" />'+\n '<input type=\"checkbox\" name=\"add_global_notification['+number+'][all_updates]\" value=\"1\" />'+\n //check_permissions\n ' " . addslashes($Language->getText('tracker_include_type', 'check_perms')) . " '+\n '<input type=\"hidden\" name=\"add_global_notification['+number+'][check_permissions]\" value=\"0\" />'+\n '<input type=\"checkbox\" name=\"add_global_notification['+number+'][check_permissions]\" value=\"1\" checked=\"checked\" />'\n );\n \n Element.insert(\$('global_notifs'), div);\n \n Event.stop(evt);\n return false;\n });\n });\n </script>"; } else { $ok = false; if (count($notifs)) { reset($notifs); while (!$ok && (list($id, ) = each($notifs))) { $ok = $notifs[$id]->getAddresses(); } } if ($ok) { echo $Language->getText('tracker_include_type', 'admin_conf'); foreach ($notifs as $key => $nop) { if ($notifs[$key]->getAddresses()) { echo '<div>' . $notifs[$key]->getAddresses() . ' '; echo $Language->getText('tracker_include_type', 'send_all_or_not', $notifs[$key]->isAllUpdates() ? $Language->getText('global', 'yes') : $Language->getText('global', 'no')); echo '</div>'; } } } else { echo $Language->getText('tracker_include_type', 'admin_not_conf'); } } echo '<h3>' . $Language->getText('tracker_include_type', 'perso_mail_notif') . '</h3>'; if ($this->userIsAdmin()) { // To watch other users you must have at least admin rights on the tracker echo ' <h4>' . $Language->getText('tracker_include_type', 'users_to_watch') . ' ' . help_button('TrackerAdministration.html#TrackerWatchers') . '</h4> <P>' . $Language->getText('tracker_include_type', 'backup_person') . ' <p><INPUT TYPE="TEXT" NAME="watchees" VALUE="' . $hp->purify($watchees, CODENDI_PURIFIER_CONVERT_HTML) . '" SIZE="55" MAXLENGTH="255"><br></p> '; $res = $this->getWatchers($user_id); $arr_watchers = array(); $watchers = ""; while ($row_watcher = db_fetch_array($res)) { $watcher_name = user_getname($row_watcher['user_id']); $watchers .= '<a href="/users/' . urlencode($watcher_name) . '">' . $hp->purify($watcher_name, CODENDI_PURIFIER_CONVERT_HTML) . '</a>,'; } $watchers = substr($watchers, 0, -1); // remove extra comma at the end if ($watchers) { echo "<p>" . $Language->getText('tracker_include_type', 'watchers', $hp->purify($watchers, CODENDI_PURIFIER_CONVERT_HTML)); } else { echo "<p>" . $Language->getText('tracker_include_type', 'no_watcher'); } echo '<br><br>'; } // Build Role/Event table // Rk: Can't use html_build_list_table_top because of the specific layout echo '<h4>' . $Language->getText('tracker_include_type', 'event_settings') . ' ' . help_button('TrackerAdministration.html#TrackerEventRoleBasedEmailNotification') . '</h4> <P>' . $Language->getText('tracker_include_type', 'tune_settings'); echo ' <table BORDER="0" CELLSPACING="1" CELLPADDING="2" class="small"> <tr class="boxtitle"> <td colspan="' . (int) $this->num_roles . '" align="center" width="50%"><b>' . $Language->getText('tracker_include_type', 'role_is') . '</b></td> <td rowspan="2" width="50%"><b> ' . $Language->getText('tracker_include_type', 'notify_me') . '</b></td> </tr>'; for ($i = 0; $i < $this->num_roles; $i++) { echo '<td align="center" width="10%"><b>' . $Language->getText('tracker_common_types', $this->arr_roles[$i]['short_description_msg']) . "</b></td>\n"; } echo "</tr>\n"; for ($j = 0; $j < $this->num_events; $j++) { $event_id = $this->arr_events[$j]['event_id']; $event_label = $this->arr_events[$j]['event_label']; echo "<tr class=\"" . util_get_alt_row_color($j) . "\">\n"; for ($i = 0; $i < $this->num_roles; $i++) { $role_id = $this->arr_roles[$i]['role_id']; $role_label = $this->arr_roles[$i]['role_label']; $cbox_name = 'cb_' . $role_id . '_' . $event_id; //echo "<BR>$role_label $role_id $event_label $event_id ".$arr_notif['$role_label']['$event_label']; if ($event_label == 'NEW_ARTIFACT' && $role_label != 'ASSIGNEE' && $role_label != 'SUBMITTER' || $event_label == 'ROLE_CHANGE' && $role_label != 'ASSIGNEE' && $role_label != 'CC') { // if the user is not a member then the ASSIGNEE column cannot // be set. If it's not an assignee or a submitter the new_artifact event is meaningless echo ' <td align="center"><input type="hidden" name="' . $cbox_name . '" value="1">-</td>' . "\n"; } else { echo ' <td align="center"><input type="checkbox" name="' . $cbox_name . '" value="1" ' . ($arr_notif[$role_label][$event_label] ? 'checked' : '') . "></td>\n"; } } echo ' <td> ' . $Language->getText('tracker_common_types', $this->arr_events[$j]['description_msg']) . "</td>\n"; echo "</tr>\n"; } echo "</table>\n"; $em = EventManager::instance(); $em->processEvent('artifact_type_html_display_notification_form', array('at' => $this, 'group_id' => $group_id, 'art_field_fact' => $GLOBALS['art_field_fact'])); echo '<P align="center"><INPUT type="submit" name="submit" value="' . $Language->getText('tracker_include_artifact', 'submit') . '"> </FORM>'; }
//{{{ Global Notifications $submitted_notifications = $request->get('global_notification'); /* new Valid_MultidimensionalArray( 'global_notification', array( 'addresses' => 'string', 'all_updates' => new Valid_WhiteList('', array(0, 1)), 'check_permissions' => new Valid_WhiteList('', array(0, 1)) ) ) ); */ if ($submitted_notifications) { $agnf = new ArtifactGlobalNotificationFactory(); $notifs = $agnf->getGlobalNotificationsForTracker($atid); foreach ($notifs as $id => $nop) { if (isset($submitted_notifications[$id]) && ($submitted_notifications[$id]['addresses'] != $notifs[$id]->getAddresses() || $submitted_notifications[$id]['all_updates'] != $notifs[$id]->isAllUpdates() || $submitted_notifications[$id]['check_permissions'] != $notifs[$id]->isCheckPermissions())) { $ok = $agnf->updateGlobalNotification($id, $submitted_notifications[$id]) && $ok; } } } if (is_array($request->get('add_global_notification'))) { foreach ($request->get('add_global_notification') as $new_global_notif) { if (isset($new_global_notif['addresses']) && trim($new_global_notif['addresses']) && isset($new_global_notif['all_updates']) && isset($new_global_notif['check_permissions'])) { if ($id = $agnf->addGlobalNotificationForTracker($atid)) { $ok = $agnf->updateGlobalNotification($id, $new_global_notif) && $ok; } } } }