<?php

include_once 'Functions.php';
if (isset($_POST)) {
    if (isset($_POST['reg_user'])) {
        require_once '../private/LMS_Engine.php';
        $engine = new LMS_Engine();
        $file = $_FILES['upload_image'];
        $uploaded = upload_image($file);
        if (strlen($uploaded) == 34) {
            if ($_POST['user_type'] == 'student') {
                $val = $engine->add_student_user($engine->new_pocket_id(), $_POST['full_name'], $_POST['grade'], $_POST['section'], $uploaded);
                if ($val == 1) {
                    header("Location: ../Librarian.php?page=add_new_student");
                    exit;
                } else {
                    header("Location: ../Librarian.php?page=add_new_student");
                    exit;
                }
            } else {
                $val = $engine->add_new_teacher($_POST['full_name'], $_POST['user_name'], $_POST['user_pass'], $_POST['department']);
                header("Location: ../Librarian.php?page=add_new_student");
                exit;
            }
        } else {
            header("Location: ../Librarian.php?page=add_new_student");
            exit;
        }
    }
    if (isset($_POST['upload_books'])) {
        require_once '../private/File_Manager.php';