Jump to content

Recommended Posts

Form: Group Permissions

Goal:  To loop through all categories that have something checked under it and insert database rows accordingly

 

Example:  An admin creates a group and chooses the ability to create, modify, and delete under the Xbox 360 category.  The script inserts a row into the permissions table(shown below) with the id of the Xbox 360 subcategory and the value of 1(true) for create, modify, and delete.

 

Permissions Table: VVV

permissiontable.jpg

 

Group Table: VVV

grouptable.jpg

 

Permission Form Example:

groupperms.jpg

 

Permission Form Source:

        
        <table align='center' cellspacing='1' cellpadding='3' border='0'>
        
        	<tr>
            
            	<td align='right'>Category</td>
                <td align='center'>Read</td>
                <td align='center'>Create</td>
                <td align='center'>Modify</td> 
                <td align='center'>Attach</td>

                <td align='center'>Comment</td>
                <td align='center'>Delete</td>
                
            </tr><tr>
            
            	<td align='left' colspan='7' style='background: #e4e4e4;'>News</td>

						</tr><tr><td align='right'>Website</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>

<td align='left' colspan='7' style='background: #e4e4e4;'>Reviews</td>

						</tr><tr><td align='right'>Xbox 360</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>
<td align='right'>PlayStation 3</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>
<td align='right'>Nintendo Wii</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>
<td align='right'>PC Games</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>
<td align='right'>Nintendo DS</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>
<td align='right'>PlayStation Portable</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>
<td align='left' colspan='7' style='background: #e4e4e4;'>Tutorials</td>

						</tr><tr><td align='right'>HTML/CSS</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>
<td align='right'>PHP Coding</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>

<td align='right'>JavaScript</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>
<td align='right'>Adobe PhotoShop</td>

				  <td align='center'><input type='checkbox' name='read[]' id='read[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='create[]' id='create[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='modify[]' id='modify[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='attach[]' id='attach[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='comment[]' id='comment[]' value='1'></td>

				  <td align='center'><input type='checkbox' name='delete[]' id='delete[]' value='1'></td>

			</tr><tr>

                
            </tr>
            
        </table>

 

How would I do something like this?

Link to comment
https://forums.phpfreaks.com/topic/189403-group-permissions-with-checkboxes/
Share on other sites

1) I would use bit flags instead of tinyint/bools

 

I posted not to long ago, a set of functions to use bitflags... all the knowledge you need is that integer fields are 32 bits, so you can have a total of 32 flags, a tiny int is 8 bits, so you can use a tinyint in your db, but you would have to assign it as unsigned tinyint, as mysql would consider a tinyint int the rage of -127 to 128, and php only works with full ints.

 

BitFlags Quick Start

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.