<?php
session_start();
include '../assets/constant/config.php';

try {
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
  echo "Connection failed: " . $e->getMessage();
}
?>
<?php include('include/sidebar.php'); ?>

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

<!--  connect author at mdkhairnar92@gmail.com  -->

<div class="page-content-wrapper ">

  <div class="container-fluid">

    <div class="row">
      <div class="col-sm-12">
        <div class="page-title-box">
          <div class="btn-group float-right">


          </div>
          <h4 class="page-title">Add User</h4>
        </div>
      </div>
      <div class="clearfix"></div>
    </div>
    <!-- end page title end breadcrumb -->
    <div class="row">
      <div class="col-lg-12">
        <div class="card">
          <div class="card-body">

            <div class="tab-content">

              <div class="tab-pane active p-3" id="home" role="tabpanel">
                <form name="myform" action="app/user_crud.php" class="row" method="POST" enctype="multipart/form-data" onsubmit="return validation()" id="add_service">

                  

                  <div class="form-group col-md-6">
                    <label class="control-label">Full Name<span class="text-danger">*</span></label>
                    <input class="form-control" type="text" name="username" placeholder="enter a name ">
                  </div>
                         <div class="form-group col-sm-6">
                         <label class="control-label">Gender<span class="text-danger">*</span></label>
                          <select class="form-control" name="gender">
                        <option value="">Select gender</option>
                        <option value="1">Male</option>
                        <option value="2">Female</option>
                       
                        </select>
                        </div>

                   <div class="form-group col-md-6">
                    <label class="control-label">Photo<span class="text-danger">*(file size must be less than 500 x 400 pixel)</span></label>
                    <input class="form-control" type="file" name="photo" >
                  </div> 
                   <div class="form-group col-md-6">
                    <label class="control-label">Phone <span class="text-danger">*</span></label>
                    <input class="form-control" type="text" name="mobileno" placeholder="enter a phone number ">
                  </div>



                  <div class="form-group col-md-6">
                    <label class="control-label">Email <span class="text-danger">*</span></label>
                    <input class="form-control" type="email" name="email" placeholder="enter a email ">
                  </div>
              
              <div class="form-group col-md-6">
                    <label class="control-label">Password <span class="text-danger">*</span></label>
                    <input class="form-control" type="password" name="password" placeholder="enter password ">
                  </div>

                 <div class="form-group col-md-6">
                    <label class="control-label"> Repeat Password <span class="text-danger">*</span></label>
                    <input class="form-control" type="password" name="repassword" placeholder="enter repeat password ">
                  </div>


                              <div class="form-group col-md-6">
                              <label for="id_label_multiple">Role<span class="text-danger">*</span> </label>
                              <select class="form-control postName" id="role" aria-label="Default select example" type="text" name="role" >
                              <option value="">Select Role</option>
                               <?php    
                                $sql1=$conn->prepare("select * from `groups` where delete_status='0' ");
                                $sql1->execute();
                                $row1=$sql1->fetchAll();
                                //print_r($row);
                                //exit;
                                foreach ($row1 as $key1) {?>
                                <option value="<?php echo $key1['id'];?> ">
                                       <?php echo $key1['name'];?>
                                        </option>
                                    <?php } ?>
                              </select>
                           </div>

              <div class="form-group col-md-6">
                                    <label>Address <span class="text-danger">*</span></label>
                                    <textarea name="address" id="editor" class="form-control text-area-5" placeholder="Enter Address"></textarea>
                                     </div>
                  
                 <div class="form-group col-md-6">
                                    <label>Notes <span class="text-danger">*</span></label>
                                    <textarea name="notes" id="editor1" cols="30" rows="10" class="form-control text-area-5" placeholder="Enter Notes"></textarea>
                                     </div>
                 
                           <div class="form-group col-md-12">

                    <button class="btn btn-primary" type="submit" name="submit1" onclick="addService()">Save</button>

                  </div>
                </form>
              </div>


            </div>

          </div>
        </div><!--end card-->
      </div><!--end col-->
    </div><!--end row-->
  </div> <!-- Page content Wrapper -->
</div> <!-- content -->

<?php include('include/footer.php'); ?>
<!--  Author Name: Mayuri K. 
 for any PHP, Codeignitor or Laravel website or software development contact me at mayuri.infospace@gmail.com  -->



<script type="text/javascript">
  function addService() {
    jQuery.validator.addMethod("alphanumeric", function(value, element) {
      return this.optional(element) || /^(?=.*[a-zA-Z])[a-zA-Z0-9\s!@#$%^&*()_-]+$/.test(value);
    }, "Please enter alphabet characters only");

    jQuery.validator.addMethod("lettersonly", function(value, element) {
      // Check if the value is empty
      if (value.trim() === "") {
        return false;
      }
      return /^[a-zA-Z\s]*$/.test(value);
    }, "Please enter alphabet characters only");
    $('#add_service').validate({
      rules: {
        username: {
          required: true,
           
        },

        gender: {
          required: true
        },
        mobileno: {
          required: true
        },
        email: {
          required: true
        },
        password: {
          required: true
        },
        repassword: {
          required: true
        },
        role: {
          required: true
        },
        address: {
          required: true
        },
        notes: {
          required: true
        }

      },
      messages: {
        username: {
          required: "Please enter a heading",
          pattern: "Only alphanumeric characters and spaces are allowed"
        },

        address: {
          required: "Please enter a short_content ",
          pattern: "Only alphanumeric characters and spaces are allowed"
        },
        notes: {
          required: "Please enter a content",
          pattern: "Only alphanumeric characters and spaces are allowed"
        },
        password: {
          required: "Please enter a metatitle",
        },
        repassword: {
          required: "Please enter a metadescription",
        }
       
       
      }
    });
  };
</script>