diff --git a/htdocs/admin/perms.php b/htdocs/admin/perms.php index 1f811c325dd..6ad62242f6f 100644 --- a/htdocs/admin/perms.php +++ b/htdocs/admin/perms.php @@ -35,6 +35,8 @@ $action = GETPOST('action', 'aZ09'); if (!$user->admin) accessforbidden(); +$entity=$conf->entity; + /* * Actions @@ -70,14 +72,12 @@ print ''.$langs->trans("DefaultRightsDesc")." ".$lan $db->begin(); -// Charge les modules soumis a permissions +// Search all modules with permission and reload permissions def. $modules = array(); $modulesdir = dolGetModulesDirs(); foreach ($modulesdir as $dir) { - // Load modules attributes in arrays (name, numero, orders) from dir directory - //print $dir."\n
"; $handle = @opendir(dol_osencode($dir)); if (is_resource($handle)) { @@ -102,7 +102,7 @@ foreach ($modulesdir as $dir) // Load all permissions if ($objMod->rights_class) { - $ret = $objMod->insert_permissions(0); + $ret = $objMod->insert_permissions(0, $entity); $modules[$objMod->rights_class] = $objMod; //print "modules[".$objMod->rights_class."]=$objMod;"; } @@ -122,35 +122,58 @@ dol_fiche_head($head, 'default', $langs->trans("Security"), -1); // Show warning about external users print info_admin(showModulesExludedForExternal($modules)).'
'."\n"; +print "\n"; print '
'; print ''; -// Show permissions lines -$sql = "SELECT r.id, r.libelle, r.module, r.perms, r.subperms, r.bydefault"; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''."\n"; + +//print "xx".$conf->global->MAIN_USE_ADVANCED_PERMS; +$sql = "SELECT r.id, r.libelle as label, r.module, r.module_position, r.perms, r.subperms, r.bydefault"; $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r"; $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous" -$sql .= " AND entity = ".$conf->entity; +$sql .= " AND r.entity = ".$entity; if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled -$sql .= " ORDER BY r.module, r.id"; +$sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; - $oldmod = ""; + $oldmod = ''; while ($i < $num) { $obj = $db->fetch_object($result); - // Si la ligne correspond a un module qui n'existe plus (absent de includes/module), on l'ignore - if (!$modules[$obj->module]) + // If line is for a module that doe snot existe anymore (absent of includes/module), we ignore it + if (empty($modules[$obj->module])) { $i++; continue; } + // Save field module_position in database if value is still zero + if (empty($obj->module_position)) + { + if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) + { + // TODO Define familyposition + $family = $modules[$obj->module]->family_position; + $familyposition = 0; + $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def SET module_position = ".$modules[$obj->module]->module_position.","; + $sqlupdate.= " family_position = ".$familyposition; + $sqlupdate.= " WHERE module_position = 0 AND module = '".$db->escape($obj->module)."'"; + $db->query($sqlupdate); + } + } + // Check if permission we found is inside a module definition. If not, we discard it. $found = false; foreach ($modules[$obj->module]->rights as $key => $val) @@ -169,49 +192,65 @@ if ($result) } // Break found, it's a new module to catch - if ($oldmod <> $obj->module) + if (isset($obj->module) && ($oldmod <> $obj->module)) { $oldmod = $obj->module; + + // Break detected, we get objMod $objMod = $modules[$obj->module]; $picto = ($objMod->picto ? $objMod->picto : 'generic'); - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; + // Show break line + print ''; + print ''; + print ''; + print ''; + print ''; + print ''."\n"; } - + $perm_libelle = ($conf->global->MAIN_USE_ADVANCED_PERMS && ($langs->trans("PermissionAdvanced".$obj->id) != ("PermissionAdvanced".$obj->id)) ? $langs->trans("PermissionAdvanced".$obj->id) : (($langs->trans("Permission".$obj->id) != ("Permission".$obj->id)) ? $langs->trans("Permission".$obj->id) : $obj->label)); + print ''; - print ''; - $perm_libelle = ($conf->global->MAIN_USE_ADVANCED_PERMS && ($langs->trans("PermissionAdvanced".$obj->id) != ("PermissionAdvanced".$obj->id)) ? $langs->trans("PermissionAdvanced".$obj->id) : (($langs->trans("Permission".$obj->id) != ("Permission".$obj->id)) ? $langs->trans("Permission".$obj->id) : $obj->libelle)); + // Tick + if ($obj->bydefault == 1) + { + print ''; + print ''; + } + else + { + print ''; + print ''; + } + + // Permission and tick print ''; - print ''; + print ''."\n"; + $i++; } } - +else dol_print_error($db); print '
'.$langs->trans("Module").' '.$langs->trans("Default").''.$langs->trans("Permissions").'
'.$langs->trans("Module").''.$langs->trans("Permission").''.$langs->trans("Default").' 
'; + print img_object('', $picto, 'class="pictoobjectwidth"').' '.$objMod->getName(); + print ''; + print '   
'; - print img_object('', $picto, 'class="pictoobjectwidth"').' '.$objMod->getName(); - print ' '; + + // Picto and label of module + print ''; + //print img_object('', $picto, 'class="pictoobjectwidth"').' '.$objMod->getName(); + //print ' '; print ''; + print ''.img_edit_remove().''; + print ''; + print img_picto($langs->trans("Active"), 'tick'); + print ''; + print ''.img_edit_add().''; + print ''; + print ' '; + print ''.$perm_libelle.''; - if ($obj->bydefault == 1) - { - print img_picto($langs->trans("Active"), 'tick'); - print ''; - print ''.img_edit_remove().''; - } - else - { - print ' '; - print ''; - print ''.img_edit_add().''; - } - - print '
'; print '
'; diff --git a/htdocs/user/perms.php b/htdocs/user/perms.php index 62070e3b31e..05814f4b832 100644 --- a/htdocs/user/perms.php +++ b/htdocs/user/perms.php @@ -77,7 +77,7 @@ $entity=$conf->entity; $hookmanager->initHooks(array('usercard','userperms','globalcard')); -/** +/* * Actions */ @@ -128,7 +128,7 @@ if (empty($reshook)) { } -/** +/* * View */ @@ -175,7 +175,7 @@ foreach($modulesdir as $dir) // Load all permissions if ($objMod->rights_class) { - $ret=$objMod->insert_permissions(0, $entity); + $ret = $objMod->insert_permissions(0, $entity); $modules[$objMod->rights_class]=$objMod; //print "modules[".$objMod->rights_class."]=$objMod;"; } @@ -271,8 +271,9 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e print "\n"; -print '
'; -print ''; +print '
'; +print '
'; + print ''; print ''; if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin)) @@ -295,7 +296,7 @@ $sql = "SELECT r.id, r.libelle as label, r.module, r.module_position"; $sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r"; $sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous" $sql.= " AND r.entity = " . $entity; -if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is disable +if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled $sql.= " ORDER BY r.family_position, r.module_position, r.module, r.id"; $result=$db->query($sql); @@ -370,7 +371,9 @@ if ($result) print ''; // Picto and label of module - print ''; + print ''; // Permission and tick if (! empty($object->admin) && ! empty($objMod->rights_admin_allowed)) // Permission granted because admin @@ -393,7 +396,6 @@ if ($result) print img_picto($langs->trans("Active"), 'tick'); print ''; } - elseif (is_array($permsgroupbyentity[$entity])) { if (in_array($obj->id, $permsgroupbyentity[$entity])) // Permission granted by group
'.$langs->trans("Module").'
'.img_object('', $picto, 'class="pictoobjectwidth"').' '.$objMod->getName().''; + //print img_object('', $picto, 'class="pictoobjectwidth"').' '.$objMod->getName(); + print '