26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/asset.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
33 $langs->loadLangs(array(
"admin",
"assets"));
41 $action =
GETPOST(
'action',
'aZ09');
42 $backtopage =
GETPOST(
'backtopage',
'alpha');
44 $value =
GETPOST(
'value',
'alpha');
45 $label =
GETPOST(
'label',
'alpha');
46 $scandir =
GETPOST(
'scan_dir',
'alpha');
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),
64 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
71 if ((
float) DOL_VERSION >= 6) {
72 include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
75 if ($action ==
'updateMask') {
76 $maskconstorder =
GETPOST(
'maskconstorder',
'aZ09');
77 $maskorder =
GETPOST(
'maskorder',
'alpha');
79 if ($maskconstorder && preg_match(
'/_MASK$/', $maskconstorder)) {
80 $res =
dolibarr_set_const($db, $maskconstorder, $maskorder,
'chaine', 0,
'', $conf->entity);
91 } elseif ($action ==
'specimen') {
92 $modele =
GETPOST(
'module',
'alpha');
93 $tmpobjectkey =
GETPOST(
'object');
95 $tmpobject =
new $tmpobjectkey($db);
96 $tmpobject->initAsSpecimen();
99 $file =
''; $classname =
''; $filefound = 0;
100 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
101 foreach ($dirmodels as $reldir) {
102 $file =
dol_buildpath($reldir.
"core/modules/asset/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
103 if (file_exists($file)) {
105 $classname =
"pdf_".$modele;
113 $module =
new $classname($db);
115 if ($module->write_file($tmpobject, $langs) > 0) {
116 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
124 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
126 } elseif ($action ==
'setmod') {
128 $tmpobjectkey =
GETPOST(
'object');
129 if (!empty($tmpobjectkey)) {
130 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
"_ADDON";
133 } elseif ($action ==
'set') {
136 } elseif ($action ==
'del') {
139 $tmpobjectkey =
GETPOST(
'object');
140 if (!empty($tmpobjectkey)) {
141 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
142 if ($conf->global->$constforval ==
"$value") {
147 } elseif ($action ==
'setdoc') {
149 $tmpobjectkey =
GETPOST(
'object');
150 if (!empty($tmpobjectkey)) {
151 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
155 $conf->global->$constforval = $value;
164 } elseif ($action ==
'unsetdoc') {
165 $tmpobjectkey =
GETPOST(
'object');
166 if (!empty($tmpobjectkey)) {
167 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
181 $page_name =
"AssetSetup";
186 $linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
188 print
load_fiche_titre($langs->trans($page_name), $linkback,
'title_setup');
195 echo
'<span class="opacitymedium">'.$langs->trans(
"AssetSetupPage").
'</span>';
198 $moduledir =
'asset';
199 $myTmpObjects = array();
200 $myTmpObjects[
'Asset'] = array(
'includerefgeneration'=>1,
'includedocgeneration'=>0);
203 foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
204 if ($myTmpObjectKey ==
'MyObject') {
207 if ($myTmpObjectArray[
'includerefgeneration']) {
213 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectKey),
'',
'');
215 print
'<table class="noborder centpercent">';
216 print
'<tr class="liste_titre">';
217 print
'<td>'.$langs->trans(
"Name").
'</td>';
218 print
'<td>'.$langs->trans(
"Description").
'</td>';
219 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
220 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
221 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
226 foreach ($dirmodels as $reldir) {
230 $handle = opendir($dir);
231 if (is_resource($handle)) {
232 while (($file = readdir($handle)) !==
false) {
233 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') === 0 && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
234 $file = substr($file, 0,
dol_strlen($file) - 4);
236 require_once $dir.
'/'.$file.
'.php';
238 $module =
new $file($db);
241 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
244 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
248 if ($module->isEnabled()) {
249 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
251 print
'<tr class="oddeven"><td>'.$module->name.
"</td><td>\n";
252 print $module->info();
256 print
'<td class="nowrap">';
257 $tmp = $module->getExample();
258 if (preg_match(
'/^Error/', $tmp)) {
259 $langs->load(
"errors");
260 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
261 } elseif ($tmp ==
'NotConfigured') {
262 print $langs->trans($tmp);
268 print
'<td class="center">';
269 $constforvar =
'ASSET_'.strtoupper($myTmpObjectKey).
'_ADDON';
271 print
img_picto($langs->trans(
"Activated"),
'switch_on');
273 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&object='.strtolower($myTmpObjectKey).
'&value='.urlencode($file).
'">';
274 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
279 $mytmpinstance =
new $myTmpObjectKey($db);
280 $mytmpinstance->initAsSpecimen();
284 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
286 $nextval = $module->getNextValue($mytmpinstance);
287 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
288 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
290 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
291 $nextval = $langs->trans($nextval);
293 $htmltooltip .= $nextval.
'<br>';
295 $htmltooltip .= $langs->trans($module->error).
'<br>';
299 print
'<td class="center">';
300 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
311 print
"</table><br>\n";
314 if ($myTmpObjectArray[
'includedocgeneration']) {
319 $type = strtolower($myTmpObjectKey);
321 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
326 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
327 $sql .=
" WHERE type = '".$db->escape($type).
"'";
328 $sql .=
" AND entity = ".$conf->entity;
329 $resql = $db->query($sql);
332 $num_rows = $db->num_rows(
$resql);
333 while ($i < $num_rows) {
334 $array = $db->fetch_array(
$resql);
335 array_push($def, $array[0]);
342 print
"<table class=\"noborder\" width=\"100%\">\n";
343 print
"<tr class=\"liste_titre\">\n";
344 print
'<td>'.$langs->trans(
"Name").
'</td>';
345 print
'<td>'.$langs->trans(
"Description").
'</td>';
346 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
347 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
348 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
349 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
354 foreach ($dirmodels as $reldir) {
355 foreach (array(
'',
'/doc') as $valdir) {
356 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
360 $handle = opendir($dir);
361 if (is_resource($handle)) {
362 while (($file = readdir($handle)) !==
false) {
368 foreach ($filelist as $file) {
369 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
370 if (file_exists($dir.
'/'.$file)) {
371 $name = substr($file, 4,
dol_strlen($file) - 16);
372 $classname = substr($file, 0,
dol_strlen($file) - 12);
374 require_once $dir.
'/'.$file;
375 $module =
new $classname($db);
377 $modulequalified = 1;
378 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
379 $modulequalified = 0;
381 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
382 $modulequalified = 0;
385 if ($modulequalified) {
386 print
'<tr class="oddeven"><td width="100">';
387 print (empty($module->name) ? $name : $module->name);
389 if (method_exists($module,
'info')) {
390 print $module->info($langs);
392 print $module->description;
397 if (in_array($name, $def)) {
398 print
'<td class="center">'.
"\n";
399 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.
newToken().
'&value='.urlencode($name).
'">';
400 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
404 print
'<td class="center">'.
"\n";
405 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=set&token='.
newToken().
'&value='.urlencode($name).
'&scan_dir='.urlencode($module->scandir).
'&label='.urlencode($module->name).
'">'.
img_picto($langs->trans(
"Disabled"),
'switch_off').
'</a>';
410 print
'<td class="center">';
411 $constforvar =
'ASSET_'.strtoupper($myTmpObjectKey).
'_ADDON';
415 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=unsetdoc&token='.
newToken().
'&object='.urlencode(strtolower($myTmpObjectKey)).
'&value='.urlencode($name).
'&scan_dir='.urlencode($module->scandir).
'&label='.urlencode($module->name).
'&type='.urlencode($type).
'" alt="'.$langs->trans(
"Disable").
'">'.
img_picto($langs->trans(
"Enabled"),
'on').
'</a>';
417 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setdoc&token='.
newToken().
'&object='.urlencode(strtolower($myTmpObjectKey)).
'&value='.urlencode($name).
'&scan_dir='.urlencode($module->scandir).
'&label='.urlencode($module->name).
'" alt="'.$langs->trans(
"Default").
'">'.
img_picto($langs->trans(
"Disabled"),
'off').
'</a>';
422 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
423 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
424 if ($module->type ==
'pdf') {
425 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
427 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
429 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
430 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
431 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
433 print
'<td class="center">';
434 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
438 print
'<td class="center">';
439 if ($module->type ==
'pdf') {
440 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.$name.
'&object='.$myTmpObjectKey.
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
442 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
460 if ($action ==
'edit') {
461 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
462 print
'<input type="hidden" name="token" value="'.newToken().
'">';
463 print
'<input type="hidden" name="action" value="update">';
465 print
'<table class="noborder centpercent">';
466 print
'<tr class="liste_titre"><td class="titlefield">'.$langs->trans(
"Parameter").
'</td><td>'.$langs->trans(
"Value").
'</td></tr>';
468 foreach ($arrayofparameters as $constname => $val) {
469 if ($val[
'enabled']==1) {
471 print
'<tr class="oddeven"><td>';
472 $tooltiphelp = (($langs->trans($constname .
'Tooltip') != $constname .
'Tooltip') ? $langs->trans($constname .
'Tooltip') :
'');
473 print
'<span id="helplink'.$constname.
'" class="spanforparamtooltip">'.
$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1,
'info',
'', 0, 3,
'tootips'.$constname).
'</span>';
476 if ($val[
'type'] ==
'textarea') {
477 print
'<textarea class="flat" name="'.$constname.
'" id="'.$constname.
'" cols="50" rows="5" wrap="soft">' .
"\n";
478 print $conf->global->{$constname};
479 print
"</textarea>\n";
480 } elseif ($val[
'type']==
'html') {
481 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
482 $doleditor =
new DolEditor($constname, $conf->global->{$constname},
'', 160,
'dolibarr_notes',
'',
false,
false, $conf->fckeditor->enabled, ROWS_5,
'90%');
483 $doleditor->Create();
484 } elseif ($val[
'type'] ==
'yesno') {
485 print
$form->selectyesno($constname, $conf->global->{$constname}, 1);
486 } elseif (preg_match(
'/emailtemplate:/', $val[
'type'])) {
487 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
490 $tmp = explode(
':', $val[
'type']);
491 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
493 $arrayofmessagename = array();
494 if (is_array($formmail->lines_model)) {
495 foreach ($formmail->lines_model as $modelmail) {
498 if (!empty($arrayofmessagename[$modelmail->label])) {
499 $moreonlabel =
' <span class="opacitymedium">(' . $langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
502 $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace(
'/\(|\)/',
'', $modelmail->label)) . $moreonlabel;
505 print
$form->selectarray($constname, $arrayofmessagename, $conf->global->{$constname},
'None', 0, 0,
'', 0, 0, 0,
'',
'', 1);
506 } elseif (preg_match(
'/category:/', $val[
'type'])) {
507 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
508 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
511 $tmp = explode(
':', $val[
'type']);
512 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
513 print $formother->select_categories($tmp[1], $conf->global->{$constname}, $constname, 0, $langs->trans(
'CustomersProspectsCategoriesShort'));
514 } elseif (preg_match(
'/thirdparty_type/', $val[
'type'])) {
515 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
517 print $formcompany->selectProspectCustomerType($conf->global->{$constname}, $constname);
518 } elseif ($val[
'type'] ==
'securekey') {
519 print
'<input required="required" type="text" class="flat" id="'.$constname.
'" name="'.$constname.
'" value="'.(
GETPOST($constname,
'alpha') ?
GETPOST($constname,
'alpha') : $conf->global->{$constname}).
'" size="40">';
520 if (!empty($conf->use_javascript_ajax)) {
521 print
' '.img_picto($langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$constname.
'" class="linkobject"');
525 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
527 } elseif ($val[
'type'] ==
'product') {
529 $selected = (empty($conf->global->$constname) ?
'' : $conf->global->$constname);
530 $form->select_produits($selected, $constname,
'', 0);
532 } elseif ($val[
'type'] ==
'accountancy_code') {
533 $selected = (empty($conf->global->$constname) ?
'' : $conf->global->$constname);
535 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formaccounting.class.php';
537 print $formaccounting->select_account($selected, $constname, 1,
null, 1, 1,
'minwidth150 maxwidth300', 1);
539 print
'<input name="' . $constname .
'" class="maxwidth200" value="' .
dol_escape_htmltag($selected) .
'">';
541 } elseif ($val[
'type'] ==
'accountancy_category') {
542 $selected = (empty($conf->global->$constname) ?
'' : $conf->global->$constname);
544 print
'<input type="text" name="' . $constname .
'" list="pcg_type_datalist" value="' . $selected .
'">';
546 print
'<datalist id="pcg_type_datalist">';
547 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/accountancysystem.class.php';
549 $accountsystem->fetch($conf->global->CHARTOFACCOUNTS);
550 $sql =
'SELECT DISTINCT pcg_type FROM ' . MAIN_DB_PREFIX .
'accounting_account';
551 $sql .=
" WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) .
"'";
552 $sql .=
' AND entity in ('.getEntity(
'accounting_account', 0).
')';
553 $sql .=
' LIMIT 50000';
554 $resql = $db->query($sql);
556 while ($obj = $db->fetch_object(
$resql)) {
562 print
'<input name="' . $constname .
'" class="maxwidth200" value="' .
dol_escape_htmltag($selected) .
'">';
565 print
'<input name="'.$constname.
'" class="flat '.(empty($val[
'css']) ?
'minwidth200' : $val[
'css']).
'" value="'.$conf->global->{$constname}.
'">';
572 print
'<br><div class="center">';
573 print
'<input class="button button-save" type="submit" value="'.$langs->trans(
"Save").
'">';
579 if (!empty($arrayofparameters)) {
580 print
'<table class="noborder centpercent">';
581 print
'<tr class="liste_titre"><td class="titlefield">'.$langs->trans(
"Parameter").
'</td><td>'.$langs->trans(
"Value").
'</td></tr>';
583 foreach ($arrayofparameters as $constname => $val) {
584 if ($val[
'enabled']==1) {
586 print
'<tr class="oddeven"><td>';
587 $tooltiphelp = (($langs->trans($constname .
'Tooltip') != $constname .
'Tooltip') ? $langs->trans($constname .
'Tooltip') :
'');
588 print
$form->textwithpicto($langs->trans($constname), $tooltiphelp);
591 if ($val[
'type'] ==
'textarea') {
592 print
dol_nl2br($conf->global->{$constname});
593 } elseif ($val[
'type']==
'html') {
594 print $conf->global->{$constname};
595 } elseif ($val[
'type'] ==
'yesno') {
597 } elseif (preg_match(
'/emailtemplate:/', $val[
'type'])) {
598 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
601 $tmp = explode(
':', $val[
'type']);
603 $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, $conf->global->{$constname});
607 print $langs->trans($template->label);
608 } elseif (preg_match(
'/category:/', $val[
'type'])) {
610 $result = $c->fetch($conf->global->{$constname});
613 } elseif ($result > 0 ) {
614 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
616 foreach ($ways as $way) {
617 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
619 print
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
621 } elseif (preg_match(
'/thirdparty_type/', $val[
'type'])) {
622 if ($conf->global->{$constname}==2) {
623 print $langs->trans(
"Prospect");
624 } elseif ($conf->global->{$constname}==3) {
625 print $langs->trans(
"ProspectCustomer");
626 } elseif ($conf->global->{$constname}==1) {
627 print $langs->trans(
"Customer");
628 } elseif ($conf->global->{$constname}==0) {
629 print $langs->trans(
"NorProspectNorCustomer");
631 } elseif ($val[
'type'] ==
'product') {
633 $resprod = $product->fetch($conf->global->{$constname});
636 } elseif ($resprod < 0) {
639 } elseif ($val[
'type'] ==
'accountancy_code') {
641 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/accountingaccount.class.php';
643 $accountingaccount->fetch(
'', $conf->global->{$constname}, 1);
645 print $accountingaccount->getNomUrl(0, 1, 1,
'', 1);
647 print $conf->global->{$constname};
650 print $conf->global->{$constname};
658 print
'<div class="tabsAction">';
659 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
662 print
'<br>'.$langs->trans(
"NothingToSetup");
666 if (empty($setupnotempty)) {
667 print
'<br>'.$langs->trans(
"NothingToSetup");