dolibarr 25.0.0-alpha
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-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
41require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
42require_once DOL_DOCUMENT_ROOT . '/core/lib/doleditor.lib.php';
43require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
44require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
45
46// Load translation files required by the page
47$langs->loadLangs(array('main', 'admin', 'subtotals', 'errors'));
48$action = GETPOST('action', 'aZ09');
49
50if (!$user->admin) {
52}
53
54$formother = new FormOther($db);
55
56// default color const
57$default = 'ffffff';
58
59// Constant and translation of the module description
60$modules = [
61 'PROPAL' => array('lang' => 'propal', 'key' => 'Proposal', 'old_pdf' => '(azur model)'),
62 'COMMANDE' => array('lang' => 'orders', 'key' => 'CustomerOrder', 'old_pdf' => '(einstein model)'),
63 'FICHINTER' => array('lang' => 'interventions', 'key' => 'Intervention', 'old_pdf' => '(soleil model)'),
64 'FACTURE' => array('lang' => 'bills', 'key' => 'CustomerInvoice', 'old_pdf' => '(crabe model)'),
65 'FACTUREREC' => array('lang' => 'bills', 'key' => 'RecurringInvoiceTemplate'),
66 'SUPPLIER_PROPOSAL' => [
67 'lang' => 'supplier_proposal',
68 'key' => 'SupplierProposal',
69 'old_pdf' => '(aurore model)',
70 ],
71 'ORDER_SUPPLIER' => [
72 'lang' => 'orders',
73 'key' => 'SupplierOrder',
74 'old_pdf' => '(muscadet model)',
75 ],
76 'INVOICE_SUPPLIER' => [
77 'lang' => 'bills',
78 'key' => 'SupplierInvoice',
79 ],
80];
81// Conditions for the option to be offered
82$conditions = [
83 'PROPAL' => isModEnabled("propal"),
84 'COMMANDE' => isModEnabled("order"),
85 'FICHINTER' => (isModEnabled("intervention")),
86 'FACTURE' => isModEnabled("invoice"),
87 'FACTUREREC' => isModEnabled("invoice"),
88 'SUPPLIER_PROPOSAL' => isModEnabled("supplier_proposal"),
89 'ORDER_SUPPLIER' => isModEnabled("supplier_order"),
90 'INVOICE_SUPPLIER' => isModEnabled("supplier_invoice"),
91];
92
93$max_depth = 0;
94
95foreach ($modules as $const => $desc) {
96 $const_depth = getDolGlobalString('SUBTOTAL_' . $const . '_MAX_DEPTH', 2);
97
98 $constante_title = 'SUBTOTAL_TITLE_' . $const;
99 $constante_subtotal = 'SUBTOTAL_' . $const;
100 if (getDolGlobalString($constante_title) || getDolGlobalString($constante_subtotal)) {
101 $max_depth = max($const_depth, $max_depth);
102 }
103}
104
105$colors = array();
106
107for ($i = 0; $i < $max_depth; $i++) {
108 $colors['SUBTOTAL_BACK_COLOR_LEVEL_' . ($i + 1)] = array('level' => $i + 1, 'color' => getDolGlobalString('SUBTOTAL_BACK_COLOR_LEVEL_' . ($i + 1), $default));
109}
110
111/*
112 * Actions
113 */
114
115if (preg_match('/^SUBTOTAL_.*$/', $action)) {
116 if (preg_match('/^.*_MAX_DEPTH$/', $action)) {
117 dolibarr_set_const($db, $action, GETPOSTINT($action), 'int', 0, '', $conf->entity);
118 header("Location: " . $_SERVER['PHP_SELF']);
119 setEventMessages($langs->trans("SetupSaved"), null);
120 exit;
121 } else {
122 $value = getDolGlobalInt($action, 0);
123 $value == 0 ? $value = 1 : $value = 0;
124 dolibarr_set_const($db, $action, $value, 'chaine', 0, '', $conf->entity);
125 header("Location: " . $_SERVER['PHP_SELF']);
126 setEventMessages($langs->trans("SetupSaved"), null);
127 exit;
128 }
129}
130
131if ($action == 'update_colors') {
132 foreach ($colors as $const => $color) {
133 $color_to_update = GETPOST($const, 'aZ09');
134 if ($color_to_update != $color['color']) {
135 dolibarr_set_const($db, $const, $color_to_update, 'chaine', 0, '', $conf->entity);
136 }
137 }
138
139 header("Location: " . $_SERVER["PHP_SELF"]);
140 exit;
141}
142
143
144/*
145 * View
146 */
147
148llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-subtotals');
149
150$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
151
152print load_fiche_titre($langs->trans("SubtotalSetup"), $linkback, 'title_setup');
153
154if (empty($conf->use_javascript_ajax)) {
155 setEventMessages(null, array($langs->trans("NotAvailable"), $langs->trans("JavascriptDisabled")), 'errors');
156} else {
157 print '<table class="noborder centpercent">';
158 print '<tr class="liste_titre">';
159 print '<td width="1100">' . $langs->trans("Settings") . '</td>';
160 print '<td class="center">' . $langs->trans("Title") . '</td>';
161 print '<td class="center">' . $langs->trans("SubTotal") . '</td>';
162 print '<td class="center">' . $langs->trans("SubtotalTextColumnTitle") . '</td>';
163 print '<td class="center">' . $langs->trans("MaxSubtotalLevel") . '</td>';
164 print "</tr>\n";
165
166 // Modules
167 foreach ($modules as $const => $desc) {
168 // If this condition is not met, the option is not offered
169 if (!$conditions[$const]) {
170 continue;
171 }
172
173 $langs->load($desc['lang']);
174
175 $constante_title = 'SUBTOTAL_TITLE_' . $const;
176 $constante_subtotal = 'SUBTOTAL_' . $const;
177 $constante_text = 'SUBTOTAL_TEXT_' . $const;
178 print '<!-- constant = ' . $constante_subtotal . ' -->' . "\n";
179 print '<tr class="oddeven">';
180 print '<td>';
181 if (isset($desc['old_pdf'])) {
182 print $form->textwithpicto($langs->trans($desc['key']), $langs->trans("NotSupportedByAllPDF", $desc['old_pdf']));
183 } else {
184 print $langs->trans($desc['key']);
185 }
186 print '</td>';
187
188 print '<td class="center">';
189 $value_title = getDolGlobalInt($constante_title, 0);
190 print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=' . $constante_title . '&token=' . newToken() . '">';
191 print $value_title == 0 ? img_picto($langs->trans("Disabled"), 'switch_off') : img_picto($langs->trans("Enabled"), 'switch_on') . '</a>';
192 print '</td>';
193
194 print '<td class="center">';
195 $value_subtotal = getDolGlobalInt($constante_subtotal, 0);
196 print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=' . $constante_subtotal . '&token=' . newToken() . '">';
197 print $value_subtotal == 0 ? img_picto($langs->trans("Disabled"), 'switch_off') : img_picto($langs->trans("Enabled"), 'switch_on') . '</a>';
198 print '</td>';
199
200 print '<td class="center">';
201 $value_text = getDolGlobalInt($constante_text, 0);
202 print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=' . $constante_text . '&token=' . newToken() . '">';
203 print $value_text == 0 ? img_picto($langs->trans("Disabled"), 'switch_off') : img_picto($langs->trans("Enabled"), 'switch_on') . '</a>';
204 print '</td>';
205
206 print '<td class="center nowraponall">';
207 $can_modify = !($value_subtotal == 0 && $value_title == 0);
208 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '" spellcheck="false">';
209 print '<input type="hidden" name="token" value="' . newToken() . '">';
210 print '<input type="hidden" name="action" value="SUBTOTAL_' . $const . '_MAX_DEPTH">';
211 print '<input size="3" type="text" class="center"';
212 print $can_modify ? '' : ' disabled="disabled" ';
213 print 'name="SUBTOTAL_' . $const . '_MAX_DEPTH" value="' . getDolGlobalString('SUBTOTAL_' . $const . '_MAX_DEPTH', $can_modify ? 2 : 0) . '">';
214 print $can_modify ? '<input type="submit" class="button button-edit reposition smallpaddingimp" name="Button"value="' . $langs->trans("Modify") . '">' : '';
215 print '</form>';
216 print '</td>';
217
218 print '</tr>';
219 }
220
221 print '</table>';
222
223 // Other options
224
225 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '" spellcheck="false">';
226 print '<input type="hidden" name="token" value="' . newToken() . '">';
227 print '<input type="hidden" name="action" value="update_colors">';
228
229 print '<table class="noborder centpercent">';
230 print '<tr class="liste_titre">';
231 print '<td>' . $langs->trans("Other") . '</td>';
232 print '<td></td>';
233 print "</tr>\n";
234
235 foreach ($colors as $key => $value) {
236 print '<tr class="oddeven">';
237 print '<td>' . $langs->trans("SubtotalLineBackColor", $value['level']) . '</td>';
238 print '<td class="center width250">';
239 print $formother->selectColor(colorArrayToHex(colorStringToArray($value['color'], array()), $default), $key, '', 1, array(), '', '', $default) . ' ';
240 print ' &nbsp; <span class="nowraponall opacitymedium">' . $langs->trans("Default") . '</span>: <strong>' . $default . '</strong>';
241 print $form->textwithpicto('', $langs->trans("NotSupportedByAllThemes") . ', ' . $langs->trans("PressF5AfterChangingThis"));
242 print '</td>';
243 print '</tr>';
244 }
245
246 print '</table>' . "\n";
247}
248
249print '<div class="center">';
250print '<input class="button button-save reposition buttonforacesave" type="submit" name="submit" value="' . $langs->trans("Save") . '">';
251print '<input class="button button-cancel reposition" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
252print '</div>';
253
254// End of page
255llxFooter();
256$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 to help generate other html components Only common components are here.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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,...
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.