/**
     * Show all the cc addresses of all the artifacts in $change_ids
     * @param group_id: the group id
     * @param group_artifact_id: the artifact type ID
     * @param change_ids: all the ids of the artifacts affected
     */
    function showCCList($change_ids)
    {
        $hp = Codendi_HTMLPurifier::instance();
        global $Language;
        $out = "";
        $result = $this->getCC($change_ids);
        if (db_numrows($result) > 0) {
            $title_arr = array();
            $title_arr[] = $Language->getText('tracker_include_artifact', 'cc_address');
            $title_arr[] = $Language->getText('tracker_include_type', 'occurrence');
            $title_arr[] = $Language->getText('tracker_include_canned', 'delete');
            $out .= html_build_list_table_top($title_arr);
            $fmt = "\n" . '<TR class="%s"><td>%s</td><td align="center">%s</td><td align="center">%s</td></tr>';
            // Loop through the cc and format them
            $email = "";
            $row_color = 0;
            $i = 0;
            while ($row = db_fetch_array($result)) {
                if ($row['email'] != $email) {
                    if ($email != "") {
                        $html_delete = '
		<INPUT TYPE="CHECKBOX" NAME="delete_cc[]" VALUE="' . $hp->purify($delete_ids, CODENDI_PURIFIER_CONVERT_HTML) . '">';
                        $out .= sprintf($fmt, util_get_alt_row_color($row_color), $href_cc, $i, $html_delete);
                        $row_color++;
                        $i = 0;
                    }
                    $email = $row['email'];
                    $res_username = user_get_result_set_from_unix($email);
                    if ($res_username && db_numrows($res_username) == 1) {
                        $href_cc = util_user_link($email);
                    } else {
                        $href_cc = "<a href=\"mailto:" . util_normalize_email($email) . "\">" . $hp->purify($email, CODENDI_PURIFIER_CONVERT_HTML) . '</a>';
                    }
                    $delete_ids = $row['artifact_cc_id'];
                } else {
                    $delete_ids .= "," . $row['artifact_cc_id'];
                }
                $i++;
            }
            $html_delete = '
		<INPUT TYPE="CHECKBOX" NAME="delete_cc[]" VALUE="' . $delete_ids . '">';
            $out .= sprintf($fmt, util_get_alt_row_color($row_color), $href_cc, $i, $html_delete);
            $out .= "</TABLE>";
        }
        return $out;
    }
