Ajout du système de transfert des sms vers un email

This commit is contained in:
Pierre-Lin Bonnemaison 2015-08-18 04:37:20 +02:00
parent 9a70e23c0a
commit f2c6c3c7a7
6 changed files with 198 additions and 32 deletions

View File

@ -55,6 +55,7 @@
$_SESSION['connect'] = true;
$_SESSION['admin'] = $user['admin'];
$_SESSION['email'] = $user['email'];
$_SESSION['transfer'] = $user['transfer'];
$_SESSION['csrf'] = str_shuffle(uniqid().uniqid());
header('Location: ' . $this->generateUrl(''));
return true;

View File

@ -20,6 +20,11 @@
),
'optionals' => array(),
),
'sendTransfers' => array(
'description' => 'Cette commande permet d\'envoyer par mails les sms à transférés.',
'requireds' => [],
'optionals' => [],
),
);
$message = "Vous êtes ici dans l'aide de la console.\n";
@ -274,6 +279,9 @@
die(7);
}
//On insert le SMS dans le tableau des sms à envoyer par mail
$db->insertIntoTable('transfers', ['content' => $content]);
//Chaque commande sera executée.
foreach ($found_commands as $command_name => $command)
{
@ -286,4 +294,45 @@
sleep(2);
}
}
/**
* Cette fonction permet d'envoyer par mail les sms à transférer
*/
public function sendTransfers ()
{
global $db;
$transfers = $db->getFromTableWhere('transfers', ['progress' => false]);
$ids_transfers = [];
$ids_receiveds = [];
foreach ($transfers as $transfer)
{
$ids_transfers[] = $transfer['id'];
$ids_receiveds[] = $transfer['id_received'];
}
$db->updateProgressTransfersIn($ids_transfers, true);
$receiveds = $db->getReceivedsIn($ids_receiveds);
$users = $db->getFromTableWhere('users', ['transfer' => true]);
foreach ($users as $user)
{
foreach ($receiveds as $received)
{
echo "Transfer d'un SMS du " . $received['send_by'] . " à l'email " . $user['email'];
$to = $user['email'];
$subject = '[RaspiSMS] - Transfert d\'un SMS du ' . $received['send_by'];
$message = "
Le numéro " . $received['send_by'] . " vous a envoyé un SMS\n
-----------------------------------------------------------\n" . $received['content'];
$ok = mail($to, $subject, $message);
echo " ... " . ($ok ? 'OK' : 'KO') . "\n";
}
}
}
}

View File

