"", "result" => "", "form" => "", ); //---------------------------- // request parameter //---------------------------- $qProjectID = isset($_SESSION["project_id"]) ? $_SESSION["project_id"] : REQ_NON; $qToken = isset($_REQUEST["q_token"]) ? $_REQUEST["q_token"] : REQ_NON; $qTargetAllDocument = isset($_REQUEST["q_target_all_document"]) ? $_REQUEST["q_target_all_document"] : REQ_NON; $qTargetDocumentID = isset($_REQUEST["q_target_document_id"]) ? $_REQUEST["q_target_document_id"] : REQ_NON; //---------------------------- // judge post //---------------------------- $isPost = ($qToken !== REQ_NON); //---------------------------- // set types //---------------------------- Util::setType($qToken, "string"); Util::setType($qProjectID, "int"); Util::setType($qTargetAllDocument, "int"); Util::setType($qTargetDocumentID, "int"); //---------------------------- // Auth-Before validate //---------------------------- if ( $result === RES_OK ){ if ( $isPost ){ if ( $qTargetDocumentID == REQ_NON ){ $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("document"); if( ! $auth->readList($qProjectID) ){ $result = RES_NG; $gResult->push("{$WORD($wk, 3)}"); } } //---------------------------- // Auth-After validate //---------------------------- if ( $result === RES_OK ){ if ( ! $isPost ){ $qTargetAllDocument = ON; $qTargetDocumentID = INIT_ID; } } //---------------------------- // function //---------------------------- //---------------------------- // process //---------------------------- if ( $result === RES_OK ){ $objDAODocument = DAO::instance("document"); $objDAODocumentText = DAO::instance("document_text"); $objViewDocument = View::instance("document"); $objViewExterm = View::instance("exterm"); $objProject = new Project($qProjectID); if ( $arrAppended = $objProject->getAppended() ){ // 使用可能文書一覧 if ( isset($arrAppended["document"]) ){ $arrDocument = $arrAppended["document"]; } } // 抽出(ダウンロード) -------------------- if ( $isPost ){ $downLoadData = ""; $title = "SelectDocument"; $arrTargetDocument = $qTargetDocumentID; $tempFL = tmpfile(); $tempFLObj = stream_get_meta_data($tempFL); $tempFLName = $tempFLObj['uri']; if ( count($arrTargetDocument) > 0 ){ $offset = 0; $limit = 1000; do { $resDAODocumentText = $objDAODocumentText->get($arrTargetDocument, NULL, $limit, $offset); if ( $resDAODocumentText["result"] === RES_OK ){ foreach ( $resDAODocumentText["data"] as $dataDocumentText ){ $textS = $dataDocumentText["t_document_text_s"]; $textS = mb_convert_encoding($textS, "UTF-8", "UTF-8,EUC-JP,SJIS,JIS,ASCII"); $textS = preg_replace("/(\r|\n)/", "", $textS); $textT = $dataDocumentText["t_document_text_t"]; $textT = mb_convert_encoding($textT, "UTF-8", "UTF-8,EUC-JP,SJIS,JIS,ASCII"); $textT = preg_replace("/(\r|\n)/", "", $textT); fwrite($tempFL, "{$textS}\t{$textT}\r\n"); } } $offset += $limit; } while ( $resDAODocumentText["count"] > $offset ); // DownLoad header('Content-Disposition: attachment; filename="'.$title.'.tsv"'); header('Content-Type: text/plain; charset=UTF-8'); header('Content-Length: '.filesize($tempFLName)); fseek($tempFL, 0); echo fread($tempFL, filesize($tempFLName)); fclose($tempFL); exit(); } } } //---------------------------- // menu //---------------------------- { // menu ---------------------------------------------------------------- if ( $result !== RES_NG ){ $arrMenu = array(); //----- $arrMenu[0] = $objViewDocument->tab(View_document::TAB_LIST, $auth, $qProjectID); $arrMenu[1] = $objViewDocument->tab(View_document::TAB_DOWNLOAD_ALL, $auth, $qProjectID); //----- $arrHtml["menu"] = Printer::menuTab($arrMenu, 1); } // title --------------------------------------------------------------- $title = "{$WORD($wk, 4)}"; // form ---------------------------------------------------------------- if ( $result !== RES_NG ){ // フォーム(抽出対象) $arrControl[] = array( "id" => "q_target_all_document", "name" => "{$WORD($wk, 5)}", "form" => array( $objViewExterm->formTarget($arrDocument, $qTargetAllDocument === ON ? array() : $qTargetDocumentID), ), "validate" => array( "required_target_document" => FALSE, ), "required" => TRUE, ); // フォーム(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, "./"); $arrHtml["form"] = Printer::form("form_download", "form_download", "./download.html", "post", $arrControl, $arrAction); } else { // アクション(OK) $arrHtml["form"] = Printer::link("OK", "btn btn-default", NULL, NULL, "./download.html"); } // result -------------------------------------------------------------- $arrHtml["result"] = $gResult->string(TRUE, $result); } ?>