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
session_start ();
include_once ( 'creation_sondage.php' );
2013-03-13 18:29:48 +01:00
if ( is_readable ( '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-09-04 17:52:18 +02:00
// Step 1/3 : error if $_SESSION from info_sondage are not valid
2014-11-15 01:27:38 +01:00
if ( Utils :: issetAndNoEmpty ( 'titre' , $_SESSION ) === false || Utils :: issetAndNoEmpty ( 'nom' , $_SESSION ) === false || (( $config [ 'use_smtp' ]) ? Utils :: issetAndNoEmpty ( 'adresse' , $_SESSION ) === false : false )) {
2014-09-04 17:52:18 +02:00
Utils :: print_header ( _ ( " Error! " ) );
bandeau_titre ( _ ( " Error! " ));
echo '
< div class = " alert alter-danger " >
2014-11-06 15:20:03 +01:00
< h3 > ' . _("You haven' t filled the first section of the poll creation . " ) . ' !</h3>
2014-09-04 17:52:18 +02:00
< p > ' . _("Back to the homepage of ") . ' ' . ' < a href = " ' . Utils::get_server_name() . ' " > ' . NOMAPPLICATION . ' </ a >.</ p >
</ div > ' ;
bandeau_pied ();
} else {
// Step 4 : Data prepare before insert in DB
if ( Utils :: issetAndNoEmpty ( 'confirmation' )) {
$temp_results = array ();
$choixdate = '' ;
if ( Utils :: issetAndNoEmpty ( 'totalchoixjour' , $_SESSION ) === true ) {
for ( $i = 0 ; $i < count ( $_SESSION [ " totalchoixjour " ]); $i ++ ) {
2014-09-29 16:33:15 +02:00
if ( count ( $_SESSION [ 'horaires' . $i ]) != 0 ) {
for ( $j = 0 ; $j < min ( count ( $_SESSION [ 'horaires' . $i ]), 12 ); $j ++ ) {
if ( $_SESSION [ 'horaires' . $i ][ $j ] != " " ) {
array_push ( $temp_results , $_SESSION [ " totalchoixjour " ][ $i ] . '@' . $_SESSION [ 'horaires' . $i ][ $j ]);
} else {
array_push ( $temp_results , $_SESSION [ " totalchoixjour " ][ $i ]);
}
2014-09-04 17:52:18 +02:00
}
2014-09-29 16:33:15 +02:00
} else {
array_push ( $temp_results , $_SESSION [ " totalchoixjour " ][ $i ]);
2014-09-04 17:52:18 +02:00
}
2011-05-15 05:56:11 +02:00
}
2014-09-29 16:33:15 +02:00
2011-05-15 05:56:11 +02:00
}
2014-09-04 17:52:18 +02:00
// Sort and remove doublons
$temp_results = array_unique ( $temp_results );
sort ( $temp_results );
for ( $i = 0 ; $i < count ( $temp_results ); $i ++ ) {
if ( isset ( $temp_results [ $i ])) {
$choixdate .= ',' . $temp_results [ $i ];
}
2011-05-15 05:56:11 +02:00
}
2013-03-13 18:29:48 +01:00
2014-09-04 17:52:18 +02:00
$_SESSION [ " toutchoix " ] = substr ( $choixdate , 1 );
2014-10-21 01:31:26 +02:00
// Expiration date → 6 months after last day if not filled or in bad format
2014-11-14 17:35:22 +01:00
$_SESSION [ " champdatefin " ] = end ( $temp_results ) + ( 86400 * $config [ 'default_poll_duration' ]);
2014-10-21 01:31:26 +02:00
if ( Utils :: issetAndNoEmpty ( 'champdatefin' )) {
$registredate = explode ( " / " , $_POST [ " champdatefin " ]);
if ( is_array ( $registredate ) == true && count ( $registredate ) == 3 ) {
$time = mktime ( 0 , 0 , 0 , $registredate [ 1 ], $registredate [ 0 ], $registredate [ 2 ]);
if ( $time > time () + ( 24 * 60 * 60 )) {
$_SESSION [ " champdatefin " ] = $time ;
}
}
}
2014-09-04 17:52:18 +02:00
ajouter_sondage ();
2013-03-13 18:29:48 +01:00
2011-05-15 03:56:54 +02:00
} else {
2014-09-04 17:52:18 +02:00
if ( Utils :: issetAndNoEmpty ( 'days' )) {
if ( ! isset ( $_SESSION [ " totalchoixjour " ])) {
$_SESSION [ " totalchoixjour " ] = array ();
2011-05-15 05:56:11 +02:00
}
2014-09-04 17:52:18 +02:00
$k = 0 ;
for ( $i = 0 ; $i < count ( $_POST [ " days " ]); $i ++ ) {
if ( isset ( $_POST [ " days " ][ $i ]) && $_POST [ " days " ][ $i ] != '' ) {
$_SESSION [ 'totalchoixjour' ][ $k ] = mktime ( 0 , 0 , 0 , substr ( $_POST [ " days " ][ $i ], 3 , 2 ), substr ( $_POST [ " days " ][ $i ], 0 , 2 ), substr ( $_POST [ " days " ][ $i ], 6 , 4 ));
$l = 0 ;
for ( $j = 0 ; $j < count ( $_POST [ 'horaires' . $i ]); $j ++ ) {
if ( isset ( $_POST [ 'horaires' . $i ][ $j ]) && $_POST [ 'horaires' . $i ][ $j ] != '' ) {
$_SESSION [ 'horaires' . $k ][ $l ] = $_POST [ 'horaires' . $i ][ $j ];
$l ++ ;
}
}
$k ++ ;
}
2011-05-15 05:56:11 +02:00
}
2011-05-15 03:56:54 +02:00
}
}
2011-05-15 01:32:47 +02:00
2014-09-04 17:52:18 +02:00
//le format du sondage est DATE
$_SESSION [ " formatsondage " ] = " D " . $_SESSION [ " studsplus " ];
// Step 3/3 : Confirm poll creation
if ( Utils :: issetAndNoEmpty ( 'choixheures' ) && Utils :: issetAndNoEmpty ( 'totalchoixjour' , $_SESSION )) {
Utils :: print_header ( _ ( " Removal date and confirmation (3 on 3) " ) );
bandeau_titre ( _ ( " Removal date and confirmation (3 on 3) " ));
$temp_array = array_unique ( $_SESSION [ " totalchoixjour " ]);
sort ( $temp_array );
2014-11-14 17:35:22 +01:00
$removal_date = strftime ( $date_format [ 'txt_full' ], end ( $temp_array ) + ( 86400 * $config [ 'default_poll_duration' ]));
2014-10-21 01:31:26 +02:00
// Sumary
$summary = '<ul>' ;
for ( $i = 0 ; $i < count ( $_SESSION [ " totalchoixjour " ]); $i ++ ) {
2014-11-14 17:35:22 +01:00
$summary .= '<li>' . strftime ( $date_format [ 'txt_full' ], $_SESSION [ " totalchoixjour " ][ $i ]);
2014-10-21 01:31:26 +02:00
for ( $j = 0 ; $j < count ( $_SESSION [ 'horaires' . $i ]); $j ++ ) {
if ( isset ( $_SESSION [ 'horaires' . $i ][ $j ])) {
$summary .= ( $j == 0 ) ? ' : ' : ', ' ;
$summary .= $_SESSION [ 'horaires' . $i ][ $j ];
}
}
$summary .= '</li>' . " \n " ;
}
$summary .= '</ul>' ;
2014-09-04 17:52:18 +02:00
echo '
< form name = " formulaire " action = " ' . Utils::get_server_name() . 'choix_date.php " method = " POST " class = " form-horizontal " role = " form " >
< div class = " row " id = " selected-days " >
< div class = " col-md-8 col-md-offset-2 " >
2014-11-06 15:20:03 +01:00
< h3 > '. _("Confirm the creation of your poll") .' </ h3 >
2014-10-21 01:31:26 +02:00
< div class = " well summary " >
2014-11-06 15:20:03 +01:00
< h4 > '. _("List of your choices").' </ h4 >
2014-10-21 01:31:26 +02:00
'. $summary .'
</ div >
< div class = " alert alert-info clearfix " >
2014-11-14 17:35:22 +01:00
< p > ' . _("Your poll will be automatically removed "). $config[' default_poll_duration '] . ' ' . _("days") ._(" after the last date of your poll:") . ' < strong > '.$removal_date.' </ strong >.< br /> ' . _("You can fix another removal date for it.") .' </ p >
2014-10-21 01:31:26 +02:00
< div class = " form-group " >
< label for = " champdatefin " class = " col-sm-5 control-label " > '. _("Removal date (optional)") .' </ label >
< div class = " col-sm-6 " >
< div class = " input-group date " >
< span class = " input-group-addon " >< i class = " glyphicon glyphicon-calendar text-info " ></ i ></ span >
< input type = " text " class = " form-control " id = " champdatefin " data - date - format = " '. _( " dd / mm / yyyy " ) .' " aria - describedby = " dateformat " name = " champdatefin " value = " " size = " 10 " maxlength = " 10 " placeholder = " '. _( " dd / mm / yyyy " ) .' " />
</ div >
</ div >
< span id = " dateformat " class = " sr-only " > '. _("(dd/mm/yyyy)") .' </ span >
</ div >
2014-09-04 17:52:18 +02:00
</ div >
< div class = " alert alert-warning " >
2014-11-14 17:35:22 +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 > ' ;
if ( $config [ 'use_smtp' ] == true ){
echo '
< 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 > ' ;
}
echo '
2014-09-04 17:52:18 +02:00
</ div >
< p class = " text-right " >
2014-10-21 01:31:26 +02:00
< button class = " btn btn-default " onclick = " javascript:window.history.back(); " title = " '. _('Back to step 2') . ' " > '. _(' Back ') . ' </ button >
2014-09-04 17:52:18 +02:00
< button name = " confirmation " value = " confirmation " type = " submit " class = " btn btn-success " > '. _(' Create the poll ') . ' </ button >
</ p >
</ div >
</ div >
</ form > ' . " \n " ;
bandeau_pied ();
// Step 2/3 : Select dates of the poll
2011-05-15 03:56:54 +02:00
} else {
2014-09-04 17:52:18 +02:00
Utils :: print_header ( _ ( " Poll dates (2 on 3) " ) );
bandeau_titre ( _ ( " Poll dates (2 on 3) " ));
echo '
< form name = " formulaire " action = " ' . Utils::get_server_name() . 'choix_date.php " method = " POST " class = " form-horizontal " role = " form " >
< div class = " row " id = " selected-days " >
2014-10-21 01:31:26 +02:00
< div class = " col-md-10 col-md-offset-1 " >
2014-11-06 15:20:03 +01:00
< h3 > '. _("Choose the dates of your poll") .' </ h3 >
2014-09-04 17:52:18 +02:00
< div class = " alert alert-info " >
< p > '. _("To schedule an event you need to propose at least two choices (two hours for one day or two days).").' </ p >
2014-10-21 01:31:26 +02:00
< p > '. _("You can add or remove additionnal days and hours 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 >
2014-09-04 17:52:18 +02:00
< p > '. _("For each selected day, you can choose, or not, meeting hours (e.g.: \"8h\", \"8:30\", \"8h-10h\", \"evening\", etc.)").' </ p >
</ div > ' ;
2014-10-21 01:31:26 +02:00
// Fields days : 3 by default
$nb_days = ( isset ( $_SESSION [ " totalchoixjour " ])) ? count ( $_SESSION [ " totalchoixjour " ]) : 3 ;
2014-09-04 17:52:18 +02:00
for ( $i = 0 ; $i < $nb_days ; $i ++ ) {
$day_value = isset ( $_SESSION [ " totalchoixjour " ][ $i ]) ? strftime ( " %d/%m/%Y " , $_SESSION [ " totalchoixjour " ][ $i ]) : '' ;
echo '
< fieldset >
< div class = " form-group " >
< legend >
2014-11-14 17:35:22 +01:00
< label class = " sr-only " for = " day'. $i .' " > '. _("Day") .' '. ($i+1) .' </ label >
2014-09-04 17:52:18 +02:00
< div class = " input-group date col-xs-7 " >
< span class = " input-group-addon " >< i class = " glyphicon glyphicon-calendar text-info " ></ i ></ span >
2014-10-21 01:31:26 +02:00
< input type = " text " class = " form-control " id = " day'. $i .' " title = " '. _( " Day " ) .' '. ( $i +1) .' " data - date - format = " '. _( " dd / mm / yyyy " ) .' " aria - describedby = " dateformat'. $i .' " name = " days[] " value = " '. $day_value .' " size = " 10 " maxlength = " 10 " placeholder = " '. _( " dd / mm / yyyy " ) .' " />
2014-09-04 17:52:18 +02:00
</ div >
2014-10-21 01:31:26 +02:00
< span id = " dateformat'. $i .' " class = " sr-only " > '. _("(dd/mm/yyyy)") .' </ span >
2014-09-04 17:52:18 +02:00
</ legend > ' . " \n " ;
// Fields hours : 3 by default
2014-11-15 01:38:23 +01:00
for ( $j = 0 ; $j < max ( count ( isset ( $_SESSION [ " horaires " . $i ]) ? $_SESSION [ " horaires " . $i ] : 0 ), 3 ); $j ++ ) {
$hour_value = isset ( $_SESSION [ " horaires " . $i ][ $j ]) ? $_SESSION [ " horaires " . $i ][ $j ] : '' ;
2014-09-04 17:52:18 +02:00
echo '
< div class = " col-sm-2 " >
< label for = " d'. $i .'-h'. $j .' " class = " sr-only control-label " > '. _("Time") .' '. ($j+1) .' </ label >
2014-10-21 01:31:26 +02:00
< input type = " text " class = " form-control hours " title = " '. $day_value .' - '. _( " Time " ) .' '. ( $j +1) .' " placeholder = " '. _( " Time " ) .' '. ( $j +1) .' " id = " d'. $i .'-h'. $j .' " name = " horaires'. $i .'[] " value = " '. $hour_value .' " />
2014-09-04 17:52:18 +02:00
</ div > ' . " \n " ;
}
echo '
< div class = " col-sm-2 " >< div class = " btn-group btn-group-xs " style = " margin-top: 5px; " >
2014-11-06 15:20:03 +01:00
< button type = " button " title = " '. _( " Remove an hour " ) .' " class = " remove-an-hour btn btn-default " >< span class = " glyphicon glyphicon-minus text-info " ></ span >< span class = " sr-only " > '. _("Remove an hour") .' </ span ></ button >
< button type = " button " title = " '. _( " Add an hour " ) .' " class = " add-an-hour btn btn-default " >< span class = " glyphicon glyphicon-plus text-success " ></ span >< span class = " sr-only " > '. _("Add an hour") .' </ span ></ button >
2014-09-04 17:52:18 +02:00
</ div ></ div >
</ div >
</ fieldset > ' ;
}
echo '
2014-10-21 01:31:26 +02:00
< div class = " col-md-4 " >
< button type = " button " id = " copyhours " class = " btn btn-default disabled " title = " '. _( " Copy hours of the first day " ) .' " >< span class = " glyphicon glyphicon-sort-by-attributes-alt text-info " ></ span >< span class = " sr-only " > '. _("Copy hours of the first day") .' </ span ></ button >
2014-09-04 17:52:18 +02:00
< div class = " btn-group btn-group " >
2014-11-06 15:20:03 +01:00
< button type = " button " id = " remove-a-day " class = " btn btn-default disabled " title = " '. _( " Remove a day " ) .' " >< span class = " glyphicon glyphicon-minus text-info " ></ span >< span class = " sr-only " > '. _("Remove a day") .' </ span ></ button >
< button type = " button " id = " add-a-day " class = " btn btn-default " title = " '. _( " Add a day " ) .' " >< span class = " glyphicon glyphicon-plus text-success " ></ span >< span class = " sr-only " > '. _("Add a day") .' </ 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-09-04 17:52:18 +02:00
< div class = " btn-group " >
< button type = " button " class = " btn btn-default dropdown-toggle " data - toggle = " dropdown " >
< span class = " glyphicon glyphicon-remove text-danger " ></ span > '. _("Remove") . ' < span class = " caret " ></ span >
</ button >
< ul class = " dropdown-menu " role = " menu " >
< li >< a id = " resetdays " href = " javascript:void(0) " > '. _("Remove all days") .' </ a ></ li >
< li >< a id = " resethours " href = " javascript:void(0) " > '. _("Remove all hours") .' </ a ></ li >
</ ul >
</ div >
2014-10-21 01:31:26 +02:00
< a class = " btn btn-default " href = " '.Utils::get_server_name().'infos_sondage.php?choix_sondage=date " title = " '. _('Back to step 1') . ' " > '. _(' Back ') . ' </ a >
< button name = " choixheures " value = " '. _( " Next " ) .' " type = " submit " class = " btn btn-success disabled " title = " '. _('Go to step 3') . ' " > '. _("Next") .' </ button >
2014-09-04 17:52:18 +02:00
</ div >
</ div >
</ div >
</ form > ' . " \n " ;
bandeau_pied ();
2011-06-23 01:21:56 +02:00
2011-05-15 03:56:54 +02:00
}
2014-06-11 19:19:17 +02:00
}