<?php include('../includes/connection.php');
@session_start();

if(!isset($_SESSION['admin_login'])) {
  header("Location: login.php");
  }

 include('header.php'); 

$msg = 0;

if(isset($_POST['submit'])) {

        $vault_ownername = str_replace("'", "\'", $_POST['vault_ownername']);
        $vault_owneremail = str_replace("'", "\'", $_POST['vault_owneremail']);
        $vault_ownerphone = str_replace("'", "\'", $_POST['vault_ownerphone']);
        $vault_owneraddress = str_replace("'", "\'", $_POST['vault_owneraddress']);
        $content_remark = str_replace("'", "\'", $_POST['content_remark']);
        $declared_estimatedvalue = str_replace("'", "\'", $_POST['declared_estimatedvalue']);
        $qualityofcontent = str_replace("'", "\'", $_POST['qualityofcontent']);
        $content_information = str_replace("'", "\'", $_POST['content_information']);
        $weightt = str_replace("'", "\'", $_POST['weight']);
        $monthlycharges = str_replace("'", "\'", $_POST['monthlycharges']);
        $outstandingcharges = str_replace("'", "\'", $_POST['outstandingcharges']);
        $vaultpasscode = str_replace("'", "\'", $_POST['vaultpasscode']);
        $vaultusername = str_replace("'", "\'", $_POST['vaultusername']);
        $v_name = str_replace("'", "\'", $_POST['v_name']);
        $v_email = str_replace("'", "\'", $_POST['v_email']);
        $v_telephone = str_replace("'", "\'", $_POST['v_telephone']);
        $v_country = str_replace("'", "\'", $_POST['v_country']);
        $identification_card = str_replace("'", "\'", $_POST['identification_card']);
        $v_address = str_replace("'", "\'", $_POST['v_address']);

      $image = $_FILES['image']['name'];
      $tmp_name = $_FILES['image']['tmp_name'];
      move_uploaded_file($tmp_name, "images/$image");


    mysqli_query($DB_CONN,"INSERT INTO `vault`(`vault_ownername`, `vault_owneremail`, `vault_ownerphone`, `vault_owneraddress`, `content_remark`, `declared_estimatedvalue`, `qualityofcontent`, `content_information`, `weight`, `monthlycharges`, `outstandingcharges`, `vaultpasscode`, `v_name`, `v_email`, `v_telephone`, `v_country`, `identification_card`, `v_address`,`vault_ownerimage`,`vaultusername`) VALUES ('{$vault_ownername}','{$vault_owneremail}','{$vault_ownerphone}','{$vault_owneraddress}','{$content_remark}','{$declared_estimatedvalue}','{$qualityofcontent}','{$content_information}','{$weightt}','{$monthlycharges}','{$outstandingcharges}','{$vaultpasscode}','{$v_name}','{$v_email}','{$v_telephone}','{$v_country}','{$identification_card}','{$v_address}','{$image}','{$vaultusername}')");


    



    $msg = 1;
    $msg_alert = '<br> <div class="alert alert-success alert-dismissible"> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
      <strong> Success! </strong> Vault Added Successfully </div>';
}




$n=10; 
function getName($n) { 
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
    $randomString = ''; 
  
    for ($i = 0; $i < $n; $i++) { 
        $index = rand(0, strlen($characters) - 1); 
        $randomString .= $characters[$index]; 
    } 
  
    return $randomString; 
} 
  

 ?>
      

