edit.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/categories/edit.php
  22. * \ingroup category
  23. * \brief Page d'edition de categorie produit
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. // Load translation files required by the page
  30. $langs->load("categories");
  31. $id=GETPOST('id','int');
  32. $ref=GETPOST('ref');
  33. $type=GETPOST('type');
  34. $action=(GETPOST('action','aZ09')?GETPOST('action','aZ09'):'edit');
  35. $confirm=GETPOST('confirm');
  36. $cancel=GETPOST('cancel','alpha');
  37. $socid=GETPOST('socid','int');
  38. $label=GETPOST('label');
  39. $description=GETPOST('description');
  40. $color=GETPOST('color','alpha');
  41. $visible=GETPOST('visible');
  42. $parent=GETPOST('parent');
  43. if ($id == "")
  44. {
  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. if ($id > 0)
  52. {
  53. $result=$object->fetch($id);
  54. }
  55. $extrafields = new ExtraFields($db);
  56. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  57. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
  58. $hookmanager->initHooks(array('categorycard'));
  59. /*
  60. * Actions
  61. */
  62. if ($cancel)
  63. {
  64. header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
  65. exit;
  66. }
  67. // Action mise a jour d'une categorie
  68. if ($action == 'update' && $user->rights->categorie->creer)
  69. {
  70. $object->label = $label;
  71. $object->description = dol_htmlcleanlastbr($description);
  72. $object->color = $color;
  73. $object->socid = ($socid ? $socid : 'null');
  74. $object->visible = $visible;
  75. if ($parent != "-1")
  76. $object->fk_parent = $parent;
  77. else
  78. $object->fk_parent = "";
  79. if (empty($object->label))
  80. {
  81. $error++;
  82. $action = 'edit';
  83. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  84. }
  85. if (! $error && empty($object->error))
  86. {
  87. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  88. if ($ret < 0) $error++;
  89. if (! $error && $object->update($user) > 0)
  90. {
  91. header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
  92. exit;
  93. }
  94. else
  95. {
  96. setEventMessages($object->error, $object->errors, 'errors');
  97. }
  98. }
  99. else
  100. {
  101. setEventMessages($object->error, $object->errors, 'errors');
  102. }
  103. }
  104. /*
  105. * View
  106. */
  107. $form = new Form($db);
  108. $formother = new FormOther($db);
  109. llxHeader("","",$langs->trans("Categories"));
  110. print load_fiche_titre($langs->trans("ModifCat"));
  111. $object->fetch($id);
  112. print "\n";
  113. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
  114. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  115. print '<input type="hidden" name="action" value="update">';
  116. print '<input type="hidden" name="id" value="'.$object->id.'">';
  117. print '<input type="hidden" name="type" value="'.$type.'">';
  118. dol_fiche_head('');
  119. print '<table class="border" width="100%">';
  120. // Ref
  121. print '<tr><td class="titlefieldcreate fieldrequired">';
  122. print $langs->trans("Ref").'</td>';
  123. print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
  124. print '</tr>';
  125. // Description
  126. print '<tr>';
  127. print '<td>'.$langs->trans("Description").'</td>';
  128. print '<td >';
  129. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  130. $doleditor=new DolEditor('description',$object->description,'',200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled,ROWS_6,'90%');
  131. $doleditor->Create();
  132. print '</td></tr>';
  133. // Color
  134. print '<tr>';
  135. print '<td>'.$langs->trans("Color").'</td>';
  136. print '<td >';
  137. print $formother->selectColor($object->color, 'color');
  138. print '</td></tr>';
  139. // Parent category
  140. print '<tr><td>'.$langs->trans("In").'</td><td>';
  141. print $form->select_all_categories($type,$object->fk_parent,'parent',64,$object->id);
  142. print '</td></tr>';
  143. $parameters=array();
  144. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  145. print $hookmanager->resPrint;
  146. if (empty($reshook))
  147. {
  148. print $object->showOptionals($extrafields,'edit');
  149. }
  150. print '</table>';
  151. dol_fiche_end();
  152. print '<div class="center"><input type="submit" class="button" name"submit" value="'.$langs->trans("Modify").'"> &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
  153. print '</form>';
  154. // End of page
  155. llxFooter();
  156. $db->close();