dolibarr 22.0.5
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 $langs, $mysoc;
81
82 // $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
83
84 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
85
86 print '<body id="mainbody" class="publicnewmemberform">';
87
88 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
89 htmlPrintOnlineHeader($mysoc, $langs, 'OPENSURVEY_IMAGE_PUBLIC_INTERFACE');
90
91 print '<span id="dolpaymentspan"></span>'."\n";
92 print '<div class="center">'."\n";
93
94 print '<form name="formulaire" action="studs.php?sondage='.urlencode($numsondage).'#bas" method="POST">'."\n";
95 print '<input type="hidden" name="sondage" value="'.$numsondage.'"/>';
96 print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
97 print "\n";
98
99 print '<div class="survey_borders"><br><br>';
100}
101
108{
109 print '</div>';
110 print '</form>';
111 print '</div>';
112
113 printCommonFooter('public');
114
116
117 print "</body>\n";
118 print "</html>\n";
119}
120
121
128{
130
131 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
132 //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
133 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
134
135 $url = $urlwithouturlroot.dol_buildpath('/opensurvey/', 1);
136
137 if (!preg_match("|/$|", $url)) {
138 $url .= "/";
139 }
140
141 return $url;
142}
143
151function issetAndNoEmpty($name, $tableau = null)
152{
153 if ($tableau === null) {
154 $tableau = $_POST;
155 }
156
157 return (isset($tableau[$name]) && !empty($tableau[$name]));
158}
159
160
168function getUrlSondage($id, $admin = false)
169{
170 if ($admin === true) {
171 $url = get_server_name().'results.php?id='.$id;
172 } else {
173 $url = get_server_name().'/public/studs.php?sondage='.$id;
174 }
175
176 return $url;
177}
178
179
186function dol_survey_random($car)
187{
188 $string = "";
189 $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
190 mt_srand((int) ((float) microtime() * 1000000));
191 for ($i = 0; $i < $car; $i++) {
192 $string .= $chaine[mt_rand() % strlen($chaine)];
193 }
194 return $string;
195}
196
203{
204 global $db, $user;
205
206 require_once DOL_DOCUMENT_ROOT.'/opensurvey/class/opensurveysondage.class.php';
207
208 $sondage = dol_survey_random(16);
209
210 $allow_comments = empty($_SESSION['allow_comments']) ? 0 : 1;
211 $allow_spy = empty($_SESSION['allow_spy']) ? 0 : 1;
212
213 // Insert survey
214 $opensurveysondage = new Opensurveysondage($db);
215 $opensurveysondage->id_sondage = $sondage;
216 $opensurveysondage->description = $_SESSION['description'];
217 $opensurveysondage->mail_admin = $_SESSION['adresse'];
218 $opensurveysondage->nom_admin = $_SESSION['nom'];
219 $opensurveysondage->title = $_SESSION['title'];
220 $opensurveysondage->date_fin = $_SESSION['champdatefin'];
221 $opensurveysondage->format = $_SESSION['formatsondage'];
222 $opensurveysondage->mailsonde = $_SESSION['mailsonde'];
223 $opensurveysondage->allow_comments = $allow_comments;
224 $opensurveysondage->allow_spy = $allow_spy;
225 $opensurveysondage->sujet = $_SESSION['toutchoix'];
226
227 $res = $opensurveysondage->create($user);
228
229 if ($res < 0) {
230 dol_print_error($db);
231 }
232
233 unset($_SESSION["title"]);
234 unset($_SESSION["nom"]);
235 unset($_SESSION["adresse"]);
236 unset($_SESSION["description"]);
237 unset($_SESSION["mailsonde"]);
238 unset($_SESSION['allow_comments']);
239 unset($_SESSION['allow_spy']);
240 unset($_SESSION['toutchoix']);
241 unset($_SESSION['totalchoixjour']);
242 unset($_SESSION['champdatefin']);
243
244 $urlback = dol_buildpath('/opensurvey/card.php', 1).'?id='.$sondage;
245
246 header("Location: ".$urlback);
247 exit();
248}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
global $dolibarr_main_url_root
Put here description of your class.
htmlPrintOnlineHeader($mysoc, $langs, $showlogo=1, $alttext='', $subimageconst='', $altlogo1='', $altlogo2='')
Show the header of a company in HTML public pages.
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).
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.