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-12-03 21:08:08 +01:00
// TODO Move this file into a class into app/classes/Framadate
2014-09-04 17:52:18 +02:00
namespace Framadate ;
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
2014-12-03 21:08:08 +01:00
/**
* Generer une chaine de caractere unique et aleatoire
*/
2011-05-15 03:56:54 +02:00
function random ( $car )
{
2014-12-03 21:08:08 +01:00
// TODO Better random ?
$string = '' ;
$chaine = 'abcdefghijklmnopqrstuvwxyz123456789' ;
2014-09-04 17:52:18 +02:00
srand (( double ) microtime () * 1000000 );
for ( $i = 0 ; $i < $car ; $i ++ ) {
$string .= $chaine [ rand () % strlen ( $chaine )];
}
return $string ;
2011-05-15 01:32:47 +02:00
}
2014-12-05 01:08:38 +01:00
function ajouter_sondage ( $title , $comment , $adminName , $adminMail , $format , $editable , $endDate , $receiveNewVotes , $choices )
2011-05-15 03:56:54 +02:00
{
2014-09-04 17:52:18 +02:00
global $connect ;
2014-12-03 21:08:08 +01:00
global $config ;
2014-12-05 01:08:38 +01:00
// Generate poll ids
2014-12-03 21:08:08 +01:00
$poll_id = random ( 16 );
$admin_poll_id = $poll_id . random ( 8 );
2014-12-05 01:08:38 +01:00
// Insert poll + slots
$connect -> beginTransaction ();
2014-09-04 17:52:18 +02:00
$sql = ' INSERT INTO sondage
2014-12-05 01:08:38 +01:00
( poll_id , admin_poll_id , title , comment , admin_name , admin_mail , end_date , format , editable , receiveNewVotes )
VALUES ( ? , ? , ? , ? , ? , ? , FROM_UNIXTIME ( ? ), ? , ? , ? ) ' ;
2014-12-03 21:08:08 +01:00
$prepared = $connect -> prepare ( $sql );
2014-12-05 01:08:38 +01:00
$prepared -> execute ( array ( $poll_id , $admin_poll_id , $title , $comment , $adminName , $adminMail , $endDate , $format , $editable , $receiveNewVotes ));
$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 ));
}
}
2014-09-04 17:52:18 +02:00
2014-12-05 01:08:38 +01:00
$connect -> commit ();
2014-09-04 17:52:18 +02:00
2014-12-05 01:08:38 +01:00
// Send confirmation by mail if enabled
2014-12-03 21:08:08 +01:00
if ( $config [ 'use_smtp' ] === true ){
2014-11-14 17:35:22 +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. " );
$message .= " \n \n " ;
2014-12-03 21:08:08 +01:00
$message .= stripslashes ( html_entity_decode ( $adminName , ENT_QUOTES , " UTF-8 " )) . " " . _ ( " hast just created a poll called " ) . " : \" " . stripslashes ( htmlspecialchars_decode ( $title , ENT_QUOTES )) . " \" . \n " ;
2014-11-14 17:35:22 +01:00
$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-11-14 17:35:22 +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 " );
$message_admin .= " : \n \n " . " %s \n \n " . _ ( " Thanks for your confidence. " ) . " \n " . NOMAPPLICATION ;
2014-11-12 17:49:52 +01:00
2014-12-03 21:08:08 +01:00
$message = sprintf ( $message , Utils :: getUrlSondage ( $poll_id ));
$message_admin = sprintf ( $message_admin , Utils :: getUrlSondage ( $admin_poll_id , true ));
2014-11-12 17:49:52 +01:00
2014-11-14 17:35:22 +01:00
if ( Utils :: isValidEmail ( $_SESSION [ 'adresse' ])) {
2014-12-03 21:08:08 +01:00
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' ] );
2014-11-14 17:35:22 +01:00
}
}
2014-12-03 21:08:08 +01:00
2014-12-05 01:08:38 +01:00
error_log ( date ( 'H:i:s d/m/Y:' ) . ' CREATION: ' . $poll_id . " \t " . $format . " \t " . $adminName . " \t " . $adminMail . " \n " , 3 , 'admin/logs_studs.txt' );
2014-09-04 17:52:18 +02:00
2014-12-03 21:08:08 +01:00
return $admin_poll_id ;
2012-01-09 01:26:44 +01:00
}