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