'; + + global $connect; + if ($connect->areTablesCreated()) { + echo '
'. _('Framadate is not properly installed, please check the "INSTALL" to setup the database before continuing.') .'
'; + bandeau_pied(); + die(); + } + } function liste_lang() diff --git a/choix_date.php b/choix_date.php index b9f6314..4d33ca3 100644 --- a/choix_date.php +++ b/choix_date.php @@ -18,7 +18,7 @@ */ namespace Framadate; -session_start(); +include_once __DIR__ . '/app/inc/init.php'; include_once('creation_sondage.php'); @@ -29,7 +29,7 @@ if (is_readable('bandeaux_local.php')) { } // Step 1/3 : error if $_SESSION from info_sondage are not valid -if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmpty('nom', $_SESSION) === false || (($config['use_smtp']) ? Utils::issetAndNoEmpty('adresse', $_SESSION) === false : false)) { +if (!isset($_SESSION['form']->titre) || !isset($_SESSION['form']->nom) || (($config['use_smtp']) ? !isset($_SESSION['form']->adresse) : false)) { Utils::print_header ( _("Error!") ); bandeau_titre(_("Error!")); @@ -73,70 +73,103 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp } } - $_SESSION["toutchoix"]=substr($choixdate,1); + $_SESSION['form']->toutchoix=substr($choixdate,1); // Expiration date → 6 months after last day if not filled or in bad format - $_SESSION["champdatefin"]=end($temp_results)+(86400 * $config['default_poll_duration']); + $_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)) { - $_SESSION["champdatefin"]=$time; + $_SESSION['form']->champdatefin=$time; } } } - ajouter_sondage(); +exit('
'.print_r($_SESSION, true).'
'); + $admin_poll_id = ajouter_sondage( + $_SESSION['form']->titre, + $_SESSION['form']->commentaires, + $_SESSION['form']->nom, + $_SESSION['form']->adresse, + $_SESSION['form']->formatsondage, + $_SESSION['form']->champdatefin, + $_SESSION['form']->mailsonde, + $_SESSION['form']->toutchoix + ); + + unset($_SESSION['form']); +exit('
'.print_r($_SESSION, true).'
'); + + + Utils::cleaningOldPolls($connect, 'admin/logs_studs.txt'); + + // TODO cleanup $_SESSION + Redirect + + // Don't keep days, hours and choices in memory (in order to make new polls) + //for ($i = 0; $i < count($_SESSION['totalchoixjour']); $i++) { + // unset($_SESSION['horaires'.$i]); + //} + //unset($_SESSION['totalchoixjour']); + //unset($_SESSION['choices']); + + //header('Location:' . Utils::getUrlSondage($sondage_admin, true)); + + exit; } else { + if (Utils::issetAndNoEmpty('days')) { - if (!isset($_SESSION["totalchoixjour"])) { - $_SESSION["totalchoixjour"]=array(); - } - $k = 0; - for ($i = 0; $i < count($_POST["days"]); $i++) { - if (isset($_POST["days"][$i]) && $_POST["days"][$i] !='') { - $_SESSION['totalchoixjour'][$k] = mktime(0, 0, 0, substr($_POST["days"][$i],3,2),substr($_POST["days"][$i],0,2),substr($_POST["days"][$i],6,4)); + + // Clear previous choices + $_SESSION['form']->clearChoices(); - $l = 0; - for($j = 0; $j < count($_POST['horaires'.$i]); $j++) { - if (isset($_POST['horaires'.$i][$j]) && $_POST['horaires'.$i][$j] != '') { - $_SESSION['horaires'.$k][$l] = $_POST['horaires'.$i][$j]; - $l++; + for ($i = 0; $i < count($_POST['days']); $i++) { + $day = $_POST['days'][$i]; + + if (!empty($day)) { + // Add choice to Form data + $time = mktime(0, 0, 0, substr($_POST["days"][$i],3,2),substr($_POST["days"][$i],0,2),substr($_POST["days"][$i],6,4)); + $choice = new Choice($time); + $_SESSION['form']->addChoice($choice); + + $schedules = $_POST['horaires'.$i]; + for($j = 0; $j < count($schedules); $j++) { + if (!empty($schedules[$j])) { + $choice->addSlot($schedules[$j]); } } - $k++; } } } } //le format du sondage est DATE - $_SESSION["formatsondage"] = "D".$_SESSION["studsplus"]; + $_SESSION['form']->formatsondage = "D".$_SESSION['form']->studsplus; // Step 3/3 : Confirm poll creation - if (Utils::issetAndNoEmpty('choixheures') && Utils::issetAndNoEmpty('totalchoixjour', $_SESSION)) { + if (Utils::issetAndNoEmpty('choixheures') && !isset($_SESSION['form']->totalchoixjour)) { Utils::print_header ( _("Removal date and confirmation (3 on 3)") ); bandeau_titre(_("Removal date and confirmation (3 on 3)")); - $temp_array = array_unique($_SESSION["totalchoixjour"]); - sort($temp_array); - $removal_date=utf8_encode(strftime($date_format['txt_full'], end($temp_array)+ (86400 * $config['default_poll_duration']))); + $_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']))); - // Sumary + // Summary $summary = ''; @@ -177,6 +210,7 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp '."\n"; +//exit('
POST
'.print_r($_POST, true).'
SESSION
'.print_r($_SESSION, true).'
'); bandeau_pied(); diff --git a/creation_sondage.php b/creation_sondage.php index 1e7f982..1226637 100644 --- a/creation_sondage.php +++ b/creation_sondage.php @@ -16,20 +16,20 @@ * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ +// TODO Move this file into a class into app/classes/Framadate namespace Framadate; -if (session_id() == "") { - session_start(); -} - include_once __DIR__ . '/app/inc/init.php'; -//Generer une chaine de caractere unique et aleatoire +/** + * Generer une chaine de caractere unique et aleatoire + */ function random($car) { - $string = ""; - $chaine = "abcdefghijklmnopqrstuvwxyz123456789"; +// TODO Better random ? + $string = ''; + $chaine = 'abcdefghijklmnopqrstuvwxyz123456789'; srand((double)microtime()*1000000); for($i=0; $i<$car; $i++) { $string .= $chaine[rand()%strlen($chaine)]; @@ -38,63 +38,43 @@ function random($car) return $string; } -function ajouter_sondage() +function ajouter_sondage($title, $comment, $adminName, $adminMail, $format, $endDate, $mailsonde, $slots) { global $connect; + global $config; + $poll_id = random(16); + $admin_poll_id = $poll_id.random(8); - $sondage=random(16); - $sondage_admin=$sondage.random(8); - - $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. + $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 ( - '.$connect->Param('id_sondage').', - '.$connect->Param('commentaires').', - '.$connect->Param('mail_admin').', - '.$connect->Param('nom_admin').', - '.$connect->Param('titre').', - '.$connect->Param('id_sondage_admin').', - FROM_UNIXTIME('.$date_fin.'), - '.$connect->Param('format').', - '.$connect->Param('mailsonde').' - )'; - $sql = $connect->Prepare($sql); - $res = $connect->Execute($sql, array($sondage, $_SESSION['commentaires'], $_SESSION['adresse'], $_SESSION['nom'], $_SESSION['titre'], $sondage_admin, $_SESSION['formatsondage'], $_SESSION['mailsonde'])); + VALUES (?,?,?,?,?,?,?,?)'; + $prepared = $connect->prepare($sql); + $res = $prepared->execute(array($poll_id, $comment, $adminMail, $adminName, $title, $admin_poll_id, $format, $mailsonde)); - $sql = 'INSERT INTO sujet_studs values ('.$connect->Param('sondage').', '.$connect->Param('choix').')'; - $sql = $connect->Prepare($sql); - $connect->Execute($sql, array($sondage, $_SESSION['toutchoix'])); + $prepared = $connect->prepare('INSERT INTO sujet_studs values (?, ?)'); + $prepared->execute(array($poll_id, $slots)); - if($config['use_smtp']==true){ + 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"; - $message .= stripslashes(html_entity_decode($_SESSION["nom"],ENT_QUOTES,"UTF-8"))." " . _("hast just created a poll called") . " : \"".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES))."\".\n"; + $message .= stripslashes(html_entity_decode($adminName, ENT_QUOTES, "UTF-8"))." " . _("hast just created a poll called") . " : \"".stripslashes(htmlspecialchars_decode($title,ENT_QUOTES))."\".\n"; $message .= _("Thanks for filling the poll at the link above") . " :\n\n%s\n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION; $message_admin = _("This message should NOT be sent to the polled people. It is private for the poll's creator.\n\nYou can now modify it at the link above"); $message_admin .= " :\n\n"."%s \n\n" . _("Thanks for your confidence.") . "\n".NOMAPPLICATION; - $message = sprintf($message, Utils::getUrlSondage($sondage)); - $message_admin = sprintf($message_admin, Utils::getUrlSondage($sondage_admin, true)); + $message = sprintf($message, Utils::getUrlSondage($poll_id)); + $message_admin = sprintf($message_admin, Utils::getUrlSondage($admin_poll_id, true)); if (Utils::isValidEmail($_SESSION['adresse'])) { - Utils::sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("Author's message") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message_admin, $_SESSION['adresse'] ); - Utils::sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("For sending to the polled users") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message, $_SESSION['adresse'] ); + Utils::sendEmail( $adminMail, "[".NOMAPPLICATION."][" . _("Author's message") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($title,ENT_QUOTES)), $message_admin, $_SESSION['adresse'] ); + Utils::sendEmail( $adminMail, "[".NOMAPPLICATION."][" . _("For sending to the polled users") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($title,ENT_QUOTES)), $message, $_SESSION['adresse'] ); } } - error_log(date('H:i:s d/m/Y:') . ' CREATION: '.$sondage."\t".$_SESSION[formatsondage]."\t".$_SESSION[nom]."\t".$_SESSION[adresse]."\t \t".$_SESSION[toutchoix]."\n", 3, 'admin/logs_studs.txt'); - Utils::cleaning_polls($connect, 'admin/logs_studs.txt'); + + 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'); - // Don't keep days, hours and choices in memory (in order to make new polls) - for ($i = 0; $i < count($_SESSION["totalchoixjour"]); $i++) { - unset($_SESSION['horaires'.$i]); - } - unset($_SESSION["totalchoixjour"]); - unset($_SESSION['choices']); - - header("Location:".Utils::getUrlSondage($sondage_admin, true)); - - exit(); + return $admin_poll_id; } diff --git a/index.php b/index.php index 6fed009..4e46fbe 100644 --- a/index.php +++ b/index.php @@ -18,8 +18,6 @@ */ namespace Framadate; -use Framadate\Utils; - include_once __DIR__ . '/app/inc/init.php'; if (is_readable('bandeaux_local.php')) { @@ -28,12 +26,9 @@ if (is_readable('bandeaux_local.php')) { include_once('bandeaux.php'); } -session_start(); - // affichage de la page Utils::print_header( _("Home") ); bandeau_titre(_("Make your polls")); - echo '
diff --git a/infos_sondage.php b/infos_sondage.php index 59d5848..99f27c3 100644 --- a/infos_sondage.php +++ b/infos_sondage.php @@ -18,8 +18,10 @@ */ namespace Framadate; -session_start(); include_once __DIR__ . '/app/inc/init.php'; +if (!isset($_SESSION['form'])) { + $_SESSION['form'] = new Form(); +} if (file_exists('bandeaux_local.php')) { include_once('bandeaux_local.php'); @@ -27,14 +29,14 @@ if (file_exists('bandeaux_local.php')) { include_once('bandeaux.php'); } -// Type de sondage :