

<!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>ANONYMOUSLY</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>


<body class="p-3 m-0 border-0 bd-example m-0 border-0">  
<?php   //include 'menu.php'; ?>
        
<?php  

    

  echo ("<script LANGUAGE='JavaScript'>
    window.alert('COMMENTa (In the best interest of the learner/s.)');
    
    </script>");

?>



<?php
// define variables and set to empty values
//to1 variable represent the name of school.
$tconcernErr = $toErr = $regardingErr =   $to1Err =  $concernErr =  "";

$tconcern = $to =  $regarding =   $to1 = $concern =  "";

//other variables

    $counter = 0 ;

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  
 
  
  //codes for type of concern
  if (empty($_POST["tconcern"])) {
    $tconcernErr = "Type of concern is required";
  } else {
    $tconcern = test_input($_POST["tconcern"]);
    $counter++;
  }
  
   //codes for addressed to 
  if (empty($_POST["to"])) {
    $toErr = "Addressed to  is required";
  } else {
    $to = test_input($_POST["to"]);
    $counter++;
  }
  
   //codes for regarding 
  if (empty($_POST["regarding"])) {
    $regardingErr = "Please select one option";
  } else {
    $regarding = test_input($_POST["regarding"]);
    $counter++;
  }
  
  
   //codes for transfer to1
  if (empty($_POST["to1"])) {
    $to1Err = "Town/City name is required";
  } else {
    $to1 = test_input($_POST["to1"]);
    $counter++;
  }
  
   //codes for concern
  if (empty($_POST["concern"])) {
    $concernErr = "Concern is required";
  } else {
    $concern = test_input($_POST["concern"]);
    $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;
}

?>

<u><center><h2>Contribute : Anonymously</h2></center></u>
<p><span class="error">* required field</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
    
    <div class="form-floating">
  <select class="form-select" id="tconcern" name = "tconcern" aria-label="tconcern"  value="<?php echo $tconcern;?>" required>
    <option selected></option>
    <option value="Complain">Complain</option>
    <option value="Suggestion">Suggestion</option>
    <option value="Compliment">Compliment</option>
    
  </select>
  <label for="floatingSelect">Type of concern</label>
</div> <br />


    <div class="form-floating">
  <select class="form-select" id="to" name = "to" aria-label="to"  value="<?php echo $to;?>" required>
    <option selected></option>
    <option value="SGB">SGB</option>
    <option value="Circuit Manager">Circuit Manager</option>
    <option value="Principal">Principal</option>
    <option value="SMT">SMT</option>
    <option value="Teachers">Teachers</option>
    <option value="Learners">Learners</option>
    <option value="Admin">Admin</option>
    <option value="cleaners">Cleaners</option>
    <option value="Maintenance">Maintenance</option>
    <option value="Kitchen">Kitchen staff</option>
    <option value="educator assistant">Educator assistant</option>
    <option value="General Assistant">General assistant</option>
    <option value="RCL">RCL</option>
    <option value="Other">Other</option>
    
  </select>
  <label for="floatingSelect">Addressed to :</label>
</div> <br />
    
    
    <div class="form-floating">
  <select class="form-select" id="regarding" name = "regarding" aria-label="regarding"  value="<?php echo $regarding;?>" required>
    <option selected></option>
    <option value="Bullying">Bullying</option>
    <option value="Cyberbullying">Cyberbullying</option>
    <option value="Facilities">Facilities</option>
    <option value="Academic matter">Academic Matter</option>
    <option value="Discipline">Discipline</option>
    <option value="Teacher-student relations">Teacher-student relations</option>
    <option value="Safety">Safety and security</option>
    <option value="Communication barrier">Communictions barriers</option>
    <option value="Special education services">Special education services</option>
    <option value="Extracurricular activities">Extracurricular activities</option>
    <option value="Technology">Technology and resources</option>
    <option value="Transportation">Transportation</option>
    <option value="Health">Health , wellness and nutrition</option>
    <option value="Administrative processes">Administrative processes</option>
    <option value="Teacher proffessionalism">Teacher professionalism</option>
    <option value="other">Other</option>
    
    
  </select>
  <label for="floatingSelect">Regarding  :</label>
</div> <br />
    
  

    

   
         <label for="exampleDataList" class="form-label" style="color:red;">School name : please select the right school. </label>
<input class="form-control" list="towns" id="exampleDataList" name= "to1" placeholder="Type and select school name here." 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);
        }

        $sql = "SELECT school FROM schools ORDER BY school ASC";
        $result = $conn->query($sql);

        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 />
      <label for="exampleDataList" class="form-label" style="color:red;"> COMMENTa : here. </label>
    <div class="form-floating">
  <textarea class="form-control" name = "concern"placeholder="Leave a concern here" id="floatingTextarea2" style="height: 100px" minlength="50" maxlength="10000" required></textarea>
  <label for="floatingTextarea2">Please type your concern here...</label>
</div>
    
      <br /> 
    <div class="d-grid gap-2 col-6 mx-auto">
  <button type="submit" class="btn btn-primary" type="button">Submit : Concern</button>
  
</div>
 
  
    </form>

<?php



echo '<br />';
//echo $counter;echo '<br />';
echo '<br />';

       

        
        
        if ($counter === 5 ){
            
         
         //getting today's date
         $date = date("Y/m/d");
        
        //connecting to the database
        
        $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 if the selected school appear in the database
        $exist = "No";
        $sql = "SELECT school FROM schools WHERE school = '$to1' ";
        $result = $conn->query($sql);
        
        
         if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       $exist = "Yes";
            }
         }
         
         if ($exist != "Yes"){
         
         echo ("<script LANGUAGE='JavaScript'>
    window.alert('The selected school does not appear in our database. Please choose carefully.');
    window.location.href='/anonymouscsc.php';
    </script>");
        
         }
        
        //to1 variable is the name of the school
        $sql = "SELECT * FROM schools WHERE school = '$to1' ";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
       
       $province = $row["province"];
       $sector = $row["sector"];
       $phase = $row["phase"];
       $district = $row["district"];
       $circuit = $row["circuit"];
       $town = $row["town"];
       $emis = $row["emis"];
       
       
         }
            } 
       
        
        
        
        
        
        
        // prepare and bind
        $stmt = $conn->prepare("INSERT INTO anonymousconcerns (tconcern,addressedto,regarding,school,concern,province,sector,phase,district,circuit,town,emis,date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
        
        $stmt->bind_param("sssssssssssss", $tconcern,$to,$regarding,$to1,$concern,$province,$sector,$phase,$district,$circuit,$town,$emis,$date);
        
        $stmt->execute();

        $conn->close();
        
      
        
        
        // Display the alert box 
        //echo '<script>alert("You have successfully registered in our database. Please login to search our database.")</script>';
        
        echo ("<script LANGUAGE='JavaScript'>
    window.alert('You have successfully registered your concern in our database . Since you registered concern anonymously, you wont get feedback. thanks for your contribution.');
    
    
    
    window.location.href='/index.php';
    </script>");
        
        
            
        }


?>

</body>
</html>
