dolibarr 24.0.0-beta
setup.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php';
37require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
38
39global $langs, $user;
40
41// Load translation files required by the page
42$langs->loadLangs(array("admin", "assets"));
43
44// Access control
45if (!$user->admin) {
47}
48
49// Parameters
50$action = GETPOST('action', 'aZ09');
51$backtopage = GETPOST('backtopage', 'alpha');
52
53$value = GETPOST('value', 'alpha');
54$label = GETPOST('label', 'alpha');
55$scandir = GETPOST('scan_dir', 'alpha');
56$type = 'asset';
57
58$arrayofparameters = array(
59 'ASSET_ACCOUNTANCY_CATEGORY' => array('type' => 'accountancy_category', 'enabled' => 1),
60 'ASSET_DEPRECIATION_DURATION_PER_YEAR' => array('type' => 'string', 'css' => 'minwidth200', 'enabled' => 1),
61 //'ASSET_MYPARAM2'=>array('type'=>'textarea','enabled'=>1),
62 //'ASSET_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
63 //'ASSET_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
64 //'ASSET_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
65 //'ASSET_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
66 //'ASSET_MYPARAM6'=>array('type'=>'securekey', 'enabled'=>1),
67 //'ASSET_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
68);
69
70$error = 0;
71
72$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
73
74$moduledir = 'asset';
75$myTmpObjects = [
76 'asset' => array('label' => 'Asset', 'includerefgeneration' => 1, 'includedocgeneration' => 0, 'class' => 'Asset')
77];
78
79$tmpobjectkey = GETPOST('object', 'aZ09');
80if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
81 accessforbidden('Bad value for object. Hack attempt ?');
82}
83
84
85/*
86 * Actions
87 */
88
89include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
90
91if ($action == 'updateMask') {
92 $maskconst = GETPOST('maskconst', 'alpha');
93 $mask = GETPOST('mask', 'alpha');
94
95 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
96 $res = dolibarr_set_const($db, $maskconst, $mask, 'chaine', 0, '', $conf->entity);
97 if (!($res > 0)) {
98 $error++;
99 }
100 }
101
102 if (!$error) {
103 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
104 } else {
105 setEventMessages($langs->trans("Error"), null, 'errors');
106 }
107} elseif ($action == 'specimen' && $tmpobjectkey) {
108 $modele = GETPOST('module', 'alpha');
109
110 $className = $myTmpObjects[$tmpobjectkey]['class'];
111 $tmpobject = new $className($db);
112 $tmpobject->initAsSpecimen();
113
114 // Search template files
115 $file = '';
116 $classname = '';
117 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
118 foreach ($dirmodels as $reldir) {
119 $file = dol_buildpath($reldir."core/modules/asset/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
120 if (file_exists($file)) {
121 $classname = "pdf_".$modele;
122 break;
123 }
124 }
125
126 if ($classname !== '') {
127 require_once $file;
128
129 $module = new $classname($db);
130 '@phan-var-force ModelePDFAsset $module';
131
132 if ($module->write_file($tmpobject, $langs) > 0) {
133 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
134 return;
135 } else {
136 setEventMessages($module->error, null, 'errors');
137 dol_syslog($module->error, LOG_ERR);
138 }
139 } else {
140 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
141 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
142 }
143} elseif ($action == 'setmod') {
144 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
145 if (!empty($tmpobjectkey)) {
146 $constforval = 'ASSET_'.strtoupper($tmpobjectkey)."_ADDON";
147 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
148 }
149} elseif ($action == 'set') {
150 // Activate a model
151 $ret = addDocumentModel($value, $type, $label, $scandir);
152} elseif ($action == 'del') {
153 $ret = delDocumentModel($value, $type);
154 if ($ret > 0) {
155 if (!empty($tmpobjectkey)) {
156 $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
157 if (getDolGlobalString($constforval) == "$value") {
158 dolibarr_del_const($db, $constforval, $conf->entity);
159 }
160 }
161 }
162} elseif ($action == 'setdoc') {
163 // Set or unset default model
164 if (!empty($tmpobjectkey)) {
165 $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
166 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
167 // The constant that was read before the new set
168 // We therefore requires a variable to have a coherent view
169 $conf->global->$constforval = $value;
170 }
171
172 // We disable/enable the document template (into llx_document_model table)
173 $ret = delDocumentModel($value, $type);
174 if ($ret > 0) {
175 $ret = addDocumentModel($value, $type, $label, $scandir);
176 }
177 }
178} elseif ($action == 'unsetdoc') {
179 if (!empty($tmpobjectkey)) {
180 $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
181 dolibarr_del_const($db, $constforval, $conf->entity);
182 }
183}
184
185
186
187/*
188 * View
189 */
190
191$form = new Form($db);
192
193$help_url = '';
194$page_name = "AssetSetup";
195
196llxHeader('', $langs->trans($page_name), $help_url);
197
198// Subheader
199$linkback = '<a href="'.($backtopage ? $backtopage : 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>';
200
201print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
202
203// Configuration header
204$head = assetAdminPrepareHead();
205print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "asset");
206
207foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
208 if ($myTmpObjectArray['includerefgeneration']) {
209 /*
210 * Assets Numbering model
211 */
212 print load_fiche_titre($langs->trans("AssetNumberingModules", $myTmpObjectKey), '', '');
213
214 print '<table class="noborder centpercent">';
215 print '<tr class="liste_titre">';
216 print '<td>'.$langs->trans("Name").'</td>';
217 print '<td>'.$langs->trans("Description").'</td>';
218 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
219 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
220 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
221 print '</tr>'."\n";
222
223 clearstatcache();
224
225 foreach ($dirmodels as $reldir) {
226 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
227
228 if (is_dir($dir)) {
229 $handle = opendir($dir);
230 if (is_resource($handle)) {
231 while (($file = readdir($handle)) !== false) {
232 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
233 $file = substr($file, 0, dol_strlen($file) - 4);
234
235 require_once $dir.'/'.$file.'.php';
236
237 $module = new $file($db);
238 '@phan-var-force ModeleNumRefAsset $module';
239
240 // Show modules according to feature level
241 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
242 continue;
243 }
244 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
245 continue;
246 }
247
248 if ($module->isEnabled()) {
249 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
250
251 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
252 print $module->info($langs);
253 print '</td>';
254
255 // Show example of the numbering model
256 print '<td class="nowrap">';
257 $tmp = $module->getExample();
258 if (preg_match('/^Error/', $tmp)) {
259 $langs->load("errors");
260 print '<div class="error">'.$langs->trans($tmp).'</div>';
261 } elseif ($tmp == 'NotConfigured') {
262 print $langs->trans($tmp);
263 } else {
264 print $tmp;
265 }
266 print '</td>'."\n";
267
268 print '<td class="center">';
269 $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
270 $defaultifnotset = 'mod_asset_standard';
271 $activenumberingmodel = getDolGlobalString($constforvar, $defaultifnotset);
272 if ($activenumberingmodel == $file) {
273 print img_picto($langs->trans("Activated"), 'switch_on');
274 } else {
275 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
276 print img_picto($langs->trans("Disabled"), 'switch_off');
277 print '</a>';
278 }
279 print '</td>';
280
281 $className = $myTmpObjectArray['class'];
282 $mytmpinstance = new $className($db);
283 $mytmpinstance->initAsSpecimen();
284
285 // Info
286 $htmltooltip = '';
287 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
288
289 $nextval = $module->getNextValue($mytmpinstance);
290 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
291 $htmltooltip .= ''.$langs->trans("NextValue").': ';
292 if ($nextval) {
293 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
294 $nextval = $langs->trans($nextval);
295 }
296 $htmltooltip .= $nextval.'<br>';
297 } else {
298 $htmltooltip .= $langs->trans($module->error).'<br>';
299 }
300 }
301
302 print '<td class="center">';
303 print $form->textwithpicto('', $htmltooltip, 1, 'info');
304 print '</td>';
305
306 print "</tr>\n";
307 }
308 }
309 }
310 closedir($handle);
311 }
312 }
313 }
314 print "</table><br>\n";
315 }
316
317 if ($myTmpObjectArray['includedocgeneration']) {
318 /*
319 * Document templates generators
320 */
321 $type = strtolower($myTmpObjectKey);
322
323 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
324
325 // Load array def with activated templates
326 // TODO Replace with $def = getListOfModels($db, $type);
327 $def = array();
328 $sql = "SELECT nom";
329 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
330 $sql .= " WHERE type = '".$db->escape($type)."'";
331 $sql .= " AND entity = ".((int) $conf->entity);
332 $resql = $db->query($sql);
333 if ($resql) {
334 $i = 0;
335 $num_rows = $db->num_rows($resql);
336 while ($i < $num_rows) {
337 $array = $db->fetch_array($resql);
338 if (is_array($array)) {
339 array_push($def, $array[0]);
340 }
341 $i++;
342 }
343 } else {
345 }
346
347 print "<table class=\"noborder\" width=\"100%\">\n";
348 print "<tr class=\"liste_titre\">\n";
349 print '<td>'.$langs->trans("Name").'</td>';
350 print '<td>'.$langs->trans("Description").'</td>';
351 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
352 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
353 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
354 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
355 print "</tr>\n";
356
357 clearstatcache();
358
359 foreach ($dirmodels as $reldir) {
360 foreach (array('', '/doc') as $valdir) {
361 $realpath = $reldir."core/modules/".$moduledir.$valdir;
362 $dir = dol_buildpath($realpath);
363
364 if (is_dir($dir)) {
365 $handle = opendir($dir);
366 if (is_resource($handle)) {
367 $filelist = array();
368 while (($file = readdir($handle)) !== false) {
369 $filelist[] = $file;
370 }
371 closedir($handle);
372 arsort($filelist);
373
374 foreach ($filelist as $file) {
375 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
376 if (file_exists($dir.'/'.$file)) {
377 $name = substr($file, 4, dol_strlen($file) - 16);
378 $classname = substr($file, 0, dol_strlen($file) - 12);
379
380 require_once $dir.'/'.$file;
381 $module = new $classname($db);
382 '@phan-var-force ModelePDFAsset $module';
383
384 $modulequalified = 1;
385 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
386 $modulequalified = 0;
387 }
388 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
389 $modulequalified = 0;
390 }
391
392 if ($modulequalified) {
393 print '<tr class="oddeven"><td width="100">';
394 print(empty($module->name) ? $name : $module->name);
395 print "</td><td>\n";
396 if (method_exists($module, 'info')) {
397 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
398 } else {
399 print $module->description;
400 }
401 print '</td>';
402
403 // Active
404 if (in_array($name, $def)) {
405 print '<td class="center">'."\n";
406 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
407 print img_picto($langs->trans("Enabled"), 'switch_on');
408 print '</a>';
409 print '</td>';
410 } else {
411 print '<td class="center">'."\n";
412 print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
413 print "</td>";
414 }
415
416 // Default
417 print '<td class="center">';
418 $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
419 if (getDolGlobalString($constforvar) == $name) {
420 //print img_picto($langs->trans("Default"), 'on');
421 // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
422 print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&token='.newToken().'&object='.urlencode(strtolower($myTmpObjectKey)).'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&amp;type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
423 } else {
424 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&object='.urlencode(strtolower($myTmpObjectKey)).'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
425 }
426 print '</td>';
427
428 // Info
429 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
430 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
431 if ($module->type == 'pdf') {
432 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
433 }
434 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
435
436 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
437 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
438 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
439
440 print '<td class="center">';
441 print $form->textwithpicto('', $htmltooltip, 1, 'info');
442 print '</td>';
443
444 // Preview
445 print '<td class="center">';
446 if ($module->type == 'pdf') {
447 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
448 } else {
449 print img_object($langs->transnoentitiesnoconv("PreviewNotAvailable"), 'generic');
450 }
451 print '</td>';
452
453 print "</tr>\n";
454 }
455 }
456 }
457 }
458 }
459 }
460 }
461 }
462
463 print '</table>';
464 }
465}
466
467if ($action == 'edit') {
468 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
469 print '<input type="hidden" name="token" value="'.newToken().'">';
470 print '<input type="hidden" name="action" value="update">';
471
472 print '<table class="noborder centpercent">';
473 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
474
475 foreach ($arrayofparameters as $constname => $val) {
476 if ($val['enabled'] == 1) {
477 print '<tr class="oddeven"><td>';
478 $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
479 print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
480 print '</td><td>';
481
482 if ($val['type'] == 'textarea') {
483 print '<textarea class="flat" name="'.$constname.'" id="'.$constname.'" cols="50" rows="5" wrap="soft">' . "\n";
484 print getDolGlobalString($constname);
485 print "</textarea>\n";
486 } elseif ($val['type'] == 'html') {
487 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
488 $doleditor = new DolEditor($constname, getDolGlobalString($constname), '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
489 $doleditor->Create();
490 } elseif ($val['type'] == 'yesno') {
491 print $form->selectyesno($constname, getDolGlobalString($constname), 1);
492 } elseif (preg_match('/emailtemplate:/', $val['type'])) {
493 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
494 $formmail = new FormMail($db);
495
496 $tmp = explode(':', $val['type']);
497 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
498 //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
499 $arrayofmessagename = array();
500 if (is_array($formmail->lines_model)) {
501 foreach ($formmail->lines_model as $modelmail) {
502 //var_dump($modelmail);
503 $moreonlabel = '';
504 if (!empty($arrayofmessagename[$modelmail->label])) {
505 $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
506 }
507 // The 'label' is the key that is unique if we exclude the language
508 $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\‍(|\‍)/', '', $modelmail->label)) . $moreonlabel;
509 }
510 }
511 print $form->selectarray($constname, $arrayofmessagename, getDolGlobalString($constname), 'None', 0, 0, '', 0, 0, 0, '', '', 1);
512 } elseif (preg_match('/category:/', $val['type'])) {
513 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
514 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
515 $formother = new FormOther($db);
516
517 $tmp = explode(':', $val['type']);
518 print img_picto('', 'category', 'class="pictofixedwidth"');
519 print $formother->select_categories($tmp[1], getDolGlobalInt($constname), $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
520 } elseif (preg_match('/thirdparty_type/', $val['type'])) {
521 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
522 $formcompany = new FormCompany($db);
523 print $formcompany->selectProspectCustomerType(getDolGlobalString($constname), $constname);
524 } elseif ($val['type'] == 'securekey') {
525 print '<input required="required" type="text" class="flat" id="'.$constname.'" name="'.$constname.'" value="'.(GETPOST($constname, 'alpha') ? GETPOST($constname, 'alpha') : getDolGlobalString($constname)).'" size="40">';
526 if (!empty($conf->use_javascript_ajax)) {
527 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token'.$constname.'" class="linkobject"');
528 }
529
530 // Add button to autosuggest a key
531 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
532 print dolJSToSetRandomPassword($constname, 'generate_token'.$constname);
533 } elseif ($val['type'] == 'product') {
534 if (isModEnabled("product") || isModEnabled("service")) {
535 $selected = getDolGlobalInt($constname);
536 $form->select_produits($selected, $constname, '', 0);
537 }
538 } elseif ($val['type'] == 'accountancy_code') {
539 $selected = getDolGlobalString($constname);
540 if (isModEnabled('accounting')) {
541 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
542 $formaccounting = new FormAccounting($db);
543 print $formaccounting->select_account($selected, $constname, 1, array(), 1, 1, 'minwidth150 maxwidth300', '1');
544 } else {
545 print '<input name="' . $constname . '" class="maxwidth200" value="' . dol_escape_htmltag($selected) . '">';
546 }
547 } elseif ($val['type'] == 'accountancy_category') {
548 $selected = getDolGlobalString($constname);
549 if (isModEnabled('accounting')) {
550 print '<input type="text" name="' . $constname . '" list="pcg_type_datalist" value="' . $selected . '">';
551 // autosuggest from existing account types if found
552 print '<datalist id="pcg_type_datalist">';
553 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancysystem.class.php';
554 $accountsystem = new AccountancySystem($db);
555 $accountsystem->fetch(getDolGlobalInt('CHARTOFACCOUNTS'));
556 $sql = 'SELECT DISTINCT pcg_type FROM ' . MAIN_DB_PREFIX . 'accounting_account';
557 $sql .= " WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) . "'";
558 $sql .= ' AND entity in ('.getEntity('accounting_account', 0).')'; // Always limit to current entity. No sharing in accountancy.
559 $sql .= ' LIMIT 50000'; // just as a sanity check
560 $resql = $db->query($sql);
561 if ($resql) {
562 while ($obj = $db->fetch_object($resql)) {
563 print '<option value="' . dol_escape_htmltag($obj->pcg_type) . '">';
564 }
565 }
566 print '</datalist>';
567 } else {
568 print '<input name="' . $constname . '" class="maxwidth200" value="' . dol_escape_htmltag($selected) . '">';
569 }
570 } else {
571 print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($constname).'">';
572 }
573 print '</td></tr>';
574 }
575 }
576 print '</table>';
577
578 print '<br><div class="center">';
579 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
580 print '</div>';
581
582 print '</form>';
583 print '<br>';
584} else {
585 if (!empty($arrayofparameters)) {
586 print '<table class="noborder centpercent">';
587 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td></td></tr>';
588
589 foreach ($arrayofparameters as $constname => $val) {
590 if ($val['enabled'] == 1) {
591 print '<tr class="oddeven"><td>';
592 $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
593 print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
594 print '</td><td>';
595
596 if ($val['type'] == 'textarea') {
597 print dol_nl2br(getDolGlobalString($constname));
598 } elseif ($val['type'] == 'html') {
599 print getDolGlobalString($constname);
600 } elseif ($val['type'] == 'yesno') {
601 print ajax_constantonoff($constname);
602 } elseif (preg_match('/emailtemplate:/', $val['type'])) {
603 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
604 $formmail = new FormMail($db);
605
606 $tmp = explode(':', $val['type']);
607
608 $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, getDolGlobalInt($constname));
609 if ($template < 0) {
610 setEventMessages(null, $formmail->errors, 'errors');
611 }
612 print $langs->trans($template->label);
613 } elseif (preg_match('/category:/', $val['type'])) {
614 $c = new Categorie($db);
615 $result = $c->fetch(getDolGlobalInt($constname));
616 if ($result < 0) {
617 setEventMessages(null, $c->errors, 'errors');
618 } elseif ($result > 0) {
619 $ways = $c->print_all_ways('auto', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
620 $toprint = array();
621 foreach ($ways as $way) {
622 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
623 }
624 print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
625 }
626 } elseif (preg_match('/thirdparty_type/', $val['type'])) {
627 if (getDolGlobalInt($constname) == 2) {
628 print $langs->trans("Prospect");
629 } elseif (getDolGlobalInt($constname) == 3) {
630 print $langs->trans("ProspectCustomer");
631 } elseif (getDolGlobalInt($constname) == 1) {
632 print $langs->trans("Customer");
633 } elseif (getDolGlobalInt($constname) == 0) {
634 print $langs->trans("NorProspectNorCustomer");
635 }
636 } elseif ($val['type'] == 'product') {
637 $product = new Product($db);
638 $resprod = $product->fetch(getDolGlobalInt($constname));
639 if ($resprod > 0) {
640 print $product->ref;
641 } elseif ($resprod < 0) {
642 setEventMessages(null, $product->errors, "errors");
643 }
644 } elseif ($val['type'] == 'accountancy_code') {
645 if (isModEnabled('accounting')) {
646 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
647 $accountingaccount = new AccountingAccount($db);
648 $accountingaccount->fetch(0, getDolGlobalString($constname), 1);
649
650 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
651 } else {
652 print getDolGlobalString($constname);
653 }
654 } else {
655 print getDolGlobalString($constname);
656 }
657 print '</td></tr>';
658 }
659 }
660
661 print '</table>';
662
663 print '<div class="tabsAction">';
664 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
665 print '</div>';
666 } else {
667 print '<br>'.$langs->trans("NothingToSetup");
668 }
669}
670
671
672// Page end
673print dol_get_fiche_end();
674
675llxFooter();
676$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.
assetAdminPrepareHead()
Prepare admin pages header.
Definition asset.lib.php:32
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
$c
Definition line.php:334
Class to manage accountancy systems.
Class to manage accounting accounts.
Class to manage categories.
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components for accounting management.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
Class to help generate other html components Only common components are here.
Class to manage products or services.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
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.
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Output javascript to autoset a generated password using default module into a HTML element.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.