-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgestionDbController.php
57 lines (48 loc) · 1.83 KB
/
gestionDbController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
require '../twig/vendor/autoload.php';
require_once "../model/Db.php";
require_once "../model/LogsModel.php";
session_start();
/* Cargamos twig para usar el render */
$loader = new \Twig\Loader\FilesystemLoader('../view/html');
$twig = new \Twig\Environment($loader);
//Si no es administrador se redirige al inicio
if ($_SESSION['datosUsuario']['rol'] != 'administrador') {
header('Location: inicioController.php');
}
$db = Db::getInstance();
$log = new LogsModel();
$queryString = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
parse_str($queryString, $params);
$tipo = '';
$archivoRestauracion = '';
if (isset($params['tipo'])) {
$tipo = $params['tipo'];
if ($tipo == 'restaurar2' && isset($_FILES['archivoSQL']) && $_FILES['archivoSQL']['error'] === UPLOAD_ERR_OK) {
$archivoRestauracion = file_get_contents($_FILES['archivoSQL']['tmp_name']);
}
}
$archivoRender = 'gestionBBDD.html';
if ($tipo == 'copia' && Db::crearCopiaDeSeguridad()) {
$log->setCopiaSeguridad(date('Y-m-d H:i:s'), $_SESSION['datosUsuario']['email']);
$archivoRender = 'confirmacionesBaseDatos.html';
$tipo = 'crear';
} else if ($tipo == 'restaurar1') {
$tipo = 'restaurar';
} else if ($tipo == 'restaurar2' && Db::restaurarCopiaDeSeguridad($archivoRestauracion)) {
$log->setRestaurarCopiaSeguridad(date('Y-m-d H:i:s'), $_SESSION['datosUsuario']['email']);
header('Location: inicioController.php');
$_SESSION = array();
} else if ($tipo == 'borrar1') {
$tipo = 'borrar';
} else if ($tipo == 'borrar2' && Db::borrarDb()) {
$log->setBorrarDb(date('Y-m-d H:i:s'), $_SESSION['datosUsuario']['email']);
header('Location: inicioController.php');
$_SESSION = array();
}
echo $twig->render($archivoRender, [
'ranking' => $_SESSION['ranking'],
'datosUsuario' => $_SESSION['datosUsuario'],
'tipo' => $tipo
]);
?>