I have a table of permissions, a table of roles, and a mapping table. I'd like to create a GUI for a website admin to be able to add new roles and assign permissions to that role. Currently it's done at the database as such subject to user error.
For sake of simplicity, let's say we have four roles, SuperAdmin, Admin, Manager, and User. Permissions are Create, Read, Update, Delete. In the diagram below SuperAdmin and Admin match as do Manager and User (product of a user error and further why I'm wanting to create the GUI but I digress).
Currently my output displays a row for each Role whereas ideally the Role would be only displayed once and the appropriate checkbox would be ticked for the corresponding Permission similar to the following:
Here is the CF code I have and I don't know how to approach this to do what I want.
<cfquery name="securityGroups" datasource="#application.support#">
Select
r.roleLabel,
r.roleID,
p.permName,
p.permID
From
npermissions p Inner Join
nrole_npermission_map rp On rp.permissionID = p.permID Inner Join
nroles r On rp.roleID = r.roleID
</cfquery>
<cfquery name="securityPermissions" datasource="#application.support#">
Select
p.permName,
p.permID
From
npermissions p
</cfquery>
<table id="datatables" class="datatables">
<thead>
<tr>
<th>Role</th>
<cfoutput query="securityPermissions">
<th>#securityPermissions.permName#</th>
</cfoutput>
</tr>
</thead>
<tbody>
<cfoutput query="securityGroups" group="roleID">
<tr>
<td>#securityGroups.roleLabel#</td>
<cfoutput>
<td>
<input type="checkbox" name="permID" value="#securityPermissions.permID#" <cfif securityGroups.permID eq securityPermissions.permID>checked</cfif> >#securityPermissions.permname# (#securityGroups.permID# eq #securityPermissions.permID#)
</td>
</cfoutput>
</tr>
</cfoutput>
</tbody>
</table>
With the code above, this produces the following output which is the closest I've been able to get to my desired output. The right permissions are displayed but the checkboxes are not checked and of some permissions are not being displayed.
I thought I remember reading something about this years ago on easycfm as either a tutorial or in the forums.