dolibarr 21.0.0-beta
event-message.php
1<?php
2/*
3 * Copyright (C) 2024 Anthony Damhet <a.damhet@progiseize.fr>
4 * Copyright (C) 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
20// Load Dolibarr environment
21require '../../../../main.inc.php';
22
30// Protection if external user
31if ($user->socid > 0) {
33}
34
35// Includes
36require_once DOL_DOCUMENT_ROOT . '/admin/tools/ui/class/documentation.class.php';
37
38// Load documentation translations
39$langs->load('uxdocumentation');
40
41$action = GETPOST('action', 'alpha');
42
43if ($action == 'displayeventmessage') {
44 setEventMessages($langs->trans('DocSetEventMessageUnique'), null);
45} elseif ($action == 'displayeventmessages') {
46 $messageArray = [$langs->trans('DocSetEventMessage', '1'),
47 $langs->trans('DocSetEventMessage', '2'),
48 $langs->trans('DocSetEventMessage', '3')];
49 setEventMessages(null, $messageArray);
50} elseif ($action == 'displayeventmessageok') {
51 setEventMessages($langs->trans('DocSetEventMessageOK'), null);
52} elseif ($action == 'displayeventmessagewarning') {
53 setEventMessages($langs->trans('DocSetEventMessageWarning'), null, 'warnings');
54} elseif ($action == 'displayeventmessageerror') {
55 setEventMessages($langs->trans('DocSetEventMessageError'), null, 'errors');
56}
57
58//
59$documentation = new Documentation($db);
60$morejs = [
61 '/includes/ace/src/ace.js',
62 '/includes/ace/src/ext-statusbar.js',
63 '/includes/ace/src/ext-language_tools.js',
64];
65// Output html head + body - Param is Title
66$documentation->docHeader('SetEventMessages', $morejs);
67
68// Set view for menu and breadcrumb
69// Menu must be set in constructor of documentation class
70$documentation->view = array('Components','Event Message');
71
72// Output sidebar
73$documentation->showSidebar(); ?>
74
75<div class="doc-wrapper">
76
77 <?php $documentation->showBreadCrumb(); ?>
78
79 <div class="doc-content-wrapper">
80
81 <h1 class="documentation-title"><?php echo $langs->trans('DocSetEventMessageTitle'); ?></h1>
82 <p class="documentation-text"><?php echo $langs->trans('DocSetEventMessageMainDescription'); ?></p>
83
84 <!-- Summary -->
85 <?php $documentation->showSummary(); ?>
86
87 <!-- Basic usage -->
88 <div class="documentation-section" id="seteventmessagesection-basicusage">
89 <h2 class="documentation-title"><?php echo $langs->trans('DocBasicUsage'); ?></h2>
90 <p class="documentation-text"><?php echo $langs->trans('DocSetEventMessageDescription'); ?></p>
91 <div class="documentation-example">
92 <?php
93 $label = 'My action label used for accessibility visually for impaired people';
94 $user_right = 1;
95
96 $html = '<span class="fa fa-comment paddingright"></span>'.$langs->trans('DocSetEventMessageDisplayMessage');
97 $action_type = 'displayeventmessage';
98 $url = $_SERVER["PHP_SELF"].'?action=displayeventmessage';
99 print dolGetButtonAction($label, $html, $action_type, $url, '', $user_right);
100
101 $label = 'My action label used for accessibility visually for impaired people';
102 $user_right = 1;
103
104 $html = '<span class="fa fa-comments paddingright"></span>'.$langs->trans('DocSetEventMessageDisplayMessages');;
105 $action_type = 'displayeventmessages';
106 $url = $_SERVER["PHP_SELF"].'?action=displayeventmessages';
107 print dolGetButtonAction($label, $html, $action_type, $url, '', $user_right); ?>
108 </div>
109 <?php
110 $lines = array(
111 '<?php',
112 '
125',
126 '',
127 'setEventMessages("message", null);',
128 'setEventMessages(null, messages[]);',
129 );
130 echo $documentation->showCode($lines, 'php'); ?>
131 </div>
132
133 <!-- Contextual variations -->
134 <div class="documentation-section" id="seteventmessagesection-contextvariations">
135 <h2 class="documentation-title"><?php echo $langs->trans('DocSetEventMessageContextualVariations'); ?></h2>
136 <p class="documentation-text"><?php echo $langs->trans('DocSetEventMessageContextualVariationsDescription'); ?></p>
137 <div class="documentation-example">
138 <?php
139 $label = 'My action label used for accessibility visually for impaired people';
140 $user_right = 1;
141 $html = '<span class="fa fa-comment paddingright"></span>'.$langs->trans('DocSetEventMessageDisplayOKMessage');;
142 $action_type = 'displayeventmessageok';
143 $url = $_SERVER["PHP_SELF"].'?action=displayeventmessageok#seteventmessagesection-contextvariations';
144 $params['attr']['style'] = 'background: #446548';
145 print dolGetButtonAction('', $html, $action_type, $url, '', $user_right, $params);
146
147 $label = 'My action label used for accessibility visually for impaired people';
148 $user_right = 1;
149 $html = '<span class="fa fa-comment paddingright"></span>'.$langs->trans('DocSetEventMessageDisplayWarningMessage');;
150 $action_type = 'displayeventmessagewarning';
151 $url = $_SERVER["PHP_SELF"].'?action=displayeventmessagewarning#seteventmessagesection-contextvariations';
152 $params['attr']['style'] = 'background: #a28918';
153 print dolGetButtonAction($label, $html, $action_type, $url, '', $user_right, $params);
154
155 $label = 'My action label used for accessibility visually for impaired people';
156 $user_right = 1;
157 $html = '<span class="fa fa-comment paddingright"></span>'.$langs->trans('DocSetEventMessageDisplayErrorMessage');;
158 $action_type = 'displayeventmessageerror';
159 $url = $_SERVER["PHP_SELF"].'?action=displayeventmessageerror#seteventmessagesection-contextvariations';
160 $params['attr']['style'] = 'background: #a72947';
161 print dolGetButtonAction($label, $html, $action_type, $url, '', $user_right, $params); ?>
162 </div>
163 <?php
164 $lines = array(
165 '<?php',
166 'setEventMessages("message", null)',
167 'setEventMessages("message", null, "warnings")',
168 'setEventMessages("message", null, "errors")'
169 );
170 echo $documentation->showCode($lines, 'php'); ?>
171 </div>
172 <!-- -->
173 </div>
174
175</div>
176
177<?php
178// Output close body + html
179$documentation->docFooter();
180
181?>
Class to manage UI documentation.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
usage($program, $header)
Print the usage when executing scripts from install/.
Definition inc.php:94
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.