iwa-panda1

Manage Weather Data by International Weather Agency (Version 1)
Log | Files | Refs

search_contract.php (3113B)


      1 <!DOCTYPE html>
      2 <html lang="eng">
      3   <head>
      4     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
      5       <link rel="stylesheet" type="text/css" href="/css/homepage.css">
      6     <?php
      7       include "views/navbar.php";
      8       include "utils/autoloader.php";
      9       if(!in_array(1, $_SESSION['user_permissions'])){
     10         header('Location: /dashboard');
     11         exit;
     12       }
     13       $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
     14     ?>
     15   </head>
     16 <body>
     17   <form class="d-flex" action="search_contract" method="post">
     18       <input class="form-control me-2" type="search" name="search_id" placeholder="ID" aria-label="Search">
     19   <button class="btn btn-outline-success" type="submit">Search</button>
     20 </form>
     21     <?php
     22 
     23         $query = [];
     24         if(isset($_POST['search_id'])) {
     25             $query["customer_id"] = "{$_POST['search_id']}";
     26         }
     27         if(isset($_POST['delete'])){
     28             $c = $db->get(Contract::class);
     29             $c->where("customer_id", $_POST['delete']);
     30             $c->delete();
     31         }
     32         if($query == null){
     33             $query['customer_id'] = "%";
     34         }
     35         display_results($db, $query);
     36     function display_results($db, $query){
     37       //create a User orm class and load all the records where user like query
     38       $results = $db->all_where(Contract::class, $query);
     39     
     40       // display results
     41       if($results != null){
     42           echo "<table class=\"table table-striped\">
     43           <thead>
     44             <tr>
     45               <th>Contract id</th>
     46               <th>Customer id </th>
     47               <th>Sub id </th>
     48               <th>Tariff</th>
     49               <th>Start date</th>
     50               <th>End date</th>
     51               <th>Standards</th>
     52               <th>Token</th>
     53               <th>Alter contract data</th>
     54               <th>Delete</th>
     55             </tr>
     56           </thead>
     57           <tbody>";
     58               foreach($results as $data) {
     59                 $link_alter = "/alter_contract?contract_id=" . $data->contract_id;
     60                 echo "<tr>";
     61                 echo "<td>" . $data->contract_id . "</td>";
     62                 echo "<td>" . $data->customer_id . "</td>";
     63                 echo "<td>" . $data->sub_id . "</td>";
     64                 echo "<td>" . $data->tariff . "</td>";
     65                 echo "<td>" . $data->start_date . "</td>";
     66                 echo "<td>" . $data->end_date . "</td>";
     67                 echo "<td>" . $data->standards . "</td>";
     68                 echo "<td>" . $data->token . "</td>";
     69                 echo "<td><a href='" . $link_alter . "'>Alter</a></td>";
     70                 echo "
     71                 <td>
     72                   <form method=\"post\" action=\"search_contract\">
     73                     <button type=\"submit\" name='delete' value=" . $data->customer_id ." ' class=\"btn btn-primary\">Delete</button>
     74                   </form>
     75                 </td>";
     76                 echo "</tr>";
     77               }
     78             echo"
     79           </tbody>
     80         </table>";
     81         }else{
     82           echo "No contracts were found.";
     83       }    
     84     }
     85   ?>
     86   </body>
     87 </html>
     88