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

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

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

          

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

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

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


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

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

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


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

          if($('#gender').val().length !== 0){
            $("#gender").addClass(" is-valid ");
            $("#gender").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#gender";
            }
            passCheck=false;
            $("#gender").addClass(" is-invalid ");
           $("#gender").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/employeeend/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 ={
                'username':$('#username').val(),
                'password':$('#password').val(),
                'chi_name':$('#chi_name').val(),
                // 'inputadminname':$('#inputadminname').val(),
                'eng_firstname':$('#eng_firstname').val(),
                'eng_lastname':$('#eng_lastname').val(),
                'role_name':$('#role_name').val(),
                'tenant_no':$('#tenant_no').val(),
                'income_type':$('#income_type').val(),
                'income':$('#income').val(),
                'commission':$('#commission').val(),
                'gender':$('#gender').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) {

        });// $( 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;">
           <a href="/at-cms/employeeadmin">返回</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">
                <input type="text"  class="form-control" id="username" name="username" value="" placeholder="輸入登入名稱">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="password" class="col-sm-2 col-form-label">登入密碼*</label>
              <div class="col-sm-10">
                <input type="password" class="form-control" id="password" name="password" >
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="confirm_password" class="col-sm-2 col-form-label">確認登入密碼*</label>
              <div class="col-sm-10">
                <input type="password" class="form-control" id="confirm_password" name="confirm_password" >
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料或密碼和登入密碼不同</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="chi_name" class="col-sm-2 col-form-label">中文名稱*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="chi_name" name="chi_name" placeholder="輸入中文名稱">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
             <div class="form-group row">
              <label for="eng_firstname" class="col-sm-2 col-form-label">英文姓*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="eng_firstname" name="eng_firstname" placeholder="輸入英文姓">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="eng_lastname" class="col-sm-2 col-form-label">英文名*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="eng_lastname" name="eng_lastname" placeholder="輸入英文名">
                <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">
               
                <select class="select mas-select select2-offscreen" name="role_name" id="role_name" tabindex="-1"><option value="">--- 請選擇職位名稱 ---</option>
                <?php
                  foreach ($employeegroup as $row) {
                ?>
                 
                  <?php
                    if($row->name=="manager"){
                      echo ' <option value="'.$row->id.'">';
                      echo "經理";
                      echo '</option>';
                    }
                    if($row->name=="therapist"){
                      echo ' <option value="'.$row->id.'">';
                      echo "美容師";
                      echo '</option>';
                    }
                    if($row->name=="therapist/manager"){
                      echo ' <option value="'.$row->id.'">';
                      echo "美容師/經理";
                      echo '</option>';
                    }
                    if($row->name=="consultant"){
                      echo ' <option value="'.$row->id.'">';
                      echo "顧問";
                      echo '</option>';
                    }
                    if($row->name=="consultant/manager"){
                      echo ' <option value="'.$row->id.'">';
                      echo "顧問/經理";
                      echo '</option>';
                    }
                  ?>
                  
                <?php
                    }
                  ?>
                  </select>
                  <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">
                <select class="select mas-select select2-offscreen" name="tenant_no" id="tenant_no" tabindex="-1">
                <?php
                  foreach ($shop as $row) {
                ?>
                <option value="<?php echo $row->id;?>" ><?php echo $row->name;?></option>
                 <?php
                    }
                  ?>

                </select>
                <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">
                <select class="select mas-select select2-offscreen" name="income_type" id="income_type" tabindex="-1">
                  <option value="">--- 請選擇薪酬種類 ---</option>
                <?php
                  foreach ($employeeincometype as $row) {
                ?>
                <option value="<?php echo $row->id;?>" ><?php echo $row->name;?></option>
                 <?php
                    }
                  ?>

                </select>
                <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">
                <input type="text" class="form-control" id="income" name="income" placeholder="">
                <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">
                <input type="text" class="form-control" id="commission" name="commission" placeholder="">
                <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">
                 <?php
                            $st[""] = "";
                            $st["0"] = "女";
                            $st["1"] = "男";

                            echo form_dropdown('gender', $st, 0, 'id="gender" name="gender" data-placeholder="' . ' '  . '" class="form-control input-tip select2" style=""');
                            ?>
                  <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="輸入備註"></textarea>
              </div>
            </div>

            <div class="form-group row">
                        <div class="col-sm-12">
                        <p style="font-size: 12px;"><span style="color:#616161">*為必填項目<br>登入名稱為英文字或數字組成(不分大小寫)</span></p>
                        <span id="newmsg" class="text-center"></span>
                         </div>
            </div>
            
            <div class="form-group row">
                        <div class="col-sm-12 text-center">
                        <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>