/** * render a requirement as HTML code for printing * * @author Andreas Simon * * @param resource $db * @param array $node the node to be printed * @param array $options * displayDates: true display creation and last edit date (including hh:mm:ss) * * @param string $tocPrefix Prefix to be printed in TOC before title of node * @param int $level * @param int $tprojectID * * @return string $output HTML Code * * @internal revisions * */ function renderReqForPrinting(&$db, $node, &$options, $tocPrefix, $reqLevel, $tprojectID) { static $tableColspan; static $firstColWidth; static $labels; static $title_separator; static $req_mgr; static $tplan_mgr; static $req_cfg; static $req_spec_cfg; static $decodeReq; static $force = null; static $basehref; if (!$req_mgr) { $basehref = $_SESSION['basehref']; $req_cfg = config_get('req_cfg'); $req_spec_cfg = config_get('req_spec_cfg'); $firstColWidth = '20%'; $tableColspan = 2; $labels = array('requirement' => 'requirement', 'status' => 'status', 'scope' => 'scope', 'type' => 'type', 'author' => 'author', 'relations' => 'relations', 'not_aplicable' => 'not_aplicable', 'coverage' => 'coverage', 'last_edit' => 'last_edit', 'custom_field' => 'custom_field', 'relation_project' => 'relation_project', 'related_tcs' => 'related_tcs', 'version' => 'version', 'revision' => 'revision', 'attached_files' => 'attached_files'); $labels = init_labels($labels); $decodeReq = array(); $decodeReq['status'] = init_labels($req_cfg->status_labels); $decodeReq['type'] = init_labels($req_cfg->type_labels); $force['displayVersion'] = isset($options['displayVersion']) ? $options['displayVersion'] : false; $force['displayLastEdit'] = isset($options['displayLastEdit']) ? $options['displayLastEdit'] : false; $title_separator = config_get('gui_title_separator_1'); $req_mgr = new requirement_mgr($db); $tplan_mgr = new testplan($db); } $versionID = isset($node['version_id']) ? intval($node['version_id']) : requirement_mgr::LATEST_VERSION; $revision = isset($node['revision']) ? intval($node['revision']) : null; $getOpt = array('renderImageInline' => true); if (is_null($revision)) { // will get last revision of requested req version $dummy = $req_mgr->get_by_id($node['id'], $versionID, 1, $getOpt); } else { $dummy = $req_mgr->get_version_revision($versionID, array('number' => $revision), $getOpt); if (!is_null($dummy)) { // do this way instead of using SQL alias on get_version_revision(), in order // to avoid issues (potential not confirmed)on different DBMS. $dummy[0]['id'] = $dummy[0]['req_id']; } } $req = $dummy[0]; // update with values got from req, this is needed if user did not provide it $versionID = $req['version_id']; $revision = $req['revision']; $name = htmlspecialchars($req["req_doc_id"] . $title_separator . $req['title']); // change table style in case of single req printing to not be indented $table_style = ""; if (isset($options['docType']) && $options['docType'] == SINGLE_REQ) { $table_style = "style=\"margin-left: 0;\""; } $output = "<table class=\"req\" {$table_style}><tr><th colspan=\"{$tableColspan}\">" . "<span class=\"label\">{$labels['requirement']}:</span> " . $name . "</th></tr>\n"; if ($force['displayVersion']) { foreach (array('version', 'revision') as $key) { $output .= '<tr><td valign="top">' . '<span class="label">' . $labels[$key] . ':</span></td>' . '<td>' . $req[$key] . "</td></tr>\n"; } } if ($options['toc']) { $options['tocCode'] .= '<p style="padding-left: ' . 15 * $reqLevel . 'px;"><a href="#' . prefixToHTMLID('req' . $node['id']) . '">' . $name . '</a></p>'; $output .= '<a name="' . prefixToHTMLID('req' . $node['id']) . '"></a>'; } if ($options['req_author']) { $output .= '<tr><td valign="top">' . '<span class="label">' . $labels['author'] . ':</span></td>' . '<td>' . htmlspecialchars(gendocGetUserName($db, $req['author_id'])); if (isset($options['displayDates']) && $options['displayDates']) { $dummy = null; $output .= ' - ' . localize_dateOrTimeStamp(null, $dummy, 'timestamp_format', $req['creation_ts']); } $output .= "</td></tr>\n"; if ($req['modifier_id'] > 0) { // add updater if available and differs from author OR forced if ($force['displayLastEdit'] || $req['modifier_id'] != $req['modifier_id']) { $output .= '<tr><td valign="top">' . '<span class="label">' . $labels['last_edit'] . ':</span></td>' . '<td>' . htmlspecialchars(gendocGetUserName($db, $req['modifier_id'])); if (isset($options['displayDates']) && $options['displayDates']) { $dummy = null; $output .= ' - ' . localize_dateOrTimeStamp(null, $dummy, 'timestamp_format', $req['modification_ts']); } $output .= "</td></tr>\n"; } } } foreach (array('status', 'type') as $key) { if ($options['req_' . $key]) { $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels[$key] . "</span></td>" . "<td>" . $decodeReq[$key][$req[$key]] . "</td></tr>"; } } if ($options['req_coverage']) { $current = count($req_mgr->get_coverage($req['id'])); $expected = $req['expected_coverage']; $coverage = $labels['not_aplicable'] . " ({$current}/0)"; if ($expected) { $percentage = round(100 / $expected * $current, 2); $coverage = "{$percentage}% ({$current}/{$expected})"; } $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['coverage'] . "</span></td>" . "<td>{$coverage}</td></tr>"; } if ($options['req_scope']) { $output .= "<tr><td colspan=\"{$tableColspan}\"> <br/>" . $req['scope'] . "</td></tr>"; } if ($options['req_relations']) { $relations = $req_mgr->get_relations($req['id']); if ($relations['num_relations']) { $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['relations'] . "</span></td><td>"; $filler = str_repeat(' ', 5); // MAGIC allowed foreach ($relations['relations'] as $rel) { $output .= "{$rel['type_localized']}: <br/>{$filler}" . htmlspecialchars($rel['related_req']['req_doc_id']) . $title_separator . htmlspecialchars($rel['related_req']['title']) . "</br>" . "{$filler}{$labels['status']}: " . "{$decodeReq['status'][$rel['related_req']['status']]} <br/>"; if ($req_cfg->relations->interproject_linking) { $output .= "{$filler}{$labels['relation_project']}: " . htmlspecialchars($rel['related_req']['testproject_name']) . " <br/>"; } } $output .= "</td></tr>"; } } if ($options['req_linked_tcs']) { $req_coverage = $req_mgr->get_coverage($req['id']); if (count($req_coverage)) { $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['related_tcs'] . "</span></td>" . "<td>"; foreach ($req_coverage as $tc) { $output .= htmlspecialchars($tc['tc_external_id'] . $title_separator . $tc['name']) . "<br/>"; } $output .= "</td></tr>"; } } if ($options['req_cf']) { $childID = is_null($revision) || $req['revision_id'] < 0 ? $req['version_id'] : $req['revision_id']; $linked_cf = $req_mgr->get_linked_cfields($req['id'], $childID); if ($linked_cf) { foreach ($linked_cf as $key => $cf) { $cflabel = htmlspecialchars($cf['label']); $value = htmlspecialchars($cf['value']); $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $cflabel . "</span></td>" . "<td>{$value}</td></tr>"; } } } // Display Images Inline (Always) $attachSet = $req_mgr->getAttachmentInfos($req['id']); if (count($attachSet)) { $output .= "<tr><td width=\"{$firstColWidth}\"><span class=\"label\">" . $labels['attached_files'] . "</span></td><td>"; foreach ($attachSet as $fitem) { if ($fitem['is_image']) { $output .= "<li>" . htmlspecialchars($fitem['file_name']) . "</li>"; $output .= '<li>' . '<img src="' . $basehref . 'lib/attachments/attachmentdownload.php?skipCheck=1&id=' . $fitem['id'] . '">'; } else { $output .= '<li>' . '<a href="' . $basehref . 'lib/attachments/attachmentdownload.php?skipCheck=1&id=' . $fitem['id'] . '" ' . ' target="#blank" > ' . htmlspecialchars($fitem['file_name']) . '</a>'; } } $output .= "</td></tr>"; } $output .= "</table><br/>"; return $output; }
/** * * */ function initialize_gui(&$dbHandler, $argsObj) { $tproject_mgr = new testproject($dbHandler); $req_mgr = new requirement_mgr($dbHandler); $commandMgr = new reqCommands($dbHandler); $gui = $commandMgr->initGuiBean(); $gui->refreshTree = $argsObj->refreshTree; $gui->req_cfg = config_get('req_cfg'); $gui->tproject_id = $argsObj->tproject_id; $gui->tproject_name = $argsObj->tproject_name; $gui->grants = new stdClass(); $gui->grants->req_mgmt = $argsObj->user->hasRight($dbHandler, "mgt_modify_req", $argsObj->tproject_id); // IMPORTANT NOTICE // We can arrive here after following operation // 1. user click on left pane tree on REQ SPEC NODE // 2. on right pane screen user click on CREATE button on Requirements Operations // 3. on new screen user CLICK CANCEL // In this situation $argsObj->req_id is 0 OR EMPTY $gui->req_id = $argsObj->req_id; if ($gui->req_id <= 0) { // Quick Exit // is not too clear why do not need to add lib/requirements/ on target $target = "reqSpecView.php?tproject_id={$gui->tproject_id}" . "&req_spec_id={$argsObj->req_spec_id}"; header("Location: {$target}"); exit; } // everything is fine - standard processing $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($argsObj->tproject_id); $gui->glueChar = config_get('testcase_cfg')->glue_character; $gui->pieceSep = config_get('gui_title_separator_1'); /* if wanted, show only the given version */ $gui->version_option = $argsObj->req_version_id ? $argsObj->req_version_id : requirement_mgr::ALL_VERSIONS; $gui->req_versions = $req_mgr->get_by_id($gui->req_id, $gui->version_option); $gui->req_has_history = count($req_mgr->get_history($gui->req_id, array('output' => 'array'))) > 1; $gui->req = current($gui->req_versions); $gui->req_coverage = $req_mgr->get_coverage($gui->req_id); // This seems weird but is done to adapt template than can display multiple // requirements. This logic has been borrowed from test case versions management $gui->current_version[0] = array($gui->req); $gui->cfields_current_version[0] = $req_mgr->html_table_of_custom_field_values($gui->req_id, $gui->req['version_id'], $argsObj->tproject_id); // Now CF for other Versions $gui->other_versions[0] = null; $gui->cfields_other_versions[] = null; if (count($gui->req_versions) > 1) { $gui->other_versions[0] = array_slice($gui->req_versions, 1); $loop2do = count($gui->other_versions[0]); for ($qdx = 0; $qdx < $loop2do; $qdx++) { $target_version = $gui->other_versions[0][$qdx]['version_id']; $gui->cfields_other_versions[0][$qdx] = $req_mgr->html_table_of_custom_field_values($gui->req_id, $target_version, $argsObj->tproject_id); } } $gui->show_title = false; $gui->main_descr = lang_get('req') . $gui->pieceSep . $gui->req['title']; $gui->showReqSpecTitle = $argsObj->showReqSpecTitle; if ($gui->showReqSpecTitle) { $gui->parent_descr = lang_get('req_spec_short') . $gui->pieceSep . $gui->req['req_spec_title']; } $gui->attachments[$gui->req_id] = $req_mgr->getAttachmentInfos($gui->req_id); $gui->attachmentTableName = $req_mgr->getAttachmentTableName(); $gui->reqStatus = init_labels($gui->req_cfg->status_labels); $gui->reqTypeDomain = init_labels($gui->req_cfg->type_labels); // added req relations for BUGID 1748 $gui->req_relations = FALSE; $gui->req_relation_select = FALSE; $gui->testproject_select = FALSE; $gui->req_add_result_msg = isset($argsObj->relation_add_result_msg) ? $argsObj->relation_add_result_msg : ""; if ($gui->req_cfg->relations->enable) { $gui->req_relations = $req_mgr->get_relations($gui->req_id); $gui->req_relation_select = $req_mgr->init_relation_type_select(); if ($gui->req_cfg->relations->interproject_linking) { $gui->testproject_select = initTestprojectSelect($argsObj->userID, $argsObj->tproject_id, $tproject_mgr); } } return $gui; }