dolibarr 23.0.3
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-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2025 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
67
68/*
69 * Actions
70 */
71
72include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
73
74
75if ($action == 'updateMask') {
76 $maskconststocktransfer = GETPOST('maskconststocktransfer', 'aZ09');
77 $maskstocktransfer = GETPOST('maskStockTransfer', 'alpha');
78
79 if ($maskconststocktransfer && preg_match('/_MASK$/', $maskconststocktransfer)) {
80 $res = dolibarr_set_const($db, $maskconststocktransfer, $maskstocktransfer, 'chaine', 0, '', $conf->entity);
81 if ($res <= 0) {
82 $error++;
83 }
84 }
85
86 if (!$error) {
87 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
88 } else {
89 setEventMessages($langs->trans("Error"), null, 'errors');
90 }
91} elseif ($action == 'specimen') {
92 $modele = GETPOST('module', 'alpha');
93 $tmpobjectkey = 'StockTransfer';
94
95 $tmpobject = new $tmpobjectkey($db);
96 $tmpobject->initAsSpecimen();
97
98 // Search template files
99 $file = '';
100 $classname = '';
101 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
102 foreach ($dirmodels as $reldir) {
103 $file = dol_buildpath($reldir."core/modules/stocktransfer/doc/pdf_".$modele.".modules.php", 0);
104 if (file_exists($file)) {
105 $classname = "pdf_".$modele;
106 break;
107 }
108 }
109
110 if ($classname !== '') {
111 require_once $file;
112
113 $module = new $classname($db);
114 '@phan-var-force ModelePDFStockTransfer $module';
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="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></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$moduledir = 'stocktransfer';
185$myTmpObjects = array();
186$myTmpObjects[$moduledir] = array('includerefgeneration' => 1, 'includedocgeneration' => 1, 'class' => 'StockTransfer');
187
188foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
189 // Orders Numbering model
190 print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
191
192 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
193 print '<table class="noborder centpercent">';
194 print '<tr class="liste_titre">';
195 print '<td>'.$langs->trans("Name").'</td>';
196 print '<td>'.$langs->trans("Description").'</td>';
197 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
198 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
199 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
200 print '</tr>'."\n";
201
202 clearstatcache();
203
204 foreach ($dirmodels as $reldir) {
205 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
206
207 if (is_dir($dir)) {
208 $handle = opendir($dir);
209 if (is_resource($handle)) {
210 while (($file = readdir($handle)) !== false) {
211 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
212 $file = substr($file, 0, dol_strlen($file) - 4);
213
214 require_once $dir.'/'.$file.'.php';
215
216 $module = new $file($db);
217
218 '@phan-var-force ModeleNumRefStockTransfer $module';
219
220 // Show modules according to features level
221 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
222 continue;
223 }
224 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
225 continue;
226 }
227
228 if ($module->isEnabled()) {
229 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
230
231 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
232 print $module->info($langs);
233 print '</td>';
234
235 // Show example of numbering model
236 print '<td class="nowrap">';
237 $tmp = $module->getExample();
238 if (preg_match('/^Error/', $tmp)) {
239 print '<div class="error">'.$langs->trans($tmp).'</div>';
240 } elseif ($tmp == 'NotConfigured') {
241 print $langs->trans($tmp);
242 } else {
243 print $tmp;
244 }
245 print '</td>'."\n";
246
247 print '<td class="center">';
248 $constforvar = 'STOCKTRANSFER_'.strtoupper($myTmpObjectKey).'_ADDON';
249 if (getDolGlobalString($constforvar) == $file) {
250 print img_picto($langs->trans("Activated"), 'switch_on');
251 } else {
252 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.$file.'">';
253 print img_picto($langs->trans("Disabled"), 'switch_off');
254 print '</a>';
255 }
256 print '</td>';
257
258 $nameofclass = $myTmpObjectArray['class'];
259 $mytmpinstance = new $nameofclass($db);
260 $mytmpinstance->initAsSpecimen();
261
262 // Info
263 $htmltooltip = '';
264 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
265
266 $nextval = $module->getNextValue($mytmpinstance);
267 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
268 $htmltooltip .= ''.$langs->trans("NextValue").': ';
269 if ($nextval) {
270 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
271 $nextval = $langs->trans($nextval);
272 }
273 $htmltooltip .= $nextval.'<br>';
274 } else {
275 $htmltooltip .= $langs->trans($module->error).'<br>';
276 }
277 }
278
279 print '<td class="center">';
280 print $form->textwithpicto('', $htmltooltip, 1, 'info');
281 print '</td>';
282
283 print "</tr>\n";
284 }
285 }
286 }
287 closedir($handle);
288 }
289 }
290 }
291 print "</table></div><br>\n";
292
293 // Document templates generators
294 $type = strtolower($myTmpObjectKey);
295
296 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
297
298 // Load array def with activated templates
299 $def = array();
300 $sql = "SELECT nom";
301 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
302 $sql .= " WHERE type = '".$db->escape($type)."'";
303 $sql .= " AND entity = ".((int) $conf->entity);
304 $resql = $db->query($sql);
305 if ($resql) {
306 $i = 0;
307 $num_rows = $db->num_rows($resql);
308 while ($i < $num_rows) {
309 $array = $db->fetch_array($resql);
310 if (is_array($array)) {
311 array_push($def, $array[0]);
312 }
313 $i++;
314 }
315 } else {
316 dol_print_error($db);
317 }
318
319 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
320 print '<table class="noborder centpercent">'."\n";
321 print '<tr class="liste_titre">'."\n";
322 print '<td>'.$langs->trans("Name").'</td>';
323 print '<td>'.$langs->trans("Description").'</td>';
324 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
325 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
326 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
327 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
328 print "</tr>\n";
329
330 clearstatcache();
331
332 foreach ($dirmodels as $reldir) {
333 foreach (array('', '/doc') as $valdir) {
334 $realpath = $reldir."core/modules/".$moduledir.$valdir;
335 $dir = dol_buildpath($realpath);
336
337 if (is_dir($dir)) {
338 $handle = opendir($dir);
339 if (is_resource($handle)) {
340 $filelist = array();
341 while (($file = readdir($handle)) !== false) {
342 $filelist[] = $file;
343 }
344 closedir($handle);
345 arsort($filelist);
346
347 foreach ($filelist as $file) {
348 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
349 if (file_exists($dir.'/'.$file)) {
350 $name = substr($file, 4, dol_strlen($file) - 16);
351 $classname = substr($file, 0, dol_strlen($file) - 12);
352
353 require_once $dir.'/'.$file;
354 $module = new $classname($db);
355
356 '@phan-var-force ModelePDFStockTransfer $module';
357
358 $modulequalified = 1;
359 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
360 $modulequalified = 0;
361 }
362 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
363 $modulequalified = 0;
364 }
365
366 if ($modulequalified) {
367 print '<tr class="oddeven"><td>';
368 print(empty($module->name) ? $name : $module->name);
369 print "</td><td>\n";
370 if (method_exists($module, 'info')) {
371 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
372 } else {
373 print $module->description;
374 }
375 print '</td>';
376
377 // Active
378 if (in_array($name, $def)) {
379 print '<td class="center">'."\n";
380 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.urlencode($name).'&token='.newToken().'">';
381 print img_picto($langs->trans("Enabled"), 'switch_on');
382 print '</a>';
383 print '</td>';
384 } else {
385 print '<td class="center">'."\n";
386 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>';
387 print "</td>";
388 }
389
390 // Default
391 print '<td class="center">';
392 $constforvar = strtoupper($myTmpObjectKey).'_ADDON_PDF';
393 if (getDolGlobalString($constforvar) == $name) {
394 print img_picto($langs->trans("Default"), 'on');
395 } else {
396 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>';
397 }
398 print '</td>';
399
400 // Info
401 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
402 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
403 if ($module->type == 'pdf') {
404 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
405 }
406 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
407
408 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
409 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
410 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
411
412 print '<td class="center">';
413 print $form->textwithpicto('', $htmltooltip, 1, 'info');
414 print '</td>';
415
416 // Preview
417 print '<td class="center">';
418 if ($module->type == 'pdf') {
419 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
420 } else {
421 print img_object($langs->transnoentitiesnoconv("PreviewNotAvailable"), 'generic');
422 }
423 print '</td>';
424
425 print "</tr>\n";
426 }
427 }
428 }
429 }
430 }
431 }
432 }
433 }
434
435 print '</table></div>';
436}
437
438
439print '<br>';
440print load_fiche_titre($langs->trans("OtherOptions"), '', '');
441
442print '<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
443print '<table class="noborder centpercent">';
444
445print '<tr class="liste_titre">';
446print '<td>'.$langs->trans("Parameter").'</td>';
447print '<td></td>';
448print '</tr>'."\n";
449
450// Notifications
451/*
452print '<tr class="oddeven">';
453print '<td>'.img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("Notifications").'</td>';
454print '<td colspan="2">';
455print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification");
456print '</td></tr>';
457*/
458
459// More PDF options
460print '<tr class="oddeven">';
461print '<td>'.img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("MoreOptionsRelatedToPDF").'</td>';
462print '<td colspan="2">';
463print img_picto('', 'url', 'class="pictofixedwidth"').'<a href="'.DOL_URL_ROOT.'/admin/pdf_other.php">'.$langs->trans("SeeInPDFSetupPage").'</a>';
464print '</td></tr>';
465
466print '</table></div>';
467
468
469// Page end
470print dol_get_fiche_end();
471
472llxFooter();
473$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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage generation of HTML components Only common components must be here.
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, $allowothertags=array())
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, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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:128
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.