<?php $this->load->view('includes/header');
?>
<div class="page-title">
<h2><span>Edit Kisaan</span></h2>
  <div class="buttons">
    <?php echo anchor("sitepanel/kisans/", '<span>Cancel</span>', 'class="btn btn-danger pull-right" '); ?>
    <a href="javascript:void(0);" class="btn btn-success addbtn pull-right"><span>Update</span></a>    
  </div>
</div>
<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap">
  <div class="row">
    <div class="col-md-12">
      <div class="panel panel-default">
        <div class="panel-body">
          <?php echo form_open_multipart("sitepanel/kisans/edit/".$mres['customers_id'], 'class="form-horizontal" id="catForm"'); ?>  
           <?php  //echo validation_message();
                  //echo error_message(); ?>
          <input type="hidden" name="country_id" id="country" value="105"> 
          <?php /*
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Country</label>
            <div class="col-md-6">
            <?php $country_id=set_value("country_id"); ?>                                                                                                                                                        
              <select name="country_id" class="form-control" id="country">
                <option value="">--Select Country--</option>
                <?php
                if ($country) {
                  foreach ($country as $cnt) {
                    if ($cnt['id'] == $country_id) {
                      $sel = "selected";
                    } else {
                      $sel = "";
                    }
                    ?>
                    <option value="<?php echo $cnt['id']; ?>" <?php echo $sel; ?>><?php echo $cnt['name']; ?></option>
                    <?php
                  }
                }
                ?>
              </select>
              <?php echo form_error("country_id");?>
            </div>
          </div>*/?>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>State</label>
            <div class="col-md-6">
            <?php $state_id=set_value("state_id",$mres['state_id']); ?>
              <select name="state_id" class="form-control" id="state">
                <option value="">--Select State--</option>
                <?php
                if (is_array($states) && !empty($states)) {
                  foreach ($states as $state) {
                    if ($state['id'] == $state_id) {
                      $sel = 'selected="selected"';
                    } else {
                      $sel = "";
                    }
                    ?>
                    <option value="<?php echo $state['id']; ?>" <?php echo $sel; ?>><?php echo $state['name']; ?></option>
                    <?php
                  }
                }
                ?>
              </select>
              <?php echo form_error("state_id");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>District</label>
            <div class="col-md-6">
              <?php $city_id=set_value("city_id",$mres['city_id']); ?>
                <select name="city_id" class="form-control" id="city">
                  <option value="">--Select District--</option>
                  <?php 
                  if ($cities) {
                    foreach ($cities as $city) {
                      if ($city['id'] == $city_id) {
                        $sel = "selected";
                      } else {
                        $sel = "";
                      }
                      ?>
                      <option value="<?php echo $city['id'] ?>" <?php echo $sel; ?>><?php echo $city['city']; ?></option>
                      <?php
                    }
                  }
                  ?>
                </select>
                <?php echo form_error("city_id");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Block</label>
            <div class="col-md-6">
              <?php $block_id=set_value("block_id",$mres['block_id']); ?>
                <select name="block_id" class="form-control" id="block">
                  <option value="">--Select Block--</option>
                  <?php 
                  if ($blocks) {
                    foreach ($blocks as $block) {
                      if ($block['id'] == $block_id) {
                        $sel = "selected";
                      } else {
                        $sel = "";
                      }
                      ?>
                      <option value="<?php echo $block['id'] ?>" <?php echo $sel; ?>><?php echo $block['name']; ?></option>
                      <?php
                    }
                  }
                  ?>
                </select>
                <?php echo form_error("block_id");?>
            </div>
          </div>

          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Panchayat</label>
            <div class="col-md-6">
              <?php $panchayat_id=set_value("panchayat_id",$mres['panchayat_id']); ?>
                <select name="panchayat_id" class="form-control" id="panchayat">
                  <option value="">--Select Panchayat--</option>
                  <?php 
                  if ($panchayats) {
                    foreach ($panchayats as $panchayat) {
                      if ($panchayat['id'] == $panchayat_id) {
                        $sel = "selected";
                      } else {
                        $sel = "";
                      }
                      ?>
                      <option value="<?php echo $panchayat['id'] ?>" <?php echo $sel; ?>><?php echo $panchayat['name']; ?></option>
                      <?php
                    }
                  }
                  ?>
                </select>
                <?php echo form_error("panchayat_id");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Village</label>
            <div class="col-md-6">
              <?php $village_id=set_value("village_id",$mres['village_id']); ?>
                <select name="village_id" class="form-control" id="village">
                  <option value="">--Select Village--</option>
                  <?php 
                  if ($villages) {
                    foreach ($villages as $village) {
                      if ($village['id'] == $village_id) {
                        $sel = "selected";
                      } else {
                        $sel = "";
                      }
                      ?>
                      <option value="<?php echo $village['id'] ?>" <?php echo $sel; ?>><?php echo $village['name']; ?></option>
                      <?php
                    }
                  }
                  ?>
                </select>
                <?php echo form_error("village_id");?>
            </div>
          </div>
          <?php if($this->session->userdata('admin_type')=='2'){ ?>
            <input type="hidden" name="district_head_id" id="district_head_id" value="<?php echo $this->session->userdata('admin_id');?>">
            <?php }else if($this->session->userdata('admin_type')=='3' || $this->session->userdata('admin_type')=='4'){ ?>
            <input type="hidden" name="district_head_id" id="district_head_id" value="<?php echo $this->session->userdata('district_head_id');?>">
          <?php }else{?>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>District Head</label>
              <div class="col-md-6">
              <?php $district_head_id=set_value("district_head_id",$mres['district_head_id']); ?>
                <select name="district_head_id" class="form-control" id="district_head_id">
                  <option value="">--Select District Head--</option>
                  <?php
                  if (is_array($district_heads) && !empty($district_heads)) {
                    foreach ($district_heads as $district_head) {
                      if ($district_head['admin_id'] == $district_head_id) {
                        $sel = "selected";
                      } else {
                        $sel = "";
                      }
                      ?>
                      <option value="<?php echo $district_head['admin_id']; ?>" <?php echo $sel; ?>><?php echo $district_head['admin_name']; ?></option>
                      <?php
                    }
                  }
                  ?>
                </select>
              <?php echo form_error("district_head_id");?>
            </div>
          </div>
          <?php } ?>
          <?php if($this->session->userdata('admin_type')=='3'){ ?>
            <input type="hidden" name="kisan_mitra_id" id="kisan_mitra_id" value="<?php echo $this->session->userdata('admin_id');?>">
            <?php }else if($this->session->userdata('admin_type')=='4'){ ?>
            <input type="hidden" name="kisan_mitra_id" id="kisan_mitra_id" value="<?php echo $this->session->userdata('kisan_mitra_id');?>">
          <?php }else{?>
          <div class="form-group">
              <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Kisaan Mitra</label>
              <div class="col-md-6">
              <?php $kisan_mitra_id=set_value("kisan_mitra_id",$mres['kisan_mitra_id']); ?>
                <select name="kisan_mitra_id" class="form-control" id="kisan_mitra_id">
                  <option value="">--Select Kisaan Mitra--</option>
                  <?php
                  if (is_array($kisan_mitras) && !empty($kisan_mitras)) {
                    foreach ($kisan_mitras as $kisan_mitra) {
                      if ($kisan_mitra['admin_id'] == $kisan_mitra_id) {
                        $sel = "selected";
                      } else {
                        $sel = "";
                      }
                      ?>
                      <option value="<?php echo $kisan_mitra['admin_id']; ?>" <?php echo $sel; ?>><?php echo $kisan_mitra['admin_name']; ?></option>
                      <?php
                    }
                  }
                  ?>
                </select>
                <?php echo form_error("kisan_mitra_id");?>
              </div>
          </div>
          <?php } ?>
          <?php if($this->session->userdata('admin_type')=='4'){ ?>
            <input type="hidden" name="kisan_sahayak_id" id="kisan_sahayak_id" value="<?php echo $this->session->userdata('admin_id');?>">
          <?php }else{ ?>
          <div class="form-group">
              <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>KM Sahyogi</label>
              <div class="col-md-6">
              <?php $kisan_sahayak_id=set_value("kisan_sahayak_id",$mres['kisan_sahayak_id']); ?>
                <select name="kisan_sahayak_id" class="form-control" id="kisan_sahayak_id">
                  <option value="">--Select KM Sahyogi--</option>
                  <?php
                  if (is_array($kisan_sahayaks) && !empty($kisan_sahayaks)) {
                    foreach ($kisan_sahayaks as $kisan_sahayak) {
                      if ($kisan_sahayak['admin_id'] == $kisan_sahayak_id) {
                        $sel = "selected";
                      } else {
                        $sel = "";
                      }
                      ?>
                      <option value="<?php echo $kisan_sahayak['admin_id']; ?>" <?php echo $sel; ?>><?php echo $kisan_sahayak['admin_name']; ?></option>
                      <?php
                    }
                  }
                  ?>
                </select>
                <?php echo form_error("kisan_sahayak_id");?>
              </div>
          </div>
          <?php } ?>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Name</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="first_name" id="first_name" value="<?php echo set_value("first_name",$mres['first_name']);?>"> 
              <?php echo form_error("first_name");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Father's Name</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="fathers_name" id="fathers_name" value="<?php echo set_value("fathers_name",$mres['fathers_name']);?>"> 
              <?php echo form_error("fathers_name");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>D.O.B.</label>
            <div class="col-md-6">                                     
              <input class="form-control" name="birth_date" id="birth_date"  type="date" min="1930-01-01" max="<?php echo date('Y-m-d');?>" value="<?php echo set_value("birth_date",$mres['birth_date']);?>"> 
              <?php echo form_error("birth_date");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Mobile Number</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="mobile_number" id="mobile_number" value="<?php echo set_value("mobile_number",$mres['mobile_number']);?>"> 
              <?php echo form_error("mobile_number");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Alt Name</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="alt_name" id="alt_name" value="<?php echo set_value("alt_name",$mres['alt_name']);?>"> 
              <?php echo form_error("alt_name");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Alt Mobile Number</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="alt_mobile" id="alt_mobile" value="<?php echo set_value("alt_mobile",$mres['alt_mobile']);?>"> 
              <?php echo form_error("alt_mobile");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Relationship</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="relationship" id="relationship" value="<?php echo set_value("relationship",$mres['relationship']);?>"> 
              <?php echo form_error("relationship");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Land Size (Owned)</label>
            <div class="col-md-3">                                     
              <input type="text" class="form-control lsowned" name="land_size_owned" id="land_size_owned" value="<?php echo set_value("land_size_owned",$mres['land_size_owned']);?>"> 
              <?php echo form_error("land_size_owned");?>
            </div>
            <div class="col-md-3">
            <?php $land_size_owned_unit=set_value("land_size_owned_unit",$mres['land_size_owned_unit']); ?>  
              <select name="land_size_owned_unit" id="land_size_owned_unit"  class="form-control land_size_unit_id">
                <?php foreach($landSizeUnitArray as $key=>$val){
                      if ($val == $land_size_owned_unit) {
                        $sel = "selected";
                      } else {
                        $sel = "";
                      }
                  ?>
                    <option value="<?php echo $val;?>" <?php echo $sel; ?>><?php echo $key;?></option>
                <?php } ?>
              </select>                                   
              <?php echo form_error("land_size_owned_unit");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Land Size (Leased)</label>
            <div class="col-md-3">                                     
              <input type="text" class="form-control lsowned" name="land_size_leased" id="land_size_leased" value="<?php echo set_value("land_size_leased",$mres['land_size_leased']);?>"> 
              <?php echo form_error("land_size_leased");?>
            </div>
            <div class="col-md-3">  
            <?php $land_size_leased_unit=set_value("land_size_owned_unit",$mres['land_size_owned_unit']); ?>  
              <select name="land_size_leased_unit" id="land_size_leased_unit"  class="form-control land_size_unit_id">
              <?php foreach($landSizeUnitArray as $key=>$val){
                      if ($val == $land_size_leased_unit) {
                        $sel = "selected";
                      } else {
                        $sel = "";
                      }
                  ?>
                    <option value="<?php echo $val;?>" <?php echo $sel; ?>><?php echo $key;?></option>
                <?php } ?>
              </select>                                   
              <?php echo form_error("land_size_leased_unit");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Total Land</label>
            <div class="col-md-3">                                     
              <input type="text" class="form-control" name="total_land_size" id="total_land_size" readonly value="<?php echo set_value("total_land_size",$mres['total_land_size']);?>"> 
              <?php echo form_error("total_land_size");?>
            </div>
            <div class="col-md-3"> 
              <?php $total_land_size_unit=set_value("total_land_size_unit",$mres['total_land_size_unit']); ?>  
              <select name="total_land_size_unit" id="total_land_size_unit" class="form-control land_size_unit_id">
              <?php foreach($landSizeUnitArray as $key=>$val){
                      if ($val == $total_land_size_unit) {
                        $sel = "selected";
                      } else {
                        $sel = "";
                      }
                  ?>
                    <option value="<?php echo $val;?>" <?php echo $sel; ?>><?php echo $key;?></option>
                <?php } ?>
              </select>                                   
              <?php echo form_error("total_land_size_unit");?>
            </div>
          </div>
          <div class="form-group">
          <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Current Annual Income</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="current_annual_income" id="current_annual_income" value="<?php echo set_value("current_annual_income",$mres['current_annual_income']);?>"> 
              <?php echo form_error("current_annual_income");?>
            </div>
          </div>
          <div class="form-group" style="background:#eee"  style="width:100%">
            <label class="col-md-3 control-label"><strong>Crops</strong></label>
          </div>
          <?php
            $sellingMonthsArray=$this->config->item('sellingMonthsArray');
            $category_ids=explode(",",$cropsRes['category_id']);
            $qty_per_years=explode(",",$cropsRes['qty_per_year']);
            $selling_price_msps=explode(",",$cropsRes['selling_price_msp']);
            $selling_months=explode(",",$cropsRes['selling_month']);
          ?>
          <div class="form-group">
            <?php for($i=0;$i<count($category_ids);$i++){ ?>
            <div class="row pull-left" style="padding-bottom: 15px; width:100%;">
              <div class="col-md-3">
                <select name="category_id[]" size="1" class="form-control">
                    <?php echo get_nested_dropdown_menu(0,$category_ids[$i]); ?>
                </select>
              </div>
              <div class="col-md-3">
                <input type="text" class="form-control" name="qty_per_year[]" id="qty_per_year" value="<?php echo set_value("qty_per_year",$qty_per_years[$i]);?>" Placeholder="Qty. Per Year"> 
              </div>
              <div class="col-md-3">
                <input type="text" class="form-control" name="selling_price_msp[]" id="selling_price_msp" value="<?php echo set_value("selling_price_msp",$selling_price_msps[$i]);?>" Placeholder="Selling Price (MSP)"> 
              </div>
              <div class="col-md-2"> 
                  <?php $selling_month=set_value("selling_month",$selling_months[$i]); ?>  
                  <select name="selling_month[]" id="selling_month" class="form-control">
                  <?php foreach($sellingMonthsArray as $val){
                          if ($val == $selling_month) {
                            $sel = "selected";
                          } else {
                            $sel = "";
                          }
                      ?>
                        <option value="<?php echo $val;?>" <?php echo $sel; ?>><?php echo $val;?></option>
                    <?php } ?>
                  </select>                                   
              </div>
              <div class="col-md-1">
                <?php /*<a href="javascript:void(0);" class="btn add-more">Add more</a> */ ?>
              </div>
            <div>
            <?php } ?>
          </div>
          <div class="clearfix"></div>
            </div>

            <div class="form-group"   style="width:100%"> </div>
          <div class="form-group" style="background:#eee"  style="width:100%">
                <label class="col-md-3 control-label"><strong>KYC Docs</strong></label>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Aadhar Card</label>
            <div class="col-md-2 col-xs-12">
              <a class="file-input-wrapper btn btn-default  fileinput btn-primary"><span>Browse file</span><input type="file" class="fileinput btn-primary" name="aadhar_card" id="aadhar_card" title="Browse file" accept="image/*"></a>
              <?php if($mres['aadhar_card']){
                $product_path = "user/" . $mres['aadhar_card']; ?>                                
              <a href="#" data-toggle="modal" data-target=".image_pop" class="pull-right">
              <img src="<?php echo base_url() . 'uploaded-files/' . $product_path; ?>" width="50" class="img-responsive img-rounded center-block" alt="">
              </a>
              <?php } ?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>PAN Card</label>
            <div class="col-md-2 col-xs-12">
              <a class="file-input-wrapper btn btn-default  fileinput btn-primary"><span>Browse file</span><input type="file" class="fileinput btn-primary" name="pan_card" id="pan_card" title="Browse file" accept="image/*"></a>
              <?php if($mres['pan_card']){
                $product_path = "user/" . $mres['pan_card']; ?>                                
              <a href="#" data-toggle="modal" data-target=".image_pop" class="pull-right">
              <img src="<?php echo base_url() . 'uploaded-files/' . $product_path; ?>" width="50" class="img-responsive img-rounded center-block" alt="">
              </a>
              <?php } ?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Cancelled Cheque</label>
            <div class="col-md-2 col-xs-12">
              <a class="file-input-wrapper btn btn-default  fileinput btn-primary"><span>Browse file</span><input type="file" class="fileinput btn-primary" name="cancelled_Cheque" id="cancelled_Cheque" title="Browse file" accept="image/*"></a>
              <?php if($mres['cancelled_Cheque']){
                $product_path = "user/" . $mres['cancelled_Cheque']; ?>                                
              <a href="#" data-toggle="modal" data-target=".image_pop" class="pull-right">
              <img src="<?php echo base_url() . 'uploaded-files/' . $product_path; ?>" width="50" class="img-responsive img-rounded center-block" alt="">
              </a>
              <?php } ?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Address Proof</label>
            <div class="col-md-2 col-xs-12">
              <a class="file-input-wrapper btn btn-default  fileinput btn-primary"><span>Browse file</span><input type="file" class="fileinput btn-primary" name="address_proof" id="address_proof" title="Browse file" accept="image/*"></a>
              <?php if($mres['address_proof']){
                $product_path = "user/" . $mres['address_proof']; ?>                                
              <a href="#" data-toggle="modal" data-target=".image_pop" class="pull-right">
              <img src="<?php echo base_url() . 'uploaded-files/' . $product_path; ?>" width="50" class="img-responsive img-rounded center-block" alt="">
              </a>
              <?php } ?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Major Issues/Problems/Challenges Faced by Farmer</label>
            <div class="col-md-6">                                     
              <textarea class="form-control" name="major_issues" id="major_issues"><?php echo set_value("major_issues",$mres['major_issues']);?></textarea> 
              <?php echo form_error("major_issues");?>
            </div>
          </div>
          <div class="form-group">
                  <label class="col-md-3 control-label"></label>
                  <div class="col-md-9">
                    <input type="submit" name="sub" class="btn btn-success pull-right" value="Update" class="button2" />
                  </div>
                </div>
          
          <?php echo form_close(); ?>                                
        </div>
      </div>
    </div>
  </div>                    
