On passe au nouveau système de framework !

This commit is contained in:
Pierre-Lin Bonnemaison 2015-08-08 13:23:47 +02:00
parent 8b61ea0a9a
commit 0f47389ae1
13 changed files with 408 additions and 432 deletions

View file

@ -32,7 +32,7 @@
global $db;
//Recupération des commandes
$commands = $db->getAll('commands');
$commands = $db->getFromTableWhere('commands');
$this->render('commands', array(
'commands' => $commands,
@ -42,24 +42,24 @@
/**
* Cette fonction va supprimer une liste de commands
* @return void;
* @param int... $ids : Les id des commandes à supprimer
* @return boolean;
*/
public function delete()
public function delete(...$ids)
{
if (!internalTools::verifyCSRF())
{
header('Location: ' . $this->generateUrl('commands', 'showAll', array(
'errormessage' => 'Jeton CSRF invalide !'
)));
return true;
$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
header('Location: ' . $this->generateUrl('commands', 'showAll'));
return false;
}
//Create de l'object de base de données
global $db;
$commands_ids = $_GET;
$db->deleteCommandsIn($commands_ids);
$db->deleteCommandsIn($ids);
header('Location: ' . $this->generateUrl('commands'));
return true;
}
/**
@ -71,14 +71,14 @@
}
/**
* Cette fonction retourne la page d'édition des contacts
* Cette fonction retourne la page d'édition des commandes
* @param int... $ids : Les id des commandes à editer
*/
public function edit()
public function edit(...$ids)
{
global $db;
$commands = $db->getCommandsIn($_GET);
$commands = $db->getCommandsIn($ids);
$this->render('editCommands', array(
'commands' => $commands,
));
@ -86,72 +86,66 @@
/**
* Cette fonction insert une nouvelle commande
* @param string $_POST['name'] : Le nom de la commande
* @param string $_POST['script'] : Le script a appeler
* @param boolean $_POST['admin'] : Si la commande necessite les droits d'admin (par défaut non)
* @return boolean;
*/
public function create()
{
if (!internalTools::verifyCSRF())
{
header('Location: ' . $this->generateUrl('commands', 'showAll', array(
'errormessage' => 'Jeton CSRF invalide !'
)));
$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
header('Location: ' . $this->generateUrl('commands', 'showAll'));
return true;
}
global $db;
$nom = $_POST['name'];
$script = $_POST['script'];
$admin = (isset($_POST['admin']) ? $_POST['admin'] : false);
if ($db->createCommand($nom, $script, $admin))
{
$db->createEvent('COMMAND_ADD', 'Ajout commande : ' . $nom . ' => ' . $script);
header('Location: ' . $this->generateUrl('commands', 'showAll', array(
'successmessage' => 'La commande a bien été créée.'
)));
return true;
if (!$db->insertIntoTable('commands', ['name' => $nom, 'script' => $script, 'admin' => $admin]))
{
$_SESSION['errormessage'] = 'Impossible créer cette commande.';
header('Location: ' . $this->generateUrl('commands', 'add'));
return false;
}
header('Location: ' . $this->generateUrl('commands', 'add', array(
'errormessage' => 'Impossible créer cette commande.'
)));
return false;
$db->insertIntoTable('events', ['type' => 'COMMAND_ADD', 'text' => 'Ajout commande : ' . $nom . ' => ' . $script]);
$_SESSION['successmessage'] = 'La commande a bien été créée.';
header('Location: ' . $this->generateUrl('commands', 'showAll'));
return true;
}
/**
* Cette fonction met à jour une commande
* @param array $_POST['commands'] : Un tableau des commandes avec leur nouvelle valeurs
* @return boolean;
*/
public function update()
{
if (!internalTools::verifyCSRF())
{
header('Location: ' . $this->generateUrl('commands', 'showAll', array(
'errormessage' => 'Jeton CSRF invalide !'
)));
return true;
$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
header('Location: ' . $this->generateUrl('commands', 'showAll'));
return false;
}
global $db;
$errors = array(); //On initialise le tableau qui contiendra les erreurs rencontrés
//Pour chaque commande reçu, on boucle en récupérant son id (la clef), et la commande elle-même (la value)
foreach ($_POST['commands'] as $id => $command)
{
$db->updateCommand($id, $command['name'], $command['script'], $command['admin']);
$db->updateTableWhere('commands', $command, ['id' => $id]);
}
$message = 'Toutes les commandes ont été modifiées avec succès.';
header('Location: ' . $this->generateUrl('commands', 'showAll', array(
'successmessage' => $message,
)));
}
public function flagMeThat()
{
var_dump(internalTools::parseForFlag('[COMMAND:chauffer 35][PASSWORD:mon password qui rox][LOGin:monlogin]'));
$_SESSION['successmessage'] = 'Toutes les commandes ont été modifiées avec succès.';
header('Location: ' . $this->generateUrl('commands', 'showAll'));
}
}