From cd6e3464dbf151f0e2f9a9cfb55336ad65db3d6e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 2 Jan 2013 14:35:16 +0100 Subject: [PATCH] Fix: Several fixes for bad management of external/internal users. --- htdocs/comm/action/contact.php | 2 +- htdocs/core/boxes/box_activity.php | 26 +++- htdocs/core/class/html.form.class.php | 11 +- htdocs/core/class/html.formcompany.class.php | 2 +- htdocs/langs/en_US/companies.lang | 3 +- htdocs/langs/fr_FR/companies.lang | 3 +- htdocs/user/fiche.php | 130 ++++++++++++------- 7 files changed, 115 insertions(+), 62 deletions(-) diff --git a/htdocs/comm/action/contact.php b/htdocs/comm/action/contact.php index c86792f4572..fd8e7a83dd3 100644 --- a/htdocs/comm/action/contact.php +++ b/htdocs/comm/action/contact.php @@ -309,7 +309,7 @@ if ($id > 0 || ! empty($ref)) print ''; $nbofcontacts=$form->select_contacts($selectedCompany,'','contactid'); - if ($nbofcontacts == 0) print $langs->trans("NoContactDefined"); + if ($nbofcontacts == 0) print $langs->trans("NoContactDefinedForThirdParty"); print ''; print ''; $formcompany->selectTypeContact($object,'','type','external','rowid'); diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index 5e4267bd12c..817bf77ddd1 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -69,6 +69,7 @@ class box_activity extends ModeleBoxes include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $facturestatic=new Facture($db); $propalstatic=new Propal($db); $commandestatic=new Commande($db); @@ -80,10 +81,14 @@ class box_activity extends ModeleBoxes if (! empty($conf->facture->enabled) && $user->rights->facture->lire) { $sql = "SELECT f.paye, f.fk_statut, sum(f.total_ttc) as Mnttot, count(*) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; + $sql.= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= ")"; $sql.= " WHERE f.entity = ".$conf->entity; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; $sql.= " AND f.fk_soc = s.rowid"; - $sql.= " AND (DATE_FORMAT(f.datef,'%Y') = ".date("Y")." or paye=0)"; + $sql.= " AND f.datef between '".$db->idate(dol_get_first_day(date("Y"),1,1))."' AND '".$db->idate(dol_get_last_day(date("Y"),12,1))."'"; $sql.= " GROUP BY f.paye, f.fk_statut "; $sql.= " ORDER BY f.fk_statut DESC"; @@ -136,9 +141,14 @@ class box_activity extends ModeleBoxes if (! empty($conf->commande->enabled) && $user->rights->commande->lire) { $sql = "SELECT c.fk_statut,c.facture, sum(c.total_ttc) as Mnttot, count(*) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; + $sql.= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= ")"; $sql.= " WHERE c.entity = ".$conf->entity; $sql.= " AND c.fk_soc = s.rowid"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; + $sql.= " AND c.datec between '".$db->idate(dol_get_first_day(date("Y"),1,1))."' AND '".$db->idate(dol_get_last_day(date("Y"),12,1))."'"; $sql.= " AND c.facture=0"; $sql.= " GROUP BY c.fk_statut"; $sql.= " ORDER BY c.fk_statut DESC"; @@ -178,11 +188,15 @@ class box_activity extends ModeleBoxes if (! empty($conf->propal->enabled) && $user->rights->propal->lire) { $sql = "SELECT p.fk_statut, sum(p.total) as Mnttot, count(*) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p"; + $sql.= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= ")"; $sql.= " WHERE p.entity = ".$conf->entity; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND DATE_FORMAT(p.datep,'%Y') = ".date("Y"); - $sql.= " AND p.date_cloture IS NULL "; // just unclosed + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; + $sql.= " AND p.datep between '".$db->idate(dol_get_first_day(date("Y"),1,1))."' AND '".$db->idate(dol_get_last_day(date("Y"),12,1))."'"; + $sql.= " AND p.date_cloture IS NULL"; // just unclosed $sql.= " GROUP BY p.fk_statut"; $sql.= " ORDER BY p.fk_statut DESC"; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index d7342b87732..6cf1f3aff41 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -826,7 +826,7 @@ class Form * @param int $socid Id ot third party or 0 for all * @param string $selected Id contact pre-selectionne * @param string $htmlname Name of HTML field ('none' for a not editable field) - * @param int $showempty 0=no empty value, 1=add an empty value + * @param int $showempty 0=no empty value, 1=add an empty value, 2=add line 'Internal' (used by user edit) * @param string $exclude List of contacts id to exclude * @param string $limitto Disable answers that are not id in this array list * @param string $showfunction Add function into label @@ -863,7 +863,8 @@ class Form $num=$this->db->num_rows($resql); if ($htmlname != 'none' || $options_only) $out.= ''.yn($object->admin); print ' ('.$langs->trans("ExternalUser").')'; @@ -1702,7 +1738,7 @@ else print ''; } - //Multicompany + // Multicompany if (! empty($conf->multicompany->enabled)) { if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) @@ -1716,25 +1752,25 @@ else print ''; } } - else - { - // Type - print ''.$langs->trans("Type").''; - print ''; - if ($object->societe_id) - { - print $langs->trans("External"); - } - else if ($object->ldap_sid) - { - print $langs->trans("DomainUser"); - } - else - { - print $langs->trans("Internal"); - } - print ''; + + // Type + print ''.$langs->trans("Type").''; + print ''; + if ($user->id == $object->id || ! $user->admin) + { + $type=$langs->trans("Internal"); + if ($object->societe_id) $type=$langs->trans("External"); + print $form->textwithpicto($type,$langs->trans("InternalExternalDesc")); + if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')'; + } + else + { + $type=0; + if ($object->contact_id) $type=$object->contact_id; + print $form->selectcontacts(0,$type,'contactid',2,'','',1,'',false,1); + if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')'; } + print ''; // Tel pro print "".''.$langs->trans("PhonePro").'';