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