dolibarr 25.0.0-alpha
setup.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php';
37require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
38
39global $langs, $user;
40
41// Load translation files required by the page
42$langs->loadLangs(array("admin", "assets"));
43
44// Access control
45if (!$user->admin) {
47}
48
49// Parameters
50$action = GETPOST('action', 'aZ09');
51$backtopage = GETPOST('backtopage', 'alpha');
52
53$value = GETPOST('value', 'alpha');
54$label = GETPOST('label', 'alpha');
55$scandir = GETPOST('scan_dir', 'alpha');
56$type = 'asset';
57
58// Day count conventions available to compute the prorata temporis of a depreciation.
59// Note: the deprecated setup ASSET_DEPRECIATION_DURATION_PER_YEAR is not editable anymore. It let a
60// count of real calendar days be divided by 360, which is not a convention but a calculation error
61// (it overestimates every partial period by about 1.39%). It is still read to deduce the convention
62// of an installation that has never saved this page (see getAssetDepreciationDayCountConvention()).
63$arrayofdaycountconventions = array();
64foreach (getAssetDepreciationDayCountConventions() as $conventioncode => $conventionlabelkey) {
65 $arrayofdaycountconventions[$conventioncode] = $langs->trans($conventionlabelkey);
66}
67
71$arrayofparameters = array(
72 'ASSET_ACCOUNTANCY_CATEGORY' => array('type' => 'accountancy_category', 'enabled' => 1),
73 'ASSET_DEPRECIATION_DAY_COUNT_CONVENTION' => array('type' => 'select', 'arrayofkeyval' => $arrayofdaycountconventions, 'default' => getAssetDepreciationDayCountConvention(), 'css' => 'minwidth300', 'enabled' => 1),
74 //'ASSET_MYPARAM2'=>array('type'=>'textarea','enabled'=>1),
75 //'ASSET_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
76 //'ASSET_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
77 //'ASSET_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
78 //'ASSET_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
79 //'ASSET_MYPARAM6'=>array('type'=>'securekey', 'enabled'=>1),
80 //'ASSET_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
81);
82
83$error = 0;
84
85$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
86
87$moduledir = 'asset';
88$myTmpObjects = [
89 'asset' => array('label' => 'Asset', 'includerefgeneration' => 1, 'includedocgeneration' => 1, 'class' => 'Asset')
90];
91
92$tmpobjectkey = GETPOST('object', 'aZ09');
93if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
94 accessforbidden('Bad value for object. Hack attempt ?');
95}
96
97
98/*
99 * Actions
100 */
101
102include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
103
104if ($action == 'updateMask') {
105 $maskconst = GETPOST('maskconst', 'alpha');
106 $mask = GETPOST('mask', 'alpha');
107
108 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
109 $res = dolibarr_set_const($db, $maskconst, $mask, 'chaine', 0, '', $conf->entity);
110 if (!($res > 0)) {
111 $error++;
112 }
113 }
114
115 if (!$error) {
116 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
117 } else {
118 setEventMessages($langs->trans("Error"), null, 'errors');
119 }
120} elseif ($action == 'specimen' && $tmpobjectkey) {
121 $modele = GETPOST('module', 'alpha');
122
123 $className = $myTmpObjects[$tmpobjectkey]['class'];
124 $tmpobject = new $className($db);
125 $tmpobject->initAsSpecimen();
126
127 // Search template files
128 $file = '';
129 $classname = '';
130 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
131 foreach ($dirmodels as $reldir) {
132 $file = dol_buildpath($reldir."core/modules/asset/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
133 if (file_exists($file)) {
134 $classname = "pdf_".$modele;
135 break;
136 }
137 }
138
139 if ($classname !== '') {
140 require_once $file;
141
142 $module = new $classname($db);
143 '@phan-var-force ModelePDFAsset $module';
144
145 if ($module->write_file($tmpobject, $langs) > 0) {
146 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
147 return;
148 } else {
149 setEventMessages($module->error, null, 'errors');
150 dol_syslog($module->error, LOG_ERR);
151 }
152 } else {
153 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
154 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
155 }
156} elseif ($action == 'setmod') {
157 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
158 if (!empty($tmpobjectkey)) {
159 $constforval = 'ASSET_'.strtoupper($tmpobjectkey)."_ADDON";
160 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
161 }
162} elseif ($action == 'set') {
163 // Activate a model
164 $ret = addDocumentModel($value, $type, $label, $scandir);
165} elseif ($action == 'del') {
166 $ret = delDocumentModel($value, $type);
167 if ($ret > 0) {
168 if (!empty($tmpobjectkey)) {
169 $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
170 if (getDolGlobalString($constforval) == "$value") {
171 dolibarr_del_const($db, $constforval, $conf->entity);
172 }
173 }
174 }
175} elseif ($action == 'setdoc') {
176 // Set or unset default model
177 if (!empty($tmpobjectkey)) {
178 $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
179 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
180 // The constant that was read before the new set
181 // We therefore requires a variable to have a coherent view
182 $conf->global->$constforval = $value;
183 }
184
185 // We disable/enable the document template (into llx_document_model table)
186 $ret = delDocumentModel($value, $type);
187 if ($ret > 0) {
188 $ret = addDocumentModel($value, $type, $label, $scandir);
189 }
190 }
191} elseif ($action == 'unsetdoc') {
192 if (!empty($tmpobjectkey)) {
193 $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
194 dolibarr_del_const($db, $constforval, $conf->entity);
195 }
196}
197
198
199
200/*
201 * View
202 */
203
204$form = new Form($db);
205
206$help_url = '';
207$page_name = "AssetSetup";
208
209llxHeader('', $langs->trans($page_name), $help_url);
210
211// Subheader
212$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
213
214print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
215
216// Configuration header
217$head = assetAdminPrepareHead();
218print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "asset");
219
220foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
221 if ($myTmpObjectArray['includerefgeneration']) {
222 /*
223 * Assets Numbering model
224 */
225 print load_fiche_titre($langs->trans("AssetNumberingModules", $myTmpObjectKey), '', '');
226
227 print '<table class="noborder centpercent">';
228 print '<tr class="liste_titre">';
229 print '<td>'.$langs->trans("Name").'</td>';
230 print '<td>'.$langs->trans("Description").'</td>';
231 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
232 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
233 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
234 print '</tr>'."\n";
235
236 clearstatcache();
237
238 foreach ($dirmodels as $reldir) {
239 $dir = dol_buildpath($reldir."core/modules/".$moduledir);
240
241 if (is_dir($dir)) {
242 $handle = opendir($dir);
243 if (is_resource($handle)) {
244 while (($file = readdir($handle)) !== false) {
245 if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && dol_substr($file, dol_strlen($file) - 3, 3) == 'php') {
246 $file = dol_substr($file, 0, dol_strlen($file) - 4);
247
248 require_once $dir.'/'.$file.'.php';
249
250 $module = new $file($db);
251 '@phan-var-force ModeleNumRefAsset $module';
252
253 // Show modules according to feature level
254 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
255 continue;
256 }
257 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
258 continue;
259 }
260
261 if ($module->isEnabled()) {
262 dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
263
264 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
265 print $module->info($langs);
266 print '</td>';
267
268 // Show example of the numbering model
269 print '<td class="nowrap">';
270 $tmp = $module->getExample();
271 if (preg_match('/^Error/', $tmp)) {
272 $langs->load("errors");
273 print '<div class="error">'.$langs->trans($tmp).'</div>';
274 } elseif ($tmp == 'NotConfigured') {
275 print $langs->trans($tmp);
276 } else {
277 print $tmp;
278 }
279 print '</td>'."\n";
280
281 print '<td class="center">';
282 $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
283 $defaultifnotset = 'mod_asset_standard';
284 $activenumberingmodel = getDolGlobalString($constforvar, $defaultifnotset);
285 if ($activenumberingmodel == $file) {
286 print img_picto($langs->trans("Activated"), 'switch_on');
287 } else {
288 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
289 print img_picto($langs->trans("Disabled"), 'switch_off');
290 print '</a>';
291 }
292 print '</td>';
293
294 $className = $myTmpObjectArray['class'];
295 $mytmpinstance = new $className($db);
296 $mytmpinstance->initAsSpecimen();
297
298 // Info
299 $htmltooltip = '';
300 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
301
302 $nextval = $module->getNextValue($mytmpinstance);
303 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
304 $htmltooltip .= ''.$langs->trans("NextValue").': ';
305 if ($nextval) {
306 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
307 $nextval = $langs->trans($nextval);
308 }
309 $htmltooltip .= $nextval.'<br>';
310 } else {
311 $htmltooltip .= $langs->trans($module->error).'<br>';
312 }
313 }
314
315 print '<td class="center">';
316 print $form->textwithpicto('', $htmltooltip, 1, 'info');
317 print '</td>';
318
319 print "</tr>\n";
320 }
321 }
322 }
323 closedir($handle);
324 }
325 }
326 }
327 print "</table><br>\n";
328 }
329
330 if ($myTmpObjectArray['includedocgeneration']) {
331 /*
332 * Document templates generators
333 */
334 $type = strtolower($myTmpObjectKey);
335
336 print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
337
338 // Load array def with activated templates
339 // TODO Replace with $def = getListOfModels($db, $type);
340 $def = array();
341 $sql = "SELECT nom";
342 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
343 $sql .= " WHERE type = '".$db->escape($type)."'";
344 $sql .= " AND entity = ".((int) $conf->entity);
345 $resql = $db->query($sql);
346 if ($resql) {
347 $i = 0;
348 $num_rows = $db->num_rows($resql);
349 while ($i < $num_rows) {
350 $array = $db->fetch_array($resql);
351 if (is_array($array)) {
352 array_push($def, $array[0]);
353 }
354 $i++;
355 }
356 } else {
357 dol_print_error($db);
358 }
359
360 print "<table class=\"noborder\" width=\"100%\">\n";
361 print "<tr class=\"liste_titre\">\n";
362 print '<td>'.$langs->trans("Name").'</td>';
363 print '<td>'.$langs->trans("Description").'</td>';
364 print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
365 print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
366 print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
367 print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
368 print "</tr>\n";
369
370 clearstatcache();
371
372 foreach ($dirmodels as $reldir) {
373 foreach (array('', '/doc') as $valdir) {
374 $realpath = $reldir."core/modules/".$moduledir.$valdir;
375 $dir = dol_buildpath($realpath);
376
377 if (is_dir($dir)) {
378 $handle = opendir($dir);
379 if (is_resource($handle)) {
380 $filelist = array();
381 while (($file = readdir($handle)) !== false) {
382 $filelist[] = $file;
383 }
384 closedir($handle);
385 arsort($filelist);
386
387 foreach ($filelist as $file) {
388 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
389 if (file_exists($dir.'/'.$file)) {
390 $name = dol_substr($file, 4, dol_strlen($file) - 16);
391 $classname = dol_substr($file, 0, dol_strlen($file) - 12);
392
393 require_once $dir.'/'.$file;
394 $module = new $classname($db);
395 '@phan-var-force ModelePDFAsset $module';
396
397 $modulequalified = 1;
398 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
399 $modulequalified = 0;
400 }
401 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
402 $modulequalified = 0;
403 }
404
405 if ($modulequalified) {
406 print '<tr class="oddeven"><td width="100">';
407 print(empty($module->name) ? $name : $module->name);
408 print "</td><td>\n";
409 if (method_exists($module, 'info')) {
410 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
411 } else {
412 print $module->description;
413 }
414 print '</td>';
415
416 // Active
417 if (in_array($name, $def)) {
418 print '<td class="center">'."\n";
419 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
420 print img_picto($langs->trans("Enabled"), 'switch_on');
421 print '</a>';
422 print '</td>';
423 } else {
424 print '<td class="center">'."\n";
425 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>';
426 print "</td>";
427 }
428
429 // Default
430 print '<td class="center">';
431 $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
432 if (getDolGlobalString($constforvar) == $name) {
433 //print img_picto($langs->trans("Default"), 'on');
434 // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
435 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>';
436 } else {
437 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>';
438 }
439 print '</td>';
440
441 // Info
442 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
443 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
444 if ($module->type == 'pdf') {
445 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
446 }
447 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
448
449 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
450 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
451 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
452
453 print '<td class="center">';
454 print $form->textwithpicto('', $htmltooltip, 1, 'info');
455 print '</td>';
456
457 // Preview
458 print '<td class="center">';
459 if ($module->type == 'pdf') {
460 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
461 } else {
462 print img_object($langs->transnoentitiesnoconv("PreviewNotAvailable"), 'generic');
463 }
464 print '</td>';
465
466 print "</tr>\n";
467 }
468 }
469 }
470 }
471 }
472 }
473 }
474 }
475
476 print '</table>';
477 }
478}
479
480if ($action == 'edit') {
481 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
482 print '<input type="hidden" name="token" value="'.newToken().'">';
483 print '<input type="hidden" name="action" value="update">';
484
485 print '<table class="noborder centpercent">';
486 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
487
488 foreach ($arrayofparameters as $constname => $val) {
489 if ($val['enabled'] == 1) {
490 print '<tr class="oddeven"><td>';
491 $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
492 print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
493 print '</td><td>';
494
495 if ($val['type'] == 'select') {
496 $selected = getDolGlobalString($constname, isset($val['default']) ? $val['default'] : '');
497 if (!isset($val['arrayofkeyval'][$selected])) {
498 // A value stored outside the list (forged post, deprecated setup) must show the value
499 // really in use, not silently the first entry of the list
500 $selected = isset($val['default']) ? $val['default'] : '';
501 }
502 print $form->selectarray($constname, $val['arrayofkeyval'], $selected, 0, 0, 0, '', 0, 0, 0, '', (empty($val['css']) ? 'minwidth200' : $val['css']));
503 } elseif ($val['type'] == 'textarea') {
504 print '<textarea class="flat" name="'.$constname.'" id="'.$constname.'" cols="50" rows="5" wrap="soft">' . "\n";
505 print getDolGlobalString($constname);
506 print "</textarea>\n";
507 } elseif ($val['type'] == 'html') {
508 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
509 $doleditor = new DolEditor($constname, getDolGlobalString($constname), '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%');
510 $doleditor->Create();
511 } elseif ($val['type'] == 'yesno') {
512 print $form->selectyesno($constname, getDolGlobalString($constname), 1);
513 } elseif (preg_match('/emailtemplate:/', $val['type'])) {
514 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
515 $formmail = new FormMail($db);
516
517 $tmp = explode(':', $val['type']);
518 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
519 //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
520 $arrayofmessagename = array();
521 if (is_array($formmail->lines_model)) {
522 foreach ($formmail->lines_model as $modelmail) {
523 //var_dump($modelmail);
524 $moreonlabel = '';
525 if (!empty($arrayofmessagename[$modelmail->label])) {
526 $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
527 }
528 // The 'label' is the key that is unique if we exclude the language
529 $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\‍(|\‍)/', '', $modelmail->label)) . $moreonlabel;
530 }
531 }
532 print $form->selectarray($constname, $arrayofmessagename, getDolGlobalString($constname), 'None', 0, 0, '', 0, 0, 0, '', '', 1);
533 } elseif (preg_match('/category:/', $val['type'])) {
534 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
535 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
536 $formother = new FormOther($db);
537
538 $tmp = explode(':', $val['type']);
539 print img_picto('', 'category', 'class="pictofixedwidth"');
540 print $formother->select_categories($tmp[1], getDolGlobalInt($constname), $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
541 } elseif (preg_match('/thirdparty_type/', $val['type'])) {
542 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
543 $formcompany = new FormCompany($db);
544 print $formcompany->selectProspectCustomerType(getDolGlobalString($constname), $constname);
545 } elseif ($val['type'] == 'securekey') {
546 print '<input required="required" type="text" class="flat" id="'.$constname.'" name="'.$constname.'" value="'.(GETPOST($constname, 'alpha') ? GETPOST($constname, 'alpha') : getDolGlobalString($constname)).'" size="40">';
547 if (!empty($conf->use_javascript_ajax)) {
548 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token'.$constname.'" class="linkobject"');
549 }
550
551 // Add button to autosuggest a key
552 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
553 print dolJSToSetRandomPassword($constname, 'generate_token'.$constname);
554 } elseif ($val['type'] == 'product') {
555 if (isModEnabled("product") || isModEnabled("service")) {
556 $selected = getDolGlobalInt($constname);
557 $form->select_produits($selected, $constname, '', 0);
558 }
559 } elseif ($val['type'] == 'accountancy_code') {
560 $selected = getDolGlobalString($constname);
561 if (isModEnabled('accounting')) {
562 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
563 $formaccounting = new FormAccounting($db);
564 print $formaccounting->select_account($selected, $constname, 1, array(), 1, 1, 'minwidth150 maxwidth300', '1');
565 } else {
566 print '<input name="' . $constname . '" class="maxwidth200" value="' . dol_escape_htmltag($selected) . '">';
567 }
568 } elseif ($val['type'] == 'accountancy_category') {
569 $selected = getDolGlobalString($constname);
570 if (isModEnabled('accounting')) {
571 print '<input type="text" name="' . $constname . '" list="pcg_type_datalist" value="' . $selected . '">';
572 // autosuggest from existing account types if found
573 print '<datalist id="pcg_type_datalist">';
574 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancysystem.class.php';
575 $accountsystem = new AccountancySystem($db);
576 $accountsystem->fetch(getDolGlobalInt('CHARTOFACCOUNTS'));
577 $sql = 'SELECT DISTINCT pcg_type FROM ' . MAIN_DB_PREFIX . 'accounting_account';
578 $sql .= " WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) . "'";
579 $sql .= ' AND entity in ('.getEntity('accounting_account', 0).')'; // Always limit to current entity. No sharing in accountancy.
580 $sql .= ' LIMIT 50000'; // just as a sanity check
581 $resql = $db->query($sql);
582 if ($resql) {
583 while ($obj = $db->fetch_object($resql)) {
584 print '<option value="' . dol_escape_htmltag($obj->pcg_type) . '">';
585 }
586 }
587 print '</datalist>';
588 } else {
589 print '<input name="' . $constname . '" class="maxwidth200" value="' . dol_escape_htmltag($selected) . '">';
590 }
591 } else {
592 print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($constname).'">';
593 }
594 print '</td></tr>';
595 }
596 }
597 print '</table>';
598
599 print '<br><div class="center">';
600 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
601 print '</div>';
602
603 print '</form>';
604 print '<br>';
605} else {
606 if (!empty($arrayofparameters)) {
607 print '<table class="noborder centpercent">';
608 print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td></td></tr>';
609
610 foreach ($arrayofparameters as $constname => $val) {
611 if ($val['enabled'] == 1) {
612 print '<tr class="oddeven"><td>';
613 $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
614 print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
615 print '</td><td>';
616
617 if ($val['type'] == 'select') {
618 $selected = getDolGlobalString($constname, isset($val['default']) ? $val['default'] : '');
619 print isset($val['arrayofkeyval'][$selected]) ? $val['arrayofkeyval'][$selected] : dol_escape_htmltag($selected);
620 } elseif ($val['type'] == 'textarea') {
621 print dol_nl2br(getDolGlobalString($constname));
622 } elseif ($val['type'] == 'html') {
623 print getDolGlobalString($constname);
624 } elseif ($val['type'] == 'yesno') {
625 print ajax_constantonoff($constname);
626 } elseif (preg_match('/emailtemplate:/', $val['type'])) {
627 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
628 $formmail = new FormMail($db);
629
630 $tmp = explode(':', $val['type']);
631
632 $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, getDolGlobalInt($constname));
633 if ($template < 0) {
634 setEventMessages(null, $formmail->errors, 'errors');
635 }
636 print $langs->trans($template->label);
637 } elseif (preg_match('/category:/', $val['type'])) {
638 $c = new Categorie($db);
639 $result = $c->fetch(getDolGlobalInt($constname));
640 if ($result < 0) {
641 setEventMessages(null, $c->errors, 'errors');
642 } elseif ($result > 0) {
643 $ways = $c->print_all_ways('auto', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
644 $toprint = array();
645 foreach ($ways as $way) {
646 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
647 }
648 print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
649 }
650 } elseif (preg_match('/thirdparty_type/', $val['type'])) {
651 if (getDolGlobalInt($constname) == 2) {
652 print $langs->trans("Prospect");
653 } elseif (getDolGlobalInt($constname) == 3) {
654 print $langs->trans("ProspectCustomer");
655 } elseif (getDolGlobalInt($constname) == 1) {
656 print $langs->trans("Customer");
657 } elseif (getDolGlobalInt($constname) == 0) {
658 print $langs->trans("NorProspectNorCustomer");
659 }
660 } elseif ($val['type'] == 'product') {
661 $product = new Product($db);
662 $resprod = $product->fetch(getDolGlobalInt($constname));
663 if ($resprod > 0) {
664 print $product->ref;
665 } elseif ($resprod < 0) {
666 setEventMessages(null, $product->errors, "errors");
667 }
668 } elseif ($val['type'] == 'accountancy_code') {
669 if (isModEnabled('accounting')) {
670 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
671 $accountingaccount = new AccountingAccount($db);
672 $accountingaccount->fetch(0, getDolGlobalString($constname), 1);
673
674 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
675 } else {
676 print getDolGlobalString($constname);
677 }
678 } else {
679 print getDolGlobalString($constname);
680 }
681 print '</td></tr>';
682 }
683 }
684
685 print '</table>';
686
687 print '<div class="tabsAction">';
688 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
689 print '</div>';
690 } else {
691 print '<br>'.$langs->trans("NothingToSetup");
692 }
693}
694
695
696// Page end
697print dol_get_fiche_end();
698
699llxFooter();
700$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:32
getAssetDepreciationDayCountConventions()
Return the list of the day count conventions available to compute the prorata temporis of a depreciat...
getAssetDepreciationDayCountConvention()
Return the day count convention to use to compute the prorata temporis of a depreciation.
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:346
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 to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
Class to help generate other html components Only common components are here.
Class to manage products or services.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Output javascript to autoset a generated password using default module into a HTML element.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.