

<!DOCTYPE HTML>  
<html>
<head>
     <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
    <title>view concerns</title>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
  
  <style>
.error {color: #FF0000;}
body {
  background-color: aqua;
}
</style>
  
  </head>
<font face = "verdana">

<body class="p-3 m-0 border-0 bd-example m-0 border-0">
 
 <?php
    //to1 is the variable name for the school
    $to1Err = "";
    
    $to1 = "";
 
 
    //other variables

    $counter = 0 ;

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  
 
  //codes for transfer to1
  if (empty($_POST["to1"])) {
    $to1Err = "Town/City name is required";
  } else {
    $to1 = test_input($_POST["to1"]);
    $counter++;
  }
  
    
    
    }
 
 
 function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
function wording($data) {
  $data = strtolower($data);
  $data = ucwords($data);
  return $data;
}
 
 
 ?>
 
  <?php  // include 'menu.php';?>
  
    <u><center><h2>Please select school.</h2></center></u>
<p><span class="error">* required field</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  


     <label for="exampleDataList" class="form-label" style="color:red;">* Select school. </label>
<input class="form-control" list="towns" id="exampleDataList" name= "to1" placeholder="1. Type and select school name." required >
<datalist id="towns">
  <option value="">
  
  
  <?php
$servername = "localhost";
$username = "commemay_sono";
$password = "Masiu@5$5$5$";
$dbname = "commemay_csc";

        // Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
              die("Connection failed: " . $conn->connect_error);
        }
        //query without prepared statement
        $sql = "SELECT school FROM schools ORDER BY school ASC";
        $result = $conn->query($sql);
        
        
        //query with prepared statement
       
       /*
        $sql = "SELECT school FROM schools WHERE school = ? ORDER BY school ASC ";
        $stmt = $conn->prepare($sql); 
        $stmt->bind_param("s", $to1);
        $stmt->execute();
        $result = $stmt->get_result();
        */

        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       
       $school = $row["school"];
      
       echo '<option value="'.$school.'">';
       
       
         }
            } 
        $conn->close();
?> 
  
    </datalist>
    
      <br />   
    <div class="d-grid gap-2 col-6 mx-auto">
  <button type="submit" class="btn btn-primary" type="button">View Concerns </button>
  <br />
</div>
 
  
    </form>
    
    <?php
    
     if ($counter === 1){
            
        $servername = "localhost";
        $username = "commemay_sono";
        $password = "Masiu@5$5$5$";
        $dbname = "commemay_csc";

        // Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
              die("Connection failed: " . $conn->connect_error);
        }
        
        //checking school existance in the table
        $exist = 0 ;
         $sql = "SELECT  *  FROM schools WHERE school = '$to1'  ORDER BY num ASC";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       //setting the variable names
       
        $exist++;
        
            }
        }
        
        if ($exist === 0 ){
            
            
         echo ("<script LANGUAGE='JavaScript'>
        window.alert('The name of selected school does not appear in our system.Please select carefully or contact the web developer to include it in the system');
        window.location.href='http://www.commenta.co.za/viewcsc.php';
        </script>");
             
           
            
        }
        
        
        
         echo '<table class="table table-light table-striped table-hover">';
       echo '<tbody>';
        
        
        //declaring variables
        
        $complains = 0;
        $suggestions = 0 ;
        $compliments = 0;
        
         $sql = "SELECT  *  FROM anonymousconcerns WHERE tconcern = 'Complain' AND school = '$to1'  ORDER BY num ASC";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       //setting the variable names
       
        $complains++;
        
            }
        }
        
         $sql = "SELECT  *  FROM learnerconcerns WHERE tconcern = 'Complain' AND school = '$to1'  ORDER BY num ASC";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       //setting the variable names
       
        $complains++;
        
            }
        }
        
        $sql = "SELECT  *  FROM parentconcerns WHERE tconcern = 'Complain' AND school = '$to1'  ORDER BY num ASC";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       //setting the variable names
       
        $complains++;
        
            }
        }
        
        //codes for counting total number of suggestions
        
         $sql = "SELECT  *  FROM anonymousconcerns WHERE tconcern = 'Suggestion' AND school = '$to1'  ORDER BY num ASC";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       //setting the variable names
       
        $suggestions++;
        
            }
        }
        
         $sql = "SELECT  *  FROM learnerconcerns WHERE tconcern = 'Suggestion' AND school = '$to1'  ORDER BY num ASC";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       //setting the variable names
       
        $suggestions++;
        
            }
        }
        
        $sql = "SELECT  *  FROM parentconcerns WHERE tconcern = 'Suggestion' AND school = '$to1'  ORDER BY num ASC";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       //setting the variable names
       
        $suggestions++;
        
            }
        }
    
    
     //codes for counting total number of Compliments
        
         $sql = "SELECT  *  FROM anonymousconcerns WHERE tconcern = 'Compliment' AND school = '$to1'  ORDER BY num ASC";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       //setting the variable names
       
        $compliments++;
        
            }
        }
        
         $sql = "SELECT  *  FROM learnerconcerns WHERE tconcern = 'Compliment' AND school = '$to1'  ORDER BY num ASC";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       //setting the variable names
       
        $compliments++;
        
            }
        }
        
        $sql = "SELECT  *  FROM parentconcerns WHERE tconcern = 'Compliment' AND school = '$to1'  ORDER BY num ASC";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       //setting the variable names
       
        $compliments++;
        
            }
        }
    
    
    
    
         echo ' <tr  >
     
      <td colspan="2" ><center><button type="button" class="btn btn-primary">
        <span class="badge text-bg-danger">'.$to1.'</span>
            </button></center> </td>
     
      
    </tr>';
    
     echo ' <tr>
     
      <td>Complains </td>
      <td><span class="badge text-bg-danger">'.$complains.'</span> </td>
      
    </tr>';
       
        echo ' <tr>
     
      <td>Suggestions </td>
      <td><span class="badge text-bg-info">'.$suggestions.'</span> </td>
      
    </tr>';
     echo ' <tr>
     
      <td>Compliments </td>
      <td><span class="badge text-bg-warning">'.$compliments.'</span> </td>
      
    </tr>';
    
    
     }
     
    
    ?>
    
    </font>
</body>
</html>  

   