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