reception_setup.php 16 KB

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