diff --git a/app/classes/Framadate/Form.php b/app/classes/Framadate/Form.php index 641f0f1..79d1c68 100644 --- a/app/classes/Framadate/Form.php +++ b/app/classes/Framadate/Form.php @@ -11,16 +11,16 @@ class Form public $formatsondage; public $champdatefin; public $choix_sondage; - public $studsplus; - public $mailsonde; - public $toutchoix; - public $totalchoixjour; - public $horaires; /** - * Step of form + * Tells if users can modify their choices. */ - public $step = 0; + public $editable; + + /** + * If true, notify poll administrator when new vote is made. + */ + public $receiveNewVotes; /** * List of available choices diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index a10884e..60f5b62 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -11,6 +11,8 @@ class FramaDB function __construct($connection_string, $user, $password) { $this->pdo = new \PDO($connection_string, $user, $password); + $this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ); + $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } function areTablesCreated() diff --git a/app/classes/Framadate/Utils.php b/app/classes/Framadate/Utils.php index c48aff2..ae431c0 100644 --- a/app/classes/Framadate/Utils.php +++ b/app/classes/Framadate/Utils.php @@ -239,7 +239,7 @@ class Utils $prepared = $connect->prepare('DELETE FROM comments WHERE id_sondage = ?'); $prepared->execute(array($poll_id)); - $prepared = $connect->prepare('DELETE FROM sondage WHERE id_sondage = ?'); + $prepared = $connect->prepare('DELETE FROM sondage WHERE poll_id = ?'); $prepared->execute(array($poll_id)); } @@ -247,15 +247,13 @@ class Utils public static function cleaningOldPolls($log_txt) { global $connect; - $resultSet = $connect->query('SELECT id_sondage, format, nom_admin, mail_admin FROM sondage WHERE date_fin < NOW() LIMIT 20'); + $resultSet = $connect->query('SELECT poll_id, format, admin_name FROM sondage WHERE end_date < NOW() LIMIT 20'); $toClean = $resultSet->fetchAll(\PDO::FETCH_CLASS); - - echo '
toClean:'.print_r($toClean, true).''; $connect->beginTransaction(); foreach ($toClean as $row) { - if (self::removeSondage($row->id_sondage)) { - error_log(date('H:i:s d/m/Y:') . ' EXPIRATION: '. $row->id_sondage."\t".$row->format."\t".$row->nom_admin."\t".$row->mail_admin."\n", 3, $log_txt); + if (self::removeSondage($row->poll_id)) { + error_log(date('H:i:s d/m/Y:') . ' EXPIRATION: '. $row->poll_id."\t".$row->format."\t".$row->admin_name."\n", 3, $log_txt); } } $connect->commit(); diff --git a/choix_date.php b/choix_date.php index df0ac98..200b8a9 100644 --- a/choix_date.php +++ b/choix_date.php @@ -45,58 +45,37 @@ if (!isset($_SESSION['form']->titre) || !isset($_SESSION['form']->nom) || (($con } else { // Step 4 : Data prepare before insert in DB if (Utils::issetAndNoEmpty('confirmation')) { - $temp_results = array(); - $choixdate=''; - if (Utils::issetAndNoEmpty('totalchoixjour', $_SESSION) === true) { - for ($i = 0; $i < count($_SESSION["totalchoixjour"]); $i++) { - if(count($_SESSION['horaires'.$i])!=0) { - for ($j=0;$j< min(count($_SESSION['horaires'.$i]),12);$j++) { - if ($_SESSION['horaires'.$i][$j]!="") { - array_push($temp_results, $_SESSION["totalchoixjour"][$i].'@'.$_SESSION['horaires'.$i][$j]); - } else { - array_push($temp_results, $_SESSION["totalchoixjour"][$i]); - } - } - } else { - array_push($temp_results, $_SESSION["totalchoixjour"][$i]); - } - } - } - - // Sort and remove doublons - $temp_results = array_unique($temp_results); - sort($temp_results); - for ($i=0;$i
' . _("Your poll will be automatically removed "). $config['default_poll_duration'] . ' ' . _("days") ._(" after the last date of your poll:") . ' '.$removal_date.'.
' . _("You can fix another removal date for it.") .'
' . _("Your poll will be automatically removed "). $config['default_poll_duration'] . ' ' . _("days") . ' ' ._("after the last date of your poll") . '.
' . _("You can fix another removal date for it.") .'
POST'); bandeau_pied(); - // Step 2/3 : Select dates of the poll + // Step 2/4 : Select dates of the poll } else { Utils::print_header ( _("Poll dates (2 on 3)") ); bandeau_titre(_("Poll dates (2 on 3)")); diff --git a/creation_sondage.php b/creation_sondage.php index 1226637..77ab9e0 100644 --- a/creation_sondage.php +++ b/creation_sondage.php @@ -38,24 +38,34 @@ function random($car) return $string; } -function ajouter_sondage($title, $comment, $adminName, $adminMail, $format, $endDate, $mailsonde, $slots) +function ajouter_sondage($title, $comment, $adminName, $adminMail, $format, $editable, $endDate, $receiveNewVotes, $choices) { global $connect; global $config; + + // Generate poll ids $poll_id = random(16); $admin_poll_id = $poll_id.random(8); + + // Insert poll + slots + $connect->beginTransaction(); - $date_fin = $_SESSION['champdatefin']; // provided by choix_autre.php or choix_date.php - $_SESSION['champdatefin'] = ''; //clean param cause 2 polls created by the same user in the same session can be affected by this param during the 2nd creation. $sql = 'INSERT INTO sondage - (id_sondage, commentaires, mail_admin, nom_admin, titre, id_sondage_admin, date_fin, format, mailsonde) - VALUES (?,?,?,?,?,?,?,?)'; + (poll_id, admin_poll_id, title, comment, admin_name, admin_mail, end_date, format, editable, receiveNewVotes) + VALUES (?,?,?,?,?,?,FROM_UNIXTIME(?),?,?,?)'; $prepared = $connect->prepare($sql); - $res = $prepared->execute(array($poll_id, $comment, $adminMail, $adminName, $title, $admin_poll_id, $format, $mailsonde)); + $prepared->execute(array($poll_id, $admin_poll_id, $title, $comment, $adminName, $adminMail, $endDate, $format, $editable, $receiveNewVotes)); - $prepared = $connect->prepare('INSERT INTO sujet_studs values (?, ?)'); - $prepared->execute(array($poll_id, $slots)); + $prepared = $connect->prepare('INSERT INTO sujet_studs (id_sondage, sujet) VALUES (?, ?)'); + foreach ($choices as $choice) { + foreach ($choice->getSlots() as $slot) { + $prepared->execute(array($poll_id, $choice->getName().'@'.$slot)); + } + } + $connect->commit(); + + // Send confirmation by mail if enabled if($config['use_smtp'] === true){ $message = _("This is the message you have to send to the people you want to poll. \nNow, you have to send this message to everyone you want to poll."); $message .= "\n\n"; @@ -74,7 +84,7 @@ function ajouter_sondage($title, $comment, $adminName, $adminMail, $format, $end } } - error_log(date('H:i:s d/m/Y:') . ' CREATION: '.$poll_id."\t".$format."\t".$adminName."\t".$adminMail."\t \t".$slots."\n", 3, 'admin/logs_studs.txt'); + error_log(date('H:i:s d/m/Y:') . ' CREATION: '.$poll_id."\t".$format."\t".$adminName."\t".$adminMail."\n", 3, 'admin/logs_studs.txt'); return $admin_poll_id; } diff --git a/infos_sondage.php b/infos_sondage.php index 99f27c3..dc773bf 100644 --- a/infos_sondage.php +++ b/infos_sondage.php @@ -41,7 +41,7 @@ if ((isset($_GET['choix_sondage']) && $_GET['choix_sondage'] == 'date') || // On teste toutes les variables pour supprimer l'ensemble des warnings PHP // On transforme en entites html les données afin éviter les failles XSS -$post_var = array('poursuivre', 'titre', 'nom', 'adresse', 'commentaires', 'studsplus', 'mailsonde', 'creation_sondage_date', 'creation_sondage_autre'); +$post_var = array('poursuivre', 'titre', 'nom', 'adresse', 'commentaires', 'editable', 'receiveNewVotes', 'creation_sondage_date', 'creation_sondage_autre'); foreach ($post_var as $var) { if (isset($_POST[$var]) === true) { $$var = htmlentities($_POST[$var], ENT_QUOTES, 'UTF-8'); @@ -55,8 +55,6 @@ $erreur_adresse = false; $erreur_injection_titre = false; $erreur_injection_nom = false; $erreur_injection_commentaires = false; -$cocheplus = ''; -$cochemail = ''; #tests if (Utils::issetAndNoEmpty("poursuivre")){ @@ -64,8 +62,8 @@ if (Utils::issetAndNoEmpty("poursuivre")){ $_SESSION['form']->nom = $nom; $_SESSION['form']->adresse = $adresse; $_SESSION['form']->commentaires = $commentaires; - $_SESSION['form']->studsplus = ($studsplus !== null) ? '+' : $_SESSION['form']->studsplus = ''; - $_SESSION['form']->mailsonde = ($mailsonde !== null) ? true : false; + $_SESSION['form']->editable = ($editable !== null) ? true : false; + $_SESSION['form']->receiveNewVotes = ($receiveNewVotes !== null) ? true : false; if ($config['use_smtp']==true){ if (Utils::isValidEmail($adresse) === false) { @@ -86,7 +84,7 @@ if (Utils::issetAndNoEmpty("poursuivre")){ } // Si pas d'erreur dans l'adresse alors on change de page vers date ou autre - if($config['use_smtp']==true){ + if($config['use_smtp'] == true){ $email_OK = $adresse && !$erreur_adresse; } else{ $email_OK = true; @@ -189,19 +187,15 @@ if (USE_REMOTE_USER && isset($_SERVER['REMOTE_USER'])) { } // Checkbox checked ? -if (!$_SESSION['form']->studsplus && !Utils::issetAndNoEmpty('creation_sondage_date') && !Utils::issetAndNoEmpty('creation_sondage_autre')) { - $_SESSION['form']->studsplus="+"; +if ($_SESSION['form']->editable) { + $editable = 'checked'; } -if ($_SESSION['form']->studsplus=="+") { - $cocheplus="checked"; +if ($_SESSION['form']->receiveNewVotes) { + $receiveNewVotes = 'checked'; } -if ($_SESSION['form']->mailsonde) { - $cochemail="checked"; -} - -// Affichage du formulaire +// Display form echo '
'.print_r($_POST, true).'
SESSION
'.print_r($_SESSION, true).'