

<!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>PARENTS : SIGNUP</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
// define variables and set to empty values
$titleErr = $surnameErr = $cellnumErr = $whatsappErr = $emailErr =  $hearErr =  $to1Err = $to2Err = $to3Err = $to4Err = $to5Err = $to6Err =  $pass1Err = $pass2Err = "";

$title = $surname = $cellnum = $whatsapp = $email =  $hear =  $to1 = $to2 = $to3 = $to4 = $to5 = $to6 = $pass1 = $pass2 = "";

//other variables

    $counter = 0 ;

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  
  //codes for title
  if (empty($_POST["title"])) {
    $titleErr = "Title is required";
  } else {
    $title = test_input($_POST["title"]);
    $counter++;
  }
  
  //codes for surname
  if (empty($_POST["surname"])) {
    $surnameErr = "Surname is required";
  } else {
    $surname = test_input($_POST["surname"]);
    $surname = wording($_POST["surname"]);
    // check if name only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z-' ]*$/",$surname)) {
      $surnameErr = "Only letters and white space allowed";
    } else {
        $counter++;
    }
  }
  
  //codes for cellnum
  if (empty($_POST["cellnum"])) {
    $cellnumErr = "Cell number is required";
  } else {
    $cellnum = test_input($_POST["cellnum"]);
    $celllen = strlen($cellnum);
    $cell = "9999999999";
    $cell = strlen($cell);
    
    if ($celllen === $cell){
        $counter++;
    }else {
        $cellnumErr = "Cell number must be 10 digits";
    }
    
  }
  
  //codes for whatsapp number
  if (empty($_POST["whatsapp"])) {
    $whatsappErr = "Whatsapp number is required";
  } else {
    $whatsapp = test_input($_POST["whatsapp"]);
    $celllen = strlen($whatsapp);
    $cell = "9999999999";
    $cell = strlen($cell);
    
    if ($celllen === $cell){
        $counter++;
    }else {
        $whatsappErr = "Whatsapp number must be 10 digits";
    }
    
  }
  
  //codes for e-mail address
  
   if (empty($_POST["email"])) {
    $emailErr = "Email is required";
  } else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "Invalid email format";
    }
  }
 
    
  
  //codes for password 1
  if (empty($_POST["pass1"])) {
    $pass1Err = "Password is required";
  } else {
    $pass1 = test_input($_POST["pass1"]);
    
  }
  
  //codes for password 2
  if (empty($_POST["pass2"])) {
    $pass2Err = "Confirm password is required";
  } else {
    $pass2 = test_input($_POST["pass2"]);
    
  }
  //comparing password 1 with password 2 
  if ($pass1 === $pass2 ){
      $counter++;
  } else{
       $pass1Err = "Mismatch password ";
       $pass1Err = "Mismatch password ";
  }
  
  //codes for hear about us
  if (empty($_POST["hear"])) {
    $hearErr = "Please select one option.";
  } else {
    $hear = test_input($_POST["hear"]);
    $counter++;
  }
  
 
  
   //codes for transfer to1
  if (empty($_POST["to1"])) {
    $to1Err = "Town/City name is required";
  } else {
    $to1 = test_input($_POST["to1"]);
    $counter++;
  }
  
  //codes for transfer to2
  if (empty($_POST["to2"])) {
    $to2Err = "Town/City name is required";
  } else {
    $to2 = test_input($_POST["to2"]);
    
   
  }
  
  //codes for transfer to3
  if (empty($_POST["to3"])) {
    $to3Err = "Town/City name is required";
  } else {
    $to3 = test_input($_POST["to3"]);
    
    
  }
  
  //codes for transfer to4
  if (empty($_POST["to1"])) {
    $to4Err = "Town/City name is required";
  } else {
    $to4 = test_input($_POST["to4"]);
    
    
  }
  
  //codes for transfer to5
  if (empty($_POST["to5"])) {
    $to5Err = "Town/City name is required";
  } else {
    $to5 = test_input($_POST["to5"]);
    
    
  }
  
  //codes for transfer to6
  if (empty($_POST["to6"])) {
    $to6Err = "Town/City name is required";
  } else {
    $to6 = test_input($_POST["to6"]);
   
    
  }
  
  
  
}

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>Parent : Profile</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="title" name = "title" aria-label="title"  value="<?php echo $title;?>" required>
    <option selected></option>
    <option value="Dr">Dr</option>
    <option value="Mr">Mr</option>
    <option value="Mrs">Mrs</option>
    <option value="Miss">Miss</option>
    
  </select>
  <label for="floatingSelect">Title</label>
</div> <br />
  
  <div class="form-floating mb-3">
  <input type="text" class="form-control" name="surname" id="surname" placeholder="Surname" value="<?php echo $surname;?>" required autofocus minlength="3" maxlength="30">
  <span class="error">* <?php echo $surnameErr;?></span>
  <br>
  <label for="surname">Surname</label>
</div>

<div class="form-floating mb-3">
  <input type="text" class="form-control" name="cellnum" id="cellnum" placeholder="Cell number" value="<?php echo $cellnum;?>" required minlength="10" maxlength="10" >
  <span class="error">* <?php echo $cellnumErr;?></span>
  
  <label for="cellnum">Cell number</label>
</div>


<div class="form-floating mb-3">
  <input type="text" class="form-control" name="whatsapp" id="whatsapp" placeholder="Whatsapp number" value="<?php echo $whatsapp;?>" required minlength="10" maxlength="10" >
  <span class="error">* <?php echo $whatsappErr;?></span>
  
  <label for="whatsapp">Whatsapp number</label>
