/**
  * xmlToMapReqSpec
  *
  */
 function xmlToMapReqSpec($xml_item, $level = 0)
 {
     static $iterations = 0;
     static $mapped;
     static $req_mgr;
     // Attention: following PHP Manual SimpleXML documentation, Please remember to cast
     //            before using data from $xml,
     if (is_null($xml_item)) {
         return null;
     }
     // used to reset static structures if calling this in loop
     if ($level == 0) {
         $iterations = 0;
         $mapped = null;
     }
     $dummy = array();
     $dummy['node_order'] = (int) $xml_item->node_order;
     $dummy['scope'] = (string) $xml_item->scope;
     $dummy['type'] = (int) $xml_item->type;
     $dummy['total_req'] = (int) $xml_item->total_req;
     $dummy['level'] = $level;
     $depth = $level + 1;
     foreach ($xml_item->attributes() as $key => $value) {
         $dummy[$key] = (string) $value;
         // See PHP Manual SimpleXML documentation.
     }
     if (property_exists($xml_item, 'custom_fields')) {
         $dummy['custom_fields'] = array();
         foreach ($xml_item->custom_fields->children() as $key) {
             $dummy['custom_fields'][(string) $key->name] = (string) $key->value;
         }
     }
     $mapped[] = array('req_spec' => $dummy, 'requirements' => null, 'level' => $dummy['level']);
     // Process children
     if (property_exists($xml_item, 'requirement')) {
         if (is_null($req_mgr)) {
             $req_mgr = new requirement_mgr($this->db);
         }
         $loop2do = count($xml_item->requirement);
         for ($idx = 0; $idx <= $loop2do; $idx++) {
             $xml_req = $req_mgr->xmlToMapRequirement($xml_item->requirement[$idx]);
             if (!is_null($xml_req)) {
                 $fdx = count($mapped) - 1;
                 $mapped[$fdx]['requirements'][] = $xml_req;
             }
         }
     }
     if (property_exists($xml_item, 'req_spec')) {
         $loop2do = count($xml_item->req_spec);
         for ($idx = 0; $idx <= $loop2do; $idx++) {
             $this->xmlToMapReqSpec($xml_item->req_spec[$idx], $depth);
         }
     }
     return $mapped;
 }
Example #2
0
/**
 * doUploadFile
 *
 */
function doUploadFile(&$dbHandler, $fileName, $importScope, &$argsObj, &$reqSpecMgr)
{
    $retval = new stdClass();
    $retval->items = null;
    $retval->file_check = array('status_ok' => 1, 'msg' => 'ok');
    $source = isset($_FILES['uploadedFile']['tmp_name']) ? $_FILES['uploadedFile']['tmp_name'] : null;
    if ($source != 'none' && $source != '') {
        if ($retval->file_check['status_ok']) {
            if (move_uploaded_file($source, $fileName)) {
                // Must be recoded - $file_check = check_syntax($gui->fileName,$args->importType);
                if ($retval->file_check['status_ok']) {
                    if (strcasecmp($argsObj->importType, 'XML') == 0) {
                        $retval->file_check['status_ok'] = !(($xml = simplexml_load_file($fileName)) === FALSE);
                        if ($retval->file_check['status_ok']) {
                            $retval->items = array();
                            // New simple check on file contents
                            $isReqSpec = property_exists($xml, 'req_spec');
                            $fileFormatOK = $isReqSpec && $importScope != 'items' || !$isReqSpec && $importScope == 'items';
                            // if($isReqSpec)
                            //
                            // switch($importScope)
                            // {
                            // 	case 'branch':
                            // 	case 'tree':
                            // 		$fileFormatOK = property_exists($xml,'req_spec');
                            // 	break;
                            //
                            // 	case 'items':
                            //
                            // 	break;
                            //
                            // }
                            // we can have two types of files:
                            // 1. req. specs + requirements
                            // 2. just requirements
                            if ($isReqSpec) {
                                foreach ($xml->req_spec as $xkm) {
                                    $retval->items = array_merge($retval->items, $reqSpecMgr->xmlToMapReqSpec($xkm));
                                }
                            } else {
                                $reqMgr = new requirement_mgr($dbHandler);
                                $loop2do = count($xml->requirement);
                                $items = null;
                                for ($zdx = 0; $zdx <= $loop2do; $zdx++) {
                                    $xml_req = $reqMgr->xmlToMapRequirement($xml->requirement[$zdx]);
                                    if (!is_null($xml_req)) {
                                        $items[] = $xml_req;
                                    }
                                }
                                if ($loop2do > 0) {
                                    // IMPORTANT NOTICE
                                    // this keys must be same that returned by $reqSpecMgr->xmlToMapReqSpec
                                    // because are used at GUI to draw
                                    $retval->items[] = array('requirements' => $items, 'req_spec' => null, 'level' => 0);
                                }
                            }
                        } else {
                            $retval->file_check['msg'] = lang_get('xml_load_file_failed');
                        }
                    } else {
                        $retval->items = doReqImport($dbHandler, $argsObj->tproject_id, $argsObj->user_id, $argsObj->req_spec_id, $fileName, $argsObj->importType, $argsObj->emptyScope, $argsObj->conflictSolution, false);
                    }
                }
            }
        }
    } else {
        $retval->file_check = array('status_ok' => 0, 'msg' => lang_get('please_choose_req_file'));
    }
    return $retval;
}