dolibarr  13.0.2
fonctions.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  *
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 
33 {
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  $head[1][2] = 'preview';
48  $h++;
49 
50  // Show more tabs from modules
51  // Entries must be declared in modules descriptor with line
52  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
53  // $this->tabs = array('entity:-tabname); to remove a tab
54  complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll');
55 
56  complete_head_from_modules($conf, $langs, $object, $head, $h, 'opensurveypoll', 'remove');
57 
58  return $head;
59 }
60 
73 function llxHeaderSurvey($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $numsondage = '')
74 {
75  global $conf, $langs, $mysoc;
76  global $dolibarr_main_url_root;
77 
78  //$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
79 
80  top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
81 
82  print '<body id="mainbody" class="publicnewmemberform">';
83 
84  print '<span id="dolpaymentspan"></span>'."\n";
85  print '<div class="center">'."\n";
86  print '<form name="formulaire" action="studs.php?sondage='.urlencode($numsondage).'#bas" method="POST">'."\n";
87  print '<input type="hidden" name="sondage" value="'.$numsondage.'"/>';
88  print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
89  print "\n";
90 
91  // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
92  // Define logo and logosmall
93  $logosmall = $mysoc->logo_small;
94  $logo = $mysoc->logo;
95  //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
96  // Define urllogo
97  $urllogo = '';
98  $urllogofull = '';
99  if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall))
100  {
101  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
102  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
103  } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo))
104  {
105  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
106  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
107  }
108 
109  // Output html code for logo
110  if ($urllogo)
111  {
112  print '<div class="backgreypublicpayment">';
113  print '<div class="logopublicpayment">';
114  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
115  print '>';
116  print '</div>';
117  if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
118  print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref?utm_medium=website&utm_source=poweredby" href="https://www.dolibarr.org" 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  print '<div style="margin-left: 50px; margin-right: 50px; text-align: start;"><br>';
124 }
125 
131 function llxFooterSurvey()
132 {
133  print '</div>';
134  print '</form>';
135  print '</div>';
136 
137  printCommonFooter('public');
138 
140 
141  print "</body>\n";
142  print "</html>\n";
143 }
144 
145 
151 function get_server_name()
152 {
153  global $dolibarr_main_url_root;
154 
155  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
156  //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
157  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
158 
159  $url = $urlwithouturlroot.dol_buildpath('/opensurvey/', 1);
160 
161  if (!preg_match("|/$|", $url)) {
162  $url = $url."/";
163  }
164 
165  return $url;
166 }
167 
175 function issetAndNoEmpty($name, $tableau = null)
176 {
177  if ($tableau === null) {
178  $tableau = $_POST;
179  }
180 
181  return (isset($tableau[$name]) === true && empty($tableau[$name]) === false);
182 }
183 
184 
192 function getUrlSondage($id, $admin = false)
193 {
194  if ($admin === true) {
195  $url = get_server_name().'results.php?id='.$id;
196  } else {
197  $url = get_server_name().'/public/studs.php?sondage='.$id;
198  }
199 
200  return $url;
201 }
202 
203 
210 function dol_survey_random($car)
211 {
212  $string = "";
213  $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
214  mt_srand((double) microtime() * 1000000);
215  for ($i = 0; $i < $car; $i++) {
216  $string .= $chaine[mt_rand() % strlen($chaine)];
217  }
218  return $string;
219 }
220 
226 function ajouter_sondage()
227 {
228  global $db, $user;
229 
230  require_once DOL_DOCUMENT_ROOT.'/opensurvey/class/opensurveysondage.class.php';
231 
232  $sondage = dol_survey_random(16);
233 
234  $allow_comments = empty($_SESSION['allow_comments']) ? 0 : 1;
235  $allow_spy = empty($_SESSION['allow_spy']) ? 0 : 1;
236 
237  // Insert survey
238  $opensurveysondage = new Opensurveysondage($db);
239  $opensurveysondage->id_sondage = $sondage;
240  $opensurveysondage->description = $_SESSION['description'];
241  $opensurveysondage->mail_admin = $_SESSION['adresse'];
242  $opensurveysondage->nom_admin = $_SESSION['nom'];
243  $opensurveysondage->title = $_SESSION['title'];
244  $opensurveysondage->date_fin = $_SESSION['champdatefin'];
245  $opensurveysondage->format = $_SESSION['formatsondage'];
246  $opensurveysondage->mailsonde = $_SESSION['mailsonde'];
247  $opensurveysondage->allow_comments = $allow_comments;
248  $opensurveysondage->allow_spy = $allow_spy;
249  $opensurveysondage->sujet = $_SESSION['toutchoix'];
250 
251  $res = $opensurveysondage->create($user);
252 
253  if ($res < 0) {
254  dol_print_error($db);
255  }
256 
257  unset($_SESSION["title"]);
258  unset($_SESSION["nom"]);
259  unset($_SESSION["adresse"]);
260  unset($_SESSION["description"]);
261  unset($_SESSION["mailsonde"]);
262  unset($_SESSION['allow_comments']);
263  unset($_SESSION['allow_spy']);
264  unset($_SESSION['toutchoix']);
265  unset($_SESSION['totalchoixjour']);
266  unset($_SESSION['champdatefin']);
267 
268  $urlback = dol_buildpath('/opensurvey/card.php', 1).'?id='.$sondage;
269 
270  header("Location: ".$urlback);
271  exit();
272 }
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
printCommonFooter($zone= 'private')
Print common footer : conf-&gt;global-&gt;MAIN_HTML_FOOTER js for switch of menu hider js for conf-&gt;global-...
get_server_name()
get_server_name
Definition: fonctions.php:151
getUrlSondage($id, $admin=false)
Fonction permettant de générer les URL pour les sondage.
Definition: fonctions.php:192
top_htmlhead($head, $title= '', $disablejs=0, $disablehead=0, $arrayofjs= '', $arrayofcss= '', $disablejmobile=0, $disablenofollow=0)
Ouput html header of a page.
Definition: main.inc.php:1280
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
llxFooterSurvey()
Show footer for new member.
Definition: fonctions.php:131
issetAndNoEmpty($name, $tableau=null)
Fonction vérifiant l&#39;existance et la valeur non vide d&#39;une clé d&#39;un tableau.
Definition: fonctions.php:175
dol_survey_random($car)
Generate a random id.
Definition: fonctions.php:210
Put here description of your class.
opensurvey_prepare_head(Opensurveysondage $object)
Returns an array with the tabs for the &quot;Opensurvey poll&quot; section It loads tabs from modules looking f...
Definition: fonctions.php:32
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
ajouter_sondage()
Add a poll.
Definition: fonctions.php:226
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
llxHeaderSurvey($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs= '', $arrayofcss= '', $numsondage= '')
Show header for new member.
Definition: fonctions.php:73