dolibarr  16.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 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 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php';
27 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
28 
29 global $langs, $user;
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("admin", "assets"));
33 
34 // Access control
35 if (!$user->admin) {
37 }
38 
39 // Parameters
40 $action = GETPOST('action', 'aZ09');
41 $backtopage = GETPOST('backtopage', 'alpha');
42 
43 $value = GETPOST('value', 'alpha');
44 $label = GETPOST('label', 'alpha');
45 $scandir = GETPOST('scan_dir', 'alpha');
46 $type = 'asset';
47 
48 $arrayofparameters = array(
49  'ASSET_ACCOUNTANCY_CATEGORY'=>array('type'=>'accountancy_category', 'enabled'=>1),
50  'ASSET_DEPRECIATION_DURATION_PER_YEAR'=>array('type'=>'string', 'css'=>'minwidth200', 'enabled'=>1),
51  //'ASSET_MYPARAM2'=>array('type'=>'textarea','enabled'=>1),
52  //'ASSET_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
53  //'ASSET_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
54  //'ASSET_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
55  //'ASSET_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
56  //'ASSET_MYPARAM6'=>array('type'=>'securekey', 'enabled'=>1),
57  //'ASSET_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
58 );
59 
60 $error = 0;
61 $setupnotempty = 0;
62 
63 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
64 
65 
66 /*
67  * Actions
68  */
69 
70 if ((float) DOL_VERSION >= 6) {
71  include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
72 }
73 
74 if ($action == 'updateMask') {
75  $maskconstorder = GETPOST('maskconstorder', 'alpha');
76  $maskorder = GETPOST('maskorder', 'alpha');
77 
78  if ($maskconstorder) {
79  $res = dolibarr_set_const($db, $maskconstorder, $maskorder, 'chaine', 0, '', $conf->entity);
80  if (!($res > 0)) {
81  $error++;
82  }
83  }
84 
85  if (!$error) {
86  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
87  } else {
88  setEventMessages($langs->trans("Error"), null, 'errors');
89  }
90 } elseif ($action == 'specimen') {
91  $modele = GETPOST('module', 'alpha');
92  $tmpobjectkey = GETPOST('object');
93 
94  $tmpobject = new $tmpobjectkey($db);
95  $tmpobject->initAsSpecimen();
96 
97  // Search template files
98  $file = ''; $classname = ''; $filefound = 0;
99  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
100  foreach ($dirmodels as $reldir) {
101  $file = dol_buildpath($reldir."core/modules/asset/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
102  if (file_exists($file)) {
103  $filefound = 1;
104  $classname = "pdf_".$modele;
105  break;
106  }
107  }
108 
109  if ($filefound) {
110  require_once $file;
111 
112  $module = new $classname($db);
113 
114  if ($module->write_file($tmpobject, $langs) > 0) {
115  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
116  return;
117  } else {
118  setEventMessages($module->error, null, 'errors');
119  dol_syslog($module->error, LOG_ERR);
120  }
121  } else {
122  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
123  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
124  }
125 } elseif ($action == 'setmod') {
126  // TODO Check if numbering module chosen can be activated by calling method canBeActivated
127  $tmpobjectkey = GETPOST('object');
128  if (!empty($tmpobjectkey)) {
129  $constforval = 'ASSET_'.strtoupper($tmpobjectkey)."_ADDON";
130  dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
131  }
132 } elseif ($action == 'set') {
133  // Activate a model
134  $ret = addDocumentModel($value, $type, $label, $scandir);
135 } elseif ($action == 'del') {
136  $ret = delDocumentModel($value, $type);
137  if ($ret > 0) {
138  $tmpobjectkey = GETPOST('object');
139  if (!empty($tmpobjectkey)) {
140  $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
141  if ($conf->global->$constforval == "$value") {
142  dolibarr_del_const($db, $constforval, $conf->entity);
143  }
144  }
145  }
146 } elseif ($action == 'setdoc') {
147  // Set or unset default model
148  $tmpobjectkey = GETPOST('object');
149  if (!empty($tmpobjectkey)) {
150  $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
151  if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
152  // The constant that was read before the new set
153  // We therefore requires a variable to have a coherent view
154  $conf->global->$constforval = $value;
155  }
156 
157  // We disable/enable the document template (into llx_document_model table)
158  $ret = delDocumentModel($value, $type);
159  if ($ret > 0) {
160  $ret = addDocumentModel($value, $type, $label, $scandir);
161  }
162  }
163 } elseif ($action == 'unsetdoc') {
164  $tmpobjectkey = GETPOST('object');
165  if (!empty($tmpobjectkey)) {
166  $constforval = 'ASSET_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
167  dolibarr_del_const($db, $constforval, $conf->entity);
168  }
169 }
170 
171 
172 
173 /*
174  * View
175  */
176 
177 $form = new Form($db);
178 
179 $help_url = '';
180 $page_name = "AssetSetup";
181 
182 llxHeader('', $langs->trans($page_name), $help_url);
183 
184 // Subheader
185 $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
186 
187 print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
188 
189 // Configuration header
190 $head = assetAdminPrepareHead();
191 print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "asset");
192 
193 // Setup page goes here
194 echo '<span class="opacitymedium">'.$langs->trans("AssetSetupPage").'</span>';
195 
196 
197 $moduledir = 'asset';
198 $myTmpObjects = array();
199 $myTmpObjects['Asset'] = array('includerefgeneration'=>1, 'includedocgeneration'=>0);
200 
201 
202 foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
203  if ($myTmpObjectKey == 'MyObject') {
204  continue;
205  }
206  if ($myTmpObjectArray['includerefgeneration']) {
207  /*
208  * Orders Numbering model
209  */
210  $setupnotempty++;
211 
212  print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
213 
214  print '<table class="noborder centpercent">';
215  print '<tr class="liste_titre">';
216  print '<td>'.$langs->trans("Name").'</td>';
217  print '<td>'.$langs->trans("Description").'</td>';
218  print '<td class="nowrap">'.$langs->trans("Example").'</td>';
219  print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
220  print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
221  print '</tr>'."\n";
222 
223  clearstatcache();
224 
225  foreach ($dirmodels as $reldir) {
226  $dir = dol_buildpath($reldir."core/modules/".$moduledir);
227 
228  if (is_dir($dir)) {
229  $handle = opendir($dir);
230  if (is_resource($handle)) {
231  while (($file = readdir($handle)) !== false) {
232  if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
233  $file = substr($file, 0, dol_strlen($file) - 4);
234 
235  require_once $dir.'/'.$file.'.php';
236 
237  $module = new $file($db);
238 
239  // Show modules according to features level
240  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
241  continue;
242  }
243  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
244  continue;
245  }
246 
247  if ($module->isEnabled()) {
248  dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
249 
250  print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
251  print $module->info();
252  print '</td>';
253 
254  // Show example of numbering model
255  print '<td class="nowrap">';
256  $tmp = $module->getExample();
257  if (preg_match('/^Error/', $tmp)) {
258  $langs->load("errors");
259  print '<div class="error">'.$langs->trans($tmp).'</div>';
260  } elseif ($tmp == 'NotConfigured') {
261  print $langs->trans($tmp);
262  } else {
263  print $tmp;
264  }
265  print '</td>'."\n";
266 
267  print '<td class="center">';
268  $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
269  if (getDolGlobalString($constforvar) == $file) {
270  print img_picto($langs->trans("Activated"), 'switch_on');
271  } else {
272  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
273  print img_picto($langs->trans("Disabled"), 'switch_off');
274  print '</a>';
275  }
276  print '</td>';
277 
278  $mytmpinstance = new $myTmpObjectKey($db);
279  $mytmpinstance->initAsSpecimen();
280 
281  // Info
282  $htmltooltip = '';
283  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
284 
285  $nextval = $module->getNextValue($mytmpinstance);
286  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
287  $htmltooltip .= ''.$langs->trans("NextValue").': ';
288  if ($nextval) {
289  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
290  $nextval = $langs->trans($nextval);
291  }
292  $htmltooltip .= $nextval.'<br>';
293  } else {
294  $htmltooltip .= $langs->trans($module->error).'<br>';
295  }
296  }
297 
298  print '<td class="center">';
299  print $form->textwithpicto('', $htmltooltip, 1, 0);
300  print '</td>';
301 
302  print "</tr>\n";
303  }
304  }
305  }
306  closedir($handle);
307  }
308  }
309  }
310  print "</table><br>\n";
311  }
312 
313  if ($myTmpObjectArray['includedocgeneration']) {
314  /*
315  * Document templates generators
316  */
317  $setupnotempty++;
318  $type = strtolower($myTmpObjectKey);
319 
320  print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
321 
322  // Load array def with activated templates
323  $def = array();
324  $sql = "SELECT nom";
325  $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
326  $sql .= " WHERE type = '".$db->escape($type)."'";
327  $sql .= " AND entity = ".$conf->entity;
328  $resql = $db->query($sql);
329  if ($resql) {
330  $i = 0;
331  $num_rows = $db->num_rows($resql);
332  while ($i < $num_rows) {
333  $array = $db->fetch_array($resql);
334  array_push($def, $array[0]);
335  $i++;
336  }
337  } else {
338  dol_print_error($db);
339  }
340 
341  print "<table class=\"noborder\" width=\"100%\">\n";
342  print "<tr class=\"liste_titre\">\n";
343  print '<td>'.$langs->trans("Name").'</td>';
344  print '<td>'.$langs->trans("Description").'</td>';
345  print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
346  print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
347  print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
348  print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
349  print "</tr>\n";
350 
351  clearstatcache();
352 
353  foreach ($dirmodels as $reldir) {
354  foreach (array('', '/doc') as $valdir) {
355  $realpath = $reldir."core/modules/".$moduledir.$valdir;
356  $dir = dol_buildpath($realpath);
357 
358  if (is_dir($dir)) {
359  $handle = opendir($dir);
360  if (is_resource($handle)) {
361  while (($file = readdir($handle)) !== false) {
362  $filelist[] = $file;
363  }
364  closedir($handle);
365  arsort($filelist);
366 
367  foreach ($filelist as $file) {
368  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
369  if (file_exists($dir.'/'.$file)) {
370  $name = substr($file, 4, dol_strlen($file) - 16);
371  $classname = substr($file, 0, dol_strlen($file) - 12);
372 
373  require_once $dir.'/'.$file;
374  $module = new $classname($db);
375 
376  $modulequalified = 1;
377  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
378  $modulequalified = 0;
379  }
380  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
381  $modulequalified = 0;
382  }
383 
384  if ($modulequalified) {
385  print '<tr class="oddeven"><td width="100">';
386  print (empty($module->name) ? $name : $module->name);
387  print "</td><td>\n";
388  if (method_exists($module, 'info')) {
389  print $module->info($langs);
390  } else {
391  print $module->description;
392  }
393  print '</td>';
394 
395  // Active
396  if (in_array($name, $def)) {
397  print '<td class="center">'."\n";
398  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
399  print img_picto($langs->trans("Enabled"), 'switch_on');
400  print '</a>';
401  print '</td>';
402  } else {
403  print '<td class="center">'."\n";
404  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>';
405  print "</td>";
406  }
407 
408  // Default
409  print '<td class="center">';
410  $constforvar = 'ASSET_'.strtoupper($myTmpObjectKey).'_ADDON';
411  if (getDolGlobalString($constforvar) == $name) {
412  //print img_picto($langs->trans("Default"), 'on');
413  // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
414  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>';
415  } else {
416  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>';
417  }
418  print '</td>';
419 
420  // Info
421  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
422  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
423  if ($module->type == 'pdf') {
424  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
425  }
426  $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
427 
428  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
429  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
430  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
431 
432  print '<td class="center">';
433  print $form->textwithpicto('', $htmltooltip, 1, 0);
434  print '</td>';
435 
436  // Preview
437  print '<td class="center">';
438  if ($module->type == 'pdf') {
439  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
440  } else {
441  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
442  }
443  print '</td>';
444 
445  print "</tr>\n";
446  }
447  }
448  }
449  }
450  }
451  }
452  }
453  }
454 
455  print '</table>';
456  }
457 }
458 
459 if ($action == 'edit') {
460  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
461  print '<input type="hidden" name="token" value="'.newToken().'">';
462  print '<input type="hidden" name="action" value="update">';
463 
464  print '<table class="noborder centpercent">';
465  print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
466 
467  foreach ($arrayofparameters as $constname => $val) {
468  if ($val['enabled']==1) {
469  $setupnotempty++;
470  print '<tr class="oddeven"><td>';
471  $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
472  print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
473  print '</td><td>';
474 
475  if ($val['type'] == 'textarea') {
476  print '<textarea class="flat" name="'.$constname.'" id="'.$constname.'" cols="50" rows="5" wrap="soft">' . "\n";
477  print $conf->global->{$constname};
478  print "</textarea>\n";
479  } elseif ($val['type']== 'html') {
480  require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
481  $doleditor = new DolEditor($constname, $conf->global->{$constname}, '', 160, 'dolibarr_notes', '', false, false, $conf->fckeditor->enabled, ROWS_5, '90%');
482  $doleditor->Create();
483  } elseif ($val['type'] == 'yesno') {
484  print $form->selectyesno($constname, $conf->global->{$constname}, 1);
485  } elseif (preg_match('/emailtemplate:/', $val['type'])) {
486  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
487  $formmail = new FormMail($db);
488 
489  $tmp = explode(':', $val['type']);
490  $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
491  //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
492  $arrayofmessagename = array();
493  if (is_array($formmail->lines_model)) {
494  foreach ($formmail->lines_model as $modelmail) {
495  //var_dump($modelmail);
496  $moreonlabel = '';
497  if (!empty($arrayofmessagename[$modelmail->label])) {
498  $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
499  }
500  // The 'label' is the key that is unique if we exclude the language
501  $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->label)) . $moreonlabel;
502  }
503  }
504  print $form->selectarray($constname, $arrayofmessagename, $conf->global->{$constname}, 'None', 0, 0, '', 0, 0, 0, '', '', 1);
505  } elseif (preg_match('/category:/', $val['type'])) {
506  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
507  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
508  $formother = new FormOther($db);
509 
510  $tmp = explode(':', $val['type']);
511  print img_picto('', 'category', 'class="pictofixedwidth"');
512  print $formother->select_categories($tmp[1], $conf->global->{$constname}, $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
513  } elseif (preg_match('/thirdparty_type/', $val['type'])) {
514  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
515  $formcompany = new FormCompany($db);
516  print $formcompany->selectProspectCustomerType($conf->global->{$constname}, $constname);
517  } elseif ($val['type'] == 'securekey') {
518  print '<input required="required" type="text" class="flat" id="'.$constname.'" name="'.$constname.'" value="'.(GETPOST($constname, 'alpha') ?GETPOST($constname, 'alpha') : $conf->global->{$constname}).'" size="40">';
519  if (!empty($conf->use_javascript_ajax)) {
520  print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token'.$constname.'" class="linkobject"');
521  }
522  if (!empty($conf->use_javascript_ajax)) {
523  print "\n".'<script type="text/javascript">';
524  print '$(document).ready(function () {
525  $("#generate_token'.$constname.'").click(function() {
526  $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
527  action: \'getrandompassword\',
528  generic: true
529  },
530  function(token) {
531  $("#'.$constname.'").val(token);
532  });
533  });
534  });';
535  print '</script>';
536  }
537  } elseif ($val['type'] == 'product') {
538  if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
539  $selected = (empty($conf->global->$constname) ? '' : $conf->global->$constname);
540  $form->select_produits($selected, $constname, '', 0);
541  }
542  } elseif ($val['type'] == 'accountancy_code') {
543  $selected = (empty($conf->global->$constname) ? '' : $conf->global->$constname);
544  if (!empty($conf->accounting->enabled)) {
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, null, 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 = (empty($conf->global->$constname) ? '' : $conf->global->$constname);
553  if (!empty($conf->accounting->enabled)) {
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($conf->global->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="'.$conf->global->{$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>'.$langs->trans("Value").'</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($conf->global->{$constname});
603  } elseif ($val['type']== 'html') {
604  print $conf->global->{$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, $conf->global->{$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($conf->global->{$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 formated 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 ($conf->global->{$constname}==2) {
633  print $langs->trans("Prospect");
634  } elseif ($conf->global->{$constname}==3) {
635  print $langs->trans("ProspectCustomer");
636  } elseif ($conf->global->{$constname}==1) {
637  print $langs->trans("Customer");
638  } elseif ($conf->global->{$constname}==0) {
639  print $langs->trans("NorProspectNorCustomer");
640  }
641  } elseif ($val['type'] == 'product') {
642  $product = new Product($db);
643  $resprod = $product->fetch($conf->global->{$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 (!empty($conf->accounting->enabled)) {
651  require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
652  $accountingaccount = new AccountingAccount($db);
653  $accountingaccount->fetch('', $conf->global->{$constname}, 1);
654 
655  print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
656  } else {
657  print $conf->global->{$constname};
658  }
659  } else {
660  print $conf->global->{$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 
676 if (empty($setupnotempty)) {
677  print '<br>'.$langs->trans("NothingToSetup");
678 }
679 
680 // Page end
681 print dol_get_fiche_end();
682 
683 llxFooter();
684 $db->close();
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6491
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_nl2br
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
Definition: functions.lib.php:6963
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1033
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
Categorie
Class to manage categories.
Definition: categorie.class.php:47
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
delDocumentModel
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1894
AccountancySystem
Class to manage accountancy systems.
Definition: accountancysystem.class.php:29
assetAdminPrepareHead
assetAdminPrepareHead()
Prepare admin pages header.
Definition: asset.lib.php:29
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
ajax_constantonoff
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='')
On/off button for constant.
Definition: ajax.lib.php:573
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
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).
Definition: admin.lib.php:627
AccountingAccount
Class to manage accounting accounts.
Definition: accountingaccount.class.php:36
addDocumentModel
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1863
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30