dolibarr 22.0.5
subtotals.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2012-2013 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2019 Christophe Battarel <christophe@altairis.fr>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT . '/core/lib/doleditor.lib.php';
33require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
34require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
35
45// Load translation files required by the page
46$langs->loadLangs(array('main', 'admin', 'subtotals', 'errors'));
47$action = GETPOST('action', 'aZ09');
48
49if (!$user->admin) {
51}
52
53$formother = new FormOther($db);
54
55// default color const
56$default = 'ffffff';
57
58// Constant and translation of the module description
59$modules = array(
60 'PROPAL' => array('lang' => 'propal', 'key' => 'Proposal', 'old_pdf' => '(azur model)'),
61 'COMMANDE' => array('lang' => 'orders', 'key' => 'CustomerOrder', 'old_pdf' => '(einstein model)'),
62 'FACTURE' => array('lang' => 'bills', 'key' => 'CustomerInvoice', 'old_pdf' => '(crabe model)'),
63 'FACTUREREC' => array('lang' => 'bills', 'key' => 'RecurringInvoiceTemplate'),
64);
65// Conditions for the option to be offered
66$conditions = array(
67 'PROPAL' => (isModEnabled("propal")),
68 'COMMANDE' => (isModEnabled("order")),
69 'FACTURE' => (isModEnabled("invoice")),
70 'FACTUREREC' => (isModEnabled("invoice")),
71);
72
73$max_depth = 0;
74
75foreach ($modules as $const => $desc) {
76 $const_depth = getDolGlobalString('SUBTOTAL_' . $const . '_MAX_DEPTH');
77 $max_depth = max($const_depth, $max_depth);
78}
79
80$colors = array();
81
82for ($i = 0; $i < $max_depth; $i++) {
83 $colors['SUBTOTAL_BACK_COLOR_LEVEL_' . ($i + 1)] = array('level' => $i + 1, 'color' => getDolGlobalString('SUBTOTAL_BACK_COLOR_LEVEL_' . ($i + 1), $default));
84}
85
86/*
87 * Actions
88 */
89
90if (preg_match('/^SUBTOTAL_.*$/', $action)) {
91 if (preg_match('/^.*_MAX_DEPTH$/', $action)) {
92 dolibarr_set_const($db, $action, GETPOSTINT($action), 'int', 0, '', $conf->entity);
93 header("Location: " . $_SERVER['PHP_SELF']);
94 setEventMessages($langs->trans("SetupSaved"), null);
95 exit;
96 } else {
97 $value = getDolGlobalInt($action, 0);
98 $value == 0 ? $value = 1 : $value = 0;
99 dolibarr_set_const($db, $action, $value, 'chaine', 0, '', $conf->entity);
100 header("Location: " . $_SERVER['PHP_SELF']);
101 setEventMessages($langs->trans("SetupSaved"), null);
102 exit;
103 }
104}
105
106if ($action == 'update_colors') {
107 foreach ($colors as $const => $color) {
108 $color_to_update = GETPOST($const, 'aZ09');
109 if ($color_to_update != $color['color']) {
110 dolibarr_set_const($db, $const, $color_to_update, 'chaine', 0, '', $conf->entity);
111 }
112 }
113
114 header("Location: " . $_SERVER["PHP_SELF"]);
115 exit;
116}
117
118
119/*
120 * View
121 */
122
123llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-subtotals');
124$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
125
126print load_fiche_titre($langs->trans("SubtotalSetup"), $linkback, 'title_setup');
127
128if (empty($conf->use_javascript_ajax)) {
129 setEventMessages(null, array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), 'errors');
130} else {
131 print '<table class="noborder centpercent">';
132 print '<tr class="liste_titre">';
133 print '<td width="1100">' . $langs->trans("Settings") . '</td>';
134 print '<td class="center">' . $langs->trans("Title") . '</td>';
135 print '<td class="center">' . $langs->trans("Subtotal") . '</td>';
136 print '<td class="center">' . $langs->trans("MaxSubtotalLevel") . '</td>';
137 print "</tr>\n";
138
139 // Modules
140 foreach ($modules as $const => $desc) {
141 // If this condition is not met, the option is not offered
142 if (!$conditions[$const]) {
143 continue;
144 }
145
146 $langs->load($desc['lang']);
147
148 $constante_title = 'SUBTOTAL_TITLE_' . $const;
149 $constante_subtotal = 'SUBTOTAL_' . $const;
150 print '<!-- constant = ' . $constante_subtotal . ' -->' . "\n";
151 print '<tr class="oddeven">';
152 print '<td>';
153 if (isset($desc['old_pdf'])) {
154 print $form->textwithpicto($langs->trans($desc['key']), $langs->trans("NotSupportedByAllPDF", $desc['old_pdf']));
155 } else {
156 print $langs->trans($desc['key']);
157 }
158 print '</td>';
159
160 print '<td class="center">';
161 $value_title = getDolGlobalInt($constante_title, 0);
162 print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=' . $constante_title . '&token=' . newToken() . '">';
163 print $value_title == 0 ? img_picto($langs->trans("Disabled"), 'switch_off') : img_picto($langs->trans("Enabled"), 'switch_on') . '</a>';
164 print '</td>';
165
166 print '<td class="center">';
167 $value_subtotal = getDolGlobalInt($constante_subtotal, 0);
168 print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=' . $constante_subtotal . '&token=' . newToken() . '">';
169 print $value_subtotal == 0 ? img_picto($langs->trans("Disabled"), 'switch_off') : img_picto($langs->trans("Enabled"), 'switch_on') . '</a>';
170 print '</td>';
171
172 print '<td class="center">';
173 $can_modify = !($value_subtotal == 0 && $value_title == 0);
174 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '" >';
175 print '<input type="hidden" name="token" value="' . newToken() . '">';
176 print '<input type="hidden" name="action" value="SUBTOTAL_' . $const . '_MAX_DEPTH">';
177 print '<input size="3" type="text"';
178 print $can_modify ? '' : ' disabled="disabled" ';
179 print 'name="SUBTOTAL_' . $const . '_MAX_DEPTH" value="' . getDolGlobalString('SUBTOTAL_' . $const . '_MAX_DEPTH', $can_modify ? 2 : 0) . '">';
180 print $can_modify ? '<input type="submit" class="button button-edit reposition smallpaddingimp" name="Button"value="' . $langs->trans("Modify") . '">' : '';
181 print '</form>';
182 print '</td>';
183
184 print '</tr>';
185 }
186
187 print '</table>';
188
189 // Other options
190
191 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
192 print '<input type="hidden" name="token" value="' . newToken() . '">';
193 print '<input type="hidden" name="action" value="update_colors">';
194
195 print '<table class="noborder centpercent">';
196 print '<tr class="liste_titre">';
197 print '<td>' . $langs->trans("Other") . '</td>';
198 print '<td></td>';
199 print "</tr>\n";
200
201 foreach ($colors as $key => $value) {
202 print '<tr class="oddeven">';
203 print '<td>' . $langs->trans("SubtotalLineBackColor", $value['level']) . '</td>';
204 print '<td class="center width250">';
205 print $formother->selectColor(colorArrayToHex(colorStringToArray($value['color'], array()), $default), $key, '', 1, array(), '', '', $default) . ' ';
206 print ' &nbsp; <span class="nowraponall opacitymedium">' . $langs->trans("Default") . '</span>: <strong>' . $default . '</strong>';
207 print $form->textwithpicto('', $langs->trans("NotSupportedByAllThemes") . ', ' . $langs->trans("PressF5AfterChangingThis"));
208 print '</td>';
209 print '</tr>';
210 }
211
212 print '</table>' . "\n";
213}
214
215print '<div class="center">';
216print '<input class="button button-save reposition buttonforacesave" type="submit" name="submit" value="' . $langs->trans("Save") . '">';
217print '<input class="button button-cancel reposition" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
218print '</div>';
219
220// End of page
221llxFooter();
222$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class permettant la generation de composants html autre Only common components are here.
colorArrayToHex($arraycolor, $colorifnotfound='888888')
Convert an array with RGB value into hex RGB value.
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,...
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_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.