/** * @param object dbHandler reference to db handler * */ function doImport(&$dbHandler, $testproject_id) { $import_msg = array('ok' => array(), 'ko' => array()); $file_check = array('show_results' => 0, 'status_ok' => 0, 'msg' => '', 'filename' => '', 'import_msg' => $import_msg); $key = 'targetFilename'; $dest = TL_TEMP_PATH . session_id() . "-import_platforms.tmp"; $fInfo = $_FILES[$key]; $source = isset($fInfo['tmp_name']) ? $fInfo['tmp_name'] : null; if ($source != 'none' && $source != '') { $file_check['filename'] = $fInfo['name']; $xml = false; if (move_uploaded_file($source, $dest)) { $xml = @simplexml_load_file($dest); } if ($xml !== FALSE) { $file_check['status_ok'] = 1; $file_check['show_results'] = 1; $platform_mgr = new tlPlatform($dbHandler, $testproject_id); $platformsOnSystem = $platform_mgr->getAllAsMap('name', 'rows'); foreach ($xml as $platform) { // Check if platform with this name already exists on test Project // if answer is yes => update fields $name = trim($platform->name); if (isset($platformsOnSystem[$name])) { $import_msg['ok'][] = sprintf(lang_get('platform_updated'), $platform->name); $platform_mgr->update($platformsOnSystem[$name]['id'], $name, $platform->notes); } else { $import_msg['ok'][] = sprintf(lang_get('platform_imported'), $platform->name); $platform_mgr->create($name, $platform->notes); } } } else { $file_check['msg'] = lang_get('problems_loading_xml_content'); } } else { $msg = getFileUploadErrorMessage($fInfo); $file_check = array('show_results' => 0, 'status_ok' => 0, 'msg' => $msg); } $file_check['import_msg'] = $import_msg; return $file_check; }