Server IP : 68.65.122.142  /  Your IP : 52.15.177.199
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/mygc.glenbowcollege.ca/student/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/glenirhm//mygc.glenbowcollege.ca/student/submit_documents.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');

// only allow images to be uploaded
//$form->upload_accepted_mimes = 'image/jpg,image/jpeg,image/png,application/pdf';

$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 = '*';

if($form->submit()) {
    $enrollment_contract_upload = $form->post('enrollment_contract_upload');
    $amendment_student_contract_upload = $form->post('amendment_student_contract_upload');
    $signature_page_upload = $form->post('signature_page_upload');

    if(!$form->errors()) {
        echo $_SESSION['name'];
        echo "<br>";
        echo "<br>";

        $username = $_SESSION['name'];
        $enrollment_contract_upload_name = $enrollment_contract_upload['name'];
        $amendment_student_contract_upload_name = $amendment_student_contract_upload['name'];
        $signature_page_upload_name = $signature_page_upload['name'];

        $sql2 = "UPDATE student SET 
        /* Whenever the documents are submitted, we want to block the user
        from submitting them again. This is why we use this variable */
        documents_submitted = 1,
        enrollment_contract_upload = '$enrollment_contract_upload_name',
        amendment_student_contract_upload = '$amendment_student_contract_upload_name',
        signature_page_upload = '$signature_page_upload_name'
        WHERE username = '$username'";

        //echo $sql2;
        if($con->query($sql2) === true){
            //echo "Records inserted successfully.";
            $form->success_message('We received your documents, 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 {
            $confirmation_link = 'https://' . dirname($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 2) . '/admin/view_records.php';		
            $body = '<p>The student has submitted the signed documents. Please inspect the student records to take necessary actions : <a href="' . $confirmation_link . '">' . $confirmation_link . '</a></p>';

            sendEmail($EMAIL_HOST, $EMAIL_USERNAME, $EMAIL_PASS, $EMAIL_FROM, $EMAIL_ROOT, 'A Student Submitted Signed Documents', 
                $body, '', null);

            // Send email to the student
            sendEmail($EMAIL_HOST, $EMAIL_USERNAME, $EMAIL_PASS, $EMAIL_FROM, $_POST['email'], 'You Submitted Signed Documents', 
                'Please wait for the admin to process them', '', 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['documents_submitted'];
    // form_submitted field is changed by the admin
    if ($row['form_submitted'] == 0) {
        echo "You first need to submit the initial form. <br>
        Please contact the administrator if you you have any questions";

    }

    else if ($row['confirmed'] == 0) {
        echo "Please wait for the administrator to confirm your status. <br>
        Please contact the administrator if you you have any questions";

    }    
    
    else if ($row['documents_submitted'] == 1) {
        echo "You already submitted the documents. <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->file('enrollment_contract_upload', 'Upload The Enrollment Contract');
        $form->file('amendment_student_contract_upload', 'Upload The Amendment Student Contract');
        $form->file('signature_page_upload', 'Upload The Signature Page');
        //$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>