inventory_extrafields.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/product/admin/inventory_extrafields.php
  24. * \ingroup stock
  25. * \brief Page to setup extra fields of inventory
  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"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  31. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  32. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  33. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
  34. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  35. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  36. // Try main.inc.php using relative path
  37. if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
  38. if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
  39. if (!$res) die("Include of main fails");
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
  42. // Load translation files required by the page
  43. $langs->loadLangs(array('stock@stock', 'admin'));
  44. $extrafields = new ExtraFields($db);
  45. $form = new Form($db);
  46. // List of supported format
  47. $tmptype2label = ExtraFields::$type2label;
  48. $type2label = array('');
  49. foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val);
  50. $action = GETPOST('action', 'aZ09');
  51. $attrname = GETPOST('attrname', 'alpha');
  52. $elementtype = 'inventory'; //Must be the $table_element of the class that manage extrafield
  53. if (!$user->admin) accessforbidden();
  54. /*
  55. * Actions
  56. */
  57. require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
  58. /*
  59. * View
  60. */
  61. $textobject = $langs->transnoentitiesnoconv("Inventory");
  62. llxHeader('', $langs->trans("InventorySetup"), $help_url);
  63. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  64. print load_fiche_titre($langs->trans("InventorySetup"), $linkback, 'title_setup');
  65. $head = stock_admin_prepare_head();
  66. print dol_get_fiche_head($head, 'inventoryAttributes', $langs->trans("InventoryExtraFields"), -1, 'account');
  67. require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
  68. print dol_get_fiche_end();
  69. /*
  70. * Creation of an optional field
  71. */
  72. if ($action == 'create') {
  73. print '<br><div id="newattrib"></div>';
  74. print load_fiche_titre($langs->trans('NewAttribute'));
  75. require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
  76. }
  77. /*
  78. * Edition of an optional field
  79. */
  80. if ($action == 'edit' && !empty($attrname)) {
  81. print "<br>";
  82. print load_fiche_titre($langs->trans("FieldEdition", $attrname));
  83. require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
  84. }
  85. // End of page
  86. llxFooter();
  87. $db->close();