<?php 
if(isset($taluk) && $taluk !=0)
  { $taluk; 
  }else{
  $taluk='';
  }
if(isset($panchayath) && $panchayath !=0)
  { $panchayath; 
  }else{
  $panchayath='';
  }
?>
<div id="page-wrapper">

            <div class="container-fluid">

                <!-- Page Heading -->
                <div class="row">
                    <div class="col-lg-12">
                        <h3 class="page-header">
                            New Agent
                        </h3>
                        
                    </div>
                </div>
                <!-- /.row -->

                <div class="row">
                    <div class="col-lg-6">

                        <?php $attributes = array('id' => 'addnewuser','method'=>'post');
                        echo form_open('user/insert_users', $attributes);
                        ?>
                        <div id="status_div">
                        
                        <?php if($this->session->flashdata('err')) { ?>
                        <div class="alert-info">  <?php echo $this->session->flashdata('err');?></div>
                        <?php } ?>
                        </div>

                            <div class="form-group">
                                <label>Name</label>
                                <input class="form-control" type="text" name="name" value="<?php  if(isset($name)){ echo $name;} ?>"  id="name" required="">
                                 <label class="error">
                                  <?php if(form_error('name')) { echo form_error('name'); } ?>
                                </label>
                            </div>

                            <div class="form-group">
                                <label>Email</label>
                                <input class="form-control" type="text" name="username" value="<?php  if(isset($username)){ echo $username;} ?>"  id="username" required="">
                                <label class="error">
                                  <?php if(form_error('username')) { echo form_error('username'); } ?>
                                </label>
                            </div>


                            <div class="form-group">
                                <label>Password</label>
                                <input class="form-control" type="password" name="password" value="<?php  if(isset($password)){ echo $password;} ?>"  id="password" required="" onchange="this.setCustomValidity(this.validity.patternMismatch ? this.title : ''); if(this.checkValidity()) form.confirm_password.pattern = this.value;">
                                <label class="error">
                                  <?php if(form_error('password')) { echo form_error('password'); } ?>
                                </label>
                            </div>
							<div class="form-group">
                                <label>Confirm Password</label>
                                <input class="form-control" type="password" name="confirm_password" value="<?php  if(isset($confirm_password)){ echo $confirm_password;} ?>"  id="confirm_password" required="" onchange="this.setCustomValidity(this.validity.patternMismatch ? this.title : '');">
                                <label class="error">
                                  <?php if(form_error('password')) { echo form_error('password'); } ?>
                                </label>
                            </div>
                            <div class="form-group">
                                    <label>Select Taluk</label>
                                  
                                    <?php $array=array(''=>'Select Taluk');
                                    foreach($taluk_all as $value ){

                                        $array[$value['id']] = $value['taluk_name'];
                                    }
                                    echo form_dropdown("taluk", $array, $taluk ,'class="form-control" id="taluk" onchange="get_panchayath(this.value)"');
                                     ?>
                                    <label class="error">
                                  <?php if(form_error('taluk')) { echo form_error('taluk'); } ?>
                                </label>
                            </div>
                            <div class="form-group">
                                    <label>Select Panchayath</label>
                                  
                                    <?php $array=array();
                                    echo form_dropdown("panchayath", $array, $panchayath ,'required="required" class="form-control" id="panchayath"');
                                     ?>
                                    <label class="error">
                                  <?php if(form_error('panchayath')) { echo form_error('panchayath'); } ?>
                                </label>
                            </div>



                 
                      
                      

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

                        </form>

                    </div>
                    
                </div>
                <!-- /.row -->

            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

     </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="<?php echo base_url()?>js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="<?php echo base_url()?>js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.validate.js"></script>
    <script>
    $(document).ready(function() {
        get_panchayath(<?php echo $taluk;?>,<?php echo $panchayath;?>);
       $('#status_div').delay(5000).fadeOut(3600);
      });
       
    </script>
    <script language='JavaScript' type='text/JavaScript'>
    $(document).ready(function() { 
    $("#addnewuser").validate({ 
    rules : {
    
    password: { 
               required: true, minlength: 6,maxlength: 50
                  }, 
    confirm_password: { 
                    required: true, equalTo: "#password"
                  }, 
    name : 'required',
    //username : 'required',
    taluk : 'required',
    panchayath : 'required',
    username : {
            required : true,
            email : true  },
    mobile : { required : true,
    number : true,
    minlength: 10
    }
    
    }, 
    messages : {
    password     : 'Please specify your Password',
    confirm_password : 'Please specify your Confirm Password Again',
    name :'Please specify your Name',
    //username :'Please specify your username',
    taluk :'Please specify your Taluk',
    panchayath :'Please specify your Panchayath',
    username : { 
        required : 'Please specify your username',
        email : ' Enter valid Email Address'},                   
    mobile : {  
      required : 'Please specify your Phone Number',
    number : 'Enter valid Phone Number',
    min :'Enter valid Phone Number' },
    
    }
    });
    });
    function get_panchayath(taluk_id,panchayath) {
        //alert(taluk_id);
       if (taluk_id) {
           $.ajax({
               type: "POST",
               url: "<?php echo site_url('user/get_panchayath');?>",
               data: "taluk_id=" + encodeURIComponent(taluk_id) + "&<?php echo $this->security->get_csrf_token_name(); ?>=<?php echo $this->security->get_csrf_hash(); ?>",
               success: function(panchayath_list) {
                   if (panchayath_list != 0) {
                       $('#panchayath').empty();
                       $('#panchayath').append("<option value=''>Select Panchayath</option>");
                       $.each(JSON.parse(panchayath_list), function(j, item) {
                           var opt = $('<option />');
         
                              
                               opt = "<option value='" + item.id + "'>" + item.panchayath_name + " </option>";
                      
                           $('#panchayath').append(opt);
                           $("#panchayath").val(panchayath);
                       });
                       
                   }
               },

           });
       }
   }

</script>

<?php
if(isset($taluk_a) && $taluk_a !='')
{
    $taluk_a=$taluk_a;
}else
{
    $taluk_a='';
}
?>

<style type="text/css">
.error
{
  color:rgb(238, 57, 57) !important ;
}
</style>
</body>

</html>