<?php include('common/header.php'); ?>
  <!-- Main Sidebar Container -->
<?php include('common/sidenav.php'); ?>


<?php
 include_once ('includes/config.php');
   
// Check connection
    if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
    } 

if(isset($_POST['submit']))
{
 
$sess= $_SESSION['sess_user'];


   
//insert.php
$name =$_POST['company'];
$address = $_POST['address'];

//$vendormeasurement =$_POST['vendor_measurement'];








 // Check connection
    if ($con->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    } 
  else

 
     $sql = "SELECT * FROM `vendors` WHERE company_name='$name'";
    $results = $con->query($sql);
   if ($results->num_rows > 0) 

  {
      
   //echo"<script type='text/javascript'>alert('Name Already Exist.');</script>";
     // echo "<script>(window.location.href='vendor.php'?Failed');</script>";
     
     echo "<div class='container'><div class='custom-alert'>Name Already Exist.</div></div>";
        echo "<script>setTimeout(function() { window.location.href='vendor.php'; }, 2000);</script>";
  }
 else
{
    
    $sqls="INSERT INTO vendors(`company_name`,`company_address`)Values('$name','$address')";
     $results = $con->query($sqls);
     
     echo "<div class='container'><div class='custom-alert'>Record Successfully Added!</div></div>";
        echo "<script>setTimeout(function() { window.location.href='vendor.php'; }, 1000);</script>";
     
    //echo "<script>(window.location.href='vendor.php'?success');</script>";
    
    
}
 
  



$con->close();
}
 ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
  

    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Vendor List</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item">  <button id="formButton" type="button"  class="btn btn-danger"><i class="fa fa-plus">Add New</i></button></li>
             
            <!--  <li class="breadcrumb-item active"><a href="#">Dashboard</a></li>-->
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">


            <div class="card">
              <div class="card-header">
         <!-- add driver -->
    
      	<form id="form1" class="form-hidden" method="post">
          			<h3>Add Info</h3>

          	    <div class="row">
          	        
                     <div class="col-md-6">
                       <div class="form-group">
                              <label>Company Name</label>
                                <input type="text" placeholder="Company Name" required="required" class="form-control" name="company">
                      </div>       
                        
                    </div>
          	      
          	         <div class="col-md-6">
                         <div class="form-group">
                        <label>Site Address</label>
                        <textarea name="address" required placeholder="Address" class="form-control"></textarea>
                    </div></div>
          	    </div>

                
              

                <div class="row">
                  <div class="col-md-6">
                      <div class="form-group">
                           
                      <div class="form-example-int mg-t-15">
                            <button name="submit" class="btn btn-danger notika-btn-success">Submit</button>
                        </div>
                     
                  </div>
                </div>
                </div>
           </form>
              

    <!-- end add driver -->
                <h3 class="card-title">Lists</h3>
              </div>
        
              <!-- /.card-header -->
              <div class="card-body">
               <table id="example1" class="table table-striped">
                  <thead class="bg bg-danger">
                  <tr>
                    <th>S No</th>
                    <th>Company</th>
                    <th>Site Address</th>
                    
                    <!--<th>Vendor Measurement</th>-->
                    <th>Action</th>
                  </tr>
                  </thead>
                  <tbody>

  <?php
    include('includes/config.php');
               
      $no=0;
      $result = mysqli_query($con, "SELECT * FROM `vendors` where vs_status='0' ORDER BY v_id ASC");
       while($row = mysqli_fetch_assoc($result)) {
       $no++; 
      
          
  ?>
                  <tr>
                      <?php $id = $row['v_id']; ?>
                    <td><?php echo $no; ?></td>
                  
                    <td><?php echo $row['company_name']; ?></td>
                   
                    <td><?php echo $row['company_address']; ?></td>
                   
                   <!-- <td><?php// echo $row['vendor_measurement']; ?></td>-->
                   
                   
                    <td>
                        <a href="vendoredit.php?id=<?php echo $row['v_id']; ?>">
                  <i class="fas fa-edit"></i>
                          ||
                        <a  onclick="return confirm('Are you sure <?php echo $row['company_name']; ?> ?')" href="vendordelete.php?id=<?php echo $id; ?>"  ><i style="font-size:15px; color:red;"  class="fa fa-trash"></i></a>
                        
                    </td>
                    
                  </tr>

                    


    <?php
    }

  
  ?>
 
                  </tbody>
                </table>
                     
                
                
                
                
                
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->



<script>
  //show a confirmation and redirect to the delete profile script
  function deleteProfile() {
    if (confirm("Do you really want to delete your profile?")) {
        //location.href = '/deleteuser.php';
    }
}
</script>


  </div>
  <!-- /.content-wrapper -->


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