diff --git a/dev/tools/rector/README.md b/dev/tools/rector/README.md index e5143d3efdf..c117361cd10 100644 --- a/dev/tools/rector/README.md +++ b/dev/tools/rector/README.md @@ -10,19 +10,13 @@ composer install ``` #### Usage -##### To see change before apply +##### To make changes (Add --dry-run for test mode only) ```shell ./vendor/bin/rector process --dry-run ``` -##### To apply change +##### To make changes on a given directory ```shell -./vendor/bin/rector process -``` - -##### Run only for a directory - -```shell -./vendor/bin/rector process ../../../htdocs/core/ +./vendor/bin/rector process [--dry-run] ../../../htdocs/core/ ``` diff --git a/htdocs/core/ajax/ajaxtooltip.php b/htdocs/core/ajax/ajaxtooltip.php index 616832d9555..301b9ef1d6e 100644 --- a/htdocs/core/ajax/ajaxtooltip.php +++ b/htdocs/core/ajax/ajaxtooltip.php @@ -60,7 +60,7 @@ $module = $object->module; $element = $object->element; $usesublevelpermission = ($module != $element ? $element : ''); -if ($usesublevelpermission && !isset($user->rights->$module->$element)) { // There is no permission on object defined, we will check permission on module directly +if ($usesublevelpermission && !$user->hasRight($module, $element)) { // There is no permission on object defined, we will check permission on module directly $usesublevelpermission = ''; } diff --git a/htdocs/core/ajax/extraparams.php b/htdocs/core/ajax/extraparams.php index 80f280e7a06..0adef3e9d74 100644 --- a/htdocs/core/ajax/extraparams.php +++ b/htdocs/core/ajax/extraparams.php @@ -50,7 +50,7 @@ $object = fetchObjectByElement($id, $element); $module = $object->module; $element = $object->element; $usesublevelpermission = ($module != $element ? $element : ''); -if ($usesublevelpermission && !isset($user->rights->$module->$element)) { // There is no permission on object defined, we will check permission on module directly +if ($usesublevelpermission && !$user->hasRight($module, $element)) { // There is no permission on object defined, we will check permission on module directly $usesublevelpermission = ''; } diff --git a/htdocs/core/ajax/fileupload.php b/htdocs/core/ajax/fileupload.php index 69aae0dab4e..177154cee3a 100644 --- a/htdocs/core/ajax/fileupload.php +++ b/htdocs/core/ajax/fileupload.php @@ -50,7 +50,7 @@ $module = $object->module; $element = $object->element; $usesublevelpermission = ($module != $element ? $element : ''); -if ($usesublevelpermission && !isset($user->rights->$module->$element)) { // There is no permission on object defined, we will check permission on module directly +if ($usesublevelpermission && !$user->hasRight($module, $element)) { // There is no permission on object defined, we will check permission on module directly $usesublevelpermission = ''; } diff --git a/htdocs/core/ajax/loadinplace.php b/htdocs/core/ajax/loadinplace.php index 415e51af8e5..13c80cd50b1 100644 --- a/htdocs/core/ajax/loadinplace.php +++ b/htdocs/core/ajax/loadinplace.php @@ -49,7 +49,7 @@ $object = fetchObjectByElement($id, $element); $module = $object->module; $element = $object->element; $usesublevelpermission = ($module != $element ? $element : ''); -if ($usesublevelpermission && !isset($user->rights->$module->$element)) { // There is no permission on object defined, we will check permission on module directly +if ($usesublevelpermission && !$user->hasRight($module, $element)) { // There is no permission on object defined, we will check permission on module directly $usesublevelpermission = ''; } @@ -102,10 +102,10 @@ if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_e $subelement = 'facture'; } - if ($user->rights->$element->lire || $user->rights->$element->read - || (isset($subelement) && ($user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read)) + if ($user->hasRight($element, 'lire') || $user->hasRight($element, 'read') + || (isset($subelement) && ($user->hasRight($element, $subelement, 'lire') || $user->hasRight($element, $subelement, 'read'))) || ($element == 'payment' && $user->hasRight('facture', 'lire')) - || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->lire)) { + || ($element == 'payment_supplier' && $user->hasRight('fournisseur', 'facture', 'lire'))) { if ($type == 'select') { $methodname = 'load_cache_'.$loadmethod; $cachename = 'cache_'.GETPOST('loadmethod', 'alpha'); diff --git a/htdocs/core/ajax/objectonoff.php b/htdocs/core/ajax/objectonoff.php index 5166ba52b52..eeb0ab18f66 100644 --- a/htdocs/core/ajax/objectonoff.php +++ b/htdocs/core/ajax/objectonoff.php @@ -64,7 +64,7 @@ $object->fields[$field] = array('type' => $format, 'enabled' => 1); $module = $object->module; $element = $object->element; $usesublevelpermission = ($module != $element ? $element : ''); -if ($usesublevelpermission && !isset($user->rights->$module->$element)) { // There is no permission on object defined, we will check permission on module directly +if ($usesublevelpermission && !$user->hasRight($module, $element)) { // There is no permission on object defined, we will check permission on module directly $usesublevelpermission = ''; } diff --git a/htdocs/core/ajax/row.php b/htdocs/core/ajax/row.php index 9a3bfc8d541..c394b5647f6 100644 --- a/htdocs/core/ajax/row.php +++ b/htdocs/core/ajax/row.php @@ -86,42 +86,42 @@ if (GETPOST('roworder', 'alpha', 3) && GETPOST('table_element_line', 'aZ09', 3) $perm = 1; } elseif ($table_element_line == 'emailcollector_emailcollectoraction' && $user->admin) { $perm = 1; - } elseif ($table_element_line == 'bom_bomline' && $user->rights->bom->write) { + } elseif ($table_element_line == 'bom_bomline' && $user->hasRight('bom', 'write')) { $perm = 1; - } elseif ($table_element_line == 'mrp_production' && $user->rights->mrp->write) { + } elseif ($table_element_line == 'mrp_production' && $user->hasRight('mrp', 'write')) { $perm = 1; - } elseif ($table_element_line == 'supplier_proposaldet' && $user->rights->supplier_proposal->creer) { + } elseif ($table_element_line == 'supplier_proposaldet' && $user->hasRight('supplier_proposal', 'creer')) { $perm = 1; - } elseif ($table_element_line == 'commande_fournisseurdet' && $user->rights->fournisseur->commande->creer) { + } elseif ($table_element_line == 'commande_fournisseurdet' && $user->hasRight('fournisseur', 'commande', 'creer')) { $perm = 1; - } elseif ($table_element_line == 'facture_fourn_det' && $user->rights->fournisseur->facture->creer) { + } elseif ($table_element_line == 'facture_fourn_det' && $user->hasRight('fournisseur', 'facture', 'creer')) { $perm = 1; - } elseif ($table_element_line == 'facture_fourn_det_rec' && $user->rights->fournisseur->facture->creer) { + } elseif ($table_element_line == 'facture_fourn_det_rec' && $user->hasRight('fournisseur', 'facture', 'creer')) { $perm = 1; } elseif ($table_element_line == 'product_attribute_value' && $fk_element == 'fk_product_attribute' && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) { $perm = 1; } elseif ($table_element_line == 'ecm_files') { // Used when of page "documents.php" - if (!empty($user->rights->ecm->creer)) { + if ($user->hasRight('ecm', 'creer')) { $perm = 1; - } elseif ($fk_element == 'fk_product' && ($user->hasRight('produit', 'creer') || !empty($user->rights->service->creer))) { + } elseif ($fk_element == 'fk_product' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) { $perm = 1; - } elseif ($fk_element == 'fk_ticket' && !empty($user->rights->ticket->write)) { + } elseif ($fk_element == 'fk_ticket' && $user->hasRight('ticket', 'write')) { $perm = 1; - } elseif ($fk_element == 'fk_holiday' && !empty($user->rights->holiday->write)) { + } elseif ($fk_element == 'fk_holiday' && $user->hasRight('holiday', 'write')) { $perm = 1; - } elseif ($fk_element == 'fk_soc' && !empty($user->rights->societe->creer)) { + } elseif ($fk_element == 'fk_soc' && $user->hasRight('societe', 'creer')) { $perm = 1; } - } elseif ($table_element_line == 'product_association' && $fk_element == 'fk_product' && ($user->hasRight('produit', 'creer') || !empty($user->rights->service->creer))) { + } elseif ($table_element_line == 'product_association' && $fk_element == 'fk_product' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) { $perm = 1; - } elseif ($table_element_line == 'projet_task' && $fk_element == 'fk_projet' && $user->rights->projet->creer) { + } elseif ($table_element_line == 'projet_task' && $fk_element == 'fk_projet' && $user->hasRight('projet', 'creer')) { $perm = 1; } elseif ($table_element_line == 'contratdet' && $fk_element == 'fk_contrat' && $user->hasRight('contrat', 'creer')) { $perm = 1; } else { $tmparray = explode('_', $table_element_line); $tmpmodule = $tmparray[0]; $tmpobject = preg_replace('/line$/', '', $tmparray[1]); - if (!empty($tmpmodule) && !empty($tmpobject) && !empty($conf->$tmpmodule->enabled) && !empty($user->rights->$tmpobject->write)) { + if (!empty($tmpmodule) && !empty($tmpobject) && !empty($conf->$tmpmodule->enabled) && $user->hasRight($tmpobject, 'write')) { $perm = 1; } } diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 9cbecc8e9c7..f44dc385e39 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -61,7 +61,7 @@ $object = fetchObjectByElement($id, $element); $module = $object->module; $element = $object->element; $usesublevelpermission = ($module != $element ? $element : ''); -if ($usesublevelpermission && !isset($user->rights->$module->$element)) { // There is no permission on object defined, we will check permission on module directly +if ($usesublevelpermission && !$user->hasRight($module, $element)) { // There is no permission on object defined, we will check permission on module directly $usesublevelpermission = ''; } diff --git a/htdocs/core/ajax/selectsearchbox.php b/htdocs/core/ajax/selectsearchbox.php index 05f8c8d215e..ecc9ed4908e 100644 --- a/htdocs/core/ajax/selectsearchbox.php +++ b/htdocs/core/ajax/selectsearchbox.php @@ -187,7 +187,7 @@ if (empty($reshook)) { // This pushes a search entry to the top if (!empty($conf->global->DEFAULT_SEARCH_INTO_MODULE)) { - $key = 'searchinto'.$conf->global->DEFAULT_SEARCH_INTO_MODULE; + $key = 'searchinto' . getDolGlobalString('DEFAULT_SEARCH_INTO_MODULE'); if (array_key_exists($key, $arrayresult)) { $arrayresult[$key]['position'] = -1000; } diff --git a/htdocs/core/boxes/box_actions.php b/htdocs/core/boxes/box_actions.php index 840d6c06ffc..58c74799904 100644 --- a/htdocs/core/boxes/box_actions.php +++ b/htdocs/core/boxes/box_actions.php @@ -92,14 +92,14 @@ class box_actions extends ModeleBoxes $sql .= ", s.code_client, s.code_compta, s.client"; $sql .= ", s.logo, s.email, s.entity"; $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; $sql .= " WHERE a.fk_action = ta.id"; $sql .= " AND a.entity IN (".getEntity('actioncomm').")"; $sql .= " AND a.percent >= 0 AND a.percent < 100"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")"; } if ($user->socid) { diff --git a/htdocs/core/boxes/box_actions_future.php b/htdocs/core/boxes/box_actions_future.php index 61a40938b8c..1a4c7584cc1 100644 --- a/htdocs/core/boxes/box_actions_future.php +++ b/htdocs/core/boxes/box_actions_future.php @@ -94,14 +94,14 @@ class box_actions_future extends ModeleBoxes $sql .= ", s.code_client, s.code_compta, s.client"; $sql .= ", s.logo, s.email, s.entity"; $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; $sql .= " WHERE a.fk_action = ta.id"; $sql .= " AND a.entity IN (".getEntity('actioncomm').")"; //$sql .= " AND a.percent >= 0 AND a.percent < 100"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")"; } if ($user->socid) { diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index 144ca4e8f23..21105904d9c 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -113,13 +113,13 @@ class box_activity extends ModeleBoxes $sql = "SELECT p.fk_statut, SUM(p.total_ttc) as Mnttot, COUNT(*) as nb"; $sql .= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= ")"; $sql .= " WHERE p.entity IN (".getEntity('propal').")"; $sql .= " AND p.fk_soc = s.rowid"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { @@ -202,13 +202,13 @@ class box_activity extends ModeleBoxes $sql = "SELECT c.fk_statut, sum(c.total_ttc) as Mnttot, count(*) as nb"; $sql .= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= ")"; $sql .= " WHERE c.entity IN (".getEntity('commande').")"; $sql .= " AND c.fk_soc = s.rowid"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { @@ -287,12 +287,12 @@ class box_activity extends ModeleBoxes $data = array(); $sql = "SELECT 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"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= ")"; $sql .= " WHERE f.entity IN (".getEntity('invoice').')'; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_boms.php b/htdocs/core/boxes/box_boms.php index 018d361b27e..e8acdf2c25c 100644 --- a/htdocs/core/boxes/box_boms.php +++ b/htdocs/core/boxes/box_boms.php @@ -84,7 +84,7 @@ class box_boms extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleLatestModifiedBoms", $max)); - if ($user->rights->bom->read) { + if ($user->hasRight('bom', 'read')) { $sql = "SELECT p.ref as product_ref"; $sql .= ", p.rowid as productid"; $sql .= ", p.tosell"; diff --git a/htdocs/core/boxes/box_bookmarks.php b/htdocs/core/boxes/box_bookmarks.php index 17348048edf..2873107f3b8 100644 --- a/htdocs/core/boxes/box_bookmarks.php +++ b/htdocs/core/boxes/box_bookmarks.php @@ -84,7 +84,7 @@ class box_bookmarks extends ModeleBoxes $this->info_box_head['subtext'] = $langs->trans("ListOfBookmark"); } - if ($user->rights->bookmark->lire) { + if ($user->hasRight('bookmark', 'lire')) { $sql = "SELECT b.title, b.url, b.target, b.favicon"; $sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b"; $sql .= " WHERE fk_user = ".((int) $user->id); diff --git a/htdocs/core/boxes/box_clients.php b/htdocs/core/boxes/box_clients.php index 4e14b01079b..91dfcd395f1 100644 --- a/htdocs/core/boxes/box_clients.php +++ b/htdocs/core/boxes/box_clients.php @@ -92,12 +92,12 @@ class box_clients extends ModeleBoxes $sql .= ", s.logo, s.email, s.entity"; $sql .= ", s.datec, s.tms, s.status"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE s.client IN (1, 3)"; $sql .= " AND s.entity IN (".getEntity('societe').")"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } // Add where from hooks diff --git a/htdocs/core/boxes/box_commandes.php b/htdocs/core/boxes/box_commandes.php index c83d1de30c0..a678b8f0e01 100644 --- a/htdocs/core/boxes/box_commandes.php +++ b/htdocs/core/boxes/box_commandes.php @@ -100,7 +100,7 @@ class box_commandes extends ModeleBoxes $sql .= ", c.total_tva"; $sql .= ", c.total_ttc"; $sql .= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.fk_soc = s.rowid"; @@ -108,7 +108,7 @@ class box_commandes extends ModeleBoxes if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY)) { $sql .= " AND c.fk_statut = 1"; } - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_comptes.php b/htdocs/core/boxes/box_comptes.php index 70f17df60b3..40dc424ef61 100644 --- a/htdocs/core/boxes/box_comptes.php +++ b/htdocs/core/boxes/box_comptes.php @@ -85,7 +85,7 @@ class box_comptes extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleCurrentAccounts")); - if ($user->rights->banque->lire) { + if ($user->hasRight('banque', 'lire')) { $sql = "SELECT b.rowid, b.ref, b.label, b.bank,b.number, b.courant, b.clos, b.rappro, b.url"; $sql .= ", b.code_banque, b.code_guichet, b.cle_rib, b.bic, b.iban_prefix as iban"; $sql .= ", b.domiciliation, b.proprio, b.owner_address"; diff --git a/htdocs/core/boxes/box_contacts.php b/htdocs/core/boxes/box_contacts.php index 47ad55399ad..bd39bb7da8c 100644 --- a/htdocs/core/boxes/box_contacts.php +++ b/htdocs/core/boxes/box_contacts.php @@ -107,11 +107,11 @@ class box_contacts extends ModeleBoxes if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); } - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE sp.entity IN (".getEntity('contact').")"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } // Add where from hooks diff --git a/htdocs/core/boxes/box_contracts.php b/htdocs/core/boxes/box_contracts.php index 4251a4491f6..95985fe688e 100644 --- a/htdocs/core/boxes/box_contracts.php +++ b/htdocs/core/boxes/box_contracts.php @@ -78,7 +78,7 @@ class box_contracts extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleLastContracts", $max)); - if ($user->rights->contrat->lire) { + if ($user->hasRight('contrat', 'lire')) { $contractstatic = new Contrat($this->db); $thirdpartytmp = new Societe($this->db); @@ -86,12 +86,12 @@ class box_contracts extends ModeleBoxes $sql .= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.datec, c.tms as date_modification, c.fin_validite, c.date_cloture,"; $sql .= " c.ref_customer, c.ref_supplier"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.fk_soc = s.rowid"; $sql .= " AND c.entity = ".$conf->entity; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_customers_outstanding_bill_reached.php b/htdocs/core/boxes/box_customers_outstanding_bill_reached.php index ec82f1a57e4..eee1900c628 100644 --- a/htdocs/core/boxes/box_customers_outstanding_bill_reached.php +++ b/htdocs/core/boxes/box_customers_outstanding_bill_reached.php @@ -93,12 +93,12 @@ class box_customers_outstanding_bill_reached extends ModeleBoxes $sql .= ", s.outstanding_limit"; $sql .= ", s.datec, s.tms, s.status"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE s.client IN (1, 3)"; $sql .= " AND s.entity IN (".getEntity('societe').")"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_factures.php b/htdocs/core/boxes/box_factures.php index 6f37390d27b..eb0b5d1d4aa 100644 --- a/htdocs/core/boxes/box_factures.php +++ b/htdocs/core/boxes/box_factures.php @@ -103,12 +103,12 @@ class box_factures extends ModeleBoxes $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture,"; $sql .= " ".MAIN_DB_PREFIX."societe as s"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('invoice').")"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_factures_fourn.php b/htdocs/core/boxes/box_factures_fourn.php index ac05d51e607..3b35eb98f13 100644 --- a/htdocs/core/boxes/box_factures_fourn.php +++ b/htdocs/core/boxes/box_factures_fourn.php @@ -100,12 +100,12 @@ class box_factures_fourn extends ModeleBoxes $sql .= ', f.date_lim_reglement as datelimite, f.tms, f.type'; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " AND f.entity = ".$conf->entity; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_factures_fourn_imp.php b/htdocs/core/boxes/box_factures_fourn_imp.php index 291c8961ddc..172f7989935 100644 --- a/htdocs/core/boxes/box_factures_fourn_imp.php +++ b/htdocs/core/boxes/box_factures_fourn_imp.php @@ -99,14 +99,14 @@ class box_factures_fourn_imp extends ModeleBoxes $sql2 = " FROM ".MAIN_DB_PREFIX."societe as s"; $sql2 .= ",".MAIN_DB_PREFIX."facture_fourn as f"; $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql2 .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql2 .= " WHERE f.fk_soc = s.rowid"; $sql2 .= " AND f.entity IN (".getEntity('supplier_invoice').")"; $sql2 .= " AND f.paye = 0"; $sql2 .= " AND fk_statut = 1"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql2 .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_factures_imp.php b/htdocs/core/boxes/box_factures_imp.php index 0e45396bc89..d96a4b53eee 100644 --- a/htdocs/core/boxes/box_factures_imp.php +++ b/htdocs/core/boxes/box_factures_imp.php @@ -109,7 +109,7 @@ class box_factures_imp extends ModeleBoxes if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { $sql2 .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); } - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql2 .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql2 .= ", ".MAIN_DB_PREFIX."facture as f"; @@ -118,7 +118,7 @@ class box_factures_imp extends ModeleBoxes $sql2 .= " AND f.entity IN (".getEntity('invoice').")"; $sql2 .= " AND f.paye = 0"; $sql2 .= " AND fk_statut = 1"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql2 .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_ficheinter.php b/htdocs/core/boxes/box_ficheinter.php index f69ccb0ad94..f0e75929039 100644 --- a/htdocs/core/boxes/box_ficheinter.php +++ b/htdocs/core/boxes/box_ficheinter.php @@ -80,7 +80,7 @@ class box_ficheinter extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleLastFicheInter", $max)); - if (!empty($user->rights->ficheinter->lire)) { + if ($user->hasRight('ficheinter', 'lire')) { $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut as status"; $sql .= ", f.datec"; $sql .= ", f.date_valid as datev"; @@ -89,13 +89,13 @@ class box_ficheinter extends ModeleBoxes $sql .= ", s.code_client, s.code_compta, s.client"; $sql .= ", s.logo, s.email, s.entity"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - if (empty($user->rights->societe->client->voir)) { + if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= ", ".MAIN_DB_PREFIX."fichinter as f"; $sql .= " WHERE f.fk_soc = s.rowid "; $sql .= " AND f.entity = ".$conf->entity; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_fournisseurs.php b/htdocs/core/boxes/box_fournisseurs.php index 1c14ac0be4f..12936f713ac 100644 --- a/htdocs/core/boxes/box_fournisseurs.php +++ b/htdocs/core/boxes/box_fournisseurs.php @@ -87,12 +87,12 @@ class box_fournisseurs extends ModeleBoxes $sql .= ", s.logo, s.email, s.entity"; $sql .= ", s.datec, s.tms, s.status"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE s.fournisseur = 1"; $sql .= " AND s.entity IN (".getEntity('societe').")"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } // Add where from hooks diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php index 49be094ecb0..49099019737 100644 --- a/htdocs/core/boxes/box_graph_invoices_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_permonth.php @@ -99,7 +99,7 @@ class box_graph_invoices_permonth extends ModeleBoxes if ($user->socid) { $socid = $user->socid; } - if (empty($user->rights->societe->client->voir) || $socid) { + if (!$user->hasRight('societe', 'client', 'voir') || $socid) { $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user } diff --git a/htdocs/core/boxes/box_graph_invoices_peryear.php b/htdocs/core/boxes/box_graph_invoices_peryear.php index df5e505fc2a..d0e9bfea937 100644 --- a/htdocs/core/boxes/box_graph_invoices_peryear.php +++ b/htdocs/core/boxes/box_graph_invoices_peryear.php @@ -93,7 +93,7 @@ class box_graph_invoices_peryear extends ModeleBoxes $prefix = ''; $socid = 0; if ($user->socid) $socid = $user->socid; - if (empty($user->rights->societe->client->voir) || $socid) $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user + if (!$user->hasRight('societe', 'client', 'voir') || $socid) $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user if ($user->hasRight('facture', 'lire')) { $mesg = ''; diff --git a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php index b92862d5089..c2efefe36a9 100644 --- a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php @@ -98,7 +98,7 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes if ($user->socid) { $socid = $user->socid; } - if (empty($user->rights->societe->client->voir) || $socid) { + if (!$user->hasRight('societe', 'client', 'voir') || $socid) { $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user } diff --git a/htdocs/core/boxes/box_graph_nb_ticket_last_x_days.php b/htdocs/core/boxes/box_graph_nb_ticket_last_x_days.php index bf45b0f1cd4..9c7e6ff7f6c 100644 --- a/htdocs/core/boxes/box_graph_nb_ticket_last_x_days.php +++ b/htdocs/core/boxes/box_graph_nb_ticket_last_x_days.php @@ -107,7 +107,7 @@ class box_graph_nb_ticket_last_x_days extends ModeleBoxes $minimumdatec = dol_time_plus_duree($today, -1 * ($days - 1), 'd'); $minimumdatecformated = dol_print_date($minimumdatec, 'dayrfc'); - if ($user->rights->ticket->read) { + if ($user->hasRight('ticket', 'read')) { $sql = "SELECT CAST(t.datec AS DATE) as datec, COUNT(t.datec) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t"; $sql .= " WHERE CAST(t.datec AS DATE) > '".$this->db->idate($minimumdatec)."'"; diff --git a/htdocs/core/boxes/box_graph_nb_tickets_type.php b/htdocs/core/boxes/box_graph_nb_tickets_type.php index 1b2aaeca0d9..35ba1426a86 100644 --- a/htdocs/core/boxes/box_graph_nb_tickets_type.php +++ b/htdocs/core/boxes/box_graph_nb_tickets_type.php @@ -83,7 +83,7 @@ class box_graph_nb_tickets_type extends ModeleBoxes $listofopplabel = array(); $listofoppcode = array(); $colorseriesstat = array(); - if ($user->rights->ticket->read) { + if ($user->hasRight('ticket', 'read')) { $sql = "SELECT ctt.rowid, ctt.label, ctt.code"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_ticket_type as ctt"; $sql .= " WHERE ctt.active = 1"; diff --git a/htdocs/core/boxes/box_graph_orders_permonth.php b/htdocs/core/boxes/box_graph_orders_permonth.php index 849ce2e8b35..7290dba1704 100644 --- a/htdocs/core/boxes/box_graph_orders_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_permonth.php @@ -99,7 +99,7 @@ class box_graph_orders_permonth extends ModeleBoxes if ($user->socid) { $socid = $user->socid; } - if (empty($user->rights->societe->client->voir) || $socid) { + if (!$user->hasRight('societe', 'client', 'voir') || $socid) { $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user } diff --git a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php index 0c2badbb0b8..2361164e15d 100644 --- a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php @@ -98,11 +98,11 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes if ($user->socid) { $socid = $user->socid; } - if (empty($user->rights->societe->client->voir) || $socid) { + if (!$user->hasRight('societe', 'client', 'voir') || $socid) { $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user } - if ($user->rights->fournisseur->commande->lire) { + if ($user->hasRight('fournisseur', 'commande', 'lire')) { $langs->load("orders"); $param_year = 'DOLUSERCOOKIE_box_'.$this->boxcode.'_year'; diff --git a/htdocs/core/boxes/box_graph_product_distribution.php b/htdocs/core/boxes/box_graph_product_distribution.php index 7c9e88239fe..7352948ef56 100644 --- a/htdocs/core/boxes/box_graph_product_distribution.php +++ b/htdocs/core/boxes/box_graph_product_distribution.php @@ -110,10 +110,10 @@ class box_graph_product_distribution extends ModeleBoxes if (!isModEnabled('facture') || !$user->hasRight('facture', 'lire')) { $showinvoicenb = 0; } - if (isModEnabled('propal') || empty($user->rights->propal->lire)) { + if (isModEnabled('propal') || !$user->hasRight('propal', 'lire')) { $showpropalnb = 0; } - if (!isModEnabled('commande') || empty($user->rights->commande->lire)) { + if (!isModEnabled('commande') || !$user->hasRight('commande', 'lire')) { $showordernb = 0; } diff --git a/htdocs/core/boxes/box_graph_propales_permonth.php b/htdocs/core/boxes/box_graph_propales_permonth.php index da2d7710064..9feac62f6da 100644 --- a/htdocs/core/boxes/box_graph_propales_permonth.php +++ b/htdocs/core/boxes/box_graph_propales_permonth.php @@ -101,7 +101,7 @@ class box_graph_propales_permonth extends ModeleBoxes if ($user->socid) { $socid = $user->socid; } - if (empty($user->rights->societe->client->voir) || $socid) { + if (!$user->hasRight('societe', 'client', 'voir') || $socid) { $prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user } diff --git a/htdocs/core/boxes/box_mos.php b/htdocs/core/boxes/box_mos.php index 7a299665faf..a4ab7eb934c 100644 --- a/htdocs/core/boxes/box_mos.php +++ b/htdocs/core/boxes/box_mos.php @@ -84,7 +84,7 @@ class box_mos extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleLatestModifiedMos", $max)); - if ($user->rights->mrp->read) { + if ($user->hasRight('mrp', 'read')) { $sql = "SELECT p.ref as product_ref"; $sql .= ", p.rowid as productid"; $sql .= ", p.tosell"; diff --git a/htdocs/core/boxes/box_produits_alerte_stock.php b/htdocs/core/boxes/box_produits_alerte_stock.php index 72b9e770962..bae7af2198b 100644 --- a/htdocs/core/boxes/box_produits_alerte_stock.php +++ b/htdocs/core/boxes/box_produits_alerte_stock.php @@ -86,7 +86,7 @@ class box_produits_alerte_stock extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleProductsAlertStock", $max)); - if (($user->rights->produit->lire || $user->hasRight('service', 'lire')) && $user->rights->stock->lire) { + if (($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire')) && $user->hasRight('stock', 'lire')) { $sql = "SELECT p.rowid, p.label, p.price, p.ref, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.barcode, p.seuil_stock_alerte, p.entity,"; $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,"; $sql .= " p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,"; @@ -95,10 +95,10 @@ class box_produits_alerte_stock extends ModeleBoxes $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as s on p.rowid = s.fk_product"; $sql .= ' WHERE p.entity IN ('.getEntity($productstatic->element).')'; $sql .= " AND p.seuil_stock_alerte > 0"; - if (empty($user->rights->produit->lire)) { + if (!$user->hasRight('produit', 'lire')) { $sql .= ' AND p.fk_product_type <> 0'; } - if (empty($user->rights->service->lire)) { + if (!$user->hasRight('service', 'lire')) { $sql .= ' AND p.fk_product_type <> 1'; } // Add where from hooks diff --git a/htdocs/core/boxes/box_project.php b/htdocs/core/boxes/box_project.php index eee2a8571ee..36e9dc34f54 100644 --- a/htdocs/core/boxes/box_project.php +++ b/htdocs/core/boxes/box_project.php @@ -86,7 +86,7 @@ class box_project extends ModeleBoxes $i = 0; // list the summary of the orders - if ($user->rights->projet->lire) { + if ($user->hasRight('projet', 'lire')) { include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $projectstatic = new Project($this->db); @@ -97,7 +97,7 @@ class box_project extends ModeleBoxes // Get list of project id allowed to user (in a string list separated by coma) $projectsListId = ''; - if (empty($user->rights->projet->all->lire)) { + if (!$user->hasRight('projet', 'all', 'lire')) { $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid); } @@ -107,7 +107,7 @@ class box_project extends ModeleBoxes $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid"; $sql .= " WHERE p.entity IN (".getEntity('project').")"; // Only current entity or severals if permission ok $sql .= " AND p.fk_statut = ".((int) $projectstatic::STATUS_VALIDATED); // Only open projects - if (empty($user->rights->projet->all->lire)) { + if (!$user->hasRight('projet', 'all', 'lire')) { $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users } diff --git a/htdocs/core/boxes/box_project_opportunities.php b/htdocs/core/boxes/box_project_opportunities.php index 02b8e49151e..d8a73842e09 100644 --- a/htdocs/core/boxes/box_project_opportunities.php +++ b/htdocs/core/boxes/box_project_opportunities.php @@ -94,7 +94,7 @@ class box_project_opportunities extends ModeleBoxes // Get list of project id allowed to user (in a string list separated by coma) $projectsListId = ''; - if (empty($user->rights->projet->all->lire)) { + if (!$user->hasRight('projet', 'all', 'lire')) { $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid); } @@ -109,7 +109,7 @@ class box_project_opportunities extends ModeleBoxes $sql .= " AND p.fk_opp_status > 0"; $sql .= " AND p.fk_statut IN (".$this->db->sanitize($projectstatic::STATUS_DRAFT.",".$projectstatic::STATUS_VALIDATED).")"; // draft and open projects //$sql .= " AND p.fk_statut = ".((int) $projectstatic::STATUS_VALIDATED); // Only open projects - if (empty($user->rights->projet->all->lire)) { + if (!$user->hasRight('projet', 'all', 'lire')) { $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users } diff --git a/htdocs/core/boxes/box_propales.php b/htdocs/core/boxes/box_propales.php index d731e017842..9c6208808a1 100644 --- a/htdocs/core/boxes/box_propales.php +++ b/htdocs/core/boxes/box_propales.php @@ -89,12 +89,12 @@ class box_propales extends ModeleBoxes $sql .= ", s.logo, s.email, s.entity"; $sql .= ", p.rowid, p.ref, p.fk_statut as status, p.datep as dp, p.datec, p.fin_validite, p.date_cloture, p.total_ht, p.total_tva, p.total_ttc, p.tms"; $sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('propal').")"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_prospect.php b/htdocs/core/boxes/box_prospect.php index 69e8432a879..0791f68185e 100644 --- a/htdocs/core/boxes/box_prospect.php +++ b/htdocs/core/boxes/box_prospect.php @@ -93,12 +93,12 @@ class box_prospect extends ModeleBoxes $sql .= ", s.fk_stcomm"; $sql .= ", s.datec, s.tms, s.status"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE s.client IN (2, 3)"; $sql .= " AND s.entity IN (".getEntity('societe').")"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } // Add where from hooks diff --git a/htdocs/core/boxes/box_services_contracts.php b/htdocs/core/boxes/box_services_contracts.php index 55ce8ebd024..d584d84081d 100644 --- a/htdocs/core/boxes/box_services_contracts.php +++ b/htdocs/core/boxes/box_services_contracts.php @@ -81,7 +81,7 @@ class box_services_contracts extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxLastProductsInContract", $max)); - if ($user->rights->service->lire && $user->hasRight('contrat', 'lire')) { + if ($user->hasRight('service', 'lire') && $user->hasRight('contrat', 'lire')) { $contractstatic = new Contrat($this->db); $contractlinestatic = new ContratLigne($this->db); $thirdpartytmp = new Societe($this->db); @@ -95,7 +95,7 @@ class box_services_contracts extends ModeleBoxes $sql .= " INNER JOIN ".MAIN_DB_PREFIX."contrat as c ON s.rowid = c.fk_soc"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } $sql .= ")"; diff --git a/htdocs/core/boxes/box_services_expired.php b/htdocs/core/boxes/box_services_expired.php index 25fa5ca2b1f..375c4bbb7c8 100644 --- a/htdocs/core/boxes/box_services_expired.php +++ b/htdocs/core/boxes/box_services_expired.php @@ -79,14 +79,14 @@ class box_services_expired extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxLastExpiredServices", $max)); - if ($user->rights->contrat->lire) { + if ($user->hasRight('contrat', 'lire')) { // Select contracts with at least one expired service $sql = "SELECT "; $sql .= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.ref_customer, c.ref_supplier,"; $sql .= " s.nom as name, s.rowid as socid, s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,"; $sql .= " MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services"; $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe s, ".MAIN_DB_PREFIX."contratdet as cd"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->db->idate($now)."'"; @@ -95,7 +95,7 @@ class box_services_expired extends ModeleBoxes if ($user->socid) { $sql .= ' AND c.fk_soc = '.((int) $user->socid); } - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } $sql .= " GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid"; diff --git a/htdocs/core/boxes/box_shipments.php b/htdocs/core/boxes/box_shipments.php index 4e54f3c5992..ffaf9190b80 100644 --- a/htdocs/core/boxes/box_shipments.php +++ b/htdocs/core/boxes/box_shipments.php @@ -86,7 +86,7 @@ class box_shipments extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleLastCustomerShipments", $max)); - if ($user->rights->expedition->lire) { + if ($user->hasRight('expedition', 'lire')) { $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias"; $sql .= ", s.code_client, s.code_compta, s.client"; $sql .= ", s.logo, s.email, s.entity"; @@ -101,7 +101,7 @@ class box_shipments extends ModeleBoxes $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc"; } $sql .= " WHERE e.entity IN (".getEntity('expedition').")"; @@ -111,7 +111,7 @@ class box_shipments extends ModeleBoxes if ($user->socid > 0) { $sql.= " AND s.rowid = ".((int) $user->socid); } - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND sc.fk_user = ".((int) $user->id); } else { $sql .= " ORDER BY e.date_delivery, e.ref DESC "; diff --git a/htdocs/core/boxes/box_supplier_orders.php b/htdocs/core/boxes/box_supplier_orders.php index f3db3526bb6..0a93660dbeb 100644 --- a/htdocs/core/boxes/box_supplier_orders.php +++ b/htdocs/core/boxes/box_supplier_orders.php @@ -81,7 +81,7 @@ class box_supplier_orders extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleLatest".(!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) ? "" : "Modified")."SupplierOrders", $max)); - if ($user->rights->fournisseur->commande->lire) { + if ($user->hasRight('fournisseur', 'commande', 'lire')) { $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias"; $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur"; $sql .= ", s.logo, s.email, s.entity"; @@ -92,12 +92,12 @@ class box_supplier_orders extends ModeleBoxes $sql .= ", c.fk_statut as status"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('supplier_order').")"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php b/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php index fabdaabcb6d..c2984fb1b12 100644 --- a/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php +++ b/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php @@ -81,7 +81,7 @@ class box_supplier_orders_awaiting_reception extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleSupplierOrdersAwaitingReception", $max)); - if ($user->rights->fournisseur->commande->lire) { + if ($user->hasRight('fournisseur', 'commande', 'lire')) { $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias"; $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur"; $sql .= ", s.logo, s.email, s.entity"; @@ -92,14 +92,14 @@ class box_supplier_orders_awaiting_reception extends ModeleBoxes $sql .= ", c.fk_statut as status"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('supplier_order').")"; $sql .= " AND c.date_livraison IS NOT NULL"; $sql .= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.")"; - if (empty($user->rights->societe->client->voir) && !$user->socid) { + if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($user->socid) { diff --git a/htdocs/core/boxes/box_task.php b/htdocs/core/boxes/box_task.php index 486342e27d7..86b38495465 100644 --- a/htdocs/core/boxes/box_task.php +++ b/htdocs/core/boxes/box_task.php @@ -115,7 +115,7 @@ class box_task extends ModeleBoxes ); // list the summary of the orders - if ($user->rights->projet->lire) { + if ($user->hasRight('projet', 'lire')) { $boxcontent .= '
'."\n"; $boxcontent .= '