/** * */ function fileUploadManagement(&$dbHandler, $id, $title, $table) { $retVal = new stdClass(); $retVal->uploaded = null; $retVal->msg = null; $fInfo = isset($_FILES['uploadedFile']) ? $_FILES['uploadedFile'] : null; if ($fInfo && $id) { $fSize = isset($fInfo['size']) ? $fInfo['size'] : 0; $fTmpName = isset($fInfo['tmp_name']) ? $fInfo['tmp_name'] : ''; if ($fSize && $fTmpName != "") { $repo = tlAttachmentRepository::create($dbHandler); $retVal->uploaded = $repo->insertAttachment($id, $table, $title, $fInfo); if ($retVal->uploaded) { logAuditEvent(TLS("audit_attachment_created", $title, $fInfo['name']), "CREATE", $id, "attachments"); } } else { $retVal->msg = getFileUploadErrorMessage($fInfo); } } return $retVal; }
* * Scope: Import keywords page * * Filename $RCSfile: keywordsImport.php,v $ * @version $Revision: 1.11 $ * @modified $Date: 2010/02/14 17:33:58 $ by $Author: franciscom $ */ require_once '../../config.inc.php'; require_once 'common.php'; require_once 'csv.inc.php'; require_once 'xml.inc.php'; testlinkInitPage($db, false, false, "checkRights"); $templateCfg = templateConfiguration(); $args = init_args(); $dest = TL_TEMP_PATH . session_id() . "-importkeywords." . $args->importType; $msg = getFileUploadErrorMessage($args->fInfo); if (!$msg && $args->UploadFile) { if ($args->source != 'none' && $args->source != '') { if (move_uploaded_file($args->source, $dest)) { $pfn = null; switch ($args->importType) { case 'iSerializationToCSV': $pfn = "importKeywordsFromCSV"; break; case 'iSerializationToXML': $pfn = "importKeywordsFromXMLFile"; break; } if ($pfn) { $tproject = new testproject($db); $result = $tproject->{$pfn}($args->testproject_id, $dest);
if ($args->bPostBack) { $fInfo = isset($_FILES['uploadedFile']) ? $_FILES['uploadedFile'] : null; $id = $_SESSION['s_upload_id']; $gui->tableName = $_SESSION['s_upload_tableName']; if ($fInfo && $id && $gui->tableName != "") { $fSize = isset($fInfo['size']) ? $fInfo['size'] : 0; $fTmpName = isset($fInfo['tmp_name']) ? $fInfo['tmp_name'] : ''; if ($fSize && $fTmpName != "") { $repo = tlAttachmentRepository::create($db); $gui->uploaded = $repo->insertAttachment($id, $gui->tableName, $args->title, $fInfo); // if ($gui->uploaded) // { // logAuditEvent(TLS("audit_attachment_created",$args->title,$fInfo['name']),"CREATE",$id,"attachments"); // } } else { $gui->msg = getFileUploadErrorMessage($fInfo); } } } else { // Try to understand if we can remove this code - 20121102 $_SESSION['s_upload_tableName'] = $args->tableName; $_SESSION['s_upload_id'] = $args->id; } $smarty = new TLSmarty(); $smarty->assign('gui', $gui); $smarty->display('attachmentupload.tpl'); /** * @return object returns the arguments for the page */ function init_args() {
/** * @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)) { // http://websec.io/2012/08/27/Preventing-XXE-in-PHP.html $xml = @simplexml_load_file_wrapper($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) { if (property_exists($platform, 'name')) { // 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 { $import_msg['ko'][] = lang_get('bad_line_skipped'); } } } 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); } if (count($import_msg['ko']) == 0) { $import_msg['ko'] = null; } $file_check['import_msg'] = $import_msg; return $file_check; }
$fSize = isset($fInfo['size'][$fdx]) ? $fInfo['size'][$fdx] : 0; $fTmpName = isset($fInfo['tmp_name'][$fdx]) ? $fInfo['tmp_name'][$fdx] : ''; $fin = array(); $fin['size'] = $fSize; $fin['tmp_name'] = $fTmpName; $fin['type'] = $fInfo['type'][$fdx]; $fin['name'] = $fInfo['name'][$fdx]; $fin['error'] = $fInfo['error'][$fdx]; if ($fSize && $fTmpName != "") { $docRepo = tlAttachmentRepository::create($db); $gui->uploaded = $docRepo->insertAttachment($id, $gui->tableName, $args->title, $fin, $opt); if ($gui->uploaded) { logAuditEvent(TLS("audit_attachment_created", $args->title, $fin['name']), "CREATE", $id, "attachments"); } } else { $gui->msg = getFileUploadErrorMessage($fin); } } } } else { $_SESSION['s_upload_tableName'] = $args->tableName; $_SESSION['s_upload_id'] = $args->id; } $smarty = new TLSmarty(); $smarty->assign('gui', $gui); $smarty->display('attachmentupload.tpl'); /** * @return object returns the arguments for the page */ function init_args() {