<?php

require_once 'private/LMS_Engine.php';
$engine = new LMS_Engine();
$msg = "";
if (isset($_POST) && isset($_POST['update_profile'])) {
    if ($engine->is_librarian($_POST['cr_user_name'], $_POST['cr_user_pass'])) {
        if (strlen($_POST['nw_full_name']) > 3 && strlen($_POST['nw_user_name']) > 3 && strlen($_POST['nw_user_pass']) > 3) {
            if (!$engine->is_librarian($_POST['nw_user_name'], $_POST['nw_user_pass'])) {
                $con = $engine->add_new_librarian($_POST['nw_full_name'], $_POST['nw_user_name'], $_POST['nw_user_pass']);
                if ($con) {
                    $user_id = $engine->get_user_id_by($_POST['cr_user_name'], $_POST['cr_user_pass']);
                    $engine->remove_user_by($user_id);
                    $engine->add_new_librarian($_POST['nw_full_name'], $_POST['nw_user_name'], $_POST['nw_user_name']);
                    $msg = "Your profile is successfully updated!";
                } else {
                    $msg = "The system cannot update your profile! please notify to the Admin";
                }
            } else {
                $msg = "Your new user name and password are not valid. please use another one";
            }
        } else {
            $msg = "Your new user name and password character length is so short. please use 4 characters and more";
        }
    } else {
        $msg = "Your current user name and password are not valid";
    }
}
?>
<div class="container" id="main">
    <div  class="row" id="contact">