edit.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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);
  55. exit;
  56. }
  57. $type = $object->type;
  58. if (is_numeric($type)) {
  59. $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  60. }
  61. $extrafields = new ExtraFields($db);
  62. $extrafields->fetch_name_optionals_label($object->table_element);
  63. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
  64. $hookmanager->initHooks(array('categorycard'));
  65. $error = 0;
  66. /*
  67. * Actions
  68. */
  69. $parameters = array('id' => $id, 'ref' => $ref, 'cancel'=> $cancel, 'backtopage' => $backtopage, 'socid' => $socid, 'label' => $label, 'description' => $description, 'color' => $color, 'visible' => $visible, 'parent' => $parent);
  70. // Note that $action and $object may be modified by some hooks
  71. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  72. if ($reshook < 0) {
  73. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  74. }
  75. if (empty($reshook)) {
  76. if ($cancel) {
  77. if ($backtopage) {
  78. header("Location: ".$backtopage);
  79. exit;
  80. } else {
  81. header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
  82. exit;
  83. }
  84. }
  85. // Action mise a jour d'une categorie
  86. if ($action == 'update' && $user->hasRight('categorie', 'creer')) {
  87. $object->oldcopy = dol_clone($object, 2);
  88. $object->label = $label;
  89. $object->description = dol_htmlcleanlastbr($description);
  90. $object->color = $color;
  91. $object->socid = ($socid > 0 ? $socid : 0);
  92. $object->visible = $visible;
  93. $object->fk_parent = $parent != -1 ? $parent : 0;
  94. if (empty($object->label)) {
  95. $error++;
  96. $action = 'edit';
  97. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  98. }
  99. if (!$error && empty($object->error)) {
  100. $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  101. if ($ret < 0) {
  102. $error++;
  103. }
  104. if (!$error && $object->update($user) > 0) {
  105. if ($backtopage) {
  106. header("Location: ".$backtopage);
  107. exit;
  108. } else {
  109. header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
  110. exit;
  111. }
  112. } else {
  113. setEventMessages($object->error, $object->errors, 'errors');
  114. }
  115. } else {
  116. setEventMessages($object->error, $object->errors, 'errors');
  117. }
  118. }
  119. }
  120. /*
  121. * View
  122. */
  123. $form = new Form($db);
  124. $formother = new FormOther($db);
  125. llxHeader("", "", $langs->trans("Categories"));
  126. print load_fiche_titre($langs->trans("ModifCat"));
  127. $object->fetch($id);
  128. print "\n";
  129. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
  130. print '<input type="hidden" name="token" value="'.newToken().'">';
  131. print '<input type="hidden" name="action" value="update">';
  132. print '<input type="hidden" name="id" value="'.$object->id.'">';
  133. print '<input type="hidden" name="type" value="'.$type.'">';
  134. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  135. print dol_get_fiche_head('');
  136. print '<table class="border centpercent">';
  137. // Ref
  138. print '<tr><td class="titlefieldcreate fieldrequired">';
  139. print $langs->trans("Ref").'</td>';
  140. print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
  141. print '</tr>';
  142. // Description
  143. print '<tr>';
  144. print '<td>'.$langs->trans("Description").'</td>';
  145. print '<td>';
  146. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  147. $doleditor = new DolEditor('description', $object->description, '', 200, 'dolibarr_notes', '', false, true, isModEnabled('fckeditor'), ROWS_6, '90%');
  148. $doleditor->Create();
  149. print '</td></tr>';
  150. // Color
  151. print '<tr>';
  152. print '<td>'.$langs->trans("Color").'</td>';
  153. print '<td>';
  154. print $formother->selectColor($object->color, 'color');
  155. print '</td></tr>';
  156. // Parent category
  157. print '<tr><td>'.$langs->trans("In").'</td><td>';
  158. print img_picto('', 'category', 'class="pictofixedwidth"');
  159. print $form->select_all_categories($type, $object->fk_parent, 'parent', 64, $object->id);
  160. print ajax_combobox('parent');
  161. print '</td></tr>';
  162. $parameters = array();
  163. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  164. print $hookmanager->resPrint;
  165. if (empty($reshook)) {
  166. print $object->showOptionals($extrafields, 'edit', $parameters);
  167. }
  168. print '</table>';
  169. print dol_get_fiche_end();
  170. 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>';
  171. print '</form>';
  172. // End of page
  173. llxFooter();
  174. $db->close();