<?php $this->load->view("includes/header"); ?>
<div class="page-title">
  <h2><span><?php echo $heading_title; ?></span></h2>
  <?php echo anchor("sitepanel/district_head/", '<span>Cancel</span>', 'class="btn btn-primary pull-right" '); ?>
    <a href="javascript:void(0);" class="btn btn-success addbtn pull-right"><span>Update</span></a>    
</div>
<div class="page-content-wrap"> 
  <div class="fix"></div>
  <div class="row">
    <div class="col-md-12">
      <div class="panel panel-default">
        <div class="panel-body">
          <?php //echo validation_message(); ?>
          <?php //echo error_message(); ?> 
          <?php echo form_open_multipart("sitepanel/district_head/edit/".$mres['admin_id'], 'class="form-horizontal" id="catForm"'); ?> 
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>User Name</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="admin_username" id="admin_username" value="<?php echo set_value("admin_username",$mres['admin_username']);?>"> 
              <?php echo form_error("admin_username");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Password</label>
            <div class="col-md-6">                                     
              <input type="password" class="form-control" name="admin_password" id="admin_password" value="<?php echo set_value("admin_password",$mres['admin_password']);?>"> 
              <?php echo form_error("admin_password");?>
            </div>
          </div>
          <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="admin_name" id="admin_name" value="<?php echo set_value("admin_name",$mres['admin_name']);?>"> 
              <?php echo form_error("admin_name");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Upload Photo</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="image1" id="image1" title="Browse file" accept="image/*"></a>
              <?php if($mres['admin_image']){
                $product_path = "district_head/" . $mres['admin_image']; ?>                                
              <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>Mobile Number</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="phone" id="phone" value="<?php echo set_value("phone",$mres['phone']);?>"> 
              <?php echo form_error("phone");?>
            </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="contact_phone" id="contact_phone" value="<?php echo set_value("contact_phone",$mres['contact_phone']);?>"> 
              <?php echo form_error("contact_phone");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Personal Email ID</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="admin_email" id="admin_email" value="<?php echo set_value("admin_email",$mres['admin_email']);?>"> 
              <?php echo form_error("admin_email");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>Official Email ID</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="contact_email" id="contact_email" value="<?php echo set_value("contact_email",$mres['contact_email']);?>"> 
              <?php echo form_error("contact_email");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required">*</span>Address</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="address" id="address" value="<?php echo set_value("address",$mres['address']);?>"> 
              <?php echo form_error("address");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label"><span class="required"></span>PIN Code</label>
            <div class="col-md-6">                                     
              <input type="text" class="form-control" name="pincode" id="pincode" value="<?php echo set_value("pincode",$mres['pincode']);?>"> 
              <?php echo form_error("pincode");?>
            </div>
          </div>

          <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['admin_state']); ?>
              <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['admin_district']); ?>
                <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['admin_block']); ?>
                <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['admin_panchayat']); ?>
                <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['admin_village']); ?>
                <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>
          <div class="form-group" style="background:#eee">
                <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 = "district_head/" . $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 = "district_head/" . $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 = "district_head/" . $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 = "district_head/" . $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">Has Laptop?</label>
            <?php $has_laptops=set_value("has_laptop",$mres['has_laptop']);?>
            <div class="col-md-6">                                     
              <input type="radio" name="has_laptop" value="No" checked="checked"> No &nbsp;&nbsp;
              <input type="radio" name="has_laptop" value="Yes" <?php if($has_laptops=='Yes'){ echo 'checked="checked"';}?>> Yes
              <?php //echo form_error("has_laptop");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label">Has Smartphone?</label>
            <?php $has_smartphones=set_value("has_smartphone",$mres['has_smartphone']);?>
            <div class="col-md-6">                                     
              <input type="radio" name="has_smartphone" value="No" checked="checked"> No &nbsp;&nbsp;
              <input type="radio" name="has_smartphone" value="Yes" <?php if($has_smartphones=='Yes'){ echo 'checked="checked"';}?>> Yes
              <?php //echo form_error("has_laptop");?>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-3 col-xs-12 control-label">Has Vehicle?</label>
            <?php $has_vehicles=set_value("has_vehicle",$mres['has_vehicle']);?>
            <div class="col-md-1">                                     
              <input type="radio" name="has_vehicle" class="has_vehicle" value="No" checked="checked"> No &nbsp;&nbsp;
              <input type="radio" name="has_vehicle" class="has_vehicle" value="Yes" <?php if($has_vehicles=='Yes'){ echo 'checked="checked"';}?>> Yes
            </div>
            <div class="col-md-1" id="has_vehicles">
              <?php $which_vehicles=array();?>
              <?php if($this->input->post()){$which_vehicles=$this->input->post("which_vehicle");}else{$which_vehicles=@explode(",",$mres['which_vehicle']);}   ?>
              <input type="checkbox" name="which_vehicle[]" value="Bike" <?php if(!empty($which_vehicles) && in_array("Bike", $which_vehicles)){ echo 'checked="checked"';} ?> > Bike &nbsp;&nbsp;
              <input type="checkbox" name="which_vehicle[]" value="Car" <?php if(!empty($which_vehicles) && in_array("Car", $which_vehicles)){ echo 'checked="checked"';} ?> > Car
            </div>
          </div>
        
          <div class="form-group">
          <label class="col-md-3 control-label"></label>
            <div class="col-md-9">
              <?php /*<input type="submit" class="btn bg-red pull-right" name="submit" value="Submit">*/ ?>
              <input type="submit" name="sub" class="btn btn-success pull-right" value="Update" class="button2" />
              <input type="hidden" name="action" value="addcategory" />
            </div>
          </div>
          <?php echo form_close(); ?>
        </div>
      </div>
    </div>
  </div>
</div>
<?php $this->load->view("includes/footer"); ?>
<script type="text/javascript">
  $('.addbtn').click(function(){
    $('#catForm').submit();
  });
</script>
<script>
  $(document).ready(function () {
    if($(".has_vehicle:checked").val()=='No'){
        $("#has_vehicles").hide();
      }
    $(".has_vehicle").click(function(){
      var hasval=$(".has_vehicle:checked").val();
      if(hasval=='Yes'){
        $("#has_vehicles").show();
      }else{
        $("#has_vehicles").hide();
      }
    });
    
    //$("#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()){ ?>
    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 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>