<?php 

if(isset($user['taluk']) && $user['taluk'] !=0)
  { 
    $taluk=$user['taluk'];
  }else{
  $taluk='';
  }
if(isset($user['panchayath']) && $user['panchayath'] !=0)
  {  $panchayath=$user['panchayath'];
  }else{
  $panchayath='';
  }
  
?>
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.validate.js"></script>


        <div id="page-wrapper">

            <div class="container-fluid">

                <!-- Page Heading -->
                <div class="row">
                    <div class="col-lg-12">
                      <h3 class="page-header">
                            Update profile 
                        </h3>
                       <!--<a href="javascript:history.back()" class="btn btn-primary pull-right" >Back</a>-->
                        
                    </div>
                    
                </div>
                <!-- /.row -->

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

                        <?php $attributes = array('id' => 'addnewuser','method'=>'post');
                        echo form_open('user/edit_user_change', $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($user['name'])){ echo $user['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($user['username'])){ echo $user['username'];} ?>"  id="username" required="">
                                <label class="error">
                                  <?php if(form_error('username')) { echo form_error('username'); } ?>
                                </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>
                            <input type="hidden" value="<?php echo $user['id']?>" name="id">
                          

                            <button type="submit"  class="btn btn-primary">EDIT</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 language='JavaScript' type='text/JavaScript'>
        $(document).ready(function() {  
        $("#addnewuser").validate({ 
          rules : {
    
		
		name : 'required',
		taluk : 'required',
        panchayath : 'required',
		username : {
        required:true,
		email : true  },
		
		
		}, 
		messages : {
		
		name :'Please specify your Name',
        taluk :'Please specify your Taluk',
        panchayath :'Please specify your Panchayath',
		username : { 
        required:'Please specify your Email Address',    
		email : ' Enter valid Email Address'},                   
		
		
		}
        });
        });
    function get_panchayath(taluk_id,panchayath) {

       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>
    <script type="text/javascript">
    $(document).ready(function() {
        get_panchayath(<?php echo $user['taluk'];?>,<?php echo $user['panchayath'];?>);
     $('#status_div').delay(5000).fadeOut(3600);
     });
    </script>
    <style type="text/css">
    .error
    {
      color:rgb(238, 57, 57) !important ;
    }
    </style>
</body>

</html>