setup.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2022 Alice Adminson <aadminson@example.com>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file bookcal/admin/setup.php
  20. * \ingroup bookcal
  21. * \brief BookCal setup page.
  22. */
  23. // Load Dolibarr environment
  24. require '../../main.inc.php';
  25. global $langs, $user;
  26. // Libraries
  27. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  28. require_once '../lib/bookcal.lib.php';
  29. //require_once "../class/myclass.class.php";
  30. // Translations
  31. $langs->loadLangs(array("admin", "agenda"));
  32. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  33. $hookmanager->initHooks(array('bookcalsetup', 'globalsetup'));
  34. // Access control
  35. if (!$user->admin) {
  36. accessforbidden();
  37. }
  38. // Parameters
  39. $action = GETPOST('action', 'aZ09');
  40. $backtopage = GETPOST('backtopage', 'alpha');
  41. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  42. $value = GETPOST('value', 'alpha');
  43. $label = GETPOST('label', 'alpha');
  44. $scandir = GETPOST('scan_dir', 'alpha');
  45. $type = 'myobject';
  46. $error = 0;
  47. $setupnotempty = 0;
  48. // Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
  49. $useFormSetup = 1;
  50. if (!class_exists('FormSetup')) {
  51. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
  52. }
  53. $formSetup = new FormSetup($db);
  54. // Setup conf BOOKCAL_PUBLIC_INTERFACE_TOPIC
  55. $item = $formSetup->newItem('BOOKCAL_PUBLIC_INTERFACE_TOPIC');
  56. $item->defaultFieldValue = 'MyBigCompany public interface for Bookcal';
  57. /*// Setup conf BOOKCAL_MYPARAM8
  58. $item = $formSetup->newItem('BOOKCAL_MYPARAM8');
  59. $TField = array(
  60. 'test01' => $langs->trans('test01'),
  61. 'test02' => $langs->trans('test02'),
  62. 'test03' => $langs->trans('test03'),
  63. 'test04' => $langs->trans('test04'),
  64. 'test05' => $langs->trans('test05'),
  65. 'test06' => $langs->trans('test06'),
  66. );
  67. $item->setAsMultiSelect($TField);
  68. $item->helpText = $langs->transnoentities('BOOKCAL_MYPARAM8');
  69. // Setup conf BOOKCAL_MYPARAM9
  70. $formSetup->newItem('BOOKCAL_MYPARAM9')->setAsSelect($TField);
  71. // Setup conf BOOKCAL_MYPARAM10
  72. $item = $formSetup->newItem('BOOKCAL_MYPARAM10');
  73. $item->setAsColor();
  74. $item->defaultFieldValue = '#FF0000';
  75. $item->nameText = $item->getNameText().' more html text ';
  76. $item->fieldInputOverride = '';
  77. $item->helpText = $langs->transnoentities('AnHelpMessage');*/
  78. //$item->fieldValue = '';
  79. //$item->fieldAttr = array() ; // fields attribute only for compatible fields like input text
  80. //$item->fieldOverride = false; // set this var to override field output will override $fieldInputOverride and $fieldOutputOverride too
  81. //$item->fieldInputOverride = false; // set this var to override field input
  82. //$item->fieldOutputOverride = false; // set this var to override field output
  83. $setupnotempty =+ count($formSetup->items);
  84. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  85. /*
  86. * Actions
  87. */
  88. // For retrocompatibility Dolibarr < 15.0
  89. if (versioncompare(explode('.', DOL_VERSION), array(15)) < 0 && $action == 'update' && !empty($user->admin)) {
  90. $formSetup->saveConfFromPost();
  91. }
  92. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  93. if ($action == 'updateMask') {
  94. $maskconst = GETPOST('maskconst', 'aZ09');
  95. $maskvalue = GETPOST('maskvalue', 'alpha');
  96. if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
  97. $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
  98. if (!($res > 0)) {
  99. $error++;
  100. }
  101. }
  102. if (!$error) {
  103. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  104. } else {
  105. setEventMessages($langs->trans("Error"), null, 'errors');
  106. }
  107. } elseif ($action == 'specimen') {
  108. $modele = GETPOST('module', 'alpha');
  109. $tmpobjectkey = GETPOST('object');
  110. $tmpobject = new $tmpobjectkey($db);
  111. $tmpobject->initAsSpecimen();
  112. // Search template files
  113. $file = '';
  114. $classname = '';
  115. $filefound = 0;
  116. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  117. foreach ($dirmodels as $reldir) {
  118. $file = dol_buildpath($reldir."core/modules/bookcal/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
  119. if (file_exists($file)) {
  120. $filefound = 1;
  121. $classname = "pdf_".$modele."_".strtolower($tmpobjectkey);
  122. break;
  123. }
  124. }
  125. if ($filefound) {
  126. require_once $file;
  127. $module = new $classname($db);
  128. if ($module->write_file($tmpobject, $langs) > 0) {
  129. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=bookcal-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
  130. return;
  131. } else {
  132. setEventMessages($module->error, null, 'errors');
  133. dol_syslog($module->error, LOG_ERR);
  134. }
  135. } else {
  136. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  137. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  138. }
  139. } elseif ($action == 'setmod') {
  140. // TODO Check if numbering module chosen can be activated by calling method canBeActivated
  141. $tmpobjectkey = GETPOST('object');
  142. if (!empty($tmpobjectkey)) {
  143. $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey)."_ADDON";
  144. dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
  145. }
  146. } elseif ($action == 'set') {
  147. // Activate a model
  148. $ret = addDocumentModel($value, $type, $label, $scandir);
  149. } elseif ($action == 'del') {
  150. $ret = delDocumentModel($value, $type);
  151. if ($ret > 0) {
  152. $tmpobjectkey = GETPOST('object');
  153. if (!empty($tmpobjectkey)) {
  154. $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  155. if ($conf->global->$constforval == "$value") {
  156. dolibarr_del_const($db, $constforval, $conf->entity);
  157. }
  158. }
  159. }
  160. } elseif ($action == 'setdoc') {
  161. // Set or unset default model
  162. $tmpobjectkey = GETPOST('object');
  163. if (!empty($tmpobjectkey)) {
  164. $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  165. if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
  166. // The constant that was read before the new set
  167. // We therefore requires a variable to have a coherent view
  168. $conf->global->$constforval = $value;
  169. }
  170. // We disable/enable the document template (into llx_document_model table)
  171. $ret = delDocumentModel($value, $type);
  172. if ($ret > 0) {
  173. $ret = addDocumentModel($value, $type, $label, $scandir);
  174. }
  175. }
  176. } elseif ($action == 'unsetdoc') {
  177. $tmpobjectkey = GETPOST('object');
  178. if (!empty($tmpobjectkey)) {
  179. $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  180. dolibarr_del_const($db, $constforval, $conf->entity);
  181. }
  182. }
  183. /*
  184. * View
  185. */
  186. $form = new Form($db);
  187. $help_url = '';
  188. $page_name = "BookCalSetup";
  189. llxHeader('', $langs->trans($page_name), $help_url);
  190. // Subheader
  191. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
  192. print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
  193. // Configuration header
  194. $head = bookcalAdminPrepareHead();
  195. print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "fa-calendar-check");
  196. // Setup page goes here
  197. //echo '<span class="opacitymedium">'.$langs->trans("BookCalSetupPage").'</span><br><br>';
  198. if ($action == 'edit') {
  199. print $formSetup->generateOutput(true);
  200. print '<br>';
  201. } elseif (!empty($formSetup->items)) {
  202. print $formSetup->generateOutput();
  203. print '<div class="tabsAction">';
  204. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  205. print '</div>';
  206. } else {
  207. print '<br>'.$langs->trans("NothingToSetup");
  208. }
  209. if (empty($setupnotempty)) {
  210. print '<br>'.$langs->trans("NothingToSetup");
  211. }
  212. // Page end
  213. print dol_get_fiche_end();
  214. llxFooter();
  215. $db->close();