Fix: uniformize code

This commit is contained in:
Regis Houssin 2011-10-04 20:47:50 +08:00
parent 0b3cbf9b84
commit 2099cfebf3

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Brice Davoleau <brice.davoleau@gmail.com> * Copyright (C) 2005 Brice Davoleau <brice.davoleau@gmail.com>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com> * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
@ -32,50 +32,47 @@ require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php");
$langs->load("categories"); $langs->load("categories");
$langs->load("products"); $langs->load("products");
$socid=GETPOST('socid'); $socid = GETPOST('socid');
$id=GETPOST('id'); $id = GETPOST('id');
$ref=GETPOST('ref'); $ref = GETPOST('ref');
$mesg=GETPOST('mesg'); $type = GETPOST('type');
$mesg = GETPOST('mesg');
$dbtablename = ''; $dbtablename = '';
// For categories on third parties // For categories on third parties
if (! empty($_REQUEST["socid"])) { if (! empty($socid)) $id = $socid;
$_REQUEST["id"]=$_REQUEST["socid"]; if (! isset($type)) $type = 0;
$id=$socid; if ($type == 1 || $type == 2) $socid = $id;
}
if (! isset($_REQUEST["type"])) $_REQUEST["type"]=0;
if ($_REQUEST["type"] == 1) $socid=$id;
if ($_REQUEST["type"] == 2) $socid=$id;
if ($_REQUEST["id"] || $_REQUEST["ref"]) if ($id || $ref)
{ {
if ($_REQUEST["type"] == 0) { if ($type == 0) {
$type = 'product'; $elementtype = 'product';
$objecttype = 'produit|service&categorie'; $objecttype = 'produit|service&categorie';
$objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["ref"])?$_REQUEST["ref"]:''); $objectid = isset($id)?$id:(isset($ref)?$ref:'');
$dbtablename = 'product'; $dbtablename = 'product';
$fieldid = isset($_REQUEST["ref"])?'ref':'rowid'; $fieldid = isset($ref)?'ref':'rowid';
} }
if ($_REQUEST["type"] == 1) { if ($type == 1) {
$type = 'fournisseur'; $elementtype = 'fournisseur';
$objecttype = 'societe&categorie'; $objecttype = 'societe&categorie';
$objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["socid"])?$_REQUEST["socid"]:''); $objectid = isset($id)?$id:(isset($socid)?$socid:'');
$fieldid = 'rowid'; $fieldid = 'rowid';
} }
if ($_REQUEST["type"] == 2) { if ($type == 2) {
$type = 'societe'; $elementtype = 'societe';
$objecttype = 'societe&categorie'; $objecttype = 'societe&categorie';
$objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["socid"])?$_REQUEST["socid"]:''); $objectid = isset($id)?$id:(isset($socid)?$socid:'');
$fieldid = 'rowid'; $fieldid = 'rowid';
} }
if ($_REQUEST["type"] == 3) { if ($type == 3) {
$type = 'member'; $elementtype = 'member';
$objecttype = 'adherent&categorie'; $objecttype = 'adherent&categorie';
$objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["ref"])?$_REQUEST["ref"]:''); $objectid = isset($id)?$id:(isset($ref)?$ref:'');
$dbtablename = 'adherent'; $dbtablename = 'adherent';
$fieldid = isset($_REQUEST["ref"])?'ref':'rowid'; $fieldid = isset($ref)?'ref':'rowid';
} }
} }
@ -91,25 +88,24 @@ $result = restrictedArea($user,$objecttype,$objectid,$dbtablename,'','',$fieldid
//Suppression d'un objet d'une categorie //Suppression d'un objet d'une categorie
if ($_REQUEST["removecat"]) if ($_REQUEST["removecat"])
{ {
if ($_REQUEST["type"]==0 && ($user->rights->produit->creer || $user->rights->service->creer)) if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer))
{ {
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
$object = new Product($db); $object = new Product($db);
if ($_REQUEST["ref"]) $result = $object->fetch('',$_REQUEST["ref"]); $result = $object->fetch($id, $ref);
if ($_REQUEST["id"]) $result = $object->fetch($_REQUEST["id"]); $elementtype = 'product';
$type = 'product';
} }
if ($_REQUEST["type"]==1 && $user->rights->societe->creer) if ($type==1 && $user->rights->societe->creer)
{ {
$object = new Societe($db); $object = new Societe($db);
$result = $object->fetch($objectid); $result = $object->fetch($objectid);
} }
if ($_REQUEST["type"]==2 && $user->rights->societe->creer) if ($type==2 && $user->rights->societe->creer)
{ {
$object = new Societe($db); $object = new Societe($db);
$result = $object->fetch($objectid); $result = $object->fetch($objectid);
} }
if ($_REQUEST["type"] == 3 && $user->rights->adherent->creer) if ($type == 3 && $user->rights->adherent->creer)
{ {
require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
$object = new Adherent($db); $object = new Adherent($db);
@ -118,46 +114,42 @@ if ($_REQUEST["removecat"])
$cat = new Categorie($db); $cat = new Categorie($db);
$result=$cat->fetch($_REQUEST["removecat"]); $result=$cat->fetch($_REQUEST["removecat"]);
$result=$cat->del_type($object,$type); $result=$cat->del_type($object,$elementtype);
} }
// Add object into a category // Add object into a category
if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0) if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0)
{ {
$_GET["id"]=$_REQUEST["id"]; if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer))
$_GET["type"]=$_REQUEST["type"];
if ($_REQUEST["type"]==0 && ($user->rights->produit->creer || $user->rights->service->creer))
{ {
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
$object = new Product($db); $object = new Product($db);
if ($_REQUEST["ref"]) $result = $object->fetch('',$_REQUEST["ref"]); $result = $object->fetch($id, $ref);
if ($_REQUEST["id"]) $result = $object->fetch($_REQUEST["id"]); $elementtype = 'product';
$type = 'product';
} }
if ($_REQUEST["type"]==1 && $user->rights->societe->creer) if ($type==1 && $user->rights->societe->creer)
{ {
$object = new Societe($db); $object = new Societe($db);
$result = $object->fetch($objectid); $result = $object->fetch($objectid);
$type = 'fournisseur'; $elementtype = 'fournisseur';
} }
if ($_REQUEST["type"]==2 && $user->rights->societe->creer) if ($type==2 && $user->rights->societe->creer)
{ {
$object = new Societe($db); $object = new Societe($db);
$result = $object->fetch($objectid); $result = $object->fetch($objectid);
$type = 'societe'; $elementtype = 'societe';
} }
if ($_REQUEST["type"]==3 && $user->rights->adherent->creer) if ($type==3 && $user->rights->adherent->creer)
{ {
require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
$object = new Adherent($db); $object = new Adherent($db);
$result = $object->fetch($objectid); $result = $object->fetch($objectid);
$type = 'member'; $elementtype = 'member';
} }
$cat = new Categorie($db); $cat = new Categorie($db);
$result=$cat->fetch($_REQUEST["catMere"]); $result=$cat->fetch($_REQUEST["catMere"]);
$result=$cat->add_type($object,$type); $result=$cat->add_type($object,$elementtype);
if ($result >= 0) if ($result >= 0)
{ {
$mesg='<div class="ok">'.$langs->trans("WasAddedSuccessfully",$cat->label).'</div>'; $mesg='<div class="ok">'.$langs->trans("WasAddedSuccessfully",$cat->label).'</div>';
@ -202,7 +194,7 @@ if ($socid)
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="25%">'.$langs->trans("ThirdPartyName").'</td><td colspan="3">'; print '<tr><td width="25%">'.$langs->trans("ThirdPartyName").'</td><td colspan="3">';
print $html->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom'); print $html->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom','','&type='.$type);
print '</td></tr>'; print '</td></tr>';
if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
@ -234,14 +226,15 @@ if ($socid)
} }
// Address // Address
print "<tr><td valign=\"top\">".$langs->trans('Address')."</td><td colspan=\"3\">".nl2br($soc->address)."</td></tr>"; print '<tr><td valign="top">'.$langs->trans('Address').'</td><td colspan="3">'.nl2br($soc->address).'</td></tr>';
// Zip / Town // Zip / Town
print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$soc->cp."</td>"; print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$soc->cp."</td>";
print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$soc->ville."</td></tr>"; print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$soc->ville."</td></tr>";
// Country // Country
if ($soc->pays) { if ($soc->pays)
{
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'; print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
$img=picto_from_langcode($soc->pays_code); $img=picto_from_langcode($soc->pays_code);
print ($img?$img.' ':''); print ($img?$img.' ':'');
@ -282,9 +275,9 @@ if ($socid)
if ($soc->fournisseur) formCategory($db,$soc,1); if ($soc->fournisseur) formCategory($db,$soc,1);
} }
else if ($_GET["id"] || $_GET["ref"]) else if ($id || $ref)
{ {
if ($_GET["type"] == 0) if ($type == 0)
{ {
$langs->load("products"); $langs->load("products");
@ -296,8 +289,7 @@ else if ($_GET["id"] || $_GET["ref"])
// Produit // Produit
$product = new Product($db); $product = new Product($db);
if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); $result = $product->fetch($id, $ref);
if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
llxHeader("","",$langs->trans("CardProduct".$product->type)); llxHeader("","",$langs->trans("CardProduct".$product->type));
@ -340,7 +332,7 @@ else if ($_GET["id"] || $_GET["ref"])
formCategory($db,$product,0); formCategory($db,$product,0);
} }
if ($_GET["type"] == 3) if ($type == 3)
{ {
$langs->load("members"); $langs->load("members");
@ -353,8 +345,7 @@ else if ($_GET["id"] || $_GET["ref"])
// Produit // Produit
$member = new Adherent($db); $member = new Adherent($db);
if ($_GET["ref"]) $result = $member->fetch('',$_GET["ref"]); $result = $member->fetch($id, $ref);
if ($_GET["id"]) $result = $member->fetch($_GET["id"]);
$membert = new AdherentType($db); $membert = new AdherentType($db);
$membert->fetch($member->typeid); $membert->fetch($member->typeid);