Example #1
0
 public function __construct()
 {
     $db = null;
     doDBConnect($db);
     parent::__construct($db);
     $this->object_table = $this->tables["users"];
 }
 /** 
  * class constructor 
  * 
  * @param resource &$db reference to database handler
  * @param integer $tplanId
  **/
 public function __construct(&$db, &$tplanId = null)
 {
     $this->db = $db;
     $this->testPlanID = $tplanId;
     // tlObjectWithDB::__construct($db);
     parent::__construct($this->db);
 }
/**
 * 
 *
 */
function getBareBonesReq($dbHandler, $reqID)
{
    $debugMsg = ' Function: ' . __FUNCTION__;
    $tables = tlObjectWithDB::getDBTables(array('requirements', 'nodes_hierarchy'));
    $sql = " /* {$debugMsg} */ SELECT REQ.req_doc_id, NH_REQ.name " . " FROM {$tables['requirements']} REQ " . " JOIN {$tables['nodes_hierarchy']} NH_REQ\tON  NH_REQ.id = REQ.id " . " WHERE REQ.id = " . intval($reqID);
    $bones = $dbHandler->get_recordset($sql);
    return $bones[0];
}
 /**
  * class constructor
  * 
  * @param $db [ref] resource the database connection
  */
 function __construct(&$db)
 {
     tlObjectWithDB::__construct($db);
     $this->repositoryType = self::getType();
     $this->repositoryCompressionType = self::getCompression();
     $this->repositoryPath = self::getPathToRepository();
     $this->attachmentCfg = config_get('attachments');
 }
 /**
  * class constructor
  * 
  * @param $db [ref] resource the database connection
  */
 function __construct(&$db)
 {
     tlObjectWithDB::__construct($db);
     $this->attachmentCfg = config_get('attachments');
     $prop2init = array('type', 'compressionType', 'path');
     foreach ($prop2init as $prop) {
         $this->{$prop} = $this->attachmentCfg->repository->{$prop};
     }
 }
Example #6
0
function doExport(&$dbHandler, $filename)
{
    $tables = tlObjectWithDB::getDBTables(array('custom_fields', 'cfield_node_types'));
    $adodbXML = new ADODB_XML("1.0", "ISO-8859-1");
    $sql = " SELECT name,label,type,possible_values,default_value,valid_regexp, " . " length_min,length_max,show_on_design,enable_on_design,show_on_execution," . " enable_on_execution,show_on_testplan_design,enable_on_testplan_design, " . " node_type_id,required " . " FROM {$tables['custom_fields']} CF,{$tables['cfield_node_types']} " . " WHERE CF.id=field_id ";
    $adodbXML->setRootTagName('custom_fields');
    $adodbXML->setRowTagName('custom_field');
    $content = $adodbXML->ConvertToXMLString($dbHandler->db, $sql);
    downloadContentsToFile($content, $filename);
    exit;
}
function doExport(&$dbHandler, $filename)
{
    $adodbXML = new ADODB_XML("1.0", "ISO-8859-1");
    $adodbXML->setRootTagName('users');
    $adodbXML->setRowTagName('user');
    $tables = tlObjectWithDB::getDBTables(array('users'));
    $fieldSet = 'id,login,role_id,email,first,last,locale,default_testproject_id,active';
    $sql = " SELECT {$fieldSet} FROM {$tables['users']} ";
    $content = $adodbXML->ConvertToXMLString($dbHandler->db, $sql);
    downloadContentsToFile($content, $filename);
    exit;
}
function doExport(&$db, $filename, $testproject_id)
{
    $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
    $tables = tlObjectWithDB::getDBTables(array('platforms'));
    $adodbXML = new ADODB_XML("1.0", "UTF-8");
    $sql = "/* {$debugMsg} */ SELECT name,notes " . " FROM {$tables['platforms']} PLAT " . " WHERE PLAT.testproject_id=" . intval($testproject_id);
    $adodbXML->setRootTagName('platforms');
    $adodbXML->setRowTagName('platform');
    $content = $adodbXML->ConvertToXMLString($db->db, $sql);
    downloadContentsToFile($content, $filename);
    exit;
}
 public function __construct(&$dbHandler)
 {
     $this->db = $dbHandler;
     $this->tprojectMgr = new testproject($dbHandler);
     $this->tables = tlObjectWithDB::getDBTables(array('tcversions', 'nodes_hierarchy', 'testplan_tcversions', 'cfield_design_values'));
     $this->cfg = new stdClass();
     $this->cfg->showTestCaseID = config_get('treemenu_show_testcase_id');
     $this->cfg->glueChar = config_get('testcase_cfg')->glue_character;
     $this->cfg->nodeTypeCode = $this->tprojectMgr->tree_manager->get_available_node_types();
     $this->cfg->nodeCodeType = array_flip($this->cfg->nodeTypeCode);
     $this->cfg->results = config_get('results');
     $this->cfg->renderTestSpecNode = new stdClass();
     $this->cfg->renderTestSpecNode->key2del = array_merge(array_keys($this->cfg->results['status_code']), array('node_type_id', 'parent_id', 'node_order', 'node_table', 'tcversion_id', 'external_id', 'version', 'testcase_count'));
 }
Example #10
0
/**
 * @internal revisions
 * 20121010 - asimon - TICKET 4353: added active/inactive filter
 */
