<?php
  if( !hasPermission($_SESSION['user_detail']['role_id'], 'agent_add') ) {
    echo '<script>window.location.href="index.php?page=no_permission.php"</script>';die();
  }
    
  $voucher_no          = agentCode($conn);
  $g_act_codes         = accountCode($conn);
?>
<section class="content-header">
  <div class="row">
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 bottom20">
        <h3 class="capital font15 padding5 bold">ADD NEW AGENT</h3>
      </div>
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 text-right bottom20">
        <h3>
          <?php if( hasPermission($_SESSION['user_detail']['role_id'], 'agent_list') ) { ?>
          <a href="index.php?page=agent/list.php" class="btn btn-danger capital bottom10 custome-btn">VIEW AGENT DETAILS</a>
          <?php } ?>
        </h3>
      </div>
  </div>
</section>
<hr class="bottom35"> 
<section class="hitz-top-header">
   <div class="row bottom40">
      <div class="col-xs-12">
         <div class="box box-success">
            <div class="box-body">
              <form action="agent/insert.php" method="post" enctype="multipart/form-data" class="common-frm-validation" id="signupForm">
                
                <div class="row">
                  <div class="col-md-1">
                    <div class="form-group">
                      <label class="capital">CODE</label><span style="color: red">*</span>
                      <input type="text" size="35" id="code" name="code" class="form-control required" autocomplete="off" readonly="" value="<?php echo $voucher_no;?>" />
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                      <label class="capital">agent name</label><span style="color: red">*</span>
                      <input type="text" size="35" id="name" name="name" class="form-control required" placeholder="AGENT NAME" autocomplete="off" onChange="CheckName(this.value);" autofocus="" />
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-1"></div>
                  <div class="col-md-4">
                    <div class="form-group">
                      <label class="capital">address</label><span style="color: red">*</span>
                      <textarea class="form-control required" name="address" id="address" style="height: 35px !important;"></textarea> 
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-1"></div>
                  <div class="col-md-2">
                    <div class="form-group">
                      <label class="capital">city</label><span style="color: red">*</span>
                        <input type="text" name="city" id="get_city" class="form-control required" placeholder="CITY" />
                    </div>
                  </div>
                  <div class="col-md-2">
                    <div class="form-group">
                      <label class="capital">District</label>
                      <input type="text" name="district" id="get_district" class="form-control" placeholder="DISTRICT" />  
                    </div>
                  </div>
                  <div class="col-md-2">
                    <div class="form-group">
                      <label class="capital">state</label><span style="color: red">*</span>
                      <input type="text" name="state" id="autocompletes" class="form-control required" placeholder="STATE" />
                    </div>
                  </div>
                  <div class="col-md-1">
                    <div class="form-group">
                      <label class="capital">country</label>
                      <input type="text" name="country" id="autocomplete" class="form-control" placeholder="COUNTRY" /> 
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-1"></div>
                  <div class="col-md-2">
                    <div class="form-group">
                      <label class="capital">pincode</label>
                      <input type="text" size="35" id="pincode" name="pincode" class="form-control" placeholder="PINCODE" autocomplete="off" />
                    </div>
                  </div>
                  <div class="col-md-2">
                    <div class="form-group">
                      <label class="capital">phone</label>
                      <input type="text" size="35" id="contact" name="contact" class="form-control" placeholder="PHONE" autocomplete="off" />
                    </div>
                  </div>
                  <div class="col-md-2">
                    <div class="form-group">
                      <label class="capital">Mobile</label>
                      <input type="text" size="35" id="mobile" name="mobile" class="form-control" placeholder="MOBILE" autocomplete="off" />
                    </div>
                  </div>
                  <div class="col-md-2">
                    <div class="form-group">
                      <label class="capital">e-mail</label>
                      <input type="text" size="35" id="email" name="email" class="form-control" placeholder="E-MAIL" autocomplete="off" />
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-1"></div>
                  <div class="col-md-2">
                    <div class="form-group">
                      <label class="capital">pancard no</label>
                      <input type="text" size="35" id="pan" name="pan" class="form-control" placeholder="PANCARD" autocomplete="off" />
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                      <label class="capital">PAN IMAGE</label>
                      <input type="file" size="35" id="image" name="image" autocomplete="off" class="image" />
                      
                    </div>
                    
                </div>
                <div class="col-md-4">
                      <div class="form-group">
                        <label class="capital">Status</label><span style="color: red">*</span><br>
                        <label class="radio-inline fontradiobuttion">
                        <input type="radio" name="status" value="0" checked> <span class="label-text">ACTIVE</span>
                        </label>
                        <label class="radio-inline fontradiobuttion">
                        <input type="radio" name="status" value="1"> <span class="label-text">IN-ACTIVE</span>
                        </label>
                      </div>
                </div>
                </div>
                
               <input type="hidden" value="" name="id" id="id">
                <hr>
                <div class="row" align="center">
                  <button id="btn" class="btn btn-primary ajax-submit capital" type="submit"> Save & List</button>
                  <a href="index.php?page=agent/list.php" class="btn btn-danger capital"> Cancel</a>
                </div>
              </form>
            </div>
         </div>
      </div>
   </div>
</section>
<script type="text/javascript">
  $( function() {
    $( "#autocomplete" ).autocomplete({
        source: function( request, response ) {
            
            $.ajax({
                url: "agent/get_country.php",
                type: 'post',
                dataType: "json",
                data: {
                    search: request.term
                },
                success: function( data ) {
                    response( data );
                }
            });
        },
        select: function (event, ui) {
            $('#autocomplete').val(ui.item.label);
            return false;
        }
    });
    $( "#autocompletes" ).autocomplete({
        source: function( request, response ) {
            
            $.ajax({
                url: "agent/get_state.php",
                type: 'post',
                dataType: "json",
                data: {
                    search: request.term
                },
                success: function( data ) {
                    response( data );
                }
            });
        },
        select: function (event, ui) {
            $('#autocompletes').val(ui.item.label);
            return false;
        }
    });
    $( "#get_district" ).autocomplete({
        source: function( request, response ) {
          $.ajax({
              url: "agent/get_district.php",
              type: 'post',
              dataType: "json",
              data: {
                  search: request.term
              },
              success: function( data ) {
                  response( data );
              }
          });
        },
        select: function (event, ui) {
            $('#get_district').val(ui.item.label);
            return false;
        }
    });
    $( "#get_city" ).autocomplete({
        source: function( request, response ) {
          $.ajax({
              url: "agent/get_city.php",
              type: 'post',
              dataType: "json",
              data: {
                  search: request.term
              },
              success: function( data ) {
                  response( data );
              }
          });
        },
        select: function (event, ui) {
            $('#get_city').val(ui.item.label);
            return false;
        }
    });

  });
  function CheckName() {
    var name      = $("#name").val();
    $.ajax({
      'type': 'POST',
      'url': 'agent/check_name.php',
      'data': {
        'name': name
      },
      dataType: 'JSON',
      success: function (result) {
        if(result.status == 1) {
          jQuery('.submit').attr('disabled', true);
          swal("Opps !!", "SAME NAME DETECT...!!!", "info")
          setTimeout("location.reload(true);",800); 
        }else{
          jQuery('.submit').attr('enable', true);
        }
      }
    });
  };
</script>