2006-02-21 16:01:41 +01:00
|
|
|
<?php
|
|
|
|
|
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
|
2011-08-24 13:16:43 +02:00
|
|
|
* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
2012-12-30 15:13:49 +01:00
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
2009-08-28 18:37:45 +02:00
|
|
|
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
|
2013-07-16 21:04:58 +02:00
|
|
|
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
2006-02-21 16:01:41 +01: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
|
2006-02-21 16:01:41 +01: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
|
2011-08-03 02:45:22 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-02-21 16:01:41 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2009-08-28 18:37:45 +02:00
|
|
|
* \file htdocs/categories/fiche.php
|
|
|
|
|
* \ingroup category
|
|
|
|
|
* \brief Page to create a new category
|
|
|
|
|
*/
|
2006-02-21 16:01:41 +01: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';
|
2006-02-21 16:01:41 +01:00
|
|
|
|
2010-06-02 22:01:13 +02:00
|
|
|
$langs->load("categories");
|
|
|
|
|
|
2009-08-28 03:14:35 +02:00
|
|
|
|
|
|
|
|
// Security check
|
2012-02-27 22:26:22 +01:00
|
|
|
$socid=GETPOST('socid','int');
|
2006-02-21 16:01:41 +01:00
|
|
|
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');
|
2006-02-21 16:01:41 +01:00
|
|
|
|
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');
|
|
|
|
|
$visible=GETPOST('visible');
|
2012-10-08 19:27:02 +02:00
|
|
|
$parent=GETPOST('parent');
|
2012-07-28 11:28:37 +02:00
|
|
|
|
2011-03-19 13:47:39 +01:00
|
|
|
if ($origin)
|
2006-03-25 18:02:50 +01:00
|
|
|
{
|
2011-03-19 13:47:39 +01:00
|
|
|
if ($type == 0) $idProdOrigin = $origin;
|
|
|
|
|
if ($type == 1) $idSupplierOrigin = $origin;
|
|
|
|
|
if ($type == 2) $idCompanyOrigin = $origin;
|
|
|
|
|
if ($type == 3) $idMemberOrigin = $origin;
|
2013-07-16 21:04:58 +02:00
|
|
|
if ($type == 4) $idContactOrigin = $origin;
|
2008-10-07 14:24:33 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-19 13:47:39 +01:00
|
|
|
if ($catorigin && $type == 0) $idCatOrigin = $catorigin;
|
2008-10-07 11:36:33 +02:00
|
|
|
|
2006-02-21 16:01:41 +01:00
|
|
|
|
2007-11-12 22:47:20 +01:00
|
|
|
/*
|
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)
|
2006-02-22 18:37:32 +01:00
|
|
|
{
|
2008-10-07 10:46:31 +02:00
|
|
|
// Action ajout d'une categorie
|
2011-03-19 13:47:39 +01:00
|
|
|
if ($cancel)
|
2007-11-12 22:47:20 +01:00
|
|
|
{
|
2010-03-20 01:07:47 +01:00
|
|
|
if ($urlfrom)
|
|
|
|
|
{
|
|
|
|
|
header("Location: ".$urlfrom);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
else if ($idProdOrigin)
|
2007-11-12 22:47:20 +01:00
|
|
|
{
|
2011-03-19 13:47:39 +01:00
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?id='.$idProdOrigin.'&type='.$type);
|
2007-11-12 22:47:20 +01:00
|
|
|
exit;
|
|
|
|
|
}
|
2008-10-07 10:46:31 +02:00
|
|
|
else if ($idCompanyOrigin)
|
2007-11-12 22:47:20 +01:00
|
|
|
{
|
2011-03-19 13:47:39 +01:00
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idCompanyOrigin.'&type='.$type);
|
2008-02-15 01:12:30 +01:00
|
|
|
exit;
|
|
|
|
|
}
|
2008-10-07 10:46:31 +02:00
|
|
|
else if ($idSupplierOrigin)
|
2008-02-15 01:12:30 +01:00
|
|
|
{
|
2011-03-19 13:47:39 +01:00
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idSupplierOrigin.'&type='.$type);
|
2007-11-12 22:47:20 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2008-10-07 14:24:33 +02:00
|
|
|
else if ($idCatOrigin)
|
|
|
|
|
{
|
2011-03-19 13:47:39 +01:00
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCatOrigin.'&type='.$type);
|
2008-10-07 14:24:33 +02:00
|
|
|
exit;
|
|
|
|
|
}
|
2013-07-16 21:04:58 +02:00
|
|
|
else if ($idContactOrigin)
|
|
|
|
|
{
|
|
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2008-10-07 10:46:31 +02:00
|
|
|
else
|
|
|
|
|
{
|
2011-03-19 13:47:39 +01:00
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type);
|
2008-10-07 10:46:31 +02:00
|
|
|
exit;
|
|
|
|
|
}
|
2007-11-12 22:47:20 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-19 13:47:39 +01:00
|
|
|
$object = new Categorie($db);
|
2006-03-03 21:52:01 +01:00
|
|
|
|
2013-02-19 15:33:49 +01:00
|
|
|
$object->label = $label;
|
2013-04-28 01:12:40 +02:00
|
|
|
$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;
|
2008-10-07 11:36:33 +02:00
|
|
|
|
2012-10-08 19:27:02 +02:00
|
|
|
if ($parent != "-1") $object->fk_parent = $parent;
|
2006-07-30 02:37:31 +02:00
|
|
|
|
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++;
|
|
|
|
|
$errors[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref"));
|
|
|
|
|
$action = 'create';
|
2007-02-22 22:04:33 +01:00
|
|
|
}
|
2009-08-28 03:14:35 +02:00
|
|
|
|
2009-08-28 18:37:45 +02:00
|
|
|
// Create category in database
|
2012-07-28 11:28:37 +02:00
|
|
|
if (! $error)
|
2006-03-03 21:52:01 +01:00
|
|
|
{
|
2011-03-19 13:47:39 +01:00
|
|
|
$result = $object->create();
|
2007-12-05 15:11:44 +01:00
|
|
|
if ($result > 0)
|
2006-03-03 21:52:01 +01:00
|
|
|
{
|
2011-03-19 13:47:39 +01:00
|
|
|
$action = 'confirmed';
|
2006-03-13 17:40:34 +01:00
|
|
|
$_POST["addcat"] = '';
|
2006-03-03 21:52:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
2007-11-12 22:47:20 +01:00
|
|
|
}
|
|
|
|
|
|
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)
|
2007-11-12 22:47:20 +01:00
|
|
|
{
|
2008-02-15 01:12:30 +01:00
|
|
|
// Action confirmation de creation categorie
|
2011-03-19 13:47:39 +01:00
|
|
|
if ($action == 'confirmed')
|
2006-07-30 02:37:31 +02:00
|
|
|
{
|
2010-03-20 01:07:47 +01:00
|
|
|
if ($urlfrom)
|
|
|
|
|
{
|
|
|
|
|
header("Location: ".$urlfrom);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
else if ($idProdOrigin)
|
2006-07-30 02:37:31 +02:00
|
|
|
{
|
2007-11-12 23:13:15 +01:00
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?id='.$idProdOrigin.'&mesg='.urlencode($langs->trans("CatCreated")));
|
|
|
|
|
exit;
|
2006-07-30 02:37:31 +02:00
|
|
|
}
|
2010-03-20 01:07:47 +01:00
|
|
|
else if ($idCompanyOrigin)
|
2007-04-30 12:53:58 +02:00
|
|
|
{
|
2007-11-12 23:13:15 +01:00
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idCompanyOrigin.'&mesg='.urlencode($langs->trans("CatCreated")));
|
|
|
|
|
exit;
|
2007-04-30 12:53:58 +02:00
|
|
|
}
|
2010-03-20 01:07:47 +01:00
|
|
|
else if ($idSupplierOrigin)
|
2007-12-05 15:11:44 +01:00
|
|
|
{
|
2008-02-15 01:12:30 +01:00
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idSupplierOrigin.'&mesg='.urlencode($langs->trans("CatCreated")));
|
2007-12-05 15:11:44 +01:00
|
|
|
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 ($idCatOrigin)
|
2008-10-07 14:24:33 +02:00
|
|
|
{
|
|
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCatOrigin.'&mesg='.urlencode($langs->trans("CatCreated")));
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2013-07-16 21:04:58 +02:00
|
|
|
else if ($idContactOrigin)
|
|
|
|
|
{
|
|
|
|
|
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&mesg='.urlencode($langs->trans("CatCreated")));
|
|
|
|
|
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;
|
2006-07-30 02:37:31 +02:00
|
|
|
}
|
2006-02-22 18:37:32 +01:00
|
|
|
}
|
|
|
|
|
|
2006-02-22 15:38:14 +01:00
|
|
|
|
2009-08-28 18:37:45 +02:00
|
|
|
/*
|
|
|
|
|
* View
|
|
|
|
|
*/
|
2007-11-12 23:13:15 +01:00
|
|
|
|
2011-11-08 10:18:45 +01:00
|
|
|
$form = new Form($db);
|
2007-11-12 23:13:15 +01:00
|
|
|
|
2013-09-06 12:10:09 +02:00
|
|
|
llxHeader("","",$langs->trans("Categories"));
|
|
|
|
|
|
2006-07-30 02:37:31 +02:00
|
|
|
if ($user->rights->categorie->creer)
|
2006-02-21 16:01:41 +01:00
|
|
|
{
|
2006-03-13 17:40:34 +01:00
|
|
|
/*
|
2008-02-15 01:12:30 +01:00
|
|
|
* Fiche en mode creation
|
2006-07-30 02:37:31 +02:00
|
|
|
*/
|
2011-03-19 13:47:39 +01:00
|
|
|
if ($action == 'create' || $_POST["addcat"] == 'addcat')
|
2006-03-03 21:52:01 +01:00
|
|
|
{
|
2013-02-19 15:33:49 +01:00
|
|
|
dol_set_focus('#label');
|
2013-04-28 01:12:40 +02:00
|
|
|
|
2011-03-19 13:47:39 +01:00
|
|
|
print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$type.'" method="POST">';
|
2009-05-17 10:01:54 +02:00
|
|
|
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.'">';
|
2006-03-03 21:52:01 +01:00
|
|
|
print '<input type="hidden" name="action" value="add">';
|
|
|
|
|
print '<input type="hidden" name="addcat" value="addcat">';
|
2010-11-07 23:02:35 +01:00
|
|
|
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.'">';
|
2007-12-28 18:09:13 +01:00
|
|
|
|
2006-03-03 21:52:01 +01:00
|
|
|
print_fiche_titre($langs->trans("CreateCat"));
|
2006-02-22 15:38:14 +01:00
|
|
|
|
2012-07-28 11:28:37 +02:00
|
|
|
dol_htmloutput_errors('',$errors);
|
2009-08-28 18:37:45 +02:00
|
|
|
|
2007-12-28 18:09:13 +01:00
|
|
|
print '<table width="100%" class="border">';
|
2010-10-20 00:52:32 +02:00
|
|
|
|
|
|
|
|
// Ref
|
2006-03-03 21:52:01 +01:00
|
|
|
print '<tr>';
|
2013-05-10 12:48:11 +02:00
|
|
|
print '<td width="25%" class="fieldrequired">'.$langs->trans("Ref").'</td><td><input id="label" class="flat" name="label" size="25" value="'.$label.'">';
|
2006-03-03 21:52:01 +01:00
|
|
|
print'</td></tr>';
|
2010-10-20 00:52:32 +02:00
|
|
|
|
|
|
|
|
// Description
|
2006-03-03 21:52:01 +01:00
|
|
|
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
2012-07-28 11:28:37 +02:00
|
|
|
$doleditor=new DolEditor('description',$description,'',200,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_PRODUCTDESC,ROWS_6,50);
|
2010-09-02 20:51:47 +02:00
|
|
|
$doleditor->Create();
|
2006-07-30 02:37:31 +02:00
|
|
|
print '</td></tr>';
|
2010-03-13 00:59:23 +01:00
|
|
|
|
2010-10-20 00:52:32 +02:00
|
|
|
// Parent category
|
2011-08-28 04:18:20 +02:00
|
|
|
print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
|
2012-10-08 19:27:02 +02:00
|
|
|
print $form->select_all_categories($type, $catorigin);
|
2010-03-13 00:59:23 +01:00
|
|
|
print '</td></tr>';
|
|
|
|
|
|
2010-02-28 17:14:00 +01:00
|
|
|
print '</table>';
|
|
|
|
|
|
|
|
|
|
print '<center><br>';
|
2007-12-28 18:09:13 +01:00
|
|
|
print '<input type="submit" class="button" value="'.$langs->trans("CreateThisCat").'" name="creation" />';
|
2007-11-12 22:47:20 +01:00
|
|
|
print ' ';
|
|
|
|
|
print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel" />';
|
2010-02-28 17:14:00 +01:00
|
|
|
print '</center>';
|
|
|
|
|
|
2007-12-28 18:09:13 +01:00
|
|
|
print '</form>';
|
2006-03-03 21:52:01 +01:00
|
|
|
}
|
2006-02-21 16:01:41 +01:00
|
|
|
}
|
2006-03-03 21:52:01 +01:00
|
|
|
|
2006-02-21 16:01:41 +01:00
|
|
|
|
2011-08-27 16:24:16 +02:00
|
|
|
llxFooter();
|
2013-02-19 15:33:49 +01:00
|
|
|
|
|
|
|
|
$db->close();
|
2006-02-21 16:01:41 +01:00
|
|
|
?>
|