Révision ff47f4e6
_config/config_template.php | ||
---|---|---|
64 | 64 |
define("DATABASE_USER", "{{dbusername}}"); |
65 | 65 |
define("DATABASE_PASSWORD", "{{dbpassword}}"); |
66 | 66 |
|
67 |
// Autre constantes |
|
67 |
// Mot de passe administrateur |
|
68 |
define ("SUPER_ADMIN","{{supassword}}"); |
|
68 | 69 |
|
70 |
// Autre constantes |
|
69 | 71 |
define ("DEBUG_MODE", "dev"); |
_scripts/berlin1989.php | ||
---|---|---|
1 |
<?php |
|
2 |
/************************************************************************************ |
|
3 |
* |
|
4 |
* Projet AbulEdu Mur de Classe - Licence: GNU/Affero GPL v3 ou + |
|
5 |
* |
|
6 |
* (c) 2020 Frédéric Adamczak <fred@fadamczak.fr> |
|
7 |
* |
|
8 |
* This file is part of AbulEdu Mur de Classe. |
|
9 |
* |
|
10 |
* AbulEdu Mur de Classe is free software: you can redistribute it and/or modify |
|
11 |
* it under the terms of the GNU Affero General Public License as published by |
|
12 |
* the Free Software Foundation, either version 3 of the License, or |
|
13 |
* (at your option) any later version. |
|
14 |
* |
|
15 |
* AbulEdu Mur de Classe is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU Affero General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU General Public License |
|
21 |
* along with ClicAlbum. If not, see <https://www.gnu.org/licenses/>. |
|
22 |
* |
|
23 |
************************************************************************************/ |
|
24 |
|
|
25 |
|
|
26 |
include_once("../_config/config.php"); |
|
27 |
|
|
28 |
echo "<h4>On efface les murs inactifs</h4>"; |
|
29 |
|
|
30 |
try { |
|
31 |
$db = new PDO('mysql:host='.DATABASE_HOST.';dbname='.DATABASE_NAME.';charset=utf8', DATABASE_USER, DATABASE_PASSWORD); |
|
32 |
} catch (PDOException $e) { |
|
33 |
print "Erreur !: " . $e->getMessage(); |
|
34 |
die(); |
|
35 |
} |
|
36 |
|
|
37 |
// On recherche tous les murs inactifs depuis 6 mois |
|
38 |
$periode = date('Y-m-d', strtotime('-12 month')); |
|
39 |
$sql = "SELECT id_mur FROM mur WHERE date_acces < '$periode'"; |
|
40 |
if (!$query=$db->query($sql)) { |
|
41 |
die ("Erreur dans la requete 1"); |
|
42 |
} |
|
43 |
|
|
44 |
$res = $query->fetchAll(PDO::FETCH_NUM); |
|
45 |
|
|
46 |
// Pour chacun de ces murs : |
|
47 |
// 1- on vide le dossier correspondant |
|
48 |
// 2- on le supprime de la base |
|
49 |
foreach($res as $mur) { |
|
50 |
$id = $mur[0]; |
|
51 |
echo "Mur n° ".$id."<br />"; |
|
52 |
$dossier = "../MURS/".$id; |
|
53 |
echo $dossier."<br />"; |
|
54 |
// Lecture du contenu du dossier |
|
55 |
$fichiers = scandir($dossier); |
|
56 |
// On enlève les fichiers . et .. |
|
57 |
array_shift($fichiers); |
|
58 |
array_shift($fichiers); |
|
59 |
// On supprime tous les fichiers restants |
|
60 |
foreach($fichiers as $fichier) { |
|
61 |
$supp = $dossier. DIRECTORY_SEPARATOR .$fichier; |
|
62 |
if (!unlink($supp)) { |
|
63 |
echo "<h5>Erreur dans la suppression de : ".$supp."</h5>"; |
|
64 |
} |
|
65 |
|
|
66 |
// On supprime les briques du mur |
|
67 |
$sql = "DELETE FROM brique WHERE id_mur='$id'"; |
|
68 |
if (!$query=$db->query($sql)) { |
|
69 |
die ("Erreur dans la requete de suppression des briques"); |
|
70 |
} |
|
71 |
} |
|
72 |
// On supprime le répertoire |
|
73 |
if (!rmdir($dossier)) { |
|
74 |
echo "<h5>Erreur dans la suppression du dossier : ".$dossier."</h5>"; |
|
75 |
} |
|
76 |
|
|
77 |
// On supprime les murs de la base. |
|
78 |
$sql = "DELETE FROM mur WHERE date_acces < '$periode'"; |
|
79 |
if (!$query=$db->query($sql)) { |
|
80 |
die ("Erreur dans la requete de suppression du mur"); |
|
81 |
} |
|
82 |
|
|
83 |
} |
|
84 |
|
|
85 |
print "<h4>Opération terminée</h4>"; |
|
86 |
|
|
87 |
?> |
controllers/adminsite_controller.php | ||
---|---|---|
1 |
<?php |
|
2 |
/************************************************************************************ |
|
3 |
* |
|
4 |
* Projet AbulEdu Mur de Classe - Licence: GNU/Affero GPL v3 ou + |
|
5 |
* |
|
6 |
* (c) 2020 Frédéric Adamczak <fred@fadamczak.fr> |
|
7 |
* |
|
8 |
* This file is part of AbulEdu Mur de Classe. |
|
9 |
* |
|
10 |
* AbulEdu Mur de Classe is free software: you can redistribute it and/or modify |
|
11 |
* it under the terms of the GNU Affero General Public License as published by |
|
12 |
* the Free Software Foundation, either version 3 of the License, or |
|
13 |
* (at your option) any later version. |
|
14 |
* |
|
15 |
* AbulEdu Mur de Classe is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU Affero General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU General Public License |
|
21 |
* along with ClicAlbum. If not, see <https://www.gnu.org/licenses/>. |
|
22 |
* |
|
23 |
************************************************************************************/ |
|
24 |
//getVar(); |
|
25 |
|
|
26 |
include_once("_classes/MyException.php"); |
|
27 |
//include_once("_classes/Categorie.php"); |
|
28 |
include_once("_classes/Mur.php"); |
|
29 |
//include_once("_classes/Theme.php"); |
|
30 |
include_once("_classes/Brique.php"); |
|
31 |
//include_once("_classes/Mailer.php"); |
|
32 |
|
|
33 |
// L'utilisateur est il connecté en SUPER_USER |
|
34 |
if ($_SESSION['SUPER_USER'] == "ok") { |
|
35 |
affichePageSuperUser(); |
|
36 |
} else { |
|
37 |
// Y a-t-il eu une tentative de connexion ? |
|
38 |
if (isset($_POST["mdp_su"])) { |
|
39 |
// Le mot de passe saisi est-il le bon ? |
|
40 |
if($_POST['mdp_su']==SUPER_ADMIN) { |
|
41 |
$_SESSION['SUPER_USER'] = "ok"; |
|
42 |
affichePageSuperUser(); |
|
43 |
} else { |
|
44 |
afficheLoginType("<span class='alert alert-danger'>Le mot de passe saisi est incorrect.</span>"); |
|
45 |
|
|
46 |
} |
|
47 |
} else { |
|
48 |
// Afficher le formulaire d'identification |
|
49 |
afficheLoginType(""); |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
function affichePageSuperUser() { |
|
54 |
// Récupération des données nécessaires à l'affichage de la page |
|
55 |
// - nombre total de murs |
|
56 |
// - nombre de mur publics |
|
57 |
// - nombre de muir n'ayant pas été actifs depuis plus de 12 mois |
|
58 |
// - l'ensemble des murs |
|
59 |
// - l'ensemble des briques |
|
60 |
|
|
61 |
$nbMurs = getNbMurs()[0]; |
|
62 |
$nbPublics = getNbMursPublics()[0]; |
|
63 |
$nbInactifs = getNbMursInactifs(date('Y-m-d', strtotime('-12 month')))[0]; |
|
64 |
$murs = getAllMurs(); |
|
65 |
$briques = getAllBriques(); |
|
66 |
|
|
67 |
// Est ce qu'il y a une requete à exécuter ? |
|
68 |
if($_POST['sql'] !='') { |
|
69 |
$requete = execSql(str_secure($_POST['sql'])); |
|
70 |
if ($requete !==false) { |
|
71 |
$res= $requete; |
|
72 |
} else { |
|
73 |
$res = "<p class='alert alert-danger mt-3'>ERREUR dans la requete SQL</p>"; |
|
74 |
} |
|
75 |
//debug($requete); |
|
76 |
} |
|
77 |
|
|
78 |
afficheSuperUser($nbMurs,$nbPublics,$nbInactifs,$murs,$res); |
|
79 |
} |
|
80 |
?> |
models/adminsite_model.php | ||
---|---|---|
1 |
<?php |
|
2 |
/************************************************************************************ |
|
3 |
* |
|
4 |
* Projet AbulEdu Mur de Classe - Licence: GNU/Affero GPL v3 ou + |
|
5 |
* |
|
6 |
* (c) 2020 Frédéric Adamczak <fred@fadamczak.fr> |
|
7 |
* |
|
8 |
* This file is part of AbulEdu Mur de Classe. |
|
9 |
* |
|
10 |
* AbulEdu Mur de Classe is free software: you can redistribute it and/or modify |
|
11 |
* it under the terms of the GNU Affero General Public License as published by |
|
12 |
* the Free Software Foundation, either version 3 of the License, or |
|
13 |
* (at your option) any later version. |
|
14 |
* |
|
15 |
* AbulEdu Mur de Classe is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU Affero General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU General Public License |
|
21 |
* along with ClicAlbum. If not, see <https://www.gnu.org/licenses/>. |
|
22 |
* |
|
23 |
************************************************************************************/ |
|
24 |
|
|
25 |
/** |
|
26 |
* Retourne le nombre total de mur présents dans la BDD |
|
27 |
* @return [Array] [Nombre de murs (tableau inidce)] |
|
28 |
*/ |
|
29 |
function getNbMurs() { |
|
30 |
global $db; |
|
31 |
|
|
32 |
$sql="SELECT COUNT(id_mur) FROM mur"; |
|
33 |
|
|
34 |
try { |
|
35 |
if (!$query=$db->query($sql)) { |
|
36 |
throw new MyException("Erreur dans le SELECT"); |
|
37 |
} else { |
|
38 |
$query->setFetchMode(PDO::FETCH_NUM); |
|
39 |
return ($query->fetch()); |
|
40 |
} |
|
41 |
} catch (MyException $e) { |
|
42 |
$e->errorMessage(); |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Retourne le nombre de murs publics |
|
48 |
* @return [Arrazy] [tableau indicé ] |
|
49 |
*/ |
|
50 |
function getNbMursPublics() { |
|
51 |
global $db; |
|
52 |
|
|
53 |
$sql="SELECT COUNT(id_mur) FROM mur WHERE mdp_acces =''"; |
|
54 |
try { |
|
55 |
if (!$query=$db->query($sql)) { |
|
56 |
throw new MyException("Erreur dans le SELECT"); |
|
57 |
} else { |
|
58 |
$query->setFetchMode(PDO::FETCH_NUM); |
|
59 |
return ($query->fetch()); |
|
60 |
} |
|
61 |
} catch (MyException $e) { |
|
62 |
$e->errorMessage(); |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Retourne les murs dont la dernière activité remonte à plus de 6 mois |
|
68 |
* @param [type] $sixMois [description] |
|
69 |
* @return [type] [description] |
|
70 |
*/ |
|
71 |
function getNbMursInactifs($periode) { |
|
72 |
global $db; |
|
73 |
|
|
74 |
$sql = "SELECT COUNT(id_mur) FROM mur WHERE date_acces < '$periode'"; |
|
75 |
try { |
|
76 |
if (!$query=$db->query($sql)) { |
|
77 |
throw new MyException("Erreur dans le SELECT"); |
|
78 |
} else { |
|
79 |
$query->setFetchMode(PDO::FETCH_NUM); |
|
80 |
return ($query->fetch()); |
|
81 |
} |
|
82 |
} catch (MyException $e) { |
|
83 |
$e->errorMessage(); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Retourne l'ensemble des murs |
|
89 |
* @return [Array] [Classe Mur] |
|
90 |
*/ |
|
91 |
function getAllMurs() { |
|
92 |
global $db; |
|
93 |
$sql = "SELECT * FROM mur ORDER BY id_mur"; |
|
94 |
try { |
|
95 |
if (!$query=$db->query($sql)) { |
|
96 |
throw new MyException("Erreur dans le SELECT"); |
|
97 |
} else { |
|
98 |
return ($query->fetchAll(PDO::FETCH_CLASS,"Mur")); |
|
99 |
} |
|
100 |
} catch (MyException $e) { |
|
101 |
$e->errorMessage(); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Retourne l'ensemble des briques |
|
107 |
* @return [Array] [Assoc] |
|
108 |
*/ |
|
109 |
function getAllBriques() { |
|
110 |
global $db; |
|
111 |
$sql = "SELECT * FROM brique ORDER BY id_mur"; |
|
112 |
try { |
|
113 |
if (!$query=$db->query($sql)) { |
|
114 |
throw new MyException("Erreur dans le SELECT"); |
|
115 |
} else { |
|
116 |
return ($query->fetchAll(PDO::FETCH_ASSOC)); |
|
117 |
} |
|
118 |
} catch (MyException $e) { |
|
119 |
$e->errorMessage(); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* Exécute une requete SQL passée en paramètres |
|
125 |
* @param [String] $sql [Requete à exécuter] |
|
126 |
* @return [Array/Boolean] [Faux si la requete n'a pu s'exécuter / Array de resultats] |
|
127 |
*/ |
|
128 |
function execSql($sql) { |
|
129 |
global $db; |
|
130 |
if ($query = $db->query($sql)) { |
|
131 |
return $query->fetchAll(PDO::FETCH_ASSOC); |
|
132 |
} else { |
|
133 |
return(false); |
|
134 |
} |
|
135 |
} |
|
136 |
?> |
views/adminsite_view.php | ||
---|---|---|
1 |
<?php |
|
2 |
/************************************************************************************ |
|
3 |
* |
|
4 |
* Projet AbulEdu Mur de Classe - Licence: GNU/Affero GPL v3 ou + |
|
5 |
* |
|
6 |
* (c) 2020 Frédéric Adamczak <fred@fadamczak.fr> |
|
7 |
* |
|
8 |
* This file is part of AbulEdu Mur de Classe. |
|
9 |
* |
|
10 |
* AbulEdu Mur de Classe is free software: you can redistribute it and/or modify |
|
11 |
* it under the terms of the GNU Affero General Public License as published by |
|
12 |
* the Free Software Foundation, either version 3 of the License, or |
|
13 |
* (at your option) any later version. |
|
14 |
* |
|
15 |
* AbulEdu Mur de Classe is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU Affero General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU General Public License |
|
21 |
* along with ClicAlbum. If not, see <https://www.gnu.org/licenses/>. |
|
22 |
* |
|
23 |
************************************************************************************/ |
|
24 |
|
|
25 |
function afficheSuperUser($nbMurs,$nbPublics,$nbInactifs,$murs,$requete) { |
|
26 |
?> |
|
27 |
|
|
28 |
<!doctype html> |
|
29 |
<html> |
|
30 |
<head> |
|
31 |
|
|
32 |
<?php include_once 'views/includes/head.php'?> |
|
33 |
|
|
34 |
<title><?= ucfirst($page) ?></title> |
|
35 |
</head> |
|
36 |
|
|
37 |
<body> |
|
38 |
|
|
39 |
<?php include_once 'views/includes/header.php'?> |
|
40 |
<div class="container"> |
|
41 |
<div class="row mt-4"> |
|
42 |
<div class="col-sm-3 ml-2 alert alert-primary"> |
|
43 |
<?=$nbMurs?> mur(s) enregistré(s) |
|
44 |
</div> |
|
45 |
<div class="col-sm-3 ml-2 alert alert-success"> |
|
46 |
<p> |
|
47 |
<?=$nbPublics?> mur(s) public(s) |
|
48 |
</p> |
|
49 |
<p> |
|
50 |
<?=$nbMurs-$nbPublics?> mur(s) privé(s) |
|
51 |
</p> |
|
52 |
</div> |
|
53 |
<div class="col-sm-3 ml-2 alert alert-secondary"> |
|
54 |
<p> |
|
55 |
<?=$nbInactifs?> mur(s) inactif(s) |
|
56 |
</p> |
|
57 |
<p id="trash"> |
|
58 |
<i class="fas fa-trash-alt"></i> Effacer les murs inactifs |
|
59 |
</p> |
|
60 |
</div> |
|
61 |
</div> |
|
62 |
|
|
63 |
<hr /> |
|
64 |
|
|
65 |
<div class="row mt-4 mb-4"> |
|
66 |
<div class="col-sm-12"> |
|
67 |
<form method="post"> |
|
68 |
<div class="form-group"> |
|
69 |
<label for="sql">Requete SQL</label> |
|
70 |
<input type="text" class="form-control" id="sql" name="sql"> |
|
71 |
</div> |
|
72 |
<button type="submit" class="btn btn-primary">lancer la requete</button> |
|
73 |
</form> |
|
74 |
</div> |
|
75 |
|
|
76 |
|
|
77 |
<div class="col-sm-12"> |
|
78 |
|
|
79 |
<?php |
|
80 |
if (strpos($requete,"ERREUR dans la requete SQL")>0) { |
|
81 |
print $requete; |
|
82 |
} else { |
|
83 |
|
|
84 |
print "<div class='alert alert-success mt-3 mb-2'>"; |
|
85 |
print "Résultats de la requete"; |
|
86 |
print "</div>"; |
|
87 |
|
|
88 |
print "<table class='table table-striped'>"; |
|
89 |
|
|
90 |
print "<thead>"; |
|
91 |
print "<tr>"; |
|
92 |
foreach ($requete[0] as $key => $value) { |
|
93 |
print "<th scope='col'>$key</th>"; |
|
94 |
} |
|
95 |
print "</tr>"; |
|
96 |
print "</thead>"; |
|
97 |
|
|
98 |
print "<tbody>"; |
|
99 |
|
|
100 |
foreach ($requete as $sql) { |
|
101 |
print "<tr>"; |
|
102 |
$i=0; |
|
103 |
foreach ($sql as $key => $value) { |
|
104 |
if ($i==0) { |
|
105 |
print "<th scope='row'>$value</th>"; |
|
106 |
} else { |
|
107 |
print "<td>$value</td>"; |
|
108 |
} |
|
109 |
++$i; |
|
110 |
} |
|
111 |
print "</tr>"; |
|
112 |
} |
|
113 |
print "</tbody>"; |
|
114 |
|
|
115 |
print "</table>"; |
|
116 |
} |
|
117 |
?> |
|
118 |
</div> |
|
119 |
</div> |
|
120 |
|
|
121 |
<hr /> |
|
122 |
|
|
123 |
<div class="row mt-4" id="lesMurs"> |
|
124 |
<div class="col-sm-12"> |
|
125 |
<b>LISTE DES MURS</b> |
|
126 |
</div> |
|
127 |
<table class="table table-striped"> |
|
128 |
<thead> |
|
129 |
<tr> |
|
130 |
<th scope="col">#</th> |
|
131 |
<th scope="col">nom</th> |
|
132 |
<th scope="col">slug</th> |
|
133 |
<th scope="col">descriptif</th> |
|
134 |
<th scope="col">date création</th> |
|
135 |
<th scope="col">dernier accès</th> |
|
136 |
</tr> |
|
137 |
</thead> |
|
138 |
<tbody> |
|
139 |
<?php |
|
140 |
foreach($murs as $mur) { |
|
141 |
print "<tr>"; |
|
142 |
print "<th scope='row'>".$mur->getid()."</th>"; |
|
143 |
print "<td>".$mur->getNom()."</td>"; |
|
144 |
print "<td>".$mur->getSlug()."</td>"; |
|
145 |
print "<td>".$mur->getDescriptif()."</td>"; |
|
146 |
print "<td>".$mur->getDateCreation()."</td>"; |
|
147 |
print "<td>".$mur->getDateAcces()."</td>"; |
|
148 |
print "</tr>"; |
|
149 |
} |
|
150 |
?> |
|
151 |
</tbody> |
|
152 |
</table> |
|
153 |
</div> |
|
154 |
|
|
155 |
</body> |
|
156 |
|
|
157 |
<script language='javascript'> |
|
158 |
|
|
159 |
$('#trash').hover(function(){ |
|
160 |
$('#trash').css('cursor','pointer'); |
|
161 |
}); |
|
162 |
$('#trash').on('click',function(){ |
|
163 |
if (confirm("Es-tu certaint de vouloir supprimer ces murs ?") == true) { |
|
164 |
console.log("on supprime les murs"); |
|
165 |
location.href = "_scripts/berlin1989.php"; |
|
166 |
} |
|
167 |
}); |
|
168 |
|
|
169 |
</script> |
|
170 |
</html> |
|
171 |
|
|
172 |
<?php |
|
173 |
} |
|
174 |
|
|
175 |
function afficheLoginType($msg) { |
|
176 |
?> |
|
177 |
|
|
178 |
<!doctype html> |
|
179 |
<html> |
|
180 |
<head> |
|
181 |
|
|
182 |
<?php include_once 'views/includes/head.php'?> |
|
183 |
|
|
184 |
<title><?= ucfirst($page) ?></title> |
|
185 |
</head> |
|
186 |
|
|
187 |
<body> |
|
188 |
|
|
189 |
<?php include_once 'views/includes/header.php'?> |
|
190 |
<div class="container"> |
|
191 |
<form method="post"> |
|
192 |
<?=$msg?> |
|
193 |
<div class="form-group"> |
|
194 |
<label for="mdp_su">Password</label> |
|
195 |
<input type="password" class="form-control" id="mdp_su" name="mdp_su"> |
|
196 |
</div> |
|
197 |
<button type="submit" class="btn btn-primary">OK</button> |
|
198 |
</form> |
|
199 |
</div> |
|
200 |
|
|
201 |
</body> |
|
202 |
</html> |
|
203 |
|
|
204 |
<?php } ?> |
Formats disponibles : Unified diff