31 require
'../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
38 $langs->loadLangs(array(
'admin',
'errors',
'trips',
'other'));
44 $action =
GETPOST(
'action',
'aZ09');
45 $value =
GETPOST(
'value',
'alpha');
46 $modulepart =
GETPOST(
'modulepart',
'aZ09');
48 $label =
GETPOST(
'label',
'alpha');
49 $scandir =
GETPOST(
'scan_dir',
'alpha');
50 $type =
'expensereport';
57 include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
59 if ($action ==
'updateMask') {
60 $maskconst =
GETPOST(
'maskconst',
'alpha');
61 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
63 $res =
dolibarr_set_const($db, $maskconst, $maskvalue,
'chaine', 0,
'', $conf->entity);
75 } elseif ($action ==
'specimen') {
76 $modele =
GETPOST(
'module',
'alpha');
79 $expensespecimen->initAsSpecimen();
80 $expensespecimen->status = 0;
83 $file =
''; $classname =
''; $filefound = 0;
84 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
85 foreach ($dirmodels as $reldir) {
86 $file =
dol_buildpath($reldir.
"core/modules/expensereport/doc/pdf_".$modele.
".modules.php", 0);
87 if (file_exists($file)) {
89 $classname =
"pdf_".$modele;
97 $module =
new $classname($db);
99 if ($module->write_file($expensespecimen, $langs) > 0) {
100 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=expensereport&file=SPECIMEN.pdf");
108 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
110 } elseif ($action ==
'set') {
113 if ($ret > 0 && empty($conf->global->EXPENSEREPORT_ADDON_PDF)) {
114 dolibarr_set_const($db,
'EXPENSEREPORT_ADDON_PDF', $value,
'chaine', 0,
'', $conf->entity);
116 } elseif ($action ==
'del') {
119 if ($conf->global->EXPENSEREPORT_ADDON_PDF ==
"$value") {
123 } elseif ($action ==
'setdoc') {
125 if (
dolibarr_set_const($db,
"EXPENSEREPORT_ADDON_PDF", $value,
'chaine', 0,
'', $conf->entity)) {
128 $conf->global->EXPENSEREPORT_ADDON_PDF = $value;
136 } elseif ($action ==
'setmod') {
140 dolibarr_set_const($db,
"EXPENSEREPORT_ADDON", $value,
'chaine', 0,
'', $conf->entity);
141 } elseif ($action ==
'setoptions') {
144 $freetext =
GETPOST(
'EXPENSEREPORT_FREE_TEXT',
'restricthtml');
145 $res1 =
dolibarr_set_const($db,
"EXPENSEREPORT_FREE_TEXT", $freetext,
'chaine', 0,
'', $conf->entity);
147 $draft =
GETPOST(
'EXPENSEREPORT_DRAFT_WATERMARK',
'alpha');
148 $res2 =
dolibarr_set_const($db,
"EXPENSEREPORT_DRAFT_WATERMARK", trim($draft),
'chaine', 0,
'', $conf->entity);
151 if (!empty($conf->project->enabled) &&
GETPOSTISSET(
'EXPENSEREPORT_PROJECT_IS_REQUIRED')) {
152 $res3 =
dolibarr_set_const($db,
'EXPENSEREPORT_PROJECT_IS_REQUIRED',
GETPOST(
'EXPENSEREPORT_PROJECT_IS_REQUIRED',
'int'),
'chaine', 0,
'', $conf->entity);
155 $dates =
GETPOST(
'EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH',
'int');
156 $res4 =
dolibarr_set_const($db,
'EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH', intval($dates),
'chaine', 0,
'', $conf->entity);
158 $amounts =
GETPOST(
'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY',
'int');
159 $res5 =
dolibarr_set_const($db,
'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY', intval($amounts),
'chaine', 0,
'', $conf->entity);
161 if (!($res1 > 0) || !($res2 > 0) || !($res3 >= 0) || !($res4 >0) || !($res5 >0)) {
179 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
181 llxHeader(
'', $langs->trans(
"ExpenseReportsSetup"));
185 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
186 print
load_fiche_titre($langs->trans(
"ExpenseReportsSetup"), $linkback,
'title_setup');
191 print
dol_get_fiche_head($head,
'expensereport', $langs->trans(
"ExpenseReports"), -1,
'trip');
197 print
load_fiche_titre($langs->trans(
"ExpenseReportNumberingModules"),
'',
'');
199 print
'<table class="noborder centpercent">';
200 print
'<tr class="liste_titre">';
201 print
'<td>'.$langs->trans(
"Name").
'</td>';
202 print
'<td>'.$langs->trans(
"Description").
'</td>';
203 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
204 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
205 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
210 foreach ($dirmodels as $reldir) {
214 $handle = opendir($dir);
215 if (is_resource($handle)) {
216 while (($file = readdir($handle)) !==
false) {
217 if (substr($file, 0, 18) ==
'mod_expensereport_' && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
218 $file = substr($file, 0,
dol_strlen($file) - 4);
220 require_once $dir.$file.
'.php';
222 $module =
new $file($db);
225 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
228 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
232 if ($module->isEnabled()) {
233 print
'<tr class="oddeven"><td>'.$module->nom.
"</td><td>\n";
234 print $module->info();
238 print
'<td class="nowrap">';
239 $tmp = $module->getExample();
240 if (preg_match(
'/^Error/', $tmp)) {
241 $langs->load(
"errors");
242 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
243 } elseif ($tmp ==
'NotConfigured') {
244 print
'<span class="opacitymedium">'.$langs->trans($tmp).
'</span>';
250 print
'<td class="center">';
251 if ($conf->global->EXPENSEREPORT_ADDON == $file) {
252 print
img_picto($langs->trans(
"Activated"),
'switch_on');
254 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&value='.urlencode($file).
'">';
255 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
261 $exp->initAsSpecimen();
265 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
266 $nextval = $module->getNextValue($exp);
267 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
268 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
270 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
271 $nextval = $langs->trans($nextval);
273 $htmltooltip .= $nextval.
'<br>';
275 $htmltooltip .= $langs->trans($module->error).
'<br>';
279 print
'<td class="center">';
280 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
291 print
"</table><br>\n";
300 $type =
'expensereport';
303 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
304 $sql .=
" WHERE type = '".$db->escape($type).
"'";
305 $sql .=
" AND entity = ".$conf->entity;
306 $resql = $db->query($sql);
309 $num_rows = $db->num_rows(
$resql);
310 while ($i < $num_rows) {
311 $array = $db->fetch_array(
$resql);
312 array_push($def, $array[0]);
319 print
'<table class="noborder centpercent">';
320 print
'<tr class="liste_titre">';
321 print
'<td>'.$langs->trans(
"Name").
'</td>';
322 print
'<td>'.$langs->trans(
"Description").
'</td>';
323 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
324 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
325 print
'<td class="center" width="80">'.$langs->trans(
"ShortInfo").
'</td>';
326 print
'<td class="center" width="80">'.$langs->trans(
"Preview").
'</td>';
331 foreach ($dirmodels as $reldir) {
332 $dir =
dol_buildpath($reldir.
"core/modules/expensereport/doc");
335 $handle = opendir($dir);
336 if (is_resource($handle)) {
337 while (($file = readdir($handle)) !==
false) {
343 foreach ($filelist as $file) {
344 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
345 if (file_exists($dir.
'/'.$file)) {
346 $name = substr($file, 4,
dol_strlen($file) - 16);
347 $classname = substr($file, 0,
dol_strlen($file) - 12);
349 require_once $dir.
'/'.$file;
350 $module =
new $classname($db);
352 $modulequalified = 1;
353 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
354 $modulequalified = 0;
356 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
357 $modulequalified = 0;
360 if ($modulequalified) {
361 print
'<tr class="oddeven"><td width="100">';
362 print (empty($module->name) ? $name : $module->name);
364 if (method_exists($module,
'info')) {
365 print $module->info($langs);
367 print $module->description;
372 if (in_array($name, $def)) {
373 print
'<td class="center">'.
"\n";
374 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.
newToken().
'&value='.urlencode($name).
'&scan_dir='.urlencode($module->scandir).
'&label='.urlencode($module->name).
'">';
375 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
379 print
'<td class="center">'.
"\n";
380 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>';
385 print
'<td class="center">';
386 if ($conf->global->EXPENSEREPORT_ADDON_PDF ==
"$name") {
387 print
img_picto($langs->trans(
"Default"),
'on');
389 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setdoc&token='.
newToken().
'&value='.$name.
'&scan_dir='.$module->scandir.
'&label='.urlencode($module->name).
'" alt="'.$langs->trans(
"Default").
'">'.
img_picto($langs->trans(
"Disabled"),
'off').
'</a>';
394 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
395 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
396 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
397 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
398 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
399 $htmltooltip .=
'<br>'.$langs->trans(
"PaymentMode").
': '.
yn($module->option_modereg, 1, 1);
400 $htmltooltip .=
'<br>'.$langs->trans(
"PaymentConditions").
': '.
yn($module->option_condreg, 1, 1);
401 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
402 $htmltooltip .=
'<br>'.$langs->trans(
"WatermarkOnDraftOrders").
': '.
yn($module->option_draft_watermark, 1, 1);
403 print
'<td class="center">';
404 print
$form->textwithpicto(
'', $htmltooltip, -1, 0);
408 print
'<td class="center">';
409 if ($module->type ==
'pdf') {
410 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.$name.
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
412 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
436 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
437 print
'<input type="hidden" name="token" value="'.newToken().
'">';
438 print
'<input type="hidden" name="action" value="setoptions">';
441 print
'<table class="noborder centpercent">';
442 print
'<tr class="liste_titre">';
443 print
'<td>'.$langs->trans(
"Parameter").
'</td>';
444 print
'<td class="center" width="60"></td>';
448 $substitutionarray[
'__(AnyTranslationKey)__'] = $langs->trans(
"Translation");
449 $htmltext =
'<i>'.$langs->trans(
"AvailableVariables").
':<br>';
450 foreach ($substitutionarray as $key => $val) {
451 $htmltext .= $key.
'<br>';
455 print
'<tr class="oddeven"><td colspan="2">';
456 print
$form->textwithpicto($langs->trans(
"FreeLegalTextOnExpenseReports"), $langs->trans(
"AddCRIfTooLong").
'<br><br>'.$htmltext, 1,
'help',
'', 0, 2,
'freetexttooltip').
'<br>';
457 $variablename =
'EXPENSEREPORT_FREE_TEXT';
458 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
459 print
'<textarea name="'.$variablename.
'" class="flat" cols="120">'.
getDolGlobalString($variablename).
'</textarea>';
461 include_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
463 print $doleditor->Create();
465 print
'</td></tr>'.
"\n";
469 print
'<tr class="oddeven"><td colspan="2">';
470 print
$form->textwithpicto($langs->trans(
"WatermarkOnDraftExpenseReports"), $htmltext, 1,
'help',
'', 0, 2,
'watermarktooltip').
'<br>';
471 print
'<input class="flat minwidth200" type="text" name="EXPENSEREPORT_DRAFT_WATERMARK" value="'.dol_escape_htmltag(
getDolGlobalString(
'EXPENSEREPORT_DRAFT_WATERMARK')).
'">';
472 print
'</td></tr>'.
"\n";
474 if (!empty($conf->project->enabled)) {
475 print
'<tr class="oddeven"><td>';
476 print $langs->trans(
'ProjectIsRequiredOnExpenseReports');
477 print
'</td><td class="right">';
478 print
$form->selectyesno(
'EXPENSEREPORT_PROJECT_IS_REQUIRED', empty($conf->global->EXPENSEREPORT_PROJECT_IS_REQUIRED) ? 0 : 1, 1);
482 print
'<tr class="oddeven"><td>';
483 print $langs->trans(
'PrefillExpenseReportDatesWithCurrentMonth');
484 print
'</td><td class="right">';
485 print
$form->selectyesno(
'EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH', empty($conf->global->EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH) ? 0 : 1, 1);
488 print
'<tr class="oddeven"><td>';
489 print $langs->trans(
'ForceExpenseReportsLineAmountsIncludingTaxesOnly');
490 print
'</td><td class="right">';
491 print
$form->selectyesno(
'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY', empty($conf->global->EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY) ? 0 : 1, 1);
496 print
$form->buttonsSaveCancel(
"Save",
'');