dishadcruze Posted June 1, 2017 Share Posted June 1, 2017 I have created a script for access level. where i give access on user basis for each page. i have a table page with links and page name and i have table access_level to store page ids with user id who has the access to which page Here are the tables Giving access like this , permissions.php <ul id="demo2" class="mnav"> <li><a href="#">Sales</a> <ul> <li><a href="#">Lead</a> <ul><table align="center" width="900px;"> <?php $s1 = mysqli_query($con, "SELECT * FROM pages WHERE code='ld'") or die(mysqli_error($con)); while($s2 = mysqli_fetch_array($s1)) { ?> <tr><td><li><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['page_id']; ?>" /> </li></td></tr> <?php } ?> </table> </ul> </li> <li><a href="#">Customer</a> <ul><table align="center" width="900px;"> <?php $s1 = mysqli_query($con, "SELECT * FROM pages WHERE code='cst'") or die(mysqli_error($con)); while($s2 = mysqli_fetch_array($s1)) { ?> <tr><td><li><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['page_id']; ?>" /> </li></td></tr> <?php } ?> </table> </ul> </li> </li> </ul> I am saving it like this if(isset($_POST['submit'])) { $user = $_POST['user']; foreach($_POST['sn'] as $sn) { $sql = "insert into access (page_id, user_id, active) values (".$sn.", ".$user.", 1)"; $query = mysqli_query($con, $sql) or die (mysqli_error($con)); } } User ID i am getting from a dropdown from users table. Code works fine. But instead of Delete, Details, Print i want to make it as 'All' . When i check 'All' checkbox all the value (New, View, Edit, Delete, Details) has to be checked from that code . I am not getting how to do it. Please suggest I tried Doing like this <script type="text/javascript"> function do_this(){ var checkboxes = document.getElementsByName('sn[]'); var button = document.getElementById('toggle'); if(button.value == 'select'){ for (var i in checkboxes){ checkboxes[i].checked = 'FALSE'; } button.value = 'deselect' }else{ for (var i in checkboxes){ checkboxes[i].checked = ''; } button.value = 'select'; } } </script> <tr><td>Customer</td> <?php $s1 = mysqli_query($con, "SELECT * FROM pages WHERE code='cst'") or die(mysqli_error($con)); while($s2 = mysqli_fetch_array($s1)) { ?> <td><input type="checkbox" name="sn[]" value="<?php echo $s2['page_id']; ?>" /> </td> <?php } ?> <td><input type="button" id="toggle" value="select" onClick="do_this()" /></td> </tr> But it selects all the check boxes (as my checkbox name is sn[] for all) means from all the codes (led, cst...) Quote Link to comment Share on other sites More sharing options...
benanamen Posted June 1, 2017 Share Posted June 1, 2017 For what you are doing you want to implement "Bitwise Permissions". Here is a simple example http://sforsuresh.in/implemention-of-user-permission-with-php-mysql-bitwise-operators/ Quote Link to comment Share on other sites More sharing options...
dishadcruze Posted June 1, 2017 Author Share Posted June 1, 2017 (edited) @benanamen So for each section (Lead, Customer..) I should have bt values in 2's multiples? Thanks lot. I will try now. Please help me if i face any issues in the coding. Edited June 1, 2017 by dishadcruze Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.