@ -35,7 +35,7 @@
if (!internalTools::verifyCSRF($csrf))
{
$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
header('Location: ' . $this->generateUrl('profile', 'showAll'));
header('Location: ' . $this->generateUrl('profile'));
return false;
}
@ -45,7 +45,7 @@
if (empty($_POST['password']) || empty($_POST['verif_password']) || $_POST['password'] != $_POST['verif_password'])
{
$_SESSION['errormessage'] = 'Les mots de passe ne correspondent pas.';
header('Location: ' . $this->generateUrl('profile', 'show'));
header('Location: ' . $this->generateUrl('profile'));
return false;
}
@ -55,12 +55,52 @@
if (!$db->updateTableWhere('users', ['password' => $password], ['id' => $user[0]['id']]))
{
$_SESSION['errormessage'] = 'Impossible de mettre à jour le mot de passe.';
header('Location: ' . $this->generateUrl('profile', 'show'));
header('Location: ' . $this->generateUrl('profile'));
return false;
}
$_SESSION['successmessage'] = 'Les données ont été mises à jour.';
header('Location: ' . $this->generateUrl('profile', 'show'));
header('Location: ' . $this->generateUrl('profile'));
return true;
}
/**
* Cette fonction change la valeur du champ "transfer" de l'utilisateur
* @param $csrf : Le jeton CSRF
* @param string $_POST['transfer'] : Le nouveau transfer de l'utilisateur
* @return void;
*/
public function changeTransfer($csrf)
{
//On vérifie que le jeton csrf est bon
if (!internalTools::verifyCSRF($csrf))
{
$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
header('Location: ' . $this->generateUrl('profile'));
return false;
}
//Creation de l'object de base de données
global $db;
if (!isset($_POST['transfer']))
{
$_SESSION['errormessage'] = 'Vous devez renseigner un valeur';
header('Location: ' . $this->generateUrl('profile'));
return false;
}
$transfer = (boolean)$_POST['transfer'];
if (!$db->updateTableWhere('users', ['transfer' => $transfer], ['email' => $_SESSION['email']]))
{
$_SESSION['errormessage'] = 'Impossible de mettre les données à jour.';
header('Location: ' . $this->generateUrl('profile'));
return false;
}
$_SESSION['transfer'] = $transfer;
$_SESSION['successmessage'] = 'Les données ont été mises à jour.';
header('Location: ' . $this->generateUrl('profile'));
return true;
}
@ -77,7 +117,7 @@
if (!internalTools::verifyCSRF($csrf))
{
$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
header('Location: ' . $this->generateUrl('profile', 'showAll'));
header('Location: ' . $this->generateUrl('profile'));
return false;
}
@ -88,7 +128,7 @@
if (empty($_POST['mail']) || empty($_POST['verif_mail']) || $_POST['mail'] != $_POST['verif_mail'])
{
$_SESSION['errormessage'] = 'Les e-mails ne correspondent pas.';
header('Location: ' . $this->generateUrl('profile', 'show', array(
header('Location: ' . $this->generateUrl('profile', array(
'errormessage' => 'Les e-mails ne correspondent pas.'
)));
return false;
@ -99,7 +139,7 @@
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$_SESSION['errormessage'] = 'L\'adresse e-mail est invalide.';
header('Location: ' . $this->generateUrl('profile', 'show'));
header('Location: ' . $this->generateUrl('profile'));
return false;
}
@ -108,13 +148,13 @@
if (!$db->updateTableWhere('users', ['email' => $email], ['id' => $user[0]['id']]))
{
$_SESSION['errormessage'] = 'Cette adresse e-mail est déjà utilisée.';
header('Location: ' . $this->generateUrl('profile', 'show'));
header('Location: ' . $this->generateUrl('profile'));
return false;
}
$_SESSION['email'] = $email;
$_SESSION['successmessage'] = 'Les données ont été mises à jour.';
header('Location: ' . $this->generateUrl('profile', 'show'));
header('Location: ' . $this->generateUrl('profile'));
return true;
}
@ -130,7 +170,7 @@
if (!internalTools::verifyCSRF($csrf))
{
$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
header('Location: ' . $this->generateUrl('profile', 'showAll'));
header('Location: ' . $this->generateUrl('profile'));
return false;
}
@ -141,14 +181,14 @@
if (empty($_POST['delete_account']))
{
$_SESSION['errormessage'] = 'Le compte n\'a pas été supprimé';
header('Location: ' . $this->generateUrl('profile', 'show'));
header('Location: ' . $this->generateUrl('profile'));
return false;
}
if (!$db->deleteFromTableWhere('users', ['email' => $_SESSION['email']]))
{
$_SESSION['errormessage'] = 'Impossible de supprime le compte';
header('Location: ' . $this->generateUrl('profile', 'show'));
header('Location: ' . $this->generateUrl('profile'));
return false;
}

View File

@ -3,7 +3,7 @@
CREATE DATABASE IF NOT EXISTS raspisms;
USE raspisms;
CREATE TABLE receiveds
CREATE TABLE IF NOT EXISTS receiveds
(
id INT NOT NULL AUTO_INCREMENT,
at DATETIME NOT NULL,
@ -13,7 +13,7 @@ CREATE TABLE receiveds
PRIMARY KEY (id)
);
CREATE TABLE sendeds
CREATE TABLE IF NOT EXISTS sendeds
(
id INT NOT NULL AUTO_INCREMENT,
at DATETIME NOT NULL,
@ -22,7 +22,7 @@ CREATE TABLE sendeds
PRIMARY KEY (id)
);
CREATE TABLE scheduleds
CREATE TABLE IF NOT EXISTS scheduleds
(
id INT NOT NULL AUTO_INCREMENT,
at DATETIME NOT NULL,
@ -31,7 +31,7 @@ CREATE TABLE scheduleds
PRIMARY KEY (id)
);
CREATE TABLE contacts
CREATE TABLE IF NOT EXISTS contacts
(
id INT NOT NULL AUTO_INCREMENT,
@ -41,7 +41,7 @@ CREATE TABLE contacts
UNIQUE (name)
);
CREATE TABLE groups
CREATE TABLE IF NOT EXISTS groups
(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
@ -49,7 +49,7 @@ CREATE TABLE groups
UNIQUE (name)
);
CREATE TABLE groups_contacts
CREATE TABLE IF NOT EXISTS groups_contacts
(
id INT NOT NULL AUTO_INCREMENT,
id_group INT NOT NULL,
@ -59,7 +59,7 @@ CREATE TABLE groups_contacts
FOREIGN KEY (id_contact) REFERENCES contacts (id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE scheduleds_contacts
CREATE TABLE IF NOT EXISTS scheduleds_contacts
(
id INT NOT NULL AUTO_INCREMENT,
id_scheduled INT NOT NULL,
@ -69,7 +69,7 @@ CREATE TABLE scheduleds_contacts
FOREIGN KEY (id_contact) REFERENCES contacts (id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE scheduleds_groups
CREATE TABLE IF NOT EXISTS scheduleds_groups
(
id INT NOT NULL AUTO_INCREMENT,
id_scheduled INT NOT NULL,
@ -79,7 +79,7 @@ CREATE TABLE scheduleds_groups
FOREIGN KEY (id_group) REFERENCES groups (id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE scheduleds_numbers
CREATE TABLE IF NOT EXISTS scheduleds_numbers
(
id INT NOT NULL AUTO_INCREMENT,
id_scheduled INT NOT NULL,
@ -88,7 +88,7 @@ CREATE TABLE scheduleds_numbers
FOREIGN KEY (id_scheduled) REFERENCES scheduleds (id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE commands
CREATE TABLE IF NOT EXISTS commands
(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(25) NOT NULL,
@ -98,7 +98,7 @@ CREATE TABLE commands
UNIQUE (name)
);
CREATE TABLE events
CREATE TABLE IF NOT EXISTS events
(
id INT NOT NULL AUTO_INCREMENT,
type VARCHAR(25) NOT NULL,
@ -107,13 +107,22 @@ CREATE TABLE events
PRIMARY KEY (id)
);
CREATE TABLE users
CREATE TABLE IF NOT EXISTS users
(
id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
admin BOOLEAN NOT NULL,
admin BOOLEAN NOT NULL DEFAULT FALSE,
transfer BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (id),
UNIQUE (email)
);
CREATE TABLE IF NOT EXISTS transfers
(
id INT NOT NULL AUTO_INCREMENT,
id_received INT NOT NULL,
progress BOOLEAN NOT NULL DEFAULT 0,
PRIMARY KEY (id),
FOREIGN KEY (id_received) REFERENCES receiveds (id) ON DELETE CASCADE ON UPDATE CASCADE
);

View File

@ -139,6 +139,30 @@
return $this->runQuery($query, $params);
}
/**
* Récupère les receiveds dont l'id fait partie de la liste fournie
* @param array $receiveds_ids = Tableau des id des receiveds voulus
* @return array : Retourne un tableau avec les receiveds adaptés
*/
public function getReceivedsIn($receiveds_ids)
{
$query = "
SELECT *
FROM receiveds
WHERE id ";
//On génère la clause IN et les paramètres adaptés depuis le tableau des id
$generted_in = $this->generateInFromArray($receiveds_ids);
$query .= $generted_in['QUERY'];
$params = $generted_in['PARAMS'];
return $this->runQuery($query, $params);
}
/***********************************/
/* PARTIE DES REQUETES DISCUSSIONS */
/***********************************/
/**
* Récupère les SMS reçus groupé par numéro et trié par date
* @return array : Le tablea avec les sms et la date
@ -712,4 +736,28 @@
return $this->runQuery($query, $params, self::ROWCOUNT);
}
/*********************************/
/* PARTIE DES REQUETES TRANSFERS */
/*********************************/
/**
* Change le statut des tranfers dont l'id est fourni dans $transfers_id
* @param array $transfers_ids = Tableau des id des transfers voulus
* @return int : Retourne le nombre de lignes mises à jour
*/
public function updateProgressTransfersIn($transfers_ids, $progress)
{
$query = "
UPDATE transfers
SET progress = :progress
WHERE id ";
//On génère la clause IN et les paramètres adaptés depuis le tableau des id
$generted_in = $this->generateInFromArray($transfers_ids);
$query .= $generted_in['QUERY'];
$params = $generted_in['PARAMS'];
$params['progress'] = (boolean)$progress;
return $this->runQuery($query, $params, self::ROWCOUNT);
}
}

View File

@ -64,6 +64,23 @@
</form>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><i class="fa fa-trash-o fa-fw"></i> Supprimer ce compte</h4>
</div>
<div class="panel-body">
<form action="<?php echo $this->generateUrl('profile', 'delete', [$_SESSION['csrf']]); ?>" method="POST">
<div class="checkbox">
<label>
<input name="delete_account" type="checkbox" value="1" /> Je suis totalement sûr de vouloir supprimer ce compte
</label>
</div>
<div class="text-center">
<button class="btn btn-danger">Supprimer ce compte</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-xs-12 col-md-6">
<div class="panel panel-default">
@ -88,17 +105,19 @@
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><i class="fa fa-trash-o fa-fw"></i> Supprimer ce compte</h4>
<h4 class="panel-title"><i class="fa fa-share fa-fw"></i> Transfert des SMS par e-mail</h4>
</div>
<div class="panel-body">
<form action="<?php echo $this->generateUrl('profile', 'delete', [$_SESSION['csrf']]); ?>" method="POST">
<div class="checkbox">
<label>
<input name="delete_account" type="checkbox" value="1" /> Je suis totalement sûr de vouloir supprimer ce compte
</label>
<form action="<?php echo $this->generateUrl('profile', 'changeTransfer', [$_SESSION['csrf']]); ?>" method="POST">
<div class="form-group">
<label>Transfert activé : </label>
<select name="transfer" class="form-control">
<option value="0">Non</option>
<option value="1" <?php echo $_SESSION['transfer'] ? 'selected' : ''; ?>>Oui</option>
</select>
</div>
<div class="text-center">
<button class="btn btn-danger">Supprimer ce compte</button>
<button class="btn btn-success">Mettre à jour les données</button>
</div>
</form>
</div>