reception_setup.php 16 KB

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