calendar_extrafields.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  7. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/bookcal/admin/calendar_extrafields.php
  24. * \ingroup bookcal
  25. * \brief Page to setup extra fields of calendar
  26. */
  27. // Load Dolibarr environment
  28. $res = 0;
  29. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  30. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  31. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  32. }
  33. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  34. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  35. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  36. $i--;
  37. $j--;
  38. }
  39. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
  40. $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  41. }
  42. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
  43. $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  44. }
  45. // Try main.inc.php using relative path
  46. if (!$res && file_exists("../../main.inc.php")) {
  47. $res = @include "../../main.inc.php";
  48. }
  49. if (!$res && file_exists("../../../main.inc.php")) {
  50. $res = @include "../../../main.inc.php";
  51. }
  52. if (!$res) {
  53. die("Include of main fails");
  54. }
  55. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  56. require_once '../lib/bookcal.lib.php';
  57. // Load translation files required by the page
  58. $langs->loadLangs(array('bookcal@bookcal', 'admin'));
  59. $extrafields = new ExtraFields($db);
  60. $form = new Form($db);
  61. // List of supported format
  62. $tmptype2label = ExtraFields::$type2label;
  63. $type2label = array('');
  64. foreach ($tmptype2label as $key => $val) {
  65. $type2label[$key] = $langs->transnoentitiesnoconv($val);
  66. }
  67. $action = GETPOST('action', 'aZ09');
  68. $attrname = GETPOST('attrname', 'alpha');
  69. $elementtype = 'bookcal_calendar'; //Must be the $table_element of the class that manage extrafield
  70. if (!$user->admin) {
  71. accessforbidden();
  72. }
  73. /*
  74. * Actions
  75. */
  76. require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
  77. /*
  78. * View
  79. */
  80. $textobject = $langs->transnoentitiesnoconv("Calendar");
  81. $help_url = '';
  82. $page_name = "BookCalSetup";
  83. llxHeader('', $langs->trans("BookCalSetup"), $help_url);
  84. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  85. print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
  86. $head = bookcalAdminPrepareHead();
  87. print dol_get_fiche_head($head, 'calendar_extrafields', $langs->trans($page_name), -1, 'bookcal@bookcal');
  88. require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
  89. print dol_get_fiche_end();
  90. // Buttons
  91. if ((float) DOL_VERSION < 17) { // On v17+, the "New Attribute" button is included into tpl.
  92. if ($action != 'create' && $action != 'edit') {
  93. print '<div class="tabsAction">';
  94. print '<a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?action=create">'.$langs->trans("NewAttribute").'</a>';
  95. print "</div>";
  96. }
  97. }
  98. /*
  99. * Creation of an optional field
  100. */
  101. if ($action == 'create') {
  102. print '<br><div id="newattrib"></div>';
  103. print load_fiche_titre($langs->trans('NewAttribute'));
  104. require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
  105. }
  106. /*
  107. * Edition of an optional field
  108. */
  109. if ($action == 'edit' && !empty($attrname)) {
  110. print "<br>";
  111. print load_fiche_titre($langs->trans("FieldEdition", $attrname));
  112. require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
  113. }
  114. // End of page
  115. llxFooter();
  116. $db->close();