Beispiel #2
0
 /**
  * Display the list of CC addresses
  *
  * @param group_id: the group id
  * @param group_artifact_id: the artifact type ID
  * @param ascii: ascii mode
  *
  * @return void
  */
 function showCCList($group_id, $group_artifact_id, $ascii = false, $pv = 0)
 {
     $hp = Codendi_HTMLPurifier::instance();
     global $Language;
     //
     //      format the CC list for this artifact
     //
     $result = $this->getCCList();
     $rows = db_numrows($result);
     $out = '';
     // Nobody in the CC list -> return now
     if ($rows <= 0) {
         if ($ascii) {
             $out = $Language->getText('tracker_include_artifact', 'cc_empty') . $GLOBALS['sys_lf'];
         } else {
             $out = '<H4>' . $Language->getText('tracker_include_artifact', 'cc_empty') . '</H4>';
         }
         return $out;
     }
     // Header first an determine what the print out format is
     // based on output type (Ascii, HTML)
     if ($ascii) {
         $out .= $Language->getText('tracker_include_artifact', 'cc_list') . $GLOBALS['sys_lf'] . str_repeat("*", strlen($Language->getText('tracker_include_artifact', 'cc_list'))) . $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'];
         $fmt = "%-35s | %s" . $GLOBALS['sys_lf'];
         $out .= sprintf($fmt, $Language->getText('tracker_include_artifact', 'cc_address'), $Language->getText('tracker_include_artifact', 'fill_cc_list_cmt'));
         $out .= "------------------------------------------------------------------" . $GLOBALS['sys_lf'];
     } else {
         $title_arr = array();
         $title_arr[] = $Language->getText('tracker_include_artifact', 'cc_address');
         $title_arr[] = $Language->getText('tracker_include_artifact', 'fill_cc_list_cmt');
         $title_arr[] = $Language->getText('tracker_include_artifact', 'added_by');
         $title_arr[] = $Language->getText('tracker_include_artifact', 'posted_on');
         if ($pv == 0) {
             $title_arr[] = $Language->getText('tracker_include_canned', 'delete');
         }
         $out .= html_build_list_table_top($title_arr);
         $fmt = "\n" . '<TR class="%s"><td>%s</td><td>%s</td><td align="center">%s</td><td align="center">%s</td>';
         if ($pv == 0) {
             $fmt .= '<td align="center">%s</td>';
         }
         $fmt .= '</tr>';
     }
     // Loop through the cc and format them
     for ($i = 0; $i < $rows; $i++) {
         $email = db_result($result, $i, 'email');
         $artifact_cc_id = db_result($result, $i, 'artifact_cc_id');
         // if the CC is a user point to its user page else build a mailto: URL
         $res_username = user_get_result_set_from_unix($email);
         if ($res_username && db_numrows($res_username) == 1) {
             $href_cc = util_user_link($email);
         } else {
             $href_cc = '<a href="mailto:' . util_normalize_email($email) . '">' . $email . '</a>';
         }
         if ($ascii) {
             $out .= sprintf($fmt, $email, SimpleSanitizer::unsanitize(db_result($result, $i, 'comment')));
         } else {
             // show CC delete icon if one of the condition is met:
             // (a) current user is a group member
             // (b) the CC name is the current user
             // (c) the CC email address matches the one of the current user
             // (d) the current user is the person who added a gieven name in CC list
             if (user_ismember($this->ArtifactType->getGroupID()) || user_getname(user_getid()) == $email || user_getemail(user_getid()) == $email || user_getname(user_getid()) == db_result($result, $i, 'user_name')) {
                 $html_delete = '<a href="?func=delete_cc&group_id=' . (int) $group_id . '&aid=' . (int) $this->getID() . '&atid=' . (int) $group_artifact_id . '&artifact_cc_id=' . (int) $artifact_cc_id . '" ' . ' onClick="return confirm(\'' . $Language->getText('tracker_include_artifact', 'delete_cc') . '\')">' . '<IMG SRC="' . util_get_image_theme("ic/trash.png") . '" HEIGHT="16" WIDTH="16" BORDER="0" ALT="' . $Language->getText('global', 'btn_delete') . '"></A>';
             } else {
                 $html_delete = '-';
             }
             $out .= sprintf($fmt, util_get_alt_row_color($i), $href_cc, $hp->purify(SimpleSanitizer::unsanitize(db_result($result, $i, 'comment')), CODENDI_PURIFIER_BASIC, $this->ArtifactType->getGroupId()), util_user_link(db_result($result, $i, 'user_name')), format_date($GLOBALS['Language']->getText('system', 'datefmt'), db_result($result, $i, 'date')), $html_delete);
         }
         // for
     }
     // final touch...
     $out .= $ascii ? $GLOBALS['sys_lf'] : "</TABLE>";
     return $out;
 }
Beispiel #3
0
/**
 * Return the emails normalized 
**/
function util_normalize_emails($adresses)
{
    $adresses = util_split_emails($adresses);
    list($host, $port) = explode(':', $GLOBALS['sys_default_domain']);
    foreach ($adresses as $key => $value) {
        if (trim($value) !== "") {
            $value = util_cleanup_emails($value);
            if (!validate_email($value)) {
                //Maybe it is a codendi username, we take his e-mail
                $result = user_get_result_set_from_unix($value);
                if ($result && db_numrows($result) > 0) {
                    $value = db_result($result, 0, "email");
                } else {
                    $value = $value . "@" . $host;
                }
            }
            $adresses[$key] = $value;
        }
    }
    return implode(',', $adresses);
}
Beispiel #4
0
 function setWatchees($user_id, $watchees)
 {
     global $Language;
     //echo "setWatchees($user_id, $watchees)<br>";
     if ($watchees) {
         //echo "watchees";
         $res_watch = true;
         $arr_user_names = split('[,;]', $watchees);
         $arr_user_ids = array();
         while (list(, $user_name) = each($arr_user_names)) {
             $user_ident = util_user_finder($user_name, true);
             $res = user_get_result_set_from_unix($user_ident);
             if (!$res || db_numrows($res) <= 0) {
                 // user doesn;t exist  so abort this step and give feedback
                 $this->setError(" - " . $Language->getText('tracker_common_type', 'invalid_name', $user_name));
                 $res_watch = false;
                 continue;
             } else {
                 // store in a hash to eliminate duplicates. skip user itself
                 if (db_result($res, 0, 'user_id') != $user_id) {
                     $arr_user_ids[db_result($res, 0, 'user_id')] = 1;
                 }
             }
         }
         if ($res_watch) {
             $this->deleteWatchees($user_id);
             $arr_watchees = array_keys($arr_user_ids);
             $sql = 'INSERT INTO artifact_watcher (artifact_group_id, user_id,watchee_id) VALUES ';
             $num_watchees = count($arr_watchees);
             for ($i = 0; $i < $num_watchees; $i++) {
                 $sql .= "('" . db_ei($this->getID()) . "','" . db_ei($user_id) . "','" . db_ei($arr_watchees[$i]) . "'),";
             }
             $sql = substr($sql, 0, -1);
             // remove extra comma at the end
             //echo $sql."<br>";
             return db_query($sql);
         }
     } else {
         $this->deleteWatchees($user_id);
     }
 }
