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