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