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