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;$itoutchoix=substr($choixdate,1); - - // Expiration date → 6 months after last day if not filled or in bad format - $_SESSION['form']->champdatefin=end($temp_results)+(86400 * $config['default_poll_duration']); - - if (Utils::issetAndNoEmpty('champdatefin')) { - $registredate = explode("/",$_POST["champdatefin"]); - if (is_array($registredate) == true && count($registredate) == 3) { - $time = mktime(0,0,0,$registredate[1],$registredate[0],$registredate[2]); - if ($time > time() + (24*60*60)) { + // Define expiration date + if (!empty($_POST['champdatefin'])) + { + $registredate = explode('/', $_POST['champdatefin']); + if (is_array($registredate) && count($registredate) == 3) + { + $time = mktime(0,0,0, $registredate[1], $registredate[0], $registredate[2]); + if ($time > time() + (24*60*60)) + { $_SESSION['form']->champdatefin=$time; } } + } + + if(empty($_SESSION['form']->champdatefin)) + { + // By default, expiration date is 6 months after last day + $_SESSION['form']->champdatefin=end($temp_results)+(86400 * $config['default_poll_duration']); } - + $admin_poll_id = ajouter_sondage( $_SESSION['form']->titre, $_SESSION['form']->commentaires, $_SESSION['form']->nom, $_SESSION['form']->adresse, $_SESSION['form']->formatsondage, + $_SESSION['form']->editable, $_SESSION['form']->champdatefin, - $_SESSION['form']->mailsonde, - $_SESSION['form']->toutchoix + $_SESSION['form']->receiveNewVotes, + $_SESSION['form']->getChoices() ); // Clean Form data in $_SESSION @@ -137,9 +116,9 @@ if (!isset($_SESSION['form']->titre) || !isset($_SESSION['form']->nom) || (($con } //le format du sondage est DATE - $_SESSION['form']->formatsondage = "D".$_SESSION['form']->studsplus; + $_SESSION['form']->formatsondage = 'D'; - // Step 3/3 : Confirm poll creation + // Step 3/4 : Confirm poll creation if (Utils::issetAndNoEmpty('choixheures') && !isset($_SESSION['form']->totalchoixjour)) { Utils::print_header ( _("Removal date and confirmation (3 on 3)") ); @@ -147,7 +126,7 @@ if (!isset($_SESSION['form']->titre) || !isset($_SESSION['form']->nom) || (($con $_SESSION['form']->sortChoices(); $last_date = $_SESSION['form']->lastChoice()->getName(); - $removal_date = utf8_encode(strftime($date_format['txt_full'], $last_date + (86400 * $config['default_poll_duration']))); + $removal_date = $last_date + (86400 * $config['default_poll_duration']); // Summary $summary = '