edit.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
  3. * Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  6. * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/categories/edit.php
  23. * \ingroup category
  24. * \brief Page d'edition de categorie produit
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. // Load translation files required by the page
  32. $langs->load("categories");
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alphanohtml');
  35. $action = (GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'edit');
  36. $confirm = GETPOST('confirm');
  37. $cancel = GETPOST('cancel', 'alpha');
  38. $backtopage = GETPOST('backtopage', 'alpha');
  39. $socid = (int) GETPOST('socid', 'int');
  40. $label = (string) GETPOST('label', 'alphanohtml');
  41. $description = (string) GETPOST('description', 'restricthtml');
  42. $color = preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml'));
  43. $visible = (int) GETPOST('visible', 'int');
  44. $parent = (int) GETPOST('parent', 'int');
  45. if ($id == "") {
  46. dol_print_error('', 'Missing parameter id');
  47. exit();
  48. }
  49. // Security check
  50. $result = restrictedArea($user, 'categorie', $id, '&category');
  51. $object = new Categorie($db);
  52. $result = $object->fetch($id, $label);
  53. if ($result <= 0) {
  54. dol_print_error($db, $object->error); exit;
  55. }
  56. $type = $object->type;
  57. if (is_numeric($type)) {
  58. $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  59. }
  60. $extrafields = new ExtraFields($db);
  61. $extrafields->fetch_name_optionals_label($object->table_element);
  62. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
  63. $hookmanager->initHooks(array('categorycard'));
  64. $error = 0;
  65. /*
  66. * Actions
  67. */
  68. if ($cancel) {
  69. if ($backtopage) {
  70. header("Location: ".$backtopage);
  71. exit;
  72. } else {
  73. header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
  74. exit;
  75. }
  76. }
  77. // Action mise a jour d'une categorie
  78. if ($action == 'update' && $user->rights->categorie->creer) {
  79. $object->oldcopy = dol_clone($object);
  80. $object->label = $label;
  81. $object->description = dol_htmlcleanlastbr($description);
  82. $object->color = $color;
  83. $object->socid = ($socid > 0 ? $socid : 0);
  84. $object->visible = $visible;
  85. $object->fk_parent = $parent != -1 ? $parent : 0;
  86. if (empty($object->label)) {
  87. $error++;
  88. $action = 'edit';
  89. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  90. }
  91. if (!$error && empty($object->error)) {
  92. $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  93. if ($ret < 0) {
  94. $error++;
  95. }
  96. if (!$error && $object->update($user) > 0) {
  97. if ($backtopage) {
  98. header("Location: ".$backtopage);
  99. exit;
  100. } else {
  101. header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
  102. exit;
  103. }
  104. } else {
  105. setEventMessages($object->error, $object->errors, 'errors');
  106. }
  107. } else {
  108. setEventMessages($object->error, $object->errors, 'errors');
  109. }
  110. }
  111. /*
  112. * View
  113. */
  114. $form = new Form($db);
  115. $formother = new FormOther($db);
  116. llxHeader("", "", $langs->trans("Categories"));
  117. print load_fiche_titre($langs->trans("ModifCat"));
  118. $object->fetch($id);
  119. print "\n";
  120. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
  121. print '<input type="hidden" name="token" value="'.newToken().'">';
  122. print '<input type="hidden" name="action" value="update">';
  123. print '<input type="hidden" name="id" value="'.$object->id.'">';
  124. print '<input type="hidden" name="type" value="'.$type.'">';
  125. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  126. print dol_get_fiche_head('');
  127. print '<table class="border centpercent">';
  128. // Ref
  129. print '<tr><td class="titlefieldcreate fieldrequired">';
  130. print $langs->trans("Ref").'</td>';
  131. print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
  132. print '</tr>';
  133. // Description
  134. print '<tr>';
  135. print '<td>'.$langs->trans("Description").'</td>';
  136. print '<td>';
  137. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  138. $doleditor = new DolEditor('description', $object->description, '', 200, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor'), ROWS_6, '90%');
  139. $doleditor->Create();
  140. print '</td></tr>';
  141. // Color
  142. print '<tr>';
  143. print '<td>'.$langs->trans("Color").'</td>';
  144. print '<td>';
  145. print $formother->selectColor($object->color, 'color');
  146. print '</td></tr>';
  147. // Parent category
  148. print '<tr><td>'.$langs->trans("In").'</td><td>';
  149. print img_picto('', 'category', 'class="pictofixedwidth"');
  150. print $form->select_all_categories($type, $object->fk_parent, 'parent', 64, $object->id);
  151. print ajax_combobox('parent');
  152. print '</td></tr>';
  153. $parameters = array();
  154. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  155. print $hookmanager->resPrint;
  156. if (empty($reshook)) {
  157. print $object->showOptionals($extrafields, 'edit', $parameters);
  158. }
  159. print '</table>';
  160. print dol_get_fiche_end();
  161. print '<div class="center"><input type="submit" class="button" name"submit" value="'.$langs->trans("Modify").'"> &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
  162. print '</form>';
  163. // End of page
  164. llxFooter();
  165. $db->close();