<?php 



  include('libraryPHP/site_config.php');

  include('libraryPHP/session_check_url.php');





?>


<!DOCTYPE html>

<html lang="en">



<head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">

   <title><?php echo $appName?> | <?php echo $pageTitle?></title>


 <?php echo $appFaviconHtml ?>
    <!-- theme css start -->

    <?php //include("theme_css.php"); ?>

     <?php include("commoncss.php"); ?>
    <!-- theme css end -->

    <style>

        .eye {

            position: absolute;

            right: 4%;

            transform: translate(0, -176%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword1 {

            position: absolute;

            right: 52%;

            transform: translate(0, -176%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword2 {

            position: absolute;

            right: 154%;

            transform: translate(0, -174%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword3 {

            position: absolute;

            right: 52%;

            transform: translate(0, -176%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword4 {

            position: absolute;

            right: 154%;

            transform: translate(0, -174%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword5 {

            position: absolute;

            right: 52%;

            transform: translate(0, -174%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword6 {

            position: absolute;

            right: 154%;

            transform: translate(0, -174%);

            top: auto;

            cursor: pointer;

        }
          


    </style>




</head>



<body>



    <!-- Main Wrapper -->

    <div class="main-wrapper">



        <!-- Header start  -->

        <?php include("header.php"); ?>

        <!-- /Header end -->



        <!-- Sidebar -->

        <?php include("sidebar.php"); ?>

        <!-- /Sidebar -->



        <!-- Page Wrapper -->

        <div class="page-wrapper">



            <div class="content container-fluid">



                <!-- Page Header -->

                <div class="page-header">

                    <div class="row">

                        <div class="col">

                            <h3 class="page-title">Add User</h3>

                            <ul class="breadcrumb">

                                <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
                                   <li class="breadcrumb-item"><a href="manage_user.php">User list</a></li>

                                <li class="breadcrumb-item active">Add User</li>

                            </ul>

                        </div>

                    </div>

                </div>

                <!-- /Page Header -->



                <!-- start write start -->

                <div class="col-12">



                    <div class="card">



                        <div class="card-body">

                           



                               <form method="POST" id="add_subadmin_form" class="form-horizontal"
                                                enctype="multipart/form-data">
                                                <input required="required" type="hidden" id="action" name="action"
                                                    value="add_subadmin">

                                                <div class="form-group row">

                                                    <label class="col-form-label col-md-2">Name</label>

                                                        <div class="col-md-10">

                                                            <input type="text" class="form-control" value="" placeholder="Enter  Name" name="name">

                                                        </div>

                                                    </div>

                                                


                                                    <div class="form-group row">

                                                      <label class="col-form-label col-md-2">Email</label>

                                                        <div class="col-md-10">

                                                            <input type="email" class="form-control" name="email" id="email" placeholder="Enter Email">

                                                        </div>

                                                    </div>

                                                    <div class="form-group row">

                                                        <label class="col-form-label col-md-2">Select Role</label>

                                                        <div class="col-md-10">
                                                             <select class="form-control" style="width: 100%;" name="role" id="role">
                                                                <option value="" selected hidden disabled="">Choose Role</option> 

                                                                <?php 
                                                                        $user_id    =   0; 
                                                                        $name           =   '';
                                                                        if(!empty($getEditData['role_ary'])){
                                                                        foreach($getEditData['role_ary'] as $value) {
                                                                        $user_role_id    =   $value['user_role_id'];
                                                                        $role           =   $value['role'];
                                                                  
                                                                ?>
                                                                 
                                                             <option value="<?php echo $user_role_id;?>"><?php echo $role;?></option> 

                                                                 <?php  
                                                                       }
                                                                    } 
                                                                ?>  

                                                             </select>

                                                        </div>

                                                    </div>


                                                   <!--  <div class="form-group row">

                                                        <label class="col-form-label col-md-2">Password</label>

                                                        <div class="col-md-10">

                                                           <input type="password" class="form-control" id="new_password" name="password" placeholder="Enter  Password" maxlength="16">

                                                        <span class="eye" onclick="myfunction2()">

                                                            <i class="far fa-eye-slash " id="togglePassword3"></i>

                                                            <i class="far fa-eye " id="togglePassword4" style="display:none;"></i>

                                                        </span>

                                                        </div>

                                                    </div> -->

<!-- 
                                                        <div class="form-group row">

                                                        <label class="col-form-label col-md-2">Confirm Password</label>

                                                        <div class="col-md-10">

                                                          
                                                        <input type="password" class="form-control" id="confirm_password" name="cpassword" placeholder="Enter Confirm Password" maxlength="16">

                                                        <span class="eye" onclick="myfunction3()">

                                                            <i class="far fa-eye-slash " id="togglePassword5"></i>

                                                            <i class="far fa-eye " id="togglePassword6" style="display:none;"></i>

                                                        </span>

                                                        </div>

                                                    </div> -->

                                                <div class="form-group row">

                                                    <label class="col-form-label col-md-2">Mobile No.</label>

                                                        <div class="col-md-10">

                                                            <input type="number" class="form-control" name="mobile" id="mobile" placeholder="Enter mobile number">

                                                        </div>

                                                    </div>



<!--                                                 <div class="form-group row">

                                                        <label class="col-form-label col-md-2">Privileges </label>

                                                        <div class="col-md-10">

                                 <div class="form-check-inline">
                                  <label class="form-check-label">
                                    <input type="checkbox" class="form-check-input" value="1"name="permission_option[]">&nbsp;Dashboard
                                  </label>

                                                          

                                <div class="form-check-inline">
                                  <label class="form-check-label">
                                    <input type="checkbox" class="form-check-input" value="4" name="permission_option[]">&nbsp;Manage Equipment Type
                                  </label>
                                </div>

                                 <div class="form-check-inline">
                                  <label class="form-check-label">
                                    <input type="checkbox" class="form-check-input" value="5" name="permission_option[]">&nbsp;Manage Equipment
                                  </label>
                                </div>




                                <div class="form-check-inline">
                                  <label class="form-check-label">
                                    <input type="checkbox" class="form-check-input" value="13" name="permission_option[]">&nbsp;Tabular Reports
                                </div>

                                <div class="form-check-inline">
                                  <label class="form-check-label">
                                    <input type="checkbox" class="form-check-input" value="14" name="permission_option[]">&nbsp;Analytical Reports
                                </div>




                                                        </div>



                                                    </div>
                                                      <label id="permission_option[]-error" class="error" for="permission_option[]"></label> -->






                                                       <!-- <div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="2"name="permission_option[]">&nbsp;Manage Finders
  </label>
</div>
<div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="3"name="permission_option[]">&nbsp;Manage Workers
  </label>
</div> -->


<!-- 
 <div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="6" name="permission_option[]">&nbsp;Manage Inspection Type
  </label>
</div>

 <div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="7" name="permission_option[]">&nbsp;Manage Inspection 
  </label>
</div> -->

<!-- <div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="6" name="permission_option[]">&nbsp;Manage Cities
</div>



<div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="7"name="permission_option[]">&nbsp;Manage Commission
  </label>
</div>
<div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="16" name="permission_option[]">&nbsp;Manage Subscription Plan
</div>
<div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="8" name="permission_option[]">&nbsp;Manage Jobs
  </label>
</div>

<br>
<br>

<div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="9" name="permission_option[]">&nbsp;Manage Contents
  </label>
</div>
<div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="11" name="permission_option[]">&nbsp;Manage FAQs
  </label>
</div>
<div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="12" name="permission_option[]">&nbsp;Manage Broadcast
  </label>
</div> -->
<!-- <div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="10" name="permission_option[]">&nbsp;Contact Us
  </label>
</div>

<div class="form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="15" name="permission_option[]">&nbsp;Manage Earning
  </label>
</div> -->



                                                     


                                                    <div class="form-group row">

                                                        <label class="col-form-label col-md-2"></label>

                                                        <div class="col-md-10">

                                                            <div href="#img_view">

                                                                <img src="assets/images/placeholder.png" class="img-responsive rounded-circle" name="profile_image" id="image_holder1" style="width:80px; height: 80px;" onerror="this.src='assets/images/placeholder.png'" alt="">



                                                                <a href="" class="close_my_popup"><img src=""></a>

                                                            </div>

                                                        </div>

                                                    </div>

                                                    <div class="form-group row">

                                                        <label class="col-form-label col-md-2">Profile Image</label>

                                                        <div class="col-md-10">

                                                            <input class="form-control" type="file" id="fileUpload1" name="image">

                                                            <label style="color:red;">(Note : please choose image resolution with 500X500 pixels)</label>

                                                        </div>

                                                    </div>





                                                    <!-- <div class="form-group row">

                                                        <label class="col-form-label col-md-2">Textarea</label>

                                                        <div class="col-md-10">

                                                            <textarea rows="5" cols="5" class="form-control" placeholder="Enter text here"></textarea>

                                                        </div>

                                                    </div> -->



                                                    <div class="form-group row">

                                                        <label class="col-form-label col-md-2"></label>

                                                        <div class="col-md-10">

                                                            <button class="btn btn-primary "  type="submit">Add User</button>

                                                        </div>

                                                    </div>





                                                </form>




                        </div>



                    </div>



                </div> <!-- end col -->



                <!-- start write end -->

            </div>

        </div>

        <!-- /Page Wrapper -->

        <!-- footer start -->

        <?php include("footer.php"); ?>

            <!-- footer end -->



    </div>

    <!-- /Main Wrapper -->



    <!-- sctipt start  -->

  <?php include('commonjs.php')?>

        <?php include_once('extrajs.php') ?>
    <!-- script end -->

   <script>

     jQuery.validator.addMethod("noSpace", function(value, element) { 
      return value == '' || value.trim().length != 0;  
    }, "No space please and don't leave it empty");


    $.validator.addMethod("customemail", 
    function(value, element) {
        return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(value);
    }, 
    "Enter valid email"
); 
     $('#add_subadmin_form').validate({
                    rules: {
                       
                        name: {
                            required: true,
                            minlength:3,
                            maxlength: 18,
                            noSpace: true
                        },

                     email: {
                      required: true,
                      email:false,
                      customemail: true,
                      
                      remote: {

                    url: URLAPI+'user_controller.php',

                    type: 'get',

                    data: {

                        'action': 'email_check_add',

                        'email': function() {

                            return $("#email").val();

                        },

                        

                    }

                },
               

                  },

                          
                    image:{
                        required:true,
                    },

                     role:{
                        required:true,
                    },

                    'permission_option[]':{
                        required:true,
                    },


                    mobile:{
                        required:true,
                        minlength:10,
                        maxlength:10,
                        remote: {

                    url: URLAPI+'user_controller.php',

                    type: 'get',

                    data: {

                        'action': 'mobile_check_add',

                        'mobile': function() {

                            return $("#mobile").val();

                        },
                        

                        

                    }

                },
                    },

                 

                    },
                    messages: {
                       
                        name: {
                            required: "Please enter Subadmin name",
                            minlength: "Subadmin name  must be at least 3 characters",
                            maxlength: " Maximum 16  characters  allowed in Subadmin name "
                        },
                        email: {
                      required: "Please enter  email" ,
                      remote: "Email already Exist!"
                     
                  },

                  role:{
                        required:"Please choose role",
                    },
                        
                        

                    mobile:
                    {
                       required:"Please enter Mobile Number",

                        minlength:"confirm mobile number  must be at least 10 digit long",

                        maxlength: "Please enter  maximum 10 digit  ",
                        remote:'Mobile number already exist',
                        },
                   


                    image:
                    {
                        required:'Please Choose image',
                    },

                    'permission_option[]':{
                        required:"Please select previliges",
                    },

                    


                    },
                  

                    submitHandler:function(form,e){

                       
         
              

       //e.preventDefault();
      var link=URLAPI+'manage_all_controller.php';
      var data = new FormData($(form)[0]);
      var message = msgLoading.blankMessage[language];
      console.log('message',message);

      apiRequest.postFile(link,data,message).then(function(obj){
      if(obj.success === true){
        var title ='';
        var message = obj.msg[language];
        swal_alert(title,message,"manage_user.php","success");
        // $('#add_driver').modal('hide');
        // $('#image-holder').attr('src','');
        // getUserTable('first', 'all');
        return false;

      }else{
        var title = msgTitleOperation.StaffNotAdded[language];
        var message = obj.msg[language];
        swal_alert(title,message,'#','error');
         return false;
      }
    },function(err){

      consoleProvider.log('err',err);
      var title    = msgTitleOperation.errorOnServer[language];
      var messsage = msgOperations.errorOnServer[language];
      swal_alert(title,message,"#","warning");
      return false;

    });

  }//end of submit handler
                });</script>
     <script>

        function myfunction1() {

            var x = document.getElementById("oldpassword");

            var y = document.getElementById("togglePassword1");

            var z = document.getElementById("togglePassword2");



            if (x.type === 'password') {

                x.type = "text";

                y.style.display = "none";

                z.style.display = "block";

            } else {

                x.type = "password";

                y.style.display = "block";

                z.style.display = "none";

            }

        }



        function myfunction2() {

            var x = document.getElementById("new_password");

            var y = document.getElementById("togglePassword3");

            var z = document.getElementById("togglePassword4");



            if (x.type === 'password') {

                x.type = "text";

                y.style.display = "none";

                z.style.display = "block";

            } else {

                x.type = "password";

                y.style.display = "block";

                z.style.display = "none";

            }

        }



        function myfunction3() {

            var x = document.getElementById("confirm_password");

            var y = document.getElementById("togglePassword5");

            var z = document.getElementById("togglePassword6");



            if (x.type === 'password') {

                x.type = "text";

                y.style.display = "none";

                z.style.display = "block";

            } else {

                x.type = "password";

                y.style.display = "block";

                z.style.display = "none";

            }

        }

    </script>

    <script>
        // for image validation
        $("#fileUpload1").on('change', function () {
        //----------------- Image Preview and validation code start here -------------------
        var countFiles = $(this)[0].files.length;
        if(countFiles==0){
            $(this)[0].value='';
            var image_holder = $("#image_holder1");
              $(image_holder).attr('src', ' ');
                // notifyMessage.warning('Warning!', 'This browser does not support FileReader');
                return false;
        }else{
            var imgPath = $(this)[0].value;
            var extn = imgPath.substring(imgPath.lastIndexOf('.') + 1).toLowerCase();
            var image_holder = $("#image_holder1");
            console.log('fffdfh',image_holder);
            image_holder.empty();
            console.log('123',image_holder);
            console.log('countFiles',countFiles);

            if (extn == "png" || extn == "jpg" || extn == "jpeg") {
                if (typeof (FileReader) != "undefined") {
                    for (var i = 0; i < countFiles; i++) {
                        var reader = new FileReader();
                        reader.onload = function (e) {
                            $(image_holder).attr('src', e.target.result);
                        }
                        image_holder.show();
                        reader.readAsDataURL($(this)[0].files[i]);
                    }

                }else {
                    $(this)[0].value='';
                    // notifyMessage.warning('Warning!', 'This browser does not support FileReader');
                    return false;
                }

            }else {
                $(this)[0].value='';
                swal({
                    // title: title,
                    text: 'You can choose only("jpeg","jpg","png")file',
                    icon: "warning", //error, success, info
                    button: "Ok",
                })
                return false;
            }

        }
        
        //----------------- Image Preview and validation code end here -------------------
        });
    </script>



</body>



</html>