Beispiel #5
0
function user_getemail_from_unix($user_name)
{
    global $Language;
    $result = user_get_result_set_from_unix($user_name);
    if ($result && db_numrows($result) > 0) {
        return db_result($result, 0, "email");
    } else {
        return $Language->getText('include_user', 'email_not_found');
    }
}
 /**
  * prepare our $data record so that we can use standard artifact methods to create, update, ...
  * the imported artifact
  */
 function prepareVfl($data, &$artifact_depend_id, &$add_cc, &$cc_comment, &$comments)
 {
     global $Language;
     for ($c = 0; $c < count($data); $c++) {
         $label = $this->parsed_labels[$c];
         $field = $this->used_fields[$label];
         if ($field) {
             $field_name = $field->getName();
         }
         $imported_value = $data[$label];
         // FOLLOW-UP COMMENTS
         if ($label == $this->lbl_list['follow_ups']) {
             //$field_name = "details";
             if ($data[$label] != "" && trim($data[$label]) != $Language->getText('plugin_tracker_import_utils', 'no_followups')) {
                 $comments = $data[$label];
             }
             continue;
             // DEPEND ON
         } else {
             if ($label == $this->lbl_list['is_dependent_on']) {
                 $depends = $data[$label];
                 if ($depends != $Language->getText('global', 'none') && $depends != "") {
                     $artifact_depend_id = $depends;
                 } else {
                     //we have to delete tracker_depend_ids if nothing has been specified
                     $artifact_depend_id = $Language->getText('global', 'none');
                 }
                 continue;
                 // CC LIST
             } else {
                 if ($label == $this->lbl_list['add_cc']) {
                     if ($data[$label] != "" && $data[$label] != $Language->getText('global', 'none')) {
                         $add_cc = $data[$label];
                     } else {
                         $add_cc = "";
                     }
                     continue;
                     // CC COMMENT
                 } else {
                     if ($label == $this->lbl_list['cc_comment']) {
                         $cc_comment = $data[$label];
                         continue;
                         // ORIGINAL SUBMISSION
                         //special treatment for "Original Submission" alias "details"
                         //in the import. To avoid confusion, the details field is renamed
                         //original_submission in the import
                         //} else if (isset($field_name) && $field_name == "details") {
                         //$vfl["original_submission"] = $data[$label];
                         //continue;
                         // SUBMITTED BY
                     } else {
                         if ($field_name == "submitted_by") {
                             $sub_user_name = $data[$label];
                             if ($sub_user_name && $sub_user_name != "") {
                                 $res = user_get_result_set_from_unix($sub_user_name);
                                 $imported_value = db_result($res, 0, 'user_id');
                             }
                             $vfl[$field_name] = $imported_value;
                             continue;
                         }
                     }
                 }
             }
         }
         // transform imported_value into format that can be inserted into db
         unset($value);
         unset($predef_vals);
         if (isset($this->predefined_values[$c])) {
             $predef_vals = $this->predefined_values[$c];
         }
         if (isset($predef_vals)) {
             if ($field && $field->getDisplayType() == "MB") {
                 $val_arr = explode(",", $imported_value);
                 while (list(, $name) = each($val_arr)) {
                     if ($name == $Language->getText('global', 'none')) {
                         $value[] = 100;
                     } else {
                         $value[] = $predef_vals[$name];
                     }
                 }
             } else {
                 if ($imported_value == $Language->getText('global', 'none')) {
                     $value = 100;
                 } else {
                     $value = $predef_vals[$imported_value];
                 }
                 //special case for severity where we allow to specify
                 // 1 instead of "1 - Ordinary"
                 // 5 instead of "5 - Major"
                 // 9 intead of "9 - Critical"
                 if ($field_name == "severity" && (strcasecmp($imported_value, '1') == 0 || strcasecmp($imported_value, '5') == 0 || strcasecmp($imported_value, '9') == 0)) {
                     $value = $imported_value;
                 }
             }
             $vfl[$field_name] = $value;
             // IT COULD BE SO SIMPLE !!!
         } else {
             $vfl[$field_name] = $imported_value;
         }
     }
     return $vfl;
 }