Jump to content

access level on user and page wise


Recommended Posts

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

post-203240-0-53663800-1496331083_thumb.png

post-203240-0-22134700-1496331095_thumb.png

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...)

 

 

 

Link to post
Share on other sites
This thread is more than a year old.

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.