ShoeLace1291 Posted January 22, 2010 Share Posted January 22, 2010 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 Group Table: VVV Permission Form Example: 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 More sharing options...
laffin Posted January 22, 2010 Share Posted January 22, 2010 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 Link to comment https://forums.phpfreaks.com/topic/189403-group-permissions-with-checkboxes/#findComment-999776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.