dolibarr 21.0.0-beta
event-message.php
1<?php
2/*
3 * Copyright (C) 2024 Anthony Damhet <a.damhet@progiseize.fr>
4 *
5 * This program and files/directory inner it is free software: you can
6 * redistribute it and/or modify it under the terms of the
7 * GNU Affero General Public License (AGPL) 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 AGPL for more details.
15 *
16 * You should have received a copy of the GNU AGPL
17 * along with this program. If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.
18 */
19
20$res=0;
21if (! $res && file_exists("../../main.inc.php")) : $res=@include '../../main.inc.php';
22endif;
23if (! $res && file_exists("../../../main.inc.php")) : $res=@include '../../../main.inc.php';
24endif;
25if (! $res && file_exists("../../../../main.inc.php")) : $res=@include '../../../../main.inc.php';
26endif;
27
28
29// Protection if external user
30if ($user->socid > 0) : accessforbidden();
31endif;
32
33// Includes
34dol_include_once('admin/tools/ui/class/documentation.class.php');
35
36// Load documentation translations
37$langs->load('uxdocumentation');
38
39$action = GETPOST('action', 'alpha');
40
41if ($action == 'displayeventmessage') {
42 setEventMessages($langs->trans('DocSetEventMessageUnique'), null);
43} elseif ($action == 'displayeventmessages') {
44 $messageArray = [$langs->trans('DocSetEventMessage', '1'),
45 $langs->trans('DocSetEventMessage', '2'),
46 $langs->trans('DocSetEventMessage', '3')];
47 setEventMessages(null, $messageArray);
48} elseif ($action == 'displayeventmessageok') {
49 setEventMessages($langs->trans('DocSetEventMessageOK'), null);
50} elseif ($action == 'displayeventmessagewarning') {
51 setEventMessages($langs->trans('DocSetEventMessageWarning'), null, 'warnings');
52} elseif ($action == 'displayeventmessageerror') {
53 setEventMessages($langs->trans('DocSetEventMessageError'), null, 'errors');
54}
55
56//
57$documentation = new Documentation($db);
58
59// Output html head + body - Param is Title
60$documentation->docHeader('SetEventMessages');
61
62// Set view for menu and breadcrumb
63// Menu must be set in constructor of documentation class
64$documentation->view = array('Components','Event Message');
65
66// Output sidebar
67$documentation->showSidebar(); ?>
68
69<div class="doc-wrapper">
70
71 <?php $documentation->showBreadCrumb(); ?>
72
73 <div class="doc-content-wrapper">
74
75 <h1 class="documentation-title"><?php echo $langs->trans('DocSetEventMessageTitle'); ?></h1>
76 <p class="documentation-text"><?php echo $langs->trans('DocSetEventMessageMainDescription'); ?></p>
77
78 <!-- Summary -->
79 <?php $documentation->showSummary(); ?>
80
81 <!-- Basic usage -->
82 <div class="documentation-section" id="seteventmessagesection-basicusage">
83 <h2 class="documentation-title"><?php echo $langs->trans('DocBasicUsage'); ?></h2>
84 <p class="documentation-text"><?php echo $langs->trans('DocSetEventMessageDescription'); ?></p>
85 <div class="documentation-example">
86 <?php
87 $label = 'My action label used for accessibility visually for impaired people';
88 $user_right = 1;
89
90 $html = '<span class="fa fa-comment paddingright"></span>'.$langs->trans('DocSetEventMessageDisplayMessage');
91 $action_type = 'displayeventmessage';
92 $url = $_SERVER["PHP_SELF"].'?action=displayeventmessage';
93 print dolGetButtonAction($label, $html, $action_type, $url, '', $user_right);
94
95 $label = 'My action label used for accessibility visually for impaired people';
96 $user_right = 1;
97
98 $html = '<span class="fa fa-comments paddingright"></span>'.$langs->trans('DocSetEventMessageDisplayMessages');;
99 $action_type = 'displayeventmessages';
100 $url = $_SERVER["PHP_SELF"].'?action=displayeventmessages';
101 print dolGetButtonAction($label, $html, $action_type, $url, '', $user_right); ?>
102 </div>
103 <?php
104 $lines = array(
105 '<?php',
106 '
119',
120 '',
121 'setEventMessages("message", null);',
122 'setEventMessages(null, messages[]);',
123 );
124 echo $documentation->showCode($lines); ?>
125 </div>
126
127 <!-- Contextual variations -->
128 <div class="documentation-section" id="seteventmessagesection-contextvariations">
129 <h2 class="documentation-title"><?php echo $langs->trans('DocSetEventMessageContextualVariations'); ?></h2>
130 <p class="documentation-text"><?php echo $langs->trans('DocSetEventMessageContextualVariationsDescription'); ?></p>
131 <div class="documentation-example">
132 <?php
133 $label = 'My action label used for accessibility visually for impaired people';
134 $user_right = 1;
135 $html = '<span class="fa fa-comment paddingright"></span>'.$langs->trans('DocSetEventMessageDisplayOKMessage');;
136 $action_type = 'displayeventmessageok';
137 $url = $_SERVER["PHP_SELF"].'?action=displayeventmessageok#seteventmessagesection-contextvariations';
138 $params['attr']['style'] = 'background: #446548';
139 print dolGetButtonAction('', $html, $action_type, $url, '', $user_right, $params);
140
141 $label = 'My action label used for accessibility visually for impaired people';
142 $user_right = 1;
143 $html = '<span class="fa fa-comment paddingright"></span>'.$langs->trans('DocSetEventMessageDisplayWarningMessage');;
144 $action_type = 'displayeventmessagewarning';
145 $url = $_SERVER["PHP_SELF"].'?action=displayeventmessagewarning#seteventmessagesection-contextvariations';
146 $params['attr']['style'] = 'background: #a28918';
147 print dolGetButtonAction($label, $html, $action_type, $url, '', $user_right, $params);
148
149 $label = 'My action label used for accessibility visually for impaired people';
150 $user_right = 1;
151 $html = '<span class="fa fa-comment paddingright"></span>'.$langs->trans('DocSetEventMessageDisplayErrorMessage');;
152 $action_type = 'displayeventmessageerror';
153 $url = $_SERVER["PHP_SELF"].'?action=displayeventmessageerror#seteventmessagesection-contextvariations';
154 $params['attr']['style'] = 'background: #a72947';
155 print dolGetButtonAction($label, $html, $action_type, $url, '', $user_right, $params); ?>
156 </div>
157 <?php
158 $lines = array(
159 'setEventMessages("message", null)',
160 'setEventMessages("message", null, "warnings")',
161 'setEventMessages("message", null, "errors")'
162 );
163 echo $documentation->showCode($lines); ?>
164 </div>
165 <!-- -->
166 </div>
167
168</div>
169
170<?php
171// Output close body + html
172$documentation->docFooter();
173
174?>
Class to manage UI documentation.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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.