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