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>'; }
$ok = $ath->updateNotificationSettings(user_getid(), $request->getValidated('watchees', 'string', ''), $request->getValidated('stop_notification', new Valid_WhiteList('stop_notification', array('1')), 0)); //{{{ 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; } } }
/** * addArtifactFollowup - add a followup to the artifact $artifact_id * * @param string $sessionKey the session hash associated with the session opened by the person who calls the service * @param int $group_id the ID of the group we want to add the follow-up * @param int $group_artifact_id the ID of the tracker we want to add the follow-up * @param int $artifact_id the ID of the artifact we want to add the follow-up * @param string $body the body of the follow-up * @param int $comment_type_id the comment type ID if so, or 100 if comment type is not used * @param int $format the format within the followup will be posted (text/HTML) * @return boolean true if the add is ok or a soap fault if : * - group_id does not match with a valid project, * - group_artifact_id does not match with a valid tracker * - artifact_id does not match with a valid artifact * - the add failed */ function addArtifactFollowup($sessionKey, $group_id, $group_artifact_id, $artifact_id, $body, $comment_type_id, $format) { global $art_field_fact, $ath; if (session_continue($sessionKey)) { try { $pm = ProjectManager::instance(); $grp = $pm->getGroupByIdForSoap($group_id, 'addArtifactFollowup'); } catch (SoapFault $e) { return $e; } $ath = new ArtifactType($grp, $group_artifact_id); if (!$ath || !is_object($ath)) { return new SoapFault(get_artifact_type_fault, 'Could Not Get ArtifactType', 'addArtifactFollowup'); } elseif ($ath->isError()) { return new SoapFault(get_artifact_type_fault, $ath->getErrorMessage(), 'addArtifactFollowup'); } $art_field_fact = new ArtifactFieldFactory($ath); if (!$art_field_fact || !is_object($art_field_fact)) { return new SoapFault(get_artifact_field_factory_fault, 'Could Not Get ArtifactFieldFactory', 'addArtifactFollowup'); } elseif ($art_field_fact->isError()) { return new SoapFault(get_artifact_field_factory_fault, $art_field_fact->getErrorMessage(), 'addArtifactFollowup'); } $a = new Artifact($ath, $artifact_id); if (!$a || !is_object($a)) { return new SoapFault(get_artifact_fault, 'Could Not Get Artifact', 'addArtifactFollowup'); } elseif ($a->isError()) { return new SoapFault(get_artifact_fault, $a->getErrorMessage(), 'addArtifactFollowup'); } // add the follow up with 0 as canned_response_id. To set a canned response, just put the content in the body comment. if (!$a->addFollowUpComment($body, $comment_type_id, 0, &$changes, $format)) { return new SoapFault(create_followup_fault, 'Comment could not be saved', 'addArtifactFollowup'); } else { // Send notification $agnf = new ArtifactGlobalNotificationFactory(); $addresses = $agnf->getAllAddresses($ath->getID(), true); $a->mailFollowupWithPermissions($addresses, $changes); return true; } // Update last_update_date field $a->update_last_update_date(); } else { return new SoapFault(invalid_session_fault, 'Invalid Session', 'addArtifactFollowup'); } }
exit_no_group(); } break; case 'export': require './export.php'; break; case 'updatecomment': $artifact_id = $request->get('artifact_id'); if (user_isloggedin() && $request->exist('followup_update')) { $followup_update = $request->get('followup_update'); $ah = new ArtifactHtml($ath, $artifact_id); $vFormat = new Valid_WhiteList('comment_format', array(Artifact::FORMAT_HTML, Artifact::FORMAT_TEXT)); $comment_format = $request->getValidated('comment_format', $vFormat, Artifact::FORMAT_TEXT); if ($ah->updateFollowupComment($request->get('artifact_history_id'), $followup_update, $changes, $comment_format)) { $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('tracker_common_artifact', 'followup_upd_succ')); $agnf = new ArtifactGlobalNotificationFactory(); $addresses = $agnf->getAllAddresses($ath->getID(), true); $ah->mailFollowupWithPermissions($addresses, $changes); } else { $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('tracker_common_artifact', 'followup_upd_fail')); } } $GLOBALS['Response']->redirect('?group_id=' . (int) $group_id . '&atid=' . (int) $atid . '&aid=' . (int) $artifact_id . '&func=detail'); break; case 'browse': $masschange = false; if ($request->get('change_report_column')) { $report_id = $request->getValidated('report_id', 'uint'); $field_name = $request->getValidated('change_report_column', 'string'); $arf = new ArtifactReportFactory($ath); if ($report = $arf->getArtifactReportHtml($report_id, $atid)) {
function updateArtifact($row, $data, $aid, &$errors, $notify = false) { global $Language; $ah = new ArtifactHtml($this->ath, $aid); if (!$ah || !is_object($ah)) { exit_error($Language->getText('global', 'error'), $Language->getText('tracker_index', 'not_create_art')); } else { if ($ah->isError()) { exit_error($Language->getText('global', 'error'), $ah->getErrorMessage()); } else { // Check if users can update anonymously if (!user_isloggedin() && !$this->ath->allowsAnon()) { exit_not_logged_in(); } if (!$ah->ArtifactType->userIsAdmin()) { exit_permission_denied(); return; } $vfl = $this->prepareVfl($data, $artifact_depend_id, $add_cc, $cc_comment, $comments); //data control layer if (!$ah->handleUpdate($artifact_depend_id, 100, $changes, false, $vfl, true)) { exit_error($Language->getText('global', 'error'), ''); } if ($add_cc) { if (!$ah->updateCC($add_cc, $cc_comment)) { $errors .= $Language->getText('tracker_import_utils', 'problem_add_cc', $ah->getID()) . " "; } } $comments_ok = false; if ($comments) { if ($this->parseFollowUpComments($comments, $parsed_comments, $aid) && $parsed_comments && !empty($parsed_comments)) { $comments_ok = true; $changes = null; if (!$ah->addFollowUpComments($parsed_comments)) { $errors .= $Language->getText('tracker_import_utils', 'problem_insert_followup', $ah->getID()) . " "; $comments_ok = false; return false; } } else { return false; } } if ($notify && (count($changes) > 0 || $add_cc || $comments_ok)) { $agnf = new ArtifactGlobalNotificationFactory(); $ah->mailFollowupWithPermissions($agnf->getAllAddresses($this->ath->getID(), $update = true), $changes); } if (count($changes) > 0 || $add_cc || $comments_ok) { // Update the 'last_update_date' artifact field $res_last_up = $ah->update_last_update_date(); } } } return true; }