dolibarr 21.0.0-beta
buttons.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// Protection if external user
29if ($user->socid > 0) : accessforbidden();
30endif;
31
32// Includes
33dol_include_once('admin/tools/ui/class/documentation.class.php');
34
35// Load documentation translations
36$langs->load('uxdocumentation');
37
38//
39$documentation = new Documentation($db);
40
41// Output html head + body - Param is Title
42$documentation->docHeader('Buttons');
43
44// Set view for menu and breadcrumb
45// Menu must be set in constructor of documentation class
46$documentation->view = array('Components','Buttons');
47
48// Output sidebar
49$documentation->showSidebar(); ?>
50
51<div class="doc-wrapper">
52
53 <?php $documentation->showBreadCrumb(); ?>
54
55 <div class="doc-content-wrapper">
56
57 <h1 class="documentation-title"><?php echo $langs->trans('DocButtonsTitle'); ?></h1>
58 <p class="documentation-text"><?php echo $langs->trans('DocButtonsMainDescription'); ?></p>
59
60 <!-- Summary -->
61 <?php $documentation->showSummary(); ?>
62
63 <!-- Example of simple usage -->
64 <div class="documentation-section" id="buttonsection-basicusage">
65 <h2 class="documentation-title"><?php echo $langs->trans('DocBasicUsage'); ?></h2>
66 <p class="documentation-text"><?php echo $langs->trans('DocButtonBasicUsageDescription'); ?></p>
67 <div class="documentation-example">
68 <?php
69 $label = 'My action label used for accessibility visually for impaired people';
70 $user_right = 1;
71
72 $html = '<span class="fa fa-clone paddingright" aria-hidden="true"></span> My default action';
73 $action_type = 'default';
74 $id = 'button-id-1';
75 $url = '#'.$id;
76 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right);
77
78 $html = '<span class="fa fa-trash-alt paddingright" aria-hidden="true"></span> My delete action';
79 $action_type = 'delete';
80 $id = 'button-id-2';
81 $url = '#'.$id;
82 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right);
83
84 $html = '<span class="fa fa-radiation paddingright" aria-hidden="true"></span> My danger action';
85 $action_type = 'danger';
86 $id = 'button-id-3';
87 $url = '#'.$id;
88 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right); ?>
89
90 <br><br>
91
92 <?php
93 $user_right = 0;
94
95 $html = '<span class="fa fa-clone paddingright" aria-hidden="true"></span> My default action';
96 $action_type = 'default';
97 $id = 'button-id-4';
98 $url = '#'.$id;
99 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right);
100
101 $html = '<span class="fa fa-trash-alt paddingright" aria-hidden="true"></span> My delete action';
102 $action_type = 'delete';
103 $id = 'button-id-5';
104 $url = '#'.$id;
105 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right);
106
107 $html = '<span class="fa fa-radiation paddingright" aria-hidden="true"></span> My danger action';
108 $action_type = 'danger';
109 $id = 'button-id-6';
110 $url = '#'.$id;
111 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right); ?>
112 </div>
113 <?php
114 $lines = array(
115 '<?php',
116 '
128',
129 'print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);',
130 );
131 echo $documentation->showCode($lines); ?>
132 </div>
133
134 <!-- Example of modal usage -->
135 <div class="documentation-section" id="buttonsection-modals">
136 <h2 class="documentation-title"><?php echo $langs->trans('DocButtonModal'); ?></h2>
137 <p class="documentation-text"><?php echo $langs->trans('DocButtonModalDescription'); ?></p>
138 <div class="documentation-example">
139 <?php
140 $userRight = 1;
141
142 $html = '<span class="fa fa-clone" paddingright" aria-hidden="true"></span> My default action';
143 $actionType = 'default';
144 $id = 'button-id-7';
145 $url = '#'.$id;
146 $params = array(
147 'confirm' => true
148 );
149 print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);
150
151 $html = '<span class="fa fa-trash-alt paddingright" aria-hidden="true"></span> My delete action';
152 $actionType = 'delete';
153 $id = 'button-id-8';
154 $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id;
155 $params = array(
156 'confirm' => array(
157 'url' => 'your confirm action url',
158 'title' => 'Your title to display',
159 'action-btn-label' => 'Your confirm label',
160 'cancel-btn-label' => 'Your cancel label',
161 'content' => 'Content to display with <strong>HTML</strong> compatible <ul><li>test 01</li><li>test 02</li><li>test 03</li></ul>'
162 )
163 );
164 print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);
165
166 $userRight = 0;
167
168 $html = '<span class="fa fa-clone" ></span> My default action';
169 $actionType = 'delete';
170 $id = 'button-id-9';
171 $url = '#'.$id;
172 $params = array(
173 'confirm' => true
174 );
175 print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); ?>
176 </div>
177 <?php
178 $lines = array(
179 '<?php',
180 '// Default parameters',
181 '$params = array(',
182 ' \'confirm\' => true',
183 ');',
184 '',
185 '// Custom parameters',
186 '$params = array(',
187 ' \'confirm\' => array(',
188 ' \'url\' => \'your confirm action url\',',
189 ' \'title\' => \'Your title to display\',',
190 ' \'action-btn-label\' => \'Your confirm label\',',
191 ' \'cancel-btn-label\' => \'Your cancel label\',',
192 ' \'content\' => \'Content to display with <strong>HTML</strong> compatible <ul><li>test 01</li><li>test 02</li><li>test 03</li></ul>\'',
193 ' )',
194 ');',
195 '',
196 'print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);',
197 );
198 echo $documentation->showCode($lines); ?>
199 </div>
200
201 <!-- Example of subbutton usage -->
202 <div class="documentation-section" id="buttonsection-submenu">
203 <h2 class="documentation-title"><?php echo $langs->trans('DocButtonSubmenu'); ?></h2>
204 <p class="documentation-text"><?php echo $langs->trans('DocButtonSubmenuDescription'); ?></p>
205 <div class="documentation-example">
206 <?php
207 $userRight = 1;
208 $html = '<span class="fa fa-clone" paddingright" aria-hidden="true"></span> My default action';
209 $actionType = 'default';
210 $id = 'button-id-7';
211 $submenu_url = str_replace(DOL_URL_ROOT, '', $_SERVER['PHP_SELF']);
212 $url = array(
213 array(
214 'lang'=>'documentation@documentation',
215 'url'=> $submenu_url.'#'.$id,
216 'label' => 'My SubAction 1',
217 'perm' => 1
218 ),
219 array(
220 'lang'=>'documentation@documentation',
221 'url'=> $submenu_url.'#'.$id,
222 'label' => 'My SubAction 2',
223 'perm' => 0
224 ),
225 );
226 $params = array();
227 print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); ?>
228 </div>
229 <?php
230 $lines = array(
231 '<?php',
232 '// Simple button',
233 '$url = \'url_script\';',
234 'print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);',
235 '',
236 '// Dropdown button',
237 '$url = array(',
238 ' array(',
239 ' \'lang\' => \'langfile\',',
240 ' \'url\' => \'url_script_1\', // Url without DOL_URL_ROOT',
241 ' \'label\' => \'My SubAction 1\',',
242 ' \'perm\' => 1, // The user have the rights',
243 ' ),',
244 ' array(',
245 ' \'lang\' => \'langfile\',',
246 ' \'url\' => \'url_script_2\', // Url without DOL_URL_ROOT',
247 ' \'label\' => \'My SubAction 2\',',
248 ' \'perm\' => 0, // The user does not have the rights',
249 ' ),',
250 ');',
251 'print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);'
252 );
253 echo $documentation->showCode($lines); ?>
254 </div>
255
256
257 <!-- Example of subbutton usage -->
258 <div class="documentation-section" id="buttonsection-icon-btn">
259 <h2 class="documentation-title"><?php echo $langs->trans('DocButtonIconsLowEmphasis'); ?></h2>
260 <p class="documentation-text"><?php echo $langs->trans('DocButtonIconsDescriptionLowEmphasis'); ?></p>
261 <div class="documentation-example">
262 <?php
263 $btnLabel = $langs->trans('Label');
264 print ' <button class="btn-low-emphasis --btn-icon" title="'.dol_escape_htmltag($btnLabel).'" aria-label="'.dol_escape_htmltag($btnLabel).'" >'.img_picto($btnLabel, 'fa-arrow-right', 'aria-hidden="true"', 0, 0, 1).'</button>';
265
266 $btnLabel = $langs->trans('Reset');
267 print ' <button class="btn-low-emphasis --btn-icon" title="'.dol_escape_htmltag($btnLabel).'" aria-label="'.dol_escape_htmltag($btnLabel).'" >'.img_picto($btnLabel, 'eraser', 'aria-hidden="true"', 0, 0, 1).'</button>';
268 ?>
269 </div>
270 <?php
271 $lines = array(
272 '<?php',
273 '$btnLabel = $langs->trans(\'Label\');',
274 'print \' <button class="btn-low-emphasis --btn-icon" title="\'.dol_escape_htmltag($btnLabel).\'" aria-label="\'.dol_escape_htmltag($btnLabel).\'" >\'.img_picto($btnLabel, \'fa-arrow-right\', \'aria-hidden="true"\', 0, 0, 1).\'</button>\';',
275 '',
276 '$btnLabel = $langs->trans(\'Reset\');',
277 'print \' <button class="btn-low-emphasis --btn-icon" title="\'.dol_escape_htmltag($btnLabel).\'" aria-label="\'.dol_escape_htmltag($btnLabel).\'" >\'.img_picto($btnLabel, \'eraser\', \'aria-hidden="true"\', 0, 0, 1).\'</button>\';',
278
279 );
280 echo $documentation->showCode($lines); ?>
281 </div>
282
283 <!-- Example of subbutton usage -->
284 <div class="documentation-section" id="buttonsection-icon-btn">
285 <h2 class="documentation-title"><?php echo $langs->trans('DocButtonIconsForTitle'); ?></h2>
286 <div class="documentation-example">
287 <?php
288
289
290 $btnLabel = $langs->trans('Label');
291 print dolGetButtonTitle($btnLabel, '', 'fa fa-file', '#', '', 0); // Not Enough Permissions
292 print dolGetButtonTitle($btnLabel, '', 'fa fa-file', '#', '', 1); // Active
293 print dolGetButtonTitle($btnLabel, '', 'fa fa-file', '#', '', 2); // Active and selected
294 print dolGetButtonTitle($btnLabel, '', 'fa fa-file', '#', '', -1); // Functionality is disabled
295 print dolGetButtonTitle($btnLabel, '', 'fa fa-file', '#', '', -2); // Disabled without info
296
297
298 ?>
299 </div>
300 <?php
301 $lines = array(
302 '<?php',
303 '$btnLabel = $langs->trans(\'Label\');',
304 '$status = 0; // Not Enough Permissions',
305 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-file\', \'#\', \'\', $status);',
306 '$status = 1; // Active',
307 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-file\', \'#\', \'\', $status);',
308 '$status = 2; // Active and selected',
309 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-file\', \'#\', \'\', $status);',
310 '$status = -1; // Functionality is disabled',
311 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-file\', \'#\', \'\', $status);',
312 '$status = -2; // Disabled without info',
313 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-file\', \'#\', \'\', $status);',
314 );
315
316 echo $documentation->showCode($lines); ?><div class="documentation-example">
317 <?php
318
319
320 $btnLabel = $langs->trans('Label');
321 print dolGetButtonTitle($btnLabel, '', 'fa fa-download', '#', '', 0, ['forcenohideoftext'=>1]); // Not Enough Permissions
322 print dolGetButtonTitle($btnLabel, '', 'fa fa-download', '#', '', 1, ['forcenohideoftext'=>1]); // Active
323 print dolGetButtonTitle($btnLabel, '', 'fa fa-download', '#', '', 2, ['forcenohideoftext'=>1]); // Active and selected
324 print dolGetButtonTitle($btnLabel, '', 'fa fa-download', '#', '', -1, ['forcenohideoftext'=>1]); // Functionality is disabled
325 print dolGetButtonTitle($btnLabel, '', 'fa fa-download', '#', '', -2, ['forcenohideoftext'=>1]); // Disabled without info
326
327
328 ?>
329 </div>
330
331 <?php
332 $lines = array(
333 '<?php',
334 '$btnLabel = $langs->trans(\'Label\');',
335 '$status = 0; // Not Enough Permissions',
336 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-download\', \'#\', \'\', $status, [\'forcenohideoftext\'=>1]);',
337 '$status = 1; // Active',
338 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-download\', \'#\', \'\', $status, [\'forcenohideoftext\'=>1]);',
339 '$status = 2; // Active and selected',
340 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-download\', \'#\', \'\', $status, [\'forcenohideoftext\'=>1]);',
341 '$status = -1; // Functionality is disabled',
342 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-download\', \'#\', \'\', $status, [\'forcenohideoftext\'=>1]);',
343 '$status = -2; // Disabled without info',
344 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-download\', \'#\', \'\', $status, [\'forcenohideoftext\'=>1]);',
345 );
346 echo $documentation->showCode($lines); ?>
347 </div>
348
349
350
351
352
353
354
355 </div>
356
357</div>
358<?php
359// Output close body + html
360$documentation->docFooter();
361?>
$id
Definition account.php:48
Class to manage UI documentation.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
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.
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...
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.