fichinter.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 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-2011 Regis Houssin <regis@dolibarr.fr>
  7. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/admin/fichinter.php
  24. * \ingroup fichinter
  25. * \brief Setup page of module Interventions
  26. */
  27. require("../main.inc.php");
  28. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php');
  30. $langs->load("admin");
  31. $langs->load("bills");
  32. $langs->load("other");
  33. $langs->load("interventions");
  34. if (!$user->admin)
  35. accessforbidden();
  36. /*
  37. * Actions
  38. */
  39. if ($_POST["action"] == 'updateMask')
  40. {
  41. $maskconst=$_POST['maskconst'];
  42. $maskvalue=$_POST['maskvalue'];
  43. if ($maskconst) dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity);
  44. }
  45. if ($_POST["action"] == 'set_FICHINTER_FREE_TEXT')
  46. {
  47. dolibarr_set_const($db, "FICHINTER_FREE_TEXT",$_POST["FICHINTER_FREE_TEXT"],'chaine',0,'',$conf->entity);
  48. }
  49. if ($_POST["action"] == 'set_FICHINTER_DRAFT_WATERMARK')
  50. {
  51. dolibarr_set_const($db, "FICHINTER_DRAFT_WATERMARK",trim($_POST["FICHINTER_DRAFT_WATERMARK"]),'chaine',0,'',$conf->entity);
  52. }
  53. if ($_GET["action"] == 'specimen')
  54. {
  55. $modele=$_GET["module"];
  56. $inter = new Fichinter($db);
  57. $inter->initAsSpecimen();
  58. // Charge le modele
  59. $dir = DOL_DOCUMENT_ROOT . "/includes/modules/fichinter/";
  60. $file = "pdf_".$modele.".modules.php";
  61. if (file_exists($dir.$file))
  62. {
  63. $classname = "pdf_".$modele;
  64. require_once($dir.$file);
  65. $obj = new $classname($db);
  66. if ($obj->write_file($inter,$langs) > 0)
  67. {
  68. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=ficheinter&file=SPECIMEN.pdf");
  69. return;
  70. }
  71. else
  72. {
  73. $mesg='<div class="error">'.$obj->error.'</div>';
  74. dol_syslog($obj->error, LOG_ERR);
  75. }
  76. }
  77. else
  78. {
  79. $mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>';
  80. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  81. }
  82. }
  83. if ($_GET["action"] == 'set')
  84. {
  85. $type='ficheinter';
  86. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  87. $sql.= " VALUES ('".$db->escape($_GET["value"])."','".$type."',".$conf->entity.", ";
  88. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  89. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  90. $sql.= ")";
  91. if ($db->query($sql))
  92. {
  93. }
  94. }
  95. if ($_GET["action"] == 'del')
  96. {
  97. $type='ficheinter';
  98. $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  99. $sql.= " WHERE nom = '".$_GET["value"]."'";
  100. $sql.= " AND type = '".$type."'";
  101. $sql.= " AND entity = ".$conf->entity;
  102. if ($db->query($sql))
  103. {
  104. }
  105. }
  106. if ($_GET["action"] == 'setdoc')
  107. {
  108. $db->begin();
  109. if (dolibarr_set_const($db, "FICHEINTER_ADDON_PDF",$_GET["value"],'chaine',0,'',$conf->entity))
  110. {
  111. // La constante qui a ete lue en avant du nouveau set
  112. // on passe donc par une variable pour avoir un affichage coherent
  113. $conf->global->FICHEINTER_ADDON_PDF = $_GET["value"];
  114. }
  115. // On active le modele
  116. $type='ficheinter';
  117. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  118. $sql_del.= " WHERE nom = '".$db->escape($_GET["value"])."'";
  119. $sql_del.= " AND type = '".$type."'";
  120. $sql_del.= " AND entity = ".$conf->entity;
  121. dol_syslog("fichinter: sql_del=".$sql_del);
  122. $result1=$db->query($sql_del);
  123. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  124. $sql.= " VALUES ('".$db->escape($_GET["value"])."', '".$type."', ".$conf->entity.", ";
  125. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  126. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  127. $sql.= ")";
  128. dol_syslog("fichinter: sql_del=".$sql_del);
  129. $result2=$db->query($sql);
  130. if ($result1 && $result2)
  131. {
  132. $db->commit();
  133. }
  134. else
  135. {
  136. $db->rollback();
  137. }
  138. }
  139. if ($_GET["action"] == 'setmod')
  140. {
  141. // TODO Verifier si module numerotation choisi peut etre active
  142. // par appel methode canBeActivated
  143. dolibarr_set_const($db, "FICHEINTER_ADDON",$_GET["value"],'chaine',0,'',$conf->entity);
  144. }
  145. // defini les constantes du modele arctic
  146. if ($_POST["action"] == 'updateMatrice') dolibarr_set_const($db, "FICHEINTER_NUM_MATRICE",$_POST["matrice"],'chaine',0,'',$conf->entity);
  147. if ($_POST["action"] == 'updatePrefix') dolibarr_set_const($db, "FICHEINTER_NUM_PREFIX",$_POST["prefix"],'chaine',0,'',$conf->entity);
  148. if ($_POST["action"] == 'setOffset') dolibarr_set_const($db, "FICHEINTER_NUM_DELTA",$_POST["offset"],'chaine',0,'',$conf->entity);
  149. if ($_POST["action"] == 'setNumRestart') dolibarr_set_const($db, "FICHEINTER_NUM_RESTART_BEGIN_YEAR",$_POST["numrestart"],'chaine',0,'',$conf->entity);
  150. /*
  151. * Affichage page
  152. */
  153. llxHeader();
  154. $html=new Form($db);
  155. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  156. print_fiche_titre($langs->trans("InterventionsSetup"),$linkback,'setup');
  157. print "<br>";
  158. print_titre($langs->trans("FicheinterNumberingModules"));
  159. print '<table class="noborder" width="100%">';
  160. print '<tr class="liste_titre">';
  161. print '<td width="100">'.$langs->trans("Name").'</td>';
  162. print '<td>'.$langs->trans("Description").'</td>';
  163. print '<td>'.$langs->trans("Example").'</td>';
  164. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  165. print '<td align="center" width="16">'.$langs->trans("Infos").'</td>';
  166. print "</tr>\n";
  167. clearstatcache();
  168. foreach ($conf->file->dol_document_root as $dirroot)
  169. {
  170. $dir = $dirroot . "/includes/modules/fichinter/";
  171. if (is_dir($dir))
  172. {
  173. $handle = opendir($dir);
  174. if (is_resource($handle))
  175. {
  176. $var=true;
  177. while (($file = readdir($handle))!==false)
  178. {
  179. if (preg_match('/^(mod_.*)\.php$/i',$file,$reg))
  180. {
  181. $file = $reg[1];
  182. $classname = substr($file,4);
  183. require_once($dir.$file.".php");
  184. $module = new $file;
  185. // Show modules according to features level
  186. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  187. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  188. if ($module->isEnabled())
  189. {
  190. $var=!$var;
  191. print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
  192. print $module->info();
  193. print '</td>';
  194. // Show example of numbering module
  195. print '<td nowrap="nowrap">';
  196. $tmp=$module->getExample();
  197. if (preg_match('/^Error/',$tmp)) print $langs->trans($tmp);
  198. else print $tmp;
  199. print '</td>'."\n";
  200. print '<td align="center">';
  201. if ($conf->global->FICHEINTER_ADDON == $classname)
  202. {
  203. print img_picto($langs->trans("Activated"),'on');
  204. }
  205. else
  206. {
  207. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$classname.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  208. }
  209. print '</td>';
  210. $ficheinter=new Fichinter($db);
  211. $ficheinter->initAsSpecimen();
  212. // Info
  213. $htmltooltip='';
  214. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  215. $nextval=$module->getNextValue($mysoc,$ficheinter);
  216. if ($nextval != $langs->trans("NotAvailable"))
  217. {
  218. $htmltooltip.=''.$langs->trans("NextValue").': '.$nextval;
  219. }
  220. print '<td align="center">';
  221. print $html->textwithpicto('',$htmltooltip,1,0);
  222. print '</td>';
  223. print '</tr>';
  224. }
  225. }
  226. }
  227. closedir($handle);
  228. }
  229. }
  230. }
  231. print '</table><br>';
  232. print_titre($langs->trans("TemplatePDFInterventions"));
  233. // Defini tableau def des modeles
  234. $type='ficheinter';
  235. $def = array();
  236. $sql = "SELECT nom";
  237. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  238. $sql.= " WHERE type = '".$type."'";
  239. $sql.= " AND entity = ".$conf->entity;
  240. $resql=$db->query($sql);
  241. if ($resql)
  242. {
  243. $i = 0;
  244. $num_rows=$db->num_rows($resql);
  245. while ($i < $num_rows)
  246. {
  247. $array = $db->fetch_array($resql);
  248. array_push($def, $array[0]);
  249. $i++;
  250. }
  251. }
  252. else
  253. {
  254. dol_print_error($db);
  255. }
  256. print '<table class="noborder" width="100%">';
  257. print '<tr class="liste_titre">';
  258. print '<td>'.$langs->trans("Name").'</td>';
  259. print '<td>'.$langs->trans("Description").'</td>';
  260. print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
  261. print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
  262. print '<td align="center" width="32" colspan="2">'.$langs->trans("Infos").'</td>';
  263. print "</tr>\n";
  264. clearstatcache();
  265. $var=true;
  266. foreach ($conf->file->dol_document_root as $dirroot)
  267. {
  268. $dir = $dirroot . "/includes/modules/fichinter/";
  269. if (is_dir($dir))
  270. {
  271. $handle=opendir($dir);
  272. if (is_resource($handle))
  273. {
  274. while (($file = readdir($handle))!==false)
  275. {
  276. if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,4) == 'pdf_')
  277. {
  278. $name = substr($file, 4, dol_strlen($file) -16);
  279. $classname = substr($file, 0, dol_strlen($file) -12);
  280. $var=!$var;
  281. print '<tr '.$bc[$var].'><td>';
  282. echo "$name";
  283. print "</td><td>\n";
  284. require_once($dir.$file);
  285. $module = new $classname();
  286. print $module->description;
  287. print '</td>';
  288. // Active
  289. if (in_array($name, $def))
  290. {
  291. print "<td align=\"center\">\n";
  292. if ($conf->global->FICHEINTER_ADDON_PDF != "$name")
  293. {
  294. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  295. print img_picto($langs->trans("Enabled"),'on');
  296. print '</a>';
  297. }
  298. else
  299. {
  300. print img_picto($langs->trans("Enabled"),'on');
  301. }
  302. print "</td>";
  303. }
  304. else
  305. {
  306. print "<td align=\"center\">\n";
  307. 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"),'off').'</a>';
  308. print "</td>";
  309. }
  310. // Defaut
  311. print "<td align=\"center\">";
  312. if ($conf->global->FICHEINTER_ADDON_PDF == "$name")
  313. {
  314. print img_picto($langs->trans("Default"),'on');
  315. }
  316. else
  317. {
  318. 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>';
  319. }
  320. print '</td>';
  321. // Info
  322. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  323. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  324. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  325. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  326. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  327. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  328. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  329. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  330. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  331. print '<td align="center">';
  332. print $html->textwithpicto('',$htmltooltip,1,0);
  333. print '</td>';
  334. print '<td align="center">';
  335. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'intervention').'</a>';
  336. print '</td>';
  337. print '</tr>';
  338. }
  339. }
  340. closedir($handle);
  341. }
  342. }
  343. }
  344. print '</table>';
  345. //Autres Options
  346. print "<br>";
  347. print_titre($langs->trans("OtherOptions"));
  348. print '<table class="noborder" width="100%">';
  349. print '<tr class="liste_titre">';
  350. print '<td>'.$langs->trans("Parameter").'</td>';
  351. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  352. print "<td>&nbsp;</td>\n";
  353. print "</tr>\n";
  354. $var=true;
  355. $var=! $var;
  356. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  357. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  358. print '<input type="hidden" name="action" value="set_FICHINTER_FREE_TEXT">';
  359. print '<tr '.$bc[$var].'><td colspan="2">';
  360. print $langs->trans("FreeLegalTextOnInterventions").' ('.$langs->trans("AddCRIfTooLong").')<br>';
  361. print '<textarea name="FICHINTER_FREE_TEXT" class="flat" cols="120">'.$conf->global->FICHINTER_FREE_TEXT.'</textarea>';
  362. print '</td><td align="right">';
  363. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  364. print "</td></tr>\n";
  365. print '</form>';
  366. //Use draft Watermark
  367. $var=!$var;
  368. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  369. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  370. print "<input type=\"hidden\" name=\"action\" value=\"set_FICHINTER_DRAFT_WATERMARK\">";
  371. print '<tr '.$bc[$var].'><td colspan="2">';
  372. print $langs->trans("WatermarkOnDraftInterventionCards").'<br>';
  373. print '<input size="50" class="flat" type="text" name="FICHINTER_DRAFT_WATERMARK" value="'.$conf->global->FICHINTER_DRAFT_WATERMARK.'">';
  374. print '</td><td align="right">';
  375. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  376. print "</td></tr>\n";
  377. print '</form>';
  378. print '</table>';
  379. print '<br>';
  380. $db->close();
  381. llxFooter();
  382. ?>