reception_setup.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?php
  2. /* Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/admin/reception_setup.php
  19. * \ingroup reception
  20. * \brief Page to setup reception module
  21. */
  22. require '../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
  27. $langs->loadLangs(array("admin", "receptions", 'other'));
  28. if (!$user->admin) accessforbidden();
  29. $action = GETPOST('action', 'alpha');
  30. $value = GETPOST('value', 'alpha');
  31. $label = GETPOST('label', 'alpha');
  32. $scandir = GETPOST('scan_dir', 'alpha');
  33. $type = 'reception';
  34. /*
  35. * Actions
  36. */
  37. if (!empty($conf->reception->enabled) && empty($conf->global->MAIN_SUBMODULE_RECEPTION))
  38. {
  39. // This option should always be set to on when module is on.
  40. dolibarr_set_const($db, "MAIN_SUBMODULE_RECEPTION", "1", 'chaine', 0, '', $conf->entity);
  41. }
  42. if (empty($conf->global->RECEPTION_ADDON_NUMBER))
  43. {
  44. $conf->global->RECEPTION_ADDON_NUMBER = 'mod_reception_beryl';
  45. }
  46. /*
  47. * Actions
  48. */
  49. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  50. if ($action == 'updateMask')
  51. {
  52. $maskconst = GETPOST('maskconstreception', 'alpha');
  53. $maskvalue = GETPOST('maskreception', 'alpha');
  54. if (!empty($maskconst))
  55. $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
  56. if (isset($res))
  57. {
  58. if ($res > 0)
  59. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  60. else setEventMessages($langs->trans("Error"), null, 'errors');
  61. }
  62. } elseif ($action == 'set_param')
  63. {
  64. $freetext = GETPOST('RECEPTION_FREE_TEXT', 'none'); // No alpha here, we want exact string
  65. $res = dolibarr_set_const($db, "RECEPTION_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
  66. if ($res <= 0)
  67. {
  68. $error++;
  69. setEventMessages($langs->trans("Error"), null, 'errors');
  70. }
  71. $draft = GETPOST('RECEPTION_DRAFT_WATERMARK', 'alpha');
  72. $res = dolibarr_set_const($db, "RECEPTION_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
  73. if ($res <= 0)
  74. {
  75. $error++;
  76. setEventMessages($langs->trans("Error"), null, 'errors');
  77. }
  78. if (!$error)
  79. {
  80. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  81. }
  82. } elseif ($action == 'specimen')
  83. {
  84. $modele = GETPOST('module', 'alpha');
  85. $exp = new Reception($db);
  86. $exp->initAsSpecimen();
  87. // Search template files
  88. $file = ''; $classname = ''; $filefound = 0;
  89. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  90. foreach ($dirmodels as $reldir)
  91. {
  92. $file = dol_buildpath($reldir."core/modules/reception/doc/pdf_".$modele.".modules.php", 0);
  93. if (file_exists($file))
  94. {
  95. $filefound = 1;
  96. $classname = "pdf_".$modele;
  97. break;
  98. }
  99. }
  100. if ($filefound)
  101. {
  102. require_once $file;
  103. $module = new $classname($db);
  104. if ($module->write_file($exp, $langs) > 0)
  105. {
  106. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=reception&file=SPECIMEN.pdf");
  107. return;
  108. } else {
  109. setEventMessages($module->error, $module->errors, 'errors');
  110. dol_syslog($module->error, LOG_ERR);
  111. }
  112. } else {
  113. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  114. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  115. }
  116. }
  117. // Activate a model
  118. elseif ($action == 'set')
  119. {
  120. $ret = addDocumentModel($value, $type, $label, $scandir);
  121. } elseif ($action == 'del')
  122. {
  123. $ret = delDocumentModel($value, $type);
  124. if ($ret > 0)
  125. {
  126. if ($conf->global->RECEPTION_ADDON_PDF == "$value") dolibarr_del_const($db, 'RECEPTION_ADDON_PDF', $conf->entity);
  127. }
  128. }
  129. // Set default model
  130. elseif ($action == 'setdoc')
  131. {
  132. if (dolibarr_set_const($db, "RECEPTION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
  133. {
  134. // La constante qui a ete lue en avant du nouveau set
  135. // on passe donc par une variable pour avoir un affichage coherent
  136. $conf->global->RECEPTION_ADDON_PDF = $value;
  137. }
  138. // On active le modele
  139. $ret = delDocumentModel($value, $type);
  140. if ($ret > 0)
  141. {
  142. $ret = addDocumentModel($value, $type, $label, $scandir);
  143. }
  144. } elseif ($action == 'setmodel')
  145. {
  146. dolibarr_set_const($db, "RECEPTION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
  147. }
  148. /*
  149. * View
  150. */
  151. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  152. $form = new Form($db);
  153. llxHeader("", $langs->trans("ReceptionsSetup"));
  154. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  155. print load_fiche_titre($langs->trans("ReceptionsSetup"), $linkback, 'title_setup');
  156. print '<br>';
  157. $head = reception_admin_prepare_head();
  158. dol_fiche_head($head, 'reception', $langs->trans("Receptions"), -1, 'sending');
  159. // Reception numbering model
  160. print load_fiche_titre($langs->trans("ReceptionsNumberingModules"));
  161. print '<table class="noborder centpercent">';
  162. print '<tr class="liste_titre">';
  163. print '<td width="100">'.$langs->trans("Name").'</td>';
  164. print '<td>'.$langs->trans("Description").'</td>';
  165. print '<td>'.$langs->trans("Example").'</td>';
  166. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  167. print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  168. print "</tr>\n";
  169. clearstatcache();
  170. foreach ($dirmodels as $reldir)
  171. {
  172. $dir = dol_buildpath($reldir."core/modules/reception");
  173. if (is_dir($dir))
  174. {
  175. $handle = opendir($dir);
  176. if (is_resource($handle))
  177. {
  178. while (($file = readdir($handle)) !== false)
  179. {
  180. if (substr($file, 0, 14) == 'mod_reception_' && substr($file, dol_strlen($file) - 3, 3) == 'php')
  181. {
  182. $file = substr($file, 0, dol_strlen($file) - 4);
  183. require_once $dir.'/'.$file.'.php';
  184. $module = new $file;
  185. if ($module->isEnabled())
  186. {
  187. // Show modules according to features level
  188. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  189. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  190. print '<tr><td>'.$module->nom."</td>\n";
  191. print '<td>';
  192. print $module->info();
  193. print '</td>';
  194. // Show example of numbering module
  195. print '<td class="nowrap">';
  196. $tmp = $module->getExample();
  197. if (preg_match('/^Error/', $tmp)) {
  198. $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>';
  199. } elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
  200. else print $tmp;
  201. print '</td>'."\n";
  202. print '<td class="center">';
  203. if ($conf->global->RECEPTION_ADDON_NUMBER == "$file")
  204. {
  205. print img_picto($langs->trans("Activated"), 'switch_on');
  206. } else {
  207. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodel&amp;value='.$file.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  208. print img_picto($langs->trans("Disabled"), 'switch_off');
  209. print '</a>';
  210. }
  211. print '</td>';
  212. $reception = new Reception($db);
  213. $reception->initAsSpecimen();
  214. // Info
  215. $htmltooltip = '';
  216. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  217. $nextval = $module->getNextValue($mysoc, $reception);
  218. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  219. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  220. if ($nextval) {
  221. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
  222. $nextval = $langs->trans($nextval);
  223. $htmltooltip .= $nextval.'<br>';
  224. } else {
  225. $htmltooltip .= $langs->trans($module->error).'<br>';
  226. }
  227. }
  228. print '<td class="center">';
  229. print $form->textwithpicto('', $htmltooltip, 1, 0);
  230. print '</td>';
  231. print '</tr>';
  232. }
  233. }
  234. }
  235. closedir($handle);
  236. }
  237. }
  238. }
  239. print '</table><br>';
  240. /*
  241. * Documents models for Receptions Receipt
  242. */
  243. print load_fiche_titre($langs->trans("ReceptionsReceiptModel"));
  244. // Defini tableau def de modele invoice
  245. $type = "reception";
  246. $def = array();
  247. $sql = "SELECT nom";
  248. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  249. $sql .= " WHERE type = '".$type."'";
  250. $sql .= " AND entity = ".$conf->entity;
  251. $resql = $db->query($sql);
  252. if ($resql)
  253. {
  254. $i = 0;
  255. $num_rows = $db->num_rows($resql);
  256. while ($i < $num_rows)
  257. {
  258. $array = $db->fetch_array($resql);
  259. array_push($def, $array[0]);
  260. $i++;
  261. }
  262. } else {
  263. dol_print_error($db);
  264. }
  265. print '<table class="noborder centpercent">';
  266. print '<tr class="liste_titre">';
  267. print '<td width="140">'.$langs->trans("Name").'</td>';
  268. print '<td>'.$langs->trans("Description").'</td>';
  269. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  270. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  271. print '<td align="center" width="80" class="nowrap">'.$langs->trans("ShortInfo").'</td>';
  272. print '<td align="center" width="80" class="nowrap">'.$langs->trans("Preview").'</td>';
  273. print "</tr>\n";
  274. clearstatcache();
  275. foreach ($dirmodels as $reldir)
  276. {
  277. foreach (array('', '/doc') as $valdir)
  278. {
  279. $realpath = $reldir."core/modules/reception".$valdir;
  280. $dir = dol_buildpath($realpath);
  281. if (is_dir($dir))
  282. {
  283. $handle = opendir($dir);
  284. if (is_resource($handle))
  285. {
  286. while (($file = readdir($handle)) !== false)
  287. {
  288. $filelist[] = $file;
  289. }
  290. closedir($handle);
  291. arsort($filelist);
  292. foreach ($filelist as $file)
  293. {
  294. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
  295. {
  296. if (file_exists($dir.'/'.$file))
  297. {
  298. $name = substr($file, 4, dol_strlen($file) - 16);
  299. $classname = substr($file, 0, dol_strlen($file) - 12);
  300. require_once $dir.'/'.$file;
  301. $module = new $classname($db);
  302. $modulequalified = 1;
  303. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
  304. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
  305. if ($modulequalified)
  306. {
  307. print '<tr><td width="100">';
  308. print (empty($module->name) ? $name : $module->name);
  309. print "</td><td>\n";
  310. if (method_exists($module, 'info')) print $module->info($langs);
  311. else print $module->description;
  312. print '</td>';
  313. // Active
  314. if (in_array($name, $def))
  315. {
  316. print '<td class="center">'."\n";
  317. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
  318. print img_picto($langs->trans("Enabled"), 'switch_on');
  319. print '</a>';
  320. print '</td>';
  321. } else {
  322. print '<td class="center">'."\n";
  323. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  324. print "</td>";
  325. }
  326. // Defaut
  327. print '<td class="center">';
  328. if ($conf->global->RECEPTION_ADDON_PDF == $name)
  329. {
  330. print img_picto($langs->trans("Default"), 'on');
  331. } else {
  332. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  333. }
  334. print '</td>';
  335. // Info
  336. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  337. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  338. if ($module->type == 'pdf')
  339. {
  340. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  341. }
  342. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  343. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  344. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  345. $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
  346. $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
  347. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  348. $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
  349. print '<td class="center">';
  350. print $form->textwithpicto('', $htmltooltip, 1, 0);
  351. print '</td>';
  352. // Preview
  353. print '<td class="center">';
  354. if ($module->type == 'pdf')
  355. {
  356. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_object($langs->trans("Preview"), 'reception').'</a>';
  357. } else {
  358. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  359. }
  360. print '</td>';
  361. print "</tr>\n";
  362. }
  363. }
  364. }
  365. }
  366. }
  367. }
  368. }
  369. }
  370. print '</table>';
  371. print '<br>';
  372. /*
  373. * Other options
  374. *
  375. */
  376. /*
  377. print load_fiche_titre($langs->trans("OtherOptions"));
  378. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  379. print '<input type="hidden" name="token" value="'.newToken().'">';
  380. print '<input type="hidden" name="action" value="set_param">';
  381. print "<table class=\"noborder\" width=\"100%\">";
  382. print "<tr class=\"liste_titre\">";
  383. print "<td>".$langs->trans("Parameter")."</td>\n";
  384. print "</tr>";
  385. $substitutionarray=pdf_getSubstitutionArray($langs);
  386. $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
  387. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  388. foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
  389. $htmltext.='</i>';
  390. print '<tr><td>';
  391. print $form->textwithpicto($langs->trans("FreeLegalTextOnReceptions"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext).'<br>';
  392. $variablename='RECEPTION_FREE_TEXT';
  393. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
  394. {
  395. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
  396. }
  397. else
  398. {
  399. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  400. $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
  401. print $doleditor->Create();
  402. }
  403. print "</td></tr>\n";
  404. print '<tr><td>';
  405. print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext).'<br>';
  406. print '<input size="50" class="flat" type="text" name="RECEPTION_DRAFT_WATERMARK" value="'.$conf->global->RECEPTION_DRAFT_WATERMARK.'">';
  407. print "</td></tr>\n";
  408. */
  409. print '</table>';
  410. //print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
  411. print '</form>';
  412. llxFooter();
  413. $db->close();