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