"", "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; $qAPIName = isset($_REQUEST["q_api_name"]) ? $_REQUEST["q_api_name"] : REQ_NON; $qAPIKey = isset($_REQUEST["q_api_key"]) ? $_REQUEST["q_api_key"] : REQ_NON; $qAPISecret = isset($_REQUEST["q_api_secret"]) ? $_REQUEST["q_api_secret"] : 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 ){ $authOrg = Auth::instance("organization"); $authUser = Auth::instance("user"); if ( $authOrg->write($qID) ){ if ( $qID === INIT_ID ){ $mode = MODE_NEW; } else { $mode = MODE_EDIT; } } else if ( $authOrg->write_isInfo($qID) ){ $mode = MODE_EDITINFO; } else { $result = RES_NG; $gResult->push("{$WORD($wk, 3)}"); } } //---------------------------- // Auth-After validate //---------------------------- if ( $result === RES_OK ){ if ( $isPost ){ if ( $mode === MODE_NEW || $mode === MODE_EDIT ){ if ( ! Validate::isString($qName) ){ $result = RES_NG; $gResult->push("{$WORD($wk, 4)}"); } } else { $qName = NULL; } if ( ! Validate::isString($qText) ){ $qText = ""; } } } //---------------------------- // function //---------------------------- //---------------------------- // process //---------------------------- if ( $result === RES_OK ){ DAO::begin(); $objDAOOrganization = DAO::instance("organization"); $objViewOrganization = View::instance("organization"); $objViewUser = View::instance("user"); // 更新 -------------------- if ( $isPost ){ $resDAOOrganization = $objDAOOrganization->register($qID, $qName, $qAPIName ,$qAPIKey ,$qAPISecret, $qText); $result = $resDAOOrganization["result"]; if ( $result === RES_OK ){ if ( $mode === MODE_NEW ){ $gResult->push("{$WORD($wk, 5)}"); } else { $gResult->push("{$WORD($wk, 6)}"); } } else { $gResult->push("{$WORD($wk, 7)}"); } } else { if ( $result === RES_OK ){ // 新規登録 -------------------- if ( $mode === MODE_NEW ){ $qName = $objDAOOrganization->getInit("t_organization_name"); $qAPIName = $objDAOOrganization->getInit("t_mtauto_name"); $qAPIKey = $objDAOOrganization->getInit("t_mtauto_key"); $qAPISecret = $objDAOOrganization->getInit("t_mtauto_secret"); $qText = $objDAOOrganization->getInit("t_organization_text"); } // 編集 -------------------- else { $objDAOOrganization->setAuth($authOrg); $resDAOOrganization = $objDAOOrganization->get($qID, NULL, FALSE); $result = $resDAOOrganization["result"]; if ( $result === RES_OK ){ $dataOrganization = $resDAOOrganization["data"][0]; $qName = $dataOrganization["t_organization_name"]; $qAPIName = $dataOrganization["t_mtauto_name"]; $qAPIKey = $dataOrganization["t_mtauto_key"]; $qAPISecret = $dataOrganization["t_mtauto_secret"]; $qText = $dataOrganization["t_organization_text"]; } else { $result = RES_NG; $gResult->push("{$WORD($wk, 8)}"); } } } } DAO::end($result); } //---------------------------- // html //---------------------------- { // menu ---------------------------------------------------------------- if ( $result !== RES_NG ){ $arrMenu = array(); //----- if ( $mode === MODE_NEW ){ $arrMenu[0] = $objViewOrganization->tab(View_organization::TAB_LIST, $authOrg); $arrMenu[1] = $objViewOrganization->tab(View_organization::TAB_NEW, $authOrg); $arrMenu[2] = $objViewUser->tab(View_user::TAB_LIST_ALL, $authUser, $qID); } else { $arrMenu[0] = $objViewOrganization->tab(View_organization::TAB_LIST, $authOrg); $arrMenu[1] = $objViewOrganization->tab(View_organization::TAB_EDIT, $authOrg, $qID); $arrMenu[2] = $objViewUser->tab(View_user::TAB_LIST, $authUser, $qID); $arrMenu[3] = $objViewUser->tab(View_user::TAB_NEW, $authUser, $qID); } //----- $arrHtml["menu"] = Printer::menuTab($arrMenu, 1); } // title --------------------------------------------------------------- if ( $mode === MODE_NEW ){ $title = "{$WORD($wk, 9)}"; } else { $title = "{$WORD($wk, 10)}"; } // form ---------------------------------------------------------------- if ( $result === RES_OK ){ if ( $isPost ){ header("Location: ./detail.html?q_id={$qID}"); } else { $arrControl = array(); $arrAction = array(); // フォーム(名前) if ( $mode === MODE_EDITINFO ){ $arrControl[] = array( "id" => "q_name", "name" => "{$WORD($wk, 11)}", "form" => Printer::formText($qName), ); } else { $arrControl[] = array( "id" => "q_name", "name" => "{$WORD($wk, 12)}", "form" => Printer::input("text", "q_name", "q_name", $qName, NULL, array("placeholder" => "{$WORD($wk, 13)}")), "validate" => array( "required" => TRUE, ), ); } // フォーム(WebAPI Name) $arrControl[] = array( "id" => "q_api_name", "name" => "{$WORD($wk, 14)}", "form" => Printer::input("text", "q_api_name", "q_api_name", $qAPIName, NULL, array("placeholder" => "{$WORD($wk, 15)}")), ); // フォーム(WebAPI Key) $arrControl[] = array( "id" => "q_api_key", "name" => "{$WORD($wk, 16)}", "form" => Printer::input("text", "q_api_key", "q_api_key", $qAPIKey, NULL, array("placeholder" => "{$WORD($wk, 17)}")), ); // フォーム(WebAPI Secret) $arrControl[] = array( "id" => "q_api_secret", "name" => "{$WORD($wk, 18)}", "form" => Printer::input("password", "q_api_secret", "q_api_secret", $qAPISecret, NULL, array("autocomplete" => "off")), ); // フォーム(説明) $arrControl[] = array( "id" => "q_text", "name" => "{$WORD($wk, 20)}", "form" => Printer::textarea("q_text", "q_text", $qText), ); // フォーム(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, "./detail.html?q_id={$qID}"); $arrHtml["form"] = Printer::form("form_organization", "form_organization", "./edit.html", "post", $arrControl, $arrAction); } } else { // アクション(OK) $arrHtml["form"] = Printer::link("OK", "btn btn-default", NULL, NULL, "/content/organization/"); } // result -------------------------------------------------------------- $arrHtml["result"] = $gResult->string(TRUE, $result); } ?>