edit.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. // Load translation files required by the page
  31. $langs->load("categories");
  32. $id = GETPOST('id', 'int');
  33. $ref = GETPOST('ref', 'alphanohtml');
  34. $action = (GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'edit');
  35. $confirm = GETPOST('confirm');
  36. $cancel = GETPOST('cancel', 'alpha');
  37. $backtopage = GETPOST('backtopage', 'alpha');
  38. $socid = (int) GETPOST('socid', 'int');
  39. $label = (string) GETPOST('label', 'alphanohtml');
  40. $description = (string) GETPOST('description', 'restricthtml');
  41. $color = preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml'));
  42. $visible = (int) GETPOST('visible', 'int');
  43. $parent = (int) GETPOST('parent', 'int');
  44. if ($id == "") {
  45. dol_print_error('', 'Missing parameter id');
  46. exit();
  47. }
  48. // Security check
  49. $result = restrictedArea($user, 'categorie', $id, '&category');
  50. $object = new Categorie($db);
  51. $result = $object->fetch($id, $label);
  52. if ($result <= 0) {
  53. dol_print_error($db, $object->error); exit;
  54. }
  55. $type = $object->type;
  56. if (is_numeric($type)) {
  57. $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  58. }
  59. $extrafields = new ExtraFields($db);
  60. $extrafields->fetch_name_optionals_label($object->table_element);
  61. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
  62. $hookmanager->initHooks(array('categorycard'));
  63. $error = 0;
  64. /*
  65. * Actions
  66. */
  67. if ($cancel) {
  68. if ($backtopage) {
  69. header("Location: ".$backtopage);
  70. exit;
  71. } else {
  72. header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
  73. exit;
  74. }
  75. }
  76. // Action mise a jour d'une categorie
  77. if ($action == 'update' && $user->rights->categorie->creer) {
  78. $object->oldcopy = dol_clone($object);
  79. $object->label = $label;
  80. $object->description = dol_htmlcleanlastbr($description);
  81. $object->color = $color;
  82. $object->socid = ($socid > 0 ? $socid : 0);
  83. $object->visible = $visible;
  84. $object->fk_parent = $parent != -1 ? $parent : 0;
  85. if (empty($object->label)) {
  86. $error++;
  87. $action = 'edit';
  88. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  89. }
  90. if (!$error && empty($object->error)) {
  91. $ret = $extrafields->setOptionalsFromPost(null, $object);
  92. if ($ret < 0) {
  93. $error++;
  94. }
  95. if (!$error && $object->update($user) > 0) {
  96. if ($backtopage) {
  97. header("Location: ".$backtopage);
  98. exit;
  99. } else {
  100. header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
  101. exit;
  102. }
  103. } else {
  104. setEventMessages($object->error, $object->errors, 'errors');
  105. }
  106. } else {
  107. setEventMessages($object->error, $object->errors, 'errors');
  108. }
  109. }
  110. /*
  111. * View
  112. */
  113. $form = new Form($db);
  114. $formother = new FormOther($db);
  115. llxHeader("", "", $langs->trans("Categories"));
  116. print load_fiche_titre($langs->trans("ModifCat"));
  117. $object->fetch($id);
  118. print "\n";
  119. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
  120. print '<input type="hidden" name="token" value="'.newToken().'">';
  121. print '<input type="hidden" name="action" value="update">';
  122. print '<input type="hidden" name="id" value="'.$object->id.'">';
  123. print '<input type="hidden" name="type" value="'.$type.'">';
  124. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  125. print dol_get_fiche_head('');
  126. print '<table class="border centpercent">';
  127. // Ref
  128. print '<tr><td class="titlefieldcreate fieldrequired">';
  129. print $langs->trans("Ref").'</td>';
  130. print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
  131. print '</tr>';
  132. // Description
  133. print '<tr>';
  134. print '<td>'.$langs->trans("Description").'</td>';
  135. print '<td>';
  136. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  137. $doleditor = new DolEditor('description', $object->description, '', 200, 'dolibarr_notes', '', false, true, $conf->fckeditor->enabled, ROWS_6, '90%');
  138. $doleditor->Create();
  139. print '</td></tr>';
  140. // Color
  141. print '<tr>';
  142. print '<td>'.$langs->trans("Color").'</td>';
  143. print '<td>';
  144. print $formother->selectColor($object->color, 'color');
  145. print '</td></tr>';
  146. // Parent category
  147. print '<tr><td>'.$langs->trans("In").'</td><td>';
  148. print $form->select_all_categories($type, $object->fk_parent, 'parent', 64, $object->id);
  149. print '</td></tr>';
  150. $parameters = array();
  151. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  152. print $hookmanager->resPrint;
  153. if (empty($reshook)) {
  154. print $object->showOptionals($extrafields, 'edit', $parameters);
  155. }
  156. print '</table>';
  157. print dol_get_fiche_end();
  158. 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>';
  159. print '</form>';
  160. // End of page
  161. llxFooter();
  162. $db->close();