function prepareTestSpecNode(&$db, &$tprojectMgr, $tprojectID, &$node, &$map_node_tccount, $filters = null, $options = null)
{
    static $status_descr_list;
    static $debugMsg;
    static $tables;
    static $my;
    static $filtersApplied;
    static $decoding_info;
    static $tcFilterByKeywords;
    static $doFilterOn;
    if (!$tables) {
        $debugMsg = 'Class: ' . __CLASS__ . ' - ' . 'Method: ' . __FUNCTION__ . ' - ';
        $tables = tlObjectWithDB::getDBTables(array('tcversions', 'nodes_hierarchy', 'testplan_tcversions'));
        $decoding_info = array('node_id_descr' => array_flip($tprojectMgr->tree_manager->get_available_node_types()));
        $my = array();
        $my['options'] = array('hideTestCases' => 0);
        $my['filters'] = array('keywords' => null);
        $my['options'] = array_merge($my['options'], (array) $options);
        $my['filters'] = array_merge($my['filters'], (array) $filters);
        if ($doFilterOn['keywords'] = !is_null($my['filters']['keywords'])) {
            $tcFilterByKeywords = $tprojectMgr->getTCasesFilteredByKeywords($tprojectID, $my['filters']['keywords'], $my['filters']['keywords_filter_type']);
            if (is_null($tcFilterByKeywords)) {
                // tree will be empty
                $node = null;
                $tcase_counters['testcase_count'] = 0;
                return $tcase_counters;
            }
        }
        // Critic for logic that prune empty branches
        // TICKET 4353: added active/inactive filter
        $filtersApplied = $doFilterOn['keywords'] || $my['options']['ignoreInactiveTestCases'] || $my['options']['ignoreActiveTestCases'];
    }
    $tcase_counters['testcase_count'] = 0;
    $node_type = isset($node['node_type_id']) ? $decoding_info['node_id_descr'][$node['node_type_id']] : null;
    if ($node_type == 'testcase') {
        $remove_node = false;
        if ($my['options']['ignoreInactiveTestCases']) {
            $sql = " SELECT COUNT(TCV.id) AS count_active_versions " . " FROM {$tables['tcversions']} TCV, {$tables['nodes_hierarchy']} NH " . " WHERE NH.parent_id=" . $node['id'] . " AND NH.id = TCV.id AND TCV.active=1";
            $result = $db->exec_query($sql);
            $row = $db->fetch_array($result);
            if ($row['count_active_versions'] == 0) {
                $remove_node = true;
            }
        } else {
            if ($my['options']['ignoreActiveTestCases']) {
                $sql = " SELECT COUNT(TCV.id) AS count_active_versions " . " FROM {$tables['tcversions']} TCV, {$tables['nodes_hierarchy']} NH " . " WHERE NH.parent_id=" . $node['id'] . " AND NH.id = TCV.id AND TCV.active=1";
                $result = $db->exec_query($sql);
                $row = $db->fetch_array($result);
                if ($row['count_active_versions'] != 0) {
                    $remove_node = true;
                }
            }
        }
        if ($my['options']['hideTestCases'] || $remove_node || $doFilterOn['keywords'] && !isset($tcFilterByKeywords[$node['id']])) {
            $node = null;
        } else {
            // needed to avoid problems when using json_encode with EXTJS
            unset($node['childNodes']);
            $node['leaf'] = true;
            $tcase_counters['testcase_count'] = 1;
        }
    }
    // if($node_type == 'testcase')
    // ================================================================================
    if (!is_null($node) && isset($node['childNodes']) && is_array($node['childNodes'])) {
        // node has to be a Test Suite ?
        $childNodes =& $node['childNodes'];
        $childNodesQty = count($childNodes);
        //$pos2unset = array();
        for ($idx = 0; $idx < $childNodesQty; $idx++) {
            $current =& $childNodes[$idx];
            // I use set an element to null to filter out leaf menu items
            if (is_null($current)) {
                continue;
            }
            $counters_map = prepareTestSpecNode($db, $tprojectMgr, $tprojectID, $current, $map_node_tccount);
            // 20120831 - to be analized carefully, because this can be solution
            // to null issue with json and ext-js
            // if( is_null($current) )
            // {
            //  echo 'TO NULX';
            //  unset($childNodes[$idx]);
            // }
            $tcase_counters['testcase_count'] += $counters_map['testcase_count'];
        }
        //new dBug($pos2unset);
        $node['testcase_count'] = $tcase_counters['testcase_count'];
        if (isset($node['id'])) {
            $map_node_tccount[$node['id']] = array('testcount' => $node['testcase_count'], 'name' => $node['name']);
        }
        // node must be destroyed if empty had we have using filtering conditions
        if ($filtersApplied && !$tcase_counters['testcase_count'] && $node_type != 'testproject') {
            $node = null;
        }
    } else {
        if ($node_type == 'testsuite') {
            // does this means is an empty test suite ??? - franciscom 20080328
            $map_node_tccount[$node['id']] = array('testcount' => 0, 'name' => $node['name']);
            // If is an EMPTY Test suite and we have added filtering conditions,
            // We will destroy it.
            if ($filtersApplied) {
                $node = null;
            }
        }
    }
    return $tcase_counters;
}
Example #11
0
/**
 * replace BBCode-link tagged links in req/reqspec scope with actual links
 *
 * @internal revisions:
 * 20110525 - Julian - BUGID 4487 - allow to specify requirement version for internal links
 * 20100301 - asimon - added anchor and tproj parameters to tags
 * 
 * @param resource $dbHandler database handle
 * @param string $scope text in which to replace tags with links
 * @param integer $tprojectID ID of testproject to which req/reqspec belongs
 * @return string $scope text with generated links
 */
