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 include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
73 if ($action ==
'updateMask') {
74 $maskconst =
GETPOST(
'maskconst',
'alpha');
75 $mask =
GETPOST(
'mask',
'alpha');
77 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
89 } elseif ($action ==
'specimen') {
90 $modele =
GETPOST(
'module',
'alpha');
91 $tmpobjectkey =
GETPOST(
'object');
93 $tmpobject =
new $tmpobjectkey($db);
94 $tmpobject->initAsSpecimen();
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)) {
103 $classname =
"pdf_".$modele;
111 $module =
new $classname($db);
113 if ($module->write_file($tmpobject, $langs) > 0) {
114 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
122 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
124 } elseif ($action ==
'setmod') {
126 $tmpobjectkey =
GETPOST(
'object');
127 if (!empty($tmpobjectkey)) {
128 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
"_ADDON";
131 } elseif ($action ==
'set') {
134 } elseif ($action ==
'del') {
137 $tmpobjectkey =
GETPOST(
'object');
138 if (!empty($tmpobjectkey)) {
139 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
140 if ($conf->global->$constforval ==
"$value") {
145 } elseif ($action ==
'setdoc') {
147 $tmpobjectkey =
GETPOST(
'object');
148 if (!empty($tmpobjectkey)) {
149 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
153 $conf->global->$constforval = $value;
162 } elseif ($action ==
'unsetdoc') {
163 $tmpobjectkey =
GETPOST(
'object');
164 if (!empty($tmpobjectkey)) {
165 $constforval =
'ASSET_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
179 $page_name =
"AssetSetup";
184 $linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
186 print
load_fiche_titre($langs->trans($page_name), $linkback,
'title_setup');
193 echo
'<span class="opacitymedium">'.$langs->trans(
"AssetSetupPage").
'</span>';
196 $moduledir =
'asset';
197 $myTmpObjects = array();
198 $myTmpObjects[
'Asset'] = array(
'includerefgeneration'=>1,
'includedocgeneration'=>0);
201 foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
202 if ($myTmpObjectKey ==
'MyObject') {
205 if ($myTmpObjectArray[
'includerefgeneration']) {
211 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectKey),
'',
'');
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>';
224 foreach ($dirmodels as $reldir) {
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);
234 require_once $dir.
'/'.$file.
'.php';
236 $module =
new $file($db);
239 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
242 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
246 if ($module->isEnabled()) {
247 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
249 print
'<tr class="oddeven"><td>'.$module->name.
"</td><td>\n";
250 print $module->info();
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);
266 print
'<td class="center">';
267 $constforvar =
'ASSET_'.strtoupper($myTmpObjectKey).
'_ADDON';
269 print
img_picto($langs->trans(
"Activated"),
'switch_on');
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');
277 $mytmpinstance =
new $myTmpObjectKey($db);
278 $mytmpinstance->initAsSpecimen();
282 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
284 $nextval = $module->getNextValue($mytmpinstance);
285 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
286 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
288 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
289 $nextval = $langs->trans($nextval);
291 $htmltooltip .= $nextval.
'<br>';
293 $htmltooltip .= $langs->trans($module->error).
'<br>';
297 print
'<td class="center">';
298 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
309 print
"</table><br>\n";
312 if ($myTmpObjectArray[
'includedocgeneration']) {
317 $type = strtolower($myTmpObjectKey);
319 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
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);
330 $num_rows = $db->num_rows($resql);
331 while ($i < $num_rows) {
332 $array = $db->fetch_array($resql);
333 array_push($def, $array[0]);
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>';
352 foreach ($dirmodels as $reldir) {
353 foreach (array(
'',
'/doc') as $valdir) {
354 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
358 $handle = opendir($dir);
359 if (is_resource($handle)) {
360 while (($file = readdir($handle)) !==
false) {
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);
372 require_once $dir.
'/'.$file;
373 $module =
new $classname($db);
375 $modulequalified = 1;
376 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
377 $modulequalified = 0;
379 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
380 $modulequalified = 0;
383 if ($modulequalified) {
384 print
'<tr class="oddeven"><td width="100">';
385 print (empty($module->name) ? $name : $module->name);
387 if (method_exists($module,
'info')) {
388 print $module->info($langs);
390 print $module->description;
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');
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>';
408 print
'<td class="center">';
409 $constforvar =
'ASSET_'.strtoupper($myTmpObjectKey).
'_ADDON';
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).
'&type='.urlencode($type).
'" alt="'.$langs->trans(
"Disable").
'">'.
img_picto($langs->trans(
"Enabled"),
'on').
'</a>';
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>';
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;
425 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
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);
431 print
'<td class="center">';
432 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
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>';
440 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
458 if ($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">';
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>';
466 foreach ($arrayofparameters as $constname => $val) {
467 if ($val[
'enabled']==1) {
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>';
474 if ($val[
'type'] ==
'textarea') {
475 print
'<textarea class="flat" name="'.$constname.
'" id="'.$constname.
'" cols="50" rows="5" wrap="soft">' .
"\n";
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') {
484 } elseif (preg_match(
'/emailtemplate:/', $val[
'type'])) {
485 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
488 $tmp = explode(
':', $val[
'type']);
489 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
491 $arrayofmessagename = array();
492 if (is_array($formmail->lines_model)) {
493 foreach ($formmail->lines_model as $modelmail) {
496 if (!empty($arrayofmessagename[$modelmail->label])) {
497 $moreonlabel =
' <span class="opacitymedium">(' . $langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
500 $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace(
'/\(|\)/',
'', $modelmail->label)) . $moreonlabel;
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';
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';
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
' '.img_picto($langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$constname.
'" class="linkobject"');
523 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
525 } elseif ($val[
'type'] ==
'product') {
528 $form->select_produits($selected, $constname,
'', 0);
530 } elseif ($val[
'type'] ==
'accountancy_code') {
533 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formaccounting.class.php';
535 print $formaccounting->select_account($selected, $constname, 1,
null, 1, 1,
'minwidth150 maxwidth300', 1);
537 print
'<input name="' . $constname .
'" class="maxwidth200" value="' .
dol_escape_htmltag($selected) .
'">';
539 } elseif ($val[
'type'] ==
'accountancy_category') {
542 print
'<input type="text" name="' . $constname .
'" list="pcg_type_datalist" value="' . $selected .
'">';
544 print
'<datalist id="pcg_type_datalist">';
545 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/accountancysystem.class.php';
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).
')';
551 $sql .=
' LIMIT 50000';
552 $resql = $db->query(
$sql);
554 while ($obj = $db->fetch_object($resql)) {
560 print
'<input name="' . $constname .
'" class="maxwidth200" value="' .
dol_escape_htmltag($selected) .
'">';
563 print
'<input name="'.$constname.
'" class="flat '.(empty($val[
'css']) ?
'minwidth200' : $val[
'css']).
'" value="'.$conf->global->{$constname}.
'">';
570 print
'<br><div class="center">';
571 print
'<input class="button button-save" type="submit" value="'.$langs->trans(
"Save").
'">';
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>';
581 foreach ($arrayofparameters as $constname => $val) {
582 if ($val[
'enabled']==1) {
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);
589 if ($val[
'type'] ==
'textarea') {
591 } elseif ($val[
'type']==
'html') {
593 } elseif ($val[
'type'] ==
'yesno') {
595 } elseif (preg_match(
'/emailtemplate:/', $val[
'type'])) {
596 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
599 $tmp = explode(
':', $val[
'type']);
601 $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs,
getDolGlobalString($constname));
605 print $langs->trans($template->label);
606 } elseif (preg_match(
'/category:/', $val[
'type'])) {
611 } elseif ($result > 0 ) {
612 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
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>';
617 print
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
619 } elseif (preg_match(
'/thirdparty_type/', $val[
'type'])) {
621 print $langs->trans(
"Prospect");
623 print $langs->trans(
"ProspectCustomer");
625 print $langs->trans(
"Customer");
627 print $langs->trans(
"NorProspectNorCustomer");
629 } elseif ($val[
'type'] ==
'product') {
634 } elseif ($resprod < 0) {
637 } elseif ($val[
'type'] ==
'accountancy_code') {
639 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/accountingaccount.class.php';
643 print $accountingaccount->getNomUrl(0, 1, 1,
'', 1);
656 print
'<div class="tabsAction">';
657 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
660 print
'<br>'.$langs->trans(
"NothingToSetup");
664 if (empty($setupnotempty)) {
665 print
'<br>'.$langs->trans(
"NothingToSetup");