</div>
<!-- END PAGE CONTENT WRAPPER --> 
<?php $this->load->view('includes/footer'); ?>
<script type="text/javascript">
  $('.addbtn').click(function(){
    $('#catForm').submit();
  });
</script>
<script>
  $(document).ready(function () {


    $(".add-more").click(function(){
      $(".main-class").append('<div class="row" style="margin-bottom: 15px;"><div class="col-md-3"><select name="category_id[]" size="1" class="form-control"><?php echo get_nested_dropdown_menu(0,"");?></select></div><div class="col-md-3"><input type="text" class="form-control" name="qty_per_year[]" id="qty_per_year" value="<?php echo set_value("qty_per_year");?>" Placeholder="Qty. Per Year"></div><div class="col-md-3"><input type="text" class="form-control" name="selling_price_msp[]" id="selling_price_msp" value="<?php echo set_value("selling_price_msp");?>" Placeholder="Selling Price (MSP)"></div><div class="col-md-2"><?php $selling_month=set_value("selling_month"); ?><select name="selling_month[]" id="selling_month" class="form-control"><?php foreach($sellingMonthsArray as $val){if ($val == $selling_month){ $sel = "selected";} else {$sel = "";}?><option value="<?php echo $val;?>" <?php echo $sel; ?>><?php echo $val;?></option><?php } ?></select></div><div class="col-md-1"><a href="javascript:void(0);" class="btn removes">Remove</a></div><div><div>');
    });

    $(".main-class").on('click','.removes',function(){
      $(this).parent().parent('div').remove();
    });

    $(".lsowned").keyup(function(){
      //
      //NaN
      var a=parseFloat($("#land_size_owned").val());
      var b=parseFloat($("#land_size_leased").val());
          a=(isNaN(a))?0:a;
          b=(isNaN(b))?0:b;
        $("#total_land_size").val((a+b));
    });
    
    $(".land_size_unit_id").on("change",function(){
        val=$(this).val();
        $('#land_size_owned_unit').val(val);
        $('#land_size_leased_unit').val(val);
        $('#total_land_size_unit').val(val);
    });

    $("#district_head_id").change(function () {
      kisan_mitras();
    });

    $("#kisan_mitra_id").change(function () {
      kisan_sahayaks();
    });
    
    $("#country").change(function () {
      states();
    });
    $("#state").change(function () {
      cities();
    });
    $("#city").change(function () {
      blocks();
    });
    $("#block").change(function () {
      panchayats();
    });
    $("#panchayat").change(function () {
      villages();
    });

  });
  <?php if($this->input->post()){ ?>
    <?php if($this->session->userdata('admin_type')!='3'){ ?>
      <?php if($this->session->userdata('admin_type')!='4'){ ?>
        kisan_mitras('<?php echo $this->input->post('kisan_mitra_id');?>','<?php echo $this->input->post('district_head_id');?>');
      <?php } ?>
    <?php } ?>
    <?php if($this->session->userdata('admin_type')!='4'){ ?>
    kisan_sahayaks('<?php echo $this->input->post('kisan_sahayak_id');?>','<?php echo $this->input->post('kisan_mitra_id');?>');
    <?php } ?>
    states('<?php echo $this->input->post('state_id');?>','<?php echo $this->input->post('country_id');?>');
    cities('<?php echo $this->input->post('city_id');?>','<?php echo $this->input->post('state_id');?>','<?php echo $this->input->post('country_id');?>');
    blocks('<?php echo $this->input->post('block_id');?>','<?php echo $this->input->post('city_id');?>','<?php echo $this->input->post('state_id');?>','<?php echo $this->input->post('country_id');?>');
    panchayats('<?php echo $this->input->post('panchayat_id');?>','<?php echo $this->input->post('block_id');?>','<?php echo $this->input->post('city_id');?>','<?php echo $this->input->post('state_id');?>','<?php echo $this->input->post('country_id');?>');
    villages('<?php echo $this->input->post('village_id');?>','<?php echo $this->input->post('panchayat_id');?>','<?php echo $this->input->post('block_id');?>','<?php echo $this->input->post('city_id');?>','<?php echo $this->input->post('state_id');?>','<?php echo $this->input->post('country_id');?>');
  <?php } ?>

  function kisan_mitras(sel,district_head_id){ 
    if(district_head_id){
      var district_head_id =district_head_id
    }else{
      var district_head_id = $("#district_head_id").val();
    };
    if(district_head_id){
        $("#kisan_sahayak_id").html('<option value="">--Select Kisan Mitra--</option>');
        $.ajax({
          url: '<?php echo base_url('sitepanel/kisan_mitra/ajax_kisan_mitra'); ?>',
          type: 'post',
          data: ({'district_head_id': district_head_id,'sel': sel}),
          success: function (data) {
            $("#kisan_mitra_id").html(data);
          }
        });
    }else{
      $("#kisan_mitra_id").html('<option value="">--Select Kisan Mitra--</option>');
    }
  }

  function kisan_sahayaks(sel,kisan_mitra_id){ 
    if(kisan_mitra_id){
      var kisan_mitra_id =kisan_mitra_id
    }else{
      var kisan_mitra_id = $("#kisan_mitra_id").val();
    };
    if(kisan_mitra_id){
        $("#kisan_sahayak_id").html('<option value="">--Select KM Sahyogi--</option>');
        $.ajax({
          url: '<?php echo base_url('sitepanel/kisan_sahayak/ajax_kisan_sahayak'); ?>',
          type: 'post',
          data: ({'kisan_mitra_id': kisan_mitra_id,'sel': sel}),
          success: function (data) {
            $("#kisan_sahayak_id").html(data);
          }
        });
    }else{
      $("#kisan_sahayak_id").html('<option value="">--Select KM Sahyogi--</option>');
    }
  }

  function states(sel,country_id){ 
    if(country_id){
      var country =country_id
    }else{
      var country = $("#country").val();
    };
    if(country){
        $("#state").html('<option value="">--Select State--</option>');
        $("#city").html('<option value="">--Select District--</option>');
        $("#block").html('<option value="">--Select Block--</option>');
        $("#panchayat").html('<option value="">--Select Panchayat--</option>');
        $("#village").html('<option value="">--Select Village--</option>');
        $.ajax({
          url: '<?php echo base_url('sitepanel/location/ajax_state'); ?>',
          type: 'post',
          data: ({'country_id': country,'sel': sel}),
          success: function (data) {
            $("#state").html(data);
          }
        });
    }else{
      $("#state").html('<option value="">--Select State--</option>');
      $("#city").html('<option value="">--Select District--</option>');
      $("#block").html('<option value="">--Select Block--</option>');
      $("#panchayat").html('<option value="">--Select Panchayat--</option>');
      $("#village").html('<option value="">--Select Village--</option>');
    }
  }


  function cities(sel,state_id,country_id){ 
    if(country_id){
        var country_id =country_id
      }else{
        var country_id = $("#country").val()
      };
      if(state_id){
        var state_id =state_id
        }else{
          var state_id = $("#state").val()
        };
      $("#block").html('<option value="">--Select Block--</option>');
      $("#panchayat").html('<option value="">--Select Panchayat--</option>');
      $("#village").html('<option value="">--Select Village--</option>');
      $.ajax({
        url: '<?php echo base_url('sitepanel/location/ajax_city'); ?>',
        type: 'post',
        data: ({'country_id': country_id,'state_id': state_id,'sel': sel}),
        success: function (data) {
          $("#city").html(data);
        }
      });
  }

  function blocks(sel,city_id,state_id,country_id){ 
    if(country_id){
        var country_id =country_id
      }else{
        var country_id = $("#country").val()
      };
    if(city_id){
        var city_id =city_id
        }else{
          var city_id = $("#city").val()
        };
      if(state_id){
        var state_id =state_id
        }else{
          var state_id = $("#state").val()
        };
      $("#panchayat").html('<option value="">--Select Panchayat--</option>');
      $("#village").html('<option value="">--Select Village--</option>');
      $.ajax({
        url: '<?php echo base_url('sitepanel/location/ajax_block'); ?>',
        type: 'post',
        data: ({'country_id': country_id,'state_id': state_id,'city_id': city_id,'sel': sel}),
        success: function (data) {
          $("#block").html(data);
        }
      });
  }
  
  function panchayats(sel,block_id,city_id,state_id,country_id){ 
    if(country_id){
        var country_id =country_id
      }else{
        var country_id = $("#country").val()
      };
    if(block_id){
        var block_id =block_id
        }else{
          var block_id = $("#block").val()
        };
    if(city_id){
        var city_id =city_id
        }else{
          var city_id = $("#city").val()
        };
      if(state_id){
        var state_id =state_id
        }else{
          var state_id = $("#state").val()
        };
        $("#village").html('<option value="">--Select Village--</option>');
      $.ajax({
        url: '<?php echo base_url('sitepanel/location/ajax_panchayat'); ?>',
        type: 'post',
        data: ({'country_id': country_id,'state_id': state_id,'city_id': city_id,'block_id': block_id,'sel': sel}),
        success: function (data) {
          $("#panchayat").html(data);
        }
      });
  }

  function villages(sel,panchayat_id,block_id,city_id,state_id,country_id){ 
    if(country_id){
        var country_id =country_id
      }else{
        var country_id = $("#country").val()
      };
      if(state_id){
        var state_id =state_id
        }else{
          var state_id = $("#state").val()
        };
        if(city_id){
        var city_id =city_id
        }else{
          var city_id = $("#city").val()
        };
      if(block_id){
        var block_id =block_id
      }else{
        var block_id = $("#block").val()
      };
      if(panchayat_id){
        var panchayat_id =panchayat_id
      }else{
        var panchayat_id = $("#panchayat").val()
      };

        $("#village").html('<option value="">--Select Village--</option>');
      $.ajax({
        url: '<?php echo base_url('sitepanel/location/ajax_village'); ?>',
        type: 'post',
        data: ({'country_id': country_id,'state_id': state_id,'city_id': city_id,'block_id': block_id,'panchayat_id': panchayat_id,'sel': sel}),
        success: function (data) {
          $("#village").html(data);
        }
      });
  }

</script>