@@ -165,7 +165,7 @@ if(Session::getUserGrade(true) < 5){
diff --git a/twe/j_install.php b/twe/j_install.php
index e69de29b..397e3fba 100644
--- a/twe/j_install.php
+++ b/twe/j_install.php
@@ -0,0 +1,66 @@
+setReadOnly();
+if($session->userGrade < 5){
+ Json::die([
+ 'result'=>false,
+ 'reason'=>'관리자 아님'
+ ]);
+}
+
+$turnterm = Util::toInt(Util::array_get($_POST['turnterm']));
+$sync = Util::toInt(Util::array_get($_POST['sync']));
+$scenario = Util::toInt(Util::array_get($_POST['scenario']));
+$fiction = Util::toInt(Util::array_get($_POST['fiction']));
+$extend = Util::toInt(Util::array_get($_POST['extend']));
+$npcmode = Util::toInt(Util::array_get($_POST['npcmode']));
+$show_img_level = Util::toInt(Util::array_get($_POST['show_img_level']));
+
+
+
+if($turnterm===null || $sync===null || $scenario===null || $fiction===null || $extend===null || $npcmode===null || $show_img_level===null){
+ Json::die([
+ 'result'=>false,
+ 'reason'=>'입력 값이 올바르지 않습니다'
+ ]);
+}
+
+
+if(120 % $turnterm != 0){
+ Json::die([
+ 'result'=>false,
+ 'turnterm은 120의 약수여야 합니다.'
+ ]);
+}
+
+$mysqli_obj = DB::db()->get();
+
+if($mysqli_obj->multi_query(file_get_contents(__dir__.'/sql/reset.sql'))){
+ do{
+ if(!$mysqli_obj->store_result()){
+ break;
+ }
+ } while($mysqli_obj->next_result());
+}
+
+if($mysqli_obj->multi_query(file_get_contents(__dir__.'/sql/schema.sql'))){
+ do{
+ if(!$mysqli_obj->store_result()){
+ break;
+ }
+ } while($mysqli_obj->next_result());
+}
+
+//TODO:script
+$env = [
+
+];
+
+Json::die([
+ 'result'=>false,
+ 'reason'=>'NYI'
+]);
\ No newline at end of file
diff --git a/twe/js/install.js b/twe/js/install.js
index c192bb14..33b7a6c8 100644
--- a/twe/js/install.js
+++ b/twe/js/install.js
@@ -102,8 +102,77 @@ function scenarioPreview(){
));
});
}
+
+function formSetup(){
+ $('#game_form').validate({
+ rules:{
+ turnterm:"required",
+ sync:"required",
+ scenario:"required",
+ fiction:"required",
+ extend:"required",
+ npcmode:"required",
+ show_img_level:"required",
+ },
+ errorElement: "div",
+ errorPlacement: function ( error, element ) {
+ // Add the `help-block` class to the error element
+ error.addClass( "invalid-feedback" );
+
+ if ( element.prop( "type" ) === "checkbox" ) {
+ error.insertAfter( element.parent( "label" ) );
+ } else {
+ error.insertAfter( element );
+ }
+ },
+ highlight: function ( element, errorClass, validClass ) {
+ $( element ).addClass( "is-invalid" ).removeClass( "is-valid" );
+ },
+ unhighlight: function (element, errorClass, validClass) {
+ $( element ).addClass( "is-valid" ).removeClass( "is-invalid" );
+ }
+ });
+ $('#game_form').submit(function(e){
+ e.preventDefault();
+ if(!$("#game_form").valid()){
+ return;
+ }
+ $.ajax({
+ cache:false,
+ type:'post',
+ url:'j_install.php',
+ dataType:'json',
+ data:{
+ turnterm:$('#turnterm input:radio:checked').val(),
+ sync:$('#sync input:radio:checked').val(),
+ scenario:$('#scenario_sel').val(),
+ fiction:$('#fiction input:radio:checked').val(),
+ extend:$('#extend input:radio:checked').val(),
+ npcmode:$('#npcmode input:radio:checked').val(),
+ show_img_level:$('#show_img_level input:radio:checked').val()
+ }
+ }).then(function(result){
+ var deferred = $.Deferred();
+
+ if(!result.result){
+ alert(result.reason);
+ deferred.reject('fail');
+ }
+ else{
+ alert('DB.php가 생성되었습니다.');
+ deferred.resolve();
+ }
+
+ return deferred.promise();
+ }).then(function(){
+ location.href = 'install.php';
+ });
+
+ });
+}
+
$(function(){
loadScenarios();
$('#scenario_sel').change(scenarioPreview);
- //loadScenarioPreview(8);
+ formSetup();
})