PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/admin/fichinter.php

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