dolibarr 21.0.0-beta
opensurvey.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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
35{
36 global $langs, $conf;
37
38 $h = 0;
39 $head = array();
40
41 $head[0][0] = 'card.php?id='.$object->id_sondage;
42 $head[0][1] = $langs->trans("Survey");
43 $head[0][2] = 'general';
44 $h++;
45
46 $head[1][0] = 'results.php?id='.$object->id_sondage;
47 $head[1][1] = $langs->trans("SurveyResults");
48 $nbVotes = $object->countVotes();
49 if ($nbVotes > 0) {
50 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbVotes).'</span>';
51 }
52 $head[1][2] = 'preview';
53 $h++;
54
55 // Show more tabs from modules
56 // Entries must be declared in modules descriptor with line
57 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
58 // $this->tabs = array('entity:-tabname); to remove a tab
59 complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll');
60
61 complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll', 'remove');
62
63 return $head;
64}
65
78function llxHeaderSurvey($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [], $numsondage = '')
79{
80 global $conf, $langs, $mysoc;
81 global $dolibarr_main_url_root;
82
83 // $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
84
85 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
86
87 print '<body id="mainbody" class="publicnewmemberform">';
88
89 print '<span id="dolpaymentspan"></span>'."\n";
90 print '<div class="center">'."\n";
91 print '<form name="formulaire" action="studs.php?sondage='.urlencode($numsondage).'#bas" method="POST">'."\n";
92 print '<input type="hidden" name="sondage" value="'.$numsondage.'"/>';
93 print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
94 print "\n";
95
96 // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
97 // Define logo and logosmall
98 $logosmall = $mysoc->logo_small;
99 $logo = $mysoc->logo;
100 // print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
101 // Define urllogo
102 $urllogo = '';
103 $urllogofull = '';
104 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
105 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
106 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
107 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
108 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
109 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
110 }
111
112 // Output html code for logo
113 if ($urllogo) {
114 print '<div class="backgreypublicpayment">';
115 print '<div class="logopublicpayment">';
116 print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
117 print '>';
118 print '</div>';
119 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
120 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="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
121 }
122 print '</div>';
123 }
124
125 if (getDolGlobalString('OPENSURVEY_IMAGE_PUBLIC_INTERFACE')) {
126 print '<div class="backimagepublicopensurvey">';
127 print '<img id="idOPENSURVEY_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString('OPENSURVEY_IMAGE_PUBLIC_INTERFACE').'">';
128 print '</div>';
129 }
130
131 print '<div class="survey_borders"><br><br>';
132}
133
140{
141 print '</div>';
142 print '</form>';
143 print '</div>';
144
145 printCommonFooter('public');
146
148
149 print "</body>\n";
150 print "</html>\n";
151}
152
153
160{
161 global $dolibarr_main_url_root;
162
163 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
164 //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
165 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
166
167 $url = $urlwithouturlroot.dol_buildpath('/opensurvey/', 1);
168
169 if (!preg_match("|/$|", $url)) {
170 $url .= "/";
171 }
172
173 return $url;
174}
175
183function issetAndNoEmpty($name, $tableau = null)
184{
185 if ($tableau === null) {
186 $tableau = $_POST;
187 }
188
189 return (isset($tableau[$name]) && !empty($tableau[$name]));
190}
191
192
200function getUrlSondage($id, $admin = false)
201{
202 if ($admin === true) {
203 $url = get_server_name().'results.php?id='.$id;
204 } else {
205 $url = get_server_name().'/public/studs.php?sondage='.$id;
206 }
207
208 return $url;
209}
210
211
218function dol_survey_random($car)
219{
220 $string = "";
221 $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
222 mt_srand((int) ((float) microtime() * 1000000));
223 for ($i = 0; $i < $car; $i++) {
224 $string .= $chaine[mt_rand() % strlen($chaine)];
225 }
226 return $string;
227}
228
235{
236 global $db, $user;
237
238 require_once DOL_DOCUMENT_ROOT.'/opensurvey/class/opensurveysondage.class.php';
239
240 $sondage = dol_survey_random(16);
241
242 $allow_comments = empty($_SESSION['allow_comments']) ? 0 : 1;
243 $allow_spy = empty($_SESSION['allow_spy']) ? 0 : 1;
244
245 // Insert survey
246 $opensurveysondage = new Opensurveysondage($db);
247 $opensurveysondage->id_sondage = $sondage;
248 $opensurveysondage->description = $_SESSION['description'];
249 $opensurveysondage->mail_admin = $_SESSION['adresse'];
250 $opensurveysondage->nom_admin = $_SESSION['nom'];
251 $opensurveysondage->title = $_SESSION['title'];
252 $opensurveysondage->date_fin = $_SESSION['champdatefin'];
253 $opensurveysondage->format = $_SESSION['formatsondage'];
254 $opensurveysondage->mailsonde = $_SESSION['mailsonde'];
255 $opensurveysondage->allow_comments = $allow_comments;
256 $opensurveysondage->allow_spy = $allow_spy;
257 $opensurveysondage->sujet = $_SESSION['toutchoix'];
258
259 $res = $opensurveysondage->create($user);
260
261 if ($res < 0) {
262 dol_print_error($db);
263 }
264
265 unset($_SESSION["title"]);
266 unset($_SESSION["nom"]);
267 unset($_SESSION["adresse"]);
268 unset($_SESSION["description"]);
269 unset($_SESSION["mailsonde"]);
270 unset($_SESSION['allow_comments']);
271 unset($_SESSION['allow_spy']);
272 unset($_SESSION['toutchoix']);
273 unset($_SESSION['totalchoixjour']);
274 unset($_SESSION['champdatefin']);
275
276 $urlback = dol_buildpath('/opensurvey/card.php', 1).'?id='.$sondage;
277
278 header("Location: ".$urlback);
279 exit();
280}
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Put here description of your class.
printCommonFooter($zone='private')
Print common footer : conf->global->MAIN_HTML_FOOTER js for switch of menu hider js for conf->global-...
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
llxFooterSurvey()
Show footer for new member.
get_server_name()
get_server_name
opensurvey_prepare_head(Opensurveysondage $object)
Returns an array with the tabs for the "Opensurvey poll" section It loads tabs from modules looking f...
getUrlSondage($id, $admin=false)
Fonction permettant de générer les URL pour les sondage.
llxHeaderSurvey($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[], $numsondage='')
Show header for new member.
dol_survey_random($car)
Generate a random id.
issetAndNoEmpty($name, $tableau=null)
Fonction vérifiant l'existance et la valeur non vide d'une clé d'un tableau.
ajouter_sondage()
Add a poll.