/** * Return the string to display the follow ups comments * * @param Integer group_id: the group id * @param Integer output By default set to OUTPUT_BROWSER, the output is displayed on browser * set to OUTPUT_MAIL_TEXT, the followups will be sent in mail * else is an export csv/DB * @return string the follow-up comments to display in HTML or in ascii mode */ function showFollowUpComments($group_id, $pv, $output = self::OUTPUT_BROWSER) { $hp = $this->getHTMLPurifier(); $uh = UserHelper::instance(); // // Format the comment rows from artifact_history // global $Language; //$group = $this->ArtifactType->getGroup(); $group_artifact_id = $this->ArtifactType->getID(); //$group_id = $group->getGroupId(); $result = $this->getFollowups(); $rows = db_numrows($result); // No followup comment -> return now if ($rows <= 0) { if ($output == self::OUTPUT_EXPORT || $output == self::OUTPUT_MAIL_TEXT) { $out = $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . " " . $Language->getText('tracker_import_utils', 'no_followups') . $GLOBALS['sys_lf']; } else { $out = '<H4>' . $Language->getText('tracker_import_utils', 'no_followups') . '</H4>'; } return $out; } $out = ''; // Header first if ($output == self::OUTPUT_EXPORT || $output == self::OUTPUT_MAIL_TEXT) { $out .= $Language->getText('tracker_include_artifact', 'follow_ups') . $GLOBALS['sys_lf'] . str_repeat("*", strlen($Language->getText('tracker_include_artifact', 'follow_ups'))); } else { if ($rows > 0) { $out .= '<div style="text-align:right">'; $out .= '<script type="text/javascript"> function tracker_expand_all_comments() { $H(tracker_comment_togglers).values().each(function (value) { (value)(null, true, true); }); } function tracker_collapse_all_comments() { $H(tracker_comment_togglers).values().each(function (value) { (value)(null, true, false); }); } var matches = location.hash.match(/#comment_(\\d*)/); var linked_comment_id = matches ? matches[1] : null; </script>'; $out .= '<a href="#expand_all" onclick="tracker_expand_all_comments(); return false;">' . $Language->getText('tracker_include_artifact', 'expand_all') . '</a> | <a href="#expand_all" onclick="tracker_collapse_all_comments(); return false;">' . $Language->getText('tracker_include_artifact', 'collapse_all') . '</a></div>'; } } // Loop throuh the follow-up comments and format them $last_visit_date = user_get_preference('tracker_' . $this->ArtifactType->getId() . '_artifact_' . $this->getId() . '_last_visit'); for ($i = 0; $i < $rows; $i++) { $comment_type = db_result($result, $i, 'comment_type'); $comment_type_id = db_result($result, $i, 'comment_type_id'); $comment_id = db_result($result, $i, 'artifact_history_id'); $field_name = db_result($result, $i, 'field_name'); $orig_subm = $this->getOriginalCommentSubmitter($comment_id); $orig_date = $this->getOriginalCommentDate($comment_id); $value = db_result($result, $i, 'new_value'); $isHtml = db_result($result, $i, 'format'); if ($comment_type_id == 100 || $comment_type == "") { $comment_type = ''; } else { $comment_type = '[' . SimpleSanitizer::unsanitize($comment_type) . ']'; } if ($output == self::OUTPUT_EXPORT || $output == self::OUTPUT_MAIL_TEXT) { $fmt = $GLOBALS['sys_lf'] . $GLOBALS['sys_lf'] . "------------------------------------------------------------------" . $GLOBALS['sys_lf'] . $Language->getText('tracker_import_utils', 'date') . ": %-30s" . $Language->getText('global', 'by') . ": %s" . $GLOBALS['sys_lf'] . "%s"; //The mail body $comment_txt = $this->formatFollowUp($group_id, $isHtml, $value, $output); $out .= sprintf($fmt, format_date(util_get_user_preferences_export_datefmt(), db_result($orig_date, 0, 'date')), db_result($orig_subm, 0, 'mod_by') == 100 ? db_result($orig_subm, 0, 'email') : user_getname(db_result($orig_subm, 0, 'mod_by')), ($comment_type != '' ? $comment_type . $GLOBALS['sys_lf'] : '') . $comment_txt); } else { $style = ''; $toggle = 'ic/toggle_minus.png'; if ($last_visit_date > db_result($orig_date, 0, 'date') && $i > 0) { $style = 'style="display:none;"'; $toggle = 'ic/toggle_plus.png'; } $out .= "\n" . ' <div class="followup_comment" id="comment_' . $comment_id . '"> <div class="' . util_get_alt_row_color($i) . ' followup_comment_header"> <div class="followup_comment_title">'; $out .= '<script type="text/javascript">document.write(\'<span>'; $out .= $GLOBALS['HTML']->getImage($toggle, array('id' => 'comment_' . (int) $comment_id . '_toggle', 'style' => 'vertical-align:middle; cursor:hand; cursor:pointer;', 'title' => addslashes($GLOBALS['Language']->getText('tracker_include_artifact', 'toggle')))); $out .= '</span>\');</script>'; $out .= '<script type="text/javascript">'; $out .= "tracker_comment_togglers[" . (int) $comment_id . "] = function (evt, force, expand) {\n var toggle = \$('comment_" . (int) $comment_id . "_toggle');\n var element = \$('comment_" . (int) $comment_id . "_content');\n if (element) {\n if (!force || (expand && !element.visible()) || (!expand && element.visible())) {\n Element.toggle(element);\n \n //replace image\n var src_search = 'toggle_minus';\n var src_replace = 'toggle_plus';\n if (toggle.src.match('toggle_plus')) {\n src_search = 'toggle_plus';\n src_replace = 'toggle_minus';\n }\n toggle.src = toggle.src.replace(src_search, src_replace);\n }\n }\n if (evt) {\n Event.stop(evt);\n }\n return false;\n };\n Event.observe(\$('comment_" . (int) $comment_id . "_toggle'), 'click', tracker_comment_togglers[" . (int) $comment_id . "]);"; $out .= '</script>'; $out .= '<span><a href="#comment_' . (int) $comment_id . '" title="Link to this comment - #' . (int) $comment_id . '" onclick="tracker_comment_togglers[' . (int) $comment_id . '](null, true, true);">'; $out .= $GLOBALS['HTML']->getImage('ic/comment.png', array('border' => 0, 'style' => 'vertical-align:middle', 'title' => 'Link to this comment - #' . (int) $comment_id)); $out .= '</a> </span>'; $out .= '<span class="followup_comment_title_user">'; if (db_result($orig_subm, 0, 'mod_by') == 100) { $out .= db_result($orig_subm, 0, 'email'); } else { $out .= '<a href="/users/' . urlencode(user_getname(db_result($orig_subm, 0, 'mod_by'))) . '">' . $hp->purify($uh->getDisplayNameFromUserId(db_result($orig_subm, 0, 'mod_by')), CODENDI_PURIFIER_CONVERT_HTML) . '</a>'; } $out .= ' </span>'; $out .= '<span class="followup_comment_title_date">'; $out .= html_time_ago(db_result($orig_date, 0, 'date')); $out .= '</span>'; if ($field_name != "comment") { $out .= " (" . $GLOBALS['Language']->getText('tracker_include_artifact', 'last_edited') . " "; $out .= '<span class="followup_comment_title_edited_user">'; if (db_result($result, $i, 'mod_by') == 100) { $out .= db_result($result, $i, 'email'); } else { $out .= '<a href="/users/' . urlencode(user_getname(db_result($result, $i, 'mod_by'))) . '">' . $hp->purify(user_getname(db_result($result, $i, 'mod_by')), CODENDI_PURIFIER_CONVERT_HTML) . '</a>'; } $out .= ' </span>'; $out .= '<span class="followup_comment_title_date">'; $out .= html_time_ago(db_result($result, $i, 'date')); $out .= '</span>' . ")"; } $out .= "\n</div><!-- followup_comment_title -->\n"; $out .= '<div class="followup_comment_title_toolbar">'; if (db_result($orig_subm, 0, 'mod_by') == 100) { $user_quoted = db_result($orig_subm, 0, 'email'); } else { $user_quoted = $uh->getDisplayNameFromUserId(db_result($orig_subm, 0, 'mod_by')); } $user_quoted = addslashes(addslashes($user_quoted)); if ($pv == 0) { $out .= '<script type="text/javascript">document.write(\'<a href="#quote" onclick="tracker_quote_comment(\\\'' . $user_quoted . '\\\', \\\'' . (int) $comment_id . '\\\'); return false;" title="quote">'; $out .= $GLOBALS['HTML']->getImage('ic/quote.png', array('border' => 0, 'alt' => 'quote')); $out .= '</a>\');</script>'; } if ($this->userCanEditFollowupComment($comment_id) && !$pv) { $out .= '<a href="/tracker/?func=editcomment&group_id=' . (int) $group_id . '&aid=' . (int) $this->getID() . '&atid=' . (int) $group_artifact_id . '&artifact_history_id=' . (int) $comment_id . '" title="' . $GLOBALS['Language']->getText('tracker_fieldeditor', 'edit') . '">'; $out .= $GLOBALS['HTML']->getImage('ic/edit.png', array('border' => 0, 'alt' => $GLOBALS['Language']->getText('tracker_fieldeditor', 'edit'))); $out .= '</a>'; $out .= '<a href="/tracker/?func=delete_comment&group_id=' . (int) $group_id . '&aid=' . (int) $this->getID() . '&atid=' . (int) $group_artifact_id . '&artifact_history_id=' . (int) $comment_id . '" '; $out .= ' onClick="return confirm(\'' . $GLOBALS['Language']->getText('tracker_include_artifact', 'delete_comment') . '\')" title="' . $GLOBALS['Language']->getText('tracker_include_artifact', 'del') . '">'; $out .= $GLOBALS['HTML']->getImage('ic/close.png', array('border' => 0, 'alt' => $GLOBALS['Language']->getText('tracker_include_artifact', 'del'))); $out .= '</a>'; } $out .= "\n</div><!-- followup_comment_title_toolbar -->\n"; $out .= '<div style="clear:both;"></div>'; $out .= "\n</div><!-- followup_comment_header -->\n"; $out .= '<div class="followup_comment_content" ' . $style . ' id="comment_' . (int) $comment_id . '_content">'; if ($comment_type != "") { $out .= '<div class="followup_comment_content_type"><b>' . $hp->purify($comment_type, CODENDI_PURIFIER_CONVERT_HTML) . '</b></div>'; } $out .= $this->formatFollowUp($group_id, $isHtml, $value, $output); $out .= '</div>'; $out .= '</div>'; $out .= '<script type="text/javascript"> if (linked_comment_id == ' . (int) $comment_id . ') { tracker_comment_togglers[' . (int) $comment_id . '](null, true, true); } </script>'; } } if ($output == self::OUTPUT_BROWSER) { if ($rows > 0) { $out .= '<div style="text-align:right">'; $out .= '<a href="#expand_all" onclick="tracker_expand_all_comments(); return false;">' . $Language->getText('tracker_include_artifact', 'expand_all') . '</a> | <a href="#expand_all" onclick="tracker_collapse_all_comments(); return false;">' . $Language->getText('tracker_include_artifact', 'collapse_all') . '</a></div>'; } } // final touch... $out .= $output != self::OUTPUT_BROWSER ? $GLOBALS['sys_lf'] : ""; return $out; }
/** * Export muc logs of project $group_id * using monitoring openfire's plugin */ function export_muc_logs() { $request = HTTPRequest::instance(); $group_id = $request->get('group_id'); $pm = ProjectManager::instance(); $project = $pm->getProject($group_id); $any = $GLOBALS['Language']->getText('global', 'any'); if ($request->exist('log_start_date')) { $start_date = $request->get('log_start_date'); if ($start_date == '') { $start_date = $any; } } else { $week_ago = mktime(0, 0, 0, date("m"), date("d") - 7, date("Y")); $start_date = date("Y-m-d", $week_ago); } $end_date = $request->get('log_end_date'); if ($end_date == '') { $end_date = $any; } $mclm = IMMucLogManager::getMucLogManagerInstance(); $conversations = null; try { if ($start_date == $any && $end_date == $any) { $conversations = $mclm->getLogsByGroupName($project->getUnixName(true)); } elseif ($start_date == $any && $end_date != $any) { $conversations = $mclm->getLogsByGroupNameBeforeDate($project->getUnixName(true), $end_date); } elseif ($start_date != $any && $end_date == $any) { $conversations = $mclm->getLogsByGroupNameAfterDate($project->getUnixName(true), $start_date); } else { $conversations = $mclm->getLogsByGroupNameBetweenDates($project->getUnixName(true), $start_date, $end_date); } } catch (Exception $e) { echo $e->getMessage(); } $eol = "\n"; $col_list = array('date', 'nickname', 'message'); $lbl_list = array('date' => $GLOBALS['Language']->getText('plugin_im', 'muc_logs_time'), 'nickname' => $GLOBALS['Language']->getText('plugin_im', 'muc_logs_user'), 'message' => $GLOBALS['Language']->getText('plugin_im', 'muc_logs_message')); $purifier = Codendi_HTMLPurifier::instance(); $uh = new UserHelper(); $file_name = 'muc_logs_' . $project->getUnixName(); header('Content-Type: text/csv'); header('Content-Disposition: filename=' . $file_name . '.csv'); if (!$conversations || sizeof($conversations) == 0) { echo $GLOBALS['Language']->getText('plugin_im', 'no_muc_logs'); } else { // Build CSV header foreach ($lbl_list as $k => $v) { $lbl_list[$k] = SimpleSanitizer::unsanitize($v); } echo build_csv_header($col_list, $lbl_list) . $eol; // Build CSV content foreach ($conversations as $conv) { $time = format_date(util_get_user_preferences_export_datefmt(), $conv->getTimestamp()); if ($conv->getNickname() != null) { $nick = $conv->getNickname(); } else { $nick = ''; } $message = $conv->getMessage(); echo build_csv_record($col_list, array('date' => $time, 'nickname' => $nick, 'message' => $message)) . $eol; } } }
/** * Prepare the column values in the artifact record * * @param ArtifactType (tracker) $at the tracker the artifact to prepare blelong to * @param array{ArtifactField} $fields the fields of the artifact to export * @param int $group_artifact_id the tracker ID * @param array $record array 'field_name' => 'field_value' * @param string $export type of export ('csv' or 'database' : for date format, csv will take user preference, wheareas for database the format will be mysql format.) */ function prepare_artifact_record($at, $fields, $group_artifact_id, &$record, $export) { global $datetime_fmt, $sys_lf, $Language; /* $record: Input: a row from the artifact table (passed by reference. Output: the same row with values transformed for export */ reset($fields); $line = ''; while (list(, $field) = each($fields)) { if ($field->isSelectBox() || $field->isMultiSelectBox()) { $values = array(); if ($field->isStandardField()) { $values[] = $record[$field->getName()]; } else { $values = $field->getValues($record['artifact_id']); } $label_values = $field->getLabelValues($group_artifact_id, $values); $record[$field->getName()] = SimpleSanitizer::unsanitize(join(",", $label_values)); } else { if ($field->isTextArea() || $field->isTextField() && $field->getDataType() == $field->DATATYPE_TEXT) { // all text fields converted from HTML to ASCII $record[$field->getName()] = prepare_textarea($record[$field->getName()]); } else { if ($field->isDateField()) { // replace the date fields (unix time) with human readable dates that // is also accepted as a valid format in future import if ($record[$field->getName()] == '') { // if date undefined then set datetime to 0. Ideally should // NULL as well but if we pass NULL it is interpreted as a string // later in the process $record[$field->getName()] = '0'; } else { if ($export == 'database') { $record[$field->getName()] = format_date($datetime_fmt, $record[$field->getName()]); } else { $record[$field->getName()] = format_date(util_get_user_preferences_export_datefmt(), $record[$field->getName()]); } } } else { if ($field->isFloat()) { $record[$field->getName()] = number_format($record[$field->getName()], 2); } } } } } // Follow ups $ah = new ArtifactHtml($at, $record['artifact_id']); $sys_lf_sav = $sys_lf; $sys_lf = "\n"; $record['follow_ups'] = $ah->showFollowUpComments($at->Group->getID(), true, Artifact::OUTPUT_EXPORT); $sys_lf = $sys_lf_sav; // Dependencies $result = $ah->getDependencies(); $rows = db_numrows($result); $dependent = ''; for ($i = 0; $i < $rows; $i++) { $dependent_on_artifact_id = db_result($result, $i, 'is_dependent_on_artifact_id'); $dependent .= $dependent_on_artifact_id . ","; } $record['is_dependent_on'] = $dependent !== '' ? substr($dependent, 0, strlen($dependent) - 1) : $Language->getText('global', 'none'); //CC $cc_list = $ah->getCCList(); $rows = db_numrows($cc_list); $cc = array(); for ($i = 0; $i < $rows; $i++) { $cc_email = db_result($cc_list, $i, 'email'); $cc[] = $cc_email; } $record['cc'] = implode(',', $cc); }
public function toCSV() { $output = $this->gatherPermissions(); $sep = get_csv_separator(); $date = util_timestamp_to_userdateformat($_SERVER['REQUEST_TIME'], true); $filename = 'export_permissions_' . $this->group->getUnixName() . '_' . $date . '.csv'; header('Content-Disposition: filename=' . $filename); header('Content-Type: text/csv'); // Context echo $GLOBALS['Language']->getText('plugin_docman', 'format_export_project') . $sep . tocsv($this->group->getPublicName(), $sep) . $sep . tocsv($this->group->getUnixName(), $sep) . $sep . $this->group->getId() . PHP_EOL; echo $GLOBALS['Language']->getText('plugin_docman', 'format_export_date') . $sep . format_date(util_get_user_preferences_export_datefmt(), $_SERVER['REQUEST_TIME']) . PHP_EOL; echo PHP_EOL; // Datas echo $GLOBALS['Language']->getText('plugin_docman', 'format_id') . $sep; echo $GLOBALS['Language']->getText('plugin_docman', 'format_path') . $sep; echo $GLOBALS['Language']->getText('plugin_docman', 'format_type') . $sep; foreach ($this->getUgroups() as $id => $name) { echo $name . $sep; } echo PHP_EOL; foreach ($output as $itemid => $row) { echo $itemid . $sep; echo tocsv($row['title'], $sep) . $sep; echo $this->itemTypeToString($row['type']) . $sep; foreach ($this->getUgroups() as $id => $name) { if (isset($row[$id])) { $this->itemPermToString($row[$id]); } echo $sep; } echo PHP_EOL; } }