Beispiel #1
0
/**
 * 
 *
 */
function initialize_gui(&$dbHandler, $argsObj)
{
    $tproject_mgr = new testproject($dbHandler);
    $req_mgr = new requirement_mgr($dbHandler);
    $commandMgr = new reqCommands($db);
    $gui = $commandMgr->initGuiBean();
    $gui->req_cfg = config_get('req_cfg');
    $gui->tproject_name = $argsObj->tproject_name;
    $gui->grants = new stdClass();
    $gui->grants->req_mgmt = has_rights($db, "mgt_modify_req");
    $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($argsObj->tproject_id);
    $gui->glueChar = config_get('testcase_cfg')->glue_character;
    $gui->pieceSep = config_get('gui_title_separator_1');
    $gui->req_id = $argsObj->req_id;
    $gui->req_versions = $req_mgr->get_by_id($gui->req_id);
    $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);
    // BUGID 2877 - Custom Fields linked to Requirement Versions
    $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'];
    }
    // BUGID 2877 - Custom Fields linked to Requirement Versions
    // $gui->cfields = array();
    // $gui->cfields[] = $req_mgr->html_table_of_custom_field_values($gui->req_id,$argsObj->tproject_id);
    $gui->attachments[$gui->req_id] = getAttachmentInfosFrom($req_mgr, $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($db, $argsObj, $tproject_mgr);
        }
    }
    return $gui;
}
 /**
  * get analyse based on requirements and test specification
  *
  * @param integer $id: Req Spec id
  * @return array Coverage in three internal arrays: covered, uncovered, nottestable REQ
  * @author martin havlat
  */
 function get_coverage($id)
 {
     $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
     $req_mgr = new requirement_mgr($this->db);
     // $statusFilter = " AND status IN('" . strtoupper(VALID_REQ)."','".VALID_REQ."') ";
     // $order_by = " ORDER BY req_doc_id,title";
     $output = array('covered' => array(), 'uncovered' => array(), 'nottestable' => array());
     // function get_requirements($id, $range = 'all', $testcase_id = null, $options=null, $filters = null)
     $getOptions = array('order_by' => " ORDER BY req_doc_id,title");
     $getFilters = array('status' => VALID_REQ);
     $validReq = $this->get_requirements($id, 'all', null, $getOptions, $getFilters);
     // get not-testable requirements
     $getFilters = array('status' => NON_TESTABLE_REQ);
     $output['nottestable'] = $this->get_requirements($id, 'all', null, $getOptions, $getFilters);
     // get coverage
     if (sizeof($validReq)) {
         foreach ($validReq as $req) {
             // collect TC for REQ
             $arrCoverage = $req_mgr->get_coverage($req['id']);
             if (count($arrCoverage) > 0) {
                 // add information about coverage
                 $req['coverage'] = $arrCoverage;
                 $output['covered'][] = $req;
             } else {
                 $output['uncovered'][] = $req;
             }
         }
     }
     return $output;
 }
