<?php
chdir('../../');
require_once 'autoload.php';

$uni = new university_controller;

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['csrf_token']) && isset($_POST['csrf_form_id']) && $waf->csrf_validate($_POST['csrf_form_id'], $_POST['csrf_token'], $utility->action_name())) {

$sanitezed_data = $utility->sanitize_request($_POST);

$old_file = $sanitezed_data['old_file'];
unset($sanitezed_data['old_file']);

if ($_FILES['file']['name'] == "") {

$file = $old_file;

$upload_status = 'OK';

}else{

$ext = $utility->extension($_FILES);
$file = 'signature_'.time();
$upload_status = $utility->uploader('storage/images/misc/', $_FILES, $file, 'png,jpeg,jpg');
$file = $file.'.'.$ext;

}

if ($upload_status == "OK") {



$uni->update($sanitezed_data);

$data_2['sig_file'] = $file;
$uni->update($data_2);

if ($file !== $old_file) {

$utility->delete_file('storage/images/misc/'.$old_file);

}

$utility->setMessage("success", 'General settings updated');

header("location:../settings");

}else{


}




}else{

header("location:../settings");

}
?>
