looking to move user and group settings from those tables to a new permissions table.
Trying to do this a simple as possible, ill probably put in a little class
the idea is to have role_id in user table & group_role_id in group table
these have default permissions from permission table (canviewtorrents, editforum etc)
then i have group_permissions table to link group or user to permission id
we check if user role_id & group group_role_id is not default so users in same group can have different settings
i use single array but should be multi permission,group,user etc but that would mean too many edits lol i was also thinking about adding another table called roles with full access, limited access etc but opted to just add name to permission to keep it simple but making that start to start moving user settings
i had it has one join query but that limited scope a little bit
Any thoughts on improvements
then the query stuff
Trying to do this a simple as possible, ill probably put in a little class
the idea is to have role_id in user table & group_role_id in group table
these have default permissions from permission table (canviewtorrents, editforum etc)
then i have group_permissions table to link group or user to permission id
we check if user role_id & group group_role_id is not default so users in same group can have different settings
i use single array but should be multi permission,group,user etc but that would mean too many edits lol i was also thinking about adding another table called roles with full access, limited access etc but opted to just add name to permission to keep it simple but making that start to start moving user settings
i had it has one join query but that limited scope a little bit
Any thoughts on improvements
ALTER TABLE groups
ADD `group_role_id` int(10) NOT NULL DEFAULT 1;
ALTER TABLE users
ADD `role_id` int(10) NOT NULL DEFAULT 1;
CREATE TABLE IF NOT EXISTS `group_permissions` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`permission_id` int(10) NOT NULL DEFAULT 0,
`role_id` int(10) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
INSERT INTO `group_permissions` (`id`, `permission_id`, `role_id`) VALUES
(1,0,1);
CREATE TABLE IF NOT EXISTS `permissions` (
`permission_id` int(10) NOT NULL AUTO_INCREMENT,
`permission_name` varchar(40) NOT NULL DEFAULT 'no name',
`view_torrents` enum('yes','no') NOT NULL DEFAULT 'yes',
`edit_torrents` enum('yes','no') NOT NULL DEFAULT 'no',
`delete_torrents` enum('yes','no') NOT NULL DEFAULT 'no',
`view_users` enum('yes','no') NOT NULL DEFAULT 'yes',
`edit_users` enum('yes','no') NOT NULL DEFAULT 'no',
`delete_users` enum('yes','no') NOT NULL DEFAULT 'no',
`view_news` enum('yes','no') NOT NULL DEFAULT 'yes',
`edit_news` enum('yes','no') NOT NULL DEFAULT 'no',
`delete_news` enum('yes','no') NOT NULL DEFAULT 'no',
`can_upload` enum('yes','no') NOT NULL DEFAULT 'no',
`can_download` enum('yes','no') NOT NULL DEFAULT 'yes',
`view_forum` enum('yes','no') NOT NULL DEFAULT 'yes',
`edit_forum` enum('yes','no') NOT NULL DEFAULT 'yes',
`delete_forum` enum('yes','no') NOT NULL DEFAULT 'no',
PRIMARY KEY (`permission_id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
INSERT INTO `permissions` (`permission_id`, `permission_name`, `view_torrents`, `edit_torrents`, `delete_torrents`, `view_users`, `edit_users`, `delete_users`, `view_news`, `edit_news`, `delete_news`, `can_upload`, `can_download`, `view_forum`, `edit_forum`, `delete_forum`) VALUES
('0','default','yes', 'no','no','yes','no','no','yes','no','no','yes','yes','yes','no','yes'),
(1,'staff', 'yes','yes','yes','yes','yes','yes','yes','yes','yes','yes','yes','yes','yes','yes');then the query stuff
// Lets Build Permission Array
$data = array();
// Get User & Group
$user = DB::run(
"SELECT * FROM `users`
LEFT OUTER JOIN `groups`
ON users.class=groups.group_id
WHERE id = $_COOKIE[id]
AND users.enabled='yes'
AND users.status ='confirmed'"
)->fetch();
foreach ($user as $key => $value) {
$data[$key] = $value;
}
echo '<pre>'.print_r($user, true).'</pre>';
// User Role Or Group Role
$user_or_group_role = $user['role_id'] != 0 ? $user['role_id'] : $user['group_role_id'];
echo '<pre>'.print_r($user_or_group_role, true).'</pre>';
// Now Get Role (default id 1 for default group role)
$role = DB::run(
"SELECT `permission_id`
FROM `group_permissions` WHERE `role_id`=?",
[$user_or_group_role]
)->fetchColumn();
echo '<pre>'.print_r($role, true).'</pre>';
// Now Get Permission
$permission = DB::run(
"SELECT *
FROM `permissions` WHERE `permission_id`=?",
[$role]
)->fetch(PDO::FETCH_ASSOC);
foreach ($permission as $key => $value) {
$data[$key] = $value;
}
echo '<pre>'.print_r($permission, true).'</pre>';
// Full Single Array (less editing for now but should be multi)
echo '<pre>'.print_r($data, true).'</pre>';
