コード例 #1
0
ファイル: Artifact.class.php プロジェクト: nterray/tuleap
 /** for a certain set of users being part of the same ugroups
  * create the mail body containing only fields that they have the permission to read
  */
 function createMailForUsers($ugroups, $changes, $group_id, $group_artifact_id, &$ok, &$subject)
 {
     global $art_field_fact, $art_fieldset_fact, $Language;
     $fmt_len = 40;
     $fmt_left = sprintf("%%-%ds ", $fmt_len - 1);
     $fmt_right = "%s";
     $artifact_href = get_server_url() . "/tracker/?func=detail&aid=" . $this->getID() . "&atid={$group_artifact_id}&group_id={$group_id}";
     $used_fields = $art_field_fact->getAllUsedFields();
     $art_fieldset_fact = new ArtifactFieldsetFactory($this->ArtifactType);
     $used_fieldsets = $art_fieldset_fact->getAllFieldSetsContainingUsedFields();
     $ok = false;
     $body = '';
     //generate the field permissions (TRACKER_FIELD_READ, TRACKER_FIEDL_UPDATE or nothing)
     //for all fields of this tracker given the $ugroups the user is part of
     $field_perm = false;
     if ($ugroups) {
         $field_perm = $this->ArtifactType->getFieldPermissions($ugroups);
     }
     $summ = "";
     if ($field_perm === false || isset($field_perm['summary']) && $field_perm['summary'] && permission_can_read_field($field_perm['summary'])) {
         $summ = util_unconvert_htmlspecialchars($this->getValue('summary'));
     }
     $subject = '[' . $this->ArtifactType->getCapsItemName() . ' #' . $this->getID() . '] ' . $summ;
     //echo "<br>......... field_perm for "; print_r($ugroups); echo " = "; print_r($field_perm);
     // artifact fields
     // Generate the message preamble with all required
     // artifact fields - Changes first if there are some.
     if ($changes) {
         $body = $GLOBALS['sys_lf'] . "=============   " . strtoupper(SimpleSanitizer::unsanitize($this->ArtifactType->getName())) . " #" . $this->getID() . ": " . $Language->getText('tracker_include_artifact', 'latest_modif') . "   =============" . $GLOBALS['sys_lf'] . $artifact_href . $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . $this->formatChanges($changes, $field_perm, $visible_change) . $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . "";
         if (!$visible_change) {
             return;
         }
     }
     $ok = true;
     $visible_snapshot = false;
     $full_snapshot = "";
     // We write the name of the project
     $pm = ProjectManager::instance();
     $full_snapshot .= sprintf($fmt_left . $GLOBALS['sys_lf'] . "", $Language->getText('tracker_include_artifact', 'project') . ' ' . util_unconvert_htmlspecialchars($pm->getProject($group_id)->getPublicName()));
     // Write all the fields, grouped by fieldsetset and ordered by rank.
     $left = 1;
     $visible_fieldset = false;
     // fetch list of used fieldsets for this artifact
     foreach ($used_fieldsets as $fieldset_id => $fieldset) {
         $fieldset_snapshot = '';
         $used_fields = $fieldset->getAllUsedFields();
         // fetch list of used fields and the current field values
         // for this artifact
         while (list($key, $field) = each($used_fields)) {
             $field_name = $field->getName();
             if ($field_perm === false || isset($field_perm[$field_name]) && $field_perm[$field_name] && permission_can_read_field($field_perm[$field_name])) {
                 $field_html = new ArtifactFieldHtml($field);
                 $visible_fieldset = true;
                 $visible_snapshot = true;
                 // For multi select box, we need to retrieve all the values
                 if ($field->isMultiSelectBox()) {
                     $field_value = $field->getValues($this->getID());
                 } else {
                     $field_value = $this->getValue($field->getName());
                 }
                 $display = $field_html->display($group_artifact_id, $field_value, false, true, true, true);
                 $item = sprintf($left ? $fmt_left : $fmt_right, $display);
                 if (strlen($item) > $fmt_len) {
                     if (!$left) {
                         $fieldset_snapshot .= "" . $GLOBALS['sys_lf'] . "";
                     }
                     $fieldset_snapshot .= sprintf($fmt_right, $display);
                     $fieldset_snapshot .= "" . $GLOBALS['sys_lf'] . "";
                     $left = 1;
                 } else {
                     $fieldset_snapshot .= $item;
                     $left = !$left;
                     if ($left) {
                         $fieldset_snapshot .= "" . $GLOBALS['sys_lf'] . "";
                     }
                 }
             }
         }
         // while
         if ($visible_fieldset) {
             $full_snapshot .= "" . $GLOBALS['sys_lf'] . "";
             $full_snapshot .= $left ? "" : "" . $GLOBALS['sys_lf'] . "";
             $full_snapshot .= '--- ' . SimpleSanitizer::unsanitize($fieldset->getLabel()) . ' ---';
             $full_snapshot .= "" . $GLOBALS['sys_lf'] . "";
             $full_snapshot .= $fieldset_snapshot;
         }
     }
     if ($visible_snapshot) {
         $full_snapshot .= "" . $GLOBALS['sys_lf'] . "";
     }
     $body .= "=============   " . strtoupper(SimpleSanitizer::unsanitize($this->ArtifactType->getName())) . " #" . $this->getID() . ": " . $Language->getText('tracker_include_artifact', 'full_snapshot') . "   =============" . $GLOBALS['sys_lf'] . ($changes ? '' : $artifact_href) . $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . $full_snapshot;
     if (!$left) {
         $body .= "" . $GLOBALS['sys_lf'] . "";
     }
     // Now display other special fields
     // Then output the history of bug comments from newest to oldest
     $body .= $this->showFollowUpComments($group_id, 0, self::OUTPUT_MAIL_TEXT);
     // Then output the CC list
     $body .= "" . $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . $this->showCCList($group_id, $group_artifact_id, true);
     // Then output the dependencies
     $body .= "" . $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . $this->showDependencies($group_id, $group_artifact_id, true);
     // Then output the history of attached files from newest to oldest
     $body .= "" . $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . $this->showAttachedFiles($group_id, $group_artifact_id, true);
     // Extract references from the message
     $referenceManager =& ReferenceManager::instance();
     $ref_array = $referenceManager->extractReferencesGrouped($body, $group_id);
     if (count($ref_array) > 0) {
         $body .= $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . $Language->getText('tracker_include_artifact', 'references') . $GLOBALS['sys_lf'];
     }
     foreach ($ref_array as $description => $match_array) {
         $body .= $GLOBALS['sys_lf'] . $description . ":" . $GLOBALS['sys_lf'];
         foreach ($match_array as $match => $ref_instance) {
             $reference =& $ref_instance->getReference();
             $body .= ' ' . $ref_instance->getMatch() . ': ' . $ref_instance->getFullGotoLink() . $GLOBALS['sys_lf'];
         }
     }
     // Finally output the message trailer
     $body .= "" . $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . $Language->getText('tracker_include_artifact', 'follow_link');
     $body .= "" . $GLOBALS['sys_lf'] . $artifact_href;
     if ($ok) {
         $mail = new Mail();
         $mail->setBody($body);
         return $mail;
     } else {
         return null;
     }
 }
