<?php
  if( !hasPermission($_SESSION['user_detail']['role_id'], 'accountm_add') ) {
    echo '<script>window.location.href="index.php?page=no_permission.php"</script>';die();
  }
    
  $voucher_no          = accountCode($conn);

  if (isset($_REQUEST['eid']) && !empty($_REQUEST['eid']) && $_REQUEST['eid']!=0){
    $select_update     = "SELECT * FROM act_master WHERE id='".$_REQUEST['eid']."'";
    $select_update_res = mysqli_query($conn,$select_update);
    $update_row        = mysqli_fetch_array($select_update_res,MYSQLI_BOTH);
    $act_code          = $update_row['act_code'];
    $name              = $update_row['ac_name'];
    
    $agent             = "SELECT * FROM `agent` WHERE `act_code` = '".$act_code."'";
    $agent_res         = mysqli_query($conn,$agent);
    $agent_res_row     = mysqli_fetch_assoc($agent_res);

    $pancard           = $agent_res_row['pan_no'];
    $pancard_img       = $agent_res_row['pan_img'];
    $status            = $agent_res_row['status'];
    $a_id              = $agent_res_row['id'];

    if($agent_res_row['status'] == '1'){
      $status = '1';
    }else{
      $status = '0';
    }
  }
?>
<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"><?php echo ($status == 0) ? 'MANAGE AGENT DETAILS' : 'UPDATE AGENT DETAILS'; ?></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'], 'accountm_list') ) { ?>
          <a href="index.php?page=account_mst/list.php" class="btn btn-danger capital bottom10 custome-btn">VIEW ACCOUNT 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="account_mst/manage_insert.php" method="post" enctype="multipart/form-data" class="common-frm-validation" id="signupForm">
                <div class="row">
                  <div class="col-md-2">
                    <div class="form-group">
                      <label class="capital">CODE</label><span style="color: red">*</span>
                      <?php 
                      if($_GET['eid'] == ''){
                        $code = $voucher_no;
                      }else{
                        $code = $act_code;
                      }
                      ?>
                      <input type="text" size="35" id="act_code" name="act_code" class="form-control required" autocomplete="off" readonly="" value="<?php echo $code;?>" />
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                       <label class="capital">name</label><span style="color: red">*</span>
                       <input type="text" name="name" class="form-control required" placeholder="NAME" value="<?php echo $name;?>" autofocus="" readonly=""/>
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                       <label class="capital">PANCARD</label><span style="color: red">*</span>
                       <input type="text" name="pan_no" id="pan_no" class="form-control required" placeholder="PANCARD" value="<?php echo $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" /><br/>
                      <?php
                      if($pancard_img !=''){ ?>
                        <a href="assets/upload/pan/<?php echo $pancard_img?>" class="btn btn-info" data-toggle="tooltip" data-placement="bottom" title="VIEW IMAGE...!!" target="_blank"><em class="fa fa-file-image-o"></em></a>
                      <?php } ?>
                    </div>
                  </div>
                </div>
                <input type="hidden" value="<?php echo $status;?>" name="status" id="status">
                <input type="hidden" value="<?php echo $a_id;?>" name="id" id="id">
                <hr>
                <div class="row" align="center">
                  <button id="btn" class="btn btn-primary ajax-submit capital" type="submit"> <?php echo ($status == 0) ? 'Save & List' : 'Update & save'; ?></button>
                  <a href="index.php?page=account_mst/list.php" class="btn btn-danger capital"> Cancel</a>
                </div>
              </form>
              
            </div>
         </div>
      </div>
   </div>
</section>
