<!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($('#category_code').val().length !== 0){
            $("#category_code").addClass(" is-valid ");
            $("#category_code").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#category_code";
            }
            passCheck=false;
            $("#category_code").addClass(" is-invalid ");
           $("#category_code").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($('#code').val().length !== 0){
            $("#code").addClass(" is-valid ");
            $("#code").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#code";
            }
            passCheck=false;
            $("#code").addClass(" is-invalid ");
           $("#code").removeClass(" is-valid ");
          }


          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($('#work').val().length !== 0){
            $("#work").addClass(" is-valid ");
            $("#work").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#work";
            }
            passCheck=false;
            $("#work").addClass(" is-invalid ");
           $("#work").removeClass(" is-valid ");
          }

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

          if($('#time').val().length !== 0){
            $("#time").addClass(" is-valid ");
            $("#time").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#time";
            }
            passCheck=false;
            $("#time").addClass(" is-invalid ");
           $("#time").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/brservicesend/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

            // }
            // $checkeddebate=0;
            // if($('#no_credit_rebate').is(':checked')){
            //     $checkeddebate=1;
            // }
            // else
            // {
            //   $checkeddebate=0;
            // }

            var postData ={
                'category_code':$('#category_code').val(),
                'code':$('#code').val(),
                'name':$('#name').val(),
                'work':$('#work').val(),
                'description':$('#description').val(),
                // 'inputadminname':$('#inputadminname').val(),
                'price':$('#price').val(),
                // 'no_credit_rebate':$('#no_credit_rebate').val(),
                // 'no_credit_rebate':$checkeddebate ,
                'time':$('#time').val(),
                'remark':$('#remark').val(),
                'service_type':$('#service_type').val(),
                'point':$('#point').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) {

            $('#btnReset').click(function() {
                  $('#category_code').val('1');
                  $('#code').val('lastestcode');
                  $('#name').val('');
                  $('#description').val('');
                  $('#work').val('2');
                  $('#price').val('');
                  // $('#no_credit_rebate').val('');
                  $('#time').val('60');
                  $('#remark').val('');
              });


              //refresh update
              $('#btnResetUpdate').click(function() {
                  location.reload();
              });

              //end refresh updae


              //button update

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


          if($('#category_code').val().length !== 0){
            $("#category_code").addClass(" is-valid ");
            $("#category_code").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#category_code";
            }
            passCheck=false;
            $("#category_code").addClass(" is-invalid ");
           $("#category_code").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($('#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($('#work').val().length !== 0){
            $("#work").addClass(" is-valid ");
            $("#work").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#work";
            }
            passCheck=false;
            $("#work").addClass(" is-invalid ");
           $("#work").removeClass(" is-valid ");
          }

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

          if($('#time').val().length !== 0){
            $("#time").addClass(" is-valid ");
            $("#time").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#time";
            }
            passCheck=false;
            $("#time").addClass(" is-invalid ");
           $("#time").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/brservicesend/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

            // }
            // $checkeddebate=0;
            // if($('#no_credit_rebate').is(':checked')){
            //     $checkeddebate=1;
            // }
            // else
            // {
            //   $checkeddebate=0;
            // }

            var postData ={
                'category_code':$('#category_code').val(),
                'code':$('#code').val(),
                'name':$('#name').val(),
                'work':$('#work').val(),
                'description':$('#description').val(),
                // 'inputadminname':$('#inputadminname').val(),
                'price':$('#price').val(),
                // 'no_credit_rebate':$('#no_credit_rebate').val(),
                // 'no_credit_rebate':$checkeddebate ,
                'time':$('#time').val(),
                'remark':$('#remark').val(),
                'point':$('#point').val(),
                'service_type':$('#service_type').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(event) {
              //end button update



        });// $( 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: #ffffff;">
          <div class="title"><?php if ($pagemethod == "add") {
	echo "新增服務";
}?>
              <?php if ($pagemethod == "edit") {
	echo "更改服務";
}?></div>

           <div style="" class="menubar2  p-2">

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

         </div>
            <!-- add button -->
            <!-- <h5>新增服務</h5> -->
            <!-- input form -->
            <form>
            <div class="form-group row formrowdiv">
              <div class="col-sm-2 col-form-label formleftdiv" for="username" style="" >服務種類
            <!--   <label for="username" class="col-sm-2 col-form-label">服務種類*</label> --></div>
              <div class="col-sm-10 formrightdivleft " style="    ">
                <div class="formrightdiv">

             <select class="select mas-select select2-offscreen formselectbox form-control" name="category_code" id="category_code" style="width: auto;" tabindex="-1" >
              <option value="1" <?php if ($pagemethod == "edit") {
	if ($servicesdetails->category_id == "1") {echo "selected";}
}?>>FT-試做療程</option>
              <option value="2" <?php if ($pagemethod == "edit") {
	if ($servicesdetails->category_id == "2") {echo "selected";}
}?>>T-療程</option>
            </select>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有資料</div>
              </div>
            </div>
            </div>
            <div class="form-group row">
              <label for="name" class="col-sm-2 col-form-label">服務編號*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="code" name="code" placeholder="輸入服務編號" value="<?php if ($pagemethod == "edit") {
	echo
	$servicesdetails->code;
}?>">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有資料</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="name" class="col-sm-2 col-form-label">服務項目*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="name" name="name" placeholder="輸入服務項目" value="<?php if ($pagemethod == "edit") {
	echo
	$servicesdetails->name;
}?>">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有資料</div>
              </div>
            </div>
            <!-- added service row -->

              <div class="form-group row formrowdiv">
              <div class="col-sm-2 col-form-label formleftdiv" for="service_type" style="" >療程種類
            <!--   <label for="username" class="col-sm-2 col-form-label">療程種類*</label> --></div>
              <div class="col-sm-10 formrightdivleft " style="    ">
                <div class="formrightdiv">

             <select class="select mas-select select2-offscreen formselectbox form-control" name="service_type" id="service_type" style="width: auto;" tabindex="-1" >
              <option value="" <?php if ($pagemethod == "edit") {
	if (empty($servicesdetails->service_type)) {echo "selected";}
}?>></option>
              <option value="1" <?php if ($pagemethod == "edit") {
	if ($servicesdetails->service_type == "1") {echo "selected";}
}?>>儀器</option>
              <option value="2" <?php if ($pagemethod == "edit") {
	if ($servicesdetails->service_type == "2") {echo "selected";}
}?>>手工</option>
            </select>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有資料</div>
              </div>
            </div>
            </div>
            <!-- end added service row -->
             <div class="form-group row">
              <label for="description" class="col-sm-2 col-form-label">內容</label>
              <div class="col-sm-10">
                <textarea  type="text" class="form-control" id="description" name="description" rows="4" cols="50" placeholder=""><?php if ($pagemethod == "edit") {
	echo
	$servicesdetails->description;
}?></textarea>
              </div>
            </div>
            <div class="form-group row">
              <label for="work" class="col-sm-2 col-form-label">工數*</label>
              <div class="col-sm-10">
             <select class="select mas-select select2-offscreen form-control" name="work" id="work" tabindex="-1" style="width: auto;">
              <option value="0" <?php if ($pagemethod == "edit") {
	if ($servicesdetails->work == "0") {echo "selected";}
}?>>0</option>
              <option value="3" <?php if ($pagemethod == "edit") {
	if ($servicesdetails->work == "3") {echo "selected";}
}?>>0.2</option>
              <option value="4" <?php if ($pagemethod == "edit") {
	if ($servicesdetails->work == "4") {echo "selected";}
}?>>0.3</option>
              <option value="1" <?php if ($pagemethod == "edit") {
	if ($servicesdetails->work == "1") {echo "selected";}
}?>>0.5</option>
              <option value="2"
              <?php if ($pagemethod == "add") {
	echo "selected";
}?>
              <?php if ($pagemethod == "edit") {
	if ($servicesdetails->work == "2") {echo "selected";}
}?>>1</option>
              <option value="5"
              <?php if ($pagemethod == "edit") {
	if ($servicesdetails->work == "5") {echo "selected";}
}?>>2</option>

            </select>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有資料</div>
              </div>
            </div>
             <div class="form-group row">
              <label for="price" class="col-sm-2 col-form-label">價錢*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="price" name="price" placeholder="" value="<?php if ($pagemethod == "add") {
	echo "0";
}?><?php if ($pagemethod == "edit") {
	echo floatval($servicesdetails->price);
}?>">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有資料</div>
              </div>
            </div>

           <!--  <div class="form-group row">
              <label for="no_credit_rebate" class="col-sm-2 col-form-label">沒有積分回贈</label>
              <div class="col-sm-10">
                 <input type="checkbox" id="no_credit_rebate" name="no_credit_rebate" value="1"  <?php if ($pagemethod == "add") {
	echo "checked";
}?><?php if ($pagemethod == "edit") {
	if ($servicesdetails->no_credit_rebate == 1) {
		echo "checked";
	}
}?>>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料或密碼和登入密碼不同</div>
              </div>
            </div> -->



              <div class="form-group row">
              <label for="no_credit_rebate" class="col-sm-2 col-form-label">無限次數</label>
              <div class="col-sm-10">
                 <input type="checkbox" id="no_limit_package" name="no_limit_package" value="1"  <?php if ($pagemethod == "add") {
	// echo "checked";
}?><?php if ($pagemethod == "edit") {
	if ($servicesdetails->no_limit_package == 1) {
		echo "checked";
	}
}?>>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料或密碼和登入密碼不同</div>
              </div>
            </div>


             <div class="form-group row">
              <label for="time" class="col-sm-2 col-form-label">時間*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="time" name="time" placeholder="" value="<?php if ($pagemethod == "add") {
	echo "60";
}?><?php if ($pagemethod == "edit") {
	// if($servicesdetails->no_credit_rebate==1){

	echo floatval($servicesdetails->time);

	// }
}?>">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有資料</div>
              </div>
            </div>


            <div class="form-group row">
              <label for="point" class="col-sm-2 col-form-label">積分*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="point" name="point" placeholder="" value="<?php if ($pagemethod == "add") {

}?><?php if ($pagemethod == "edit") {
	// if($servicesdetails->no_credit_rebate==1){

	echo floatval($servicesdetails->point);

	// }
}?>">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有資料</div>
              </div>
            </div>

            <div class="form-group row">
              <label for="inputPassword" class="col-sm-2 col-form-label">備註</label>
              <div class="col-sm-10">
                <textarea  type="text" class="form-control" id="remark" name="remark" rows="4" cols="50" placeholder="輸入備註"><?php if ($pagemethod == "add") {
	echo "";
}?><?php if ($pagemethod == "edit") {
	// if($servicesdetails->no_credit_rebate==1){

	echo $servicesdetails->remark;

	// }
}?></textarea>
              </div>
            </div>

              <?php if ($pagemethod == "edit") {
	?>
                  <input type="hidden" class="form-control" id="id" name="id" placeholder="" value="<?php
echo $servicesdetails->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
}?>

                        </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>