Beispiel #3
0
/**
 * 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, $level, $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;
    if (!$req_mgr) {
        $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');
        $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;
    if (is_null($revision)) {
        // will get last revision of requested req version
        $dummy = $req_mgr->get_by_id($node['id'], $versionID);
    } else {
        $dummy = $req_mgr->get_version_revision($versionID, array('number' => $revision));
        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']);
    $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 * $level . '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('&nbsp;', 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>";
            }
        }
    }
    $output .= "</table><br/>";
    return $output;
}
Beispiel #4
0
$req_ids = $tproject_mgr->get_all_requirement_ids($args->tproject_id);
$req_spec_map = array();
$tc_ids = array();
$testcases = array();
// first step: get the requirements and linked testcases with which we have to work,
// order them into $req_spec_map by spec
if (count($req_ids)) {
    foreach ($req_ids as $id) {
        // get the information for this requirement
        $req = $req_mgr->get_by_id($id, requirement_mgr::LATEST_VERSION);
        $req_info = $req[0];
        $spec_id = $req_info['srs_id'];
        // if req is "usable" (either finished status or all requested) add it
        if (!$args->show_only_finished || $req_info['status'] == TL_REQ_STATUS_FINISH) {
            // coverage data
            $linked_tcs = (array) $req_mgr->get_coverage($id);
            $req_info['linked_testcases'] = $linked_tcs;
            if (!isset($req_spec_map[$spec_id])) {
                $spec_info = $req_spec_mgr->get_by_id($spec_id);
                $req_spec_map[$spec_id] = $spec_info;
                $req_spec_map[$spec_id]['requirements'] = array();
            }
            $req_spec_map[$spec_id]['requirements'][$id] = $req_info;
            foreach ($linked_tcs as $tc) {
                $tc_ids[] = $tc['id'];
            }
        }
    }
    // BUGID 3439
    if (!count($req_spec_map)) {
        $gui->warning_msg = lang_get($no_finished_reqs_msg_key);
Beispiel #5
0
$gui->reqIDs = $tproject_mgr->get_all_requirement_ids($args->tproject_id);
if (count($gui->reqIDs) > 0) {
    // get type and status labels
    $type_labels = init_labels($req_cfg->type_labels);
    $status_labels = init_labels($req_cfg->status_labels);
    $labels2get = array('no' => 'No', 'yes' => 'Yes', 'not_aplicable' => null, 'req_spec_short' => null, 'title' => null, 'version' => null, 'th_coverage' => null, 'frozen' => null, 'type' => null, 'status' => null, 'th_relations' => null, 'requirements' => null, 'number_of_reqs' => null, 'number_of_versions' => null);
    $labels = init_labels($labels2get);
    $gui->cfields4req = (array) $cfield_mgr->get_linked_cfields_at_design($args->tproject_id, 1, null, 'requirement', null, 'name');
    $version_option = $args->all_versions ? requirement_mgr::ALL_VERSIONS : requirement_mgr::LATEST_VERSION;
    // array to gather table data row per row
    $rows = array();
    foreach ($gui->reqIDs as $id) {
        // now get the rest of information for this requirement
        $req = $req_mgr->get_by_id($id, $version_option);
        // coverage data
        $tc_coverage = count($req_mgr->get_coverage($id));
        // number of relations, if feature is enabled
        if ($relations_enabled) {
            $relations = $req_mgr->count_relations($id);
            $relations = "<!-- " . sprintf("%010d", $relations) . " -->" . $relations;
        }
        // create the link to display
        $title = htmlentities($req[0]['req_doc_id'], ENT_QUOTES, $charset) . $glue_char . htmlentities($req[0]['title'], ENT_QUOTES, $charset);
        // add html comment with title for easier sorting
        $linked_title = '<!-- ' . $title . ' -->' . '<a href="javascript:openLinkedReqWindow(' . $id . ')">' . $title . '</a>';
        // reqspec-"path" to requirement
        $path = $req_mgr->tree_mgr->get_path($req[0]['srs_id']);
        foreach ($path as $key => $p) {
            $path[$key] = $p['name'];
        }
        $path = htmlentities(implode("/", $path), ENT_QUOTES, $charset);
Beispiel #6
0
/**
 * 
 *
 */
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;
}
Beispiel #7
0
/**
 * render a requirement as HTML code for printing
 * 
 * @author Andreas Simon
 * 
 * @param resource $db
 * @param array $node the node to be printed
 * @param array $printingOptions
 * @param string $tocPrefix Prefix to be printed in TOC before title of node
 * @param int $level
 * @param int $tprojectID
 * 
 * @return string $output HTML Code
 */
function renderRequirementNodeForPrinting(&$db, $node, &$printingOptions, $tocPrefix, $level, $tprojectID)
{
    static $tableColspan;
    static $firstColWidth;
    static $labels;
    static $title_separator;
    static $req_mgr;
    static $tplan_mgr;
    static $req_cfg;
    static $req_spec_cfg;
    static $reqStatusLabels;
    static $reqTypeLabels;
    if (!$req_mgr) {
        $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', 'coverage' => 'coverage', 'custom_field' => 'custom_field', 'relation_project' => 'relation_project', 'related_tcs' => 'related_tcs');
        $labels = init_labels($labels);
        $reqStatusLabels = init_labels($req_cfg->status_labels);
        $reqTypeLabels = init_labels($req_cfg->type_labels);
        $title_separator = config_get('gui_title_separator_1');
        $req_mgr = new requirement_mgr($db);
        $tplan_mgr = new testplan($db);
    }
    $arrReq = $req_mgr->get_by_id($node['id']);
    $req = $arrReq[0];
    $name = htmlspecialchars($req["req_doc_id"] . $title_separator . $req['title']);
    $output = "<table class=\"req\"><tr><th colspan=\"{$tableColspan}\">" . "<span class=\"label\">{$labels['requirement']}:</span> " . $name . "</th></tr>\n";
    if ($printingOptions['toc']) {
        $printingOptions['tocCode'] .= '<p style="padding-left: ' . 15 * $level . 'px;"><a href="#' . prefixToHTMLID('req' . $node['id']) . '">' . $name . '</a></p>';
        $output .= '<a name="' . prefixToHTMLID('req' . $node['id']) . '"></a>';
    }
    if ($printingOptions['req_author']) {
        $author = tlUser::getById($db, $req['author_id']);
        $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['author'] . "</span></td><td> " . htmlspecialchars($author->getDisplayName()) . "</td></tr>\n";
    }
    if ($printingOptions['req_status']) {
        $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['status'] . "</span></td>" . "<td>" . $reqStatusLabels[$req['status']] . "</td></tr>";
    }
    if ($printingOptions['req_type']) {
        $output .= '<tr><td width="' . $firstColWidth . '"><span class="label">' . $labels['type'] . "</span></td>" . "<td>" . $reqTypeLabels[$req['type']] . "</td></tr>";
    }
    if ($printingOptions['req_coverage']) {
        $current = count($req_mgr->get_coverage($req['id']));
        $expected = $req['expected_coverage'];
        $coverage = lang_get('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 ($printingOptions['req_scope']) {
        $output .= "<tr><td colspan=\"{$tableColspan}\"><span class=\"label\">" . $labels['scope'] . "</span><br/>" . $req['scope'] . "</td></tr>";
    }
    if ($printingOptions['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>";
            foreach ($relations['relations'] as $rel) {
                $output .= "{$rel['type_localized']}: <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . htmlspecialchars($rel['related_req']['req_doc_id']) . $title_separator . htmlspecialchars($rel['related_req']['title']) . "</br>" . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$labels['status']}: " . "{$reqStatusLabels[$rel['related_req']['status']]} <br/>";
                if ($req_cfg->relations->interproject_linking) {
                    $output .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$labels['relation_project']}: " . htmlspecialchars($rel['related_req']['testproject_name']) . " <br/>";
                }
            }
            $output .= "</td></tr>";
        }
    }
    if ($printingOptions['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 .= htmlentities($tc['tc_external_id'] . $title_separator . $tc['name']) . "<br/>";
            }
            $output .= "</td></tr>";
        }
    }
    if ($printingOptions['req_cf']) {
        //BUGID 2877 - Custom Fields linked to Req versions
        $linked_cf = $req_mgr->get_linked_cfields($req['id'], $req['version_id']);
        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>";
            }
        }
    }
    $output .= "</table><br/>";
    return $output;
}
/**
 * 
 *
 */
