dolibarr 21.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-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 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
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(0, $numsondage);
63if ($result <= 0) {
64 dol_print_error($db, $object->error);
65 exit;
66}
67
68// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
69$hookmanager->initHooks(array('surveycard', 'globalcard'));
70
71$expiredate = dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GETPOST('expireyear'));
72
73$permissiontoread = $user->hasRight('opensurvey', 'read');
74$permissiontoadd = $user->hasRight('opensurvey', 'write');
75$permissiontodelete = $user->hasRight('opensurvey', 'write'); // permission delete doesn't exists
76
77
78/*
79 * Actions
80 */
81
82$parameters = array('id' => $numsondage);
83$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
84if ($reshook < 0) {
85 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
86}
87
88if (empty($reshook)) {
89 if ($cancel) {
90 $action = '';
91 }
92
93 // Delete
94 if ($action == 'delete_confirm' && $permissiontodelete) {
95 // Security check
96 if (!$user->hasRight('opensurvey', 'write')) {
98 }
99
100 $result = $object->delete($user, 0, $numsondage);
101
102 header('Location: '.dol_buildpath('/opensurvey/list.php', 1));
103 exit();
104 }
105
106 // Close
107 if ($action == 'close' && $permissiontoadd) {
109 $object->update($user);
110 }
111
112 // Valid or Reopend
113 if (($action == 'reopen' || $action == 'validate') && $permissiontoadd) {
115 $object->update($user);
116 }
117
118 // Update
119 if ($action == 'update' && $permissiontoadd) {
120 // Security check
121 if (!$user->hasRight('opensurvey', 'write')) {
123 }
124
125 $error = 0;
126
127 if (!GETPOST('nouveautitre')) {
128 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors');
129 $error++;
130 $action = 'edit';
131 }
132
133 if (!$error) {
134 $object->title = (string) GETPOST('nouveautitre', 'alphanohtml');
135 $object->description = (string) GETPOST('nouveauxcommentaires', 'restricthtml');
136 $object->mail_admin = (string) GETPOST('nouvelleadresse', 'alpha');
137 $object->date_fin = $expiredate;
138 $object->allow_comments = GETPOST('cancomment', 'aZ09') == 'on' ? 1 : 0;
139 $object->allow_spy = GETPOST('canseeothersvote', 'aZ09') == 'on' ? 1 : 0;
140 $object->mailsonde = GETPOST('mailsonde', 'aZ09') == 'on' ? 1 : 0;
141
142 $res = $object->update($user);
143 if ($res < 0) {
144 setEventMessages($object->error, $object->errors, 'errors');
145 $action = 'edit';
146 }
147 }
148 }
149
150 // Add comment
151 if (GETPOST('ajoutcomment') && $permissiontoadd) {
152 $error = 0;
153
154 if (!GETPOST('comment', "alphanohtml")) {
155 $error++;
156 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
157 }
158 if (!GETPOST('commentuser', "alphanohtml")) {
159 $error++;
160 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors');
161 }
162
163 if (!$error) {
164 $comment = (string) GETPOST("comment", "alphanohtml");
165 $comment_user = (string) GETPOST('commentuser', "alphanohtml");
166
167 $resql = $object->addComment($comment, $comment_user);
168
169 if (!$resql) {
170 setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors');
171 }
172 }
173 }
174
175 // Delete comment
176 if ($action == 'deletecomment' && $permissiontoadd) {
177 $idcomment = GETPOSTINT('idcomment');
178 if ($idcomment > 0) {
179 // Security check
180 if (!$user->hasRight('opensurvey', 'write')) {
182 }
183
184 $resql = $object->deleteComment($idcomment);
185 }
186 }
187
188 if ($action == 'edit' && $permissiontoadd) {
189 // Security check
190 if (!$user->hasRight('opensurvey', 'write')) {
192 }
193 }
194}
195
196
197/*
198 * View
199 */
200
201$form = new Form($db);
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
230
231
232print dol_get_fiche_head($head, 'general', $langs->trans("Survey"), -1, 'poll');
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>';
255$adresseadmin = $object->mail_admin;
256print $langs->trans("Title").'</td><td>';
257if ($action == 'edit') {
258 print '<input class="width300" type="text" name="nouveautitre" value="'.dolPrintHTML($object->title).'">';
259} else {
260 print dolPrintHTML($object->title);
261}
262print '</td></tr>';
263
264// Description
265print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td class="wordbreak">';
266if ($action == 'edit') {
267 $doleditor = new DolEditor('nouveauxcommentaires', $object->description, '', 120, 'dolibarr_notes', 'In', true, 1, 1, ROWS_7, '90%');
268 $doleditor->Create(0, '');
269} else {
270 print(dol_textishtml($object->description) ? $object->description : dol_nl2br($object->description, 1, true));
271}
272print '</td></tr>';
273
274// Receive an email with each vote
275print '<tr><td>'.$langs->trans('ToReceiveEMailForEachVote').'</td><td>';
276if ($action == 'edit') {
277 print '<input type="checkbox" name="mailsonde" '.($object->mailsonde ? 'checked="checked"' : '').'">';
278} else {
279 print yn($object->mailsonde);
280
281 //If option is active and linked user does not have an email, we show a warning
282 if ($object->fk_user_creat && $object->mailsonde) {
283 if (!$userstatic->email) {
284 print ' '.img_warning($langs->trans('NoEMail'));
285 }
286 }
287}
288print '</td></tr>';
289
290// Users can comment
291print '<tr><td>'.$langs->trans('CanComment').'</td><td>';
292if ($action == 'edit') {
293 print '<input type="checkbox" name="cancomment" '.($object->allow_comments ? 'checked="checked"' : '').'">';
294} else {
295 print yn($object->allow_comments);
296}
297print '</td></tr>';
298
299// Users can see others vote
300print '<tr><td>'.$langs->trans('CanSeeOthersVote').'</td><td>';
301if ($action == 'edit') {
302 print '<input type="checkbox" name="canseeothersvote" '.($object->allow_spy ? 'checked="checked"' : '').'">';
303} else {
304 print yn($object->allow_spy);
305}
306print '</td></tr>';
307
308print '</table>';
309
310print '</div>';
311print '<div class="fichehalfright">';
312print '<div class="underbanner clearboth"></div>';
313
314print '<table class="border tableforfield centpercent">';
315
316// Expire date
317print '<tr><td>'.$langs->trans('ExpireDate').'</td><td>';
318if ($action == 'edit') {
319 print $form->selectDate($expiredate ? $expiredate : $object->date_fin, 'expire', 0, 0, 0, '', 1, 0);
320} else {
321 print dol_print_date($object->date_fin, 'day');
322 if ($object->date_fin && $object->date_fin < dol_now() && $object->status == Opensurveysondage::STATUS_VALIDATED) {
323 print img_warning($langs->trans("Expired"));
324 }
325}
326print '</td></tr>';
327
328// Author
329print '<tr><td>';
330print $langs->trans("Author").'</td><td>';
331if ($object->fk_user_creat > 0) {
332 print $userstatic->getLoginUrl(-1);
333} else {
334 if ($action == 'edit') {
335 print '<input type="text" name="nouvelleadresse" class="minwidth200" value="'.$object->mail_admin.'">';
336 } else {
337 print dol_print_email($object->mail_admin, 0, 0, 1, 0, 1, 1);
338 }
339}
340print '</td></tr>';
341
342// Link
343print '<tr><td>'.$langs->trans("UrlForSurvey", '').'</td><td>';
344
345// Define $urlwithroot
346$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
347$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
348//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
349
350$url = $urlwithroot.'/public/opensurvey/studs.php?sondage='.$object->id_sondage;
351print '<input type="text" class="quatrevingtpercent" '.($action == 'edit' ? 'disabled' : '').' id="opensurveyurl" name="opensurveyurl" value="'.$url.'">';
352//if ($action != 'edit') {
353print ajax_autoselect("opensurveyurl", $url, 'image');
354//}
355
356print '</td></tr>';
357
358// Other attributes
359$parameters = array();
360$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
361print $hookmanager->resPrint;
362
363print '</table>';
364print '</div>';
365
366print '</div>';
367print '<div class="clearboth"></div>';
368
369print dol_get_fiche_end();
370
371if ($action == 'edit') {
372 print $form->buttonsSaveCancel();
373}
374
375print '</form>'."\n";
376
377
378
379// Action bar
380
381print '<div class="tabsAction">';
382
383if ($action != 'edit' && $user->hasRight('opensurvey', 'write')) {
384 // Modify button
385 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Modify").'</a>';
386
388 // Validate button
389 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Valid").'</a>';
390 }
391
393 // Close button
394 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=close&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("Close").'</a>';
395 }
397 // Re-Open
398 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.urlencode($numsondage).'">'.$langs->trans("ReOpen").'</a>';
399 }
400
401 // Delete
402 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?suppressionsondage=1&id='.urlencode($numsondage).'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
403}
404
405print '</div>';
406
407if ($action == 'delete') {
408 print $form->formconfirm($_SERVER["PHP_SELF"].'?&id='.urlencode($numsondage), $langs->trans("RemovePoll"), $langs->trans("ConfirmRemovalOfPoll", $id), 'delete_confirm', '', '', 1);
409}
410
411
412
413
414print '<form name="formulaire5" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
415print '<input type="hidden" name="token" value="'.newToken().'">';
416print '<input type="hidden" name="action" value="addcomment">';
417print '<input type="hidden" name="id" value="'.urlencode($numsondage).'">';
418print '<input type="hidden" name="page_y" value="">';
419
420print load_fiche_titre($langs->trans("CommentsOfVoters"), '', '');
421
422// Comment list
423$comments = $object->getComments();
424
425if (!empty($comments)) {
426 foreach ($comments as $comment) {
427 if ($user->hasRight('opensurvey', 'write')) {
428 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> ';
429 }
430
431 print dol_htmlentities($comment->usercomment).': '.dol_nl2br(dol_htmlentities($comment->comment))." <br>";
432 }
433} else {
434 print '<span class="opacitymedium">'.$langs->trans("NoCommentYet").'</span><br>';
435}
436
437print '<br>';
438
439// Add comment
440if ($object->allow_comments) {
441 print $langs->trans("AddACommentForPoll").'<br>';
442 print '<textarea name="comment" rows="2" class="quatrevingtpercent"></textarea><br>'."\n";
443 print $langs->trans("Name").': <input type="text" class="minwidth300" name="commentuser" value="'.dol_escape_htmltag($user->getFullName($langs)).'"> '."\n";
444 print '<input type="submit" class="button reposition smallpaddingimp" name="ajoutcomment" value="'.dol_escape_htmltag($langs->trans("AddComment")).'"><br>'."\n";
445}
446
447print '</form>';
448
449// End of page
450llxFooter();
451$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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.
llxFooter()
Footer empty.
Definition document.php:107
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_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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)
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.