"", "result" => "", "form" => "", ); //---------------------------- // request parameter //---------------------------- $qProjectID = isset($_SESSION["project_id"]) ? $_SESSION["project_id"] : REQ_NON; $qToken = isset($_REQUEST["q_token"]) ? $_REQUEST["q_token"] : REQ_NON; $qOption = isset($_REQUEST["q_option"]) ? $_REQUEST["q_option"] : REQ_NON; $qFileName = isset($_FILES["q_file"]["name"]) ? $_FILES["q_file"]["name"] : REQ_NON; $qFileTmpName = isset($_FILES["q_file"]["tmp_name"]) ? $_FILES["q_file"]["tmp_name"] : REQ_NON; $qFileType = isset($_FILES["q_file"]["type"]) ? $_FILES["q_file"]["type"] : REQ_NON; $qFileError = isset($_FILES["q_file"]["error"]) ? $_FILES["q_file"]["error"] : REQ_NON; $qFileSize = isset($_FILES["q_file"]["size"]) ? $_FILES["q_file"]["size"] : REQ_NON; //---------------------------- // judge post //---------------------------- $isPost = ($qToken !== REQ_NON); //---------------------------- // set types //---------------------------- Util::setType($qProjectID, "int"); Util::setType($qToken, "string"); Util::setType($qOption, "int"); Util::setType($qFileName, "string"); Util::setType($qFileTmpName, "string"); Util::setType($qFileType, "string"); Util::setType($qFileError, "int"); Util::setType($qFileSize, "int"); //---------------------------- // Auth-Before validate //---------------------------- if ( $result === RES_OK ){ if ( $isPost ){ if ( ! Validate::isToken($qToken, "q_token") ){ $result = RES_NG; $gResult->push("{$WORD($wk, 1)}"); } } if ( ! Validate::isNumeric($qProjectID) ){ $result = RES_NG; $gResult->push("{$WORD($wk, 2)}"); } } //---------------------------- // Auth //---------------------------- if ( $result === RES_OK ){ $auth = Auth::instance("project"); if ( ! $auth->processImport($qProjectID) ){ $result = RES_NG; $gResult->push("{$WORD($wk, 3)}"); } } //---------------------------- // Auth-After validate //---------------------------- if ( $result === RES_OK ){ if ( $isPost ){ if ( count($qOption) === 0 ){ $result = RES_NG; $gResult->push("{$WORD($wk, 4)}"); } if ( $qFileSize > 0 ){ if ( $result === RES_OK ){ if ( $qFileError !== UPLOAD_ERR_OK ){ $result = RES_NG; $gResult->push("{$WORD($wk, 5)} (Code:{$qFileError})"); } } // ファイル確認 if ( $result === RES_OK ){ if ( ! file_exists($qFileTmpName) ){ $result = RES_NG; $gResult->push("{$WORD($wk, 6)}"); } } } else { $result = RES_NG; $gResult->push("{$WORD($wk, 7)}"); } } } //---------------------------- // function //---------------------------- //---------------------------- // process //---------------------------- if ( $result === RES_OK ){ DAO::begin(); $objDAOProject = DAO::instance("project"); $objViewProject = View::instance("project"); // array( 削除したID => 追加したID ) $arrDocumentID = array(); $arrTermRootID = array(); $arrBilingualRootID = array(); $arrDataID = array(); // 更新 -------------------- if ( $isPost ){ $doc = new DocProject(); $xml = file_get_contents($qFileTmpName); $doc->load($xml); $resDAOProject = $objDAOProject->get($qProjectID); if ( ($result = $resDAOProject["result"]) !== RES_OK ){ $gResult->push("{$WORD($wk, 8)}"); } else { $dataProject = $resDAOProject["data"][0]; $orgID = $dataProject["t_organization_id"]; } $validateError = array(); if ( $doc->validate($validateError) ){ $projectDetail = $doc->getDetail(); // ---------------------------- // ワークフロー if ( in_array(ImportOption::TASK, $qOption) ){ if ( ($workflowDetail = $doc->importWorkflow($qProjectID, $workflowID)) === FALSE ){ $result = RES_NG; } } // ---------------------------- // メンバー if ( in_array(ImportOption::MEMBER, $qOption) && $result === RES_OK ){ if ( ($arrUserRole = $doc->importMembers($qProjectID, TRUE, User::get("id"))) === FALSE ){ $result = RES_NG; } } // ---------------------------- // 文書 if ( in_array(ImportOption::DOCUMENT, $qOption) && $result === RES_OK ){ if ( ($arrDocumentID = $doc->importDocuments($qProjectID, TRUE, User::get("id"))) === FALSE ){ $result = RES_NG; } } // ---------------------------- // 用語集 if ( in_array(ImportOption::TERM, $qOption) && $result === RES_OK ){ if ( ($arrTermRootID = $doc->importTermRoots(Term::KIND_TERM, $qProjectID, TRUE, User::get("id"), User::get("organization_id"))) === FALSE ){ $result = RES_NG; } } // ---------------------------- // 翻訳メモリ集 if ( in_array(ImportOption::BILINGUAL, $qOption) && $result === RES_OK ){ if ( ($arrBilingualRootID = $doc->importTermRoots(Term::KIND_BILINGUAL, $qProjectID, TRUE, User::get("id"), User::get("organization_id"))) === FALSE ){ $result = RES_NG; } } // ---------------------------- // データ if ( in_array(ImportOption::DATA, $qOption) && $result === RES_OK ){ if ( ($arrDataID = $doc->importData($qProjectID, TRUE, User::get("id"), User::get("organization_id"))) === FALSE ){ $result = RES_NG; } } // ---------------------------- // タスク if ( in_array(ImportOption::TASK, $qOption) ){ if ( ($doc->importTask($qProjectID, TRUE, User::get("id"), $workflowID, $projectDetail["start"], $arrUserRole, $arrDocumentID, $arrTermRootID, $arrBilingualRootID, $arrDataID)) === FALSE ){ $result = RES_NG; } } if ( count($doc->importMessage) > 0 ){ $gResult->arrStrRes = array_merge($gResult->arrStrRes, $doc->importMessage); } } else { $result = RES_NG; foreach( $validateError as $error ){ $gResult->push($error); } } } // ファイル選択 -------------------- else { } DAO::end($result); } //---------------------------- // data //---------------------------- //---------------------------- // html //---------------------------- { // menu ---------------------------------------------------------------- if ( $result !== RES_NG ){ $arrMenu = array(); //----- $arrMenu[0] = $objViewProject->tab(View_project::TAB_DETAIL, $auth, $qProjectID); $arrMenu[1] = $objViewProject->tab(View_project::TAB_STRUCTURE, $auth, $qProjectID); $arrMenu[2] = $objViewProject->tab(View_project::TAB_IMPORT, $auth, $qProjectID); $arrMenu[3] = $objViewProject->tab(View_project::TAB_EXPORT, $auth, $qProjectID); //----- $arrHtml["menu"] = Printer::menuTab($arrMenu, 2); } // title --------------------------------------------------------------- $title = "{$WORD($wk, 31)}"; // form ---------------------------------------------------------------- if ( $result === RES_OK ){ if ( $isPost ){ $_SESSION["notify"][] = "{$WORD($wk, 32)}"; if ( count($gResult->arrStrRes) > 0 ){ $_SESSION["notify"][] = "{$WORD($wk, 33)}"; $_SESSION["notify"] = array_merge($_SESSION["notify"], $gResult->arrStrRes); } // アクション(OK) $arrHtml["form"] = Printer::link("{$WORD($wk, 34)}", "btn btn-default", NULL, NULL, "./detail.html?q_project_id={$qProjectID}"); header("Location: ./detail.html?q_project_id={$qProjectID}"); exit(); } else { $arrControl = array(); $arrAction = array(); // フォーム(ファイル) $arrControl[] = array( "id" => "q_file", "name" => "{$WORD($wk, 35)}", "form" => array( Printer::input("file", "q_file", "q_file"), ), ); $arrControl[] = array( "id" => "q_option", "name" => "{$WORD($wk, 36)}", "form" => Printer::checkbox( NULL, "q_option[]", array( ImportOption::MEMBER => "{$WORD($wk, 37)}", ImportOption::DOCUMENT => "{$WORD($wk, 38)}", ImportOption::TASK => "{$WORD($wk, 39)}", ImportOption::TERM => "{$WORD($wk, 40)}", ImportOption::BILINGUAL => "{$WORD($wk, 41)}", ImportOption::DATA => "{$WORD($wk, 42)}", ), $qOption, NULL, FALSE, FALSE), ); $arrControl[] = array( "id" => NULL, "name" => "", "form" => Printer::alert(FALSE, "{$WORD($wk, 43)}"), ); // フォーム(token) $arrControl[] = array( "id" => NULL, "name" => NULL, "form" => Printer::input("hidden", "q_token", "q_token", Util::token()), ); // アクション(OK) $arrAction[] = Printer::input("submit", NULL, NULL, "OK", "btn btn-primary"); // アクション(キャンセル) $arrAction[] = Printer::link("Cancel", "btn btn-default", NULL, NULL, "./detail.html"); $arrHtml["form"] = Printer::form("form_import", "form_import", "./import.html", "post", $arrControl, $arrAction, array("enctype" => "multipart/form-data")); } } else { // アクション(OK) $arrHtml["form"] = Printer::link("OK", "btn btn-default", NULL, NULL, "./detail.html"); } // result -------------------------------------------------------------- $arrHtml["result"] = $gResult->string(TRUE, $result); } ?>