2011-05-15 01:32:47 +02:00
< ? php
2014-09-04 17:52:18 +02:00
/**
* This software is governed by the CeCILL - B license . If a copy of this license
* is not distributed with this file , you can obtain one at
* http :// www . cecill . info / licences / Licence_CeCILL - B_V1 - en . txt
*
* Authors of STUdS ( initial project ) : Guilhem BORGHESI ( borghesi @ unistra . fr ) and Raphaël DROZ
* Authors of Framadate / OpenSondate : Framasoft ( https :// github . com / framasoft )
*
2014-07-04 11:21:31 +02:00
* =============================
2014-09-04 17:52:18 +02:00
*
* Ce logiciel est régi par la licence CeCILL - B . Si une copie de cette licence
* ne se trouve pas avec ce fichier vous pouvez l ' obtenir sur
* http :// www . cecill . info / licences / Licence_CeCILL - B_V1 - fr . txt
*
2014-07-04 11:21:31 +02:00
* Auteurs de STUdS ( projet initial ) : Guilhem BORGHESI ( borghesi @ unistra . fr ) et Raphaël DROZ
2014-09-04 17:52:18 +02:00
* Auteurs de Framadate / OpenSondage : Framasoft ( https :// github . com / framasoft )
2014-07-04 11:21:31 +02:00
*/
2014-09-04 17:52:18 +02:00
namespace Framadate ;
2011-05-15 01:32:47 +02:00
2015-02-25 20:58:04 +01:00
if ( session_id () == " " ) {
2014-09-04 17:52:18 +02:00
session_start ();
2011-05-15 05:50:13 +02:00
}
2011-05-15 01:32:47 +02:00
2014-09-04 17:52:18 +02:00
include_once __DIR__ . '/app/inc/init.php' ;
2011-05-15 01:32:47 +02:00
//Generer une chaine de caractere unique et aleatoire
2015-02-25 20:58:04 +01:00
function random ( $car )
2011-05-15 03:56:54 +02:00
{
2015-02-25 20:58:04 +01:00
$string = " " ;
$chaine = " abcdefghijklmnopqrstuvwxyz123456789 " ;
2014-09-04 17:52:18 +02:00
srand (( double ) microtime () * 1000000 );
2015-02-25 20:58:04 +01:00
for ( $i = 0 ; $i < $car ; $i ++ ) {
2014-09-04 17:52:18 +02:00
$string .= $chaine [ rand () % strlen ( $chaine )];
}
2011-05-15 01:32:47 +02:00
2015-02-25 20:58:04 +01:00
return $string ;
2014-11-27 00:39:15 +01:00
}
2015-03-02 19:30:26 +01:00
// Like function get_sondage_from_id()
function check_poll_id ( $id )
{
global $connect ;
2015-04-13 11:28:39 +02:00
$sql = 'SELECT `id_sondage` FROM sondage WHERE `id_sondage` = ' . $connect -> Param ( 'id_sondage' ) ;
2015-03-02 19:30:26 +01:00
$sql = $connect -> Prepare ( $sql );
$poll = $connect -> Execute ( $sql , [ $id ]);
if ( $poll === false ) {
return false ;
}
$dbpoll = $poll -> FetchObject ( false );
return $dbpoll -> id_sondage ;
}
2011-05-15 03:56:54 +02:00
function ajouter_sondage ()
{
2014-09-04 17:52:18 +02:00
global $connect ;
2014-12-02 18:15:15 +01:00
global $config ;
2014-09-04 17:52:18 +02:00
2015-03-02 19:30:26 +01:00
$sondage = random ( 16 );
while ( check_poll_id ( $sondage ) == $sondage ) {
$sondage = random ( 16 );
}
$sondage_admin = $sondage . random ( 8 );
2014-09-04 17:52:18 +02:00
2015-02-25 20:58:04 +01:00
$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.
2014-09-04 17:52:18 +02:00
$sql = ' INSERT INTO sondage
2011-05-22 04:03:44 +02:00
( 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 ').' ,
2015-02-25 20:58:04 +01:00
FROM_UNIXTIME ( '.$date_fin.' ),
2011-05-22 04:03:44 +02:00
'.$connect->Param(' format ').' ,
'.$connect->Param(' mailsonde ').'
) ' ;
2014-09-04 17:52:18 +02:00
$sql = $connect -> Prepare ( $sql );
2015-02-25 20:58:04 +01:00
$res = $connect -> Execute ( $sql , array ( $sondage , $_SESSION [ 'commentaires' ], $_SESSION [ 'adresse' ], $_SESSION [ 'nom' ], $_SESSION [ 'titre' ], $sondage_admin , $_SESSION [ 'formatsondage' ], $_SESSION [ 'mailsonde' ]));
2014-09-04 17:52:18 +02:00
2015-02-25 20:58:04 +01:00
$sql = 'INSERT INTO sujet_studs values (' . $connect -> Param ( 'sondage' ) . ', ' . $connect -> Param ( 'choix' ) . ')' ;
2014-09-04 17:52:18 +02:00
$sql = $connect -> Prepare ( $sql );
2015-02-25 20:58:04 +01:00
$connect -> Execute ( $sql , array ( $sondage , $_SESSION [ 'toutchoix' ]));
2014-09-04 17:52:18 +02:00
2015-02-25 20:58:04 +01:00
if ( $config [ 'use_smtp' ] == true ){
2014-12-03 14:30:25 +01:00
$message = _ ( " This is the message you have to send to the people you want to poll. \n Now, you have to send this message to everyone you want to poll. " );
2014-11-14 17:35:22 +01:00
$message .= " \n \n " ;
2015-02-25 20:58:04 +01:00
$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 .= _ ( " Thanks for filling the poll at the link above " ) . " : \n \n %s \n \n " . _ ( " Thanks for your confidence. " ) . " \n " . NOMAPPLICATION ;
2014-11-12 17:49:52 +01:00
2014-12-03 14:30:25 +01:00
$message_admin = _ ( " This message should NOT be sent to the polled people. It is private for the poll's creator. \n \n You can now modify it at the link above " );
2015-02-25 20:58:04 +01:00
$message_admin .= " : \n \n " . " %s \n \n " . _ ( " Thanks for your confidence. " ) . " \n " . NOMAPPLICATION ;
2014-11-12 17:49:52 +01:00
2015-02-25 20:58:04 +01:00
$message = sprintf ( $message , Utils :: getUrlSondage ( $sondage ));
$message_admin = sprintf ( $message_admin , Utils :: getUrlSondage ( $sondage_admin , true ));
2014-11-12 17:49:52 +01:00
2014-11-14 17:35:22 +01:00
if ( Utils :: isValidEmail ( $_SESSION [ 'adresse' ])) {
2015-02-25 20:58:04 +01:00
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' ] );
2014-11-14 17:35:22 +01:00
}
}
2015-02-25 20:58:04 +01:00
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');
2014-09-04 17:52:18 +02:00
// Don't keep days, hours and choices in memory (in order to make new polls)
2015-02-25 20:58:04 +01:00
for ( $i = 0 ; $i < count ( $_SESSION [ " totalchoixjour " ]); $i ++ ) {
2014-09-04 17:52:18 +02:00
unset ( $_SESSION [ 'horaires' . $i ]);
}
2015-02-25 20:58:04 +01:00
unset ( $_SESSION [ " totalchoixjour " ]);
2014-09-04 17:52:18 +02:00
unset ( $_SESSION [ 'choices' ]);
2015-02-25 20:58:04 +01:00
header ( " Location: " . Utils :: getUrlSondage ( $sondage_admin , true ));
2014-09-04 17:52:18 +02:00
exit ();
2012-01-09 01:26:44 +01:00
}