<!DOCTYPE html>
<html>

<head>

<?php   include('include/common.php');?>  




</head>

<body>

    <!-- admin javascript -->
     <script type="text/javascript">
      $( document ).ready(function() {

          //add control
        $("#btnSubmit").click(function(event) {
          var forcusitem="";
          var passCheck=true;


          if($('#name').val().length !== 0){
            $("#name").addClass(" is-valid ");
            $("#name").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#name";
            }
            passCheck=false;
            $("#name").addClass(" is-invalid ");
           $("#name").removeClass(" is-valid ");
          }


        //   if($('#inputadminname').val().length !== 0){
        //     $("#inputadminname").addClass(" is-valid ");
        //     $("#inputadminname").removeClass(" is-invalid ");
        //   }
        //   else{
        //     if(forcusitem.length===0){
        //        forcusitem="#inputadminname";
        //     }
        //     passCheck=false;
        //     $("#inputadminname").addClass(" is-invalid ");
        //    $("#inputadminname").removeClass(" is-valid ");
        //   }

          if($('#capacity').val().length !== 0){
            $("#capacity").addClass(" is-valid ");
            $("#capacity").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#capacity";
            }
            passCheck=false;
            $("#capacity").addClass(" is-invalid ");
           $("#capacity").removeClass(" is-valid ");
          }

          




        //   alert("1");
          if(passCheck==true){

          
          var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  // 'destUrl':'<?php echo base_url();?>/api/v1/frontend/add',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

            event.preventDefault();
            var postUrl= GlobalVariables.baseUrl +'/api/v1/roomend/add';
            // var postData ={
            //       'csrfToken' :'',
            //       'custname' : $('#name').val(),
            //       'tel' : $('#tel').val(),
            //       'email' : $('#email').val(),
            //       'wechat' : $('#wechat').val(),
            //       'birthday' : $('#birthday').val(),
            //       // 'selectedBox' :$('.css-checkbox:checked').val()
            //       'selectedBox' :selectBox1

            // }
            var postData ={
                'shop_id':$('#shop_id').val(),
                'name':$('#name').val(),
                'capacity':$('#capacity').val(),
                // 'inputadminname':$('#inputadminname').val(),
                'description':$('#description').val(),
                'remark':$('#remark').val()
            }
            $.ajax({
                  method: "POST",
                  url: postUrl,
                  dataType: "json",
                 data: postData,
                 success : function(data){

                // alert("posted");
                // // alert('formsubmit');
                // alert(data);
                
                // alert(data['recordstatus']);
                // alert(data['msg']);
                if(data['recordstatus']=="SUCCESS"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-primary" id="feedback">'+data['msg']+'</p>');
                    setTimeout(function() {
                        location.reload();
                    }, 3000);
                    // location.reload();

                }
                  if(data['recordstatus']=="FAILURE"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-danger"  id="feedback">'+data['msg']+'</p>');
                //   $( '#modal-bodymsg' ).empty();
                //   $( '#modal-bodymsg' ).append( '<h5 class="text-center" style="color: #a03d49;">客戶不能增加。</h5> <h5 class="text-center" style="color: #a03d49;">請稍後再嘗試。</h5>' );
                //   $('#finishModal').modal('show');
                // }
                  // if (data.AJAX_SUCCESS==GlobalVariables.AJAX_SUCCESS){
                  //     window.location.href=GlobalVariables.destUrl;
                  // } else {
                  //     $('.alert').text("登入錯誤");
                  //    $('.alert').removeClass('hidden');
                  }
              }
            });  

            }//if(passCheck==true){
        });//$("#btnSubmit").click(function(event) {

        $("#btnUpdate").click(function(event){
           var forcusitem="";
          var passCheck=true;


          if($('#name').val().length !== 0){
            $("#name").addClass(" is-valid ");
            $("#name").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#name";
            }
            passCheck=false;
            $("#name").addClass(" is-invalid ");
           $("#name").removeClass(" is-valid ");
          }


        //   if($('#inputadminname').val().length !== 0){
        //     $("#inputadminname").addClass(" is-valid ");
        //     $("#inputadminname").removeClass(" is-invalid ");
        //   }
        //   else{
        //     if(forcusitem.length===0){
        //        forcusitem="#inputadminname";
        //     }
        //     passCheck=false;
        //     $("#inputadminname").addClass(" is-invalid ");
        //    $("#inputadminname").removeClass(" is-valid ");
        //   }

          if($('#capacity').val().length !== 0){
            $("#capacity").addClass(" is-valid ");
            $("#capacity").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#capacity";
            }
            passCheck=false;
            $("#capacity").addClass(" is-invalid ");
           $("#capacity").removeClass(" is-valid ");
          }

          




        //   alert("1");
          if(passCheck==true){

          
          var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  // 'destUrl':'<?php echo base_url();?>/api/v1/frontend/add',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

            event.preventDefault();
            var postUrl= GlobalVariables.baseUrl +'/api/v1/roomend/update';
            // var postData ={
            //       'csrfToken' :'',
            //       'custname' : $('#name').val(),
            //       'tel' : $('#tel').val(),
            //       'email' : $('#email').val(),
            //       'wechat' : $('#wechat').val(),
            //       'birthday' : $('#birthday').val(),
            //       // 'selectedBox' :$('.css-checkbox:checked').val()
            //       'selectedBox' :selectBox1

            // }
            var postData ={
                'shop_id':$('#shop_id').val(),
                'name':$('#name').val(),
                'capacity':$('#capacity').val(),
                // 'inputadminname':$('#inputadminname').val(),
                'description':$('#description').val(),
                'remark':$('#remark').val(),
                'id':$('#id').val()
            }
            $.ajax({
                  method: "POST",
                  url: postUrl,
                  dataType: "json",
                 data: postData,
                 success : function(data){

                // alert("posted");
                // // alert('formsubmit');
                // alert(data);
                
                // alert(data['recordstatus']);
                // alert(data['msg']);
                if(data['recordstatus']=="SUCCESS"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-primary" id="feedback">'+data['msg']+'</p>');
                    setTimeout(function() {
                        location.reload();
                    }, 3000);
                    // location.reload();

                }
                  if(data['recordstatus']=="FAILURE"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-danger"  id="feedback">'+data['msg']+'</p>');
                //   $( '#modal-bodymsg' ).empty();
                //   $( '#modal-bodymsg' ).append( '<h5 class="text-center" style="color: #a03d49;">客戶不能增加。</h5> <h5 class="text-center" style="color: #a03d49;">請稍後再嘗試。</h5>' );
                //   $('#finishModal').modal('show');
                // }
                  // if (data.AJAX_SUCCESS==GlobalVariables.AJAX_SUCCESS){
                  //     window.location.href=GlobalVariables.destUrl;
                  // } else {
                  //     $('.alert').text("登入錯誤");
                  //    $('.alert').removeClass('hidden');
                  }
              }
            });  

            }//if(passCheck==true){

        });//$("#btnUpdate").click(function(){



        });// $( document ).ready(function() {

      </script>
    


    <?php   include('include/header.php');?>
    <div class="wrapper" >
        
        <?php   include('include/sidebar.php');?>
        <!-- Page Content  -->
        <div id="content" style="background-color: #e5e5e5;">

          <div class="title"><?php if($pagemethod=="add"){ 
                echo "新增房間";
              }?>  
              <?php if($pagemethod=="edit"){ 
                echo "更改房間";
              }?></div> 

            <div style="" class="menubar2">

           <a href="/at-cms/roomadmin"> <i class="fas fa-chevron-left" style=" display: inline-block;
  border-radius: 10px;
  box-shadow: 0px 0px 2px #888;
  color: #33aaae;
  padding: 2px 2px;"></i>返回</a>
            </div>   


           <!-- <a href="/at-cms/roomadmin">返回</a> -->
            <!-- add button -->
            <!-- <h5>新增房間</h5> -->
            <!-- input form -->
            <form>
              <div class="form-group row">
              <label for="username" class="col-sm-2 col-form-label">店鋪</label>
              <div class="col-sm-10">
                 <?php foreach ($shop as $shoprow) {
                        ?>
                           
                                <?php
                                    if($currentshop==$shoprow->id){
                                        echo $shoprow->name;
                                    }
                                ?>

                        <?php    # code...
                        }
                        ?>
                    <input type="hidden"  class="form-control" id="shop_id" name="shop_id" value="<?php echo $currentshop;?>" placeholder="">
              </div>
            </div>

              <div class="form-group row">
              <label for="username" class="col-sm-2 col-form-label">房間名稱</label>
              <div class="col-sm-10">
                <input type="text"  class="form-control" id="name" name="name" value="<?php
                if($pagemethod=="add"){ 
              } 
                if($pagemethod=="edit"){ echo 
                 $roomdetails->name;
              }?>" placeholder="輸入中文名稱">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="username" class="col-sm-2 col-form-label">容額</label>
              <div class="col-sm-10">
                <input type="text"  class="form-control" id="capacity" name="capacity" value="<?php
                if($pagemethod=="add"){ 
              } 
                if($pagemethod=="edit"){ echo 
                 $roomdetails->capacity;
              }?>" placeholder="">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="description" class="col-sm-2 col-form-label">詳情</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="description" name="description" value="<?php
                if($pagemethod=="add"){ 
              } 
                if($pagemethod=="edit"){ echo 
                 $roomdetails->description;
              }?>" >
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="remark" class="col-sm-2 col-form-label">備註</label>
              <div class="col-sm-10">
                <textarea type="text" class="form-control" id="remark" name="remark"  row="3"><?php
                if($pagemethod=="add"){ 
              } 
                if($pagemethod=="edit"){ echo 
                 $roomdetails->remark;
              }?>
                </textarea>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
           <?php if($pagemethod=="edit"){
                ?>
                  <input type="hidden" class="form-control" id="id" name="id" placeholder="" value="<?php 
                echo $roomdetails->id;?>">
             <?php    
              }?>
            <div class="form-group row">
                        <div class="col-sm-12">
                        <p style="font-size: 12px;"><span style="color:#616161">*為必填項目</span></p>
                        <span id="newmsg" class="text-center"></span>
                         </div>
            </div>
            
            <div class="form-group row">
                        <div class="col-sm-12 text-center">
                        <?php if($pagemethod=="add"){ 
                      ?>
                          <button type="button" class="btn  px-5  custombutton mr-5" id="btnReset">重設</button>

                        <button type="button" class="btn  px-5  custombutton" id="btnSubmit">確定</button>
                      <?php
              }?><?php if($pagemethod=="edit"){
                ?>    
                       <button type="button" class="btn  px-5  custombutton mr-5" id="btnResetUpdate">重設</button>

                        <button type="button" class="btn  px-5  custombutton" id="btnUpdate">更改</button>     
                <?php
              }?>
                      <!--   <button type="button" class="btn  px-5  custombutton" id="btnSubmit">確定</button> -->
                        </div>
            </div>
          </form>
          <!-- end input form -->
           
            <!-- end add button -->

            
        </div>
    </div>


    <script type="text/javascript">
        $(document).ready(function () {
            $('#sidebarCollapse').on('click', function () {
                $('#sidebar').toggleClass('active');
            });

            // password click
            bootstrapRevealPassword();

// Plugin to integrate in your javascript file
            function bootstrapRevealPassword() {
            $('[data-password]').closest('.form-group').addClass('position-relative').append('<span class="form-password-icon"><i class="material-icons">visibility_off</i></span>');

            $('.form-password-icon').on('click', function() {
                var clicks = $(this).data('clicks');
                if (clicks) {
                // odd clicks
                $(this).html('<span class="input-group-text "><i class="fas fa-eye-slash"></i></span>').prevAll(':input').attr('type', 'password');
                } else {
                // even clicks
                $(this).html('<span class="input-group-text "><i class="fas fa-eye"></i></span>').prevAll(':input').attr('type', 'text');
                }
                $(this).data("clicks", !clicks);
            });
            }

            // end password click

        });
    </script>
</body>

</html>