"", "result" => "", "form" => "", ); //---------------------------- // request parameter //---------------------------- $qToken = isset($_REQUEST["q_token"]) ? $_REQUEST["q_token"] : REQ_NON; $qID = isset($_REQUEST["q_id"]) ? $_REQUEST["q_id"] : REQ_NON; $qName = isset($_REQUEST["q_name"]) ? $_REQUEST["q_name"] : REQ_NON; $qText = isset($_REQUEST["q_text"]) ? $_REQUEST["q_text"] : REQ_NON; //---------------------------- // judge post //---------------------------- $isPost = ($qToken !== REQ_NON); //---------------------------- // set types //---------------------------- Util::setType($qToken, "string"); Util::setType($qID, "int"); Util::setType($qName, "string"); Util::setType($qText, "string"); //---------------------------- // 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($qID) ){ $result = RES_NG; $gResult->push("{$WORD($wk, 2)}"); } } else { if ( ! Validate::isNumeric($qID) ){ $qID = INIT_ID; } } } //---------------------------- // Auth //---------------------------- if ( $result === RES_OK ){ $auth = Auth::instance("bbs"); if ( ! $auth->write($qID) ){ $result = RES_NG; $gResult->push("{$WORD($wk, 3)}"); } } //---------------------------- // Auth-After validate //---------------------------- if ( $result === RES_OK ){ if ( $isPost ){ if ( ! Validate::isString($qName) ){ $result = RES_NG; $gResult->push("{$WORD($wk, 4)}"); } } } $isNew = ( $result === RES_OK && $qID === INIT_ID ); //---------------------------- // function //---------------------------- //---------------------------- // process //---------------------------- if ( $result === RES_OK ){ DAO::begin(); $objDAOBbs = DAO::instance("bbs"); // 更新 -------------------- if ( $isPost ){ if ( $result === RES_OK ){ $resDAOBbs = $objDAOBbs->register($qID, $qName, $qText, DAO::T_BBS_PROJECT_ID_SYSTEM); $result = $resDAOBbs["result"]; if ( $result === RES_OK ){ $gResult->push($isNew ? "{$WORD($wk, 5)}" : "{$WORD($wk, 6)}"); } else { $gResult->push("{$WORD($wk, 7)}"); } } } else { if ( $result === RES_OK ){ // 新規登録 -------------------- if ( $isNew ){ $qName = $objDAOBbs->getInit("t_bbs_name"); $qText = $objDAOBbs->getInit("t_bbs_text"); } // 編集 -------------------- else { $objDAOBbs->setAuth($auth); $resDAOBbs = $objDAOBbs->get($qID); $result = $resDAOBbs["result"]; if ( $result === RES_OK ){ $dataUser = $resDAOBbs["data"][0]; $qName = $dataUser["t_bbs_name"]; $qText = $dataUser["t_bbs_text"]; } else { $result = RES_NG; $gResult->push("{$WORD($wk, 8)}"); } } } } DAO::end($result); } //---------------------------- // data //---------------------------- //---------------------------- // html //---------------------------- { // menu ---------------------------------------------------------------- $arrMenu = array(); if ( $result !== RES_NG ){ $arrMenu = array(); //----- if ( $isNew ){ $arrMenu[0] = Printer::link("{$WORD($wk, 9)}", NULL, "icon-plus", NULL, "/content/bbs_system/edit.html"); } else { $arrMenu[0] = Printer::link("{$WORD($wk, 10)}", NULL, "icon-pencil", NULL, "/content/bbs_system/edit.html&q_id={$qID}"); } //----- $arrHtml["menu"] = Printer::menuTab($arrMenu, 0); } // title --------------------------------------------------------------- $title = ($isNew) ? "{$WORD($wk, 11)}" : "{$WORD($wk, 12)}"; // form ---------------------------------------------------------------- $arrControl = array(); $arrAction = array(); if ( $result === RES_OK ){ if ( $isPost ){ // アクション(OK) $arrHtml["form"] = Printer::link("OK", "btn btn-default", NULL, NULL, "./"); header("Location: ./"); } else { // フォーム(名前) $arrControl[] = array( "id" => "q_name", "name" => "{$WORD($wk, 13)}", "form" => array( Printer::input("text", "q_name", "q_name", $qName), ), "validate" => array( "required" => TRUE, ), "required" => TRUE, ); // フォーム(テキスト) $arrControl[] = array( "id" => "q_text", "name" => "{$WORD($wk, 14)}", "form" => Printer::textarea("q_text", "q_text", $qText), "fullsize" => TRUE, ); // フォーム(id) $arrControl[] = array( "id" => NULL, "name" => NULL, "form" => Printer::input("hidden", "q_id", "q_id", $qID), ); // フォーム(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_bbs_system", "form_bbs_system", "./edit.html", "post", $arrControl, $arrAction); } } else { // アクション(OK) $arrHtml["form"] = Printer::link("OK", "btn btn-default", NULL, NULL, "/"); } // result -------------------------------------------------------------- $arrHtml["result"] = $gResult->string(TRUE, $result); } ?>