dolibarr  20.0.0-alpha
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  *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19 
34 {
35  global $langs, $conf;
36 
37  $h = 0;
38  $head = array();
39 
40  $head[0][0] = 'card.php?id='.$object->id_sondage;
41  $head[0][1] = $langs->trans("Survey");
42  $head[0][2] = 'general';
43  $h++;
44 
45  $head[1][0] = 'results.php?id='.$object->id_sondage;
46  $head[1][1] = $langs->trans("SurveyResults");
47  $nbVotes = $object->countVotes();
48  if ($nbVotes > 0) {
49  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbVotes).'</span>';
50  }
51  $head[1][2] = 'preview';
52  $h++;
53 
54  // Show more tabs from modules
55  // Entries must be declared in modules descriptor with line
56  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
57  // $this->tabs = array('entity:-tabname); to remove a tab
58  complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll');
59 
60  complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll', 'remove');
61 
62  return $head;
63 }
64 
77 function llxHeaderSurvey($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [], $numsondage = '')
78 {
79  global $conf, $langs, $mysoc;
80  global $dolibarr_main_url_root;
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  print '<span id="dolpaymentspan"></span>'."\n";
89  print '<div class="center">'."\n";
90  print '<form name="formulaire" action="studs.php?sondage='.urlencode($numsondage).'#bas" method="POST">'."\n";
91  print '<input type="hidden" name="sondage" value="'.$numsondage.'"/>';
92  print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
93  print "\n";
94 
95  // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
96  // Define logo and logosmall
97  $logosmall = $mysoc->logo_small;
98  $logo = $mysoc->logo;
99  // print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
100  // Define urllogo
101  $urllogo = '';
102  $urllogofull = '';
103  if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
104  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
105  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
106  } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
107  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
108  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
109  }
110 
111  // Output html code for logo
112  if ($urllogo) {
113  print '<div class="backgreypublicpayment">';
114  print '<div class="logopublicpayment">';
115  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
116  print '>';
117  print '</div>';
118  if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
119  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>';
120  }
121  print '</div>';
122  }
123 
124  if (getDolGlobalString('OPENSURVEY_IMAGE_PUBLIC_INTERFACE')) {
125  print '<div class="backimagepublicopensurvey">';
126  print '<img id="idOPENSURVEY_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString('OPENSURVEY_IMAGE_PUBLIC_INTERFACE').'">';
127  print '</div>';
128  }
129 
130  print '<div class="survey_borders"><br><br>';
131 }
132 
138 function llxFooterSurvey()
139 {
140  print '</div>';
141  print '</form>';
142  print '</div>';
143 
144  printCommonFooter('public');
145 
147 
148  print "</body>\n";
149  print "</html>\n";
150 }
151 
152 
158 function get_server_name()
159 {
160  global $dolibarr_main_url_root;
161 
162  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
163  //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
164  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
165 
166  $url = $urlwithouturlroot.dol_buildpath('/opensurvey/', 1);
167 
168  if (!preg_match("|/$|", $url)) {
169  $url = $url."/";
170  }
171 
172  return $url;
173 }
174 
182 function issetAndNoEmpty($name, $tableau = null)
183 {
184  if ($tableau === null) {
185  $tableau = $_POST;
186  }
187 
188  return (isset($tableau[$name]) === true && empty($tableau[$name]) === false);
189 }
190 
191 
199 function getUrlSondage($id, $admin = false)
200 {
201  if ($admin === true) {
202  $url = get_server_name().'results.php?id='.$id;
203  } else {
204  $url = get_server_name().'/public/studs.php?sondage='.$id;
205  }
206 
207  return $url;
208 }
209 
210 
217 function dol_survey_random($car)
218 {
219  $string = "";
220  $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
221  mt_srand((int) ((float) microtime() * 1000000));
222  for ($i = 0; $i < $car; $i++) {
223  $string .= $chaine[mt_rand() % strlen($chaine)];
224  }
225  return $string;
226 }
227 
233 function ajouter_sondage()
234 {
235  global $db, $user;
236 
237  require_once DOL_DOCUMENT_ROOT.'/opensurvey/class/opensurveysondage.class.php';
238 
239  $sondage = dol_survey_random(16);
240 
241  $allow_comments = empty($_SESSION['allow_comments']) ? 0 : 1;
242  $allow_spy = empty($_SESSION['allow_spy']) ? 0 : 1;
243 
244  // Insert survey
245  $opensurveysondage = new Opensurveysondage($db);
246  $opensurveysondage->id_sondage = $sondage;
247  $opensurveysondage->description = $_SESSION['description'];
248  $opensurveysondage->mail_admin = $_SESSION['adresse'];
249  $opensurveysondage->nom_admin = $_SESSION['nom'];
250  $opensurveysondage->title = $_SESSION['title'];
251  $opensurveysondage->date_fin = $_SESSION['champdatefin'];
252  $opensurveysondage->format = $_SESSION['formatsondage'];
253  $opensurveysondage->mailsonde = $_SESSION['mailsonde'];
254  $opensurveysondage->allow_comments = $allow_comments;
255  $opensurveysondage->allow_spy = $allow_spy;
256  $opensurveysondage->sujet = $_SESSION['toutchoix'];
257 
258  $res = $opensurveysondage->create($user);
259 
260  if ($res < 0) {
261  dol_print_error($db);
262  }
263 
264  unset($_SESSION["title"]);
265  unset($_SESSION["nom"]);
266  unset($_SESSION["adresse"]);
267  unset($_SESSION["description"]);
268  unset($_SESSION["mailsonde"]);
269  unset($_SESSION['allow_comments']);
270  unset($_SESSION['allow_spy']);
271  unset($_SESSION['toutchoix']);
272  unset($_SESSION['totalchoixjour']);
273  unset($_SESSION['champdatefin']);
274 
275  $urlback = dol_buildpath('/opensurvey/card.php', 1).'?id='.$sondage;
276 
277  header("Location: ".$urlback);
278  exit();
279 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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 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.
Definition: main.inc.php:1749
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.