dolibarr 25.0.0-alpha
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-2026 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
60$object = new Opensurveysondage($db);
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 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
100 $result = $object->delete($user, 0, $numsondage);
101 if ($result > 0) {
102 header('Location: '.dol_buildpath('/opensurvey/list.php', 1));
103 exit();
104 } else {
105 setEventMessages($object->error, $object->errors, 'errors');
106 }
107 }
108
109 // Close
110 if ($action == 'close' && $permissiontoadd) {
112 $result = $object->update($user);
113 if ($result < 0) {
114 setEventMessages($object->error, $object->errors, 'errors');
115 }
116 }
117
118 // Valid or Reopend
119 if (($action == 'reopen' || $action == 'validate') && $permissiontoadd) {
121 $result = $object->update($user);
122 if ($result < 0) {
123 setEventMessages($object->error, $object->errors, 'errors');
124 }
125 }
126
127 // Update
128 if ($action == 'update' && $permissiontoadd) {
129 // Security check
130 if (!$user->hasRight('opensurvey', 'write')) {
132 }
133
134 $error = 0;
135
136 if (!GETPOST('nouveautitre')) {
137 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors');
138 $error++;
139 $action = 'edit';
140 }
141
142 if (!$error) {
143 $object->title = (string) GETPOST('nouveautitre', 'alphanohtml');
144 $object->description = (string) GETPOST('nouveauxcommentaires', 'restricthtml');
145 $object->mail_admin = (string) GETPOST('nouvelleadresse', 'alpha');
146 $object->date_fin = $expiredate;
147 $object->allow_comments = GETPOST('cancomment', 'aZ09') == 'on' ? 1 : 0;
148 $object->allow_spy = GETPOST('canseeothersvote', 'aZ09') == 'on' ? 1 : 0;
149 $object->mailsonde = GETPOST('mailsonde', 'aZ09') == 'on' ? 1 : 0;
150
151 $res = $object->update($user);
152 if ($res < 0) {
153 setEventMessages($object->error, $object->errors, 'errors');
154 $action = 'edit';
155 }
156 }
157 }
158
159 // Add comment
160 if (GETPOST('ajoutcomment') && $permissiontoadd) {
161 $error = 0;
162
163 if (!GETPOST('comment', "alphanohtml")) {
164 $error++;
165 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
166 }
167 if (!GETPOST('commentuser', "alphanohtml")) {
168 $error++;
169 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors');
170 }
171
172 if (!$error) {
173 $comment = (string) GETPOST("comment", "alphanohtml");
174 $comment_user = (string) GETPOST('commentuser', "alphanohtml");
175
176 $resql = $object->addComment($comment, $comment_user);
177
178 if (!$resql) {
179 setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors');
180 }
181 }
182 }
183
184 // Delete comment
185 if ($action == 'deletecomment' && $permissiontoadd) {
186 $idcomment = GETPOSTINT('idcomment');
187 if ($idcomment > 0) {
188 // Security check
189 if (!$user->hasRight('opensurvey', 'write')) {
191 }
192
193 $resql = $object->deleteComment($idcomment);
194 }
195 }
196
197 if ($action == 'edit' && $permissiontoadd) {
198 // Security check
199 if (!$user->hasRight('opensurvey', 'write')) {
201 }
202 }
203}
204
205
206/*
207 * View
208 */
209
210$form = new Form($db);
211$userstatic = null;
212
213if ($object->fk_user_creat) {
214 $userstatic = new User($db);
215 $userstatic->fetch($object->fk_user_creat);
216}
217
218$title = $object->title." - ".$langs->trans('Card');
219$helpurl = '';
220$arrayofjs = array();
221$arrayofcss = array('/opensurvey/css/style.css');
222llxHeader('', $title, $helpurl, '', 0, 0, $arrayofjs, $arrayofcss);
223
224
225// Define format of choices
226$toutsujet = explode(",", $object->sujet);
227$listofanswers = array();
228foreach ($toutsujet as $value) {
229 $tmp = explode('@', $value);
230 $listofanswers[] = array('label' => $tmp[0], 'format' => (!empty($tmp[1]) ? $tmp[1] : 'checkbox'));
231}
232$toutsujet = str_replace("@", "<br>", $toutsujet);
233$toutsujet = str_replace("°", "'", $toutsujet);
234
235print '<form name="updatesurvey" action="'.$_SERVER["PHP_SELF"].'?id='.$numsondage.'" method="POST">'."\n";
236print '<input type="hidden" name="token" value="'.newToken().'">';
237print '<input type="hidden" name="action" value="update">';
238
239$head = opensurvey_prepare_head($object);
240
241
242print dol_get_fiche_head($head, 'general', $langs->trans("Survey"), -1, $object->picto);
243
244$morehtmlref = '';
245
246$linkback = '<a href="'.DOL_URL_ROOT.'/opensurvey/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
247
248dol_banner_tab($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage', $morehtmlref);
249
250
251print '<div class="fichecenter">';
252
253print '<div class="fichehalfleft">';
254print '<div class="underbanner clearboth"></div>';
255print '<table class="border tableforfield centpercent">';
256
257// Type
258$type = ($object->format == "A") ? 'classic' : 'date';
259print '<tr><td class="titlefieldmiddle">'.$langs->trans("Type").'</td><td>';
260print img_picto('', dol_buildpath('/opensurvey/img/'.($type == 'classic' ? 'chart-32.png' : 'calendar-32.png'), 1), 'width="16"', 1);
261print ' '.$langs->trans($type == 'classic' ? "TypeClassic" : "TypeDate").'</td></tr>';
262
263// Title
264print '<tr><td>';
265print $langs->trans("Title").'</td><td>';
266if ($action == 'edit') {
267 print '<input class="width300" type="text" name="nouveautitre" value="'.dolPrintHTML($object->title).'">';
268} else {
269 print dolPrintHTML($object->title);
270}
271print '</td></tr>';
272
273// Receive an email with each vote
274print '<tr><td>'.$langs->trans('ToReceiveEMailForEachVote').'</td><td>';
275if ($action == 'edit') {
276 print '<input type="checkbox" name="mailsonde" '.($object->mailsonde ? 'checked="checked"' : '').'">';
277} else {
278 print yn($object->mailsonde);
279
280 //If option is active and linked user does not have an email, we show a warning
281 if ($object->fk_user_creat && $object->mailsonde && $userstatic !== null) {
282 if (!$userstatic->email) {
283 print ' '.img_warning($langs->trans('NoEMail'));
284 }
285 }
286}
287print '</td></tr>';
288
289// Users can comment
290print '<tr><td>'.$langs->trans('CanComment').'</td><td>';
291if ($action == 'edit') {
292 print '<input type="checkbox" name="cancomment" '.($object->allow_comments ? 'checked="checked"' : '').'">';
293} else {
294 print yn($object->allow_comments);
295}
296print '</td></tr>';
297
298// Users can see others vote
299print '<tr><td>'.$langs->trans('CanSeeOthersVote').'</td><td>';
300if ($action == 'edit') {
301 print '<input type="checkbox" name="canseeothersvote" '.($object->allow_spy ? 'checked="checked"' : '').'">';
302} else {
303 print yn($object->allow_spy);
304}
305print '</td></tr>';
306
307// Description
308print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td class="wordbreak">';
309if ($action == 'edit') {
310 $doleditor = new DolEditor('nouveauxcommentaires', $object->description, '', 120, 'dolibarr_notes', 'In', true, 1, 1, ROWS_7, '100%');
311 $doleditor->Create(0, '');
312} else {
313 print(dol_textishtml($object->description) ? $object->description : dol_nl2br($object->description, 1, true));
314}
315print '</td></tr>';
316
317print '</table>';
318
319print '</div>';
320print '<div class="fichehalfright">';
321print '<div class="underbanner clearboth"></div>';
322
323print '<table class="border tableforfield centpercent">';
324
325// Expire date
326print '<tr><td>'.$langs->trans('ExpireDate').'</td><td>';
327if ($action == 'edit') {
328 print $form->selectDate($expiredate ? $expiredate : $object->date_fin, 'expire', 0, 0, 0, '', 1, 0);
329} else {
330 print dol_print_date($object->date_fin, 'day');
331 if ($object->date_fin && dol_get_last_hour($object->date_fin) < dol_now() && $object->status == Opensurveysondage::STATUS_VALIDATED) {
332 print img_warning($langs->trans("Expired"));
333 }
334}
335print '</td></tr>';
336
337// Author
338print '<tr><td>';
339print $langs->trans("Author").'</td><td>';
340if ($object->fk_user_creat > 0 && $userstatic !== null) {
341 print $userstatic->getLoginUrl(-1);
342} else {
343 if ($action == 'edit') {
344 print '<input type="text" name="nouvelleadresse" class="minwidth200" value="'.$object->mail_admin.'">';
345 } else {
346 print dol_print_email($object->mail_admin, 0, 0, 1, 0, 1, 1);
347 }
348}
349print '</td></tr>';
350
351// Link
352print '<tr><td>'.$langs->trans("UrlForSurvey", '').'</td><td>';
353
354// Define $urlwithroot
355$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
356$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
357//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
358
359$url = $urlwithroot.'/public/opensurvey/studs.php?sondage='.$object->id_sondage;
360print '<input type="text" class="quatrevingtpercent" '.($action == 'edit' ? 'disabled' : '').' id="opensurveyurl" name="opensurveyurl" value="'.$url.'" spellcheck="false">';
361//if ($action != 'edit') {
362print ajax_autoselect("opensurveyurl", $url, 'image');
363//}
364
365print '</td></tr>';
366
367// Other attributes
368$parameters = array();
369$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
370print $hookmanager->resPrint;
371
372print '</table>';
373print '</div>';
374
375print '</div>';
376print '<div class="clearboth"></div>';
377
378print dol_get_fiche_end();
379
380if ($action == 'edit') {
381 print $form->buttonsSaveCancel();
382}
383
384print '</form>'."\n";
385
386
387
388// Action bar
389
390print '<div class="tabsAction">';
391
392if ($action != 'edit' && $user->hasRight('opensurvey', 'write')) {
393 // Modify button
394 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Modify").'</a>';
395
397 // Validate button
398 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Valid").'</a>';
399 }
400
402 // Close button
403 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=close&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Close").'</a>';
404 }
406 // Re-Open
407 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("ReOpen").'</a>';
408 }
409
410 // Delete
411 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?suppressionsondage=1&id='.urlencode($numsondage).'&action=delete&token='.newToken(), 'delete', $permissiontodelete, array('attr' => array('class' => 'reposition')))."\n";
412}
413
414print '</div>';
415
416if ($action == 'delete') {
417 print $form->formconfirm($_SERVER["PHP_SELF"].'?&id='.urlencode($numsondage), $langs->trans("RemovePoll"), $langs->trans("ConfirmRemovalOfPoll", $numsondage), 'delete_confirm', '', '', 1);
418}
419
420
421
422
423print '<form name="formulaire5" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
424print '<input type="hidden" name="token" value="'.newToken().'">';
425print '<input type="hidden" name="action" value="addcomment">';
426print '<input type="hidden" name="id" value="'.urlencode($numsondage).'">';
427print '<input type="hidden" name="page_y" value="">';
428
429print load_fiche_titre($langs->trans("CommentsOfVoters"), '', '');
430
431// Comment list
432$comments = $object->getComments();
433
434if (!empty($comments)) {
435 foreach ($comments as $comment) {
436 if ($user->hasRight('opensurvey', 'write')) {
437 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> ';
438 }
439
440 print dol_htmlentities($comment->usercomment).': '.dol_nl2br(dol_htmlentities($comment->comment))." <br>";
441 }
442} else {
443 print '<span class="opacitymedium">'.$langs->trans("NoCommentYet").'</span><br>';
444}
445
446print '<br>';
447
448// Add comment
449if ($object->allow_comments) {
450 print '<br><textarea name="comment" rows="2" class="quatrevingtpercent" placeholder="'.$langs->trans("AddACommentForPoll").'"></textarea><br>'."\n";
451 print $langs->trans("Name").': <input type="text" class="minwidth300" name="commentuser" value="'.dol_escape_htmltag($user->getFullName($langs)).'"> '."\n";
452 print '<input type="submit" class="button reposition smallpaddingimp" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
453}
454
455print '</form>';
456
457// End of page
458llxFooter();
459$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:662
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_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...
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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).
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.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
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)
Definition html.lib.php:181
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.