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
2016-08-04 22:26:37 +02:00
* Authors of Framadate / OpenSondage : Framasoft ( https :// github . com / framasoft )
2014-09-04 17:52:18 +02:00
*
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
*/
2018-02-19 00:18:43 +01:00
use Framadate\Choice ;
2021-12-17 14:08:09 +01:00
use Framadate\Services\InputService ;
2014-12-26 23:32:53 +01:00
use Framadate\Services\LogService ;
use Framadate\Services\MailService ;
2018-02-19 00:18:43 +01:00
use Framadate\Services\PollService ;
2014-12-29 21:54:07 +01:00
use Framadate\Services\PurgeService ;
2018-04-08 11:21:11 +02:00
use Framadate\Services\SessionService ;
2014-12-26 23:32:53 +01:00
use Framadate\Utils ;
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 */
/*---------*/
2015-01-06 23:52:52 +01:00
$logService = new LogService ();
2021-12-20 17:46:50 +01:00
$pollService = new PollService ( $logService );
2018-02-21 11:07:11 +01:00
$mailService = new MailService ( $config [ 'use_smtp' ], $config [ 'smtp_options' ]);
2021-12-20 17:46:50 +01:00
$purgeService = new PurgeService ( $logService );
2018-04-08 11:21:11 +02:00
$sessionService = new SessionService ();
2021-12-17 14:08:09 +01:00
$inputService = new InputService ();
2014-12-26 23:32:53 +01:00
2015-09-03 08:03:37 +02:00
if ( is_file ( '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
}
2018-12-04 18:02:54 +01:00
$form = unserialize ( $_SESSION [ 'form' ]);
2014-12-06 19:42:01 +01:00
// Step 1/4 : error if $_SESSION from info_sondage are not valid
2021-12-20 17:46:50 +01:00
if ( empty ( $form -> title ) || empty ( $form -> admin_name ) || ( $config [ 'use_smtp' ] && empty ( $form -> admin_mail ))) {
2016-05-04 00:58:45 +02:00
$smarty -> assign ( 'title' , __ ( 'Error' , 'Error!' ));
$smarty -> assign ( 'error' , __ ( 'Error' , 'You haven\'t filled the first section of the poll creation.' ));
$smarty -> display ( 'error.tpl' );
exit ;
2018-02-21 11:07:11 +01:00
}
2018-12-04 18:02:54 +01:00
// The poll format is other (A) if we are in this file
if ( ! isset ( $form -> format )) {
$form -> format = 'A' ;
}
// If we come from another format, we need to clear choices
if ( isset ( $form -> format ) && $form -> format !== 'A' ) {
$form -> format = 'A' ;
$form -> clearChoices ();
2015-04-22 00:19:12 +02:00
}
2014-09-04 17:52:18 +02:00
// Step 4 : Data prepare before insert in DB
2016-05-04 00:08:29 +02:00
if ( isset ( $_POST [ 'confirmation' ])) {
2015-01-04 01:36:55 +01:00
// Define expiration date
2021-12-20 17:46:50 +01:00
$expiration_date = $inputService -> parseDate ( $_POST [ 'enddate' ]);
$form -> end_date = $inputService -> validateDate ( $expiration_date , $pollService -> minExpiryDate (), $pollService -> maxExpiryDate ()) -> getTimestamp ();
2015-01-04 01:36:55 +01:00
2014-12-06 19:42:01 +01:00
// Insert poll in database
2018-12-04 18:02:54 +01:00
$ids = $pollService -> createPoll ( $form );
2014-12-26 23:32:53 +01:00
$poll_id = $ids [ 0 ];
$admin_poll_id = $ids [ 1 ];
// Send confirmation by mail if enabled
if ( $config [ 'use_smtp' ] === true ) {
2015-04-08 22:25:14 +02:00
$message = __ ( 'Mail' , " 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 .= '<br/><br/>' ;
2018-12-04 18:02:54 +01:00
$message .= Utils :: htmlMailEscape ( $form -> admin_name ) . ' ' . __ ( 'Mail' , 'hast just created a poll called' ) . ' : "' . Utils :: htmlMailEscape ( $form -> title ) . '".<br/>' ;
2016-05-02 17:44:14 +02:00
$message .= sprintf ( __ ( 'Mail' , 'Thanks for filling the poll at the link above' ) . ' :<br/><br/><a href="%1$s">%1$s</a>' , Utils :: getUrlSondage ( $poll_id ));
2014-12-26 23:32:53 +01:00
2015-04-08 22:25:14 +02:00
$message_admin = __ ( 'Mail' , " 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 " );
2016-05-02 17:44:14 +02:00
$message_admin .= sprintf ( ' :<br/><br/><a href="%1$s">%1$s</a>' , Utils :: getUrlSondage ( $admin_poll_id , true ));
2014-12-26 23:32:53 +01:00
2018-12-04 18:02:54 +01:00
if ( $mailService -> isValidEmail ( $form -> admin_mail )) {
2020-12-11 17:20:19 +01:00
$mailService -> send ( $form -> admin_mail , '[' . NOMAPPLICATION . '][' . __ ( 'Mail' , 'Author\'s message' ) . '] ' . __ ( 'Generic' , 'Poll' ) . ': ' . Utils :: htmlEscape ( $form -> title ), $message_admin );
$mailService -> send ( $form -> admin_mail , '[' . NOMAPPLICATION . '][' . __ ( 'Mail' , 'For sending to the polled users' ) . '] ' . __ ( 'Generic' , 'Poll' ) . ': ' . Utils :: htmlEscape ( $form -> title ), $message );
2014-12-26 23:32:53 +01:00
}
}
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
2018-04-07 22:24:55 +02:00
// creation message
2018-04-08 11:21:11 +02:00
$sessionService -> set ( " Framadate " , " messagePollCreated " , TRUE );
2018-12-04 18:02:54 +01:00
2014-12-06 19:42:01 +01:00
// Redirect to poll administration
header ( 'Location:' . Utils :: getUrlSondage ( $admin_poll_id , true ));
exit ;
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' ])) {
// Store choices in $_SESSION
if ( isset ( $_POST [ 'choices' ])) {
2018-12-04 18:02:54 +01:00
$form -> clearChoices ();
2014-12-26 23:32:53 +01:00
foreach ( $_POST [ 'choices' ] as $c ) {
if ( ! empty ( $c )) {
2015-01-07 23:16:42 +01:00
$c = strip_tags ( $c );
2015-01-05 23:30:47 +01:00
$choice = new Choice ( $c );
2018-12-04 18:02:54 +01:00
$form -> addChoice ( $choice );
2014-12-06 19:42:01 +01:00
}
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
2021-12-17 14:08:09 +01:00
$form -> end_date = $pollService -> maxExpiryDate () -> format ( 'Y-m-d H:i:s' );
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>' ;
2018-12-04 18:02:54 +01:00
foreach ( $form -> getChoices () as $i => $choice ) {
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)
2021-12-20 17:46:50 +01:00
if ( isset ( $md_a_img [ 2 ][ 0 ], $md_a_img [ 3 ][ 0 ]) && $md_a_img [ 2 ][ 0 ] !== '' && $md_a_img [ 3 ][ 0 ] !== '' ) { // [![alt](src)](href)
2018-02-19 00:18:43 +01:00
$li_subject_text = ( isset ( $md_a_img [ 1 ][ 0 ]) && $md_a_img [ 1 ][ 0 ] !== '' ) ? stripslashes ( $md_a_img [ 1 ][ 0 ]) : __ ( 'Generic' , 'Choice' ) . ' ' . ( $i + 1 );
2014-12-26 23:32:53 +01:00
$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>' ;
2018-02-19 00:18:43 +01:00
} elseif ( isset ( $md_img [ 2 ][ 0 ]) && $md_img [ 2 ][ 0 ] !== '' ) { // ![alt](src)
$li_subject_text = ( isset ( $md_img [ 1 ][ 0 ]) && $md_img [ 1 ][ 0 ] !== '' ) ? stripslashes ( $md_img [ 1 ][ 0 ]) : __ ( 'Generic' , 'Choice' ) . ' ' . ( $i + 1 );
2014-12-26 23:32:53 +01:00
$li_subject_html = '<img src="' . $md_img [ 2 ][ 0 ] . '" class="img-responsive" alt="' . $li_subject_text . '" />' ;
2018-02-19 00:18:43 +01:00
} elseif ( isset ( $md_a [ 2 ][ 0 ]) && $md_a [ 2 ][ 0 ] !== '' ) { // [text](href)
$li_subject_text = ( isset ( $md_a [ 1 ][ 0 ]) && $md_a [ 1 ][ 0 ] !== '' ) ? stripslashes ( $md_a [ 1 ][ 0 ]) : __ ( 'Generic' , 'Choice' ) . ' ' . ( $i + 1 );
2014-12-26 23:32:53 +01:00
$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>' ;
2021-12-17 14:08:09 +01:00
$end_date_str = utf8_encode ( strftime ( $date_format [ 'txt_date' ], $pollService -> maxExpiryDate () -> getTimestamp ())); //textual date
2014-12-06 19:42:01 +01:00
2018-12-04 18:02:54 +01:00
$_SESSION [ 'form' ] = serialize ( $form );
2016-05-04 00:08:29 +02:00
$smarty -> assign ( 'title' , __ ( 'Step 3' , 'Removal date and confirmation (3 on 3)' ));
$smarty -> assign ( 'summary' , $summary );
$smarty -> assign ( 'end_date_str' , $end_date_str );
$smarty -> assign ( 'default_poll_duration' , $config [ 'default_poll_duration' ]);
$smarty -> assign ( 'use_smtp' , $config [ 'use_smtp' ]);
$smarty -> display ( 'create_classic_poll_step3.tpl' );
2014-09-04 17:52:18 +02:00
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 {
2015-03-30 15:19:56 +02:00
Utils :: print_header ( __ ( 'Step 2 classic' , 'Poll subjects (2 on 3)' ));
bandeau_titre ( __ ( 'Step 2 classic' , 'Poll subjects (2 on 3)' ));
2014-09-04 17:52:18 +02:00
echo '
2021-12-17 14:05:19 +01:00
< form name = " formulaire " action = " ' . Utils::get_server_name() . 'create_classic_poll.php " method = " POST " class = " form-horizontal " >
2014-09-04 17:52:18 +02:00
< 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 " >
2015-03-30 15:19:56 +02:00
< p > ' . __(' Step 2 classic ', ' To make a generic poll you need to propose at least two choices between differents subjects . ') . ' </ p >
< p > ' . __(' Step 2 classic ', ' You can add or remove additional choices with the buttons ') . ' < span class = " glyphicon glyphicon-minus text-info " ></ span >< span class = " sr-only " > ' . __(' Generic ', ' Remove ') . ' </ span > < span class = " glyphicon glyphicon-plus text-success " ></ span >< span class = " sr-only " > ' . __(' Generic ', ' Add ') . ' </ span ></ p > ' ;
2014-12-26 23:32:53 +01:00
if ( $config [ 'user_can_add_img_or_link' ]) {
2015-04-13 11:24:44 +02:00
echo ' <p>' . __ ( 'Step 2 classic' , 'It\'s possible to propose links or images by using' ) . ' <a href="http://' . $locale . '.wikipedia.org/wiki/Markdown">' . __ ( 'Step 2 classic' , '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
2018-12-04 18:02:54 +01:00
$choices = $form -> getChoices ();
2014-12-06 19:42:01 +01:00
$nb_choices = max ( count ( $choices ), 5 );
2014-09-04 17:52:18 +02:00
for ( $i = 0 ; $i < $nb_choices ; $i ++ ) {
2021-12-20 17:46:50 +01:00
$choice = $choices [ $i ] ? ? new Choice ();
2014-09-04 17:52:18 +02:00
echo '
< div class = " form-group choice-field " >
2015-03-30 15:19:56 +02:00
< label for = " choice' . $i . ' " class = " col-sm-2 control-label " > ' . __(' Generic ', ' 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' ]) {
2015-03-30 15:19:56 +02:00
echo '<span class="input-group-addon btn-link md-a-img" title="' . __ ( 'Step 2 classic' , 'Add a link or an image' ) . ' - ' . __ ( 'Generic' , 'Choice' ) . ' ' . ( $i + 1 ) . '" ><span class="glyphicon glyphicon-picture"></span> <span class="glyphicon glyphicon-link"></span></span>' ;
2014-12-26 23:32:53 +01:00
}
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 " >
2015-03-30 15:19:56 +02:00
< button type = " button " id = " remove-a-choice " class = " btn btn-default " title = " ' . __('Step 2 classic', 'Remove a choice') . ' " >< span class = " glyphicon glyphicon-minus text-info " ></ span >< span class = " sr-only " > ' . __(' Generic ', ' Remove ') . ' </ span ></ button >
< button type = " button " id = " add-a-choice " class = " btn btn-default " title = " ' . __('Step 2 classic', 'Add a choice') . ' " >< span class = " glyphicon glyphicon-plus text-success " ></ span >< span class = " sr-only " > ' . __(' Generic ', ' 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 " >
2015-03-31 00:02:37 +02:00
< a class = " btn btn-default " href = " ' . Utils::get_server_name() . 'create_poll.php?type=classic " title = " ' . __('Step 2', 'Back to step 1') . ' " > ' . __(' Generic ', ' Back ') . ' </ a >
2015-03-30 15:19:56 +02:00
< button name = " fin_sondage_autre " value = " ' . __('Generic', 'Next') . ' " type = " submit " class = " btn btn-success disabled " title = " ' . __('Step 2', 'Go to step 3') . ' " > ' . __(' Generic ', ' 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 " >
2015-03-30 15:19:56 +02:00
< button type = " button " class = " close " data - dismiss = " modal " >< span aria - hidden = " true " >& times ; </ span >< span class = " sr-only " > ' . __(' Generic ', ' Close ') . ' </ span ></ button >
< p class = " modal-title " id = " md-a-imgModalLabel " > ' . __(' Step 2 classic ', ' Add a link or an image ') . ' </ p >
2014-10-21 01:31:26 +02:00
</ div >
< div class = " modal-body " >
2015-03-30 15:19:56 +02:00
< p class = " alert alert-info " > ' . __(' Step 2 classic ', ' 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 " >
2015-03-30 15:19:56 +02:00
< label for = " md-img " >< span class = " glyphicon glyphicon-picture " ></ span > ' . __(' Step 2 classic ', ' 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 " >
2015-03-30 15:19:56 +02:00
< label for = " md-a " >< span class = " glyphicon glyphicon-link " ></ span > ' . __(' Generic ', ' 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 " >
2015-03-30 15:19:56 +02:00
< label for = " md-text " > ' . __(' Step 2 classic ', ' 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 " >
2015-03-30 15:19:56 +02:00
< button type = " button " class = " btn btn-default " data - dismiss = " modal " > ' . __(' Generic ', ' Cancel ') . ' </ button >
< button type = " button " class = " btn btn-primary " > ' . __(' Generic ', ' Add ') . ' </ button >
2014-10-21 01:31:26 +02:00
</ div >
2014-09-04 17:52:18 +02:00
</ div >
</ div >
</ div >
2015-03-05 14:53:42 +01:00
</ form >
2021-12-17 14:05:19 +01:00
< script src = " js/app/framadatepicker.js " ></ script >
< script src = " js/app/classic_poll.js " ></ script >
2015-03-05 14:53:42 +01:00
' . " \n " ;
2014-09-04 17:52:18 +02:00
bandeau_pied ();
2011-05-15 03:56:54 +02:00
}