Fix: for multi-company

Conflicts:

	htdocs/comm/propal/class/propal.class.php
	htdocs/core/class/html.form.class.php
This commit is contained in:
Regis Houssin 2012-02-15 19:35:19 +01:00
parent 793f4961f6
commit e5c0a99584
6 changed files with 795 additions and 582 deletions

View File

@ -126,26 +126,20 @@ if ($action == 'confirm_clone' && $confirm == 'yes')
}
// Suppression de la propale
else if ($action == 'confirm_delete' && $confirm == 'yes')
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propale->supprimer)
{
if ($user->rights->propale->supprimer)
$object->fetch($id);
$result=$object->delete($user);
if ($result > 0)
{
$object->fetch($id);
$result=$object->delete($user);
$id = 0;
$brouillon = 1;
if ($result > 0)
{
Header('Location: '.$_SERVER["PHP_SELF"]);
exit;
}
else
{
$langs->load("errors");
if ($object->error == 'ErrorFailToDeleteDir') $mesg='<div class="error">'.$langs->trans('ErrorFailedToDeleteJoinedFiles').'</div>';
else $mesg='<div class="error">'.$object->error.'</div>';
}
Header('Location: '.$_SERVER["PHP_SELF"]);
exit;
}
else
{
$langs->load("errors");
if ($object->error == 'ErrorFailToDeleteDir') $mesg='<div class="error">'.$langs->trans('ErrorFailedToDeleteJoinedFiles').'</div>';
else $mesg='<div class="error">'.$object->error.'</div>';
}
}

View File

@ -1534,13 +1534,13 @@ abstract class CommonObject
$sql.= "(fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."')";
$sql.= " ".$clause." (fk_target = '".$targetid."' AND targettype = '".$targettype."')";
}
//print $sql;
print $sql;
dol_syslog(get_class($this)."::fetchObjectLink sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$num = $this->db->num_rows($resql); echo 'num='.$num.'<br>';
$i = 0;
while ($i < $num)
{
@ -1549,13 +1549,14 @@ abstract class CommonObject
{
$this->linkedObjectsIds[$obj->targettype][]=$obj->fk_target;
}
echo 'fk_target='.$obj->fk_target.' targetid='.$targetid.'<br>';
if ($obj->fk_target == $targetid)
{
$this->linkedObjectsIds[$obj->sourcetype][]=$obj->fk_source;
}
$i++;
}
var_dump($this->linkedObjectsIds);
if (! empty($this->linkedObjectsIds))
{
foreach($this->linkedObjectsIds as $objecttype => $objectids)
@ -1685,8 +1686,10 @@ abstract class CommonObject
function deleteObjectLinked()
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element";
$sql.= " WHERE fk_target = ".$this->id;
$sql.= " AND targettype = '".$this->element."'";
$sql.= " WHERE";
$sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->element."')";
$sql.= " OR";
$sql.= " (fk_target = ".$this->id." AND targettype = '".$this->element."')";
dol_syslog(get_class($this)."::deleteObjectLinked sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql))

View File

@ -235,7 +235,13 @@ class Conf
$rootfordata = DOL_DATA_ROOT;
$rootforuser = DOL_DATA_ROOT;
// If multicompany module is enabled, we redefine the root of data
if (! empty($this->global->MAIN_MODULE_MULTICOMPANY) && ! empty($this->entity) && $this->entity > 1) $rootfordata.='/'.$this->entity;
if (! empty($this->global->MAIN_MODULE_MULTICOMPANY) && ! empty($this->entity) && $this->entity > 1)
{
$rootfordata.='/'.$this->entity;
var_dump($mc->sharings);
//var_dump($mc->referent);
var_dump($mc->entities);
}
// For backward compatibility
// TODO Replace this->xxx->enabled by this->modulename->enabled to remove this code

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
<?php
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
*
* 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
@ -51,11 +51,11 @@ class ProductFournisseur extends Product
/**
* Constructor
*
* @param DoliDB $DB Database handler
* @param DoliDB $db Database handler
*/
function ProductFournisseur($DB)
function __construct($db)
{
$this->db = $DB;
$this->db = $db;
}
@ -324,15 +324,14 @@ class ProductFournisseur extends Product
function list_product_fournisseur_price($prodid)
{
global $conf;
// Suppliers list
$sql = "SELECT s.nom as supplier_name, s.rowid as fourn_id,";
$sql.= " pfp.rowid as product_fourn_pri_id, pfp.ref_fourn,";
$sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.fk_availability";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
$sql.= " ON pfp.fk_soc = s.rowid";
$sql.= " WHERE s.entity IN (".getEntity('societe', 1).")";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE pfp.entity IN (".getEntity('product', 1).")";
$sql.= " AND pfp.fk_soc = s.rowid";
$sql.= " AND pfp.fk_product = ".$prodid;
$sql.= " ORDER BY s.nom, pfp.quantity, pfp.price";

View File

@ -34,6 +34,8 @@ $langs->load("bills");
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
// Security check
$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
@ -52,22 +54,22 @@ $dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->ser
if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
if ($_GET["id"])
if ($id)
{
$product = new Product($db);
$result = $product->fetch($_GET["id"]);
$result = $product->fetch($id);
$result = $product->add_photo($dir, $_FILES['userfile']);
}
}
if ($_REQUEST["action"] == 'confirm_delete' && $_GET["file"] && $_REQUEST['confirm'] == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer))
if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer))
{
$product = new Product($db);
$product->delete_photo($dir."/".$_GET["file"]);
}
if ($_GET["action"] == 'addthumb' && $_GET["file"])
if ($action == 'addthumb' && $_GET["file"])
{
$product = new Product($db);
$product->add_thumb($dir."/".$_GET["file"]);
@ -80,12 +82,11 @@ if ($_GET["action"] == 'addthumb' && $_GET["file"])
$form = new Form($db);
if ($_GET["id"] || $_GET["ref"])
if ($id > 0 || ! empty($ref))
{
$product = new Product($db);
if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]);
if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
$result = $product->fetch($id, $ref);
llxHeader("","",$langs->trans("CardProduct".$product->type));
@ -151,7 +152,7 @@ if ($_GET["id"] || $_GET["ref"])
{
if (! empty($conf->global->MAIN_UPLOAD_DOC))
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/photos.php?action=ajout_photo&amp;id='.$product->id.'">';
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=ajout_photo&amp;id='.$product->id.'">';
print $langs->trans("AddPhoto").'</a>';
}
else
@ -166,15 +167,15 @@ if ($_GET["id"] || $_GET["ref"])
/*
* Add a photo
*/
if ($_GET["action"] == 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC))
if ($action == 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
// Affiche formulaire upload
$formfile=new FormFile($db);
$formfile->form_attach_new_file(DOL_URL_ROOT.'/product/photos.php?id='.$product->id,$langs->trans("AddPhoto"),1);
$formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?id='.$product->id,$langs->trans("AddPhoto"),1);
}
// Affiche photos
if ($_GET["action"] != 'ajout_photo')
if ($action != 'ajout_photo')
{
$nbphoto=0;
$nbbyrow=5;
@ -201,8 +202,7 @@ else
}
llxFooter();
$db->close();
llxFooter();
?>