25 require
'../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
27 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
28 require_once DOL_DOCUMENT_ROOT.
"/opensurvey/lib/opensurvey.lib.php";
31 if (!$user->rights->opensurvey->write) {
36 $_SESSION[
"formatsondage"] =
"D";
47 if (issetAndNoEmpty(
'totalchoixjour', $_SESSION) ===
true && issetAndNoEmpty(
'nbrecaseshoraires', $_SESSION) ===
true) {
48 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
51 for ($i = 0; $i < $nbofchoice; $i++) {
53 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
54 $horairesi =
GETPOST(
"horaires".$i);
55 $_SESSION[
"horaires$i"][$j] = $horairesi[$j];
57 $tmphorairesi =
GETPOST(
'horaires'.$i,
'array');
59 if (!is_array($tmphorairesi)) {
60 $errheure[$i][$j] =
true;
68 if (preg_match(
"/(\d{1,2}:\d{2})-(\d{1,2}:\d{2})/", $tmphorairesi[$j], $creneaux)) {
70 $debutcreneau = explode(
":", $creneaux[1]);
71 $fincreneau = explode(
":", $creneaux[2]);
75 if ($debutcreneau[0] < 24 && $fincreneau[0] < 24 && $debutcreneau[1] < 60 && $fincreneau[1] < 60 && ($debutcreneau[0] < $fincreneau[0] || ($debutcreneau[0] == $fincreneau[0] && $debutcreneau[1] < $fincreneau[1]))) {
76 $_SESSION[
"horaires$i"][$j] = $creneaux[1].
'-'.$creneaux[2];
78 $errheure[$i][$j] =
true;
81 } elseif (preg_match(
";^(\d{1,2}h\d{0,2})-(\d{1,2}h\d{0,2})$;i", $tmphorairesi[$j], $creneaux)) {
83 $debutcreneau = preg_split(
"/h/i", $creneaux[1]);
84 $fincreneau = preg_split(
"/h/i", $creneaux[2]);
88 if ($debutcreneau[0] < 24 && $fincreneau[0] < 24 && $debutcreneau[1] < 60 && $fincreneau[1] < 60 && ($debutcreneau[0] < $fincreneau[0] || ($debutcreneau[0] == $fincreneau[0] && $debutcreneau[1] < $fincreneau[1]))) {
89 $_SESSION[
"horaires$i"][$j] = $creneaux[1].
'-'.$creneaux[2];
91 $errheure[$i][$j] =
true;
94 } elseif (preg_match(
";^(\d{1,2}):(\d{2})$;", $tmphorairesi[$j], $heures)) {
96 if ($heures[1] < 24 && $heures[2] < 60) {
97 $_SESSION[
"horaires$i"][$j] = $heures[0];
99 $errheure[$i][$j] =
true;
102 } elseif (preg_match(
";^(\d{1,2})h(\d{0,2})$;i", $tmphorairesi[$j], $heures)) {
104 if ($heures[1] < 24 && $heures[2] < 60) {
105 $_SESSION[
"horaires$i"][$j] = $heures[0];
107 $errheure[$i][$j] =
true;
110 } elseif (preg_match(
";^(\d{1,2})-(\d{1,2})$;", $tmphorairesi[$j], $heures)) {
112 if ($heures[1] < $heures[2] && $heures[1] < 24 && $heures[2] < 24) {
113 $_SESSION[
"horaires$i"][$j] = $heures[0];
115 $errheure[$i][$j] =
true;
118 } elseif (preg_match(
";^(\d{1,2})h-(\d{1,2})h$;", $tmphorairesi[$j], $heures)) {
120 if ($heures[1] < $heures[2] && $heures[1] < 24 && $heures[2] < 24) {
121 $_SESSION[
"horaires$i"][$j] = $heures[0];
123 $errheure[$i][$j] =
true;
126 } elseif ($tmphorairesi[$j] ==
"") {
127 unset($_SESSION[
"horaires$i"][$j]);
129 $errheure[$i][$j] =
true;
133 if (issetAndNoEmpty(
'horaires'.$i, $_SESSION) ===
false || issetAndNoEmpty($j, $_SESSION[
'horaires'.$i]) ===
false) {
134 if (issetAndNoEmpty(
'horaires'.$i, $_SESSION) ===
true) {
135 $_SESSION[
"horaires$i"][$j] =
'';
137 $_SESSION[
"horaires$i"] = array();
138 $_SESSION[
"horaires$i"][$j] =
'';
143 if ($_SESSION[
"horaires$i"][0] ==
"" && $_SESSION[
"horaires$i"][1] ==
"" && $_SESSION[
"horaires$i"][2] ==
"" && $_SESSION[
"horaires$i"][3] ==
"" && $_SESSION[
"horaires$i"][4] ==
"") {
145 $choixdate .= $_SESSION[
"totalchoixjour"][$i];
147 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
148 if ($_SESSION[
"horaires$i"][$j] !=
"") {
150 $choixdate .= $_SESSION[
"totalchoixjour"][$i];
153 $choixdate .= str_replace(array(
',',
'@'), array(
',',
'@'), $_SESSION[
"horaires$i"][$j]);
159 if (!empty($errheure)) {
165 $tmphoraires0 =
GETPOST(
'horaires0',
'array');
166 if (count($_SESSION[
"totalchoixjour"]) ==
"1" && $tmphoraires0[0] ==
"" && $tmphoraires0[1] ==
"" && $tmphoraires0[2] ==
"" && $tmphoraires0[3] ==
"" && $tmphoraires0[4] ==
"") {
173 $_SESSION[
"toutchoix"] = substr(
"$choixdate", 1);
181 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
182 for ($i = 0; $i < $nbofchoice; $i++) {
183 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
184 unset($_SESSION[
"horaires$i"][$j]);
188 unset($_SESSION[
"totalchoixjour"]);
189 unset($_SESSION[
"nbrecaseshoraires"]);
198 if (!isset($_SESSION[
'description']) && !isset($_SESSION[
'mail'])) {
203 $arrayofjs = array();
204 $arrayofcss = array(
'/opensurvey/css/style.css');
205 llxHeader(
'', $langs->trans(
"OpenSurvey"),
"",
'', 0, 0, $arrayofjs, $arrayofcss);
208 if (!isset($_SESSION[
"nbrecaseshoraires"])) {
209 $_SESSION[
"nbrecaseshoraires"] = 5;
210 } elseif (
GETPOST(
'ajoutcases') && $_SESSION[
"nbrecaseshoraires"] == 5) {
211 $_SESSION[
"nbrecaseshoraires"] = 10;
217 $anneeAJ = date(
"Y");
220 if (!isset($_SESSION[
'jour'])) {
221 $_SESSION[
'jour'] = date(
'j');
223 if (!isset($_SESSION[
'mois'])) {
224 $_SESSION[
'mois'] = date(
'n');
226 if (!isset($_SESSION[
'annee'])) {
227 $_SESSION[
'annee'] = date(
'Y');
231 if (!issetAndNoEmpty(
'choixjourajout') && !issetAndNoEmpty(
'choixjourretrait') && (issetAndNoEmpty(
'retourmois') || issetAndNoEmpty(
'retourmois_x'))) {
232 $_SESSION[
"jour"] = date(
"j");
233 $_SESSION[
"mois"] = date(
"n");
234 $_SESSION[
"annee"] = date(
"Y");
238 if (issetAndNoEmpty(
'moisavant_x') || issetAndNoEmpty(
'moisavant')) {
239 if ($_SESSION[
"mois"] == 1) {
240 $_SESSION[
"mois"] = 12;
241 $_SESSION[
"annee"] = $_SESSION[
"annee"] - 1;
243 $_SESSION[
"mois"] -= 1;
247 if (issetAndNoEmpty(
'totalchoixjour', $_SESSION) ===
true) {
248 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
249 for ($i = 0; $i < $nbofchoice; $i++) {
251 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
252 $horairesi =
GETPOST(
"horaires".$i);
253 $_SESSION[
"horaires$i"][$j] = $horairesi[$j];
260 if (issetAndNoEmpty(
'moisapres_x') || issetAndNoEmpty(
'moisapres')) {
261 if ($_SESSION[
"mois"] == 12) {
262 $_SESSION[
"mois"] = 1;
263 $_SESSION[
"annee"] += 1;
265 $_SESSION[
"mois"] += 1;
269 if (issetAndNoEmpty(
'totalchoixjour', $_SESSION) ===
true) {
270 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
271 for ($i = 0; $i < $nbofchoice; $i++) {
273 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
274 $horairesi =
GETPOST(
"horaires".$i);
275 $_SESSION[
"horaires$i"][$j] = $horairesi[$j];
282 if (issetAndNoEmpty(
'anneeavant_x') || issetAndNoEmpty(
'anneeavant')) {
283 $_SESSION[
"annee"] -= 1;
286 if (issetAndNoEmpty(
'totalchoixjour', $_SESSION) ===
true) {
287 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
288 for ($i = 0; $i < $nbofchoice; $i++) {
290 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
291 $horairesi =
GETPOST(
"horaires".$i);
292 $_SESSION[
"horaires$i"][$j] = $horairesi[$j];
299 if (issetAndNoEmpty(
'anneeapres_x') || issetAndNoEmpty(
'anneeapres')) {
300 $_SESSION[
"annee"] += 1;
303 if (issetAndNoEmpty(
'totalchoixjour', $_SESSION) ===
true) {
304 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
305 for ($i = 0; $i < $nbofchoice; $i++) {
307 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
308 $horairesi =
GETPOST(
"horaires".$i);
309 $_SESSION[
"horaires$i"][$j] = $horairesi[$j];
316 $nbrejourmois = date(
"t", mktime(0, 0, 0, $_SESSION[
"mois"], 1, $_SESSION[
"annee"]));
317 $premierjourmois = date(
"N", mktime(0, 0, 0, $_SESSION[
"mois"], 1, $_SESSION[
"annee"])) - 1;
320 if (is_integer($_SESSION[
"mois"]) && $_SESSION[
"mois"] > 0 && $_SESSION[
"mois"] < 13) {
321 $motmois =
dol_print_date(mktime(0, 0, 0, $_SESSION[
"mois"], 10),
'%B');
328 print
'<form name="formulaire" action="" method="POST">'.
"\n";
329 print
'<input type="hidden" name="token" value="'.newToken().
'">';
334 print
'<div class="bodydate">'.
"\n";
335 print $langs->trans(
"OpenSurveyStep2").
"\n";
339 print
'<div class="corps">'.
"\n";
340 print
'<div class="center">'.
"\n";
341 print
'<table align="center">'.
"\n";
342 print
'<tr><td><input type="image" name="anneeavant" value="<<" src="../img/rewind.png"></td><td><input type="image" name="moisavant" value="<" src="../img/previous.png"></td>';
343 print
'<td width="150px" align="center"> '.$motmois.
' '.$_SESSION[
"annee"].
'<br>';
344 print
'<input type="image" name="retourmois" alt="'.dol_escape_htmltag($langs->trans(
"BackToCurrentMonth")).
'" title="'.
dol_escape_htmltag($langs->trans(
"BackToCurrentMonth")).
'" value="" src="'.
img_picto(
'',
'refresh',
'', 0, 1).
'">';
345 print
'</td><td><input type="image" name="moisapres" value=">" src="../img/next.png"></td>';
346 print
'<td><input type="image" name="anneeapres" value=">>" src="../img/fforward.png"></td><td></td><td></td><td></td><td></td><td></td><td>';
347 print
'</td></tr>'.
"\n";
348 print
'</table>'.
"\n";
351 print
'<div class="center calendrier">'.
"\n";
352 print
'<table align="center">'.
"\n";
356 for ($i = 0; $i < 7; $i++) {
357 print
'<td align="center" class="joursemaine">'.dol_print_date(mktime(0, 0, 0, 0, $i, 10),
'%A').
'</td>';
363 if (issetAndNoEmpty(
'choixjourajout')) {
364 if (!isset($_SESSION[
"totalchoixjour"])) {
365 $_SESSION[
"totalchoixjour"] = array();
370 if (issetAndNoEmpty(
'totalchoixjour', $_SESSION) ===
true && issetAndNoEmpty(
'choixjourajout') ===
true) {
371 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
372 for ($i = 0; $i < $nbofchoice; $i++) {
373 $choixjourajout =
GETPOST(
"choixjourajout");
374 if ($_SESSION[
"totalchoixjour"][$i] == mktime(0, 0, 0, $_SESSION[
"mois"], $choixjourajout[0], $_SESSION[
"annee"])) {
381 if ($journeuf && issetAndNoEmpty(
'choixjourajout') ===
true) {
382 $choixjourajout =
GETPOST(
"choixjourajout");
383 array_push($_SESSION[
"totalchoixjour"],
dol_mktime(0, 0, 0, $_SESSION[
"mois"], $choixjourajout[0], $_SESSION[
"annee"]));
384 sort($_SESSION[
"totalchoixjour"]);
385 $cle = array_search(
dol_mktime(0, 0, 0, $_SESSION[
"mois"], $choixjourajout[0], $_SESSION[
"annee"]), $_SESSION[
"totalchoixjour"]);
388 for ($i = 0; $i < $cle; $i++) {
389 $horairesi =
GETPOST(
"horaires".$i);
390 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
391 if (issetAndNoEmpty(
'horaires'.$i) ===
true && issetAndNoEmpty($i, $_POST[
'horaires'.$i]) ===
true) {
392 $_SESSION[
"horaires$i"][$j] = $horairesi[$j];
397 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
398 for ($i = $cle; $i < $nbofchoice; $i++) {
400 if (issetAndNoEmpty(
'horaires'.$i) ===
true && issetAndNoEmpty($i, $_POST[
'horaires'.$i]) ===
true) {
401 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
402 $horairesi =
GETPOST(
"horaires".$i);
403 $_SESSION[
"horaires$i"][$j] = $horairesi[$j];
408 unset($_SESSION[
"horaires$cle"]);
413 if (issetAndNoEmpty(
'choixjourretrait')) {
415 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
416 for ($i = 0; $i < $nbofchoice; $i++) {
418 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
419 $horairesi =
GETPOST(
"horaires".$i);
420 $_SESSION[
"horaires$i"][$j] = $horairesi[$j];
424 for ($i = 0; $i < $nbofchoice; $i++) {
425 $choixjourretrait =
GETPOST(
'choixjourretrait');
426 if ($_SESSION[
"totalchoixjour"][$i] == mktime(0, 0, 0, $_SESSION[
"mois"], $choixjourretrait[0], $_SESSION[
"annee"])) {
427 for ($j = $i; $j < $nbofchoice; $j++) {
429 $_SESSION[
"horaires$j"] = $_SESSION[
"horaires$k"];
432 array_splice($_SESSION[
"totalchoixjour"], $i, 1);
438 if (issetAndNoEmpty(
'reporterhoraires')) {
439 $_SESSION[
"horaires0"] =
GETPOST(
"horaires0");
440 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
441 for ($i = 0; $i < $nbofchoice; $i++) {
443 $_SESSION[
"horaires$j"] = $_SESSION[
"horaires$i"];
448 if (issetAndNoEmpty(
'resethoraires')) {
449 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
450 for ($i = 0; $i < $nbofchoice; $i++) {
451 unset($_SESSION[
"horaires$i"]);
458 for ($i = 0; $i < $nbrejourmois + $premierjourmois; $i++) {
459 $numerojour = $i - $premierjourmois + 1;
462 if (($i % 7) == 0 && $i != 0) {
463 print
'</tr><tr>'.
"\n";
467 if ($i < $premierjourmois) {
468 print
'<td class="avant"></td>'.
"\n";
470 if (issetAndNoEmpty(
'totalchoixjour', $_SESSION) ===
true) {
471 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
472 for ($j = 0; $j < $nbofchoice; $j++) {
474 if (date(
"j", $_SESSION[
"totalchoixjour"][$j]) == $numerojour && date(
"n", $_SESSION[
"totalchoixjour"][$j]) == $_SESSION[
"mois"] && date(
"Y", $_SESSION[
"totalchoixjour"][$j]) == $_SESSION[
"annee"]) {
475 print
'<td align="center" class="choisi"><input type="submit" class="bouton OFF" name="choixjourretrait[]" value="'.$numerojour.
'"></td>'.
"\n";
476 $dejafait = $numerojour;
482 if (isset($dejafait) ===
false || $dejafait != $numerojour) {
484 if (($numerojour >= $jourAJ && $_SESSION[
"mois"] == $moisAJ && $_SESSION[
"annee"] == $anneeAJ) || ($_SESSION[
"mois"] > $moisAJ && $_SESSION[
"annee"] == $anneeAJ) || $_SESSION[
"annee"] > $anneeAJ) {
485 print
'<td align="center" class="libre"><input type="submit" class="bouton ON" name="choixjourajout[]" value="'.$numerojour.
'"></td>'.
"\n";
488 print
'<td align="center" class="avant">'.$numerojour.
'</td>'.
"\n";
496 print
'</table>'.
"\n";
497 print
'</div></div>'.
"\n";
499 print
'<div class="bodydate"><div class="center">'.
"\n";
502 if (issetAndNoEmpty(
'totalchoixjour', $_SESSION) || $erreur) {
505 print
'<div align="left">';
506 print
'<strong>'.$langs->trans(
"SelectedDays").
':</strong>'.
"<br>\n";
507 print $langs->trans(
"SelectDayDesc").
"<br>\n";
510 print
'<table>'.
"\n";
512 print
'<td></td>'.
"\n";
514 for ($i = 0; $i < $_SESSION[
"nbrecaseshoraires"]; $i++) {
516 print
'<td classe="somme"><div class="center">'.$langs->trans(
"Time").
' '.$j.
'</div></td>'.
"\n";
519 if ($_SESSION[
"nbrecaseshoraires"] < 10) {
520 print
'<td classe="somme"><input type="image" name="ajoutcases" src="../img/add-16.png"></td>'.
"\n";
526 $nbofchoice = count($_SESSION[
"totalchoixjour"]);
528 for ($i = 0; $i < $nbofchoice; $i++) {
530 print
'<td>'.dol_print_date($_SESSION[
"totalchoixjour"][$i],
'daytext').
' ('.
dol_print_date($_SESSION[
"totalchoixjour"][$i],
'%A').
')</td>';
533 for ($j = 0; $j < $_SESSION[
"nbrecaseshoraires"]; $j++) {
535 if (isset($errheure[$i][$j]) && $errheure[$i][$j]) {
536 print
'<td><input type=text size="10" maxlength="11" name=horaires'.$i.
'[] value="'.$_SESSION[
"horaires$i"][$j].
'" style="background-color:#FF6666;"></td>'.
"\n";
539 print
'<td><input type=text size="10" maxlength="11" name=horaires'.$i.
'[] value="'.$_SESSION[
"horaires$i"][$j].
'"></td>'.
"\n";
545 print
'</table>'.
"\n";
548 print
'<table>'.
"\n";
550 print
'<td><input type="submit" class="button" name="reset" value="'.dol_escape_htmltag($langs->trans(
"RemoveAllDays")).
'"></td><td><input type="submit" class="button" name="reporterhoraires" value="'.
dol_escape_htmltag($langs->trans(
"CopyHoursOfFirstDay")).
'"></td><td><input type="submit" class="button" name="resethoraires" value="'.
dol_escape_htmltag($langs->trans(
"RemoveAllHours")).
'"></td></tr>'.
"\n";
551 print
'<tr><td colspan="3"><br><br></td></tr>'.
"\n";
552 print
'<tr><td colspan="3" align="center"><input type="submit" class="button" name="confirmation" value="'.$langs->trans(
"CreatePoll").
'"></td></tr>'.
"\n";
553 print
'</table>'.
"\n";
557 print
'</table>'.
"\n";
558 print
'<a name=bas></a>'.
"\n";
560 print
'</form>'.
"\n";
562 print
'<br><br><br><br>'.
"\n";
563 print
'</div></div>'.
"\n";