expensereport.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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@capnetworks.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-2015 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 <http://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. $langs->load("admin");
  35. $langs->load("errors");
  36. $langs->load("trips");
  37. $langs->load('other');
  38. if (! $user->admin) accessforbidden();
  39. $action = GETPOST('action','alpha');
  40. $value = GETPOST('value','alpha');
  41. $label = GETPOST('label','alpha');
  42. $scandir = GETPOST('scandir','alpha');
  43. $type='expensereport';
  44. /*
  45. * Actions
  46. */
  47. if ($action == 'updateMask')
  48. {
  49. $maskconst=GETPOST('maskconst','alpha');
  50. $maskvalue=GETPOST('maskvalue','alpha');
  51. if ($maskconst) $res = dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity);
  52. if (! $res > 0) $error++;
  53. if (! $error)
  54. {
  55. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  56. }
  57. else
  58. {
  59. setEventMessages($langs->trans("Error"), null, 'errors');
  60. }
  61. }
  62. else if ($action == 'specimen') // For fiche inter
  63. {
  64. $modele= GETPOST('module','alpha');
  65. $inter = new ExpenseReport($db);
  66. $inter->initAsSpecimen();
  67. $inter->status = 0; // Force statut draft to show watermark
  68. $inter->fk_statut = 0; // Force statut draft to show watermark
  69. // Search template files
  70. $file=''; $classname=''; $filefound=0;
  71. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  72. foreach($dirmodels as $reldir)
  73. {
  74. $file=dol_buildpath($reldir."core/modules/expensereport/doc/pdf_".$modele.".modules.php",0);
  75. if (file_exists($file))
  76. {
  77. $filefound=1;
  78. $classname = "pdf_".$modele;
  79. break;
  80. }
  81. }
  82. if ($filefound)
  83. {
  84. require_once $file;
  85. $module = new $classname($db);
  86. if ($module->write_file($inter,$langs) > 0)
  87. {
  88. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expensereport&file=SPECIMEN.pdf");
  89. return;
  90. }
  91. else
  92. {
  93. setEventMessages($module->error, $module->errors,'errors');
  94. dol_syslog($module->error, LOG_ERR);
  95. }
  96. }
  97. else
  98. {
  99. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  100. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  101. }
  102. }
  103. // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
  104. if ($action == 'setModuleOptions')
  105. {
  106. $post_size=count($_POST);
  107. $db->begin();
  108. for($i=0;$i < $post_size;$i++)
  109. {
  110. if (array_key_exists('param'.$i,$_POST))
  111. {
  112. $param=GETPOST("param".$i,'alpha');
  113. $value=GETPOST("value".$i,'alpha');
  114. if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
  115. if (! $res > 0) $error++;
  116. }
  117. }
  118. if (! $error)
  119. {
  120. $db->commit();
  121. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  122. }
  123. else
  124. {
  125. $db->rollback();
  126. setEventMessages($langs->trans("Error"), null, 'errors');
  127. }
  128. }
  129. // Activate a model
  130. else if ($action == 'set')
  131. {
  132. $ret = addDocumentModel($value, $type, $label, $scandir);
  133. if ($ret > 0 && empty($conf->global->EXPENSEREPORT_ADDON_PDF))
  134. {
  135. dolibarr_set_const($db, 'EXPENSEREPORT_ADDON_PDF', $value,'chaine',0,'',$conf->entity);
  136. }
  137. }
  138. else if ($action == 'del')
  139. {
  140. $ret = delDocumentModel($value, $type);
  141. if ($ret > 0)
  142. {
  143. if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$value") dolibarr_del_const($db, 'EXPENSEREPORT_ADDON_PDF',$conf->entity);
  144. }
  145. }
  146. // Set default model
  147. else if ($action == 'setdoc')
  148. {
  149. if (dolibarr_set_const($db, "EXPENSEREPORT_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
  150. {
  151. // La constante qui a ete lue en avant du nouveau set
  152. // on passe donc par une variable pour avoir un affichage coherent
  153. $conf->global->EXPENSEREPORT_ADDON_PDF = $value;
  154. }
  155. // On active le modele
  156. $ret = delDocumentModel($value, $type);
  157. if ($ret > 0)
  158. {
  159. $ret = addDocumentModel($value, $type, $label, $scandir);
  160. }
  161. }
  162. else if ($action == 'setmod')
  163. {
  164. // TODO Verifier si module numerotation choisi peut etre active
  165. // par appel methode canBeActivated
  166. dolibarr_set_const($db, "EXPENSEREPORT_ADDON",$value,'chaine',0,'',$conf->entity);
  167. }
  168. else if ($action == 'setoptions')
  169. {
  170. $db->begin();
  171. $freetext= GETPOST('EXPENSEREPORT_FREE_TEXT'); // No alpha here, we want exact string
  172. $res1 = dolibarr_set_const($db, "EXPENSEREPORT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
  173. $draft= GETPOST('EXPENSEREPORT_DRAFT_WATERMARK','alpha');
  174. $res2 = dolibarr_set_const($db, "EXPENSEREPORT_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
  175. if (! $res1 > 0 || ! $res2 > 0) $error++;
  176. if (! $error)
  177. {
  178. $db->commit();
  179. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  180. }
  181. else
  182. {
  183. $db->rollback();
  184. setEventMessages($langs->trans("Error"), null, 'errors');
  185. }
  186. }
  187. /*
  188. * View
  189. */
  190. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  191. llxHeader();
  192. $form=new Form($db);
  193. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  194. print load_fiche_titre($langs->trans("ExpenseReportsSetup"),$linkback,'title_setup');
  195. $head=expensereport_admin_prepare_head();
  196. dol_fiche_head($head, 'expensereport', $langs->trans("ExpenseReports"), -1, 'trip');
  197. // Interventions numbering model
  198. /*
  199. print load_fiche_titre($langs->trans("FicheinterNumberingModules"),'','');
  200. print '<table class="noborder" width="100%">';
  201. print '<tr class="liste_titre">';
  202. print '<td width="100">'.$langs->trans("Name").'</td>';
  203. print '<td>'.$langs->trans("Description").'</td>';
  204. print '<td>'.$langs->trans("Example").'</td>';
  205. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  206. print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  207. print "</tr>\n";
  208. clearstatcache();
  209. foreach ($dirmodels as $reldir)
  210. {
  211. $dir = dol_buildpath($reldir."core/modules/fichinter/");
  212. if (is_dir($dir))
  213. {
  214. $handle = opendir($dir);
  215. if (is_resource($handle))
  216. {
  217. $var=true;
  218. while (($file = readdir($handle))!==false)
  219. {
  220. if (preg_match('/^(mod_.*)\.php$/i',$file,$reg))
  221. {
  222. $file = $reg[1];
  223. $classname = substr($file,4);
  224. require_once $dir.$file.'.php';
  225. $module = new $file;
  226. if ($module->isEnabled())
  227. {
  228. // Show modules according to features level
  229. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  230. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  231. print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
  232. print $module->info();
  233. print '</td>';
  234. // Show example of numbering model
  235. print '<td class="nowrap">';
  236. $tmp=$module->getExample();
  237. if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
  238. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  239. else print $tmp;
  240. print '</td>'."\n";
  241. print '<td align="center">';
  242. if ($conf->global->FICHEINTER_ADDON == $classname)
  243. {
  244. print img_picto($langs->trans("Activated"),'switch_on');
  245. }
  246. else
  247. {
  248. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$classname.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  249. }
  250. print '</td>';
  251. $ficheinter=new Fichinter($db);
  252. $ficheinter->initAsSpecimen();
  253. // Info
  254. $htmltooltip='';
  255. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  256. $nextval=$module->getNextValue($mysoc,$ficheinter);
  257. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  258. $htmltooltip.=''.$langs->trans("NextValue").': ';
  259. if ($nextval) {
  260. if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
  261. $nextval = $langs->trans($nextval);
  262. $htmltooltip.=$nextval.'<br>';
  263. } else {
  264. $htmltooltip.=$langs->trans($module->error).'<br>';
  265. }
  266. }
  267. print '<td align="center">';
  268. print $form->textwithpicto('',$htmltooltip,1,0);
  269. print '</td>';
  270. print '</tr>';
  271. }
  272. }
  273. }
  274. closedir($handle);
  275. }
  276. }
  277. }
  278. print '</table><br>';
  279. */
  280. /*
  281. * Documents models for Interventions
  282. */
  283. print load_fiche_titre($langs->trans("TemplatePDFExpenseReports"), '', '');
  284. // Defini tableau def des modeles
  285. $type='expensereport';
  286. $def = array();
  287. $sql = "SELECT nom";
  288. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  289. $sql.= " WHERE type = '".$type."'";
  290. $sql.= " AND entity = ".$conf->entity;
  291. $resql=$db->query($sql);
  292. if ($resql)
  293. {
  294. $i = 0;
  295. $num_rows=$db->num_rows($resql);
  296. while ($i < $num_rows)
  297. {
  298. $array = $db->fetch_array($resql);
  299. array_push($def, $array[0]);
  300. $i++;
  301. }
  302. }
  303. else
  304. {
  305. dol_print_error($db);
  306. }
  307. print '<table class="noborder" width="100%">';
  308. print '<tr class="liste_titre">';
  309. print '<td>'.$langs->trans("Name").'</td>';
  310. print '<td>'.$langs->trans("Description").'</td>';
  311. print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
  312. print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
  313. print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  314. print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
  315. print "</tr>\n";
  316. clearstatcache();
  317. $var=true;
  318. foreach ($dirmodels as $reldir)
  319. {
  320. $dir = dol_buildpath($reldir."core/modules/expensereport/doc");
  321. if (is_dir($dir))
  322. {
  323. $handle=opendir($dir);
  324. if (is_resource($handle))
  325. {
  326. while (($file = readdir($handle))!==false)
  327. {
  328. $filelist[]=$file;
  329. }
  330. closedir($handle);
  331. arsort($filelist);
  332. foreach($filelist as $file)
  333. {
  334. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  335. {
  336. if (file_exists($dir.'/'.$file))
  337. {
  338. $name = substr($file, 4, dol_strlen($file) -16);
  339. $classname = substr($file, 0, dol_strlen($file) -12);
  340. require_once $dir.'/'.$file;
  341. $module = new $classname($db);
  342. $modulequalified=1;
  343. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
  344. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
  345. if ($modulequalified)
  346. {
  347. print '<tr class="oddeven"><td width="100">';
  348. print (empty($module->name)?$name:$module->name);
  349. print "</td><td>\n";
  350. if (method_exists($module,'info')) print $module->info($langs);
  351. else print $module->description;
  352. print '</td>';
  353. // Active
  354. if (in_array($name, $def))
  355. {
  356. print "<td align=\"center\">\n";
  357. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  358. print img_picto($langs->trans("Enabled"),'switch_on');
  359. print '</a>';
  360. print "</td>";
  361. }
  362. else
  363. {
  364. print "<td align=\"center\">\n";
  365. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  366. print "</td>";
  367. }
  368. // Default
  369. print "<td align=\"center\">";
  370. if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$name")
  371. {
  372. print img_picto($langs->trans("Default"),'on');
  373. }
  374. else
  375. {
  376. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  377. }
  378. print '</td>';
  379. // Info
  380. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  381. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  382. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  383. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  384. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  385. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  386. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  387. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  388. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  389. print '<td align="center">';
  390. print $form->textwithpicto('',$htmltooltip,-1,0);
  391. print '</td>';
  392. // Preview
  393. print '<td align="center">';
  394. if ($module->type == 'pdf')
  395. {
  396. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'intervention').'</a>';
  397. }
  398. else
  399. {
  400. print img_object($langs->trans("PreviewNotAvailable"),'generic');
  401. }
  402. print '</td>';
  403. print '</tr>';
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. }
  411. print '</table>';
  412. print '<br>';
  413. /*
  414. * Other options
  415. */
  416. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  417. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  418. print '<input type="hidden" name="action" value="setoptions">';
  419. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  420. print '<table class="noborder" width="100%">';
  421. print '<tr class="liste_titre">';
  422. print '<td>'.$langs->trans("Parameter").'</td>';
  423. print '<td align="center" width="60"></td>';
  424. print "</tr>\n";
  425. $var=true;
  426. $substitutionarray=pdf_getSubstitutionArray($langs);
  427. $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
  428. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  429. foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
  430. $htmltext.='</i>';
  431. $var=! $var;
  432. print '<tr class="oddeven"><td colspan="2">';
  433. print $form->textwithpicto($langs->trans("FreeLegalTextOnExpenseReports"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext).'<br>';
  434. $variablename='EXPENSEREPORT_FREE_TEXT';
  435. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
  436. {
  437. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
  438. }
  439. else
  440. {
  441. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  442. $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_details');
  443. print $doleditor->Create();
  444. }
  445. print '</td></tr>'."\n";
  446. //Use draft Watermark
  447. print '<tr class="oddeven"><td colspan="2">';
  448. print $form->textwithpicto($langs->trans("WatermarkOnDraftExpenseReports"), $htmltext).'<br>';
  449. print '<input size="50" class="flat" type="text" name="EXPENSEREPORT_DRAFT_WATERMARK" value="'.$conf->global->EXPENSEREPORT_DRAFT_WATERMARK.'">';
  450. print '</td></tr>'."\n";
  451. print '</table>';
  452. print '<div class="center">';
  453. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  454. print '</div>';
  455. print '</form>';
  456. dol_fiche_end();
  457. llxFooter();
  458. $db->close();