expensereport.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  5. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  6. * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  8. * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/admin/expensereport.php
  26. * \ingroup expensereport
  27. * \brief Setup page of module ExpenseReport
  28. */
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('admin', 'errors', 'trips', 'other'));
  36. if (!$user->admin) accessforbidden();
  37. $action = GETPOST('action', 'alpha');
  38. $value = GETPOST('value', 'alpha');
  39. $label = GETPOST('label', 'alpha');
  40. $scandir = GETPOST('scan_dir', 'alpha');
  41. $type = 'expensereport';
  42. /*
  43. * Actions
  44. */
  45. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  46. if ($action == 'updateMask')
  47. {
  48. $maskconst = GETPOST('maskconst', 'alpha');
  49. $maskvalue = GETPOST('maskvalue', 'alpha');
  50. if ($maskconst) $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
  51. if (!$res > 0) $error++;
  52. if (!$error)
  53. {
  54. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  55. }
  56. else
  57. {
  58. setEventMessages($langs->trans("Error"), null, 'errors');
  59. }
  60. }
  61. elseif ($action == 'specimen') // For fiche inter
  62. {
  63. $modele = GETPOST('module', 'alpha');
  64. $inter = new ExpenseReport($db);
  65. $inter->initAsSpecimen();
  66. $inter->status = 0; // Force statut draft to show watermark
  67. $inter->fk_statut = 0; // Force statut draft to show watermark
  68. // Search template files
  69. $file = ''; $classname = ''; $filefound = 0;
  70. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  71. foreach ($dirmodels as $reldir)
  72. {
  73. $file = dol_buildpath($reldir."core/modules/expensereport/doc/pdf_".$modele.".modules.php", 0);
  74. if (file_exists($file))
  75. {
  76. $filefound = 1;
  77. $classname = "pdf_".$modele;
  78. break;
  79. }
  80. }
  81. if ($filefound)
  82. {
  83. require_once $file;
  84. $module = new $classname($db);
  85. if ($module->write_file($inter, $langs) > 0)
  86. {
  87. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expensereport&file=SPECIMEN.pdf");
  88. return;
  89. }
  90. else
  91. {
  92. setEventMessages($module->error, $module->errors, 'errors');
  93. dol_syslog($module->error, LOG_ERR);
  94. }
  95. }
  96. else
  97. {
  98. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  99. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  100. }
  101. }
  102. // Activate a model
  103. elseif ($action == 'set')
  104. {
  105. $ret = addDocumentModel($value, $type, $label, $scandir);
  106. if ($ret > 0 && empty($conf->global->EXPENSEREPORT_ADDON_PDF))
  107. {
  108. dolibarr_set_const($db, 'EXPENSEREPORT_ADDON_PDF', $value, 'chaine', 0, '', $conf->entity);
  109. }
  110. }
  111. elseif ($action == 'del')
  112. {
  113. $ret = delDocumentModel($value, $type);
  114. if ($ret > 0)
  115. {
  116. if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$value") dolibarr_del_const($db, 'EXPENSEREPORT_ADDON_PDF', $conf->entity);
  117. }
  118. }
  119. // Set default model
  120. elseif ($action == 'setdoc')
  121. {
  122. if (dolibarr_set_const($db, "EXPENSEREPORT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
  123. {
  124. // La constante qui a ete lue en avant du nouveau set
  125. // on passe donc par une variable pour avoir un affichage coherent
  126. $conf->global->EXPENSEREPORT_ADDON_PDF = $value;
  127. }
  128. // On active le modele
  129. $ret = delDocumentModel($value, $type);
  130. if ($ret > 0)
  131. {
  132. $ret = addDocumentModel($value, $type, $label, $scandir);
  133. }
  134. }
  135. elseif ($action == 'setmod')
  136. {
  137. // TODO Verifier si module numerotation choisi peut etre active
  138. // par appel methode canBeActivated
  139. dolibarr_set_const($db, "EXPENSEREPORT_ADDON", $value, 'chaine', 0, '', $conf->entity);
  140. }
  141. elseif ($action == 'setoptions')
  142. {
  143. $db->begin();
  144. $freetext = GETPOST('EXPENSEREPORT_FREE_TEXT', 'none'); // No alpha here, we want exact string
  145. $res1 = dolibarr_set_const($db, "EXPENSEREPORT_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
  146. $draft = GETPOST('EXPENSEREPORT_DRAFT_WATERMARK', 'alpha');
  147. $res2 = dolibarr_set_const($db, "EXPENSEREPORT_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
  148. if (!$res1 > 0 || !$res2 > 0) $error++;
  149. if (!$error)
  150. {
  151. $db->commit();
  152. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  153. }
  154. else
  155. {
  156. $db->rollback();
  157. setEventMessages($langs->trans("Error"), null, 'errors');
  158. }
  159. }
  160. /*
  161. * View
  162. */
  163. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  164. llxHeader('', $langs->trans("ExpenseReportsSetup"));
  165. $form = new Form($db);
  166. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  167. print load_fiche_titre($langs->trans("ExpenseReportsSetup"), $linkback, 'title_setup');
  168. $head = expensereport_admin_prepare_head();
  169. dol_fiche_head($head, 'expensereport', $langs->trans("ExpenseReports"), -1, 'trip');
  170. /*
  171. * Expense report numbering model
  172. */
  173. print load_fiche_titre($langs->trans("ExpenseReportNumberingModules"), '', '');
  174. print '<table class="noborder centpercent">';
  175. print '<tr class="liste_titre">';
  176. print '<td>'.$langs->trans("Name").'</td>';
  177. print '<td>'.$langs->trans("Description").'</td>';
  178. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  179. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  180. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  181. print '</tr>'."\n";
  182. clearstatcache();
  183. foreach ($dirmodels as $reldir)
  184. {
  185. $dir = dol_buildpath($reldir."core/modules/expensereport/");
  186. if (is_dir($dir))
  187. {
  188. $handle = opendir($dir);
  189. if (is_resource($handle))
  190. {
  191. while (($file = readdir($handle)) !== false)
  192. {
  193. if (substr($file, 0, 18) == 'mod_expensereport_' && substr($file, dol_strlen($file) - 3, 3) == 'php')
  194. {
  195. $file = substr($file, 0, dol_strlen($file) - 4);
  196. require_once $dir.$file.'.php';
  197. $module = new $file($db);
  198. // Show modules according to features level
  199. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  200. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  201. if ($module->isEnabled())
  202. {
  203. print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
  204. print $module->info();
  205. print '</td>';
  206. // Show example of numbering model
  207. print '<td class="nowrap">';
  208. $tmp = $module->getExample();
  209. if (preg_match('/^Error/', $tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
  210. elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
  211. else print $tmp;
  212. print '</td>'."\n";
  213. print '<td class="center">';
  214. if ($conf->global->EXPENSEREPORT_ADDON == $file)
  215. {
  216. print img_picto($langs->trans("Activated"), 'switch_on');
  217. }
  218. else
  219. {
  220. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
  221. print img_picto($langs->trans("Disabled"), 'switch_off');
  222. print '</a>';
  223. }
  224. print '</td>';
  225. $exp = new ExpenseReport($db);
  226. $exp->initAsSpecimen();
  227. // Info
  228. $htmltooltip = '';
  229. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  230. $nextval = $module->getNextValue($exp);
  231. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  232. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  233. if ($nextval) {
  234. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
  235. $nextval = $langs->trans($nextval);
  236. $htmltooltip .= $nextval.'<br>';
  237. } else {
  238. $htmltooltip .= $langs->trans($module->error).'<br>';
  239. }
  240. }
  241. print '<td class="center">';
  242. print $form->textwithpicto('', $htmltooltip, 1, 0);
  243. print '</td>';
  244. print "</tr>\n";
  245. }
  246. }
  247. }
  248. closedir($handle);
  249. }
  250. }
  251. }
  252. print "</table><br>\n";
  253. /*
  254. * Documents models for Interventions
  255. */
  256. print load_fiche_titre($langs->trans("TemplatePDFExpenseReports"), '', '');
  257. // Defini tableau def des modeles
  258. $type = 'expensereport';
  259. $def = array();
  260. $sql = "SELECT nom";
  261. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  262. $sql .= " WHERE type = '".$type."'";
  263. $sql .= " AND entity = ".$conf->entity;
  264. $resql = $db->query($sql);
  265. if ($resql)
  266. {
  267. $i = 0;
  268. $num_rows = $db->num_rows($resql);
  269. while ($i < $num_rows)
  270. {
  271. $array = $db->fetch_array($resql);
  272. array_push($def, $array[0]);
  273. $i++;
  274. }
  275. }
  276. else
  277. {
  278. dol_print_error($db);
  279. }
  280. print '<table class="noborder centpercent">';
  281. print '<tr class="liste_titre">';
  282. print '<td>'.$langs->trans("Name").'</td>';
  283. print '<td>'.$langs->trans("Description").'</td>';
  284. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  285. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  286. print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  287. print '<td class="center" width="80">'.$langs->trans("Preview").'</td>';
  288. print "</tr>\n";
  289. clearstatcache();
  290. foreach ($dirmodels as $reldir)
  291. {
  292. $dir = dol_buildpath($reldir."core/modules/expensereport/doc");
  293. if (is_dir($dir))
  294. {
  295. $handle = opendir($dir);
  296. if (is_resource($handle))
  297. {
  298. while (($file = readdir($handle)) !== false)
  299. {
  300. $filelist[] = $file;
  301. }
  302. closedir($handle);
  303. arsort($filelist);
  304. foreach ($filelist as $file)
  305. {
  306. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
  307. {
  308. if (file_exists($dir.'/'.$file))
  309. {
  310. $name = substr($file, 4, dol_strlen($file) -16);
  311. $classname = substr($file, 0, dol_strlen($file) -12);
  312. require_once $dir.'/'.$file;
  313. $module = new $classname($db);
  314. $modulequalified=1;
  315. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
  316. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
  317. if ($modulequalified)
  318. {
  319. print '<tr class="oddeven"><td width="100">';
  320. print (empty($module->name)?$name:$module->name);
  321. print "</td><td>\n";
  322. if (method_exists($module, 'info')) print $module->info($langs);
  323. else print $module->description;
  324. print '</td>';
  325. // Active
  326. if (in_array($name, $def))
  327. {
  328. print '<td class="center">'."\n";
  329. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  330. print img_picto($langs->trans("Enabled"), 'switch_on');
  331. print '</a>';
  332. print "</td>";
  333. }
  334. else
  335. {
  336. print '<td class="center">'."\n";
  337. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  338. print "</td>";
  339. }
  340. // Default
  341. print '<td class="center">';
  342. if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$name")
  343. {
  344. print img_picto($langs->trans("Default"), 'on');
  345. }
  346. else
  347. {
  348. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  349. }
  350. print '</td>';
  351. // Info
  352. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  353. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  354. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  355. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  356. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  357. $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
  358. $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
  359. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  360. $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
  361. print '<td class="center">';
  362. print $form->textwithpicto('', $htmltooltip, -1, 0);
  363. print '</td>';
  364. // Preview
  365. print '<td class="center">';
  366. if ($module->type == 'pdf')
  367. {
  368. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'intervention').'</a>';
  369. }
  370. else
  371. {
  372. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  373. }
  374. print '</td>';
  375. print '</tr>';
  376. }
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. print '</table>';
  384. print '<br>';
  385. /*
  386. * Other options
  387. */
  388. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  389. print '<input type="hidden" name="token" value="'.newToken().'">';
  390. print '<input type="hidden" name="action" value="setoptions">';
  391. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  392. print '<table class="noborder centpercent">';
  393. print '<tr class="liste_titre">';
  394. print '<td>'.$langs->trans("Parameter").'</td>';
  395. print '<td class="center" width="60"></td>';
  396. print "</tr>\n";
  397. $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
  398. $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
  399. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  400. foreach ($substitutionarray as $key => $val) $htmltext .= $key.'<br>';
  401. $htmltext .= '</i>';
  402. print '<tr class="oddeven"><td colspan="2">';
  403. print $form->textwithpicto($langs->trans("FreeLegalTextOnExpenseReports"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
  404. $variablename = 'EXPENSEREPORT_FREE_TEXT';
  405. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
  406. {
  407. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
  408. }
  409. else
  410. {
  411. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  412. $doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes');
  413. print $doleditor->Create();
  414. }
  415. print '</td></tr>'."\n";
  416. // Use draft Watermark
  417. print '<tr class="oddeven"><td colspan="2">';
  418. print $form->textwithpicto($langs->trans("WatermarkOnDraftExpenseReports"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
  419. print '<input size="50" class="flat" type="text" name="EXPENSEREPORT_DRAFT_WATERMARK" value="'.$conf->global->EXPENSEREPORT_DRAFT_WATERMARK.'">';
  420. print '</td></tr>'."\n";
  421. print '</table>';
  422. print '<div class="center">';
  423. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  424. print '</div>';
  425. print '</form>';
  426. dol_fiche_end();
  427. // End of page
  428. llxFooter();
  429. $db->close();