fichinter.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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-2012 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-2013 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/fichinter.php
  26. * \ingroup fichinter
  27. * \brief Setup page of module Interventions
  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/fichinter.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  33. $langs->load("admin");
  34. $langs->load("errors");
  35. $langs->load("interventions");
  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='ficheinter';
  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. setEventMessage($langs->trans("SetupSaved"));
  55. }
  56. else
  57. {
  58. setEventMessage($langs->trans("Error"),'errors');
  59. }
  60. }
  61. else if ($action == 'specimen') // For fiche inter
  62. {
  63. $modele= GETPOST('module','alpha');
  64. $inter = new Fichinter($db);
  65. $inter->initAsSpecimen();
  66. // Search template files
  67. $file=''; $classname=''; $filefound=0;
  68. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  69. foreach($dirmodels as $reldir)
  70. {
  71. $file=dol_buildpath($reldir."core/modules/fichinter/doc/pdf_".$modele.".modules.php",0);
  72. if (file_exists($file))
  73. {
  74. $filefound=1;
  75. $classname = "pdf_".$modele;
  76. break;
  77. }
  78. }
  79. if ($filefound)
  80. {
  81. require_once $file;
  82. $module = new $classname($db);
  83. if ($module->write_file($inter,$langs) > 0)
  84. {
  85. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=ficheinter&file=SPECIMEN.pdf");
  86. return;
  87. }
  88. else
  89. {
  90. setEventMessage($obj->error,'errors');
  91. dol_syslog($obj->error, LOG_ERR);
  92. }
  93. }
  94. else
  95. {
  96. setEventMessage($langs->trans("ErrorModuleNotFound"),'errors');
  97. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  98. }
  99. }
  100. // Activate a model
  101. else if ($action == 'set')
  102. {
  103. $ret = addDocumentModel($value, $type, $label, $scandir);
  104. }
  105. else if ($action == 'del')
  106. {
  107. $ret = delDocumentModel($value, $type);
  108. if ($ret > 0)
  109. {
  110. if ($conf->global->FICHEINTER_ADDON_PDF == "$value") dolibarr_del_const($db, 'FICHEINTER_ADDON_PDF',$conf->entity);
  111. }
  112. }
  113. // Set default model
  114. else if ($action == 'setdoc')
  115. {
  116. if (dolibarr_set_const($db, "FICHEINTER_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
  117. {
  118. // La constante qui a ete lue en avant du nouveau set
  119. // on passe donc par une variable pour avoir un affichage coherent
  120. $conf->global->FICHEINTER_ADDON_PDF = $value;
  121. }
  122. // On active le modele
  123. $ret = delDocumentModel($value, $type);
  124. if ($ret > 0)
  125. {
  126. $ret = addDocumentModel($value, $type, $label, $scandir);
  127. }
  128. }
  129. else if ($action == 'setmod')
  130. {
  131. // TODO Verifier si module numerotation choisi peut etre active
  132. // par appel methode canBeActivated
  133. dolibarr_set_const($db, "FICHEINTER_ADDON",$value,'chaine',0,'',$conf->entity);
  134. }
  135. else if ($action == 'set_FICHINTER_FREE_TEXT')
  136. {
  137. $freetext= GETPOST('FICHINTER_FREE_TEXT','alpha');
  138. $res = dolibarr_set_const($db, "FICHINTER_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
  139. if (! $res > 0) $error++;
  140. if (! $error)
  141. {
  142. setEventMessage($langs->trans("SetupSaved"));
  143. }
  144. else
  145. {
  146. setEventMessage($langs->trans("Error"),'errors');
  147. }
  148. }
  149. else if ($action == 'set_FICHINTER_DRAFT_WATERMARK')
  150. {
  151. $draft= GETPOST('FICHINTER_DRAFT_WATERMARK','alpha');
  152. $res = dolibarr_set_const($db, "FICHINTER_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
  153. if (! $res > 0) $error++;
  154. if (! $error)
  155. {
  156. setEventMessage($langs->trans("SetupSaved"));
  157. }
  158. else
  159. {
  160. setEventMessage($langs->trans("Error"),'errors');
  161. }
  162. }
  163. elseif ($action == 'set_FICHINTER_PRINT_PRODUCTS')
  164. {
  165. $val = GETPOST('FICHINTER_PRINT_PRODUCTS','alpha');
  166. $res = dolibarr_set_const($db, "FICHINTER_PRINT_PRODUCTS",($val == 'on'),'bool',0,'',$conf->entity);
  167. if (! $res > 0) $error++;
  168. if (! $error)
  169. {
  170. setEventMessage($langs->trans("SetupSaved"));
  171. }
  172. else
  173. {
  174. setEventMessage($langs->trans("Error"),'errors');
  175. }
  176. }
  177. /*
  178. * View
  179. */
  180. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  181. llxHeader();
  182. $form=new Form($db);
  183. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  184. print_fiche_titre($langs->trans("InterventionsSetup"),$linkback,'setup');
  185. $head=fichinter_admin_prepare_head();
  186. dol_fiche_head($head, 'ficheinter', $langs->trans("Interventions"), 0, 'intervention');
  187. // Interventions numbering model
  188. print_titre($langs->trans("FicheinterNumberingModules"));
  189. print '<table class="noborder" width="100%">';
  190. print '<tr class="liste_titre">';
  191. print '<td width="100">'.$langs->trans("Name").'</td>';
  192. print '<td>'.$langs->trans("Description").'</td>';
  193. print '<td>'.$langs->trans("Example").'</td>';
  194. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  195. print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  196. print "</tr>\n";
  197. clearstatcache();
  198. foreach ($dirmodels as $reldir)
  199. {
  200. $dir = dol_buildpath($reldir."core/modules/fichinter/");
  201. if (is_dir($dir))
  202. {
  203. $handle = opendir($dir);
  204. if (is_resource($handle))
  205. {
  206. $var=true;
  207. while (($file = readdir($handle))!==false)
  208. {
  209. if (preg_match('/^(mod_.*)\.php$/i',$file,$reg))
  210. {
  211. $file = $reg[1];
  212. $classname = substr($file,4);
  213. require_once $dir.$file.'.php';
  214. $module = new $file;
  215. if ($module->isEnabled())
  216. {
  217. // Show modules according to features level
  218. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  219. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  220. $var=!$var;
  221. print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
  222. print $module->info();
  223. print '</td>';
  224. // Show example of numbering model
  225. print '<td class="nowrap">';
  226. $tmp=$module->getExample();
  227. if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
  228. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  229. else print $tmp;
  230. print '</td>'."\n";
  231. print '<td align="center">';
  232. if ($conf->global->FICHEINTER_ADDON == $classname)
  233. {
  234. print img_picto($langs->trans("Activated"),'switch_on');
  235. }
  236. else
  237. {
  238. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$classname.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  239. }
  240. print '</td>';
  241. $ficheinter=new Fichinter($db);
  242. $ficheinter->initAsSpecimen();
  243. // Info
  244. $htmltooltip='';
  245. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  246. $nextval=$module->getNextValue($mysoc,$ficheinter);
  247. if ($nextval != $langs->trans("NotAvailable"))
  248. {
  249. $htmltooltip.=''.$langs->trans("NextValue").': '.$nextval;
  250. }
  251. print '<td align="center">';
  252. print $form->textwithpicto('',$htmltooltip,1,0);
  253. print '</td>';
  254. print '</tr>';
  255. }
  256. }
  257. }
  258. closedir($handle);
  259. }
  260. }
  261. }
  262. print '</table><br>';
  263. /*
  264. * Documents models for Interventions
  265. */
  266. print_titre($langs->trans("TemplatePDFInterventions"));
  267. // Defini tableau def des modeles
  268. $type='ficheinter';
  269. $def = array();
  270. $sql = "SELECT nom";
  271. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  272. $sql.= " WHERE type = '".$type."'";
  273. $sql.= " AND entity = ".$conf->entity;
  274. $resql=$db->query($sql);
  275. if ($resql)
  276. {
  277. $i = 0;
  278. $num_rows=$db->num_rows($resql);
  279. while ($i < $num_rows)
  280. {
  281. $array = $db->fetch_array($resql);
  282. array_push($def, $array[0]);
  283. $i++;
  284. }
  285. }
  286. else
  287. {
  288. dol_print_error($db);
  289. }
  290. print '<table class="noborder" width="100%">';
  291. print '<tr class="liste_titre">';
  292. print '<td>'.$langs->trans("Name").'</td>';
  293. print '<td>'.$langs->trans("Description").'</td>';
  294. print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
  295. print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
  296. print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  297. print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
  298. print "</tr>\n";
  299. clearstatcache();
  300. $var=true;
  301. foreach ($dirmodels as $reldir)
  302. {
  303. $dir = dol_buildpath($reldir."core/modules/fichinter/doc/");
  304. if (is_dir($dir))
  305. {
  306. $handle=opendir($dir);
  307. if (is_resource($handle))
  308. {
  309. while (($file = readdir($handle))!==false)
  310. {
  311. if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,4) == 'pdf_')
  312. {
  313. $name = substr($file, 4, dol_strlen($file) -16);
  314. $classname = substr($file, 0, dol_strlen($file) -12);
  315. $var=!$var;
  316. print '<tr '.$bc[$var].'><td>';
  317. echo "$name";
  318. print "</td><td>\n";
  319. require_once $dir.$file;
  320. $module = new $classname($db);
  321. print $module->description;
  322. print '</td>';
  323. // Active
  324. if (in_array($name, $def))
  325. {
  326. print "<td align=\"center\">\n";
  327. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  328. print img_picto($langs->trans("Enabled"),'switch_on');
  329. print '</a>';
  330. print "</td>";
  331. }
  332. else
  333. {
  334. print "<td align=\"center\">\n";
  335. 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>';
  336. print "</td>";
  337. }
  338. // Default
  339. print "<td align=\"center\">";
  340. if ($conf->global->FICHEINTER_ADDON_PDF == "$name")
  341. {
  342. print img_picto($langs->trans("Default"),'on');
  343. }
  344. else
  345. {
  346. 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>';
  347. }
  348. print '</td>';
  349. // Info
  350. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  351. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  352. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  353. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  354. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  355. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  356. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  357. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  358. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  359. print '<td align="center">';
  360. print $form->textwithpicto('',$htmltooltip,-1,0);
  361. print '</td>';
  362. // Preview
  363. $link='<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'intervention').'</a>';
  364. print '<td align="center">';
  365. print $link;
  366. print '</td>';
  367. print '</tr>';
  368. }
  369. }
  370. closedir($handle);
  371. }
  372. }
  373. }
  374. print '</table>';
  375. print "<br>";
  376. /*
  377. * Other options
  378. *
  379. */
  380. print_titre($langs->trans("OtherOptions"));
  381. print '<table class="noborder" width="100%">';
  382. print '<tr class="liste_titre">';
  383. print '<td>'.$langs->trans("Parameter").'</td>';
  384. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  385. print "<td>&nbsp;</td>\n";
  386. print "</tr>\n";
  387. $var=true;
  388. $var=! $var;
  389. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  390. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  391. print '<input type="hidden" name="action" value="set_FICHINTER_FREE_TEXT">';
  392. print '<tr '.$bc[$var].'><td colspan="2">';
  393. print $langs->trans("FreeLegalTextOnInterventions").' ('.$langs->trans("AddCRIfTooLong").')<br>';
  394. print '<textarea name="FICHINTER_FREE_TEXT" class="flat" cols="120">'.$conf->global->FICHINTER_FREE_TEXT.'</textarea>';
  395. print '</td><td align="right">';
  396. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  397. print "</td></tr>\n";
  398. print '</form>';
  399. //Use draft Watermark
  400. $var=!$var;
  401. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  402. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  403. print "<input type=\"hidden\" name=\"action\" value=\"set_FICHINTER_DRAFT_WATERMARK\">";
  404. print '<tr '.$bc[$var].'><td colspan="2">';
  405. print $langs->trans("WatermarkOnDraftInterventionCards").'<br>';
  406. print '<input size="50" class="flat" type="text" name="FICHINTER_DRAFT_WATERMARK" value="'.$conf->global->FICHINTER_DRAFT_WATERMARK.'">';
  407. print '</td><td align="right">';
  408. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  409. print "</td></tr>\n";
  410. // print products on fichinter
  411. $var=! $var;
  412. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  413. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  414. print '<input type="hidden" name="action" value="set_FICHINTER_PRINT_PRODUCTS">';
  415. print '<tr '.$bc[$var].'><td>';
  416. print $langs->trans("PrintProductsOnFichinter").' ('.$langs->trans("PrintProductsOnFichinterDetails").')</td>';
  417. print '<td align="center"><input type="checkbox" name="FICHINTER_PRINT_PRODUCTS" ';
  418. if ($conf->global->FICHINTER_PRINT_PRODUCTS)
  419. print 'checked="checked" ';
  420. print '/>';
  421. print '</td><td align="right">';
  422. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  423. print "</td></tr>\n";
  424. print '</form>';
  425. print '</table>';
  426. print '<br>';
  427. $db->close();
  428. llxFooter();