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