dolibarr 19.0.3
setup.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php';
28require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
29
30global $langs, $user;
31
32// Load translation files required by the page
33$langs->loadLangs(array("admin", "assets"));
34
35// Access control
36if (!$user->admin) {
38}
39
40// Parameters
41$action = GETPOST('action', 'aZ09');
42$backtopage = GETPOST('backtopage', 'alpha');
43
44$value = GETPOST('value', 'alpha');
45$label = GETPOST('label', 'alpha');
46$scandir = GETPOST('scan_dir', 'alpha');
47$type = 'asset';
48
49$arrayofparameters = array(
50 'ASSET_ACCOUNTANCY_CATEGORY'=>array('type'=>'accountancy_category', 'enabled'=>1),
51 'ASSET_DEPRECIATION_DURATION_PER_YEAR'=>array('type'=>'string', 'css'=>'minwidth200', 'enabled'=>1),
52 //'ASSET_MYPARAM2'=>array('type'=>'textarea','enabled'=>1),
53 //'ASSET_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
54 //'ASSET_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
55 //'ASSET_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
56 //'ASSET_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
57 //'ASSET_MYPARAM6'=>array('type'=>'securekey', 'enabled'=>1),
58 //'ASSET_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
59);
60
61$error = 0;
62$setupnotempty = 0;
63
64$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
65
66
67/*
68 * Actions
69 */
70
71include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
72
73if ($action == 'updateMask') {
74 $maskconst = GETPOST('maskconst', 'alpha');
75 $mask = GETPOST('mask', 'alpha');
76
77 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
78 $res = dolibarr_set_const($db, $maskconst, $mask, 'chaine', 0, '', $conf->entity);
79 if (!($res > 0)) {
80 $error++;
81 }
82 }
83
84 if (!$error) {
85 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
86 } else {
87 setEventMessages($langs->trans("Error"), null, 'errors');
88 }
89} elseif ($action == 'specimen') {
90 $modele = GETPOST('module', 'alpha');
91 $tmpobjectkey = GETPOST('object');
92
93 $tmpobject = new $tmpobjectkey($db);
94 $tmpobject->initAsSpecimen();
95
96 // Search template files
97 $file = '';
98 $classname = '';
99 $filefound = 0;
100 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
101 foreach ($dirmodels as $reldir) {
102 $file = dol_buildpath($reldir."core/modules/asset/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
103 if (file_exists($file)) {
104 $filefound = 1;
105 $classname = "pdf_".$modele;
106 break;
107 }
108 }
109
110 if ($filefound) {
111 require_once $file;
112
113 $module = new $classname($db);
114
115 if ($module->write_file($tmpobject, $langs) > 0) {
116 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
117 return;
118 } else {
119 setEventMessages($module->error, null, 'errors');
120 dol_syslog($module->error, LOG_ERR);
121 }
122 } else {
123 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
124 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
125 }
126} elseif ($action == 'setmod') {
127 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
128 $tmpobjectkey = GETPOST('object');
129 if (!empty($tmpobjectkey)) {
130 $constforval = 'ASSET_'.strtoupper($tmpobjectkey)."_ADDON";
131 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
132 }
133} elseif ($action == 'set') {
134 // Activate a model
135 $ret = addDocumentModel($value, $type, $label, $scandir);
136} elseif ($action == 'del') {
137 $ret = delDocumentModel($value, $type);
138 if ($ret > 0) {
139 $tmpobjectkey = GETPOST('object');
140 if (!empty($tmpobjectkey)) {
141 $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
142 if (getDolGlobalString($constforval) == "$value") {
143 dolibarr_del_const($db, $constforval, $conf->entity);
144 }
145 }
146 }
147} elseif ($action == 'setdoc') {
148 // Set or unset default model
149 $tmpobjectkey = GETPOST('object');
150 if (!empty($tmpobjectkey)) {
151 $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
152 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
153 // The constant that was read before the new set
154 // We therefore requires a variable to have a coherent view
155 $conf->global->$constforval = $value;
156 }
157
158 // We disable/enable the document template (into llx_document_model table)
159 $ret = delDocumentModel($value, $type);
160 if ($ret > 0) {
161 $ret = addDocumentModel($value, $type, $label, $scandir);
162 }
163 }
164} elseif ($action == 'unsetdoc') {
165 $tmpobjectkey = GETPOST('object');
166 if (!empty($tmpobjectkey)) {
167 $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
168 dolibarr_del_const($db, $constforval, $conf->entity);
169 }
170}
171
172
173
174/*
175 * View
176 */
177
178$form = new Form($db);
179
180$help_url = '';
181$page_name = "AssetSetup";
182
183llxHeader('', $langs->trans($page_name), $help_url);
184
185// Subheader
186$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
187
188print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
189
190// Configuration header
191$head = assetAdminPrepareHead();
192print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "asset");
193
194// Setup page goes here
195echo '<span class="opacitymedium">'.$langs->trans("AssetSetupPage").'</span>';
196
197
198$moduledir = 'asset';
199$myTmpObjects = array();
200$myTmpObjects['Asset'] = array('includerefgeneration'=>1, 'includedocgeneration'=>0);
201
202
203foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
204 if ($myTmpObjectKey == 'MyObject') {
205 continue;
206 }
207 if ($myTmpObjectArray['includerefgeneration']) {
208 /*
209 * Assets Numbering model
210 */
211 $setupnotempty++;
212
213 print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
214
215 print '<table class="noborder centpercent">';
216 print '<tr class="liste_titre">';
217 print '<td>'.$langs->trans("Name").'</td>';
218 print '<td>'.$langs->trans("Description").'</td>';
219 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
220 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
221 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
222 print '</tr>'."\n";
223
224 clearstatcache();
225
226 foreach ($dirmodels as $reldir) {
227 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
228
229 if (is_dir($dir)) {
230 $handle = opendir($dir);
231 if (is_resource($handle)) {
232 while (($file = readdir($handle)) !== false) {
233 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
234 $file = substr($file, 0, dol_strlen($file) - 4);
235
236 require_once $dir.'/'.$file.'.php';
237
238 $module = new $file($db);
239
240 // Show modules according to features level
241 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
242 continue;
243 }
244 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
245 continue;
246 }
247
248 if ($module->isEnabled()) {
249 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
250
251 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
252 print $module->info($langs);
253 print '</td>';
254
255 // Show example of numbering model
256 print '<td class="nowrap">';
257 $tmp = $module->getExample();
258 if (preg_match('/^Error/', $tmp)) {
259 $langs->load("errors");
260 print '<div class="error">'.$langs->trans($tmp).'</div>';
261 } elseif ($tmp == 'NotConfigured') {
262 print $langs->trans($tmp);
263 } else {
264 print $tmp;
265 }
266 print '</td>'."\n";
267
268 print '<td class="center">';
269 $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
270 if (getDolGlobalString($constforvar) == $file) {
271 print img_picto($langs->trans("Activated"), 'switch_on');
272 } else {
273 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
274 print img_picto($langs->trans("Disabled"), 'switch_off');
275 print '</a>';
276 }
277 print '</td>';
278
279 $mytmpinstance = new $myTmpObjectKey($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 array_push($def, $array[0]);
336 $i++;
337 }
338 } else {
339 dol_print_error($db);
340 }
341
342 print "<table class=\"noborder\" width=\"100%\">\n";
343 print "<tr class=\"liste_titre\">\n";
344 print '<td>'.$langs->trans("Name").'</td>';
345 print '<td>'.$langs->trans("Description").'</td>';
346 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
347 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
348 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
349 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
350 print "</tr>\n";
351
352 clearstatcache();
353
354 foreach ($dirmodels as $reldir) {
355 foreach (array('', '/doc') as $valdir) {
356 $realpath = $reldir."core/modules/".$moduledir.$valdir;
357 $dir = dol_buildpath($realpath);
358
359 if (is_dir($dir)) {
360 $handle = opendir($dir);
361 if (is_resource($handle)) {
362 while (($file = readdir($handle)) !== false) {
363 $filelist[] = $file;
364 }
365 closedir($handle);
366 arsort($filelist);
367
368 foreach ($filelist as $file) {
369 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
370 if (file_exists($dir.'/'.$file)) {
371 $name = substr($file, 4, dol_strlen($file) - 16);
372 $classname = substr($file, 0, dol_strlen($file) - 12);
373
374 require_once $dir.'/'.$file;
375 $module = new $classname($db);
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);
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 formated 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('', 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();
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.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Classe permettant la generation de composants html autre Only common components are here.
Class to manage products or services.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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.
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:124
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Ouput javacript 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.