function initialize_gui(&$dbHandler, $argsObj, &$tproject_mgr)
{
    $req_mgr = new requirement_mgr($dbHandler);
    $commandMgr = new reqCommands($dbHandler);
    $gui = $commandMgr->initGuiBean();
    $gui->req_cfg = config_get('req_cfg');
    $gui->glueChar = config_get('testcase_cfg')->glue_character;
    $gui->pieceSep = config_get('gui_title_separator_1');
    $gui->refreshTree = $argsObj->refreshTree;
    $gui->tproject_name = $argsObj->tproject_name;
    $gui->req_id = $argsObj->req_id;
    /* 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, 1, array('renderImageInline' => true));
    $gui->reqHasBeenDeleted = false;
    if (is_null($gui->req_versions)) {
        // this means that requirement does not exist anymore.
        // We have to give just that info to user
        $gui->reqHasBeenDeleted = true;
        $gui->main_descr = lang_get('req_does_not_exist');
        unset($gui->show_match_count);
        return $gui;
        // >>>----> Bye!
    }
    $tproject_id = $req_mgr->getTestProjectID($argsObj->requirement_id);
    $target_id = $argsObj->tproject_id;
    if ($isAlien = $tproject_id != $argsObj->tproject_id) {
        $target_id = $tproject_id;
    }
    $gui->grants = new stdClass();
    $gui->grants->req_mgmt = $argsObj->user->hasRight($dbHandler, "mgt_modify_req", $target_id);
    $gui->grants->unfreeze_req = $argsObj->user->hasRight($dbHandler, "mgt_unfreeze_req", $target_id);
    $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($argsObj->tproject_id);
    $gui->req = current($gui->req_versions);
    $gui->req_coverage = $req_mgr->get_coverage($gui->req_id);
    $gui->direct_link = $_SESSION['basehref'] . 'linkto.php?tprojectPrefix=' . urlencode($gui->tcasePrefix) . '&item=req&id=' . urlencode($gui->req['req_doc_id']);
    $gui->fileUploadURL = $_SESSION['basehref'] . $req_mgr->getFileUploadRelativeURL($gui->req_id, $argsObj);
    $gui->delAttachmentURL = $_SESSION['basehref'] . $req_mgr->getDeleteAttachmentRelativeURL($gui->req_id);
    $gui->fileUploadMsg = '';
    $gui->import_limit = TL_REPOSITORY_MAXFILESIZE;
    $gui->log_target = null;
    $loop2do = count($gui->req_versions);
    for ($rqx = 0; $rqx < $loop2do; $rqx++) {
        $gui->log_target[] = $gui->req_versions[$rqx]['revision_id'] > 0 ? $gui->req_versions[$rqx]['revision_id'] : $gui->req_versions[$rqx]['version_id'];
    }
    $gui->req_has_history = count($req_mgr->get_history($gui->req_id, array('output' => 'array'))) > 1;
    // 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] = getAttachmentInfosFrom($req_mgr, $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);
    $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_relations['rw'] = !$isAlien;
        $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);
        }
    }
    $gui->user_feedback = $argsObj->user_feedback;
    return $gui;
}