dolibarr 21.0.0-alpha
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 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 ModelePDFAsset $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
200foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
201 if ($myTmpObjectArray['includerefgeneration']) {
202 /*
203 * Assets Numbering model
204 */
205 $setupnotempty++;
206
207 print load_fiche_titre($langs->trans("AssetNumberingModules", $myTmpObjectKey), '', '');
208
209 print '<table class="noborder centpercent">';
210 print '<tr class="liste_titre">';
211 print '<td>'.$langs->trans("Name").'</td>';
212 print '<td>'.$langs->trans("Description").'</td>';
213 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
214 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
215 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
216 print '</tr>'."\n";
217
218 clearstatcache();
219
220 foreach ($dirmodels as $reldir) {
221 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
222
223 if (is_dir($dir)) {
224 $handle = opendir($dir);
225 if (is_resource($handle)) {
226 while (($file = readdir($handle)) !== false) {
227 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
228 $file = substr($file, 0, dol_strlen($file) - 4);
229
230 require_once $dir.'/'.$file.'.php';
231
232 $module = new $file($db);
233 '@phan-var-force ModeleNumRefAsset $module';
234
235 // Show modules according to feature level
236 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
237 continue;
238 }
239 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
240 continue;
241 }
242
243 if ($module->isEnabled()) {
244 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
245
246 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
247 print $module->info($langs);
248 print '</td>';
249
250 // Show example of the numbering model
251 print '<td class="nowrap">';
252 $tmp = $module->getExample();
253 if (preg_match('/^Error/', $tmp)) {
254 $langs->load("errors");
255 print '<div class="error">'.$langs->trans($tmp).'</div>';
256 } elseif ($tmp == 'NotConfigured') {
257 print $langs->trans($tmp);
258 } else {
259 print $tmp;
260 }
261 print '</td>'."\n";
262
263 print '<td class="center">';
264 $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
265 if (getDolGlobalString($constforvar) == $file) {
266 print img_picto($langs->trans("Activated"), 'switch_on');
267 } else {
268 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
269 print img_picto($langs->trans("Disabled"), 'switch_off');
270 print '</a>';
271 }
272 print '</td>';
273
274 $className = $myTmpObjectArray['class'];
275 $mytmpinstance = new $className($db);
276 $mytmpinstance->initAsSpecimen();
277
278 // Info
279 $htmltooltip = '';
280 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
281
282 $nextval = $module->getNextValue($mytmpinstance);
283 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
284 $htmltooltip .= ''.$langs->trans("NextValue").': ';
285 if ($nextval) {
286 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
287 $nextval = $langs->trans($nextval);
288 }
289 $htmltooltip .= $nextval.'<br>';
290 } else {
291 $htmltooltip .= $langs->trans($module->error).'<br>';
292 }
293 }
294
295 print '<td class="center">';
296 print $form->textwithpicto('', $htmltooltip, 1, 0);
297 print '</td>';
298
299 print "</tr>\n";
300 }
301 }
302 }
303 closedir($handle);
304 }
305 }
306 }
307 print "</table><br>\n";
308 }
309
310 if ($myTmpObjectArray['includedocgeneration']) {
311 /*
312 * Document templates generators
313 */
314 $setupnotempty++;
315 $type = strtolower($myTmpObjectKey);
316
317 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
318
319 // Load array def with activated templates
320 $def = array();
321 $sql = "SELECT nom";
322 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
323 $sql .= " WHERE type = '".$db->escape($type)."'";
324 $sql .= " AND entity = ".$conf->entity;
325 $resql = $db->query($sql);
326 if ($resql) {
327 $i = 0;
328 $num_rows = $db->num_rows($resql);
329 while ($i < $num_rows) {
330 $array = $db->fetch_array($resql);
331 if (is_array($array)) {
332 array_push($def, $array[0]);
333 }
334 $i++;
335 }
336 } else {
337 dol_print_error($db);
338 }
339
340 print "<table class=\"noborder\" width=\"100%\">\n";
341 print "<tr class=\"liste_titre\">\n";
342 print '<td>'.$langs->trans("Name").'</td>';
343 print '<td>'.$langs->trans("Description").'</td>';
344 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
345 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
346 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
347 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
348 print "</tr>\n";
349
350 clearstatcache();
351
352 foreach ($dirmodels as $reldir) {
353 foreach (array('', '/doc') as $valdir) {
354 $realpath = $reldir."core/modules/".$moduledir.$valdir;
355 $dir = dol_buildpath($realpath);
356
357 if (is_dir($dir)) {
358 $handle = opendir($dir);
359 if (is_resource($handle)) {
360 $filelist = array();
361 while (($file = readdir($handle)) !== false) {
362 $filelist[] = $file;
363 }
364 closedir($handle);
365 arsort($filelist);
366
367 foreach ($filelist as $file) {
368 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
369 if (file_exists($dir.'/'.$file)) {
370 $name = substr($file, 4, dol_strlen($file) - 16);
371 $classname = substr($file, 0, dol_strlen($file) - 12);
372
373 require_once $dir.'/'.$file;
374 $module = new $classname($db);
375 '@phan-var-force ModelePDFAsset $module';
376
377 $modulequalified = 1;
378 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
379 $modulequalified = 0;
380 }
381 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
382 $modulequalified = 0;
383 }
384
385 if ($modulequalified) {
386 print '<tr class="oddeven"><td width="100">';
387 print(empty($module->name) ? $name : $module->name);
388 print "</td><td>\n";
389 if (method_exists($module, 'info')) {
390 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
391 } else {
392 print $module->description;
393 }
394 print '</td>';
395
396 // Active
397 if (in_array($name, $def)) {
398 print '<td class="center">'."\n";
399 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
400 print img_picto($langs->trans("Enabled"), 'switch_on');
401 print '</a>';
402 print '</td>';
403 } else {
404 print '<td class="center">'."\n";
405 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>';
406 print "</td>";
407 }
408
409 // Default
410 print '<td class="center">';
411 $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
412 if (getDolGlobalString($constforvar) == $name) {
413 //print img_picto($langs->trans("Default"), 'on');
414 // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
415 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>';
416 } else {
417 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>';
418 }
419 print '</td>';
420
421 // Info
422 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
423 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
424 if ($module->type == 'pdf') {
425 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
426 }
427 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
428
429 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
430 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
431 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
432
433 print '<td class="center">';
434 print $form->textwithpicto('', $htmltooltip, 1, 0);
435 print '</td>';
436
437 // Preview
438 print '<td class="center">';
439 if ($module->type == 'pdf') {
440 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
441 } else {
442 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
443 }
444 print '</td>';
445
446 print "</tr>\n";
447 }
448 }
449 }
450 }
451 }
452 }
453 }
454 }
455
456 print '</table>';
457 }
458}
459
460if ($action == 'edit') {
461 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
462 print '<input type="hidden" name="token" value="'.newToken().'">';
463 print '<input type="hidden" name="action" value="update">';
464
465 print '<table class="noborder centpercent">';
466 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
467
468 foreach ($arrayofparameters as $constname => $val) {
469 if ($val['enabled'] == 1) {
470 $setupnotempty++;
471 print '<tr class="oddeven"><td>';
472 $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
473 print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
474 print '</td><td>';
475
476 if ($val['type'] == 'textarea') {
477 print '<textarea class="flat" name="'.$constname.'" id="'.$constname.'" cols="50" rows="5" wrap="soft">' . "\n";
478 print getDolGlobalString($constname);
479 print "</textarea>\n";
480 } elseif ($val['type'] == 'html') {
481 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
482 $doleditor = new DolEditor($constname, getDolGlobalString($constname), '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
483 $doleditor->Create();
484 } elseif ($val['type'] == 'yesno') {
485 print $form->selectyesno($constname, getDolGlobalString($constname), 1);
486 } elseif (preg_match('/emailtemplate:/', $val['type'])) {
487 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
488 $formmail = new FormMail($db);
489
490 $tmp = explode(':', $val['type']);
491 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
492 //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
493 $arrayofmessagename = array();
494 if (is_array($formmail->lines_model)) {
495 foreach ($formmail->lines_model as $modelmail) {
496 //var_dump($modelmail);
497 $moreonlabel = '';
498 if (!empty($arrayofmessagename[$modelmail->label])) {
499 $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
500 }
501 // The 'label' is the key that is unique if we exclude the language
502 $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\‍(|\‍)/', '', $modelmail->label)) . $moreonlabel;
503 }
504 }
505 print $form->selectarray($constname, $arrayofmessagename, getDolGlobalString($constname), 'None', 0, 0, '', 0, 0, 0, '', '', 1);
506 } elseif (preg_match('/category:/', $val['type'])) {
507 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
508 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
509 $formother = new FormOther($db);
510
511 $tmp = explode(':', $val['type']);
512 print img_picto('', 'category', 'class="pictofixedwidth"');
513 print $formother->select_categories($tmp[1], getDolGlobalString($constname), $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
514 } elseif (preg_match('/thirdparty_type/', $val['type'])) {
515 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
516 $formcompany = new FormCompany($db);
517 print $formcompany->selectProspectCustomerType(getDolGlobalString($constname), $constname);
518 } elseif ($val['type'] == 'securekey') {
519 print '<input required="required" type="text" class="flat" id="'.$constname.'" name="'.$constname.'" value="'.(GETPOST($constname, 'alpha') ? GETPOST($constname, 'alpha') : getDolGlobalString($constname)).'" size="40">';
520 if (!empty($conf->use_javascript_ajax)) {
521 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token'.$constname.'" class="linkobject"');
522 }
523
524 // Add button to autosuggest a key
525 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
526 print dolJSToSetRandomPassword($constname, 'generate_token'.$constname);
527 } elseif ($val['type'] == 'product') {
528 if (isModEnabled("product") || isModEnabled("service")) {
529 $selected = getDolGlobalString($constname);
530 $form->select_produits($selected, $constname, '', 0);
531 }
532 } elseif ($val['type'] == 'accountancy_code') {
533 $selected = getDolGlobalString($constname);
534 if (isModEnabled('accounting')) {
535 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
536 $formaccounting = new FormAccounting($db);
537 print $formaccounting->select_account($selected, $constname, 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
538 } else {
539 print '<input name="' . $constname . '" class="maxwidth200" value="' . dol_escape_htmltag($selected) . '">';
540 }
541 } elseif ($val['type'] == 'accountancy_category') {
542 $selected = getDolGlobalString($constname);
543 if (isModEnabled('accounting')) {
544 print '<input type="text" name="' . $constname . '" list="pcg_type_datalist" value="' . $selected . '">';
545 // autosuggest from existing account types if found
546 print '<datalist id="pcg_type_datalist">';
547 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancysystem.class.php';
548 $accountsystem = new AccountancySystem($db);
549 $accountsystem->fetch(getDolGlobalInt('CHARTOFACCOUNTS'));
550 $sql = 'SELECT DISTINCT pcg_type FROM ' . MAIN_DB_PREFIX . 'accounting_account';
551 $sql .= " WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) . "'";
552 $sql .= ' AND entity in ('.getEntity('accounting_account', 0).')'; // Always limit to current entity. No sharing in accountancy.
553 $sql .= ' LIMIT 50000'; // just as a sanity check
554 $resql = $db->query($sql);
555 if ($resql) {
556 while ($obj = $db->fetch_object($resql)) {
557 print '<option value="' . dol_escape_htmltag($obj->pcg_type) . '">';
558 }
559 }
560 print '</datalist>';
561 } else {
562 print '<input name="' . $constname . '" class="maxwidth200" value="' . dol_escape_htmltag($selected) . '">';
563 }
564 } else {
565 print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($constname).'">';
566 }
567 print '</td></tr>';
568 }
569 }
570 print '</table>';
571
572 print '<br><div class="center">';
573 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
574 print '</div>';
575
576 print '</form>';
577 print '<br>';
578} else {
579 if (!empty($arrayofparameters)) {
580 print '<table class="noborder centpercent">';
581 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
582
583 foreach ($arrayofparameters as $constname => $val) {
584 if ($val['enabled'] == 1) {
585 $setupnotempty++;
586 print '<tr class="oddeven"><td>';
587 $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
588 print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
589 print '</td><td>';
590
591 if ($val['type'] == 'textarea') {
592 print dol_nl2br(getDolGlobalString($constname));
593 } elseif ($val['type'] == 'html') {
594 print getDolGlobalString($constname);
595 } elseif ($val['type'] == 'yesno') {
596 print ajax_constantonoff($constname);
597 } elseif (preg_match('/emailtemplate:/', $val['type'])) {
598 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
599 $formmail = new FormMail($db);
600
601 $tmp = explode(':', $val['type']);
602
603 $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, getDolGlobalString($constname));
604 if ($template < 0) {
605 setEventMessages(null, $formmail->errors, 'errors');
606 }
607 print $langs->trans($template->label);
608 } elseif (preg_match('/category:/', $val['type'])) {
609 $c = new Categorie($db);
610 $result = $c->fetch(getDolGlobalInt($constname));
611 if ($result < 0) {
612 setEventMessages(null, $c->errors, 'errors');
613 } elseif ($result > 0) {
614 $ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
615 $toprint = array();
616 foreach ($ways as $way) {
617 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
618 }
619 print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
620 }
621 } elseif (preg_match('/thirdparty_type/', $val['type'])) {
622 if (getDolGlobalInt($constname) == 2) {
623 print $langs->trans("Prospect");
624 } elseif (getDolGlobalInt($constname) == 3) {
625 print $langs->trans("ProspectCustomer");
626 } elseif (getDolGlobalInt($constname) == 1) {
627 print $langs->trans("Customer");
628 } elseif (getDolGlobalInt($constname) == 0) {
629 print $langs->trans("NorProspectNorCustomer");
630 }
631 } elseif ($val['type'] == 'product') {
632 $product = new Product($db);
633 $resprod = $product->fetch(getDolGlobalInt($constname));
634 if ($resprod > 0) {
635 print $product->ref;
636 } elseif ($resprod < 0) {
637 setEventMessages(null, $object->errors, "errors");
638 }
639 } elseif ($val['type'] == 'accountancy_code') {
640 if (isModEnabled('accounting')) {
641 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
642 $accountingaccount = new AccountingAccount($db);
643 $accountingaccount->fetch(0, getDolGlobalString($constname), 1);
644
645 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
646 } else {
647 print getDolGlobalString($constname);
648 }
649 } else {
650 print getDolGlobalString($constname);
651 }
652 print '</td></tr>';
653 }
654 }
655
656 print '</table>';
657
658 print '<div class="tabsAction">';
659 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
660 print '</div>';
661 } else {
662 print '<br>'.$langs->trans("NothingToSetup");
663 }
664}
665
666if (empty($setupnotempty)) {
667 print '<br>'.$langs->trans("NothingToSetup");
668}
669
670// Page end
671print dol_get_fiche_end();
672
673llxFooter();
674$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:31
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:70
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.
llxFooter()
Footer empty.
Definition document.php:107
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)
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)
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)
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'.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_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:140
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.