dolibarr 25.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-2026 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2026 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 && dol_substr($file, dol_strlen($file) - 3, 3) == 'php') {
212 $file = dol_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 printDocumentModelList($type, $moduledir, strtoupper($myTmpObjectKey).'_ADDON_PDF', $langs->trans("DocumentModules", $myTmpObjectKey), array(
297 'Logo' => 'option_logo',
298 'MultiLanguage' => 'option_multilang',
299 ));
300}
301
302
303print '<br>';
304print load_fiche_titre($langs->trans("OtherOptions"), '', '');
305
306print '<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
307print '<table class="noborder centpercent">';
308
309print '<tr class="liste_titre">';
310print '<td>'.$langs->trans("Parameter").'</td>';
311print '<td></td>';
312print '</tr>'."\n";
313
314// Notifications
315/*
316print '<tr class="oddeven">';
317print '<td>'.img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("Notifications").'</td>';
318print '<td colspan="2">';
319print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification");
320print '</td></tr>';
321*/
322
323// More PDF options
324print '<tr class="oddeven">';
325print '<td>'.img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("MoreOptionsRelatedToPDF").'</td>';
326print '<td colspan="2">';
327print img_picto('', 'url', 'class="pictofixedwidth"').'<a href="'.DOL_URL_ROOT.'/admin/pdf_other.php">'.$langs->trans("SeeInPDFSetupPage").'</a>';
328print '</td></tr>';
329
330print '</table></div>';
331
332
333// Page end
334print dol_get_fiche_end();
335
336llxFooter();
337$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.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
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.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.