function req_link_replace($dbHandler, $scope, $tprojectID)
{
    // Use this to improve performance when is called in loops
    static $tree_mgr;
    static $tproject_mgr;
    static $req_mgr;
    static $cfg;
    static $l18n;
    static $title;
    static $tables;
    if (!$tproject_mgr) {
        $tproject_mgr = new testproject($dbHandler);
        $tree_mgr = new tree($dbHandler);
        $req_mgr = new requirement_mgr($dbHandler);
        $tables = tlObjectWithDB::getDBTables(array('requirements', 'req_specs'));
        $cfg = config_get('internal_links');
        $l18n['version'] = lang_get('tcversion_indicator');
        $prop2loop = array('req' => array('prop' => 'req_link_title', 'default_lbl' => 'requirement'), 'req_spec' => array('prop' => 'req_spec_link_title', 'default_lbl' => 'req_spec_short'));
        // configure link title (first part of the generated link)
        $title = array();
        foreach ($prop2loop as $key => $elem) {
            $prop = $elem['prop'];
            if ($cfg->{$prop}->type == 'string' && $cfg->{$prop}->value != '') {
                $title[$key] = lang_get($cfg->{$prop}->value);
            } else {
                if ($cfg->{$prop}->type == 'none') {
                    $title[$key] = '';
                } else {
                    $title[$key] = lang_get($elem['default_lbl']) . ": ";
                }
            }
        }
    }
    $prefix = $tproject_mgr->getTestCasePrefix($tprojectID);
    $string2replace = array();
    // configure target in which link shall open
    // use a reasonable default value if nothing is set in config
    $cfg->target = isset($cfg->target) ? $cfg->target : 'popup';
    switch ($cfg->target) {
        case 'popup':
            // use javascript to open popup window
            $string2replace['req'] = '<a href="javascript:openLinkedReqVersionWindow(%s,%s,\'%s\')">%s%s%s</a>';
            $string2replace['req_spec'] = '<a href="javascript:openLinkedReqSpecWindow(%s,\'%s\')">%s%s</a>';
            break;
        case 'window':
        case 'frame':
            // open in same frame
            $target = $cfg->target == 'window' ? 'target="_blank"' : 'target="_self"';
            $string2replace['req'] = '<a ' . $target . ' href="lib/requirements/reqView.php?' . 'item=requirement&requirement_id=%s&req_version_id=%s#%s">%s%s%s</a>';
            $string2replace['req_spec'] = '<a ' . $target . ' href="lib/requirements/reqSpecView.php?' . 'item=req_spec&req_spec_id=%s#%s">%s%s</a>';
            break;
    }
    // now the actual replacing
    $patterns2search = array();
    $patterns2search['req'] = "#\\[req(.*)\\](.*)\\[/req\\]#iU";
    $patterns2search['req_spec'] = "#\\[req_spec(.*)\\](.*)\\[/req_spec\\]#iU";
    $patternPositions = array('complete_string' => 0, 'attributes' => 1, 'doc_id' => 2);
    $items2search['req'] = array('tproj', 'anchor', 'version');
    $items2search['req_spec'] = array('tproj', 'anchor');
    $itemPositions = array('item' => 0, 'item_value' => 1);
    $sql2exec = array();
    $sql2exec['req'] = " SELECT id, req_doc_id AS doc_id " . " FROM {$tables['requirements']} WHERE req_doc_id=";
    $sql2exec['req_spec'] = " SELECT id, doc_id FROM {$tables['req_specs']} " . " WHERE doc_id=";
    foreach ($patterns2search as $accessKey => $pattern) {
        $matches = array();
        preg_match_all($pattern, $scope, $matches);
        // if no req_doc_id is set skip loop
        if (count($matches[$patternPositions['doc_id']]) == 0) {
            continue;
        }
        foreach ($matches[$patternPositions['complete_string']] as $key => $matched_string) {
            $matched = array();
            $matched['tproj'] = '';
            $matched['anchor'] = '';
            $matched['version'] = '';
            // only look for attributes if any found
            if ($matches[$patternPositions['attributes']][$key] != '') {
                foreach ($items2search[$accessKey] as $item) {
                    $matched_item = array();
                    preg_match('/' . $item . '=([\\w]+)/', $matched_string, $matched_item);
                    $matched[$item] = isset($matched_item[$itemPositions['item_value']]) ? $matched_item[$itemPositions['item_value']] : '';
                }
            }
            // set tproj to current project if tproj is not specified in attributes
            if (!isset($matched['tproj']) || $matched['tproj'] == '') {
                $matched['tproj'] = $prefix;
            }
            // get all reqs / req specs with the specified doc_id
            $sql = $sql2exec[$accessKey] . "'{$matches[$patternPositions['doc_id']][$key]}'";
            $rs = $dbHandler->get_recordset($sql);
            if (count($rs) > 0) {
                foreach ($rs as $key => $value) {
                    // get root of linked node and check
                    $real_root = $tree_mgr->getTreeRoot($value['id']);
                    $matched_root_info = $tproject_mgr->get_by_prefix($matched['tproj']);
                    // do only continue if project with the specified project exists and
                    // if the requirement really belongs to the specified project (requirements
                    // with the same doc_id may exist within different projects)
                    if ($real_root == $matched_root_info['id']) {
                        if ($accessKey == 'req') {
                            // add version to link title if set
                            $version = '';
                            $req_version_id = 'null';
                            if ($matched['version'] != '') {
                                // get requirement version_id of the specified version
                                $req_version = $req_mgr->get_by_id($value['id'], null, $matched['version']);
                                // if version is not set or wrong version was set
                                // -> show latest version by setting version_id to null
                                $req_version_id = isset($req_version[0]['version_id']) ? $req_version[0]['version_id'] : 'null';
                                // if req_version_id exists set the version to show on hyperlink text
                                if ($req_version_id != 'null') {
                                    $version = sprintf($l18n['version'], $matched['version']);
                                }
                            }
                            $urlString = sprintf($string2replace[$accessKey], $value['id'], $req_version_id, $matched['anchor'], $title[$accessKey], $value['doc_id'], $version);
                        } else {
                            // build urlString for req specs which do not have a version
                            $urlString = sprintf($string2replace[$accessKey], $value['id'], $matched['anchor'], $title[$accessKey], $value['doc_id']);
                        }
                        $scope = str_replace($matched_string, $urlString, $scope);
                    }
                }
            }
        }
    }
    return $scope;
}
 /**
  *
  * @param database $dbHandler reference to database object
  */
 public function __construct(&$dbHandler)
 {
     // call to constructor of parent class tlObjectWithDB
     parent::__construct($dbHandler);
     // Here comes all initializing work: First read the config, then user input.
     // According to these inputs all filters which are not needed will not be used.
     // Then initialize and use only the remaining filters.
     $this->read_config();
     $this->init_args();
     // set filter mode to advanced or simple
     $this->advanced_filter_mode = $this->filter_mode_choice_enabled && $this->args->advanced_filter_mode && !$this->args->simple_filter_mode;
     // init button labels
     if ($this->advanced_filter_mode) {
         $label = self::SIMPLE_FILTER_BUTTON_LABEL;
         $qty = self::ADVANCED_FILTER_ITEM_QUANTITY;
     } else {
         $label = self::ADVANCED_FILTER_BUTTON_LABEL;
         $qty = self::SIMPLE_FILTER_ITEM_QUANTITY;
     }
     $this->filter_mode_button_label = lang_get($label);
     $this->filter_mode_button_name = $label;
     $this->filter_item_quantity = $qty;
     $this->init_settings();
     $this->init_filters();
 }
