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