|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2013 Laurent Destailleur <[email protected]> |
|
4
|
|
|
* Copyright (C) 2014 Marcos García <[email protected]> |
|
5
|
|
|
* Copyright (C) 2024 MDW <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* \file htdocs/opensurvey/lib/opensurvey.lib.php |
|
23
|
|
|
* \ingroup opensurvey |
|
24
|
|
|
* \brief Functions for module |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
use Dolibarr\Lib\Images; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Returns an array with the tabs for the "Opensurvey poll" section |
|
31
|
|
|
* It loads tabs from modules looking for the entity Opensurveyso |
|
32
|
|
|
* |
|
33
|
|
|
* @param Opensurveysondage $object Current viewing poll |
|
34
|
|
|
* @return array Tabs for the opensurvey section |
|
35
|
|
|
*/ |
|
36
|
|
|
function opensurvey_prepare_head(Opensurveysondage $object) |
|
37
|
|
|
{ |
|
38
|
|
|
global $langs, $conf; |
|
39
|
|
|
|
|
40
|
|
|
$h = 0; |
|
41
|
|
|
$head = array(); |
|
42
|
|
|
|
|
43
|
|
|
$head[0][0] = 'card.php?id=' . $object->id_sondage; |
|
44
|
|
|
$head[0][1] = $langs->trans("Survey"); |
|
45
|
|
|
$head[0][2] = 'general'; |
|
46
|
|
|
$h++; |
|
47
|
|
|
|
|
48
|
|
|
$head[1][0] = 'results.php?id=' . $object->id_sondage; |
|
49
|
|
|
$head[1][1] = $langs->trans("SurveyResults"); |
|
50
|
|
|
$nbVotes = $object->countVotes(); |
|
51
|
|
|
if ($nbVotes > 0) { |
|
52
|
|
|
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($nbVotes) . '</span>'; |
|
53
|
|
|
} |
|
54
|
|
|
$head[1][2] = 'preview'; |
|
55
|
|
|
$h++; |
|
56
|
|
|
|
|
57
|
|
|
// Show more tabs from modules |
|
58
|
|
|
// Entries must be declared in modules descriptor with line |
|
59
|
|
|
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
60
|
|
|
// $this->tabs = array('entity:-tabname); to remove a tab |
|
61
|
|
|
complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll'); |
|
62
|
|
|
|
|
63
|
|
|
complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll', 'remove'); |
|
64
|
|
|
|
|
65
|
|
|
return $head; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Show header for new member |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $title Title |
|
72
|
|
|
* @param string $head Head array |
|
73
|
|
|
* @param int $disablejs More content into html header |
|
74
|
|
|
* @param int $disablehead More content into html header |
|
75
|
|
|
* @param array $arrayofjs Array of complementary js files |
|
76
|
|
|
* @param array $arrayofcss Array of complementary css files |
|
77
|
|
|
* @param string $numsondage Num survey |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
|
|
function llxHeaderSurvey($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [], $numsondage = '') |
|
81
|
|
|
{ |
|
82
|
|
|
global $conf, $langs, $mysoc; |
|
83
|
|
|
global $dolibarr_main_url_root; |
|
84
|
|
|
|
|
85
|
|
|
// $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>'; |
|
86
|
|
|
|
|
87
|
|
|
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers |
|
88
|
|
|
|
|
89
|
|
|
print '<body id="mainbody" class="publicnewmemberform">'; |
|
90
|
|
|
|
|
91
|
|
|
print '<span id="dolpaymentspan"></span>' . "\n"; |
|
92
|
|
|
print '<div class="center">' . "\n"; |
|
93
|
|
|
print '<form name="formulaire" action="studs.php?sondage=' . urlencode($numsondage) . '#bas" method="POST">' . "\n"; |
|
94
|
|
|
print '<input type="hidden" name="sondage" value="' . $numsondage . '"/>'; |
|
95
|
|
|
print '<input type="hidden" name="token" value="' . newToken() . '">' . "\n"; |
|
96
|
|
|
print "\n"; |
|
97
|
|
|
|
|
98
|
|
|
// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo) |
|
99
|
|
|
// Define logo and logosmall |
|
100
|
|
|
$logosmall = $mysoc->logo_small; |
|
101
|
|
|
$logo = $mysoc->logo; |
|
102
|
|
|
// print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n"; |
|
103
|
|
|
// Define urllogo |
|
104
|
|
|
$urllogo = ''; |
|
105
|
|
|
$urllogofull = ''; |
|
106
|
|
|
|
|
107
|
|
|
$width = 0; |
|
108
|
|
|
$urllogo = Images::getLogo($conf->theme, $width, $mysoc->logo_small, $mysoc->logo, true); |
|
109
|
|
|
|
|
110
|
|
|
// Output html code for logo |
|
111
|
|
|
if ($urllogo) { |
|
112
|
|
|
print '<div class="backgreypublicpayment">'; |
|
113
|
|
|
print '<div class="logopublicpayment">'; |
|
114
|
|
|
print '<img id="dolpaymentlogo" src="' . $urllogo . '"'; |
|
115
|
|
|
print '>'; |
|
116
|
|
|
print '</div>'; |
|
117
|
|
|
if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) { |
|
118
|
|
|
print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">' . $langs->trans("PoweredBy") . '<br><img src="' . constant('DOL_URL_ROOT') . '/theme/dolibarr_logo.svg" width="80px"></a></div>'; |
|
119
|
|
|
} |
|
120
|
|
|
print '</div>'; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
if (getDolGlobalString('OPENSURVEY_IMAGE_PUBLIC_INTERFACE')) { |
|
124
|
|
|
print '<div class="backimagepublicopensurvey">'; |
|
125
|
|
|
print '<img id="idOPENSURVEY_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString('OPENSURVEY_IMAGE_PUBLIC_INTERFACE') . '">'; |
|
126
|
|
|
print '</div>'; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
print '<div class="survey_borders"><br><br>'; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Show footer for new member |
|
134
|
|
|
* |
|
135
|
|
|
* @return void |
|
136
|
|
|
*/ |
|
137
|
|
|
function llxFooterSurvey() |
|
138
|
|
|
{ |
|
139
|
|
|
print '</div>'; |
|
140
|
|
|
print '</form>'; |
|
141
|
|
|
print '</div>'; |
|
142
|
|
|
|
|
143
|
|
|
printCommonFooter('public'); |
|
144
|
|
|
|
|
145
|
|
|
dol_htmloutput_events(); |
|
146
|
|
|
|
|
147
|
|
|
print "</body>\n"; |
|
148
|
|
|
print "</html>\n"; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* get_server_name |
|
154
|
|
|
* |
|
155
|
|
|
* @return string URL to use |
|
156
|
|
|
*/ |
|
157
|
|
|
function get_server_name() |
|
158
|
|
|
{ |
|
159
|
|
|
global $dolibarr_main_url_root; |
|
160
|
|
|
|
|
161
|
|
|
$urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root)); |
|
162
|
|
|
//$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
163
|
|
|
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
164
|
|
|
|
|
165
|
|
|
$url = $urlwithouturlroot . dol_buildpath('/opensurvey/', 1); |
|
166
|
|
|
|
|
167
|
|
|
if (!preg_match("|/$|", $url)) { |
|
168
|
|
|
$url = $url . "/"; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
return $url; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Fonction vérifiant l'existance et la valeur non vide d'une clé d'un tableau |
|
176
|
|
|
* |
|
177
|
|
|
* @param string $name Key to test |
|
178
|
|
|
* @param array $tableau Array in which searching key ($_POST by default) |
|
179
|
|
|
* @return bool True if key exists and return a non empty value |
|
180
|
|
|
*/ |
|
181
|
|
|
function issetAndNoEmpty($name, $tableau = null) |
|
182
|
|
|
{ |
|
183
|
|
|
if ($tableau === null) { |
|
184
|
|
|
$tableau = $_POST; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
return (isset($tableau[$name]) === true && empty($tableau[$name]) === false); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Fonction permettant de générer les URL pour les sondage |
|
193
|
|
|
* |
|
194
|
|
|
* @param string $id L'identifiant du sondage |
|
195
|
|
|
* @param bool $admin True pour générer une URL pour l'administration d'un sondage, False pour un URL publique |
|
196
|
|
|
* @return string L'url pour le sondage |
|
197
|
|
|
*/ |
|
198
|
|
|
function getUrlSondage($id, $admin = false) |
|
199
|
|
|
{ |
|
200
|
|
|
if ($admin === true) { |
|
201
|
|
|
$url = get_server_name() . 'results.php?id=' . $id; |
|
202
|
|
|
} else { |
|
203
|
|
|
$url = get_server_name() . '/public/studs.php?sondage=' . $id; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
return $url; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Generate a random id |
|
212
|
|
|
* |
|
213
|
|
|
* @param int $car Length of string to generate key |
|
214
|
|
|
* @return string |
|
215
|
|
|
*/ |
|
216
|
|
|
function dol_survey_random($car) |
|
217
|
|
|
{ |
|
218
|
|
|
$string = ""; |
|
219
|
|
|
$chaine = "abcdefghijklmnopqrstuvwxyz123456789"; |
|
220
|
|
|
mt_srand((int)((float)microtime() * 1000000)); |
|
221
|
|
|
for ($i = 0; $i < $car; $i++) { |
|
222
|
|
|
$string .= $chaine[mt_rand() % strlen($chaine)]; |
|
223
|
|
|
} |
|
224
|
|
|
return $string; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Add a poll |
|
229
|
|
|
* |
|
230
|
|
|
* @return void |
|
231
|
|
|
*/ |
|
232
|
|
|
function ajouter_sondage() |
|
233
|
|
|
{ |
|
234
|
|
|
global $db, $user; |
|
235
|
|
|
|
|
236
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/opensurvey/class/opensurveysondage.class.php'; |
|
237
|
|
|
|
|
238
|
|
|
$sondage = dol_survey_random(16); |
|
239
|
|
|
|
|
240
|
|
|
$allow_comments = empty($_SESSION['allow_comments']) ? 0 : 1; |
|
241
|
|
|
$allow_spy = empty($_SESSION['allow_spy']) ? 0 : 1; |
|
242
|
|
|
|
|
243
|
|
|
// Insert survey |
|
244
|
|
|
$opensurveysondage = new Opensurveysondage($db); |
|
245
|
|
|
$opensurveysondage->id_sondage = $sondage; |
|
246
|
|
|
$opensurveysondage->description = $_SESSION['description']; |
|
247
|
|
|
$opensurveysondage->mail_admin = $_SESSION['adresse']; |
|
248
|
|
|
$opensurveysondage->nom_admin = $_SESSION['nom']; |
|
249
|
|
|
$opensurveysondage->title = $_SESSION['title']; |
|
250
|
|
|
$opensurveysondage->date_fin = $_SESSION['champdatefin']; |
|
251
|
|
|
$opensurveysondage->format = $_SESSION['formatsondage']; |
|
252
|
|
|
$opensurveysondage->mailsonde = $_SESSION['mailsonde']; |
|
253
|
|
|
$opensurveysondage->allow_comments = $allow_comments; |
|
254
|
|
|
$opensurveysondage->allow_spy = $allow_spy; |
|
255
|
|
|
$opensurveysondage->sujet = $_SESSION['toutchoix']; |
|
256
|
|
|
|
|
257
|
|
|
$res = $opensurveysondage->create($user); |
|
258
|
|
|
|
|
259
|
|
|
if ($res < 0) { |
|
260
|
|
|
dol_print_error($db); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
unset($_SESSION["title"]); |
|
264
|
|
|
unset($_SESSION["nom"]); |
|
265
|
|
|
unset($_SESSION["adresse"]); |
|
266
|
|
|
unset($_SESSION["description"]); |
|
267
|
|
|
unset($_SESSION["mailsonde"]); |
|
268
|
|
|
unset($_SESSION['allow_comments']); |
|
269
|
|
|
unset($_SESSION['allow_spy']); |
|
270
|
|
|
unset($_SESSION['toutchoix']); |
|
271
|
|
|
unset($_SESSION['totalchoixjour']); |
|
272
|
|
|
unset($_SESSION['champdatefin']); |
|
273
|
|
|
|
|
274
|
|
|
$urlback = dol_buildpath('/opensurvey/card.php', 1) . '?id=' . $sondage; |
|
275
|
|
|
|
|
276
|
|
|
header("Location: " . $urlback); |
|
277
|
|
|
exit(); |
|
278
|
|
|
} |
|
279
|
|
|
|