コード例 #2
0
 /**
  *  Display detail report form
  *
  *  @return void
  */
 function showReportForm()
 {
     $hp = Codendi_HTMLPurifier::instance();
     global $ath, $Language;
     $g = $ath->getGroup();
     $group_id = $g->getID();
     $atid = $ath->getID();
     $ath->adminHeader(array('title' => $Language->getText('tracker_include_report', 'modify_report'), 'help' => 'TrackerAdministration.html#TrackerReportSetting'));
     echo '<H2>' . $Language->getText('tracker_import_admin', 'tracker') . ' \'<a href="/tracker/admin/?group_id=' . (int) $group_id . '&atid=' . (int) $atid . '">' . $hp->purify(SimpleSanitizer::unsanitize($ath->getName()), CODENDI_PURIFIER_CONVERT_HTML) . '</a>\' -  ' . $Language->getText('tracker_include_report', 'modify_report') . ' \'' . $hp->purify($this->name, CODENDI_PURIFIER_CONVERT_HTML) . '\'</H2>';
     // display the table of all fields that can be included in the report
     // along with their current state in this report
     $title_arr = array();
     $title_arr[] = $Language->getText('tracker_include_report', 'field_label');
     $title_arr[] = $Language->getText('tracker_include_artifact', 'desc');
     $title_arr[] = $Language->getText('tracker_include_report', 'search_crit');
     $title_arr[] = $Language->getText('tracker_include_report', 'rank_search');
     $title_arr[] = $Language->getText('tracker_include_report', 'rep_col');
     $title_arr[] = $Language->getText('tracker_include_report', 'rank_repo');
     $title_arr[] = $Language->getText('tracker_include_report', 'col_width');
     echo '<FORM ACTION="/tracker/admin/" METHOD="POST">
                <INPUT TYPE="HIDDEN" NAME="func" VALUE="report">
                <INPUT TYPE="HIDDEN" NAME="update_report" VALUE="y">
                <INPUT TYPE="HIDDEN" NAME="atid" VALUE="' . (int) $atid . '">
                <INPUT TYPE="HIDDEN" NAME="group_id" VALUE="' . (int) $group_id . '">
                <INPUT TYPE="HIDDEN" NAME="report_id" VALUE="' . (int) $this->report_id . '">
                <INPUT TYPE="HIDDEN" NAME="post_changes" VALUE="1">
                <B>' . $Language->getText('tracker_include_artifact', 'name') . ': </B>
                <INPUT TYPE="TEXT" NAME="rep_name" VALUE="' . $hp->purify($this->name, CODENDI_PURIFIER_CONVERT_HTML) . '" CLASS="textfield_small" MAXLENGTH="80">
                      &nbsp;&nbsp;&nbsp;&nbsp;<B>' . $Language->getText('tracker_include_report', 'scope') . ': </B>';
     $scope = $this->scope;
     if ($ath->userIsAdmin()) {
         echo '<SELECT ID="rep_scope" NAME="rep_scope" onchange="if (document.getElementById(\'rep_scope\').value == \'P\') {document.getElementById(\'rep_default\').disabled=false} else { document.getElementById(\'rep_default\').disabled=true;document.getElementById(\'rep_default\').checked=false }" >
                                     <OPTION VALUE="I"' . ($scope == 'I' ? 'SELECTED' : '') . '>' . $Language->getText('global', 'Personal') . '</OPTION>
                                     <OPTION VALUE="P"' . ($scope == 'P' ? 'SELECTED' : '') . '>' . $Language->getText('global', 'Project') . '</OPTION>
                                     </SELECT>';
         echo '&nbsp;&nbsp;&nbsp;&nbsp;<B>' . $Language->getText('tracker_include_report', 'default') . ':</B>' . '<INPUT TYPE="CHECKBOX" ID="rep_default" NAME="rep_default" ' . ($this->is_default == 1 ? 'CHECKED' : '') . ' ' . ($this->scope != 'P' ? 'DISABLED' : '') . '>';
     } else {
         echo ($scope == 'P' ? $Language->getText('global', 'Project') : $Language->getText('global', 'Personal')) . '<INPUT TYPE="HIDDEN" NAME="rep_scope" VALUE="' . $hp->purify($scope, CODENDI_PURIFIER_CONVERT_HTML) . '">';
         echo '&nbsp;&nbsp;&nbsp;&nbsp;<B>' . $Language->getText('tracker_include_report', 'default') . ':</B>' . '<INPUT TYPE="CHECKBOX" ID="rep_default" NAME="rep_default" ' . ($this->is_default == 1 ? 'CHECKED' : '') . ' DISABLED >';
     }
     echo '
                 <P>
                 <B>' . $Language->getText('tracker_include_artifact', 'desc') . ':</B>
                 <INPUT TYPE="TEXT" NAME="rep_desc" VALUE="' . $hp->purify($this->description, CODENDI_PURIFIER_CONVERT_HTML) . '" SIZE="50" MAXLENGTH="120">
                       <P>';
     echo html_build_list_table_top($title_arr);
     // Write all the fields, grouped by fieldsetset and ordered by rank.
     $i = 0;
     $aff = new ArtifactFieldFactory($ath);
     $art_fieldset_fact = new ArtifactFieldsetFactory($ath);
     $used_fieldsets = $art_fieldset_fact->getAllFieldSetsContainingUsedFields();
     // fetch list of used fieldsets for this artifact
     foreach ($used_fieldsets as $fieldset_id => $fieldset) {
         $used_fields = $fieldset->getAllUsedFields();
         echo '<TR class="fieldset_separator">';
         echo '<TD colspan="7">' . $fieldset->getLabel() . '</TD>';
         echo '</TR>';
         while (list($key, $field) = each($used_fields)) {
             // Do not show fields not used by the project
             if (!$field->isUsed()) {
                 continue;
             }
             // Do not show some special fields any way
             if ($field->isSpecial()) {
                 if ($field->getName() == 'group_id' || $field->getName() == 'comment_type_id') {
                     continue;
                 }
             }
             //Do not show unreadable fields
             if (!$ath->userIsAdmin() && !$field->userCanRead($group_id, $this->group_artifact_id)) {
                 continue;
             }
             $cb_search = 'CBSRCH_' . $field->getName();
             $cb_report = 'CBREP_' . $field->getName();
             $tf_search = 'TFSRCH_' . $field->getName();
             $tf_report = 'TFREP_' . $field->getName();
             $tf_colwidth = 'TFCW_' . $field->getName();
             $rep_field = null;
             if (isset($this->fields[$field->getName()])) {
                 $rep_field = $this->fields[$field->getName()];
             }
             if (!$rep_field) {
                 $rep_field = new ArtifactReportField();
             }
             $cb_search_chk = $rep_field->isShowOnQuery() ? 'CHECKED' : '';
             $cb_report_chk = $rep_field->isShowOnResult() ? 'CHECKED' : '';
             $tf_search_val = $rep_field->getPlaceQuery();
             $tf_report_val = $rep_field->getPlaceResult();
             $tf_colwidth_val = $rep_field->getColWidth();
             echo '<TR class="' . util_get_alt_row_color($i) . '">';
             echo "\n<td>" . $field->getLabel() . '</td>' . "\n<td>" . $field->getDescription() . '</td>' . "\n<td align=\"center\">" . '<input type="checkbox" name="' . $cb_search . '" value="1" ' . $cb_search_chk . ' ></td>' . "\n<td align=\"center\">" . '<input type="text" name="' . $tf_search . '" value="' . $tf_search_val . '" size="5" maxlen="5"></td>' . "\n<td align=\"center\">" . '<input type="checkbox" name="' . $cb_report . '" value="1" ' . $cb_report_chk . ' ></td>' . "\n<td align=\"center\">" . '<input type="text" name="' . $tf_report . '" value="' . $tf_report_val . '" size="5" maxlen="5"></td>' . "\n<td align=\"center\">" . '<input type="text" name="' . $tf_colwidth . '" value="' . $tf_colwidth_val . '" size="5" maxlen="5"></td>' . '</TR>';
             $i++;
         }
     }
     echo '</TABLE>' . '<P><CENTER><INPUT TYPE="SUBMIT" VALUE="' . $Language->getText('global', 'btn_submit') . '"></CENTER>' . '</FORM>';
 }