Sondage 1.2 Wip
This commit is contained in:
parent
5459c52e6b
commit
3cadf4db58
@ -15,9 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
class sondage extends common {
|
class sondage extends common
|
||||||
|
{
|
||||||
|
|
||||||
const VERSION = '1.2';
|
const VERSION = '1.3';
|
||||||
const REALNAME = 'Sondage';
|
const REALNAME = 'Sondage';
|
||||||
const DELETE = true;
|
const DELETE = true;
|
||||||
const UPDATE = '0.0';
|
const UPDATE = '0.0';
|
||||||
@ -69,16 +70,17 @@ class sondage extends common {
|
|||||||
/**
|
/**
|
||||||
* Configuration
|
* Configuration
|
||||||
*/
|
*/
|
||||||
public function config() {
|
public function config()
|
||||||
|
{
|
||||||
// Liste des utilisateurs
|
// Liste des utilisateurs
|
||||||
$userIdsFirstnames = helper::arraycollumn($this->getData(['user']), 'firstname');
|
$userIdsFirstnames = helper::arraycollumn($this->getData(['user']), 'firstname');
|
||||||
ksort($userIdsFirstnames);
|
ksort($userIdsFirstnames);
|
||||||
self::$listUsers [] = '';
|
self::$listUsers[] = '';
|
||||||
foreach($userIdsFirstnames as $userId => $userFirstname) {
|
foreach ($userIdsFirstnames as $userId => $userFirstname) {
|
||||||
self::$listUsers [] = $userId;
|
self::$listUsers[] = $userId;
|
||||||
}
|
}
|
||||||
// Soumission du formulaire
|
// Soumission du formulaire
|
||||||
if($this->isPost()) {
|
if ($this->isPost()) {
|
||||||
// Configuration
|
// Configuration
|
||||||
// Option sélectionnée sans page choisie
|
// Option sélectionnée sans page choisie
|
||||||
$this->setData([
|
$this->setData([
|
||||||
@ -89,8 +91,8 @@ class sondage extends common {
|
|||||||
'button' => $this->getInput('formConfigButton'),
|
'button' => $this->getInput('formConfigButton'),
|
||||||
'capcha' => $this->getInput('formConfigCapcha', helper::FILTER_BOOLEAN),
|
'capcha' => $this->getInput('formConfigCapcha', helper::FILTER_BOOLEAN),
|
||||||
'group' => $this->getInput('formConfigGroup', helper::FILTER_INT),
|
'group' => $this->getInput('formConfigGroup', helper::FILTER_INT),
|
||||||
'user' => self::$listUsers [$this->getInput('formConfigUser', helper::FILTER_INT)],
|
'user' => self::$listUsers[$this->getInput('formConfigUser', helper::FILTER_INT)],
|
||||||
'mail' => $this->getInput('formConfigMail') ,
|
'mail' => $this->getInput('formConfigMail'),
|
||||||
'pageId' => $this->getInput('formConfigPageIdToggle', helper::FILTER_BOOLEAN) === true ? $this->getInput('formConfigPageId', helper::FILTER_ID) : '',
|
'pageId' => $this->getInput('formConfigPageIdToggle', helper::FILTER_BOOLEAN) === true ? $this->getInput('formConfigPageId', helper::FILTER_ID) : '',
|
||||||
'subject' => $this->getInput('formConfigSubject'),
|
'subject' => $this->getInput('formConfigSubject'),
|
||||||
'itemsperPage' => $this->getInput('formConfigItemsperPage', helper::FILTER_INT)
|
'itemsperPage' => $this->getInput('formConfigItemsperPage', helper::FILTER_INT)
|
||||||
@ -100,15 +102,18 @@ class sondage extends common {
|
|||||||
$this->setData(['module', $this->getUrl(0), 'data', []]);
|
$this->setData(['module', $this->getUrl(0), 'data', []]);
|
||||||
// Génération des champs
|
// Génération des champs
|
||||||
$inputs = [];
|
$inputs = [];
|
||||||
foreach($this->getInput('formConfigPosition', null) as $index => $position) {
|
if (is_array($this->getInput('formConfigPosition', null))) {
|
||||||
$inputs[] = [
|
foreach ($this->getInput('formConfigPosition', null) as $index => $position) {
|
||||||
'name' => $this->getInput('formConfigName[' . $index . ']'),
|
$inputs[] = [
|
||||||
'position' => helper::filter($position, helper::FILTER_INT),
|
'name' => $this->getInput('formConfigName[' . $index . ']'),
|
||||||
'required' => $this->getInput('formConfigRequired[' . $index . ']', helper::FILTER_BOOLEAN),
|
'position' => helper::filter($position, helper::FILTER_INT),
|
||||||
'type' => $this->getInput('formConfigType[' . $index . ']'),
|
'required' => $this->getInput('formConfigRequired[' . $index . ']', helper::FILTER_BOOLEAN),
|
||||||
'values' => $this->getInput('formConfigValues[' . $index . ']')
|
'type' => $this->getInput('formConfigType[' . $index . ']'),
|
||||||
];
|
'values' => $this->getInput('formConfigValues[' . $index . ']')
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setData(['module', $this->getUrl(0), 'input', $inputs]);
|
$this->setData(['module', $this->getUrl(0), 'input', $inputs]);
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
@ -118,9 +123,9 @@ class sondage extends common {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// Liste des pages
|
// Liste des pages
|
||||||
foreach($this->getHierarchy(null, false) as $parentPageId => $childrenPageIds) {
|
foreach ($this->getHierarchy(null, false) as $parentPageId => $childrenPageIds) {
|
||||||
self::$pages[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
self::$pages[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
||||||
foreach($childrenPageIds as $childKey) {
|
foreach ($childrenPageIds as $childKey) {
|
||||||
self::$pages[$childKey] = ' ' . $this->getData(['page', $childKey, 'title']);
|
self::$pages[$childKey] = ' ' . $this->getData(['page', $childKey, 'title']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,27 +143,28 @@ class sondage extends common {
|
|||||||
/**
|
/**
|
||||||
* Données enregistrées
|
* Données enregistrées
|
||||||
*/
|
*/
|
||||||
public function data() {
|
public function data()
|
||||||
|
{
|
||||||
$data = $this->getData(['module', $this->getUrl(0), 'data']);
|
$data = $this->getData(['module', $this->getUrl(0), 'data']);
|
||||||
if(is_array($data)) {
|
if (is_array($data)) {
|
||||||
// Pagination
|
// Pagination
|
||||||
$pagination = helper::pagination($data, $this->getUrl(),$this->getData(['module', $this->getUrl(0),'config', 'itemsperPage']));
|
$pagination = helper::pagination($data, $this->getUrl(), $this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']));
|
||||||
// Liste des pages
|
// Liste des pages
|
||||||
self::$pagination = $pagination['pages'];
|
self::$pagination = $pagination['pages'];
|
||||||
// Inverse l'ordre du tableau
|
// Inverse l'ordre du tableau
|
||||||
$dataIds = array_reverse(array_keys($data));
|
$dataIds = array_reverse(array_keys($data));
|
||||||
$data = array_reverse($data);
|
$data = array_reverse($data);
|
||||||
// Données en fonction de la pagination
|
// Données en fonction de la pagination
|
||||||
for($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
for ($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
||||||
$content = '';
|
$content = '';
|
||||||
foreach($data[$i] as $input => $value) {
|
foreach ($data[$i] as $input => $value) {
|
||||||
$content .= $input . ' : ' . $value . '<br>';
|
$content .= $input . ' : ' . $value . '<br>';
|
||||||
}
|
}
|
||||||
self::$data[] = [
|
self::$data[] = [
|
||||||
$content,
|
$content,
|
||||||
template::button('formDataDelete' . $dataIds[$i], [
|
template::button('formDataDelete' . $dataIds[$i], [
|
||||||
'class' => 'formDataDelete red',
|
'class' => 'formDataDelete red',
|
||||||
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $dataIds[$i] . '/' . $_SESSION['csrf'],
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $dataIds[$i] . '/' . $_SESSION['csrf'],
|
||||||
'value' => template::ico('cancel')
|
'value' => template::ico('cancel')
|
||||||
])
|
])
|
||||||
];
|
];
|
||||||
@ -174,20 +180,21 @@ class sondage extends common {
|
|||||||
/**
|
/**
|
||||||
* Réponses enregistrées
|
* Réponses enregistrées
|
||||||
*/
|
*/
|
||||||
public function result() {
|
public function result()
|
||||||
|
{
|
||||||
$data = $this->getData(['module', $this->getUrl(0), 'data']);
|
$data = $this->getData(['module', $this->getUrl(0), 'data']);
|
||||||
if($data) {
|
if ($data) {
|
||||||
// Pagination
|
// Pagination
|
||||||
$pagination = helper::pagination($data, $this->getUrl(),$this->getData(['module', $this->getUrl(0),'config', 'itemsperPage']));
|
$pagination = helper::pagination($data, $this->getUrl(), $this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']));
|
||||||
// Liste des pages
|
// Liste des pages
|
||||||
self::$pagination = $pagination['pages'];
|
self::$pagination = $pagination['pages'];
|
||||||
// Inverse l'ordre du tableau
|
// Inverse l'ordre du tableau
|
||||||
$dataIds = array_reverse(array_keys($data));
|
$dataIds = array_reverse(array_keys($data));
|
||||||
$data = array_reverse($data);
|
$data = array_reverse($data);
|
||||||
// Données en fonction de la pagination
|
// Données en fonction de la pagination
|
||||||
for($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
for ($i = $pagination['first']; $i < $pagination['last']; $i++) {
|
||||||
$content = '';
|
$content = '';
|
||||||
foreach($data[$i] as $input => $value) {
|
foreach ($data[$i] as $input => $value) {
|
||||||
$content .= $input . ' : ' . $value . '<br>';
|
$content .= $input . ' : ' . $value . '<br>';
|
||||||
}
|
}
|
||||||
self::$data[] = [
|
self::$data[] = [
|
||||||
@ -205,39 +212,40 @@ class sondage extends common {
|
|||||||
/**
|
/**
|
||||||
* Export CSV
|
* Export CSV
|
||||||
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
||||||
* @copyright Copyright (C) 2018-2020, Frédéric Tempez
|
* @copyright Copyright (C) 2018-2020, Frédéric Tempez
|
||||||
*/
|
*/
|
||||||
public function export2csv() {
|
public function export2csv()
|
||||||
|
{
|
||||||
// Jeton incorrect
|
// Jeton incorrect
|
||||||
if ($this->getUrl(2) !== $_SESSION['csrf']) {
|
if ($this->getUrl(2) !== $_SESSION['csrf']) {
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
||||||
'notification' => 'Action interdite'
|
'notification' => 'Action interdite'
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$data = $this->getData(['module', $this->getUrl(0), 'data']);
|
$data = $this->getData(['module', $this->getUrl(0), 'data']);
|
||||||
if ($data !== []) {
|
if ($data !== []) {
|
||||||
$csvfilename = 'data-'.date('dmY').'-'.date('hm').'-'.rand(10,99).'.csv';
|
$csvfilename = 'data-' . date('dmY') . '-' . date('hm') . '-' . rand(10, 99) . '.csv';
|
||||||
if (!file_exists(self::FILE_DIR.'source/data')) {
|
if (!file_exists(self::FILE_DIR . 'source/data')) {
|
||||||
mkdir(self::FILE_DIR.'source/data', 0755);
|
mkdir(self::FILE_DIR . 'source/data', 0755);
|
||||||
}
|
}
|
||||||
$fp = fopen(self::FILE_DIR.'source/data/'.$csvfilename, 'w');
|
$fp = fopen(self::FILE_DIR . 'source/data/' . $csvfilename, 'w');
|
||||||
fputcsv($fp, array_keys($data[1]), ';','"');
|
fputcsv($fp, array_keys($data[1]), ';', '"');
|
||||||
foreach ($data as $fields) {
|
foreach ($data as $fields) {
|
||||||
fputcsv($fp, $fields, ';','"');
|
fputcsv($fp, $fields, ';', '"');
|
||||||
}
|
}
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'notification' => 'Export CSV effectué dans le gestionnaire de fichiers<br />sous le nom '.$csvfilename,
|
'notification' => 'Export CSV effectué dans le gestionnaire de fichiers<br />sous le nom ' . $csvfilename,
|
||||||
'redirect' => helper::baseUrl() . $this->getUrl(0) .'/data',
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
||||||
'state' => true
|
'state' => true
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'notification' => 'Aucune donnée à exporter',
|
'notification' => 'Aucune donnée à exporter',
|
||||||
'redirect' => helper::baseUrl() . $this->getUrl(0) .'/data'
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,19 +255,20 @@ class sondage extends common {
|
|||||||
/**
|
/**
|
||||||
* Suppression
|
* Suppression
|
||||||
*/
|
*/
|
||||||
public function deleteall() {
|
public function deleteall()
|
||||||
|
{
|
||||||
// Jeton incorrect
|
// Jeton incorrect
|
||||||
if ($this->getUrl(2) !== $_SESSION['csrf']) {
|
if ($this->getUrl(2) !== $_SESSION['csrf']) {
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
||||||
'notification' => 'Action interdite'
|
'notification' => 'Action interdite'
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$data = ($this->getData(['module', $this->getUrl(0), 'data']));
|
$data = ($this->getData(['module', $this->getUrl(0), 'data']));
|
||||||
if (count($data) > 0 ) {
|
if (count($data) > 0) {
|
||||||
// Suppression multiple
|
// Suppression multiple
|
||||||
for ($i = 1; $i <= count($data) ; $i++) {
|
for ($i = 1; $i <= count($data); $i++) {
|
||||||
echo $this->deleteData(['module', $this->getUrl(0), 'data', $i]);
|
echo $this->deleteData(['module', $this->getUrl(0), 'data', $i]);
|
||||||
}
|
}
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
@ -282,17 +291,18 @@ class sondage extends common {
|
|||||||
/**
|
/**
|
||||||
* Suppression
|
* Suppression
|
||||||
*/
|
*/
|
||||||
public function delete() {
|
public function delete()
|
||||||
|
{
|
||||||
// Jeton incorrect
|
// Jeton incorrect
|
||||||
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data',
|
||||||
'notification' => 'Action interdite'
|
'notification' => 'Action interdite'
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
// La donnée n'existe pas
|
// La donnée n'existe pas
|
||||||
if($this->getData(['module', $this->getUrl(0), 'data', $this->getUrl(2)]) === null) {
|
if ($this->getData(['module', $this->getUrl(0), 'data', $this->getUrl(2)]) === null) {
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'access' => false
|
'access' => false
|
||||||
@ -317,23 +327,24 @@ class sondage extends common {
|
|||||||
/**
|
/**
|
||||||
* Accueil
|
* Accueil
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index()
|
||||||
|
{
|
||||||
// Soumission du formulaire
|
// Soumission du formulaire
|
||||||
if($this->isPost()) {
|
if ($this->isPost()) {
|
||||||
// Check la capcha
|
// Check la capcha
|
||||||
if(
|
if (
|
||||||
$this->getData(['module', $this->getUrl(0), 'config', 'capcha'])
|
$this->getData(['module', $this->getUrl(0), 'config', 'capcha'])
|
||||||
AND $this->getInput('formCapcha', helper::FILTER_INT) !== $this->getInput('formCapchaFirstNumber', helper::FILTER_INT) + $this->getInput('formCapchaSecondNumber', helper::FILTER_INT))
|
and $this->getInput('formCapcha', helper::FILTER_INT) !== $this->getInput('formCapchaFirstNumber', helper::FILTER_INT) + $this->getInput('formCapchaSecondNumber', helper::FILTER_INT)
|
||||||
{
|
) {
|
||||||
self::$inputNotices['formCapcha'] = 'Incorrect';
|
self::$inputNotices['formCapcha'] = 'Incorrect';
|
||||||
|
|
||||||
}
|
}
|
||||||
// Préparation le contenu du mail
|
// Préparation le contenu du mail
|
||||||
$data = [];
|
$data = [];
|
||||||
$content = '';
|
$content = '';
|
||||||
foreach($this->getData(['module', $this->getUrl(0), 'input']) as $index => $input) {
|
foreach ($this->getData(['module', $this->getUrl(0), 'input']) as $index => $input) {
|
||||||
// Filtre la valeur
|
// Filtre la valeur
|
||||||
switch($input['type']) {
|
switch ($input['type']) {
|
||||||
case self::TYPE_MAIL:
|
case self::TYPE_MAIL:
|
||||||
$filter = helper::FILTER_MAIL;
|
$filter = helper::FILTER_MAIL;
|
||||||
break;
|
break;
|
||||||
@ -343,7 +354,7 @@ class sondage extends common {
|
|||||||
case self::TYPE_DATETIME:
|
case self::TYPE_DATETIME:
|
||||||
$filter = helper::FILTER_STRING_SHORT; // Mettre TYPE_DATETIME pour récupérer un TIMESTAMP
|
$filter = helper::FILTER_STRING_SHORT; // Mettre TYPE_DATETIME pour récupérer un TIMESTAMP
|
||||||
break;
|
break;
|
||||||
CASE self::TYPE_CHECKBOX:
|
case self::TYPE_CHECKBOX:
|
||||||
$filter = helper::FILTER_BOOLEAN;
|
$filter = helper::FILTER_BOOLEAN;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -360,23 +371,25 @@ class sondage extends common {
|
|||||||
// Envoi du mail
|
// Envoi du mail
|
||||||
// Rechercher l'adresse en fonction du mail
|
// Rechercher l'adresse en fonction du mail
|
||||||
$sent = true;
|
$sent = true;
|
||||||
$singleuser = $this->getData(['user',
|
$singleuser = $this->getData([
|
||||||
$this->getData(['module', $this->getUrl(0), 'config', 'user']),
|
'user',
|
||||||
'mail']);
|
$this->getData(['module', $this->getUrl(0), 'config', 'user']),
|
||||||
|
'mail'
|
||||||
|
]);
|
||||||
$singlemail = $this->getData(['module', $this->getUrl(0), 'config', 'mail']);
|
$singlemail = $this->getData(['module', $this->getUrl(0), 'config', 'mail']);
|
||||||
$group = $this->getData(['module', $this->getUrl(0), 'config', 'group']);
|
$group = $this->getData(['module', $this->getUrl(0), 'config', 'group']);
|
||||||
// Verification si le mail peut être envoyé
|
// Verification si le mail peut être envoyé
|
||||||
if(
|
if (
|
||||||
self::$inputNotices === [] && (
|
self::$inputNotices === [] && (
|
||||||
$group > 0 ||
|
$group > 0 ||
|
||||||
$singleuser !== '' ||
|
$singleuser !== '' ||
|
||||||
$singlemail !== '' )
|
$singlemail !== '')
|
||||||
) {
|
) {
|
||||||
// Utilisateurs dans le groupe
|
// Utilisateurs dans le groupe
|
||||||
$to = [];
|
$to = [];
|
||||||
if ($group > 0){
|
if ($group > 0) {
|
||||||
foreach($this->getData(['user']) as $userId => $user) {
|
foreach ($this->getData(['user']) as $userId => $user) {
|
||||||
if($user['group'] >= $group) {
|
if ($user['group'] >= $group) {
|
||||||
$to[] = $user['mail'];
|
$to[] = $user['mail'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -389,10 +402,10 @@ class sondage extends common {
|
|||||||
if (!empty($singlemail)) {
|
if (!empty($singlemail)) {
|
||||||
$to[] = $singlemail;
|
$to[] = $singlemail;
|
||||||
}
|
}
|
||||||
if($to) {
|
if ($to) {
|
||||||
// Sujet du mail
|
// Sujet du mail
|
||||||
$subject = $this->getData(['module', $this->getUrl(0), 'config', 'subject']);
|
$subject = $this->getData(['module', $this->getUrl(0), 'config', 'subject']);
|
||||||
if($subject === '') {
|
if ($subject === '') {
|
||||||
$subject = 'Nouveau message en provenance de votre site';
|
$subject = 'Nouveau message en provenance de votre site';
|
||||||
}
|
}
|
||||||
// Envoi le mail
|
// Envoi le mail
|
||||||
|
Loading…
Reference in New Issue
Block a user