Example #13
0
$templateCfg = templateConfiguration();
$smarty = new TLSmarty();
$tpl = 'tcSearchResults.tpl';
$tproject_mgr = new testproject($db);
$tcase_mgr = new testcase($db);
$tcase_cfg = config_get('testcase_cfg');
$charset = config_get('charset');
$filter = null;
list($args, $filter) = init_args($tproject_mgr);
$ga = initializeGui($args, $tproject_mgr);
$gx = $tcase_mgr->getTcSearchSkeleton($args);
$gui = (object) array_merge((array) $ga, (array) $gx);
initSearch($gui, $args, $tproject_mgr);
$map = null;
if ($args->tprojectID && $args->doAction == 'doSearch') {
    $tables = tlObjectWithDB::getDBTables(array('cfield_design_values', 'nodes_hierarchy', 'requirements', 'req_coverage', 'tcsteps', 'testcase_keywords', 'tcversions', 'users'));
    $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($args->tprojectID);
    $gui->tcasePrefix .= $tcase_cfg->glue_character;
    $from = array('by_keyword_id' => ' ', 'by_custom_field' => ' ', 'by_requirement_doc_id' => '', 'users' => '');
    $tcaseID = null;
    $emptyTestProject = false;
    if ($args->targetTestCase != "" && strcmp($args->targetTestCase, $gui->tcasePrefix) != 0) {
        if (strpos($args->targetTestCase, $tcase_cfg->glue_character) === false) {
            $args->targetTestCase = $gui->tcasePrefix . $args->targetTestCase;
        }
        $tcaseID = $tcase_mgr->getInternalID($args->targetTestCase);
        $filter['by_tc_id'] = " AND NH_TCV.parent_id = " . intval($tcaseID);
    } else {
        $tproject_mgr->get_all_testcases_id($args->tprojectID, $a_tcid);
        if (!is_null($a_tcid)) {
            $filter['by_tc_id'] = " AND NH_TCV.parent_id IN (" . implode(",", $a_tcid) . ") ";
Example #14
0
 */
require_once "../../config.inc.php";
require_once "common.php";
testlinkInitPage($db);
$templateCfg = templateConfiguration();
$tproject_mgr = new testproject($db);
$req_cfg = config_get('req_cfg');
$gui = new stdClass();
$gui->main_descr = lang_get('caption_search_form_req_spec');
$gui->warning_msg = '';
$gui->path_info = null;
$gui->resultSet = null;
$map = null;
$args = init_args();
if ($args->tprojectID) {
    $tables = tlObjectWithDB::getDBTables(array("cfield_design_values", 'nodes_hierarchy', 'req_specs'));
    $filter = null;
    $from = null;
    if ($args->requirement_document_id) {
        //search by id
        $id = $db->prepare_string($args->requirement_document_id);
        $filter['by_id'] = " AND RS.doc_id like '%{$id}%' ";
    }
    if ($args->name) {
        //search by name/title
        $title = $db->prepare_string($args->name);
        $filter['by_name'] = " AND NH.name like '%{$title}%' ";
    }
    if ($args->reqSpecType != "notype") {
        //search by type
        $type = $db->prepare_string($args->reqSpecType);
 /**
  * checks if a keyword for a certain testproject already exists in the database
  * 
  * @param resource $db [ref] the database connection
  * @param string $name the name of the keyword
  * @param integer $tprojectID the testprojectID 
  * @param integer $kwID an additional keyword id which is excluded in the search 
  * @return integer return tl::OK if the keyword is found, else tlKeyword::E_NAMEALREADYEXISTS 
  */
 public static function doesKeywordExist(&$db, $name, $tprojectID, $kwID = null)
 {
     $result = tl::OK;
     $tables = tlObjectWithDB::getDBTables("keywords");
     $name = $db->prepare_string(strtoupper($name));
     $query = " SELECT id FROM {$tables['keywords']} " . " WHERE UPPER(keyword) ='" . $name . "' AND testproject_id = " . $tprojectID;
     if ($kwID) {
         $query .= " AND id <> " . $kwID;
     }
     if ($db->fetchFirstRow($query)) {
         $result = self::E_NAMEALREADYEXISTS;
     }
     return $result;
 }
function display_children($dbHandler, $root_node, $parent, $filter_node, $show_children = ON, $operation = 'manage', $mode = 'reqspec')
{
    $tables = tlObjectWithDB::getDBTables(array('requirements', 'nodes_hierarchy', 'node_types', 'req_specs'));
    $cfg = config_get('req_cfg');
    $forbidden_parent['testproject'] = 'none';
    $forbidden_parent['requirement'] = 'testproject';
    $forbidden_parent['requirement_spec'] = 'requirement_spec';
    if ($cfg->child_requirements_mgmt) {
        $forbidden_parent['requirement_spec'] = 'none';
    }
    $fn = array();
    $fn['print']['reqspec'] = array('testproject' => 'TPROJECT_PTP_RS', 'requirement_spec' => 'TPROJECT_PRS', 'requirement' => 'openLinkedReqWindow');
    $fn['manage']['reqspec'] = array('testproject' => 'TPROJECT_REQ_SPEC_MGMT', 'requirement_spec' => 'REQ_SPEC_MGMT', 'requirement' => 'REQ_MGMT');
    $fn['print']['addtc'] = array('testproject' => 'TPROJECT_PTP', 'requirement_spec' => 'TPROJECT_PRS', 'requirement' => 'TPROJECT_PRS');
    $fn['manage']['addtc'] = array('testproject' => 'EP', 'requirement_spec' => 'ERS', 'requirement' => 'ER');
    switch ($operation) {
        case 'print':
        case 'manage':
            $js_function = $fn[$operation][$mode];
            break;
        default:
            $js_function = $fn['manage'][$mode];
            break;
    }
    $nodes = null;
    $filter_node_type = $show_children ? '' : ",'requirement'";
    $sql = " SELECT NHA.*, NT.description AS node_type, RSPEC.doc_id " . " FROM {$tables['nodes_hierarchy']} NHA JOIN {$tables['node_types']}  NT " . " ON NHA.node_type_id=NT.id " . " AND NT.description NOT IN " . " ('testcase','testsuite','testcase_version','testplan','requirement_spec_revision' {$filter_node_type}) " . " LEFT OUTER JOIN {$tables['req_specs']} RSPEC " . " ON RSPEC.id = NHA.id " . " WHERE NHA.parent_id = " . intval($parent);
    if (!is_null($filter_node) && $filter_node > 0 && $parent == $root_node) {
        $sql .= " AND NHA.id = " . intval($filter_node);
    }
    $sql .= " ORDER BY NHA.node_order ";
    $nodeSet = $dbHandler->get_recordset($sql);
    if (!is_null($nodeSet)) {
        $sql = " SELECT DISTINCT req_doc_id AS doc_id,NHA.id" . " FROM {$tables['requirements']} REQ JOIN {$tables['nodes_hierarchy']} NHA ON NHA.id = REQ.id  " . " JOIN {$tables['nodes_hierarchy']}  NHB ON NHA.parent_id = NHB.id " . " JOIN {$tables['node_types']} NT ON NT.id = NHA.node_type_id " . " WHERE NHB.id = " . intval($parent) . " AND NT.description = 'requirement'";
        $requirements = $dbHandler->fetchRowsIntoMap($sql, 'id');
        $treeMgr = new tree($dbHandler);
        $ntypes = $treeMgr->get_available_node_types();
        $peerTypes = array('target' => $ntypes['requirement'], 'container' => $ntypes['requirement_spec']);
        foreach ($nodeSet as $key => $row) {
            $path['text'] = htmlspecialchars($row['name']);
            $path['id'] = $row['id'];
            // this attribute/property is used on custom code on drag and drop
            $path['position'] = $row['node_order'];
            $path['leaf'] = false;
            $path['cls'] = 'folder';
            // Important:
            // We can add custom keys, and will be able to access it using
            // public property 'attributes' of object of Class Ext.tree.TreeNode
            //
            $path['testlink_node_type'] = $row['node_type'];
            $path['testlink_node_name'] = $path['text'];
            // already htmlspecialchars() done
            $path['forbidden_parent'] = 'none';
            switch ($row['node_type']) {
                case 'testproject':
                    $path['href'] = "javascript:EP({$path['id']})";
                    $path['forbidden_parent'] = $forbidden_parent[$row['node_type']];
                    break;
                case 'requirement_spec':
                    $req_list = array();
                    $treeMgr->getAllItemsID($row['id'], $req_list, $peerTypes);
                    $path['href'] = "javascript:" . $js_function[$row['node_type']] . "({$path['id']})";
                    $path['text'] = htmlspecialchars($row['doc_id'] . ":") . $path['text'];
                    $path['forbidden_parent'] = $forbidden_parent[$row['node_type']];
                    if (!is_null($req_list)) {
                        $item_qty = count($req_list);
                        $path['text'] .= " ({$item_qty})";
                    }
                    break;
                case 'requirement':
                    $path['href'] = "javascript:" . $js_function[$row['node_type']] . "({$path['id']})";
                    $path['text'] = htmlspecialchars($requirements[$row['id']]['doc_id'] . ":") . $path['text'];
                    $path['leaf'] = true;
                    $path['forbidden_parent'] = $forbidden_parent[$row['node_type']];
                    break;
            }
            $nodes[] = $path;
        }
        // foreach
    }
    return $nodes;
}
* 
* 	@version 	$Id: getreqlog.php,v 1.1.2.5 2010/12/15 21:48:13 mx-julian Exp $
* 	@author 	Francisco Mancardi
* 
*   Used on Add/Remove test case to test plan feature, to display summary via ExtJS tooltip
*
*	@internal Revisions:
*/
require_once '../../config.inc.php';
require_once 'common.php';
testlinkInitPage($db);
$reqMgr = new requirement_mgr($db);
$item_id = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null;
$info = '';
if (!is_null($item_id)) {
    $tables = tlObjectWithDB::getDBTables(array('req_versions', 'req_revisions'));
    // get item type
    $node_types = $reqMgr->tree_mgr->get_available_node_types();
    $dummy = $reqMgr->tree_mgr->get_node_hierarchy_info($item_id);
    $target_table = 'req_revisions';
    if ($dummy['node_type_id'] == $node_types['requirement_version']) {
        $target_table = 'req_versions';
    }
    $sql = "SELECT log_message FROM {$tables[$target_table]} WHERE id=" . intval($item_id);
    $info = $db->get_recordset($sql);
    $info = nl2br($info[0]['log_message']);
    // <p> and </p> tag at the beginning and the end of summary cause visualization
    // errors -> remove them and add <br> to get a similar effect
    $info = str_replace("<p>", "", $info);
    $info = str_replace("</p>", "<br>", $info);
    // if log message is empty show this information
 /**
  * Class destructor
  */
 function __destruct()
 {
     parent::__destruct();
     $this->testProjectID = null;
 }
Example #19
0
/**
 *
 */
function getEntityByAPIKey(&$dbHandler, $apiKey, $type)
{
    $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
    $tables = tlObjectWithDB::getDBTables(array('testprojects', 'testplans'));
    switch ($type) {
        case 'testproject':
            $target = $tables['testprojects'];
            break;
        case 'testplan':
            $target = $tables['testplans'];
            break;
    }
    $sql = "/* {$debugMsg} */ " . " SELECT id FROM {$target} " . " WHERE api_key = '" . $dbHandler->prepare_string($apiKey) . "'";
    $rs = $dbHandler->get_recordset($sql);
    return $rs ? $rs[0] : null;
}
Example #20
0
/**
 * 
 * 
 */
function initEnv(&$dbHandler)
{
    $uaWhiteList = array();
    $uaWhiteList['elements'] = array('link', 'create', 'doCreate', 'add_note');
    $uaWhiteList['lenght'] = array();
    foreach ($uaWhiteList['elements'] as $xmen) {
        $uaWhiteList['lenght'][] = strlen($xmen);
    }
    $user_action['maxLengh'] = max($uaWhiteList['lenght']);
    $user_action['minLengh'] = min($uaWhiteList['lenght']);
    $iParams = array("exec_id" => array("GET", tlInputParameter::INT_N), "bug_id" => array("REQUEST", tlInputParameter::STRING_N), "tproject_id" => array("REQUEST", tlInputParameter::INT_N), "tplan_id" => array("REQUEST", tlInputParameter::INT_N), "tcversion_id" => array("REQUEST", tlInputParameter::INT_N), "bug_notes" => array("POST", tlInputParameter::STRING_N), "issueType" => array("POST", tlInputParameter::INT_N), "issuePriority" => array("POST", tlInputParameter::INT_N), "artifactComponent" => array("POST", tlInputParameter::ARRAY_INT), "artifactVersion" => array("POST", tlInputParameter::ARRAY_INT), "user_action" => array("REQUEST", tlInputParameter::STRING_N, $user_action['minLengh'], $user_action['maxLengh']));
    $args = new stdClass();
    I_PARAMS($iParams, $args);
    if ($args->exec_id) {
        $_SESSION['bugAdd_execID'] = intval($args->exec_id);
    } else {
        $args->exec_id = intval(isset($_SESSION['bugAdd_execID']) ? $_SESSION['bugAdd_execID'] : 0);
    }
    $args->user = $_SESSION['currentUser'];
    $gui = new stdClass();
    switch ($args->user_action) {
        case 'create':
        case 'doCreate':
            $gui->pageTitle = lang_get('create_issue');
            break;
        case 'add_note':
            $gui->pageTitle = lang_get('add_issue_note');
            break;
        case 'link':
        default:
            $gui->pageTitle = lang_get('title_bug_add');
            break;
    }
    $gui->msg = '';
    $gui->bug_summary = '';
    $gui->tproject_id = $args->tproject_id;
    $gui->tplan_id = $args->tplan_id;
    $gui->tcversion_id = $args->tcversion_id;
    $gui->user_action = $args->user_action;
    $gui->bug_id = $args->bug_id;
    $gui->issueType = $args->issueType;
    $gui->issuePriority = $args->issuePriority;
    $gui->artifactVersion = $args->artifactVersion;
    $gui->artifactComponent = $args->artifactComponent;
    // -----------------------------------------------------------------------
    // Special processing
    list($itObj, $itCfg) = getIssueTracker($dbHandler, $args, $gui);
    // Second access to user input
    $bug_summary['minLengh'] = 1;
    $bug_summary['maxLengh'] = $itObj->getBugSummaryMaxLength();
    $inputCfg = array("bug_summary" => array("POST", tlInputParameter::STRING_N, $bug_summary['minLengh'], $bug_summary['maxLengh']));
    I_PARAMS($inputCfg, $args);
    $args->bug_id = trim($args->bug_id);
    switch ($args->user_action) {
        case 'create':
            if ($args->bug_id == '' && $args->exec_id > 0) {
                $map = get_execution($dbHandler, $args->exec_id);
                $args->bug_notes = $map[0]['notes'];
            }
            break;
        case 'doCreate':
        case 'add_note':
        case 'link':
        default:
            break;
    }
    $gui->bug_notes = $args->bug_notes = trim($args->bug_notes);
    $args->basehref = $_SESSION['basehref'];
    $tables = tlObjectWithDB::getDBTables(array('testplans'));
    $sql = ' SELECT api_key FROM ' . $tables['testplans'] . ' WHERE id=' . intval($args->tplan_id);
    $rs = $dbHandler->get_recordset($sql);
    $args->tplan_apikey = $rs[0]['api_key'];
    return array($args, $gui, $itObj, $itCfg);
}
Example #21
0
function check_exec_values(&$db, &$tcase_mgr, &$user_mgr, $tcaseCfg, &$execValues, &$columnDef)
{
    $tables = tlObjectWithDB::getDBTables(array('users', 'execution_bugs'));
    $checks = array('status_ok' => false, 'tcase_id' => 0, 'tester_id' => 0, 'msg' => array());
    $tcase_id = $execValues['tcase_id'];
    $tcase_external_id = trim($execValues['tcase_external_id']);
    $using_external_id = $tcase_external_id != "";
    // external_id has precedence over internal id
    if ($using_external_id) {
        // need to get internal id
        $checks['tcase_id'] = $tcase_mgr->getInternalID($tcase_external_id);
        $checks['status_ok'] = intval($checks['tcase_id']) > 0 ? true : false;
        if (!$checks['status_ok']) {
            $checks['msg'][] = sprintf(lang_get('tcase_external_id_do_not_exists'), $tcase_external_id);
        }
    } else {
        // before using internal id, I want to check it's a number
        $checks['tcase_id'] = $tcase_id;
        $checks['status_ok'] = intval($checks['tcase_id']) > 0 ? true : false;
        if (!$checks['status_ok']) {
            $checks['msg'][] = sprintf(lang_get('tcase_id_is_not_number'), $tcase_id);
        }
    }
    if ($checks['status_ok']) {
        // useful for user feedback
        $identity = $using_external_id ? $tcase_external_id : $checks['tcase_id'];
    }
    if ($checks['status_ok'] && $execValues['timestamp'] != '') {
        $checks['status_ok'] = isValidISODateTime($execValues['timestamp']);
        if (!$checks['status_ok']) {
            $checks['msg'][] = sprintf(lang_get('invalid_execution_timestamp'), $identity, $execValues['timestamp']);
        }
    }
    if ($checks['status_ok'] && $execValues['tester'] != '') {
        $sql = "SELECT id,login FROM {$tables['users']} WHERE login ='******'tester']) . "'";
        $userInfo = $db->get_recordset($sql);
        if (!is_null($userInfo) && isset($userInfo[0]['id'])) {
            $checks['tester_id'] = $userInfo[0]['id'];
        } else {
            $checks['status_ok'] = false;
            $checks['msg'][] = sprintf(lang_get('invalid_tester'), $identity, $execValues['tester']);
        }
    }
    $execValues['bug_id'] = isset($execValues['bug_id']) ? $execValues['bug_id'] : null;
    if ($checks['status_ok'] && !is_null($execValues['bug_id']) && is_array($execValues['bug_id'])) {
        foreach ($execValues['bug_id'] as $bug_id) {
            if (($field_len = strlen(trim($bug_id))) > $columnDef['bug_id']->max_length) {
                $checks['msg'][] = sprintf(lang_get('bug_id_invalid_len'), $field_len, $columnDef['bug_id']->max_length);
                $checks['status_ok'] = false;
                break;
            }
        }
    }
    if ($checks['status_ok'] && isset($execValues['execution_type'])) {
        $execValues['execution_type'] = intval($execValues['execution_type']);
        $execDomain = $tcase_mgr->get_execution_types();
        if ($execValues['execution_type'] == 0) {
            $execValues['execution_type'] = TESTCASE_EXECUTION_TYPE_MANUAL;
            // right now this is useless, but may be in future can be used, then I choose to leave it.
            $checks['msg'][] = sprintf(lang_get('missing_exec_type'), $execValues['execution_type'], $execDomain[$execValues['execution_type']]);
        } else {
            $checks['status_ok'] = isset($execDomain[$execValues['execution_type']]);
            if (!$checks['status_ok']) {
                $checks['msg'][] = sprintf(lang_get('invalid_exec_type'), $execValues['execution_type']);
            }
        }
    }
    return $checks;
}
 function __construct(&$db)
 {
     parent::__construct($db);
 }
Example #23
0
/**
 *
 *
 */
function display_children($dbHandler, $root_node, $parent, $filter_node, $tcprefix, $show_tcases = 1, $operation = 'manage', $helpText = array())
{
    static $showTestCaseID;
    $tables = tlObjectWithDB::getDBTables(array('tcversions', 'nodes_hierarchy', 'node_types'));
    $forbidden_parent = array('testproject' => 'none', 'testcase' => 'testproject', 'testsuite' => 'none');
    $external = '';
    $nodes = null;
    $filter_node_type = $show_tcases ? '' : ",'testcase'";
    switch ($operation) {
        case 'print':
            $js_function = array('testproject' => 'TPROJECT_PTP', 'testsuite' => 'TPROJECT_PTS', 'testcase' => 'TPROJECT_PTS');
            break;
        case 'manage':
        default:
            $js_function = array('testproject' => 'EP', 'testsuite' => 'ETS', 'testcase' => 'ET');
            break;
    }
    $sql = " SELECT NHA.*, NT.description AS node_type " . " FROM {$tables['nodes_hierarchy']} NHA, {$tables['node_types']} NT " . " WHERE NHA.node_type_id = NT.id " . " AND parent_id = " . intval($parent) . " AND NT.description NOT IN " . " ('testcase_version','testplan','requirement_spec','requirement'{$filter_node_type}) ";
    if (!is_null($filter_node) && $filter_node > 0 && $parent == $root_node) {
        $sql .= " AND NHA.id = " . intval($filter_node);
    }
    $sql .= " ORDER BY NHA.node_order ";
    // for debug
    //file_put_contents('/tmp/sql_display_node.txt', $sql);
    $nodeSet = $dbHandler->get_recordset($sql);
    if ($show_tcases) {
        // Get external id, used on test case nodes
        $sql = " SELECT DISTINCT tc_external_id,NHA.parent_id " . " FROM {$tables['tcversions']} TCV " . " JOIN {$tables['nodes_hierarchy']} NHA  ON NHA.id = TCV.id  " . " JOIN {$tables['nodes_hierarchy']} NHB ON NHA.parent_id = NHB.id " . " WHERE NHB.parent_id = " . intval($parent) . " AND NHA.node_type_id = 4";
        $external = $dbHandler->fetchRowsIntoMap($sql, 'parent_id');
    }
    // print_r(array_values($nodeSet));
    //file_put_contents('/tmpsql_display_node.txt', serialize(array_values($nodeSet)));
    if (!is_null($nodeSet)) {
        $tproject_mgr = new testproject($dbHandler);
        foreach ($nodeSet as $key => $row) {
            $path['text'] = htmlspecialchars($row['name']);
            $path['id'] = $row['id'];
            // this attribute/property is used on custom code on drag and drop
            $path['position'] = $row['node_order'];
            $path['leaf'] = false;
            $path['cls'] = 'folder';
            // customs key will be accessed using node.attributes.[key name]
            $path['testlink_node_type'] = $row['node_type'];
            $path['testlink_node_name'] = $path['text'];
            // already htmlspecialchars() done
            $path['forbidden_parent'] = 'none';
            $tcase_qty = null;
            switch ($row['node_type']) {
                case 'testproject':
                    // at least on Test Specification seems that we do not execute this piece of code.
                    $path['href'] = "javascript:EP({$path['id']})";
                    $path['forbidden_parent'] = $forbidden_parent[$row['node_type']];
                    break;
                case 'testsuite':
                    $tcase_qty = $tproject_mgr->count_testcases($row['id']);
                    $path['href'] = "javascript:" . $js_function[$row['node_type']] . "({$path['id']})";
                    $path['forbidden_parent'] = $forbidden_parent[$row['node_type']];
                    break;
                case 'testcase':
                    $path['href'] = "javascript:" . $js_function[$row['node_type']] . "({$path['id']})";
                    $path['forbidden_parent'] = $forbidden_parent[$row['node_type']];
                    if (is_null($showTestCaseID)) {
                        $showTestCaseID = config_get('treemenu_show_testcase_id');
                    }
                    if ($showTestCaseID) {
                        $path['text'] = htmlspecialchars($tcprefix . $external[$row['id']]['tc_external_id'] . ":") . $path['text'];
                    }
                    $path['leaf'] = true;
                    break;
            }
            if (!is_null($tcase_qty)) {
                $path['text'] .= " ({$tcase_qty})";
            }
            switch ($row['node_type']) {
                case 'testproject':
                case 'testsuite':
                    if (isset($helpText[$row['node_type']])) {
                        $path['text'] = '<span title="' . $helpText[$row['node_type']] . '">' . $path['text'] . '</span>';
                    }
                    break;
            }
            $nodes[] = $path;
        }
    }
    return $nodes;
}
Example #24
0
/**
 * @param $db resource the database connecton
 * @param $execID integer the execution id whose notes should be set
 * @param $notes string the execution notes to set
 * @return unknown_type
 */
function updateExecutionNotes(&$db, $execID, $notes)
{
    $table = tlObjectWithDB::getDBTables('executions');
    $sql = "UPDATE {$table['executions']} " . "SET notes = '" . $db->prepare_string($notes) . "' " . "WHERE id = {$execID}";
    return $db->exec_query($sql) ? tl::OK : tl::ERROR;
}
 /**
  * Class constructor
  *  
  * @param object [ref] $db the database connection
  * @param string $attachmentTableName the foreign key table name to store the attachments
  */
 function __construct(&$db, $attachmentTableName)
 {
     tlObjectWithDB::__construct($db);
     $this->attachmentRepository = tlAttachmentRepository::create($this->db);
     $this->attachmentTableName = $attachmentTableName;
 }
$tproject_mgr = new testproject($db);
$req_cfg = config_get('req_cfg');
$charset = config_get('charset');
$args = init_args();
$commandMgr = new reqSpecCommands($db, $args->tprojectID);
$gui = $commandMgr->initGuiBean();
$edit_label = lang_get('requirement_spec');
$edit_icon = TL_THEME_IMG_DIR . "edit_icon.png";
$gui->main_descr = lang_get('caption_search_form_req_spec');
$gui->warning_msg = '';
$gui->path_info = null;
$gui->resultSet = null;
$gui->tableSet = null;
$itemSet = null;
if ($args->tprojectID) {
    $tables = tlObjectWithDB::getDBTables(array('cfield_design_values', 'nodes_hierarchy', 'req_specs', 'req_specs_revisions'));
    $filter = null;
    $join = null;
    // we use same approach used on requirements search => search on revisions
    if ($args->requirement_document_id) {
        $id = $db->prepare_string($args->requirement_document_id);
        $filter['by_id'] = " AND RSPECREV.doc_id like '%{$id}%' ";
    }
    if ($args->name) {
        $title = $db->prepare_string($args->name);
        $filter['by_name'] = " AND NHRSPEC.name like '%{$title}%' ";
    }
    if ($args->reqSpecType != "notype") {
        $type = $db->prepare_string($args->reqSpecType);
        $filter['by_type'] = " AND RSPECREV.type='{$type}' ";
    }
$map_status_label = $results_config['status_label'];
$map_statuscode_css = array();
foreach ($map_code_status as $code => $status) {
    if (isset($map_status_label[$status])) {
        $label = $map_status_label[$status];
        $map_statuscode_css[$code] = array();
        $map_statuscode_css[$code]['translation'] = lang_get($label);
        $map_statuscode_css[$code]['css_class'] = $map_code_status[$code] . '_text';
    }
}
// Get all test cases created by user in the current project
$options = new stdClass();
$options->mode = 'full_path';
$gui->resultSet = $tcase_mgr->get_created_per_user($args->tproject_id, $args->tplan_id, $options);
if ($doIt = !is_null($gui->resultSet)) {
    $tables = tlObjectWithDB::getDBTables(array('nodes_hierarchy'));
    $tplanSet = array_keys($gui->resultSet);
    $sql = "SELECT name,id FROM {$tables['nodes_hierarchy']} " . "WHERE id IN (" . implode(',', $tplanSet) . ")";
    $gui->tplanNames = $db->fetchRowsIntoMap($sql, 'id');
    $optColumns = array('priority' => $args->priority_enabled);
    foreach ($gui->resultSet as $tplan_id => $tcase_set) {
        list($columns, $sortByColumn) = getColumnsDefinition($optColumns);
        $rows = array();
        foreach ($tcase_set as $tcase_platform) {
            foreach ($tcase_platform as $tcase) {
                $current_row = array();
                $tcase_id = $tcase['testcase_id'];
                $tcversion_id = $tcase['tcversion_id'];
                $current_row[] = htmlspecialchars($tcase['login']);
                $current_row[] = htmlspecialchars($tcase['tcase_full_path']);
                // create linked icons
 /**
  * @param $db database object
  * @param $tproject_id to work on. If null (default) the project in session
  *                     is used
  * DO NOT USE this kind of code is not accepted have this kind of global coupling
  * for lazy users
  */
 public function __construct(&$db, $tproject_id = null)
 {
     parent::__construct($db);
     $this->tproject_id = $tproject_id;
 }
 function assignment_mgr(&$db)
 {
     parent::__construct($db);
 }
Example #30
0
 public function __construct(&$db)
 {
     parent::__construct($db);
     $this->sendto_email = config_get('tl_admin_email');
     $this->from_email = config_get('from_email');
     $this->return_path_email = config_get('return_path_email');
     // now we need to check if we have all needed configuration
     $key2check = array('sendto_email', 'from_email', 'return_path_email');
     $regex2match = config_get('validation_cfg')->user_email_valid_regex_php;
     $this->configIsOK = true;
     foreach ($key2check as $emailKey) {
         $matches = array();
         $this->{$emailKey} = trim($this->{$emailKey});
         if (is_blank($this->{$emailKey}) || !preg_match($regex2match, $this->{$emailKey}, $matches)) {
             $this->configIsOK = false;
             break;
         }
     }
 }