diff --git a/htdocs/admin/supplier_order.php b/htdocs/admin/supplier_order.php index 5a3c3808201..b7c7d3b5c3d 100644 --- a/htdocs/admin/supplier_order.php +++ b/htdocs/admin/supplier_order.php @@ -182,43 +182,27 @@ else if ($action == 'set_SUPPLIER_ORDER_OTHER') $res3=1; }*/ - // TODO We add/delete permission until permission can have a condition on a global var - $r_id = 1190; - $entity = $conf->entity; - $r_desc=$langs->trans("Permission1190"); - $r_modul='fournisseur'; - $r_type='w'; - $r_perms='commande'; - $r_subperms='approve2'; - $r_def=0; + // TODO We add/delete permission here until permission can have a condition on a global var + include_once DOL_DOCUMENT_ROOT.'/core/modules/modFournisseur.class.php'; + $newmodule=new modFournisseur($db); + // clear default rights array + $newmodule->rights=array(); + // add new right + $r=0; + $newmodule->rights[$r][0] = 1190; + $newmodule->rights[$r][1] = $langs->trans("Permission1190"); + $newmodule->rights[$r][2] = 'w'; + $newmodule->rights[$r][3] = 0; + $newmodule->rights[$r][4] = 'commande'; + $newmodule->rights[$r][5] = 'approve2'; if ($conf->global->SUPPLIER_ORDER_DOUBLE_APPROVAL) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def"; - $sql.= " (id, entity, libelle, module, type, bydefault, perms, subperms)"; - $sql.= " VALUES "; - $sql.= "(".$r_id.",".$entity.",'".$db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."','".$r_subperms."')"; - - $resqlinsert=$db->query($sql,1); - if (! $resqlinsert) - { - if ($db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS") - { - setEventMessage($db->lasterror(),'errors'); - $error++; - } - } + $newmodule->insert_permissions(1); } else { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."rights_def"; - $sql.= " WHERE id = ".$r_id; - $resqldelete=$db->query($sql,1); - if (! $resqldelete) - { - setEventMessage($db->lasterror(),'errors'); - $error++; - } + $newmodule->delete_permissions(); } } diff --git a/htdocs/core/modules/modFournisseur.class.php b/htdocs/core/modules/modFournisseur.class.php index 2e42c1f8b66..dc537426179 100644 --- a/htdocs/core/modules/modFournisseur.class.php +++ b/htdocs/core/modules/modFournisseur.class.php @@ -161,6 +161,14 @@ class modFournisseur extends DolibarrModules $this->rights[$r][4] = 'commande'; $this->rights[$r][5] = 'approuver'; + /*$r++; + $this->rights[$r][0] = 1191; + $this->rights[$r][1] = 'Approuver une commande fournisseur (si supérieur hiérarchique)'; + $this->rights[$r][2] = 'w'; + $this->rights[$r][3] = 0; + $this->rights[$r][4] = 'commande'; + $this->rights[$r][5] = 'approve_ifsupervisor_advance';*/ + $r++; $this->rights[$r][0] = 1186; $this->rights[$r][1] = 'Commander une commande fournisseur'; @@ -250,6 +258,18 @@ class modFournisseur extends DolibarrModules $this->rights[$r][4] = 'commande'; $this->rights[$r][5] = 'export'; + if ($conf->global->SUPPLIER_ORDER_DOUBLE_APPROVAL) + { + $r++; + $this->rights[$r][0] = 1190; + $this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190"); + $this->rights[$r][2] = 'w'; + $this->rights[$r][3] = 0; + $this->rights[$r][4] = 'commande'; + $this->rights[$r][5] = 'approve2'; + } + + // Exports //-------- $r=0; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index b1d20b72371..e2f7fb0ca03 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -190,7 +190,7 @@ if (empty($reshook)) if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver) + if ($action == 'reopen') // no test on permission here, permission to use will depends on status { if (in_array($object->statut, array(1, 2, 5, 6, 7, 9))) {