Add button to create category

This commit is contained in:
Laurent Destailleur 2011-08-24 11:16:43 +00:00
parent 1d86914fea
commit 89128f7747
2 changed files with 22 additions and 16 deletions

View File

@ -24,7 +24,7 @@
* \file htdocs/categories/categorie.php * \file htdocs/categories/categorie.php
* \ingroup category * \ingroup category
* \brief Page to show category tab * \brief Page to show category tab
* \version $Id: categorie.php,v 1.66 2011/08/18 22:33:43 eldy Exp $ * \version $Id: categorie.php,v 1.67 2011/08/24 11:16:43 eldy Exp $
*/ */
require("../main.inc.php"); require("../main.inc.php");
@ -33,7 +33,10 @@ require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php");
$langs->load("categories"); $langs->load("categories");
$langs->load("products"); $langs->load("products");
$mesg=isset($_GET["mesg"])?'<div class="ok">'.$_GET["mesg"].'</div>':''; $socid=GETPOST('socid');
$id=GETPOST('id');
$ref=GETPOST('ref');
$mesg=GETPOST('mesg');
$dbtablename = ''; $dbtablename = '';
@ -41,10 +44,11 @@ $dbtablename = '';
// For categories on third parties // For categories on third parties
if (! empty($_REQUEST["socid"])) { if (! empty($_REQUEST["socid"])) {
$_REQUEST["id"]=$_REQUEST["socid"]; $_REQUEST["id"]=$_REQUEST["socid"];
$id=$socid;
} }
if (! isset($_REQUEST["type"])) $_REQUEST["type"]=0; if (! isset($_REQUEST["type"])) $_REQUEST["type"]=0;
if ($_REQUEST["type"] == 1) $_GET["socid"]=$_REQUEST["id"]; if ($_REQUEST["type"] == 1) $socid=$id;
if ($_REQUEST["type"] == 2) $_GET["socid"]=$_REQUEST["id"]; if ($_REQUEST["type"] == 2) $socid=$id;
if ($_REQUEST["id"] || $_REQUEST["ref"]) if ($_REQUEST["id"] || $_REQUEST["ref"])
{ {
@ -56,13 +60,13 @@ if ($_REQUEST["id"] || $_REQUEST["ref"])
$fieldid = isset($_REQUEST["ref"])?'ref':'rowid'; $fieldid = isset($_REQUEST["ref"])?'ref':'rowid';
} }
if ($_REQUEST["type"] == 1) { if ($_REQUEST["type"] == 1) {
$type = 'fournisseur'; $socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; $type = 'fournisseur';
$objecttype = 'societe&categorie'; $objecttype = 'societe&categorie';
$objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["socid"])?$_REQUEST["socid"]:''); $objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["socid"])?$_REQUEST["socid"]:'');
$fieldid = 'rowid'; $fieldid = 'rowid';
} }
if ($_REQUEST["type"] == 2) { if ($_REQUEST["type"] == 2) {
$type = 'societe'; $socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; $type = 'societe';
$objecttype = 'societe&categorie'; $objecttype = 'societe&categorie';
$objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["socid"])?$_REQUEST["socid"]:''); $objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["socid"])?$_REQUEST["socid"]:'');
$fieldid = 'rowid'; $fieldid = 'rowid';
@ -161,8 +165,8 @@ if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0)
} }
else else
{ {
if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') $mesg='<div class="warning">'.$langs->trans("ObjectAlreadyLinkedToCategory").'</div>'; if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') $mesg='<div class="error">'.$langs->trans("ObjectAlreadyLinkedToCategory").'</div>';
else $mesg='<div class="error">'.$langs->trans("Error").' '.$cat->error.'</div>'; else $mesg=$langs->trans("Error").' '.$cat->error;
} }
} }
@ -174,10 +178,11 @@ if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0)
$html = new Form($db); $html = new Form($db);
/* /*
* Fiche categorie de client et/ou fournisseur * Fiche categorie de client et/ou fournisseur
*/ */
if ($_GET["socid"]) if ($socid)
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"); require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
@ -189,7 +194,7 @@ if ($_GET["socid"])
* Creation de l'objet client/fournisseur correspondant au socid * Creation de l'objet client/fournisseur correspondant au socid
*/ */
$soc = new Societe($db); $soc = new Societe($db);
$result = $soc->fetch($_GET["socid"]); $result = $soc->fetch($socid);
llxHeader("","",$langs->trans("Category")); llxHeader("","",$langs->trans("Category"));
@ -275,7 +280,7 @@ if ($_GET["socid"])
print '</div>'; print '</div>';
if ($mesg) print($mesg); dol_htmloutput_mesg($mesg);
if ($soc->client) formCategory($db,$soc,2); if ($soc->client) formCategory($db,$soc,2);
@ -336,7 +341,7 @@ else if ($_GET["id"] || $_GET["ref"])
print '</div>'; print '</div>';
if ($mesg) print($mesg); dol_htmloutput_mesg($mesg);
formCategory($db,$product,0); formCategory($db,$product,0);
} }
@ -455,6 +460,7 @@ function formCategory($db,$object,$typeid)
{ {
print '<td align="right">'; print '<td align="right">';
print "<a href='".DOL_URL_ROOT."/categories/fiche.php?action=create&amp;origin=".$object->id."&type=".$typeid."&urlfrom=".urlencode($_SERVER["PHP_SELF"].'?'.(($typeid==1||$typeid==2)?'socid':'id').'='.$object->id.'&type='.$typeid)."'>"; print "<a href='".DOL_URL_ROOT."/categories/fiche.php?action=create&amp;origin=".$object->id."&type=".$typeid."&urlfrom=".urlencode($_SERVER["PHP_SELF"].'?'.(($typeid==1||$typeid==2)?'socid':'id').'='.$object->id.'&type='.$typeid)."'>";
print $langs->trans("CreateCat").' ';
print img_picto($langs->trans("Create"),'filenew'); print img_picto($langs->trans("Create"),'filenew');
print "</a>"; print "</a>";
print '</td>'; print '</td>';
@ -534,5 +540,5 @@ function formCategory($db,$object,$typeid)
$db->close(); $db->close();
llxFooter('$Date: 2011/08/18 22:33:43 $ - $Revision: 1.66 $'); llxFooter('$Date: 2011/08/24 11:16:43 $ - $Revision: 1.67 $');
?> ?>

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org> /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com> * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* *
@ -22,7 +22,7 @@
* \file htdocs/categories/fiche.php * \file htdocs/categories/fiche.php
* \ingroup category * \ingroup category
* \brief Page to create a new category * \brief Page to create a new category
* \version $Id: fiche.php,v 1.85 2011/08/03 00:46:32 eldy Exp $ * \version $Id: fiche.php,v 1.86 2011/08/24 11:16:43 eldy Exp $
*/ */
require("../main.inc.php"); require("../main.inc.php");
@ -234,5 +234,5 @@ if ($user->rights->categorie->creer)
$db->close(); $db->close();
llxFooter('$Date: 2011/08/03 00:46:32 $ - $Revision: 1.85 $'); llxFooter('$Date: 2011/08/24 11:16:43 $ - $Revision: 1.86 $');
?> ?>