dolibarr 21.0.0-alpha
stocktransfer.php
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4 * Copyright (C) 2021 SuperAdmin
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.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
28// Load Dolibarr environment
29require '../main.inc.php';
30
31global $langs, $user;
32
33// Libraries
34require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
35require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
36require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer.lib.php';
37
38// Translations
39$langs->loadLangs(array("admin", "stocks"));
40
41// Access control
42if (!$user->admin) {
44}
45
46// Parameters
47$action = GETPOST('action', 'alpha');
48$backtopage = GETPOST('backtopage', 'alpha');
49
50$value = GETPOST('value', 'alpha');
51$label = GETPOST('label', 'alpha');
52$scandir = GETPOST('scan_dir', 'alpha');
53
54$arrayofparameters = array(
55 'STOCKTRANSFER_MYPARAM1' => array('css' => 'minwidth200', 'enabled' => 1),
56 'STOCKTRANSFER_MYPARAM2' => array('css' => 'minwidth500', 'enabled' => 1)
57);
58
59$error = 0;
60$setupnotempty = 0;
61
62
63/*
64 * Actions
65 */
66
67include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
68
69
70if ($action == 'updateMask') {
71 $maskconststocktransfer = GETPOST('maskconststocktransfer', 'aZ09');
72 $maskstocktransfer = GETPOST('maskStockTransfer', 'alpha');
73
74 if ($maskconststocktransfer && preg_match('/_MASK$/', $maskconststocktransfer)) {
75 $res = dolibarr_set_const($db, $maskconststocktransfer, $maskstocktransfer, 'chaine', 0, '', $conf->entity);
76 if ($res <= 0) {
77 $error++;
78 }
79 }
80
81 if (!$error) {
82 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
83 } else {
84 setEventMessages($langs->trans("Error"), null, 'errors');
85 }
86} elseif ($action == 'specimen') {
87 $modele = GETPOST('module', 'alpha');
88 $tmpobjectkey = 'StockTransfer';
89
90 $tmpobject = new $tmpobjectkey($db);
91 $tmpobject->initAsSpecimen();
92
93 // Search template files
94 $file = '';
95 $classname = '';
96 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
97 foreach ($dirmodels as $reldir) {
98 $file = dol_buildpath($reldir."core/modules/stocktransfer/doc/pdf_".$modele.".modules.php", 0);
99 if (file_exists($file)) {
100 $classname = "pdf_".$modele;
101 break;
102 }
103 }
104
105 if ($classname !== '') {
106 require_once $file;
107
108 $module = new $classname($db);
109 '@phan-var-force ModelePDFStockTransfer $module';
110
111 if ($module->write_file($tmpobject, $langs) > 0) {
112 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
113 return;
114 } else {
115 setEventMessages($module->error, null, 'errors');
116 dol_syslog($module->error, LOG_ERR);
117 }
118 } else {
119 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
120 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
121 }
122} elseif ($action == 'set') { // Activate a model
123 $ret = addDocumentModel($value, 'stocktransfer', $label, $scandir);
124} elseif ($action == 'del') {
125 $tmpobjectkey = 'StockTransfer';
126
127 $ret = delDocumentModel($value, 'stocktransfer');
128 if ($ret > 0) {
129 $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
130 if (getDolGlobalString($constforval) == "$value") {
131 dolibarr_del_const($db, $constforval, $conf->entity);
132 }
133 }
134} elseif ($action == 'setdoc') { // Set default model
135 $tmpobjectkey = 'StockTransfer';
136 $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
137 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
138 // The constant that was read before the new set
139 // We therefore requires a variable to have a coherent view
140 $conf->global->$constforval = $value;
141 }
142
143 // On active le modele
144 $ret = delDocumentModel($value, 'stocktransfer');
145 if ($ret > 0) {
146 $ret = addDocumentModel($value, 'stocktransfer', $label, $scandir);
147 }
148} elseif ($action == 'setmod') {
149 // TODO Check if numbering module chosen can be activated
150 // by calling method canBeActivated
151 $tmpobjectkey = 'StockTransfer';
152 $constforval = 'STOCKTRANSFER_'.strtoupper($tmpobjectkey)."_ADDON";
153 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
154}
155
156
157
158/*
159 * View
160 */
161
162$form = new Form($db);
163
164$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
165
166$page_name = "StockTransferSetup";
167llxHeader('', $langs->trans($page_name), '', '', 0, 0, '', '', '', 'mod-admin page-stocktransfer');
168
169// Subheader
170$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
171
172print load_fiche_titre($langs->trans($page_name), $linkback, 'stock');
173
174// Configuration header
176print dol_get_fiche_head($head, 'settings', '', -1, "stocktransfer@stocktransfer");
177
178// Setup page goes here
179print '<span class="opacitymedium">'.$langs->trans("StockTransferSetupPage").'</span>';
180
181
182/*if ($action == 'edit')
183{
184 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
185 print '<input type="hidden" name="token" value="'.newToken().'">';
186 print '<input type="hidden" name="action" value="update">';
187
188 print '<table class="noborder centpercent">';
189 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
190
191 foreach ($arrayofparameters as $key => $val)
192 {
193 print '<tr class="oddeven"><td>';
194 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
195 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
196 print '</td><td><input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'"></td></tr>';
197 }
198 print '</table>';
199
200 print '<br><div class="center">';
201 print '<input class="button" type="submit" value="'.$langs->trans("Save").'">';
202 print '</div>';
203
204 print '</form>';
205 print '<br>';
206} else {
207 if (!empty($arrayofparameters))
208 {
209 print '<table class="noborder centpercent">';
210 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
211
212 foreach ($arrayofparameters as $key => $val)
213 {
214 $setupnotempty++;
215
216 print '<tr class="oddeven"><td>';
217 $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
218 print $form->textwithpicto($langs->trans($key), $tooltiphelp);
219 print '</td><td>'.getDolGlobalString($key).'</td></tr>';
220 }
221
222 print '</table>';
223
224 print '<div class="tabsAction">';
225 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
226 print '</div>';
227 }
228 else
229 {
230 print '<br>'.$langs->trans("NothingToSetup");
231 }
232}*/
233
234
235$moduledir = 'stocktransfer';
236$myTmpObjects = array();
237$myTmpObjects[$moduledir] = array('includerefgeneration' => 1, 'includedocgeneration' => 1, 'class' => 'StockTransfer');
238
239foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
240 if ($myTmpObjectArray['includerefgeneration']) {
241 // Orders Numbering model
242 $setupnotempty++;
243
244 print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
245
246 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
247 print '<table class="noborder centpercent">';
248 print '<tr class="liste_titre">';
249 print '<td>'.$langs->trans("Name").'</td>';
250 print '<td>'.$langs->trans("Description").'</td>';
251 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
252 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
253 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
254 print '</tr>'."\n";
255
256 clearstatcache();
257
258 foreach ($dirmodels as $reldir) {
259 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
260
261 if (is_dir($dir)) {
262 $handle = opendir($dir);
263 if (is_resource($handle)) {
264 while (($file = readdir($handle)) !== false) {
265 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
266 $file = substr($file, 0, dol_strlen($file) - 4);
267
268 require_once $dir.'/'.$file.'.php';
269
270 $module = new $file($db);
271
272 '@phan-var-force ModeleNumRefStockTransfer $module';
273
274 // Show modules according to features level
275 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
276 continue;
277 }
278 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
279 continue;
280 }
281
282 if ($module->isEnabled()) {
283 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
284
285 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
286 print $module->info($langs);
287 print '</td>';
288
289 // Show example of numbering model
290 print '<td class="nowrap">';
291 $tmp = $module->getExample();
292 if (preg_match('/^Error/', $tmp)) {
293 print '<div class="error">'.$langs->trans($tmp).'</div>';
294 } elseif ($tmp == 'NotConfigured') {
295 print $langs->trans($tmp);
296 } else {
297 print $tmp;
298 }
299 print '</td>'."\n";
300
301 print '<td class="center">';
302 $constforvar = 'STOCKTRANSFER_'.strtoupper($myTmpObjectKey).'_ADDON';
303 if (getDolGlobalString($constforvar) == $file) {
304 print img_picto($langs->trans("Activated"), 'switch_on');
305 } else {
306 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.$file.'">';
307 print img_picto($langs->trans("Disabled"), 'switch_off');
308 print '</a>';
309 }
310 print '</td>';
311
312 $nameofclass = $myTmpObjectArray['class'];
313 $mytmpinstance = new $nameofclass($db);
314 $mytmpinstance->initAsSpecimen();
315
316 // Info
317 $htmltooltip = '';
318 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
319
320 $nextval = $module->getNextValue($mytmpinstance);
321 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
322 $htmltooltip .= ''.$langs->trans("NextValue").': ';
323 if ($nextval) {
324 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
325 $nextval = $langs->trans($nextval);
326 }
327 $htmltooltip .= $nextval.'<br>';
328 } else {
329 $htmltooltip .= $langs->trans($module->error).'<br>';
330 }
331 }
332
333 print '<td class="center">';
334 print $form->textwithpicto('', $htmltooltip, 1, 0);
335 print '</td>';
336
337 print "</tr>\n";
338 }
339 }
340 }
341 closedir($handle);
342 }
343 }
344 }
345 print "</table></div><br>\n";
346 }
347
348 if ($myTmpObjectArray['includedocgeneration']) {
349 // Document templates generators
350 $setupnotempty++;
351 $type = strtolower($myTmpObjectKey);
352
353 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
354
355 // Load array def with activated templates
356 $def = array();
357 $sql = "SELECT nom";
358 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
359 $sql .= " WHERE type = '".$db->escape($type)."'";
360 $sql .= " AND entity = ".$conf->entity;
361 $resql = $db->query($sql);
362 if ($resql) {
363 $i = 0;
364 $num_rows = $db->num_rows($resql);
365 while ($i < $num_rows) {
366 $array = $db->fetch_array($resql);
367 if (is_array($array)) {
368 array_push($def, $array[0]);
369 }
370 $i++;
371 }
372 } else {
373 dol_print_error($db);
374 }
375
376 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
377 print '<table class="noborder centpercent">'."\n";
378 print '<tr class="liste_titre">'."\n";
379 print '<td>'.$langs->trans("Name").'</td>';
380 print '<td>'.$langs->trans("Description").'</td>';
381 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
382 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
383 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
384 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
385 print "</tr>\n";
386
387 clearstatcache();
388
389 foreach ($dirmodels as $reldir) {
390 foreach (array('', '/doc') as $valdir) {
391 $realpath = $reldir."core/modules/".$moduledir.$valdir;
392 $dir = dol_buildpath($realpath);
393
394 if (is_dir($dir)) {
395 $handle = opendir($dir);
396 if (is_resource($handle)) {
397 $filelist = array();
398 while (($file = readdir($handle)) !== false) {
399 $filelist[] = $file;
400 }
401 closedir($handle);
402 arsort($filelist);
403
404 foreach ($filelist as $file) {
405 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
406 if (file_exists($dir.'/'.$file)) {
407 $name = substr($file, 4, dol_strlen($file) - 16);
408 $classname = substr($file, 0, dol_strlen($file) - 12);
409
410 require_once $dir.'/'.$file;
411 $module = new $classname($db);
412
413 '@phan-var-force ModelePDFStockTransfer $module';
414
415 $modulequalified = 1;
416 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
417 $modulequalified = 0;
418 }
419 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
420 $modulequalified = 0;
421 }
422
423 if ($modulequalified) {
424 print '<tr class="oddeven"><td>';
425 print(empty($module->name) ? $name : $module->name);
426 print "</td><td>\n";
427 if (method_exists($module, 'info')) {
428 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
429 } else {
430 print $module->description;
431 }
432 print '</td>';
433
434 // Active
435 if (in_array($name, $def)) {
436 print '<td class="center">'."\n";
437 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.urlencode($name).'&token='.newToken().'">';
438 print img_picto($langs->trans("Enabled"), 'switch_on');
439 print '</a>';
440 print '</td>';
441 } else {
442 print '<td class="center">'."\n";
443 print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
444 print "</td>";
445 }
446
447 // Default
448 print '<td class="center">';
449 $constforvar = strtoupper($myTmpObjectKey).'_ADDON_PDF';
450 if (getDolGlobalString($constforvar) == $name) {
451 print img_picto($langs->trans("Default"), 'on');
452 } else {
453 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&object='.urlencode($myTmpObjectKey).'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
454 }
455 print '</td>';
456
457 // Info
458 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
459 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
460 if ($module->type == 'pdf') {
461 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
462 }
463 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
464
465 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
466 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
467 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
468
469 print '<td class="center">';
470 print $form->textwithpicto('', $htmltooltip, 1, 0);
471 print '</td>';
472
473 // Preview
474 print '<td class="center">';
475 if ($module->type == 'pdf') {
476 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
477 } else {
478 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
479 }
480 print '</td>';
481
482 print "</tr>\n";
483 }
484 }
485 }
486 }
487 }
488 }
489 }
490 }
491
492 print '</table></div>';
493 }
494}
495
496if (empty($setupnotempty)) {
497 print '<br>'.$langs->trans("NothingToSetup");
498}
499
500// Page end
501print dol_get_fiche_end();
502
503llxFooter();
504$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
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:70
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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)
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
stocktransferAdminPrepareHead()
Prepare admin pages header.