<div id="content-wrapper">
    <div class="container-fluid">
          <!-- Breadcrumbs-->
          <ol class="breadcrumb">
            <li class="breadcrumb-item">
              <a href="#"> Dashboard </a>
            </li>
            <li class="breadcrumb-item active"> Vault </li>
          </ol>

        <?php if ($msg=='1') {
              echo $msg_alert;
            } ?>

        <!-- DataTables Example -->
        <div class="card mb-3">
            <div class="card-header">
                <i class="fas fa-table"> </i>  &nbsp;  Add Vault
                <a href="view_vault.php"  style="float: right;" class="btn btn-info btn-sm" > View Vault </a>
            </div>

         

            <div class="card-body">
               <form method="POST" action="" enctype="multipart/form-data">
                  <div class="container">
                      <div class="row">
                         
                              <div class="col-md-6">
                                 <label> Vault Owner’s NAME  </label>
                                 <input type="text" name="vault_ownername" placeholder="Enter Vault Owner’s NAME" class="form-control" required>
                              </div>

                              <div class="col-md-6">
                                  <label> Vault Owner’s Email   </label>
                                  <input type="email" name="vault_owneremail" placeholder="Enter Vault Owner’s Email" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                 <label> Vault Owner’s Phone  </label>
                                 <input type="text" name="vault_ownerphone" placeholder="Enter Vault Owner’s Phone" class="form-control" required>
                              </div>

                              <div class="col-md-6">
                                 <label> Vault Owner’s Image  </label>
                                 <input type="file" name="image" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                  <label>  Vault Owner’s Address   </label>
                                  <textarea name="vault_owneraddress" class="form-control" required></textarea>
                              </div>


                                      <div class="col-md-12">  <h5> VAULT INFORMATION </h5> <br> </div>

                              

                              <div class="col-md-6">
                                  <label> Content Remark </label>
                                    <select name="content_remark" class="form-control">
                                      <option value=""> - Select Content Remark - </option>

                                      <option value="Fragile"> Fragile  </option>
                                      <option value="Valuable"> Valuable    </option>
                                      <option value="Sensitive"> Sensitive  </option>

                                   </select>
                              </div>

                              <div class="col-md-6">
                                  <label> Declared Estimated Value  </label>
                                  <input type="text" name="declared_estimatedvalue" placeholder="Enter Declared Estimated Value" class="form-control" required >
                              </div>

                              
                              <div class="col-md-6">
                                  <label> Quality of content  </label>
                                  <input type="text" name="qualityofcontent" placeholder="Enter Quality of content" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                 <label> Content information ( remark about shipment ) </label>
                                 <textarea name="content_information" class="form-control" required></textarea>
                              </div>

                              <div class="col-md-6">
                                  <label> Weight   </label>
                                  <input type="text" name="weight" placeholder="Enter weight" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                  <label> Monthly Charges  </label>
                                  <input type="text" name="monthlycharges" placeholder="Enter Monthly Charges" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                  <label> Outstanding charges   </label>
                                  <input type="text" name="outstandingcharges" placeholder="Enter Outstanding charges" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                 <label> Vault Passcode  </label>
                                 <input type="text" name="vaultpasscode" value="<?php echo getName($n);; ?>" class="form-control" readonly>
                              </div>
                              
                              <div class="col-md-6">
                                  <label>  Vault Username   </label>
                                  <input type="text" name="vaultusername" placeholder="Enter Vault Username " class="form-control" required >
                              </div>

                              


                                    <div class="col-md-12"> <br> <h5> NEXT OF KIN INFORMATION </h5>  <br></div>

                              <div class="col-md-6">
                                 <label> Name </label>
                                 <input type="text" name="v_name" placeholder="Enter Name" class="form-control" required>
                              </div>


                              <div class="col-md-6">
                                 <label> Email  </label>
                                 <input type="email" name="v_email" placeholder="Enter Email" class="form-control" required>
                              </div>

                              <div class="col-md-6">
                                  <label> Telephone  </label>
                                  <input type="text" name="v_telephone" placeholder="Enter Telephone" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                  <label> Country  </label>
                                  <input type="text" name="v_country" placeholder="Enter Country" class="form-control" required >
                              </div>


                              <div class="col-md-6">
                                 <label> Identification Card </label>
                                 <input type="text" name="identification_card" placeholder="Enter Identification Card " class="form-control" required>
                              </div>

                              <div class="col-md-6">
                                  <label>  Address  </label>
                                  <textarea name="v_address" class="form-control" required></textarea>
                              </div>



                              <div class="col-md-6">
                                  <br> <button class="btn btn-success form-control" type="submit" name="submit" > Click to Save </button>
                              </div>
                              

                                      

                              
                            
                           

                           
                      </div>
                  </div> 
                </form> 
            </div>

        </div>
    </div>
</div>


    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
      <i class="fas fa-angle-up"></i>
    </a>

<?php  include('footer.php'); ?>