Add STATUS.txt file
[framadate-sandstorm.git] / creation_sondage.php
blob4d0cc054678f8c9b08753d9123a1a7a7358a50f8
1 <?php
2 /**
3 * This software is governed by the CeCILL-B license. If a copy of this license
4 * is not distributed with this file, you can obtain one at
5 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
7 * Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
8 * Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft)
10 * =============================
12 * Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
13 * ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
14 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
16 * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
17 * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
19 namespace Framadate;
21 if (session_id() == "") {
22 session_start();
25 include_once __DIR__ . '/app/inc/init.php';
28 //Generer une chaine de caractere unique et aleatoire
29 function random($car)
31 $string = "";
32 $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
33 srand((double)microtime()*1000000);
34 for($i=0; $i<$car; $i++) {
35 $string .= $chaine[rand()%strlen($chaine)];
38 return $string;
41 // Like function get_sondage_from_id()
42 function check_poll_id($id)
44 global $connect;
46 $sql = 'SELECT `id_sondage` FROM sondage WHERE `id_sondage` = ' . $connect->Param('id_sondage') ;
47 $sql = $connect->Prepare($sql);
48 $poll = $connect->Execute($sql, [$id]);
50 if ($poll === false) {
51 return false;
54 $dbpoll = $poll->FetchObject(false);
56 return $dbpoll->id_sondage;
59 function ajouter_sondage()
61 global $connect;
62 global $config;
64 $sondage = random(16);
65 while(check_poll_id($sondage) == $sondage) {
66 $sondage = random(16);
68 $sondage_admin = $sondage.random(8);
70 $date_fin = $_SESSION["champdatefin"]; // provided by choix_autre.php or choix_date.php
71 $_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.
72 $sql = 'INSERT INTO sondage
73 (id_sondage, commentaires, mail_admin, nom_admin, titre, id_sondage_admin, date_fin, format, mailsonde)
74 VALUES (
75 '.$connect->Param('id_sondage').',
76 '.$connect->Param('commentaires').',
77 '.$connect->Param('mail_admin').',
78 '.$connect->Param('nom_admin').',
79 '.$connect->Param('titre').',
80 '.$connect->Param('id_sondage_admin').',
81 FROM_UNIXTIME('.$date_fin.'),
82 '.$connect->Param('format').',
83 '.$connect->Param('mailsonde').'
84 )';
85 $sql = $connect->Prepare($sql);
86 $res = $connect->Execute($sql, array($sondage, $_SESSION['commentaires'], $_SESSION['adresse'], $_SESSION['nom'], $_SESSION['titre'], $sondage_admin, $_SESSION['formatsondage'], $_SESSION['mailsonde']));
88 $sql = 'INSERT INTO sujet_studs values ('.$connect->Param('sondage').', '.$connect->Param('choix').')';
89 $sql = $connect->Prepare($sql);
90 $connect->Execute($sql, array($sondage, $_SESSION['toutchoix']));
92 if($config['use_smtp']==true){
93 $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.");
94 $message .= "\n\n";
95 $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";
96 $message .= _("Thanks for filling the poll at the link above") . " :\n\n%s\n\n" . _("Thanks for your trust.") . "\n".NOMAPPLICATION;
98 $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");
99 $message_admin .= " :\n\n"."%s \n\n" . _("Thanks for your trust.") . "\n".NOMAPPLICATION;
101 $message = sprintf($message, Utils::getUrlSondage($sondage));
102 $message_admin = sprintf($message_admin, Utils::getUrlSondage($sondage_admin, true));
104 if (Utils::isValidEmail($_SESSION['adresse'])) {
105 Utils::sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("Author's message") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message_admin, $_SESSION['adresse'] );
106 Utils::sendEmail( "$_SESSION[adresse]", "[".NOMAPPLICATION."][" . _("For sending to the polled users") . "] " . _("Poll") . " : ".stripslashes(htmlspecialchars_decode($_SESSION["titre"],ENT_QUOTES)), $message, $_SESSION['adresse'] );
109 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');
110 //Utils::cleaning_polls($connect, 'admin/logs_studs.txt');
112 // Don't keep days, hours and choices in memory (in order to make new polls)
113 for ($i = 0; $i < count($_SESSION["totalchoixjour"]); $i++) {
114 unset($_SESSION['horaires'.$i]);
116 unset($_SESSION["totalchoixjour"]);
117 unset($_SESSION['choices']);
119 header("Location:".Utils::getUrlSondage($sondage_admin, true));
121 exit();