dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
4  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
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 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
28 require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
29 require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php";
30 require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
31 require_once DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php";
32 
33 
34 // Security check
35 if (!$user->rights->opensurvey->read) accessforbidden();
36 
37 // Initialisation des variables
38 $action = GETPOST('action', 'aZ09');
39 $cancel = GETPOST('cancel', 'alpha');
40 
41 $numsondage = '';
42 
43 if (GETPOST('id')) {
44  $numsondage = (string) GETPOST('id', 'alpha');
45 }
46 
47 $object = new Opensurveysondage($db);
48 
49 $result = $object->fetch(0, $numsondage);
50 if ($result <= 0) {
51  dol_print_error($db, $object->error);
52  exit;
53 }
54 
55 $expiredate = dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GETPOST('expireyear'));
56 
57 
58 
59 /*
60  * Actions
61  */
62 
63 $parameters = array('id' => $numsondage);
64 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
65 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
66 
67 if (empty($reshook))
68 {
69  if ($cancel) $action = '';
70 
71  // Delete
72  if ($action == 'delete_confirm')
73  {
74  // Security check
75  if (!$user->rights->opensurvey->write) accessforbidden();
76 
77  $result = $object->delete($user, '', $numsondage);
78 
79  header('Location: '.dol_buildpath('/opensurvey/list.php', 1));
80  exit();
81  }
82 
83  // Close
84  if ($action == 'close')
85  {
86  $object->status = Opensurveysondage::STATUS_CLOSED;
87  $object->update($user);
88  }
89 
90  // Reopend
91  if ($action == 'reopen')
92  {
93  $object->status = Opensurveysondage::STATUS_VALIDATED;
94  $object->update($user);
95  }
96 
97  // Update
98  if ($action == 'update')
99  {
100  // Security check
101  if (!$user->rights->opensurvey->write) accessforbidden();
102 
103  $error = 0;
104 
105  if (!GETPOST('nouveautitre'))
106  {
107  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors');
108  $error++;
109  $action = 'edit';
110  }
111 
112  if (!$error)
113  {
114  $object->title = (string) GETPOST('nouveautitre', 'alphanohtml');
115  $object->description = (string) GETPOST('nouveauxcommentaires', 'restricthtml');
116  $object->mail_admin = (string) GETPOST('nouvelleadresse', 'alpha');
117  $object->date_fin = $expiredate;
118  $object->allow_comments = GETPOST('cancomment', 'aZ09') == 'on' ? 1 : 0;
119  $object->allow_spy = GETPOST('canseeothersvote', 'aZ09') == 'on' ? 1 : 0;
120  $object->mailsonde = GETPOST('mailsonde', 'aZ09') == 'on' ? 1 : 0;
121 
122  $res = $object->update($user);
123  if ($res < 0) {
124  setEventMessages($object->error, $object->errors, 'errors');
125  $action = 'edit';
126  }
127  }
128  }
129 
130  // Add comment
131  if (GETPOST('ajoutcomment'))
132  {
133  $error = 0;
134 
135  if (!GETPOST('comment')) {
136  $error++;
137  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
138  }
139  if (!GETPOST('commentuser')) {
140  $error++;
141  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors');
142  }
143 
144  if (!$error) {
145  $comment = (string) GETPOST("comment", "restricthtml");
146  $comment_user = (string) GETPOST('commentuser', "restricthtml");
147 
148  $resql = $object->addComment($comment, $comment_user);
149 
150  if (!$resql)
151  {
152  setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors');
153  }
154  }
155  }
156 
157  // Delete comment
158  $idcomment = GETPOST('deletecomment', 'int');
159  if ($idcomment)
160  {
161  // Security check
162  if (!$user->rights->opensurvey->write) accessforbidden();
163 
164  $resql = $object->deleteComment($idcomment);
165  }
166 
167  if ($action == 'edit') {
168  // Security check
169  if (!$user->rights->opensurvey->write) accessforbidden();
170  }
171 }
172 
173 
174 /*
175  * View
176  */
177 
178 $form = new Form($db);
179 
180 if ($object->fk_user_creat)
181 {
182  $userstatic = new User($db);
183  $userstatic->fetch($object->fk_user_creat);
184 }
185 
186 $title = $object->title." - ".$langs->trans('Card');
187 $helpurl = '';
188 $arrayofjs = array();
189 $arrayofcss = array('/opensurvey/css/style.css');
190 llxHeader('', $title, $helpurl, 0, 0, 0, $arrayofjs, $arrayofcss);
191 
192 
193 // Define format of choices
194 $toutsujet = explode(",", $object->sujet);
195 $listofanswers = array();
196 foreach ($toutsujet as $value)
197 {
198  $tmp = explode('@', $value);
199  $listofanswers[] = array('label'=>$tmp[0], 'format'=>($tmp[1] ? $tmp[1] : 'checkbox'));
200 }
201 $toutsujet = str_replace("@", "<br>", $toutsujet);
202 $toutsujet = str_replace("°", "'", $toutsujet);
203 
204 print '<form name="updatesurvey" action="'.$_SERVER["PHP_SELF"].'?id='.$numsondage.'" method="POST">'."\n";
205 print '<input type="hidden" name="token" value="'.newToken().'">';
206 print '<input type="hidden" name="action" value="update">';
207 
208 $head = opensurvey_prepare_head($object);
209 
210 
211 print dol_get_fiche_head($head, 'general', $langs->trans("Survey"), -1, 'poll');
212 
213 $morehtmlref = '';
214 
215 $linkback = '<a href="'.DOL_URL_ROOT.'/opensurvey/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
216 
217 dol_banner_tab($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage', $morehtmlref);
218 
219 
220 print '<div class="fichecenter">';
221 print '<div class="underbanner clearboth"></div>';
222 
223 print '<table class="border tableforfield centpercent">';
224 
225 // Type
226 $type = ($object->format == "A") ? 'classic' : 'date';
227 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td colspan="2">';
228 print img_picto('', dol_buildpath('/opensurvey/img/'.($type == 'classic' ? 'chart-32.png' : 'calendar-32.png'), 1), 'width="16"', 1);
229 print ' '.$langs->trans($type == 'classic' ? "TypeClassic" : "TypeDate").'</td></tr>';
230 
231 // Title
232 print '<tr><td>';
233 $adresseadmin = $object->mail_admin;
234 print $langs->trans("Title").'</td><td colspan="2">';
235 if ($action == 'edit')
236 {
237  print '<input type="text" name="nouveautitre" style="width: 95%" value="'.dol_escape_htmltag(dol_htmlentities($object->title)).'">';
238 } else print dol_htmlentities($object->title);
239 print '</td></tr>';
240 
241 // Description
242 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td colspan="2">';
243 if ($action == 'edit')
244 {
245  $doleditor = new DolEditor('nouveauxcommentaires', $object->description, '', 120, 'dolibarr_notes', 'In', 1, 1, 1, ROWS_7, '90%');
246  $doleditor->Create(0, '');
247 } else {
248  print (dol_textishtml($object->description) ? $object->description : dol_nl2br($object->description, 1, true));
249 }
250 print '</td></tr>';
251 
252 // EMail
253 //If linked user, then emails are going to be sent to users' email
254 if (!$object->fk_user_creat) {
255  print '<tr><td>'.$langs->trans("EMail").'</td><td colspan="2">';
256  if ($action == 'edit')
257  {
258  print '<input type="text" name="nouvelleadresse" class="minwith200" value="'.$object->mail_admin.'">';
259  } else print dol_print_email($object->mail_admin, 0, 0, 1);
260  print '</td></tr>';
261 }
262 
263 // Receive an email with each vote
264 print '<tr><td>'.$langs->trans('ToReceiveEMailForEachVote').'</td><td colspan="2">';
265 if ($action == 'edit')
266 {
267  print '<input type="checkbox" name="mailsonde" '.($object->mailsonde ? 'checked="checked"' : '').'">';
268 } else {
269  print yn($object->mailsonde);
270 
271  //If option is active and linked user does not have an email, we show a warning
272  if ($object->fk_user_creat && $object->mailsonde) {
273  if (!$userstatic->email) {
274  print ' '.img_warning($langs->trans('NoEMail'));
275  }
276  }
277 }
278 print '</td></tr>';
279 
280 // Users can comment
281 print '<tr><td>'.$langs->trans('CanComment').'</td><td colspan="2">';
282 if ($action == 'edit')
283 {
284  print '<input type="checkbox" name="cancomment" '.($object->allow_comments ? 'checked="checked"' : '').'">';
285 } else print yn($object->allow_comments);
286 print '</td></tr>';
287 
288 // Users can see others vote
289 print '<tr><td>'.$langs->trans('CanSeeOthersVote').'</td><td colspan="2">';
290 if ($action == 'edit')
291 {
292  print '<input type="checkbox" name="canseeothersvote" '.($object->allow_spy ? 'checked="checked"' : '').'">';
293 } else print yn($object->allow_spy);
294 print '</td></tr>';
295 
296 // Expire date
297 print '<tr><td>'.$langs->trans('ExpireDate').'</td><td colspan="2">';
298 if ($action == 'edit') print $form->selectDate($expiredate ? $expiredate : $object->date_fin, 'expire', 0, 0, 0, '', 1, 0);
299 else {
300  print dol_print_date($object->date_fin, 'day');
301  if ($object->date_fin && $object->date_fin < dol_now() && $object->status == Opensurveysondage::STATUS_VALIDATED) print img_warning($langs->trans("Expired"));
302 }
303 print '</td></tr>';
304 
305 // Author
306 print '<tr><td>';
307 print $langs->trans("Author").'</td><td colspan="2">';
308 if ($object->fk_user_creat) {
309  print $userstatic->getLoginUrl(1);
310 } else {
311  print dol_htmlentities($object->nom_admin);
312 }
313 print '</td></tr>';
314 
315 // Link
316 print '<tr><td>'.img_picto('', 'globe').' '.$langs->trans("UrlForSurvey", '').'</td><td colspan="2">';
317 
318 // Define $urlwithroot
319 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
320 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
321 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
322 
323 $url = $urlwithroot.'/public/opensurvey/studs.php?sondage='.$object->id_sondage;
324 print '<input type="text" style="width: 60%" '.($action == 'edit' ? 'disabled' : '').' id="opensurveyurl" name="opensurveyurl" value="'.$url.'">';
325 if ($action != 'edit') print ajax_autoselect("opensurveyurl", $url);
326 
327 print '</td></tr>';
328 
329 print '</table>';
330 
331 print '</div>';
332 
334 
335 if ($action == 'edit')
336 {
337  print '<div class="center">';
338  print '<input type="submit" class="button button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
339  print ' &nbsp; ';
340  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
341  print '</div>';
342 }
343 
344 print '</form>'."\n";
345 
346 
347 
348 /*
349  * Barre d'actions
350  */
351 print '<div class="tabsAction">';
352 
353 if ($action != 'edit' && $user->rights->opensurvey->write) {
354  //Modify button
355  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$numsondage.'">'.$langs->trans("Modify").'</a>';
356 
357  if ($object->status == Opensurveysondage::STATUS_VALIDATED)
358  {
359  //Close button
360  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=close&id='.$numsondage.'">'.$langs->trans("Close").'</a>';
361  }
362  if ($object->status == Opensurveysondage::STATUS_CLOSED)
363  {
364  //Opened button
365  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=reopen&id='.$numsondage.'">'.$langs->trans("ReOpen").'</a>';
366  }
367 
368  //Delete button
369  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?suppressionsondage=1&id='.$numsondage.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans('Delete').'</a>';
370 }
371 
372 print '</div>';
373 
374 if ($action == 'delete')
375 {
376  print $form->formconfirm($_SERVER["PHP_SELF"].'?&id='.$numsondage, $langs->trans("RemovePoll"), $langs->trans("ConfirmRemovalOfPoll", $id), 'delete_confirm', '', '', 1);
377 }
378 
379 
380 
381 
382 print '<form name="formulaire5" action="#" method="POST">'."\n";
383 print '<input type="hidden" name="token" value="'.newToken().'">';
384 
385 print load_fiche_titre($langs->trans("CommentsOfVoters"), '', '');
386 
387 // Comment list
388 $comments = $object->getComments();
389 
390 if ($comments) {
391  foreach ($comments as $comment) {
392  if ($user->rights->opensurvey->write) {
393  print '<a href="'.dol_buildpath('/opensurvey/card.php', 1).'?deletecomment='.$comment->id_comment.'&id='.$numsondage.'"> '.img_picto('', 'delete.png', '', false, 0, 0, '', '', 0).'</a> ';
394  }
395 
396  print dol_htmlentities($comment->usercomment).': '.dol_nl2br(dol_htmlentities($comment->comment))." <br>";
397  }
398 } else {
399  print '<span class="opacitymedium">'.$langs->trans("NoCommentYet").'</span><br>';
400 }
401 
402 print '<br>';
403 
404 // Add comment
405 if ($object->allow_comments) {
406  print $langs->trans("AddACommentForPoll").'<br>';
407  print '<textarea name="comment" rows="2" class="quatrevingtpercent"></textarea><br>'."\n";
408  print $langs->trans("Name").': <input type="text" class="minwidth300" name="commentuser" value="'.$user->getFullName($langs).'"> '."\n";
409  print '<input type="submit" class="button" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
410  if (isset($erreur_commentaire_vide) && $erreur_commentaire_vide == "yes") {
411  print "<font color=#FF0000>".$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Name"))."</font>";
412  }
413 }
414 
415 print '</form>';
416 
417 // End of page
418 llxFooter();
419 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_htmlentities($string, $flags=null, $encoding= 'UTF-8', $double_encode=false)
Replace htmlentities functions.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
const STATUS_VALIDATED
Validated/Opened status.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Put here description of your class.
ajax_autoselect($htmlname, $addlink= '')
Make content of an input box selected when we click into input field.
print $_SERVER["PHP_SELF"]
Edit parameters.
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
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
dol_textishtml($msg, $option=0)
Return if a text is a html content.