forked from jxdm-dmoreau/logiciel_de_compte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
executable file
·83 lines (58 loc) · 2.01 KB
/
admin.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
// Inclusion des librairies
require_once('./smarty/Smarty.class.php');
require_once('./include/MySQL.php');
require_once('./include/chrono.php');
require_once('./include/graph_line.php');
require_once('./include/graph_3D_pie.php');
require_once('./include/graph_bar.php');
require_once('./include/Categorie.php');
session_start();
if (!isset($_SESSION['id'])) {
include('error.php');
die();
}
// Temps pour générer la page
$chrono = new chrono();
$chrono->start();
$mysql = new MySQL('localhost','root','Kamikas1','compte'); //MySQL
$oSmarty = new Smarty(); //Smarty
$oCat = $_SESSION['cat'];
// Ajout d'une nouvelle categorie
if (isset($_POST['state']) && $_POST['state'] == 1 && isset($_POST['id_cat']) && isset($_POST['name_cat'])) {
extract($_POST);
$query = "INSERT INTO categories VALUES ('','$name_cat','$id_cat', '$color_cat')";
$mysql->query($query);
$oCat = new Categorie($mysql);
$_SESSION['cat'] = $oCat;
$debug = $query;
}
// Suppression d'une catégorie
if (isset($_POST['state']) && ($_POST['state'] == 3) && isset($_POST['id_cat'])) {
extract($_POST);
//$query = "DELETE FROM categories WHERE id='$id_cat'";
$oCat->remove($id_cat, $mysql);
$debug = "La catégorie $id_cat a été supprimée.";
//$mysql->query($query);
$oCat = new Categorie($mysql);
$_SESSION['cat'] = $oCat;
}
// Modification d'une catégorie
if (isset($_POST['state']) && $_POST['state'] == 2) {
extract($_POST);
$query = "UPDATE categories SET name='$name_cat', color='$color_cat' WHERE id=$id_cat";
$mysql->query($query);
$oCat = new Categorie($mysql);
$_SESSION['cat'] = $oCat;
}
$oSmarty->assign('TEST', $oCat->getTreeJs());
$oSmarty->assign('DEBUG', $debug);
$oSmarty->assign('POST', $_POST);
// stats
$chrono->stop();
$oSmarty->assign("TIME",$chrono->getTime());
$oSmarty->assign("REQUESTS",$mysql->nbRequest);
// Affichage du template après compilation
$oSmarty->debugging = false;
$oSmarty->display('admin.html');
?>