dolibarr/htdocs/categories/card.php

295 lines
8.8 KiB
PHP
Raw Normal View History

<?php
2014-10-02 09:30:31 +02:00
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
2017-06-21 11:37:34 +02:00
* Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
2014-10-02 09:30:31 +02:00
* Copyright (C) 2005-2014 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
2015-05-23 18:52:31 +02:00
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (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
2011-08-03 02:45:22 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/categories/card.php
* \ingroup category
* \brief Page to create a new category
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
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';
2018-05-27 09:58:23 +02:00
// Load translation files required by the page
2010-06-02 22:01:13 +02:00
$langs->load("categories");
// Security check
2012-02-27 22:26:22 +01:00
$socid=GETPOST('socid','int');
if (!$user->rights->categorie->lire) accessforbidden();
2012-02-28 19:18:24 +01:00
$action = GETPOST('action','alpha');
$cancel = GETPOST('cancel','alpha');
$origin = GETPOST('origin','alpha');
$catorigin = GETPOST('catorigin','int');
$type = GETPOST('type','alpha');
$urlfrom = GETPOST('urlfrom','alpha');
2012-07-28 11:28:37 +02:00
$socid=GETPOST('socid','int');
2013-02-19 15:33:49 +01:00
$label=GETPOST('label');
2012-07-28 11:28:37 +02:00
$description=GETPOST('description');
2015-09-17 20:00:54 +02:00
$color=GETPOST('color');
2012-07-28 11:28:37 +02:00
$visible=GETPOST('visible');
$parent=GETPOST('parent');
2012-07-28 11:28:37 +02:00
2011-03-19 13:47:39 +01:00
if ($origin)
{
2015-05-23 18:52:31 +02:00
if ($type == Categorie::TYPE_PRODUCT) $idProdOrigin = $origin;
if ($type == Categorie::TYPE_SUPPLIER) $idSupplierOrigin = $origin;
if ($type == Categorie::TYPE_CUSTOMER) $idCompanyOrigin = $origin;
if ($type == Categorie::TYPE_MEMBER) $idMemberOrigin = $origin;
if ($type == Categorie::TYPE_CONTACT) $idContactOrigin = $origin;
2016-08-29 10:32:00 +02:00
if ($type == Categorie::TYPE_PROJECT) $idProjectOrigin = $origin;
}
2015-05-23 18:52:31 +02:00
if ($catorigin && $type == Categorie::TYPE_PRODUCT) $idCatOrigin = $catorigin;
$object = new Categorie($db);
$extrafields = new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('categorycard'));
/*
2010-01-19 10:54:04 +01:00
* Actions
*/
2006-02-23 12:09:21 +01:00
2010-07-29 15:13:41 +02:00
// Add action
2011-03-19 13:47:39 +01:00
if ($action == 'add' && $user->rights->categorie->creer)
{
// Action ajout d'une categorie
2011-03-19 13:47:39 +01:00
if ($cancel)
{
2010-03-20 01:07:47 +01:00
if ($urlfrom)
{
header("Location: ".$urlfrom);
exit;
}
else if ($idProdOrigin)
{
2016-08-29 21:31:27 +02:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type);
exit;
}
else if ($idCompanyOrigin)
{
2016-08-29 21:31:27 +02:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type);
2008-02-15 01:12:30 +01:00
exit;
}
else if ($idSupplierOrigin)
2008-02-15 01:12:30 +01:00
{
2016-08-29 21:31:27 +02:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type);
exit;
}
2010-03-20 01:07:47 +01:00
else if ($idMemberOrigin)
{
2011-03-19 13:47:39 +01:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type);
2010-03-20 01:07:47 +01:00
exit;
}
else if ($idContactOrigin)
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type);
exit;
}
2016-08-29 10:32:00 +02:00
else if ($idProjectOrigin)
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type);
exit;
}
else
{
2011-03-19 13:47:39 +01:00
header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type);
exit;
}
}
2014-10-02 09:30:31 +02:00
2013-02-19 15:33:49 +01:00
$object->label = $label;
2015-09-17 20:00:54 +02:00
$object->color = $color;
$object->description = dol_htmlcleanlastbr($description);
2012-07-28 11:28:37 +02:00
$object->socid = ($socid ? $socid : 'null');
$object->visible = $visible;
2011-03-19 13:47:39 +01:00
$object->type = $type;
if ($parent != "-1") $object->fk_parent = $parent;
2014-10-02 09:30:31 +02:00
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
2015-02-26 14:25:30 +01:00
if ($ret < 0) $error++;
2011-03-19 13:47:39 +01:00
if (! $object->label)
2007-02-22 22:04:33 +01:00
{
2012-07-28 11:28:37 +02:00
$error++;
2015-10-17 16:18:33 +02:00
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
2012-07-28 11:28:37 +02:00
$action = 'create';
2007-02-22 22:04:33 +01:00
}
// Create category in database
2012-07-28 11:28:37 +02:00
if (! $error)
{
2014-07-29 11:15:32 +02:00
$result = $object->create($user);
if ($result > 0)
{
2011-03-19 13:47:39 +01:00
$action = 'confirmed';
2006-03-13 17:40:34 +01:00
$_POST["addcat"] = '';
}
else
{
2015-10-31 17:21:48 +01:00
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
2010-07-29 15:13:41 +02:00
// Confirm action
2011-07-04 11:54:02 +02:00
if (($action == 'add' || $action == 'confirmed') && $user->rights->categorie->creer)
{
2008-02-15 01:12:30 +01:00
// Action confirmation de creation categorie
2011-03-19 13:47:39 +01:00
if ($action == 'confirmed')
{
2010-03-20 01:07:47 +01:00
if ($urlfrom)
{
header("Location: ".$urlfrom);
exit;
}
else if ($idProdOrigin)
{
2016-08-29 21:31:27 +02:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
}
2010-03-20 01:07:47 +01:00
else if ($idCompanyOrigin)
{
2016-08-29 21:31:27 +02:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
}
2010-03-20 01:07:47 +01:00
else if ($idSupplierOrigin)
{
2016-08-29 21:31:27 +02:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
}
2010-03-20 01:07:47 +01:00
else if ($idMemberOrigin)
{
2016-08-29 21:31:27 +02:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
}
else if ($idContactOrigin)
{
2016-08-29 21:31:27 +02:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
}
2016-08-29 10:32:00 +02:00
else if ($idProjectOrigin)
{
2016-08-29 21:31:27 +02:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$type.'&mesg='.urlencode($langs->trans("CatCreated")));
2016-08-29 10:32:00 +02:00
exit;
}
2008-02-15 01:12:30 +01:00
2011-03-19 13:47:39 +01:00
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$type);
2008-02-15 01:12:30 +01:00
exit;
}
}
/*
* View
*/
$form = new Form($db);
2015-09-17 20:00:54 +02:00
$formother = new FormOther($db);
2016-08-10 15:16:30 +02:00
$helpurl='';
llxHeader("",$langs->trans("Categories"),$helpurl);
if ($user->rights->categorie->creer)
{
2017-06-21 11:37:34 +02:00
// Create or add
2011-03-19 13:47:39 +01:00
if ($action == 'create' || $_POST["addcat"] == 'addcat')
{
2013-02-19 15:33:49 +01:00
dol_set_focus('#label');
2011-03-19 13:47:39 +01:00
print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$type.'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2010-03-20 01:07:47 +01:00
print '<input type="hidden" name="urlfrom" value="'.$urlfrom.'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="addcat" value="addcat">';
print '<input type="hidden" name="id" value="'.GETPOST('origin').'">';
2011-03-19 13:47:39 +01:00
print '<input type="hidden" name="type" value="'.$type.'">';
if ($origin) print '<input type="hidden" name="origin" value="'.$origin.'">';
if ($catorigin) print '<input type="hidden" name="catorigin" value="'.$catorigin.'">';
print load_fiche_titre($langs->trans("CreateCat"));
dol_fiche_head('');
print '<table width="100%" class="border">';
2010-10-20 00:52:32 +02:00
// Ref
print '<tr>';
2017-06-21 11:37:34 +02:00
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="label" class="minwidth100" name="label" value="'.$label.'">';
print'</td></tr>';
2010-10-20 00:52:32 +02:00
// Description
2017-01-22 12:13:32 +01:00
print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
2016-11-25 17:47:47 +01:00
$doleditor=new DolEditor('description',$description,'',200,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_PRODUCTDESC,ROWS_6,'90%');
$doleditor->Create();
print '</td></tr>';
2015-09-17 20:00:54 +02:00
// Color
print '<tr><td>'.$langs->trans("Color").'</td><td>';
print $formother->selectColor($color,'color');
2015-09-17 20:00:54 +02:00
print '</td></tr>';
2016-08-29 10:32:00 +02:00
2010-10-20 00:52:32 +02:00
// Parent category
print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
2017-06-21 11:37:34 +02:00
print $form->select_all_categories($type, $catorigin, 'parent');
print ajax_combobox('parent');
print '</td></tr>';
2014-10-02 09:30:31 +02: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;
2018-04-13 13:28:48 +02:00
if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
print '</table>';
dol_fiche_end('');
print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("CreateThisCat").'" name="creation" />';
print '&nbsp; &nbsp; &nbsp;';
print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel" />';
2014-11-25 20:13:43 +01:00
print '</div>';
print '</form>';
}
}
llxFooter();
2013-02-19 15:33:49 +01:00
$db->close();