1<?php
2/* Copyright (C) 2006      Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2008-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin        <regis.houssin@inodbox.com>
5 * Copyright (C) 2012-2013 Juanjo Menent		<jmenent@2byte.es>
6 * Copyright (C) 2013-2018 Philippe Grand       <philippe.grand@atoo-net.com>
7 * Copyright (C) 2013      Florian Henry        <florian.henry@open-concept.pro>
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
23/**
24 *	\file       htdocs/admin/stock.php
25 *	\ingroup    stock
26 *	\brief      Page to setup module stock
27 */
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
32
33// Load translation files required by the page
34$langs->loadLangs(array("admin", "stocks"));
35
36// Securit check
37if (!$user->admin) accessforbidden();
38
39$action = GETPOST('action', 'aZ09');
40$value = GETPOST('value', 'alpha');
41$label = GETPOST('label', 'alpha');
42$scandir = GETPOST('scan_dir', 'alpha');
43$type = 'stock';
44
45
46/*
47 * Action
48 */
49
50$reg = array();
51
52if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg))
53{
54	$code = $reg[1];
55
56	// If constant is for a unique choice, delete other choices
57	if (in_array($code, array('STOCK_CALCULATE_ON_BILL', 'STOCK_CALCULATE_ON_VALIDATE_ORDER', 'STOCK_CALCULATE_ON_SHIPMENT', 'STOCK_CALCULATE_ON_SHIPMENT_CLOSE'))) {
58		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_BILL', $conf->entity);
59		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_VALIDATE_ORDER', $conf->entity);
60		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SHIPMENT', $conf->entity);
61		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SHIPMENT_CLOSE', $conf->entity);
62	}
63	if (in_array($code, array('STOCK_CALCULATE_ON_SUPPLIER_BILL', 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', 'STOCK_CALCULATE_ON_RECEPTION', 'STOCK_CALCULATE_ON_RECEPTION_CLOSE', 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER'))) {
64		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SUPPLIER_BILL', $conf->entity);
65		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', $conf->entity);
66		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_RECEPTION', $conf->entity);
67		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_RECEPTION_CLOSE', $conf->entity);
68		dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER', $conf->entity);
69	}
70
71	if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0)
72	{
73		header("Location: ".$_SERVER["PHP_SELF"]);
74		exit;
75	} else {
76		dol_print_error($db);
77	}
78}
79
80if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg))
81{
82	$code = $reg[1];
83	if (dolibarr_del_const($db, $code, $conf->entity) > 0)
84	{
85		header("Location: ".$_SERVER["PHP_SELF"]);
86		exit;
87	} else {
88		dol_print_error($db);
89	}
90}
91
92if ($action == 'warehouse')
93{
94	$value = GETPOST('default_warehouse', 'alpha');
95	$res = dolibarr_set_const($db, "MAIN_DEFAULT_WAREHOUSE", $value, 'chaine', 0, '', $conf->entity);
96	if ($value == -1 || empty($value) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
97		$res = dolibarr_del_const($db, "MAIN_DEFAULT_WAREHOUSE", $conf->entity);
98	}
99	if (!($res > 0)) $error++;
100}
101
102if ($action == 'specimen')
103{
104	$modele = GETPOST('module', 'alpha');
105
106	$object = new Entrepot($db);
107	$object->initAsSpecimen();
108
109	// Search template files
110	$file = ''; $classname = ''; $filefound = 0;
111	$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
112	foreach ($dirmodels as $reldir)
113	{
114		$file = dol_buildpath($reldir."core/modules/stock/doc/pdf_".$modele.".modules.php", 0);
115		if (file_exists($file))
116		{
117			$filefound = 1;
118			$classname = "pdf_".$modele;
119			break;
120		}
121	}
122
123	if ($filefound)
124	{
125		require_once $file;
126
127		$module = new $classname($db);
128
129		if ($module->write_file($object, $langs) > 0)
130		{
131			header("Location: ".DOL_URL_ROOT."/document.php?modulepart=stock&file=SPECIMEN.pdf");
132			return;
133		} else {
134			setEventMessages($module->error, null, 'errors');
135			dol_syslog($module->error, LOG_ERR);
136		}
137	} else {
138		setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
139		dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
140	}
141}
142
143// Activate a model
144elseif ($action == 'set') {
145	$ret = addDocumentModel($value, $type, $label, $scandir);
146} elseif ($action == 'del') {
147	$ret = delDocumentModel($value, $type);
148	if ($ret > 0)
149	{
150		if ($conf->global->STOCK_ADDON_PDF == "$value") dolibarr_del_const($db, 'STOCK_ADDON_PDF', $conf->entity);
151	}
152}
153
154// Set default model
155elseif ($action == 'setdoc')
156{
157	if (dolibarr_set_const($db, "STOCK_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
158	{
159		// The constant that was read before the new set
160		// We therefore requires a variable to have a coherent view
161		$conf->global->STOCK_ADDON_PDF = $value;
162	}
163
164	// On active le modele
165	$ret = delDocumentModel($value, $type);
166	if ($ret > 0)
167	{
168		$ret = addDocumentModel($value, $type, $label, $scandir);
169	}
170}
171
172
173/*
174 * View
175 */
176
177$form = new Form($db);
178$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
179
180llxHeader('', $langs->trans("StockSetup"));
181
182$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
183print load_fiche_titre($langs->trans("StockSetup"), $linkback, 'title_setup');
184
185$head = stock_admin_prepare_head();
186
187print dol_get_fiche_head($head, 'general', $langs->trans("StockSetup"), -1, 'stock');
188
189$form = new Form($db);
190$formproduct = new FormProduct($db);
191
192
193
194$disabled = '';
195if (!empty($conf->productbatch->enabled))
196{
197	$langs->load("productbatch");
198	$disabled = ' disabled';
199	print info_admin($langs->trans("WhenProductBatchModuleOnOptionAreForced"));
200}
201
202//if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) || ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
203//{
204print info_admin($langs->trans("IfYouUsePointOfSaleCheckModule"));
205print '<br>';
206//}
207
208
209print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
210print '<input type="hidden" name="token" value="'.newToken().'">';
211print '<input type="hidden" name="action" value="warehouse">';
212
213// Title rule for stock decrease
214print '<table class="noborder centpercent">';
215print '<tr class="liste_titre">';
216print "<td>".$langs->trans("RuleForStockManagementDecrease")."</td>\n";
217print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
218print '</tr>'."\n";
219
220$found = 0;
221
222print '<tr class="oddeven">';
223print '<td>'.$langs->trans("DeStockOnBill").'</td>';
224print '<td class="right">';
225if (!empty($conf->facture->enabled))
226{
227	if ($conf->use_javascript_ajax) {
228		print ajax_constantonoff('STOCK_CALCULATE_ON_BILL', array(), null, 0, 0, 0, 2, 1);
229	} else {
230		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
231		print $form->selectarray("STOCK_CALCULATE_ON_BILL", $arrval, $conf->global->STOCK_CALCULATE_ON_BILL);
232	}
233} else {
234	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module30Name"));
235}
236print "</td>\n</tr>\n";
237$found++;
238
239
240print '<tr class="oddeven">';
241print '<td>'.$langs->trans("DeStockOnValidateOrder").'</td>';
242print '<td class="right">';
243if (!empty($conf->commande->enabled))
244{
245	if ($conf->use_javascript_ajax) {
246		print ajax_constantonoff('STOCK_CALCULATE_ON_VALIDATE_ORDER', array(), null, 0, 0, 0, 2, 1);
247	} else {
248		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
249		print $form->selectarray("STOCK_CALCULATE_ON_VALIDATE_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER);
250	}
251} else {
252	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module25Name"));
253}
254print "</td>\n</tr>\n";
255$found++;
256
257//if (! empty($conf->expedition->enabled))
258//{
259
260print '<tr class="oddeven">';
261print '<td>'.$langs->trans("DeStockOnShipment").'</td>';
262print '<td class="right">';
263if (!empty($conf->expedition->enabled))
264{
265	if ($conf->use_javascript_ajax) {
266		print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT', array(), null, 0, 0, 0, 2, 1);
267	} else {
268		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
269		print $form->selectarray("STOCK_CALCULATE_ON_SHIPMENT", $arrval, $conf->global->STOCK_CALCULATE_ON_SHIPMENT);
270	}
271} else {
272	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
273}
274print "</td>\n</tr>\n";
275$found++;
276
277
278print '<tr class="oddeven">';
279print '<td>'.$langs->trans("DeStockOnShipmentOnClosing").'</td>';
280print '<td class="right">';
281if (!empty($conf->expedition->enabled))
282{
283	if ($conf->use_javascript_ajax) {
284		print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT_CLOSE', array(), null, 0, 0, 0, 2, 1);
285	} else {
286		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
287		print $form->selectarray("STOCK_CALCULATE_ON_SHIPMENT_CLOSE", $arrval, $conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE);
288	}
289} else {
290	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
291}
292print "</td>\n</tr>\n";
293$found++;
294
295print '</table>';
296
297
298print '<br>';
299
300
301// Title rule for stock increase
302print '<table class="noborder centpercent">';
303print '<tr class="liste_titre">';
304print "<td>".$langs->trans("RuleForStockManagementIncrease")."</td>\n";
305print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
306print '</tr>'."\n";
307
308$found = 0;
309
310print '<tr class="oddeven">';
311print '<td>'.$langs->trans("ReStockOnBill").'</td>';
312print '<td class="right">';
313if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
314{
315	if ($conf->use_javascript_ajax) {
316		print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_BILL', array(), null, 0, 0, 0, 2, 1);
317	} else {
318		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
319		print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_BILL", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL);
320	}
321} else {
322	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
323}
324print "</td>\n</tr>\n";
325$found++;
326
327
328
329print '<tr class="oddeven">';
330print '<td>'.$langs->trans("ReStockOnValidateOrder").'</td>';
331print '<td class="right">';
332if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
333{
334	if ($conf->use_javascript_ajax) {
335		print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', array(), null, 0, 0, 0, 2, 1);
336	} else {
337		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
338		print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER);
339	}
340} else {
341	print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
342}
343print "</td>\n</tr>\n";
344$found++;
345
346if (!empty($conf->reception->enabled))
347{
348	print '<tr class="oddeven">';
349	print '<td>'.$langs->trans("StockOnReception").'</td>';
350	print '<td class="right">';
351
352	if ($conf->use_javascript_ajax) {
353		print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION', array(), null, 0, 0, 0, 2, 1);
354	} else {
355		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
356		print $form->selectarray("STOCK_CALCULATE_ON_RECEPTION", $arrval, $conf->global->STOCK_CALCULATE_ON_RECEPTION);
357	}
358
359	print "</td>\n</tr>\n";
360	$found++;
361
362
363	print '<tr class="oddeven">';
364	print '<td>'.$langs->trans("StockOnReceptionOnClosing").'</td>';
365	print '<td class="right">';
366
367	if ($conf->use_javascript_ajax) {
368		print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION_CLOSE', array(), null, 0, 0, 0, 2, 1);
369	} else {
370		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
371		print $form->selectarray("STOCK_CALCULATE_ON_RECEPTION_CLOSE", $arrval, $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE);
372	}
373	print "</td>\n</tr>\n";
374	$found++;
375} else {
376	print '<tr class="oddeven">';
377	print '<td>'.$langs->trans("ReStockOnDispatchOrder").'</td>';
378	print '<td class="right">';
379	if (!empty($conf->fournisseur->enabled))
380	{
381		if ($conf->use_javascript_ajax) {
382			print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER', array(), null, 0, 0, 0, 2, 1);
383		} else {
384			$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
385			print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER);
386		}
387	} else {
388		print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
389	}
390	print "</td>\n</tr>\n";
391	$found++;
392}
393
394print '</table>';
395
396print '<br>';
397
398print '<table class="noborder centpercent">';
399print '<tr class="liste_titre">';
400print "<td>".$langs->trans("RuleForStockAvailability")."</td>\n";
401print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
402print '</tr>'."\n";
403
404
405print '<tr class="oddeven">';
406print '<td>'.$langs->trans("WarehouseAllowNegativeTransfer").'</td>';
407print '<td class="right">';
408if ($conf->use_javascript_ajax) {
409	print ajax_constantonoff('STOCK_ALLOW_NEGATIVE_TRANSFER');
410} else {
411	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
412	print $form->selectarray("STOCK_ALLOW_NEGATIVE_TRANSFER", $arrval, $conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER);
413}
414print "</td>\n";
415print "</tr>\n";
416
417// Option to force stock to be enough before adding a line into document
418if ($conf->invoice->enabled)
419{
420	print '<tr class="oddeven">';
421	print '<td>'.$langs->trans("StockMustBeEnoughForInvoice").'</td>';
422	print '<td class="right">';
423	if ($conf->use_javascript_ajax) {
424		print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_INVOICE');
425	} else {
426		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
427		print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_INVOICE", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE);
428	}
429	print "</td>\n";
430	print "</tr>\n";
431}
432
433if ($conf->order->enabled)
434{
435	print '<tr class="oddeven">';
436	print '<td>'.$langs->trans("StockMustBeEnoughForOrder").'</td>';
437	print '<td class="right">';
438	if ($conf->use_javascript_ajax) {
439		print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_ORDER');
440	} else {
441		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
442		print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_ORDER", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER);
443	}
444	print "</td>\n";
445	print "</tr>\n";
446}
447
448if ($conf->expedition->enabled)
449{
450	print '<tr class="oddeven">';
451	print '<td>'.$langs->trans("StockMustBeEnoughForShipment").'</td>';
452	print '<td class="right">';
453	if ($conf->use_javascript_ajax) {
454		print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT');
455	} else {
456		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
457		print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT);
458	}
459	print "</td>\n";
460	print "</tr>\n";
461}
462print '</table>';
463
464print '<br>';
465
466$virtualdiffersfromphysical = 0;
467if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
468	|| !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
469	|| !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
470	|| !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
471	|| !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)
472	|| !empty($conf->mrp->enabled))
473{
474	$virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs.
475}
476
477if ($virtualdiffersfromphysical)
478{
479	print '<table class="noborder centpercent">';
480	print '<tr class="liste_titre">';
481	print "<td>".$langs->trans("RuleForStockReplenishment")." ".img_help('help', $langs->trans("VirtualDiffersFromPhysical"))."</td>\n";
482	print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
483	print '</tr>'."\n";
484
485	print '<tr class="oddeven">';
486	print '<td>';
487	print $form->textwithpicto($langs->trans("UseRealStockByDefault"), $langs->trans("ReplenishmentCalculation"));
488	print '</td>';
489	print '<td class="right">';
490	if ($conf->use_javascript_ajax) {
491		print ajax_constantonoff('STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT');
492	} else {
493		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
494		print $form->selectarray("STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT", $arrval, $conf->global->STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT);
495	}
496	print "</td>\n";
497	print "</tr>\n";
498	print '</table>';
499
500	print '<br>';
501}
502
503print '<form>';
504
505
506print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
507print '<input type="hidden" name="token" value="'.newToken().'">';
508print '<input type="hidden" name="action" value="warehouse">';
509
510
511/*
512 * Document templates generators
513 */
514
515print load_fiche_titre($langs->trans("WarehouseModelModules"), '', '');
516
517// Load array def with activated templates
518$def = array();
519$sql = "SELECT nom";
520$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
521$sql .= " WHERE type = '".$db->escape($type)."'";
522$sql .= " AND entity = ".$conf->entity;
523$resql = $db->query($sql);
524if ($resql)
525{
526	$i = 0;
527	$num_rows = $db->num_rows($resql);
528	while ($i < $num_rows)
529	{
530		$array = $db->fetch_array($resql);
531		array_push($def, $array[0]);
532		$i++;
533	}
534} else {
535	dol_print_error($db);
536}
537
538
539print "<table class=\"noborder\" width=\"100%\">\n";
540print "<tr class=\"liste_titre\">\n";
541print '<td>'.$langs->trans("Name").'</td>';
542print '<td>'.$langs->trans("Description").'</td>';
543print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
544print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
545print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
546print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
547print "</tr>\n";
548
549clearstatcache();
550
551foreach ($dirmodels as $reldir)
552{
553	foreach (array('', '/doc') as $valdir)
554	{
555		$realpath = $reldir."core/modules/stock".$valdir;
556		$dir = dol_buildpath($realpath);
557
558		if (is_dir($dir))
559		{
560			$handle = opendir($dir);
561			if (is_resource($handle))
562			{
563				while (($file = readdir($handle)) !== false)
564				{
565					$filelist[] = $file;
566				}
567				closedir($handle);
568				arsort($filelist);
569
570				foreach ($filelist as $file)
571				{
572					if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
573					{
574						if (file_exists($dir.'/'.$file))
575						{
576							$name = substr($file, 4, dol_strlen($file) - 16);
577							$classname = substr($file, 0, dol_strlen($file) - 12);
578
579							require_once $dir.'/'.$file;
580							$module = new $classname($db);
581
582							$modulequalified = 1;
583							if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
584							if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
585
586							if ($modulequalified)
587							{
588								print '<tr class="oddeven"><td width="100">';
589								print (empty($module->name) ? $name : $module->name);
590								print "</td><td>\n";
591								if (method_exists($module, 'info')) print $module->info($langs);
592								else print $module->description;
593								print '</td>';
594
595								// Active
596								if (in_array($name, $def))
597								{
598									print '<td class="center">'."\n";
599									print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&amp;token='.newToken().'&amp;value='.$name.'">';
600									print img_picto($langs->trans("Enabled"), 'switch_on');
601									print '</a>';
602									print '</td>';
603								} else {
604									print '<td class="center">'."\n";
605									print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
606									print "</td>";
607								}
608
609								// Default
610								print '<td class="center">';
611								if ($conf->global->STOCK_ADDON_PDF == $name)
612								{
613									print img_picto($langs->trans("Default"), 'on');
614								} else {
615									print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
616								}
617								print '</td>';
618
619								// Info
620								$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
621								$htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
622								if ($module->type == 'pdf')
623								{
624									$htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
625								}
626								$htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
627
628								$htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
629								$htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
630								$htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
631
632
633								print '<td class="center">';
634								print $form->textwithpicto('', $htmltooltip, 1, 0);
635								print '</td>';
636
637								// Preview
638								print '<td class="center">';
639								if ($module->type == 'pdf')
640								{
641									print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
642								} else {
643									print img_object($langs->trans("PreviewNotAvailable"), 'generic');
644								}
645								print '</td>';
646
647								print "</tr>\n";
648							}
649						}
650					}
651				}
652			}
653		}
654	}
655}
656
657print '</table>';
658
659print '</form>';
660
661
662// Other
663
664print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
665print '<input type="hidden" name="token" value="'.newToken().'">';
666print '<input type="hidden" name="action" value="warehouse">';
667
668print load_fiche_titre($langs->trans("Other"), '', '');
669
670print '<table class="noborder centpercent">';
671
672print '<tr class="liste_titre">';
673print "<td>".$langs->trans("Parameter")."</td>\n";
674print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
675print '</tr>'."\n";
676
677print '<tr class="oddeven">';
678print '<td>'.$langs->trans("MainDefaultWarehouse").'</td>';
679print '<td class="right">';
680print $formproduct->selectWarehouses($conf->global->MAIN_DEFAULT_WAREHOUSE, 'default_warehouse', '', 1, 0, 0, '', 0, 0, array(), 'left reposition');
681print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
682print "</td>";
683print "</tr>\n";
684
685print '<tr class="oddeven">';
686print '<td>'.$langs->trans("UserDefaultWarehouse").'</td>';
687print '<td class="right">';
688if ($conf->use_javascript_ajax) {
689	print ajax_constantonoff('MAIN_DEFAULT_WAREHOUSE_USER', array(), null, 0, 0, 1);
690} else {
691	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
692	print $form->selectarray("MAIN_DEFAULT_WAREHOUSE_USER", $arrval, $conf->global->MAIN_DEFAULT_WAREHOUSE_USER);
693}
694print "</td>\n";
695print "</tr>\n";
696
697if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
698	print '<tr class="oddeven">';
699	print '<td>'.$langs->trans("UserWarehouseAutoCreate").'</td>';
700	print '<td class="right">';
701	if ($conf->use_javascript_ajax) {
702		print ajax_constantonoff('STOCK_USERSTOCK_AUTOCREATE');
703	} else {
704		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
705		print $form->selectarray("STOCK_USERSTOCK_AUTOCREATE", $arrval, $conf->global->STOCK_USERSTOCK_AUTOCREATE);
706	}
707	print "</td>\n";
708	print "</tr>\n";
709}
710
711print '<tr class="oddeven">';
712print '<td>'.$langs->trans("WarehouseAskWarehouseDuringOrder").'</td>';
713print '<td class="right">';
714if ($conf->use_javascript_ajax) {
715	print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER');
716} else {
717	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
718	print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER);
719}
720print "</td>";
721print '</td>';
722print "</tr>\n";
723
724print '<tr class="oddeven">';
725print '<td>';
726print $form->textwithpicto($langs->trans("StockSupportServices"), $langs->trans("StockSupportServicesDesc"));
727print '</td>';
728print '<td class="right">';
729if ($conf->use_javascript_ajax) {
730	print ajax_constantonoff('STOCK_SUPPORTS_SERVICES');
731} else {
732	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
733	print $form->selectarray("STOCK_SUPPORTS_SERVICES", $arrval, $conf->global->STOCK_SUPPORTS_SERVICES);
734}
735print "</td>\n";
736print "</tr>\n";
737
738print '<tr class="oddeven">';
739print '<td>'.$langs->trans("AllowAddLimitStockByWarehouse").'</td>';
740print '<td class="right">';
741if ($conf->use_javascript_ajax) {
742	print ajax_constantonoff('STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE');
743} else {
744	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
745	print $form->selectarray("STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE", $arrval, $conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE);
746}
747print "</td>\n";
748print "</tr>\n";
749
750print '<tr class="oddeven">';
751print '<td>'.$langs->trans("AlwaysShowFullArbo").'</td>';
752print '<td class="right">';
753if ($conf->use_javascript_ajax) {
754	print ajax_constantonoff('STOCK_ALWAYS_SHOW_FULL_ARBO');
755} else {
756	$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
757	print $form->selectarray("STOCK_ALWAYS_SHOW_FULL_ARBO", $arrval, $conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO);
758}
759print "</td>\n";
760print "</tr>\n";
761print '</table>';
762
763print '</form>';
764
765// End of page
766llxFooter();
767$db->close();
768