dolibarr 21.0.0-beta
setup.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 * Copyright (C) 2024 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
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$setupnotempty = 0;
73
74$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
75
76$moduledir = 'asset';
77$myTmpObjects = array();
78$myTmpObjects['asset'] = array('label' => 'Asset', 'includerefgeneration' => 1, 'includedocgeneration' => 0, 'class' => 'Asset');
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').'">'.$langs->trans("BackToModuleList").'</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 $setupnotempty++;
214
215 print load_fiche_titre($langs->trans("AssetNumberingModules", $myTmpObjectKey), '', '');
216
217 print '<table class="noborder centpercent">';
218 print '<tr class="liste_titre">';
219 print '<td>'.$langs->trans("Name").'</td>';
220 print '<td>'.$langs->trans("Description").'</td>';
221 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
222 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
223 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
224 print '</tr>'."\n";
225
226 clearstatcache();
227
228 foreach ($dirmodels as $reldir) {
229 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
230
231 if (is_dir($dir)) {
232 $handle = opendir($dir);
233 if (is_resource($handle)) {
234 while (($file = readdir($handle)) !== false) {
235 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
236 $file = substr($file, 0, dol_strlen($file) - 4);
237
238 require_once $dir.'/'.$file.'.php';
239
240 $module = new $file($db);
241 '@phan-var-force ModeleNumRefAsset $module';
242
243 // Show modules according to feature level
244 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
245 continue;
246 }
247 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
248 continue;
249 }
250
251 if ($module->isEnabled()) {
252 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
253
254 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
255 print $module->info($langs);
256 print '</td>';
257
258 // Show example of the numbering model
259 print '<td class="nowrap">';
260 $tmp = $module->getExample();
261 if (preg_match('/^Error/', $tmp)) {
262 $langs->load("errors");
263 print '<div class="error">'.$langs->trans($tmp).'</div>';
264 } elseif ($tmp == 'NotConfigured') {
265 print $langs->trans($tmp);
266 } else {
267 print $tmp;
268 }
269 print '</td>'."\n";
270
271 print '<td class="center">';
272 $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
273 if (getDolGlobalString($constforvar) == $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, 0);
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 $setupnotempty++;
323 $type = strtolower($myTmpObjectKey);
324
325 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
326
327 // Load array def with activated templates
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 = ".$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, 0);
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->trans("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="'.$_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 $setupnotempty++;
479 print '<tr class="oddeven"><td>';
480 $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
481 print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
482 print '</td><td>';
483
484 if ($val['type'] == 'textarea') {
485 print '<textarea class="flat" name="'.$constname.'" id="'.$constname.'" cols="50" rows="5" wrap="soft">' . "\n";
486 print getDolGlobalString($constname);
487 print "</textarea>\n";
488 } elseif ($val['type'] == 'html') {
489 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
490 $doleditor = new DolEditor($constname, getDolGlobalString($constname), '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
491 $doleditor->Create();
492 } elseif ($val['type'] == 'yesno') {
493 print $form->selectyesno($constname, getDolGlobalString($constname), 1);
494 } elseif (preg_match('/emailtemplate:/', $val['type'])) {
495 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
496 $formmail = new FormMail($db);
497
498 $tmp = explode(':', $val['type']);
499 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
500 //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
501 $arrayofmessagename = array();
502 if (is_array($formmail->lines_model)) {
503 foreach ($formmail->lines_model as $modelmail) {
504 //var_dump($modelmail);
505 $moreonlabel = '';
506 if (!empty($arrayofmessagename[$modelmail->label])) {
507 $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
508 }
509 // The 'label' is the key that is unique if we exclude the language
510 $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\‍(|\‍)/', '', $modelmail->label)) . $moreonlabel;
511 }
512 }
513 print $form->selectarray($constname, $arrayofmessagename, getDolGlobalString($constname), 'None', 0, 0, '', 0, 0, 0, '', '', 1);
514 } elseif (preg_match('/category:/', $val['type'])) {
515 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
516 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
517 $formother = new FormOther($db);
518
519 $tmp = explode(':', $val['type']);
520 print img_picto('', 'category', 'class="pictofixedwidth"');
521 print $formother->select_categories($tmp[1], getDolGlobalString($constname), $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
522 } elseif (preg_match('/thirdparty_type/', $val['type'])) {
523 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
524 $formcompany = new FormCompany($db);
525 print $formcompany->selectProspectCustomerType(getDolGlobalString($constname), $constname);
526 } elseif ($val['type'] == 'securekey') {
527 print '<input required="required" type="text" class="flat" id="'.$constname.'" name="'.$constname.'" value="'.(GETPOST($constname, 'alpha') ? GETPOST($constname, 'alpha') : getDolGlobalString($constname)).'" size="40">';
528 if (!empty($conf->use_javascript_ajax)) {
529 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token'.$constname.'" class="linkobject"');
530 }
531
532 // Add button to autosuggest a key
533 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
534 print dolJSToSetRandomPassword($constname, 'generate_token'.$constname);
535 } elseif ($val['type'] == 'product') {
536 if (isModEnabled("product") || isModEnabled("service")) {
537 $selected = getDolGlobalString($constname);
538 $form->select_produits($selected, $constname, '', 0);
539 }
540 } elseif ($val['type'] == 'accountancy_code') {
541 $selected = getDolGlobalString($constname);
542 if (isModEnabled('accounting')) {
543 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
544 $formaccounting = new FormAccounting($db);
545 print $formaccounting->select_account($selected, $constname, 1, array(), 1, 1, 'minwidth150 maxwidth300', 1);
546 } else {
547 print '<input name="' . $constname . '" class="maxwidth200" value="' . dol_escape_htmltag($selected) . '">';
548 }
549 } elseif ($val['type'] == 'accountancy_category') {
550 $selected = getDolGlobalString($constname);
551 if (isModEnabled('accounting')) {
552 print '<input type="text" name="' . $constname . '" list="pcg_type_datalist" value="' . $selected . '">';
553 // autosuggest from existing account types if found
554 print '<datalist id="pcg_type_datalist">';
555 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancysystem.class.php';
556 $accountsystem = new AccountancySystem($db);
557 $accountsystem->fetch(getDolGlobalInt('CHARTOFACCOUNTS'));
558 $sql = 'SELECT DISTINCT pcg_type FROM ' . MAIN_DB_PREFIX . 'accounting_account';
559 $sql .= " WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) . "'";
560 $sql .= ' AND entity in ('.getEntity('accounting_account', 0).')'; // Always limit to current entity. No sharing in accountancy.
561 $sql .= ' LIMIT 50000'; // just as a sanity check
562 $resql = $db->query($sql);
563 if ($resql) {
564 while ($obj = $db->fetch_object($resql)) {
565 print '<option value="' . dol_escape_htmltag($obj->pcg_type) . '">';
566 }
567 }
568 print '</datalist>';
569 } else {
570 print '<input name="' . $constname . '" class="maxwidth200" value="' . dol_escape_htmltag($selected) . '">';
571 }
572 } else {
573 print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($constname).'">';
574 }
575 print '</td></tr>';
576 }
577 }
578 print '</table>';
579
580 print '<br><div class="center">';
581 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
582 print '</div>';
583
584 print '</form>';
585 print '<br>';
586} else {
587 if (!empty($arrayofparameters)) {
588 print '<table class="noborder centpercent">';
589 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
590
591 foreach ($arrayofparameters as $constname => $val) {
592 if ($val['enabled'] == 1) {
593 $setupnotempty++;
594 print '<tr class="oddeven"><td>';
595 $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
596 print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
597 print '</td><td>';
598
599 if ($val['type'] == 'textarea') {
600 print dol_nl2br(getDolGlobalString($constname));
601 } elseif ($val['type'] == 'html') {
602 print getDolGlobalString($constname);
603 } elseif ($val['type'] == 'yesno') {
604 print ajax_constantonoff($constname);
605 } elseif (preg_match('/emailtemplate:/', $val['type'])) {
606 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
607 $formmail = new FormMail($db);
608
609 $tmp = explode(':', $val['type']);
610
611 $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, getDolGlobalString($constname));
612 if ($template < 0) {
613 setEventMessages(null, $formmail->errors, 'errors');
614 }
615 print $langs->trans($template->label);
616 } elseif (preg_match('/category:/', $val['type'])) {
617 $c = new Categorie($db);
618 $result = $c->fetch(getDolGlobalInt($constname));
619 if ($result < 0) {
620 setEventMessages(null, $c->errors, 'errors');
621 } elseif ($result > 0) {
622 $ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
623 $toprint = array();
624 foreach ($ways as $way) {
625 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
626 }
627 print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
628 }
629 } elseif (preg_match('/thirdparty_type/', $val['type'])) {
630 if (getDolGlobalInt($constname) == 2) {
631 print $langs->trans("Prospect");
632 } elseif (getDolGlobalInt($constname) == 3) {
633 print $langs->trans("ProspectCustomer");
634 } elseif (getDolGlobalInt($constname) == 1) {
635 print $langs->trans("Customer");
636 } elseif (getDolGlobalInt($constname) == 0) {
637 print $langs->trans("NorProspectNorCustomer");
638 }
639 } elseif ($val['type'] == 'product') {
640 $product = new Product($db);
641 $resprod = $product->fetch(getDolGlobalInt($constname));
642 if ($resprod > 0) {
643 print $product->ref;
644 } elseif ($resprod < 0) {
645 setEventMessages(null, $object->errors, "errors");
646 }
647 } elseif ($val['type'] == 'accountancy_code') {
648 if (isModEnabled('accounting')) {
649 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
650 $accountingaccount = new AccountingAccount($db);
651 $accountingaccount->fetch(0, getDolGlobalString($constname), 1);
652
653 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
654 } else {
655 print getDolGlobalString($constname);
656 }
657 } else {
658 print getDolGlobalString($constname);
659 }
660 print '</td></tr>';
661 }
662 }
663
664 print '</table>';
665
666 print '<div class="tabsAction">';
667 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
668 print '</div>';
669 } else {
670 print '<br>'.$langs->trans("NothingToSetup");
671 }
672}
673
674if (empty($setupnotempty)) {
675 print '<br>'.$langs->trans("NothingToSetup");
676}
677
678// Page end
679print dol_get_fiche_end();
680
681llxFooter();
682$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152
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.