</div>

    <div class="form-floating mb-3">
  <input type="text" class="form-control" name="email" id="email" placeholder="E-mail address" value="<?php echo $email;?>" autofocus minlength="10" maxlength="70">
  <span class="error">* <?php echo $emailErr;?></span>
  <br>
  <label for="surname">E-mail (optional)</label>
</div>

   
         <label for="exampleDataList" class="form-label" style="color:red;">I have child/ren in the following school/s. </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);
        }

        $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>
    
     
<input class="form-control" list="towns" id="exampleDataList" name= "to2" placeholder="2. Type and select school name."  >
<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>

         
<input class="form-control" list="towns" id="exampleDataList" name= "to3" placeholder="3. Type and select school name."  >
<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>

         
<input class="form-control" list="towns" id="exampleDataList" name= "to4" placeholder="4. Type and select school name." >
<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>

     
<input class="form-control" list="towns" id="exampleDataList" name= "to5" placeholder="5. Type and select school name."  >
<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>
    
       
<input class="form-control" list="towns" id="exampleDataList" name= "to6" placeholder="6. Type and select school name." >
<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="floatingSelect" style="color:red;" >Login details : Username is your cell number. Please create your password.</label>  <br /> 
        
     <div class="form-floating mb-3">
  <input type="password" class="form-control" name="pass1" id="pass1" placeholder="Password" value="<?php echo $pass1;?>" required autofocus minlength="3" maxlength="30">
  <span class="error">* <?php echo $pass1Err;?></span>
  <br>
  <label for="surname">Password</label>
</div>

    <div class="form-floating mb-3">
  <input type="password" class="form-control" name="pass2" id="pass2" placeholder="Confirm Password" value="<?php echo $pass2;?>" required autofocus minlength="3" maxlength="30">
  <span class="error">* <?php echo $pass2Err;?></span>
  <br>
  <label for="surname">Confirm Password</label>
</div>

   
 <div class="form-floating">
  <select class="form-select" id="hear" name = "hear" aria-label="hear"  value="<?php echo $hear;?>" required>
    <option selected></option>
    <option value="Sms marketing">Sms marketing</option>
    <option value="Word of mouth">Word of mouth</option>
    <option value="School">School</option>
    <option value="Facebook">Facebook</option>
    <option value="Whatsapp group">Whatsapp group</option>
    <option value="Whatsapp">Whatsapp</option>
    <option value="Consultant">Consultant</option>
    <option value="Other">Other</option>
    
  </select>
  <label for="floatingSelect">How did you hear about us</label>
</div> <br />
       
    <div class="d-grid gap-2 col-6 mx-auto">
  <button type="submit" class="btn btn-primary" type="button">SUBMIT</button>
  
</div>
 
  
    </form>

<?php



       

        
        
        if ($counter === 7 ){
            
         
         //getting todays date
         $date = date("Y/m/d");
         
            
        //salting and hashing the password
        
        $pass = $pass1;
        
        //salting
        
        $saltpass = "masiutefoalby is a programmer".$pass;
        
        //hashed
       
       $hashedpass = hash('sha256', $saltpass);
       
       // $hashedpass = password_hash($saltpass, PASSWORD_DEFAULT);
        
      
        
        //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);
        }
        
        
       
       
       
       
        
        
        // prepare and bind
        $stmt = $conn->prepare("INSERT INTO csc (title, surname, cellnum,whatsapp,email,to1,to2,to3,to4,to5,to6,pass,hear,date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        
        $stmt->bind_param("ssssssssssssss", $title, $surname, $cellnum,$whatsapp,$email,$to1,$to2,$to3,$to4,$to5,$to6,$hashedpass,$hear,$date);
        
        $stmt->execute();

        $conn->close();
        
        //echo $counter;
        //sending our welcome message
        
        
        //credentials used are the ones for LETZ CROSS
        /*
        $apiKey = '432447af-a456-49a3-955b-c43053432837';
        $apiSecret = '3bfa90bf-25c7-4945-9317-16eb3b22f770';
        $accountApiCredentials = $apiKey . ':' . $apiSecret;

        $base64Credentials = base64_encode($accountApiCredentials);
        $authHeader = 'Authorization: Basic ' . $base64Credentials;
        */
         //creating a message
        
        /*
        $msg = 'Good day '.$title.' '.$surname.'. Thank you 4 signing up at mysgb.co.za  ur password : '.$pass.' In the best interest of learners. Thanks';
        
        */
        
        //Sending the message
        /*
         $sendData = '{ "messages" : [ { "content" : "'.$msg.'", "destination" : ">>'.$cellnum.'<<" } ] }';

$options = array(
    'http' => array(
        'header' => array("Content-Type: application/json", $authHeader),
        'method' => 'POST',
        'content' => $sendData,
        'ignore_errors' => true
    )
);


$sendResult = file_get_contents('https://rest.smsportal.com/bulkmessages', false, stream_context_create($options));

$status_line = $http_response_header[0];
preg_match('{HTTP\/\S*\s(\d{3})}', $status_line, $match);
$status = $match[1];

*/
        
        
        // 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 in our database. Kindly join our whatsapp group to make communication effective. Whatsapp link is at our homepage.');
    
   
    
    window.alert('You may login, join whatsapp group and place your concern/s.');
    
    
    window.location.href='/myparentslogin.php';
    </script>");
        
        
            
        }


?>

</body>
</html>
