2005-04-13 12:22:29 +00:00
|
|
|
<?php
|
2006-12-19 20:33:32 +00:00
|
|
|
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
|
2016-08-29 15:36:18 +00:00
|
|
|
* Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
2018-10-27 12:43:12 +00:00
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
|
2007-04-30 10:53:58 +00:00
|
|
|
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
|
2020-10-31 17:55:24 +00:00
|
|
|
* Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
|
2005-04-13 12:22:29 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 14:36:08 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-04-13 12:22:29 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 19:55:30 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2005-04-13 12:22:29 +00:00
|
|
|
*/
|
|
|
|
|
|
2006-04-01 02:37:23 +00:00
|
|
|
/**
|
2010-02-28 16:14:00 +00:00
|
|
|
* \file htdocs/categories/edit.php
|
|
|
|
|
* \ingroup category
|
|
|
|
|
* \brief Page d'edition de categorie produit
|
|
|
|
|
*/
|
2006-04-01 02:37:23 +00:00
|
|
|
|
2012-08-22 21:24:21 +00:00
|
|
|
require '../main.inc.php';
|
2012-08-22 21:11:24 +00:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
2014-03-16 15:04:18 +00:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
2015-09-17 18:00:54 +00:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
|
2006-04-01 02:37:23 +00:00
|
|
|
|
2018-05-27 07:58:23 +00:00
|
|
|
// Load translation files required by the page
|
2013-04-27 23:12:40 +00:00
|
|
|
$langs->load("categories");
|
2006-04-01 02:37:23 +00:00
|
|
|
|
2019-11-13 18:35:39 +00:00
|
|
|
$id = GETPOST('id', 'int');
|
2020-10-06 15:10:00 +00:00
|
|
|
$ref = GETPOST('ref', 'alphanohtml');
|
2019-11-13 18:35:39 +00:00
|
|
|
$action = (GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'edit');
|
|
|
|
|
$confirm = GETPOST('confirm');
|
|
|
|
|
$cancel = GETPOST('cancel', 'alpha');
|
2020-11-21 21:40:31 +00:00
|
|
|
$backtopage = GETPOST('backtopage', 'alpha');
|
2019-11-13 18:35:39 +00:00
|
|
|
|
2020-10-31 17:55:24 +00:00
|
|
|
$socid = (int) GETPOST('socid', 'int');
|
|
|
|
|
$label = (string) GETPOST('label', 'alphanohtml');
|
|
|
|
|
$description = (string) GETPOST('description', 'restricthtml');
|
|
|
|
|
$color = preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml'));
|
2020-10-25 18:44:01 +00:00
|
|
|
$visible = (int) GETPOST('visible', 'int');
|
|
|
|
|
$parent = (int) GETPOST('parent', 'int');
|
2012-07-28 09:28:37 +00:00
|
|
|
|
2020-10-25 18:44:01 +00:00
|
|
|
if ($id == "") {
|
2019-01-27 10:55:16 +00:00
|
|
|
dol_print_error('', 'Missing parameter id');
|
2011-08-20 09:02:56 +00:00
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-28 01:14:35 +00:00
|
|
|
// Security check
|
2012-03-20 14:45:15 +00:00
|
|
|
$result = restrictedArea($user, 'categorie', $id, '&category');
|
2009-08-28 01:14:35 +00:00
|
|
|
|
2014-03-16 15:04:18 +00:00
|
|
|
$object = new Categorie($db);
|
2020-11-21 12:28:37 +00:00
|
|
|
$result = $object->fetch($id, $label);
|
|
|
|
|
if ($result <= 0) {
|
|
|
|
|
dol_print_error($db, $object->error); exit;
|
2015-12-19 12:55:27 +00:00
|
|
|
}
|
2009-08-28 01:14:35 +00:00
|
|
|
|
2020-11-21 12:28:37 +00:00
|
|
|
$type = $object->type;
|
2021-02-23 17:04:37 +00:00
|
|
|
if (is_numeric($type)) {
|
|
|
|
|
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
|
|
|
|
|
}
|
2020-11-21 12:28:37 +00:00
|
|
|
|
2014-03-16 15:04:18 +00:00
|
|
|
$extrafields = new ExtraFields($db);
|
2019-10-06 12:41:52 +00:00
|
|
|
$extrafields->fetch_name_optionals_label($object->table_element);
|
2009-08-28 01:14:35 +00:00
|
|
|
|
2015-06-12 14:10:23 +00:00
|
|
|
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
|
|
|
|
|
$hookmanager->initHooks(array('categorycard'));
|
|
|
|
|
|
2020-10-27 18:14:03 +00:00
|
|
|
$error = 0;
|
|
|
|
|
|
2015-12-19 12:55:27 +00:00
|
|
|
|
2009-08-28 01:14:35 +00:00
|
|
|
/*
|
|
|
|
|
* Actions
|
|
|
|
|
*/
|
|
|
|
|
|
2020-10-25 18:44:01 +00:00
|
|
|
if ($cancel) {
|
2020-11-21 21:40:31 +00:00
|
|
|
if ($backtopage) {
|
|
|
|
|
header("Location: ".$backtopage);
|
|
|
|
|
exit;
|
|
|
|
|
} else {
|
|
|
|
|
header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2015-12-19 12:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-28 01:14:35 +00:00
|
|
|
// Action mise a jour d'une categorie
|
2020-10-25 18:44:01 +00:00
|
|
|
if ($action == 'update' && $user->rights->categorie->creer) {
|
2020-10-31 13:32:18 +00:00
|
|
|
$object->oldcopy = dol_clone($object);
|
2021-02-23 17:04:37 +00:00
|
|
|
$object->label = $label;
|
2015-12-19 12:55:27 +00:00
|
|
|
$object->description = dol_htmlcleanlastbr($description);
|
|
|
|
|
$object->color = $color;
|
2020-10-27 18:14:03 +00:00
|
|
|
$object->socid = ($socid > 0 ? $socid : 0);
|
2015-12-19 12:55:27 +00:00
|
|
|
$object->visible = $visible;
|
2020-10-31 13:32:18 +00:00
|
|
|
$object->fk_parent = $parent != -1 ? $parent : 0;
|
2009-03-02 19:07:12 +00:00
|
|
|
|
2020-10-25 18:44:01 +00:00
|
|
|
if (empty($object->label)) {
|
2020-10-31 13:32:18 +00:00
|
|
|
$error++;
|
2015-09-22 09:29:26 +00:00
|
|
|
$action = 'edit';
|
2015-10-17 14:18:33 +00:00
|
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
|
2007-11-12 21:03:22 +00:00
|
|
|
}
|
2020-10-25 18:44:01 +00:00
|
|
|
if (!$error && empty($object->error)) {
|
2021-12-06 10:19:12 +00:00
|
|
|
$ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
|
2021-02-23 17:04:37 +00:00
|
|
|
if ($ret < 0) {
|
|
|
|
|
$error++;
|
|
|
|
|
}
|
2015-02-26 13:25:30 +00:00
|
|
|
|
2021-02-23 17:04:37 +00:00
|
|
|
if (!$error && $object->update($user) > 0) {
|
2020-11-21 21:40:31 +00:00
|
|
|
if ($backtopage) {
|
|
|
|
|
header("Location: ".$backtopage);
|
|
|
|
|
exit;
|
|
|
|
|
} else {
|
|
|
|
|
header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2020-05-21 13:05:19 +00:00
|
|
|
} else {
|
2015-12-19 12:55:27 +00:00
|
|
|
setEventMessages($object->error, $object->errors, 'errors');
|
2007-11-12 21:03:22 +00:00
|
|
|
}
|
2020-05-21 13:05:19 +00:00
|
|
|
} else {
|
2015-12-19 12:55:27 +00:00
|
|
|
setEventMessages($object->error, $object->errors, 'errors');
|
2006-03-13 16:40:34 +00:00
|
|
|
}
|
2005-04-13 12:22:29 +00:00
|
|
|
}
|
2006-08-15 18:52:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2010-02-28 16:14:00 +00:00
|
|
|
* View
|
2006-08-15 18:52:02 +00:00
|
|
|
*/
|
|
|
|
|
|
2015-08-12 23:33:04 +00:00
|
|
|
$form = new Form($db);
|
2015-09-17 18:00:54 +00:00
|
|
|
$formother = new FormOther($db);
|
2015-08-12 23:33:04 +00:00
|
|
|
|
2019-01-27 10:55:16 +00:00
|
|
|
llxHeader("", "", $langs->trans("Categories"));
|
2006-08-15 18:52:02 +00:00
|
|
|
|
2015-09-24 16:33:48 +00:00
|
|
|
print load_fiche_titre($langs->trans("ModifCat"));
|
2009-03-02 19:07:12 +00:00
|
|
|
|
2012-05-21 13:45:44 +00:00
|
|
|
$object->fetch($id);
|
|
|
|
|
|
2006-08-15 18:52:02 +00:00
|
|
|
|
|
|
|
|
print "\n";
|
|
|
|
|
print '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
|
2019-12-18 22:12:31 +00:00
|
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
2006-08-15 18:52:02 +00:00
|
|
|
print '<input type="hidden" name="action" value="update">';
|
2012-05-21 13:45:44 +00:00
|
|
|
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
2008-10-08 08:03:28 +00:00
|
|
|
print '<input type="hidden" name="type" value="'.$type.'">';
|
2020-11-21 21:40:31 +00:00
|
|
|
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
|
2006-04-01 02:37:23 +00:00
|
|
|
|
2020-10-22 20:50:03 +00:00
|
|
|
print dol_get_fiche_head('');
|
2015-08-12 23:33:04 +00:00
|
|
|
|
2019-11-05 20:24:41 +00:00
|
|
|
print '<table class="border centpercent">';
|
2010-10-19 22:52:32 +00:00
|
|
|
|
|
|
|
|
// Ref
|
2016-08-29 15:36:18 +00:00
|
|
|
print '<tr><td class="titlefieldcreate fieldrequired">';
|
2007-02-04 01:39:39 +00:00
|
|
|
print $langs->trans("Ref").'</td>';
|
2015-05-04 23:43:39 +00:00
|
|
|
print '<td><input type="text" size="25" id="label" name ="label" value="'.$object->label.'" />';
|
2006-12-19 20:33:32 +00:00
|
|
|
print '</tr>';
|
2006-07-30 00:37:31 +00:00
|
|
|
|
2010-10-19 22:52:32 +00:00
|
|
|
// Description
|
2006-12-19 20:33:32 +00:00
|
|
|
print '<tr>';
|
2015-09-22 09:29:26 +00:00
|
|
|
print '<td>'.$langs->trans("Description").'</td>';
|
2020-11-27 13:24:15 +00:00
|
|
|
print '<td>';
|
2012-08-22 21:11:24 +00:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
2019-11-13 18:35:39 +00:00
|
|
|
$doleditor = new DolEditor('description', $object->description, '', 200, 'dolibarr_notes', '', false, true, $conf->fckeditor->enabled, ROWS_6, '90%');
|
2010-09-02 18:51:47 +00:00
|
|
|
$doleditor->Create();
|
2006-12-19 20:33:32 +00:00
|
|
|
print '</td></tr>';
|
2010-10-19 22:52:32 +00:00
|
|
|
|
2015-09-17 17:51:56 +00:00
|
|
|
// Color
|
|
|
|
|
print '<tr>';
|
2015-09-17 18:00:54 +00:00
|
|
|
print '<td>'.$langs->trans("Color").'</td>';
|
2020-11-27 13:24:15 +00:00
|
|
|
print '<td>';
|
2015-09-24 18:40:40 +00:00
|
|
|
print $formother->selectColor($object->color, 'color');
|
2015-09-17 17:51:56 +00:00
|
|
|
print '</td></tr>';
|
|
|
|
|
|
2010-10-19 22:52:32 +00:00
|
|
|
// Parent category
|
2011-08-28 02:18:20 +00:00
|
|
|
print '<tr><td>'.$langs->trans("In").'</td><td>';
|
2022-02-21 15:54:07 +00:00
|
|
|
print img_picto('', 'category', 'class="pictofixedwidth"');
|
2019-01-27 10:55:16 +00:00
|
|
|
print $form->select_all_categories($type, $object->fk_parent, 'parent', 64, $object->id);
|
2022-02-21 15:54:07 +00:00
|
|
|
print ajax_combobox('parent');
|
2010-10-19 22:52:32 +00:00
|
|
|
print '</td></tr>';
|
|
|
|
|
|
2019-11-13 18:35:39 +00:00
|
|
|
$parameters = array();
|
|
|
|
|
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
2017-06-11 08:37:58 +00:00
|
|
|
print $hookmanager->resPrint;
|
2020-10-25 18:44:01 +00:00
|
|
|
if (empty($reshook)) {
|
2019-11-16 13:38:05 +00:00
|
|
|
print $object->showOptionals($extrafields, 'edit', $parameters);
|
2014-03-16 15:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-13 21:27:33 +00:00
|
|
|
print '</table>';
|
2015-08-12 23:33:04 +00:00
|
|
|
|
|
|
|
|
|
2020-10-27 17:19:31 +00:00
|
|
|
print dol_get_fiche_end();
|
2015-08-12 23:33:04 +00:00
|
|
|
|
2005-04-13 12:22:29 +00:00
|
|
|
|
2020-11-23 14:12:52 +00:00
|
|
|
print '<div class="center"><input type="submit" class="button" name"submit" value="'.$langs->trans("Modify").'"> <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
|
2009-03-02 19:07:12 +00:00
|
|
|
|
2010-03-13 21:27:33 +00:00
|
|
|
print '</form>';
|
2005-04-13 12:22:29 +00:00
|
|
|
|
2018-07-29 11:40:35 +00:00
|
|
|
// End of page
|
2011-08-27 14:24:16 +00:00
|
|
|
llxFooter();
|
2012-05-21 13:45:44 +00:00
|
|
|
$db->close();
|