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