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";
32 $langs->loadLangs(array(
"admin",
"assets"));
40 $action =
GETPOST(
'action',
'aZ09');
41 $backtopage =
GETPOST(
'backtopage',
'alpha');
43 $value =
GETPOST(
'value',
'alpha');
44 $label =
GETPOST(
'label',
'alpha');
45 $scandir =
GETPOST(
'scan_dir',
'alpha');
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),
63 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
70 if ((
float) DOL_VERSION >= 6) {
71 include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
74 if ($action ==
'updateMask') {
75 $maskconstorder =
GETPOST(
'maskconstorder',
'alpha');
76 $maskorder =
GETPOST(
'maskorder',
'alpha');
78 if ($maskconstorder) {
79 $res =
dolibarr_set_const($db, $maskconstorder, $maskorder,
'chaine', 0,
'', $conf->entity);
90 } elseif ($action ==
'specimen') {
91 $modele =
GETPOST(
'module',
'alpha');
92 $tmpobjectkey =
GETPOST(
'object');
94 $tmpobject =
new $tmpobjectkey($db);
95 $tmpobject->initAsSpecimen();
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)) {
104 $classname =
"pdf_".$modele;
112 $module =
new $classname($db);
114 if ($module->write_file($tmpobject, $langs) > 0) {
115 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
123 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
125 } elseif ($action ==
'setmod') {
127 $tmpobjectkey =
GETPOST(
'object');
128 if (!empty($tmpobjectkey)) {
129 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
"_ADDON";
132 } elseif ($action ==
'set') {
135 } elseif ($action ==
'del') {
138 $tmpobjectkey =
GETPOST(
'object');
139 if (!empty($tmpobjectkey)) {
140 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
141 if ($conf->global->$constforval ==
"$value") {
146 } elseif ($action ==
'setdoc') {
148 $tmpobjectkey =
GETPOST(
'object');
149 if (!empty($tmpobjectkey)) {
150 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
154 $conf->global->$constforval = $value;
163 } elseif ($action ==
'unsetdoc') {
164 $tmpobjectkey =
GETPOST(
'object');
165 if (!empty($tmpobjectkey)) {
166 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
180 $page_name =
"AssetSetup";
185 $linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
187 print
load_fiche_titre($langs->trans($page_name), $linkback,
'title_setup');
194 echo
'<span class="opacitymedium">'.$langs->trans(
"AssetSetupPage").
'</span>';
197 $moduledir =
'asset';
198 $myTmpObjects = array();
199 $myTmpObjects[
'Asset'] = array(
'includerefgeneration'=>1,
'includedocgeneration'=>0);
202 foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
203 if ($myTmpObjectKey ==
'MyObject') {
206 if ($myTmpObjectArray[
'includerefgeneration']) {
212 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectKey),
'',
'');
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>';
225 foreach ($dirmodels as $reldir) {
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);
235 require_once $dir.
'/'.$file.
'.php';
237 $module =
new $file($db);
240 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
243 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
247 if ($module->isEnabled()) {
248 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
250 print
'<tr class="oddeven"><td>'.$module->name.
"</td><td>\n";
251 print $module->info();
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);
267 print
'<td class="center">';
268 $constforvar =
'ASSET_'.strtoupper($myTmpObjectKey).
'_ADDON';
270 print
img_picto($langs->trans(
"Activated"),
'switch_on');
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');
278 $mytmpinstance =
new $myTmpObjectKey($db);
279 $mytmpinstance->initAsSpecimen();
283 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
285 $nextval = $module->getNextValue($mytmpinstance);
286 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
287 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
289 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
290 $nextval = $langs->trans($nextval);
292 $htmltooltip .= $nextval.
'<br>';
294 $htmltooltip .= $langs->trans($module->error).
'<br>';
298 print
'<td class="center">';
299 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
310 print
"</table><br>\n";
313 if ($myTmpObjectArray[
'includedocgeneration']) {
318 $type = strtolower($myTmpObjectKey);
320 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
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);
331 $num_rows = $db->num_rows(
$resql);
332 while ($i < $num_rows) {
333 $array = $db->fetch_array(
$resql);
334 array_push($def, $array[0]);
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>';
353 foreach ($dirmodels as $reldir) {
354 foreach (array(
'',
'/doc') as $valdir) {
355 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
359 $handle = opendir($dir);
360 if (is_resource($handle)) {
361 while (($file = readdir($handle)) !==
false) {
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);
373 require_once $dir.
'/'.$file;
374 $module =
new $classname($db);
376 $modulequalified = 1;
377 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
378 $modulequalified = 0;
380 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
381 $modulequalified = 0;
384 if ($modulequalified) {
385 print
'<tr class="oddeven"><td width="100">';
386 print (empty($module->name) ? $name : $module->name);
388 if (method_exists($module,
'info')) {
389 print $module->info($langs);
391 print $module->description;
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');
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>';
409 print
'<td class="center">';
410 $constforvar =
'ASSET_'.strtoupper($myTmpObjectKey).
'_ADDON';
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).
'&type='.urlencode($type).
'" alt="'.$langs->trans(
"Disable").
'">'.
img_picto($langs->trans(
"Enabled"),
'on').
'</a>';
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>';
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;
426 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
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);
432 print
'<td class="center">';
433 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
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>';
441 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
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">';
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>';
467 foreach ($arrayofparameters as $constname => $val) {
468 if ($val[
'enabled']==1) {
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>';
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';
489 $tmp = explode(
':', $val[
'type']);
490 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
492 $arrayofmessagename = array();
493 if (is_array($formmail->lines_model)) {
494 foreach ($formmail->lines_model as $modelmail) {
497 if (!empty($arrayofmessagename[$modelmail->label])) {
498 $moreonlabel =
' <span class="opacitymedium">(' . $langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
501 $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace(
'/\(|\)/',
'', $modelmail->label)) . $moreonlabel;
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';
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';
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
' '.img_picto($langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$constname.
'" class="linkobject"');
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\',
531 $("#'.$constname.
'").val(token);
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);
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';
547 print $formaccounting->select_account($selected, $constname, 1,
null, 1, 1,
'minwidth150 maxwidth300', 1);
549 print
'<input name="' . $constname .
'" class="maxwidth200" value="' .
dol_escape_htmltag($selected) .
'">';
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 .
'">';
556 print
'<datalist id="pcg_type_datalist">';
557 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/accountancysystem.class.php';
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).
')';
563 $sql .=
' LIMIT 50000';
564 $resql = $db->query($sql);
566 while ($obj = $db->fetch_object(
$resql)) {
572 print
'<input name="' . $constname .
'" class="maxwidth200" value="' .
dol_escape_htmltag($selected) .
'">';
575 print
'<input name="'.$constname.
'" class="flat '.(empty($val[
'css']) ?
'minwidth200' : $val[
'css']).
'" value="'.$conf->global->{$constname}.
'">';
582 print
'<br><div class="center">';
583 print
'<input class="button button-save" type="submit" value="'.$langs->trans(
"Save").
'">';
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>';
593 foreach ($arrayofparameters as $constname => $val) {
594 if ($val[
'enabled']==1) {
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);
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') {
607 } elseif (preg_match(
'/emailtemplate:/', $val[
'type'])) {
608 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
611 $tmp = explode(
':', $val[
'type']);
613 $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, $conf->global->{$constname});
617 print $langs->trans($template->label);
618 } elseif (preg_match(
'/category:/', $val[
'type'])) {
620 $result = $c->fetch($conf->global->{$constname});
623 } elseif ($result > 0 ) {
624 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
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>';
629 print
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
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");
641 } elseif ($val[
'type'] ==
'product') {
643 $resprod = $product->fetch($conf->global->{$constname});
646 } elseif ($resprod < 0) {
649 } elseif ($val[
'type'] ==
'accountancy_code') {
650 if (!empty($conf->accounting->enabled)) {
651 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/accountingaccount.class.php';
653 $accountingaccount->fetch(
'', $conf->global->{$constname}, 1);
655 print $accountingaccount->getNomUrl(0, 1, 1,
'', 1);
657 print $conf->global->{$constname};
660 print $conf->global->{$constname};
668 print
'<div class="tabsAction">';
669 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
672 print
'<br>'.$langs->trans(
"NothingToSetup");
676 if (empty($setupnotempty)) {
677 print
'<br>'.$langs->trans(
"NothingToSetup");