From 04594770971cf5b7cb4b78a40b6edd0b48ac5128 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 6 Dec 2014 14:41:56 +0100 Subject: [PATCH] Fix: Miscellaneous fixes for multicompany --- htdocs/comm/action/listactions.php | 2 +- htdocs/comm/action/peruser.php | 2 +- htdocs/comm/action/rapport/index.php | 5 +++-- htdocs/install/mysql/migration/3.6.0-3.7.0.sql | 2 ++ htdocs/install/mysql/tables/llx_resource.sql | 2 +- htdocs/opensurvey/list.php | 2 +- htdocs/projet/class/project.class.php | 4 ++-- htdocs/resource/class/resource.class.php | 14 ++++++++------ 8 files changed, 19 insertions(+), 14 deletions(-) diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index 245902013a1..7fa67695860 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -180,7 +180,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ut ON a.fk_user_action = ut.rowid"; if ($usergroup > 0) $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ugu"; $sql.= " WHERE c.id = a.fk_action"; $sql.= ' AND a.fk_user_author = u.rowid'; -$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; // To limit to entity +$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; if ($actioncode) $sql.=" AND c.code='".$db->escape($actioncode)."'"; if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid); if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")"; diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index dcebefbcbb7..22cf8841c02 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -610,7 +610,7 @@ else $sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user"; - $sql.= " WHERE u.entity IN (".getEntity('user').")"; + $sql.= " WHERE u.entity IN (".getEntity('user',1).")"; if ($usergroup > 0) $sql.= " AND ug.fk_usergroup = ".$usergroup; if (GETPOST("usertodo","int",3) > 0) $sql.=" AND u.rowid = ".GETPOST("usertodo","int",3); //print $sql; diff --git a/htdocs/comm/action/rapport/index.php b/htdocs/comm/action/rapport/index.php index a9a19f57a9e..24eb117684f 100644 --- a/htdocs/comm/action/rapport/index.php +++ b/htdocs/comm/action/rapport/index.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Eric Seigne - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -55,6 +55,7 @@ $result = restrictedArea($user, 'agenda', $socid, '', 'myactions'); /* * Actions */ + if ($action == 'builddoc') { $cat = new CommActionRapport($db, $month, $year); @@ -79,7 +80,7 @@ $sql.= " date_format(a.datep, '%Y') as year"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a,"; $sql.= " ".MAIN_DB_PREFIX."user as u"; $sql.= " WHERE a.fk_user_author = u.rowid"; -$sql.= " AND a.entity = ".$conf->entity; +$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; //$sql.= " AND percent = 100"; $sql.= " GROUP BY year, month, df"; $sql.= " ORDER BY year DESC, month DESC, df DESC"; diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 40a7f7b86c6..e2c586de47f 100755 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -1140,6 +1140,8 @@ ALTER TABLE llx_facture_rec ADD COLUMN revenuestamp double(24,8) DEFAULT 0; ALTER TABLE llx_facturedet_rec MODIFY COLUMN tva_tx double(6,3); ALTER TABLE llx_facturedet_rec ADD COLUMN fk_contract_line integer NULL; +ALTER TABLE llx_resource MODIFY COLUMN entity integer DEFAULT 1 NOT NULL; + -- This request make mysql drop (mysql bug, so we add it at end): --ALTER TABLE llx_product ADD CONSTRAINT fk_product_barcode_type FOREIGN KEY (fk_barcode_type) REFERENCES llx_c_barcode_type(rowid); diff --git a/htdocs/install/mysql/tables/llx_resource.sql b/htdocs/install/mysql/tables/llx_resource.sql index 91ebbe8b75d..0d67075f1ea 100755 --- a/htdocs/install/mysql/tables/llx_resource.sql +++ b/htdocs/install/mysql/tables/llx_resource.sql @@ -17,7 +17,7 @@ CREATE TABLE llx_resource ( rowid integer AUTO_INCREMENT PRIMARY KEY, - entity integer, + entity integer DEFAULT 1 NOT NULL, ref varchar(255), description text, fk_code_type_resource varchar(32), diff --git a/htdocs/opensurvey/list.php b/htdocs/opensurvey/list.php index 83482bbe04f..d21a08007a4 100644 --- a/htdocs/opensurvey/list.php +++ b/htdocs/opensurvey/list.php @@ -123,7 +123,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } -$sql.= " WHERE p.entity = ".getEntity('survey'); +$sql.= " WHERE p.entity = ".getEntity('survey',1); if ($status == 'expired') $sql.=" AND date_fin < '".$db->idate($now)."'"; if ($status == 'opened') $sql.=" AND date_fin >= '".$db->idate($now)."'"; if ($surveytitle) $sql.=" AND titre LIKE '%".$db->escape($surveytitle)."%'"; diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 738eec46ec0..ec449f009c7 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -298,7 +298,7 @@ class Project extends CommonObject else if (! empty($ref)) { $sql.= " WHERE ref='".$this->db->escape($ref)."'"; - $sql.= " AND entity IN (".getEntity('project').")"; + $sql.= " AND entity IN (".getEntity('project',1).")"; } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -910,7 +910,7 @@ class Project extends CommonObject $sql.= ", " . MAIN_DB_PREFIX . "element_contact as ec"; $sql.= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc"; } - $sql.= " WHERE p.entity IN (".getEntity('project').")"; + $sql.= " WHERE p.entity IN (".getEntity('project',1).")"; // Internal users must see project he is contact to even if project linked to a third party he can't see. //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; if ($socid > 0) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")"; diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/resource.class.php index a7be5d0d25a..c75f37b00c2 100644 --- a/htdocs/resource/class/resource.class.php +++ b/htdocs/resource/class/resource.class.php @@ -388,7 +388,7 @@ class Resource extends CommonObject $sql.= " ty.label as type_label"; $sql.= " FROM ".MAIN_DB_PREFIX."resource as t"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource"; - //$sql.= " WHERE t.entity IN (".getEntity('resource').")"; + $sql.= " WHERE t.entity IN (".getEntity('resource',1).")"; //Manage filter if (!empty($filter)){ @@ -402,7 +402,7 @@ class Resource extends CommonObject } } $sql.= " GROUP BY t.rowid"; - $sql.= " ORDER BY $sortfield $sortorder "; + $sql.= $this->db->order($sortfield,$sortorder); if ($limit) $sql.= $this->db->plimit($limit+1,$offset); dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG); @@ -462,7 +462,7 @@ class Resource extends CommonObject $sql.= " t.fk_user_create,"; $sql.= " t.tms"; $sql.= ' FROM '.MAIN_DB_PREFIX .'element_resources as t '; - //$sql.= " WHERE t.entity IN (".getEntity('resource').")"; + $sql.= " WHERE t.entity IN (".getEntity('resource',1).")"; //Manage filter if (!empty($filter)){ @@ -476,7 +476,8 @@ class Resource extends CommonObject } } $sql.= " GROUP BY t.rowid"; - $sql.= " ORDER BY $sortfield $sortorder " . $this->db->plimit($limit+1,$offset); + $sql.= $this->db->order($sortfield,$sortorder); + if ($limit) $sql.= $this->db->plimit($limit+1,$offset); dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG); $resql=$this->db->query($sql); @@ -547,7 +548,7 @@ class Resource extends CommonObject $sql.= " t.fk_user_create,"; $sql.= " t.tms"; $sql.= ' FROM '.MAIN_DB_PREFIX .'element_resources as t '; - //$sql.= " WHERE t.entity IN (".getEntity('resource').")"; + $sql.= " WHERE t.entity IN (".getEntity('resource',1).")"; //Manage filter if (!empty($filter)){ @@ -561,7 +562,8 @@ class Resource extends CommonObject } } $sql.= " GROUP BY t.resource_id"; - $sql.= " ORDER BY " . $sortfield . " " . $sortorder . " " . $this->db->plimit($limit+1,$offset); + $sql.= $this->db->order($sortfield,$sortorder); + if ($limit) $sql.= $this->db->plimit($limit+1,$offset); dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG); $resql=$this->db->query($sql);