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-26 23:32:53 +01:00
use Framadate\Services\LogService ;
use Framadate\Services\PollService ;
use Framadate\Services\MailService ;
2014-12-29 21:54:07 +01:00
use Framadate\Services\PurgeService ;
2014-12-26 23:32:53 +01:00
use Framadate\Utils ;
use Framadate\Choice ;
2014-09-04 17:52:18 +02:00
2014-12-06 19:42:01 +01:00
include_once __DIR__ . '/app/inc/init.php' ;
2014-12-26 23:32:53 +01:00
/* Service */
/*---------*/
$logService = new LogService ( LOG_FILE );
$pollService = new PollService ( $connect , $logService );
$mailService = new MailService ( $config [ 'use_smtp' ]);
2014-12-29 21:54:07 +01:00
$purgeService = new PurgeService ( $connect , $logService );
2014-12-26 23:32:53 +01:00
2011-05-15 03:56:54 +02:00
if ( file_exists ( 'bandeaux_local.php' )) {
2014-09-04 17:52:18 +02:00
include_once ( 'bandeaux_local.php' );
2011-05-15 03:56:54 +02:00
} else {
2014-09-04 17:52:18 +02:00
include_once ( 'bandeaux.php' );
2011-05-15 01:32:47 +02:00
}
2014-12-06 19:42:01 +01:00
// Step 1/4 : error if $_SESSION from info_sondage are not valid
2014-12-26 23:32:53 +01:00
if ( empty ( $_SESSION [ 'form' ] -> title ) || empty ( $_SESSION [ 'form' ] -> admin_name ) || (( $config [ 'use_smtp' ]) ? empty ( $_SESSION [ 'form' ] -> admin_mail ) : false )) {
2014-09-04 17:52:18 +02:00
2014-12-26 23:32:53 +01:00
Utils :: print_header ( _ ( " Error! " ));
2014-09-04 17:52:18 +02:00
bandeau_titre ( _ ( " Error! " ));
echo '
< div class = " alert alert-danger " >
2014-12-06 19:42:01 +01:00
< h3 > ' . _(' You haven\ 't filled the first section of the poll creation.' ) . ' !</ h3 >
< p > ' . _(' Back to the homepage of ') . ' < a href = " ' . Utils::get_server_name() . ' " > ' . NOMAPPLICATION . ' </ a ></ p >
2014-12-26 23:32:53 +01:00
</ div > ' . " \n " ;
2014-09-04 17:52:18 +02:00
bandeau_pied ();
2011-05-15 03:56:54 +02:00
} else {
2014-12-26 23:32:53 +01:00
2014-09-04 17:52:18 +02:00
// Step 4 : Data prepare before insert in DB
2014-12-06 19:42:01 +01:00
if ( isset ( $_POST [ 'confirmecreation' ])) {
2014-09-04 17:52:18 +02:00
2015-01-04 01:36:55 +01:00
// Define expiration date
$enddate = filter_input ( INPUT_POST , 'enddate' , FILTER_VALIDATE_REGEXP , [ 'options' => [ 'regexp' => '#^[0-9]{2}/[0-9]{2}/[0-9]{4}$#' ]]);
$min_time = time () + ( 24 * 60 * 60 );
$max_time = time () + ( 86400 * $config [ 'default_poll_duration' ]);
if ( ! empty ( $enddate )) {
$registredate = explode ( '/' , $enddate );
if ( is_array ( $registredate ) && count ( $registredate ) == 3 ) {
$time = mktime ( 0 , 0 , 0 , $registredate [ 1 ], $registredate [ 0 ], $registredate [ 2 ]);
if ( $time < $min_time ) {
$_SESSION [ 'form' ] -> end_date = $min_time ;
} elseif ( $max_time < $time ) {
$_SESSION [ 'form' ] -> end_date = $max_time ;
} else {
$_SESSION [ 'form' ] -> end_date = $time ;
}
2014-09-04 17:52:18 +02:00
}
}
2014-11-14 17:35:22 +01:00
2015-01-04 01:36:55 +01:00
if ( empty ( $_SESSION [ 'form' ] -> end_date )) {
// By default, expiration date is 6 months after last day
$_SESSION [ 'form' ] -> end_date = $max_time ;
}
2014-12-06 19:42:01 +01:00
// format du sondage AUTRE
2014-12-26 23:32:53 +01:00
$_SESSION [ 'form' ] -> format = 'A' ;
2014-12-06 19:42:01 +01:00
// Insert poll in database
2014-12-26 23:32:53 +01:00
$ids = $pollService -> createPoll ( $_SESSION [ 'form' ]);
$poll_id = $ids [ 0 ];
$admin_poll_id = $ids [ 1 ];
// Send confirmation by mail if enabled
if ( $config [ 'use_smtp' ] === true ) {
$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 " ;
$message .= stripslashes ( html_entity_decode ( $_SESSION [ 'form' ] -> admin_name , ENT_QUOTES , " UTF-8 " )) . ' ' . _ ( 'hast just created a poll called' ) . ' : "' . stripslashes ( htmlspecialchars_decode ( $_SESSION [ 'form' ] -> 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 \n You 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 ( $poll_id ));
$message_admin = sprintf ( $message_admin , Utils :: getUrlSondage ( $admin_poll_id , true ));
if ( $mailService -> isValidEmail ( $_SESSION [ 'form' ] -> admin_mail )) {
$mailService -> send ( $_SESSION [ 'form' ] -> admin_mail , '[' . NOMAPPLICATION . '][' . _ ( 'Author\'s message' ) . '] ' . _ ( 'Poll' ) . ' : ' . stripslashes ( htmlspecialchars_decode ( $_SESSION [ 'form' ] -> title , ENT_QUOTES )), $message_admin );
$mailService -> send ( $_SESSION [ 'form' ] -> admin_mail , '[' . NOMAPPLICATION . '][' . _ ( 'For sending to the polled users' ) . '] ' . _ ( 'Poll' ) . ' : ' . stripslashes ( htmlspecialchars_decode ( $_SESSION [ 'form' ] -> title , ENT_QUOTES )), $message );
}
}
2014-12-06 19:42:01 +01:00
// Clean Form data in $_SESSION
unset ( $_SESSION [ 'form' ]);
// Delete old polls
2014-12-29 21:54:07 +01:00
$purgeService -> purgeOldPolls ();
2014-12-26 23:32:53 +01:00
2014-12-06 19:42:01 +01:00
// Redirect to poll administration
header ( 'Location:' . Utils :: getUrlSondage ( $admin_poll_id , true ));
exit ;
2014-09-04 17:52:18 +02:00
2014-12-26 23:32:53 +01:00
} // Step 3/4 : Confirm poll creation and choose a removal date
2014-12-06 19:42:01 +01:00
else if ( isset ( $_POST [ 'fin_sondage_autre' ])) {
2014-12-26 23:32:53 +01:00
Utils :: print_header ( _ ( 'Removal date and confirmation (3 on 3)' ));
2014-12-06 19:42:01 +01:00
bandeau_titre ( _ ( 'Removal date and confirmation (3 on 3)' ));
2014-12-26 23:32:53 +01:00
2014-12-06 19:42:01 +01:00
// Store choices in $_SESSION
if ( isset ( $_POST [ 'choices' ])) {
$_SESSION [ 'form' ] -> clearChoices ();
2014-12-26 23:32:53 +01:00
foreach ( $_POST [ 'choices' ] as $c ) {
if ( ! empty ( $c )) {
2014-12-06 19:42:01 +01:00
$choice = new Choice ( htmlentities ( html_entity_decode ( $c , ENT_QUOTES , 'UTF-8' ), ENT_QUOTES , 'UTF-8' ));
$_SESSION [ 'form' ] -> addChoice ( $choice );
}
2014-09-04 17:52:18 +02:00
}
2011-05-22 04:03:44 +02:00
}
2014-09-04 17:52:18 +02:00
2014-11-14 17:35:22 +01:00
// Expiration date is initialised with config parameter. Value will be modified in step 4 if user has defined an other date
2014-12-26 23:32:53 +01:00
$_SESSION [ 'form' ] -> end_date = time () + ( 86400 * $config [ 'default_poll_duration' ]); //60 sec * 60 min * 24 hours * config
2014-10-21 01:31:26 +02:00
2014-11-12 16:35:13 +01:00
// Summary
2014-10-21 01:31:26 +02:00
$summary = '<ol>' ;
2014-12-06 19:42:01 +01:00
foreach ( $_SESSION [ 'form' ] -> getChoices () as $choice ) {
2014-10-21 01:31:26 +02:00
2014-12-26 23:32:53 +01:00
preg_match_all ( '/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/' , $choice -> getName (), $md_a_img ); // Markdown [![alt](src)](href)
preg_match_all ( '/!\[(.*?)\]\((.*?)\)/' , $choice -> getName (), $md_img ); // Markdown ![alt](src)
preg_match_all ( '/\[(.*?)\]\((.*?)\)/' , $choice -> getName (), $md_a ); // Markdown [text](href)
if ( isset ( $md_a_img [ 2 ][ 0 ]) && $md_a_img [ 2 ][ 0 ] != '' && isset ( $md_a_img [ 3 ][ 0 ]) && $md_a_img [ 3 ][ 0 ] != '' ) { // [![alt](src)](href)
2014-10-21 01:31:26 +02:00
2014-12-26 23:32:53 +01:00
$li_subject_text = ( isset ( $md_a_img [ 1 ][ 0 ]) && $md_a_img [ 1 ][ 0 ] != '' ) ? stripslashes ( $md_a_img [ 1 ][ 0 ]) : _ ( 'Choice' ) . ' ' . ( $i + 1 );
$li_subject_html = '<a href="' . $md_a_img [ 3 ][ 0 ] . '"><img src="' . $md_a_img [ 2 ][ 0 ] . '" class="img-responsive" alt="' . $li_subject_text . '" /></a>' ;
2014-10-21 01:31:26 +02:00
2014-12-26 23:32:53 +01:00
} elseif ( isset ( $md_img [ 2 ][ 0 ]) && $md_img [ 2 ][ 0 ] != '' ) { // ![alt](src)
2014-10-21 01:31:26 +02:00
2014-12-26 23:32:53 +01:00
$li_subject_text = ( isset ( $md_img [ 1 ][ 0 ]) && $md_img [ 1 ][ 0 ] != '' ) ? stripslashes ( $md_img [ 1 ][ 0 ]) : _ ( 'Choice' ) . ' ' . ( $i + 1 );
$li_subject_html = '<img src="' . $md_img [ 2 ][ 0 ] . '" class="img-responsive" alt="' . $li_subject_text . '" />' ;
2014-10-21 01:31:26 +02:00
2014-12-26 23:32:53 +01:00
} elseif ( isset ( $md_a [ 2 ][ 0 ]) && $md_a [ 2 ][ 0 ] != '' ) { // [text](href)
2014-10-21 01:31:26 +02:00
2014-12-26 23:32:53 +01:00
$li_subject_text = ( isset ( $md_a [ 1 ][ 0 ]) && $md_a [ 1 ][ 0 ] != '' ) ? stripslashes ( $md_a [ 1 ][ 0 ]) : _ ( 'Choice' ) . ' ' . ( $i + 1 );
$li_subject_html = '<a href="' . $md_a [ 2 ][ 0 ] . '">' . $li_subject_text . '</a>' ;
2014-10-21 01:31:26 +02:00
} else { // text only
2014-12-06 19:42:01 +01:00
$li_subject_text = stripslashes ( $choice -> getName ());
2014-10-21 01:31:26 +02:00
$li_subject_html = $li_subject_text ;
}
2014-12-26 23:32:53 +01:00
$summary .= '<li>' . $li_subject_html . '</li>' . " \n " ;
2014-10-21 01:31:26 +02:00
}
$summary .= '</ol>' ;
2015-01-04 01:36:55 +01:00
$end_date_str = utf8_encode ( strftime ( '%d/%m/%Y' , $_SESSION [ 'form' ] -> end_date )); //textual date
2014-12-06 19:42:01 +01:00
2014-09-04 17:52:18 +02:00
echo '
< form name = " formulaire " action = " ' . Utils::get_server_name() . 'choix_autre.php " method = " POST " class = " form-horizontal " role = " form " >
< div class = " row " >
2014-10-21 01:31:26 +02:00
< div class = " col-md-8 col-md-offset-2 " >
< div class = " well summary " >
2014-12-26 23:32:53 +01:00
< h4 > ' . _(' List of your choices ') . ' </ h4 >
' . $summary . '
2014-10-21 01:31:26 +02:00
</ div >
2014-09-04 17:52:18 +02:00
< div class = " alert alert-info " >
2015-01-04 01:36:55 +01:00
< p > ' . _(' Your poll will be automatically removed after ') . ' ' . $config[' default_poll_duration '] . ' ' . _(' days ') . ' .< br /> ' . _(' You can set a closer removal date for it . ') . ' </ p >
2014-09-04 17:52:18 +02:00
< div class = " form-group " >
2015-01-04 01:36:55 +01:00
< label for = " enddate " class = " col-sm-5 control-label " > ' . _(' Removal date ( optional ) ') . ' </ label >
2014-09-04 17:52:18 +02:00
< div class = " col-sm-6 " >
< div class = " input-group date " >
< span class = " input-group-addon " >< i class = " glyphicon glyphicon-calendar text-info " ></ i ></ span >
2015-01-04 01:36:55 +01:00
< input type = " text " class = " form-control " id = " enddate " data - date - format = " ' . _('dd/mm/yyyy') . ' " aria - describedby = " dateformat " name = " enddate " value = " ' . $end_date_str . ' " size = " 10 " maxlength = " 10 " placeholder = " ' . _( " dd / mm / yyyy " ) . ' " />
2014-09-04 17:52:18 +02:00
</ div >
</ div >
2015-01-04 01:36:55 +01:00
< span id = " dateformat " class = " sr-only " > ' . _(' ( dd / mm / yyyy ) ') . ' </ span >
2014-09-04 17:52:18 +02:00
</ div >
</ div >
< div class = " alert alert-warning " >
2015-01-04 01:36:55 +01:00
< p > ' . _(' Once you have confirmed the creation of your poll , you will be automatically redirected on the administration page of your poll . ') . ' </ p > ' ;
2014-12-26 23:32:53 +01:00
if ( $config [ 'use_smtp' ] == true ) {
2014-11-14 17:35:22 +01:00
echo '
2015-01-04 01:36:55 +01:00
< p > ' . _(' Then , you will receive quickly two emails : one contening the link of your poll for sending it to the voters , the other contening the link to the administration page of your poll . ') . ' </ p > ' ;
2014-11-14 17:35:22 +01:00
}
echo '
2014-09-04 17:52:18 +02:00
</ div >
2014-10-21 01:31:26 +02:00
< p class = " text-right " >
2014-12-26 23:32:53 +01:00
< button class = " btn btn-default " onclick = " javascript:window.history.back(); " title = " ' . _('Back to step 2') . ' " > ' . _(' Back ') . ' </ button >
< button name = " confirmecreation " value = " confirmecreation " type = " submit " class = " btn btn-success " > ' . _(' Create the poll ') . ' </ button >
2014-10-21 01:31:26 +02:00
</ p >
2014-09-04 17:52:18 +02:00
</ div >
</ div >
2014-12-26 23:32:53 +01:00
</ form > ' . " \n " ;
2014-09-04 17:52:18 +02:00
bandeau_pied ();
2014-12-26 23:32:53 +01:00
// Step 2/4 : Select choices of the poll
2011-05-15 03:56:54 +02:00
} else {
2014-12-26 23:32:53 +01:00
Utils :: print_header ( _ ( 'Poll subjects (2 on 3)' ));
2014-12-06 19:42:01 +01:00
bandeau_titre ( _ ( 'Poll subjects (2 on 3)' ));
2014-09-04 17:52:18 +02:00
echo '
< form name = " formulaire " action = " ' . Utils::get_server_name() . 'choix_autre.php " method = " POST " class = " form-horizontal " role = " form " >
< div class = " row " >
2014-10-21 01:31:26 +02:00
< div class = " col-md-8 col-md-offset-2 " > ' ;
2014-09-04 17:52:18 +02:00
echo '
< div class = " alert alert-info " >
2014-12-26 23:32:53 +01:00
< p > ' . _("To make a generic poll you need to propose at least two choices between differents subjects.") . ' </ p >
< p > ' . _("You can add or remove additional choices with the buttons") . ' < span class = " glyphicon glyphicon-minus text-info " ></ span >< span class = " sr-only " > ' . _("Remove") . ' </ span > < span class = " glyphicon glyphicon-plus text-success " ></ span >< span class = " sr-only " > ' . _("Add") . ' </ span ></ p > ' ;
if ( $config [ 'user_can_add_img_or_link' ]) {
echo ' <p>' . _ ( " It's possible to propose links or images by using " ) . '<a href="http://' . $lang . '.wikipedia.org/wiki/Markdown">' . _ ( " the Markdown syntax " ) . '</a>.</p>' ;
2014-11-14 17:35:22 +01:00
}
2014-12-26 23:32:53 +01:00
echo ' </div>' . " \n " ;
2014-09-04 17:52:18 +02:00
// Fields choices : 5 by default
2014-12-06 19:42:01 +01:00
$choices = $_SESSION [ 'form' ] -> getChoices ();
$nb_choices = max ( count ( $choices ), 5 );
2014-09-04 17:52:18 +02:00
for ( $i = 0 ; $i < $nb_choices ; $i ++ ) {
2014-12-06 19:42:01 +01:00
$choice = isset ( $choices [ $i ]) ? $choices [ $i ] : new Choice ();
2014-09-04 17:52:18 +02:00
echo '
< div class = " form-group choice-field " >
2014-12-26 23:32:53 +01:00
< label for = " choice' . $i . ' " class = " col-sm-2 control-label " > ' . _(' Choice ') . ' ' . ($i + 1) . ' </ label >
2014-10-21 01:31:26 +02:00
< div class = " col-sm-10 input-group " >
2014-12-26 23:32:53 +01:00
< input type = " text " class = " form-control " name = " choices[] " size = " 40 " value = " ' . $choice->getName () . ' " id = " choice' . $i . ' " /> ' ;
if ( $config [ 'user_can_add_img_or_link' ]) {
echo '<span class="input-group-addon btn-link md-a-img" title="' . _ ( 'Add a link or an image' ) . ' - ' . _ ( 'Choice' ) . ' ' . ( $i + 1 ) . '" ><span class="glyphicon glyphicon-picture"></span> <span class="glyphicon glyphicon-link"></span></span>' ;
}
2014-11-11 20:56:03 +01:00
echo '
2014-11-14 17:35:22 +01:00
</ div >
2014-12-26 23:32:53 +01:00
</ div > ' . " \n " ;
2014-09-04 17:52:18 +02:00
}
echo '
2014-10-21 01:31:26 +02:00
< div class = " col-md-4 " >
2014-09-04 17:52:18 +02:00
< div class = " btn-group btn-group " >
2014-12-26 23:32:53 +01:00
< button type = " button " id = " remove-a-choice " class = " btn btn-default " title = " ' . _('Remove a choice') . ' " >< span class = " glyphicon glyphicon-minus text-info " ></ span >< span class = " sr-only " > ' . _(' Remove ') . ' </ span ></ button >
< button type = " button " id = " add-a-choice " class = " btn btn-default " title = " ' . _('Add a choice') . ' " >< span class = " glyphicon glyphicon-plus text-success " ></ span >< span class = " sr-only " > ' . _(' Add ') . ' </ span ></ button >
2014-09-04 17:52:18 +02:00
</ div >
</ div >
2014-10-21 01:31:26 +02:00
< div class = " col-md-8 text-right " >
2014-12-26 23:32:53 +01:00
< a class = " btn btn-default " href = " ' . Utils::get_server_name() . 'infos_sondage.php?choix_sondage=autre " title = " ' . _('Back to step 1') . ' " > ' . _(' Back ') . ' </ a >
< button name = " fin_sondage_autre " value = " ' . _('Next') . ' " type = " submit " class = " btn btn-success disabled " title = " ' . _('Go to step 3') . ' " > ' . _(' Next ') . ' </ button >
2014-10-21 01:31:26 +02:00
</ div >
</ div >
</ div >
< div class = " modal fade " id = " md-a-imgModal " tabindex = " -1 " role = " dialog " aria - labelledby = " md-a-imgModalLabel " aria - hidden = " true " >
< div class = " modal-dialog " >
< div class = " modal-content " >
< div class = " modal-header " >
2014-12-26 23:32:53 +01:00
< button type = " button " class = " close " data - dismiss = " modal " >< span aria - hidden = " true " >& times ; </ span >< span class = " sr-only " > ' . _(' Close ') . ' </ span ></ button >
< p class = " modal-title " id = " md-a-imgModalLabel " > ' . _("Add a link or an image") . ' </ p >
2014-10-21 01:31:26 +02:00
</ div >
< div class = " modal-body " >
2014-12-26 23:32:53 +01:00
< p class = " alert alert-info " > ' . _("These fields are optional. You can add a link, an image or both.") . ' </ p >
2014-10-21 01:31:26 +02:00
< div class = " form-group " >
2014-12-26 23:32:53 +01:00
< label for = " md-img " >< span class = " glyphicon glyphicon-picture " ></ span > ' . _(' URL of the image ') . ' </ label >
2014-10-21 01:31:26 +02:00
< input id = " md-img " type = " text " placeholder = " http://… " class = " form-control " size = " 40 " />
</ div >
< div class = " form-group " >
2014-12-26 23:32:53 +01:00
< label for = " md-a " >< span class = " glyphicon glyphicon-link " ></ span > ' . _(' Link ') . ' </ label >
2014-10-21 01:31:26 +02:00
< input id = " md-a " type = " text " placeholder = " http://… " class = " form-control " size = " 40 " />
</ div >
< div class = " form-group " >
2014-12-26 23:32:53 +01:00
< label for = " md-text " > ' . _(' Alternative text ') . ' </ label >
2014-10-21 01:31:26 +02:00
< input id = " md-text " type = " text " class = " form-control " size = " 40 " />
</ div >
</ div >
< div class = " modal-footer " >
2014-12-26 23:32:53 +01:00
< button type = " button " class = " btn btn-default " data - dismiss = " modal " > ' . _(' Cancel ') . ' </ button >
< button type = " button " class = " btn btn-primary " > ' . _(' Add ') . ' </ button >
2014-10-21 01:31:26 +02:00
</ div >
2014-09-04 17:52:18 +02:00
</ div >
</ div >
</ div >
2014-12-26 23:32:53 +01:00
</ form > ' . " \n " ;
2014-09-04 17:52:18 +02:00
bandeau_pied ();
2013-03-14 14:30:38 +01:00
2011-05-15 03:56:54 +02:00
}
2014-06-11 19:19:17 +02:00
}