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