1<?php
2/* Copyright (C) 2001-2004  Rodolphe Quiedeville    <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010  Laurent Destailleur     <eldy@users.sourceforge.net>
4 * Copyright (C) 2005       Simon Tosser            <simon@kornog-computing.com>
5 * Copyright (C) 2005-2012  Regis Houssin           <regis.houssin@inodbox.com>
6 * Copyright (C) 2016       Raphaël Doursenaud      <rdoursenaud@gpcsolutions.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22/**
23 *   	\file       htdocs/admin/delais.php
24 *		\brief      Page to setup late delays
25 */
26
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29
30// Load translation files required by the page
31$langs->load("admin");
32
33if (!$user->admin) {
34	accessforbidden();
35}
36
37$action = GETPOST('action', 'aZ09');
38if (empty($action)) {
39	$action = 'edit';
40}
41
42// Define list of managed delays
43$modules = array(
44	'agenda' => array(
45		array(
46			'code' => 'MAIN_DELAY_ACTIONS_TODO',
47			'img' => 'action'
48		)
49	),
50	'projet' => array(
51		array(
52			'code' => 'MAIN_DELAY_PROJECT_TO_CLOSE',
53			'img' => 'project'
54		),
55		array(
56			'code' => 'MAIN_DELAY_TASKS_TODO',
57			'img' => 'projecttask'
58		)
59	),
60	'propal' => array(
61		array(
62			'code' => 'MAIN_DELAY_PROPALS_TO_CLOSE',
63			'img' => 'propal'
64		),
65		array(
66			'code' => 'MAIN_DELAY_PROPALS_TO_BILL',
67			'img' => 'propal'
68		)
69	),
70	'commande' => array(
71		array(
72			'code' => 'MAIN_DELAY_ORDERS_TO_PROCESS',
73			'img' => 'order'
74		)
75	),
76	'facture' => array(
77		array(
78			'code' => 'MAIN_DELAY_CUSTOMER_BILLS_UNPAYED',
79			'img' => 'bill'
80		)
81	),
82	'fournisseur' => array(
83		array(
84			'code' => 'MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS',
85			'img' => 'order'
86		),
87		array(
88			'code' => 'MAIN_DELAY_SUPPLIER_BILLS_TO_PAY',
89			'img' => 'bill'
90		)
91	),
92	'service' => array(
93		array(
94			'code' => 'MAIN_DELAY_NOT_ACTIVATED_SERVICES',
95			'img' => 'service'
96		),
97		array(
98			'code' => 'MAIN_DELAY_RUNNING_SERVICES',
99			'img' => 'service'
100		)
101	),
102	'banque' => array(
103		array(
104			'code' => 'MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE',
105			'img' => 'account'
106		),
107		array(
108			'code' => 'MAIN_DELAY_CHEQUES_TO_DEPOSIT',
109			'img' => 'account'
110		)
111	),
112	'adherent' => array(
113		array(
114			'code' => 'MAIN_DELAY_MEMBERS',
115			'img' => 'user'
116		)
117	),
118	'expensereport' => array(
119		array(
120			'code' => 'MAIN_DELAY_EXPENSEREPORTS',
121			'img' => 'trip'
122		),
123		/* TODO Enable this
124		 array(
125		 'code' => 'MAIN_DELAY_EXPENSEREPORTS_TO_PAY',
126		 'img' => 'trip'
127		 )*/
128	),
129	'holiday' => array(
130		array(
131			'code' => 'MAIN_DELAY_HOLIDAYS',
132			'img' => 'holiday'
133		),
134	),
135);
136
137$labelmeteo = array(0=>$langs->trans("No"), 1=>$langs->trans("Yes"), 2=>$langs->trans("OnMobileOnly"));
138
139if (!isset($conf->global->MAIN_DELAY_PROJECT_TO_CLOSE)) {
140	$conf->global->MAIN_DELAY_PROJECT_TO_CLOSE = 7; // Must be same value than into conf.class.php
141}
142if (!isset($conf->global->MAIN_DELAY_TASKS_TODO)) {
143	$conf->global->MAIN_DELAY_TASKS_TODO = 7; // Must be same value than into conf.class.php
144}
145if (!isset($conf->global->MAIN_DELAY_MEMBERS)) {
146	$conf->global->MAIN_DELAY_MEMBERS = 0; // Must be same value than into conf.class.php
147}
148if (!isset($conf->global->MAIN_DELAY_ACTIONS_TODO)) {
149	$conf->global->MAIN_DELAY_ACTIONS_TODO = 7; // Must be same value than into conf.class.php
150}
151if (!isset($conf->global->MAIN_DELAY_ORDERS_TO_PROCESS)) {
152	$conf->global->MAIN_DELAY_ORDERS_TO_PROCESS = 2;
153}
154if (!isset($conf->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS)) {
155	$conf->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS = 7;
156}
157if (!isset($conf->global->MAIN_DELAY_ORDERS_TO_PROCESS)) {
158	$conf->global->MAIN_DELAY_ORDERS_TO_PROCESS = 2;
159}
160if (!isset($conf->global->MAIN_DELAY_ORDERS_TO_PROCESS)) {
161	$conf->global->MAIN_DELAY_ORDERS_TO_PROCESS = 2;
162}
163if (!isset($conf->global->MAIN_DELAY_ORDERS_TO_PROCESS)) {
164	$conf->global->MAIN_DELAY_ORDERS_TO_PROCESS = 2;
165}
166
167
168
169/*
170 * Actions
171 */
172
173if ($action == 'update') {
174	foreach ($modules as $module => $delays) {
175		if (!empty($conf->$module->enabled)) {
176			foreach ($delays as $delay) {
177				if (GETPOST($delay['code']) != '') {
178					dolibarr_set_const($db, $delay['code'], GETPOST($delay['code']), 'chaine', 0, '', $conf->entity);
179				}
180			}
181		}
182	}
183
184	dolibarr_set_const($db, "MAIN_DISABLE_METEO", GETPOST("MAIN_DISABLE_METEO"), 'chaine', 0, '', $conf->entity);
185	dolibarr_set_const($db, "MAIN_USE_METEO_WITH_PERCENTAGE", GETPOST("MAIN_USE_METEO_WITH_PERCENTAGE"), 'chaine', 0, '', $conf->entity);
186
187	// For update value with percentage
188	$plus = '';
189	if (!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
190		$plus = '_PERCENTAGE';
191	}
192	// Update values
193	for ($i = 0; $i < 4; $i++) {
194		if (GETPOSTISSET('MAIN_METEO'.$plus.'_LEVEL'.$i)) {
195			dolibarr_set_const($db, 'MAIN_METEO'.$plus.'_LEVEL'.$i, GETPOST('MAIN_METEO'.$plus.'_LEVEL'.$i, 'int'), 'chaine', 0, '', $conf->entity);
196		}
197	}
198
199	setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
200
201	$action = 'edit';
202}
203
204
205/*
206 * View
207 */
208
209$form = new Form($db);
210
211llxHeader();
212
213print load_fiche_titre($langs->trans("DelaysOfToleranceBeforeWarning"), '', 'title_setup');
214
215print '<span class="opacitymedium">'.$langs->transnoentities("DelaysOfToleranceDesc", img_warning('default', '', 'pictowarning nopaddingleft'));
216print " ".$langs->trans("OnlyActiveElementsAreShown", DOL_URL_ROOT.'/admin/modules.php')."</span><br>\n";
217print "<br>\n";
218
219if ($action == 'edit') {
220	print '<form method="post" action="'.$_SERVER['PHP_SELF'].'" name="form_index">';
221	print '<input type="hidden" name="token" value="'.newToken().'">';
222	print '<input type="hidden" name="action" value="update">';
223
224	print '<table class="noborder centpercent">';
225	print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("DelaysOfToleranceBeforeWarning").'</td><td class="center" width="120px">'.$langs->trans("Value").'</td></tr>';
226
227	foreach ($modules as $module => $delays) {
228		if (!empty($conf->$module->enabled)) {
229			foreach ($delays as $delay) {
230				$value = (!empty($conf->global->{$delay['code']}) ? $conf->global->{$delay['code']}:0);
231				print '<tr class="oddeven">';
232				print '<td width="20px">'.img_object('', $delay['img']).'</td>';
233				print '<td>'.$langs->trans('Delays_'.$delay['code']).'</td><td class="nowraponall">';
234				print '<input class="right maxwidth75" type="number" name="'.$delay['code'].'" value="'.$value.'"> '.$langs->trans("days").'</td></tr>';
235			}
236		}
237	}
238
239	print '</table>';
240
241	print '<br>';
242
243	// Show if meteo is enabled
244	print '<table class="noborder centpercent">';
245	print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td class="center" width="120px">'.$langs->trans("Value").'</td></tr>';
246
247	print '<tr class="oddeven">';
248	print '<td>'.$langs->trans("MAIN_DISABLE_METEO").'</td><td class="center">';
249	print $form->selectarray('MAIN_DISABLE_METEO', $labelmeteo, (empty($conf->global->MAIN_DISABLE_METEO) ? 0 : $conf->global->MAIN_DISABLE_METEO));
250	print '</td></tr>';
251
252	print '</table>';
253} else {
254	/*
255	 * Show parameters
256	 */
257
258	print '<table class="noborder centpercent">';
259	print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("DelaysOfToleranceBeforeWarning").'</td><td class="center" width="120px">'.$langs->trans("Value").'</td></tr>';
260
261	foreach ($modules as $module => $delays) {
262		if (!empty($conf->$module->enabled)) {
263			foreach ($delays as $delay) {
264				$value = (!empty($conf->global->{$delay['code']}) ? $conf->global->{$delay['code']}:0);
265				print '<tr class="oddeven">';
266				print '<td width="20px">'.img_object('', $delay['img']).'</td>';
267				print '<td>'.$langs->trans('Delays_'.$delay['code']).'</td>';
268				print '<td class="right">'.$value.' '.$langs->trans("days").'</td></tr>';
269			}
270		}
271	}
272
273	print '</table>';
274
275	print '<br>';
276
277	// Show if meteo is enabled
278	print '<table class="noborder centpercent">';
279	print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td class="center" width="120px">'.$langs->trans("Value").'</td></tr>';
280
281	print '<tr class="oddeven">';
282	print '<td>'.$langs->trans("MAIN_DISABLE_METEO").'</td><td class="center">';
283	print $labelmeteo[$conf->global->MAIN_DISABLE_METEO];
284	print '</td></tr>';
285
286	print '</table>';
287}
288
289print '<br>';
290
291
292if (empty($conf->global->MAIN_DISABLE_METEO) || $conf->global->MAIN_DISABLE_METEO != 1) {
293	// Show logo for weather
294	print '<span class="opacitymedium">'.$langs->trans("DescWeather").'</span> ';
295
296	if ($action == 'edit') {
297		$str_mode_std = $langs->trans('MeteoStdModEnabled').' : '.$langs->trans('MeteoUseMod', $langs->transnoentitiesnoconv('MeteoPercentageMod'));
298		$str_mode_percentage = $langs->trans('MeteoPercentageModEnabled').' : '.$langs->trans('MeteoUseMod', $langs->transnoentitiesnoconv('MeteoStdMod'));
299		if (empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
300			$str_mode_enabled = $str_mode_std;
301		} else {
302			$str_mode_enabled = $str_mode_percentage;
303		}
304		print '<a href="#" onclick="return false;" id="change_mode">'.$str_mode_enabled.'</a>';
305		print '<input type="hidden" id="MAIN_USE_METEO_WITH_PERCENTAGE" name="MAIN_USE_METEO_WITH_PERCENTAGE" value="'.(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE) ? $conf->global->MAIN_USE_METEO_WITH_PERCENTAGE : '').'" />';
306
307		print '<br><br>';
308	} else {
309		if (empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
310			print $langs->trans('MeteoStdModEnabled');
311		} else {
312			print $langs->trans('MeteoPercentageModEnabled');
313		}
314		print '<br><br>';
315	}
316
317	$offset = 0;
318	$cursor = 10; // By default
319	//if (! empty($conf->global->MAIN_METEO_OFFSET)) $offset=$conf->global->MAIN_METEO_OFFSET;
320	//if (! empty($conf->global->MAIN_METEO_GAP)) $cursor=$conf->global->MAIN_METEO_GAP;
321	$level0 = $offset; if (!empty($conf->global->MAIN_METEO_LEVEL0)) {
322		$level0 = $conf->global->MAIN_METEO_LEVEL0;
323	}
324	$level1 = $offset + 1 * $cursor; if (!empty($conf->global->MAIN_METEO_LEVEL1)) {
325		$level1 = $conf->global->MAIN_METEO_LEVEL1;
326	}
327	$level2 = $offset + 2 * $cursor; if (!empty($conf->global->MAIN_METEO_LEVEL2)) {
328		$level2 = $conf->global->MAIN_METEO_LEVEL2;
329	}
330	$level3 = $offset + 3 * $cursor; if (!empty($conf->global->MAIN_METEO_LEVEL3)) {
331		$level3 = $conf->global->MAIN_METEO_LEVEL3;
332	}
333	$text = ''; $options = 'class="valignmiddle" height="60px"';
334
335
336	if ($action == 'edit') {
337		print '<div id="standard" '.(empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE) ? '' : 'style="display:none;"').'>';
338
339		print '<div>';
340		print '<div class="inline-block" style="padding-right: 20px">';
341		print img_weather($text, 0, $options);
342		print ' &lt;= <input type="text" size="2" name="MAIN_METEO_LEVEL0" value="'.$level0.'"/></td>';
343		print '</div><div class="inline-block" style="padding-right: 20px">';
344		print img_weather($text, 1, $options);
345		print ' &lt;= <input type="text" size="2" name="MAIN_METEO_LEVEL1" value="'.$level1.'"/></td>';
346		print '</div><div class="inline-block" style="padding-right: 20px">';
347		print img_weather($text, 2, $options);
348		print ' &lt;= <input type="text" size="2" name="MAIN_METEO_LEVEL2" value="'.$level2.'"/></td>';
349		print '</div><div class="inline-block" style="padding-right: 20px">';
350		print img_weather($text, 3, $options);
351		print ' &lt;= <input type="text" size="2" name="MAIN_METEO_LEVEL3" value="'.$level3.'"/></td>';
352		print '</div>';
353		print '</div>';
354
355		print '</div>';
356
357		print '<div id="percentage" '.(empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE) ? 'style="display:none;"' : '').'>';
358
359		print '<div>';
360		print '<div class="inline-block" style="padding-right: 20px">';
361		print img_weather($text, 0, $options);
362		print ' &lt;= <input type="text" size="2" name="MAIN_METEO_PERCENTAGE_LEVEL0" value="'.getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL0').'"/>&nbsp;%</td>';
363		print '</div><div class="inline-block" style="padding-right: 20px">';
364		print img_weather($text, 1, $options);
365		print ' &lt;= <input type="text" size="2" name="MAIN_METEO_PERCENTAGE_LEVEL1" value="'.getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL1').'"/>&nbsp;%</td>';
366		print '</div><div class="inline-block" style="padding-right: 20px">';
367		print img_weather($text, 2, $options);
368		print ' &lt;= <input type="text" size="2" name="MAIN_METEO_PERCENTAGE_LEVEL2" value="'.getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL2').'"/>&nbsp;%</td>';
369		print '</div><div class="inline-block" style="padding-right: 20px">';
370		print img_weather($text, 3, $options);
371		print ' &lt;= <input type="text" size="2" name="MAIN_METEO_PERCENTAGE_LEVEL3" value="'.getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL3').'"/>&nbsp;%</td>';
372		print '</div>';
373		print '</div>';
374
375		print '</div>';
376
377		?>
378
379		<script type="text/javascript">
380
381			$(document).ready(function() {
382
383				$("#change_mode").click(function() {
384					var use_percent = $("#MAIN_USE_METEO_WITH_PERCENTAGE");
385					var str_mode_std = "<?php print $str_mode_std; ?>";
386					var str_mode_percentage = "<?php print $str_mode_percentage; ?>";
387
388					if(use_percent.val() == 1) {
389						use_percent.val(0);
390						$("#standard").show();
391						$("#percentage").hide();
392						$(this).html(str_mode_std);
393					} else {
394						use_percent.val(1);
395						$("#standard").hide();
396						$("#percentage").show();
397						$(this).html(str_mode_percentage);
398					}
399				});
400
401			});
402
403		</script>
404
405		<?php
406	} else {
407		if (!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
408			print '<div>';
409			print '<div class="inline-block" style="padding-right: 20px">';
410			print img_weather($text, 0, $options);
411			print ' &lt;= '.$conf->global->MAIN_METEO_PERCENTAGE_LEVEL0.'&nbsp;%</td>';
412			print '</div><div class="inline-block" style="padding-right: 20px">';
413			print img_weather($text, 1, $options);
414			print ' &lt;= '.$conf->global->MAIN_METEO_PERCENTAGE_LEVEL1.'&nbsp;%</td>';
415			print '</div><div class="inline-block" style="padding-right: 20px">';
416			print img_weather($text, 2, $options);
417			print ' &lt;= '.$conf->global->MAIN_METEO_PERCENTAGE_LEVEL2.'&nbsp;%</td>';
418			print '</div><div class="inline-block" style="padding-right: 20px">';
419			print img_weather($text, 3, $options);
420			print ' &lt;= '.$conf->global->MAIN_METEO_PERCENTAGE_LEVEL3.'&nbsp;%</td>';
421			print '</div><div class="inline-block" style="padding-right: 20px">';
422			print img_weather($text, 4, $options);
423			print ' &gt; '.$conf->global->MAIN_METEO_PERCENTAGE_LEVEL3.'&nbsp;%</td>';
424			print '</div>';
425			print '</div>';
426		} else {
427			print '<div>';
428			print '<div class="inline-block" style="padding-right: 20px">';
429			print img_weather($text, 0, $options);
430			print ' &lt;= '.$level0;
431			print '</div><div class="inline-block" style="padding-right: 20px">';
432			print img_weather($text, 1, $options);
433			print ' &lt;= '.$level1;
434			print '</div><div class="inline-block" style="padding-right: 20px">';
435			print img_weather($text, 2, $options);
436			print ' &lt;= '.$level2;
437			print '</div><div class="inline-block" style="padding-right: 20px">';
438			print img_weather($text, 3, $options);
439			print ' &lt;= '.$level3;
440			print '</div><div class="inline-block" style="padding-right: 20px">';
441			print img_weather($text, 4, $options);
442			print ' &gt; '.$level3;
443			print '</div>';
444			print '</div>';
445		}
446	}
447}
448
449
450if ($action == 'edit') {
451	print '<br><div class="center"><input type="submit" class="button button-save" value="'.$langs->trans("Save").'"></div>';
452	print '<br></form>';
453} else {
454	print '<br><div class="tabsAction">';
455	print '<a class="butAction" href="delais.php?action=edit">'.$langs->trans("Modify").'</a></div>';
456}
457
458// End of page
459llxFooter();
460$db->close();
461