dolibarr 22.0.5
setup.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 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 $defaultifnotset = 'mod_asset_standard';
274 $activenumberingmodel = getDolGlobalString($constforvar, $defaultifnotset);
275 if ($activenumberingmodel == $file) {
276 print img_picto($langs->trans("Activated"), 'switch_on');
277 } else {
278 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
279 print img_picto($langs->trans("Disabled"), 'switch_off');
280 print '</a>';
281 }
282 print '</td>';
283
284 $className = $myTmpObjectArray['class'];
285 $mytmpinstance = new $className($db);
286 $mytmpinstance->initAsSpecimen();
287
288 // Info
289 $htmltooltip = '';
290 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
291
292 $nextval = $module->getNextValue($mytmpinstance);
293 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
294 $htmltooltip .= ''.$langs->trans("NextValue").': ';
295 if ($nextval) {
296 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
297 $nextval = $langs->trans($nextval);
298 }
299 $htmltooltip .= $nextval.'<br>';
300 } else {
301 $htmltooltip .= $langs->trans($module->error).'<br>';
302 }
303 }
304
305 print '<td class="center">';
306 print $form->textwithpicto('', $htmltooltip, 1, 'info');
307 print '</td>';
308
309 print "</tr>\n";
310 }
311 }
312 }
313 closedir($handle);
314 }
315 }
316 }
317 print "</table><br>\n";
318 }
319
320 if ($myTmpObjectArray['includedocgeneration']) {
321 /*
322 * Document templates generators
323 */
324 $setupnotempty++;
325 $type = strtolower($myTmpObjectKey);
326
327 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
328
329 // Load array def with activated templates
330 $def = array();
331 $sql = "SELECT nom";
332 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
333 $sql .= " WHERE type = '".$db->escape($type)."'";
334 $sql .= " AND entity = ".$conf->entity;
335 $resql = $db->query($sql);
336 if ($resql) {
337 $i = 0;
338 $num_rows = $db->num_rows($resql);
339 while ($i < $num_rows) {
340 $array = $db->fetch_array($resql);
341 if (is_array($array)) {
342 array_push($def, $array[0]);
343 }
344 $i++;
345 }
346 } else {
347 dol_print_error($db);
348 }
349
350 print "<table class=\"noborder\" width=\"100%\">\n";
351 print "<tr class=\"liste_titre\">\n";
352 print '<td>'.$langs->trans("Name").'</td>';
353 print '<td>'.$langs->trans("Description").'</td>';
354 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
355 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
356 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
357 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
358 print "</tr>\n";
359
360 clearstatcache();
361
362 foreach ($dirmodels as $reldir) {
363 foreach (array('', '/doc') as $valdir) {
364 $realpath = $reldir."core/modules/".$moduledir.$valdir;
365 $dir = dol_buildpath($realpath);
366
367 if (is_dir($dir)) {
368 $handle = opendir($dir);
369 if (is_resource($handle)) {
370 $filelist = array();
371 while (($file = readdir($handle)) !== false) {
372 $filelist[] = $file;
373 }
374 closedir($handle);
375 arsort($filelist);
376
377 foreach ($filelist as $file) {
378 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
379 if (file_exists($dir.'/'.$file)) {
380 $name = substr($file, 4, dol_strlen($file) - 16);
381 $classname = substr($file, 0, dol_strlen($file) - 12);
382
383 require_once $dir.'/'.$file;
384 $module = new $classname($db);
385 '@phan-var-force ModelePDFAsset $module';
386
387 $modulequalified = 1;
388 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
389 $modulequalified = 0;
390 }
391 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
392 $modulequalified = 0;
393 }
394
395 if ($modulequalified) {
396 print '<tr class="oddeven"><td width="100">';
397 print(empty($module->name) ? $name : $module->name);
398 print "</td><td>\n";
399 if (method_exists($module, 'info')) {
400 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
401 } else {
402 print $module->description;
403 }
404 print '</td>';
405
406 // Active
407 if (in_array($name, $def)) {
408 print '<td class="center">'."\n";
409 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
410 print img_picto($langs->trans("Enabled"), 'switch_on');
411 print '</a>';
412 print '</td>';
413 } else {
414 print '<td class="center">'."\n";
415 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>';
416 print "</td>";
417 }
418
419 // Default
420 print '<td class="center">';
421 $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
422 if (getDolGlobalString($constforvar) == $name) {
423 //print img_picto($langs->trans("Default"), 'on');
424 // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
425 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>';
426 } else {
427 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>';
428 }
429 print '</td>';
430
431 // Info
432 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
433 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
434 if ($module->type == 'pdf') {
435 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
436 }
437 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
438
439 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
440 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
441 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
442
443 print '<td class="center">';
444 print $form->textwithpicto('', $htmltooltip, 1, 'info');
445 print '</td>';
446
447 // Preview
448 print '<td class="center">';
449 if ($module->type == 'pdf') {
450 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
451 } else {
452 print img_object($langs->transnoentitiesnoconv("PreviewNotAvailable"), 'generic');
453 }
454 print '</td>';
455
456 print "</tr>\n";
457 }
458 }
459 }
460 }
461 }
462 }
463 }
464 }
465
466 print '</table>';
467 }
468}
469
470if ($action == 'edit') {
471 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
472 print '<input type="hidden" name="token" value="'.newToken().'">';
473 print '<input type="hidden" name="action" value="update">';
474
475 print '<table class="noborder centpercent">';
476 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
477
478 foreach ($arrayofparameters as $constname => $val) {
479 if ($val['enabled'] == 1) {
480 $setupnotempty++;
481 print '<tr class="oddeven"><td>';
482 $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
483 print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
484 print '</td><td>';
485
486 if ($val['type'] == 'textarea') {
487 print '<textarea class="flat" name="'.$constname.'" id="'.$constname.'" cols="50" rows="5" wrap="soft">' . "\n";
488 print getDolGlobalString($constname);
489 print "</textarea>\n";
490 } elseif ($val['type'] == 'html') {
491 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
492 $doleditor = new DolEditor($constname, getDolGlobalString($constname), '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
493 $doleditor->Create();
494 } elseif ($val['type'] == 'yesno') {
495 print $form->selectyesno($constname, getDolGlobalString($constname), 1);
496 } elseif (preg_match('/emailtemplate:/', $val['type'])) {
497 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
498 $formmail = new FormMail($db);
499
500 $tmp = explode(':', $val['type']);
501 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
502 //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
503 $arrayofmessagename = array();
504 if (is_array($formmail->lines_model)) {
505 foreach ($formmail->lines_model as $modelmail) {
506 //var_dump($modelmail);
507 $moreonlabel = '';
508 if (!empty($arrayofmessagename[$modelmail->label])) {
509 $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
510 }
511 // The 'label' is the key that is unique if we exclude the language
512 $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\‍(|\‍)/', '', $modelmail->label)) . $moreonlabel;
513 }
514 }
515 print $form->selectarray($constname, $arrayofmessagename, getDolGlobalString($constname), 'None', 0, 0, '', 0, 0, 0, '', '', 1);
516 } elseif (preg_match('/category:/', $val['type'])) {
517 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
518 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
519 $formother = new FormOther($db);
520
521 $tmp = explode(':', $val['type']);
522 print img_picto('', 'category', 'class="pictofixedwidth"');
523 print $formother->select_categories($tmp[1], getDolGlobalInt($constname), $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
524 } elseif (preg_match('/thirdparty_type/', $val['type'])) {
525 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
526 $formcompany = new FormCompany($db);
527 print $formcompany->selectProspectCustomerType(getDolGlobalString($constname), $constname);
528 } elseif ($val['type'] == 'securekey') {
529 print '<input required="required" type="text" class="flat" id="'.$constname.'" name="'.$constname.'" value="'.(GETPOST($constname, 'alpha') ? GETPOST($constname, 'alpha') : getDolGlobalString($constname)).'" size="40">';
530 if (!empty($conf->use_javascript_ajax)) {
531 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token'.$constname.'" class="linkobject"');
532 }
533
534 // Add button to autosuggest a key
535 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
536 print dolJSToSetRandomPassword($constname, 'generate_token'.$constname);
537 } elseif ($val['type'] == 'product') {
538 if (isModEnabled("product") || isModEnabled("service")) {
539 $selected = getDolGlobalInt($constname);
540 $form->select_produits($selected, $constname, '', 0);
541 }
542 } elseif ($val['type'] == 'accountancy_code') {
543 $selected = getDolGlobalString($constname);
544 if (isModEnabled('accounting')) {
545 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
546 $formaccounting = new FormAccounting($db);
547 print $formaccounting->select_account($selected, $constname, 1, array(), 1, 1, 'minwidth150 maxwidth300', '1');
548 } else {
549 print '<input name="' . $constname . '" class="maxwidth200" value="' . dol_escape_htmltag($selected) . '">';
550 }
551 } elseif ($val['type'] == 'accountancy_category') {
552 $selected = getDolGlobalString($constname);
553 if (isModEnabled('accounting')) {
554 print '<input type="text" name="' . $constname . '" list="pcg_type_datalist" value="' . $selected . '">';
555 // autosuggest from existing account types if found
556 print '<datalist id="pcg_type_datalist">';
557 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancysystem.class.php';
558 $accountsystem = new AccountancySystem($db);
559 $accountsystem->fetch(getDolGlobalInt('CHARTOFACCOUNTS'));
560 $sql = 'SELECT DISTINCT pcg_type FROM ' . MAIN_DB_PREFIX . 'accounting_account';
561 $sql .= " WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) . "'";
562 $sql .= ' AND entity in ('.getEntity('accounting_account', 0).')'; // Always limit to current entity. No sharing in accountancy.
563 $sql .= ' LIMIT 50000'; // just as a sanity check
564 $resql = $db->query($sql);
565 if ($resql) {
566 while ($obj = $db->fetch_object($resql)) {
567 print '<option value="' . dol_escape_htmltag($obj->pcg_type) . '">';
568 }
569 }
570 print '</datalist>';
571 } else {
572 print '<input name="' . $constname . '" class="maxwidth200" value="' . dol_escape_htmltag($selected) . '">';
573 }
574 } else {
575 print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($constname).'">';
576 }
577 print '</td></tr>';
578 }
579 }
580 print '</table>';
581
582 print '<br><div class="center">';
583 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
584 print '</div>';
585
586 print '</form>';
587 print '<br>';
588} else {
589 if (!empty($arrayofparameters)) {
590 print '<table class="noborder centpercent">';
591 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td></td></tr>';
592
593 foreach ($arrayofparameters as $constname => $val) {
594 if ($val['enabled'] == 1) {
595 $setupnotempty++;
596 print '<tr class="oddeven"><td>';
597 $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
598 print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
599 print '</td><td>';
600
601 if ($val['type'] == 'textarea') {
602 print dol_nl2br(getDolGlobalString($constname));
603 } elseif ($val['type'] == 'html') {
604 print getDolGlobalString($constname);
605 } elseif ($val['type'] == 'yesno') {
606 print ajax_constantonoff($constname);
607 } elseif (preg_match('/emailtemplate:/', $val['type'])) {
608 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
609 $formmail = new FormMail($db);
610
611 $tmp = explode(':', $val['type']);
612
613 $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, getDolGlobalInt($constname));
614 if ($template < 0) {
615 setEventMessages(null, $formmail->errors, 'errors');
616 }
617 print $langs->trans($template->label);
618 } elseif (preg_match('/category:/', $val['type'])) {
619 $c = new Categorie($db);
620 $result = $c->fetch(getDolGlobalInt($constname));
621 if ($result < 0) {
622 setEventMessages(null, $c->errors, 'errors');
623 } elseif ($result > 0) {
624 $ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
625 $toprint = array();
626 foreach ($ways as $way) {
627 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
628 }
629 print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
630 }
631 } elseif (preg_match('/thirdparty_type/', $val['type'])) {
632 if (getDolGlobalInt($constname) == 2) {
633 print $langs->trans("Prospect");
634 } elseif (getDolGlobalInt($constname) == 3) {
635 print $langs->trans("ProspectCustomer");
636 } elseif (getDolGlobalInt($constname) == 1) {
637 print $langs->trans("Customer");
638 } elseif (getDolGlobalInt($constname) == 0) {
639 print $langs->trans("NorProspectNorCustomer");
640 }
641 } elseif ($val['type'] == 'product') {
642 $product = new Product($db);
643 $resprod = $product->fetch(getDolGlobalInt($constname));
644 if ($resprod > 0) {
645 print $product->ref;
646 } elseif ($resprod < 0) {
647 setEventMessages(null, $object->errors, "errors");
648 }
649 } elseif ($val['type'] == 'accountancy_code') {
650 if (isModEnabled('accounting')) {
651 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
652 $accountingaccount = new AccountingAccount($db);
653 $accountingaccount->fetch(0, getDolGlobalString($constname), 1);
654
655 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
656 } else {
657 print getDolGlobalString($constname);
658 }
659 } else {
660 print getDolGlobalString($constname);
661 }
662 print '</td></tr>';
663 }
664 }
665
666 print '</table>';
667
668 print '<div class="tabsAction">';
669 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
670 print '</div>';
671 } else {
672 print '<br>'.$langs->trans("NothingToSetup");
673 }
674}
675
676if (empty($setupnotempty)) {
677 print '<br>'.$langs->trans("NothingToSetup");
678}
679
680// Page end
681print dol_get_fiche_end();
682
683llxFooter();
684$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
assetAdminPrepareHead()
Prepare admin pages header.
Definition asset.lib.php:32
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
$c
Definition line.php:331
Class to manage accountancy systems.
Class to manage accounting accounts.
Class to manage categories.
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components for accounting management.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
Class permettant la generation de composants html autre Only common components are here.
Class to manage products or services.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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:161
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.