dolibarr 19.0.3
opensurvey.lib.php
1<?php
2/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Marcos GarcĂ­a <marcosgdf@gmail.com>
4 *
5* This program is free software; you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation; either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
32function opensurvey_prepare_head(Opensurveysondage $object)
33{
34 global $langs, $conf;
35
36 $h = 0;
37 $head = array();
38
39 $head[0][0] = 'card.php?id='.$object->id_sondage;
40 $head[0][1] = $langs->trans("Survey");
41 $head[0][2] = 'general';
42 $h++;
43
44 $head[1][0] = 'results.php?id='.$object->id_sondage;
45 $head[1][1] = $langs->trans("SurveyResults");
46 $nbVotes = $object->countVotes();
47 if ($nbVotes > 0) {
48 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbVotes).'</span>';
49 }
50 $head[1][2] = 'preview';
51 $h++;
52
53 // Show more tabs from modules
54 // Entries must be declared in modules descriptor with line
55 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
56 // $this->tabs = array('entity:-tabname); to remove a tab
57 complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll');
58
59 complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll', 'remove');
60
61 return $head;
62}
63
76function llxHeaderSurvey($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $numsondage = '')
77{
78 global $conf, $langs, $mysoc;
79 global $dolibarr_main_url_root;
80
81 //$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
82
83 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
84
85 print '<body id="mainbody" class="publicnewmemberform">';
86
87 print '<span id="dolpaymentspan"></span>'."\n";
88 print '<div class="center">'."\n";
89 print '<form name="formulaire" action="studs.php?sondage='.urlencode($numsondage).'#bas" method="POST">'."\n";
90 print '<input type="hidden" name="sondage" value="'.$numsondage.'"/>';
91 print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
92 print "\n";
93
94 // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
95 // Define logo and logosmall
96 $logosmall = $mysoc->logo_small;
97 $logo = $mysoc->logo;
98 //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
99 // Define urllogo
100 $urllogo = '';
101 $urllogofull = '';
102 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
103 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
104 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
105 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
106 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
107 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
108 }
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="'.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
137function llxFooterSurvey()
138{
139 print '</div>';
140 print '</form>';
141 print '</div>';
142
143 printCommonFooter('public');
144
146
147 print "</body>\n";
148 print "</html>\n";
149}
150
151
157function 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
181function 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
198function 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
216function dol_survey_random($car)
217{
218 $string = "";
219 $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
220 mt_srand((float) microtime() * 1000000);
221 for ($i = 0; $i < $car; $i++) {
222 $string .= $chaine[mt_rand() % strlen($chaine)];
223 }
224 return $string;
225}
226
232function ajouter_sondage()
233{
234 global $db, $user;
235
236 require_once 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}
Put here description of your class.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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 formated messages to output (Used to show messages on html output).
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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 dolibarr global constant string value.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.