expensereport.php 17 KB

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