dolibarr 24.0.0-beta
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-2025 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';
38require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php";
39require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
40require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
41require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
42require_once DOL_DOCUMENT_ROOT."/opensurvey/lib/opensurvey.lib.php";
43
44// Security check
45if (!$user->hasRight('opensurvey', 'read')) {
47}
48
49// Initialize Variables
50$action = GETPOST('action', 'aZ09');
51$cancel = GETPOST('cancel', 'alpha');
52
53$numsondage = '';
54
55if (GETPOST('id')) {
56 $numsondage = (string) GETPOST('id', 'alpha');
57}
58
59// Initialize objects
61
62$result = $object->fetch('', $numsondage);
63if ($result <= 0) {
64 accessforbidden("Record not found");
65}
66
67// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
68$hookmanager->initHooks(array('surveycard', 'globalcard'));
69
70$expiredate = dol_mktime(0, 0, 0, GETPOSTINT('expiremonth'), GETPOSTINT('expireday'), GETPOSTINT('expireyear'));
71
72$permissiontoread = $user->hasRight('opensurvey', 'read');
73$permissiontoadd = $user->hasRight('opensurvey', 'write');
74$permissiontodelete = $user->hasRight('opensurvey', 'write'); // permission delete doesn't exists
75
76
77/*
78 * Actions
79 */
80
81$parameters = array('id' => $numsondage);
82$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
83if ($reshook < 0) {
84 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
85}
86
87if (empty($reshook)) {
88 if ($cancel) {
89 $action = '';
90 }
91
92 // Delete
93 if ($action == 'delete_confirm' && $permissiontodelete) {
94 // Security check
95 if (!$user->hasRight('opensurvey', 'write')) {
97 }
98
99 $result = $object->delete($user, 0, $numsondage);
100
101 header('Location: '.dol_buildpath('/opensurvey/list.php', 1));
102 exit();
103 }
104
105 // Close
106 if ($action == 'close' && $permissiontoadd) {
108 $object->update($user);
109 }
110
111 // Valid or Reopend
112 if (($action == 'reopen' || $action == 'validate') && $permissiontoadd) {
114 $object->update($user);
115 }
116
117 // Update
118 if ($action == 'update' && $permissiontoadd) {
119 // Security check
120 if (!$user->hasRight('opensurvey', 'write')) {
122 }
123
124 $error = 0;
125
126 if (!GETPOST('nouveautitre')) {
127 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors');
128 $error++;
129 $action = 'edit';
130 }
131
132 if (!$error) {
133 $object->title = (string) GETPOST('nouveautitre', 'alphanohtml');
134 $object->description = (string) GETPOST('nouveauxcommentaires', 'restricthtml');
135 $object->mail_admin = (string) GETPOST('nouvelleadresse', 'alpha');
136 $object->date_fin = $expiredate;
137 $object->allow_comments = GETPOST('cancomment', 'aZ09') == 'on' ? 1 : 0;
138 $object->allow_spy = GETPOST('canseeothersvote', 'aZ09') == 'on' ? 1 : 0;
139 $object->mailsonde = GETPOST('mailsonde', 'aZ09') == 'on' ? 1 : 0;
140
141 $res = $object->update($user);
142 if ($res < 0) {
143 setEventMessages($object->error, $object->errors, 'errors');
144 $action = 'edit';
145 }
146 }
147 }
148
149 // Add comment
150 if (GETPOST('ajoutcomment') && $permissiontoadd) {
151 $error = 0;
152
153 if (!GETPOST('comment', "alphanohtml")) {
154 $error++;
155 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
156 }
157 if (!GETPOST('commentuser', "alphanohtml")) {
158 $error++;
159 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors');
160 }
161
162 if (!$error) {
163 $comment = (string) GETPOST("comment", "alphanohtml");
164 $comment_user = (string) GETPOST('commentuser', "alphanohtml");
165
166 $resql = $object->addComment($comment, $comment_user);
167
168 if (!$resql) {
169 setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors');
170 }
171 }
172 }
173
174 // Delete comment
175 if ($action == 'deletecomment' && $permissiontoadd) {
176 $idcomment = GETPOSTINT('idcomment');
177 if ($idcomment > 0) {
178 // Security check
179 if (!$user->hasRight('opensurvey', 'write')) {
181 }
182
183 $resql = $object->deleteComment($idcomment);
184 }
185 }
186
187 if ($action == 'edit' && $permissiontoadd) {
188 // Security check
189 if (!$user->hasRight('opensurvey', 'write')) {
191 }
192 }
193}
194
195
196/*
197 * View
198 */
199
200$form = new Form($db);
201$userstatic = null;
202
203if ($object->fk_user_creat) {
204 $userstatic = new User($db);
205 $userstatic->fetch($object->fk_user_creat);
206}
207
208$title = $object->title." - ".$langs->trans('Card');
209$helpurl = '';
210$arrayofjs = array();
211$arrayofcss = array('/opensurvey/css/style.css');
212llxHeader('', $title, $helpurl, '', 0, 0, $arrayofjs, $arrayofcss);
213
214
215// Define format of choices
216$toutsujet = explode(",", $object->sujet);
217$listofanswers = array();
218foreach ($toutsujet as $value) {
219 $tmp = explode('@', $value);
220 $listofanswers[] = array('label' => $tmp[0], 'format' => (!empty($tmp[1]) ? $tmp[1] : 'checkbox'));
221}
222$toutsujet = str_replace("@", "<br>", $toutsujet);
223$toutsujet = str_replace("°", "'", $toutsujet);
224
225print '<form name="updatesurvey" action="'.$_SERVER["PHP_SELF"].'?id='.$numsondage.'" method="POST">'."\n";
226print '<input type="hidden" name="token" value="'.newToken().'">';
227print '<input type="hidden" name="action" value="update">';
228
229$head = opensurvey_prepare_head($object);
230
231
232print dol_get_fiche_head($head, 'general', $langs->trans("Survey"), -1, $object->picto);
233
234$morehtmlref = '';
235
236$linkback = '<a href="'.DOL_URL_ROOT.'/opensurvey/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
237
238dol_banner_tab($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage', $morehtmlref);
239
240
241print '<div class="fichecenter">';
242
243print '<div class="fichehalfleft">';
244print '<div class="underbanner clearboth"></div>';
245print '<table class="border tableforfield centpercent">';
246
247// Type
248$type = ($object->format == "A") ? 'classic' : 'date';
249print '<tr><td class="titlefieldmiddle">'.$langs->trans("Type").'</td><td>';
250print img_picto('', dol_buildpath('/opensurvey/img/'.($type == 'classic' ? 'chart-32.png' : 'calendar-32.png'), 1), 'width="16"', 1);
251print ' '.$langs->trans($type == 'classic' ? "TypeClassic" : "TypeDate").'</td></tr>';
252
253// Title
254print '<tr><td>';
255print $langs->trans("Title").'</td><td>';
256if ($action == 'edit') {
257 print '<input class="width300" type="text" name="nouveautitre" value="'.dolPrintHTML($object->title).'">';
258} else {
259 print dolPrintHTML($object->title);
260}
261print '</td></tr>';
262
263// Receive an email with each vote
264print '<tr><td>'.$langs->trans('ToReceiveEMailForEachVote').'</td><td>';
265if ($action == 'edit') {
266 print '<input type="checkbox" name="mailsonde" '.($object->mailsonde ? 'checked="checked"' : '').'">';
267} else {
268 print yn($object->mailsonde);
269
270 //If option is active and linked user does not have an email, we show a warning
271 if ($object->fk_user_creat && $object->mailsonde && $userstatic !== null) {
272 if (!$userstatic->email) {
273 print ' '.img_warning($langs->trans('NoEMail'));
274 }
275 }
276}
277print '</td></tr>';
278
279// Users can comment
280print '<tr><td>'.$langs->trans('CanComment').'</td><td>';
281if ($action == 'edit') {
282 print '<input type="checkbox" name="cancomment" '.($object->allow_comments ? 'checked="checked"' : '').'">';
283} else {
284 print yn($object->allow_comments);
285}
286print '</td></tr>';
287
288// Users can see others vote
289print '<tr><td>'.$langs->trans('CanSeeOthersVote').'</td><td>';
290if ($action == 'edit') {
291 print '<input type="checkbox" name="canseeothersvote" '.($object->allow_spy ? 'checked="checked"' : '').'">';
292} else {
293 print yn($object->allow_spy);
294}
295print '</td></tr>';
296
297// Description
298print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td class="wordbreak">';
299if ($action == 'edit') {
300 $doleditor = new DolEditor('nouveauxcommentaires', $object->description, '', 120, 'dolibarr_notes', 'In', true, 1, 1, ROWS_7, '100%');
301 $doleditor->Create(0, '');
302} else {
303 print(dol_textishtml($object->description) ? $object->description : dol_nl2br($object->description, 1, true));
304}
305print '</td></tr>';
306
307print '</table>';
308
309print '</div>';
310print '<div class="fichehalfright">';
311print '<div class="underbanner clearboth"></div>';
312
313print '<table class="border tableforfield centpercent">';
314
315// Expire date
316print '<tr><td>'.$langs->trans('ExpireDate').'</td><td>';
317if ($action == 'edit') {
318 print $form->selectDate($expiredate ? $expiredate : $object->date_fin, 'expire', 0, 0, 0, '', 1, 0);
319} else {
320 print dol_print_date($object->date_fin, 'day');
321 if ($object->date_fin && dol_get_last_hour($object->date_fin) < dol_now() && $object->status == Opensurveysondage::STATUS_VALIDATED) {
322 print img_warning($langs->trans("Expired"));
323 }
324}
325print '</td></tr>';
326
327// Author
328print '<tr><td>';
329print $langs->trans("Author").'</td><td>';
330if ($object->fk_user_creat > 0 && $userstatic !== null) {
331 print $userstatic->getLoginUrl(-1);
332} else {
333 if ($action == 'edit') {
334 print '<input type="text" name="nouvelleadresse" class="minwidth200" value="'.$object->mail_admin.'">';
335 } else {
336 print dol_print_email($object->mail_admin, 0, 0, 1, 0, 1, 1);
337 }
338}
339print '</td></tr>';
340
341// Link
342print '<tr><td>'.$langs->trans("UrlForSurvey", '').'</td><td>';
343
344// Define $urlwithroot
345$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
346$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
347//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
348
349$url = $urlwithroot.'/public/opensurvey/studs.php?sondage='.$object->id_sondage;
350print '<input type="text" class="quatrevingtpercent" '.($action == 'edit' ? 'disabled' : '').' id="opensurveyurl" name="opensurveyurl" value="'.$url.'" spellcheck="false">';
351//if ($action != 'edit') {
352print ajax_autoselect("opensurveyurl", $url, 'image');
353//}
354
355print '</td></tr>';
356
357// Other attributes
358$parameters = array();
359$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
360print $hookmanager->resPrint;
361
362print '</table>';
363print '</div>';
364
365print '</div>';
366print '<div class="clearboth"></div>';
367
368print dol_get_fiche_end();
369
370if ($action == 'edit') {
371 print $form->buttonsSaveCancel();
372}
373
374print '</form>'."\n";
375
376
377
378// Action bar
379
380print '<div class="tabsAction">';
381
382if ($action != 'edit' && $user->hasRight('opensurvey', 'write')) {
383 // Modify button
384 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Modify").'</a>';
385
387 // Validate button
388 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Valid").'</a>';
389 }
390
392 // Close button
393 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=close&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Close").'</a>';
394 }
396 // Re-Open
397 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("ReOpen").'</a>';
398 }
399
400 // Delete
401 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?suppressionsondage=1&id='.urlencode($numsondage).'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
402}
403
404print '</div>';
405
406if ($action == 'delete') {
407 print $form->formconfirm($_SERVER["PHP_SELF"].'?&id='.urlencode($numsondage), $langs->trans("RemovePoll"), $langs->trans("ConfirmRemovalOfPoll", $id), 'delete_confirm', '', '', 1);
408}
409
410
411
412
413print '<form name="formulaire5" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
414print '<input type="hidden" name="token" value="'.newToken().'">';
415print '<input type="hidden" name="action" value="addcomment">';
416print '<input type="hidden" name="id" value="'.urlencode($numsondage).'">';
417print '<input type="hidden" name="page_y" value="">';
418
419print load_fiche_titre($langs->trans("CommentsOfVoters"), '', '');
420
421// Comment list
422$comments = $object->getComments();
423
424if (!empty($comments)) {
425 foreach ($comments as $comment) {
426 if ($user->hasRight('opensurvey', 'write')) {
427 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', '', 0, 0, 0, '', '', 0).'</a> ';
428 }
429
430 print dol_htmlentities($comment->usercomment).': '.dol_nl2br(dol_htmlentities($comment->comment))." <br>";
431 }
432} else {
433 print '<span class="opacitymedium">'.$langs->trans("NoCommentYet").'</span><br>';
434}
435
436print '<br>';
437
438// Add comment
439if ($object->allow_comments) {
440 print '<br><textarea name="comment" rows="2" class="quatrevingtpercent" placeholder="'.$langs->trans("AddACommentForPoll").'"></textarea><br>'."\n";
441 print $langs->trans("Name").': <input type="text" class="minwidth300" name="commentuser" value="'.dol_escape_htmltag($user->getFullName($langs)).'"> '."\n";
442 print '<input type="submit" class="button reposition smallpaddingimp" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
443}
444
445print '</form>';
446
447// End of page
448llxFooter();
449$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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:650
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
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...
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.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
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.
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_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $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_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.