dolibarr 22.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-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php";
30require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
31require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
32require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
33require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
34
35
46// Security check
47if (!$user->hasRight('opensurvey', 'read')) {
49}
50
51// Initialize Variables
52$action = GETPOST('action', 'aZ09');
53$cancel = GETPOST('cancel', 'alpha');
54
55$numsondage = '';
56
57if (GETPOST('id')) {
58 $numsondage = (string) GETPOST('id', 'alpha');
59}
60
61// Initialize objects
62$object = new Opensurveysondage($db);
63
64$result = $object->fetch('', $numsondage);
65if ($result <= 0) {
66 dol_print_error($db, $object->error);
67 exit;
68}
69
70// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
71$hookmanager->initHooks(array('surveycard', 'globalcard'));
72
73$expiredate = dol_mktime(0, 0, 0, GETPOSTINT('expiremonth'), GETPOSTINT('expireday'), GETPOSTINT('expireyear'));
74
75$permissiontoread = $user->hasRight('opensurvey', 'read');
76$permissiontoadd = $user->hasRight('opensurvey', 'write');
77$permissiontodelete = $user->hasRight('opensurvey', 'write'); // permission delete doesn't exists
78
79
80/*
81 * Actions
82 */
83
84$parameters = array('id' => $numsondage);
85$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
86if ($reshook < 0) {
87 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
88}
89
90if (empty($reshook)) {
91 if ($cancel) {
92 $action = '';
93 }
94
95 // Delete
96 if ($action == 'delete_confirm' && $permissiontodelete) {
97 // Security check
98 if (!$user->hasRight('opensurvey', 'write')) {
100 }
101
102 $result = $object->delete($user, 0, $numsondage);
103
104 header('Location: '.dol_buildpath('/opensurvey/list.php', 1));
105 exit();
106 }
107
108 // Close
109 if ($action == 'close' && $permissiontoadd) {
111 $object->update($user);
112 }
113
114 // Valid or Reopend
115 if (($action == 'reopen' || $action == 'validate') && $permissiontoadd) {
117 $object->update($user);
118 }
119
120 // Update
121 if ($action == 'update' && $permissiontoadd) {
122 // Security check
123 if (!$user->hasRight('opensurvey', 'write')) {
125 }
126
127 $error = 0;
128
129 if (!GETPOST('nouveautitre')) {
130 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors');
131 $error++;
132 $action = 'edit';
133 }
134
135 if (!$error) {
136 $object->title = (string) GETPOST('nouveautitre', 'alphanohtml');
137 $object->description = (string) GETPOST('nouveauxcommentaires', 'restricthtml');
138 $object->mail_admin = (string) GETPOST('nouvelleadresse', 'alpha');
139 $object->date_fin = $expiredate;
140 $object->allow_comments = GETPOST('cancomment', 'aZ09') == 'on' ? 1 : 0;
141 $object->allow_spy = GETPOST('canseeothersvote', 'aZ09') == 'on' ? 1 : 0;
142 $object->mailsonde = GETPOST('mailsonde', 'aZ09') == 'on' ? 1 : 0;
143
144 $res = $object->update($user);
145 if ($res < 0) {
146 setEventMessages($object->error, $object->errors, 'errors');
147 $action = 'edit';
148 }
149 }
150 }
151
152 // Add comment
153 if (GETPOST('ajoutcomment') && $permissiontoadd) {
154 $error = 0;
155
156 if (!GETPOST('comment', "alphanohtml")) {
157 $error++;
158 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
159 }
160 if (!GETPOST('commentuser', "alphanohtml")) {
161 $error++;
162 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors');
163 }
164
165 if (!$error) {
166 $comment = (string) GETPOST("comment", "alphanohtml");
167 $comment_user = (string) GETPOST('commentuser', "alphanohtml");
168
169 $resql = $object->addComment($comment, $comment_user);
170
171 if (!$resql) {
172 setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors');
173 }
174 }
175 }
176
177 // Delete comment
178 if ($action == 'deletecomment' && $permissiontoadd) {
179 $idcomment = GETPOSTINT('idcomment');
180 if ($idcomment > 0) {
181 // Security check
182 if (!$user->hasRight('opensurvey', 'write')) {
184 }
185
186 $resql = $object->deleteComment($idcomment);
187 }
188 }
189
190 if ($action == 'edit' && $permissiontoadd) {
191 // Security check
192 if (!$user->hasRight('opensurvey', 'write')) {
194 }
195 }
196}
197
198
199/*
200 * View
201 */
202
203$form = new Form($db);
204$userstatic = null;
205
206if ($object->fk_user_creat) {
207 $userstatic = new User($db);
208 $userstatic->fetch($object->fk_user_creat);
209}
210
211$title = $object->title." - ".$langs->trans('Card');
212$helpurl = '';
213$arrayofjs = array();
214$arrayofcss = array('/opensurvey/css/style.css');
215llxHeader('', $title, $helpurl, '', 0, 0, $arrayofjs, $arrayofcss);
216
217
218// Define format of choices
219$toutsujet = explode(",", $object->sujet);
220$listofanswers = array();
221foreach ($toutsujet as $value) {
222 $tmp = explode('@', $value);
223 $listofanswers[] = array('label' => $tmp[0], 'format' => (!empty($tmp[1]) ? $tmp[1] : 'checkbox'));
224}
225$toutsujet = str_replace("@", "<br>", $toutsujet);
226$toutsujet = str_replace("°", "'", $toutsujet);
227
228print '<form name="updatesurvey" action="'.$_SERVER["PHP_SELF"].'?id='.$numsondage.'" method="POST">'."\n";
229print '<input type="hidden" name="token" value="'.newToken().'">';
230print '<input type="hidden" name="action" value="update">';
231
233
234
235print dol_get_fiche_head($head, 'general', $langs->trans("Survey"), -1, 'poll');
236
237$morehtmlref = '';
238
239$linkback = '<a href="'.DOL_URL_ROOT.'/opensurvey/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
240
241dol_banner_tab($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage', $morehtmlref);
242
243
244print '<div class="fichecenter">';
245
246print '<div class="fichehalfleft">';
247print '<div class="underbanner clearboth"></div>';
248print '<table class="border tableforfield centpercent">';
249
250// Type
251$type = ($object->format == "A") ? 'classic' : 'date';
252print '<tr><td class="titlefieldmiddle">'.$langs->trans("Type").'</td><td>';
253print img_picto('', dol_buildpath('/opensurvey/img/'.($type == 'classic' ? 'chart-32.png' : 'calendar-32.png'), 1), 'width="16"', 1);
254print ' '.$langs->trans($type == 'classic' ? "TypeClassic" : "TypeDate").'</td></tr>';
255
256// Title
257print '<tr><td>';
258$adresseadmin = $object->mail_admin;
259print $langs->trans("Title").'</td><td>';
260if ($action == 'edit') {
261 print '<input class="width300" type="text" name="nouveautitre" value="'.dolPrintHTML($object->title).'">';
262} else {
263 print dolPrintHTML($object->title);
264}
265print '</td></tr>';
266
267// Receive an email with each vote
268print '<tr><td>'.$langs->trans('ToReceiveEMailForEachVote').'</td><td>';
269if ($action == 'edit') {
270 print '<input type="checkbox" name="mailsonde" '.($object->mailsonde ? 'checked="checked"' : '').'">';
271} else {
272 print yn($object->mailsonde);
273
274 //If option is active and linked user does not have an email, we show a warning
275 if ($object->fk_user_creat && $object->mailsonde && $userstatic !== null) {
276 if (!$userstatic->email) {
277 print ' '.img_warning($langs->trans('NoEMail'));
278 }
279 }
280}
281print '</td></tr>';
282
283// Users can comment
284print '<tr><td>'.$langs->trans('CanComment').'</td><td>';
285if ($action == 'edit') {
286 print '<input type="checkbox" name="cancomment" '.($object->allow_comments ? 'checked="checked"' : '').'">';
287} else {
288 print yn($object->allow_comments);
289}
290print '</td></tr>';
291
292// Users can see others vote
293print '<tr><td>'.$langs->trans('CanSeeOthersVote').'</td><td>';
294if ($action == 'edit') {
295 print '<input type="checkbox" name="canseeothersvote" '.($object->allow_spy ? 'checked="checked"' : '').'">';
296} else {
297 print yn($object->allow_spy);
298}
299print '</td></tr>';
300
301// Description
302print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td class="wordbreak">';
303if ($action == 'edit') {
304 $doleditor = new DolEditor('nouveauxcommentaires', $object->description, '', 120, 'dolibarr_notes', 'In', true, 1, 1, ROWS_7, '90%');
305 $doleditor->Create(0, '');
306} else {
307 print(dol_textishtml($object->description) ? $object->description : dol_nl2br($object->description, 1, true));
308}
309print '</td></tr>';
310
311print '</table>';
312
313print '</div>';
314print '<div class="fichehalfright">';
315print '<div class="underbanner clearboth"></div>';
316
317print '<table class="border tableforfield centpercent">';
318
319// Expire date
320print '<tr><td>'.$langs->trans('ExpireDate').'</td><td>';
321if ($action == 'edit') {
322 print $form->selectDate($expiredate ? $expiredate : $object->date_fin, 'expire', 0, 0, 0, '', 1, 0);
323} else {
324 print dol_print_date($object->date_fin, 'day');
325 if ($object->date_fin && dol_get_last_hour($object->date_fin) < dol_now() && $object->status == Opensurveysondage::STATUS_VALIDATED) {
326 print img_warning($langs->trans("Expired"));
327 }
328}
329print '</td></tr>';
330
331// Author
332print '<tr><td>';
333print $langs->trans("Author").'</td><td>';
334if ($object->fk_user_creat > 0 && $userstatic !== null) {
335 print $userstatic->getLoginUrl(-1);
336} else {
337 if ($action == 'edit') {
338 print '<input type="text" name="nouvelleadresse" class="minwidth200" value="'.$object->mail_admin.'">';
339 } else {
340 print dol_print_email($object->mail_admin, 0, 0, 1, 0, 1, 1);
341 }
342}
343print '</td></tr>';
344
345// Link
346print '<tr><td>'.$langs->trans("UrlForSurvey", '').'</td><td>';
347
348// Define $urlwithroot
349$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
350$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
351//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
352
353$url = $urlwithroot.'/public/opensurvey/studs.php?sondage='.$object->id_sondage;
354print '<input type="text" class="quatrevingtpercent" '.($action == 'edit' ? 'disabled' : '').' id="opensurveyurl" name="opensurveyurl" value="'.$url.'">';
355//if ($action != 'edit') {
356print ajax_autoselect("opensurveyurl", $url, 'image');
357//}
358
359print '</td></tr>';
360
361// Other attributes
362$parameters = array();
363$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
364print $hookmanager->resPrint;
365
366print '</table>';
367print '</div>';
368
369print '</div>';
370print '<div class="clearboth"></div>';
371
372print dol_get_fiche_end();
373
374if ($action == 'edit') {
375 print $form->buttonsSaveCancel();
376}
377
378print '</form>'."\n";
379
380
381
382// Action bar
383
384print '<div class="tabsAction">';
385
386if ($action != 'edit' && $user->hasRight('opensurvey', 'write')) {
387 // Modify button
388 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Modify").'</a>';
389
391 // Validate button
392 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Valid").'</a>';
393 }
394
396 // Close button
397 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=close&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Close").'</a>';
398 }
400 // Re-Open
401 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("ReOpen").'</a>';
402 }
403
404 // Delete
405 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?suppressionsondage=1&id='.urlencode($numsondage).'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
406}
407
408print '</div>';
409
410if ($action == 'delete') {
411 print $form->formconfirm($_SERVER["PHP_SELF"].'?&id='.urlencode($numsondage), $langs->trans("RemovePoll"), $langs->trans("ConfirmRemovalOfPoll", $id), 'delete_confirm', '', '', 1);
412}
413
414
415
416
417print '<form name="formulaire5" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
418print '<input type="hidden" name="token" value="'.newToken().'">';
419print '<input type="hidden" name="action" value="addcomment">';
420print '<input type="hidden" name="id" value="'.urlencode($numsondage).'">';
421print '<input type="hidden" name="page_y" value="">';
422
423print load_fiche_titre($langs->trans("CommentsOfVoters"), '', '');
424
425// Comment list
426$comments = $object->getComments();
427
428if (!empty($comments)) {
429 foreach ($comments as $comment) {
430 if ($user->hasRight('opensurvey', 'write')) {
431 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', '', 0, 0, 0, '', '', 0).'</a> ';
432 }
433
434 print dol_htmlentities($comment->usercomment).': '.dol_nl2br(dol_htmlentities($comment->comment))." <br>";
435 }
436} else {
437 print '<span class="opacitymedium">'.$langs->trans("NoCommentYet").'</span><br>';
438}
439
440print '<br>';
441
442// Add comment
443if ($object->allow_comments) {
444 print $langs->trans("AddACommentForPoll").'<br>';
445 print '<textarea name="comment" rows="2" class="quatrevingtpercent"></textarea><br>'."\n";
446 print $langs->trans("Name").': <input type="text" class="minwidth300" name="commentuser" value="'.dol_escape_htmltag($user->getFullName($langs)).'"> '."\n";
447 print '<input type="submit" class="button reposition smallpaddingimp" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
448}
449
450print '</form>';
451
452// End of page
453llxFooter();
454$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
global $dolibarr_main_url_root
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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.
const STATUS_DRAFT
Draft status (not used)
Class to manage Dolibarr users.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
Definition date.lib.php:646
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
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.
dol_now($mode='auto')
Return date for now.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
opensurvey_prepare_head(Opensurveysondage $object)
Returns an array with the tabs for the "Opensurvey poll" section It loads tabs from modules looking f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.