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