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; } }
/** * Constructor of the class * * @param String $startDate Period start date * @param String $endDate Period end date * @param Integer $groupId Project Id * * @return void */ function __construct($startDate, $endDate, $groupId = null) { $this->separator = get_csv_separator(); $this->content = ''; $this->startDate = $startDate; $this->endDate = $endDate; $this->groupId = $groupId; $this->addEmptyLine(); }
function build_csv_record($col_list, $record) { $line = ''; reset($col_list); while (list(, $col) = each($col_list)) { $line .= tocsv($record[$col]) . get_csv_separator(); } $line = substr($line, 0, -1); return $line; }
} $pm = ProjectManager::instance(); $group = $pm->getProject($group_id); if (!$group || !is_object($group) || $group->isError()) { exit_no_group(); } $vExport = new Valid_WhiteList('export', array('user_groups', 'user_groups_format')); $vExport->required(); if ($request->valid($vExport)) { $export = $request->get('export'); $col_list = array('group', 'username', 'realname'); $lbl_list = array('group' => $GLOBALS['Language']->getText('project_export_user_groups', 'user_group'), 'username' => $GLOBALS['Language']->getText('project_export_user_groups', 'user_username', array($GLOBALS['sys_name'])), 'realname' => $GLOBALS['Language']->getText('project_export_user_groups', 'user_realname')); $um = UserManager::instance(); switch ($export) { case 'user_groups': $sep = get_csv_separator(); $eol = "\n"; $name = 'export_user_groups_' . $project->getUnixName() . '.csv'; header('Content-Disposition: filename=' . $name); header('Content-Type: text/csv'); echo build_csv_header($col_list, $lbl_list) . $eol; $ugs = ugroup_db_get_existing_ugroups($group_id, array($GLOBALS['UGROUP_PROJECT_MEMBERS'], $GLOBALS['UGROUP_PROJECT_ADMIN'])); while ($ugrp = db_fetch_array($ugs)) { if ($ugrp['ugroup_id'] <= 100) { $sqlUsers = ugroup_db_get_dynamic_members($ugrp['ugroup_id'], false, $group_id); } else { $sqlUsers = ugroup_db_get_members($ugrp['ugroup_id']); } $users = db_query($sqlUsers); while ($user = db_fetch_array($users)) { $r = array('group' => util_translate_name_ugroup($ugrp['name']), 'username' => $user['user_name'], 'realname' => $um->getUserById($user['user_id'])->getRealname());
} $groupId = null; $vGroupId = new Valid_GroupId(); $vGroupId->required(); if ($request->valid($vGroupId)) { $groupId = $request->get('group_id'); } if (!$error && $request->exist('export')) { $startDate = $request->get('start'); $endDate = $request->get('end'); header('Content-Type: text/csv'); header('Content-Disposition: filename=services_usage_' . $startDate . '_' . $endDate . '.csv'); echo "Start date : {$startDate} \n"; echo "End date : {$endDate} \n\n"; $dao = new Statistics_ServicesUsageDao(CodendiDataAccess::instance(), $startDate, $endDate); $csv_exporter = new Statistics_Services_UsageFormatter(new Statistics_Formatter($startDate, $endDate, get_csv_separator())); //Project admin $csv_exporter->buildDatas($dao->getIdsOfActiveProjectsBeforeEndDate(), "Project ID"); $csv_exporter->buildDatas($dao->getNameOfActiveProjectsBeforeEndDate(), "Project Name"); $csv_exporter->buildDatas($dao->getShortNameOfActiveProjectsBeforeEndDate(), "Project Short Name"); $csv_exporter->buildDatas($dao->getPrivacyOfActiveProjectsBeforeEndDate(), "Public Project"); $csv_exporter->buildDatas($dao->getDescriptionOfActiveProjectsBeforeEndDate(), "Description"); $csv_exporter->buildDatas($dao->getRegisterTimeOfActiveProjectsBeforeEndDate(), "Creation date"); $csv_exporter->buildDatas($dao->getInfosFromTroveGroupLink(), "Organization"); $csv_exporter->buildDatas($dao->getAdministrators(), "Created by"); $csv_exporter->buildDatas($dao->getAdministratorsRealNames(), "Created by (Real name)"); $csv_exporter->buildDatas($dao->getAdministratorsEMails(), "Created by (Email)"); $csv_exporter->buildDatas($dao->getNumberOfUserAddedBetweenStartDateAndEndDate(), "Users added"); //Custom Descriptions $custom_description_factory = new Project_CustomDescription_CustomDescriptionFactory(new Project_CustomDescription_CustomDescriptionDao()); $custom_description_value_dao = new Project_CustomDescription_CustomDescriptionValueDao();
/** * Constructor of the class * * @param String $scm 'svn' or 'cvs' * @param String $startDate Period start date * @param String $endDate Period end date * @param Integer $groupId Project Id * * @return void */ function __construct($scm, $startDate, $endDate, $groupId = null) { $this->scm = $scm; parent::__construct($startDate, $endDate, get_csv_separator(), $groupId); }
} $groupId = null; $vGroupId = new Valid_GroupId(); $vGroupId->required(); if ($request->valid($vGroupId)) { $groupId = $request->get('group_id'); } if (!$error && $request->exist('export')) { header('Content-Type: text/csv'); header('Content-Disposition: filename=scm_stats_' . $startDate . '_' . $endDate . '.csv'); $statsSvn = new Statistics_Formatter_Svn($startDate, $endDate, $groupId); echo $statsSvn->getStats(); $statsCvs = new Statistics_Formatter_Cvs($startDate, $endDate, $groupId); echo $statsCvs->getStats(); $em = EventManager::instance(); $params['formatter'] = new Statistics_Formatter($startDate, $endDate, get_csv_separator(), $groupId); $em->processEvent('statistics_collector', $params); exit; } else { $title = $GLOBALS['Language']->getText('plugin_statistics', 'scm_title'); $GLOBALS['HTML']->includeCalendarScripts(); $GLOBALS['HTML']->header(array('title' => $title)); echo '<h1>' . $title . '</h1>'; echo '<form name="form_scm_stats" method="get">'; echo '<table>'; echo '<tr>'; echo '<td>'; echo '<b>' . $GLOBALS['Language']->getText('plugin_statistics', 'start_date') . '</b>'; echo '</td><td>'; echo '<b>' . $GLOBALS['Language']->getText('plugin_statistics', 'end_date') . '</b>'; echo '</td><td>';
/** parse a file in csv format containing artifacts to be imported into the db * @param $csv_filename (IN): the complete file name of the cvs file to be parsed * @param $is_tmp (IN): true if cvs_file is only temporary file and we want to unlink it * after parsing * @param $artifacts (OUT): the artifacts with their field values parsed from the csv file * @return true if parse ok, false if errors occurred */ function parse($csv_filename, $is_tmp, &$artifacts_data, &$number_inserts, &$number_updates) { global $Language; $hp = Codendi_HTMLPurifier::instance(); $number_inserts = 0; $number_updates = 0; //avoid that lines with a length > 1000 will be truncated by fgetcsv $length = 1000; $array = file($csv_filename); for ($i = 0; $i < count($array); $i++) { if ($length < strlen($array[$i])) { $length = strlen($array[$i]); } } $length++; //unset($array); $csv_file = fopen($csv_filename, "r"); $row = 0; while ($data = fgetcsv($csv_file, $length, get_csv_separator())) { // do the real parsing here //parse the first line with all the field names if ($row == 0) { $ok = $this->parseFieldNames($data); if (!$ok) { return false; } // get already predefined values for fields $this->getPredefinedValues(); //parse artifact values } else { //verify whether this row contains enough values $num = count($data); if ($num != $this->num_columns) { $data_details = ""; foreach ($data as $key => $value) { if ($data_details != "") { $data_details .= ", "; } $data_details .= "[" . $this->parsed_labels[$key] . "] => {$value}"; } reset($data); $this->setError($Language->getText('plugin_tracker_import_utils', 'column_mismatch', array($row + 1, $hp->purify($data_details, CODENDI_PURIFIER_CONVERT_HTML), $num, $this->num_columns))); return FALSE; } // if no tracker_id given, create new artifacts if ($this->aid_column == -1) { $ok = $this->checkInsertArtifact($row, $data); $number_inserts++; // if tracker_id given, verify if it exists already //else send error } else { $aid = $data[$this->aid_column]; if ($aid != "") { $ok = $this->checkUpdateArtifact($row, $data, $aid); $number_updates++; } else { // have to create artifact from scratch $ok = $this->checkInsertArtifact($row, $data, true); $number_inserts++; } } if (!$ok) { return false; } else { $artifacts_data[] = $data; } } $row++; } fclose($csv_file); if ($is_tmp) { unlink($csv_filename); } return true; }