Click here to Skip to main content
15,881,803 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: PHP 8.1 Count issue Pin
Richard MacCutchan30-Mar-23 0:45
mveRichard MacCutchan30-Mar-23 0:45 
AnswerRe: PHP 8.1 Count issue Pin
Richard Deeming30-Mar-23 0:45
mveRichard Deeming30-Mar-23 0:45 
GeneralRe: PHP 8.1 Count issue Pin
Aruna KN30-Mar-23 1:38
Aruna KN30-Mar-23 1:38 
GeneralRe: PHP 8.1 Count issue Pin
Richard Deeming30-Mar-23 2:53
mveRichard Deeming30-Mar-23 2:53 
GeneralRe: PHP 8.1 Count issue Pin
Aruna KN30-Mar-23 3:21
Aruna KN30-Mar-23 3:21 
QuestionIf command triggering at wrong time with PHP 8.1 Pin
Aruna KN29-Mar-23 18:56
Aruna KN29-Mar-23 18:56 
AnswerRe: If command triggering at wrong time with PHP 8.1 Pin
Richard Deeming29-Mar-23 21:22
mveRichard Deeming29-Mar-23 21:22 
GeneralRe: If command triggering at wrong time with PHP 8.1 Pin
Aruna KN29-Mar-23 21:27
Aruna KN29-Mar-23 21:27 
GeneralRe: If command triggering at wrong time with PHP 8.1 Pin
Aruna KN29-Mar-23 22:15
Aruna KN29-Mar-23 22:15 
QuestionBlank space or NULL with PHP 8.1 Pin
Aruna KN14-Mar-23 22:57
Aruna KN14-Mar-23 22:57 
AnswerRe: Blank space or NULL with PHP 8.1 Pin
Richard MacCutchan15-Mar-23 7:10
mveRichard MacCutchan15-Mar-23 7:10 
QuestionPHP Fatal error: Uncaught TypeError: count() Pin
Aruna KN10-Mar-23 20:17
Aruna KN10-Mar-23 20:17 
AnswerRe: PHP Fatal error: Uncaught TypeError: count() Pin
Graham Breach11-Mar-23 1:45
Graham Breach11-Mar-23 1:45 
GeneralRe: PHP Fatal error: Uncaught TypeError: count() Pin
Aruna KN11-Mar-23 16:32
Aruna KN11-Mar-23 16:32 
Questionhtaccess %3F redirect issue Pin
Aruna KN10-Mar-23 19:40
Aruna KN10-Mar-23 19:40 
QuestionHow to develop a game using implement the api Pin
piumini sakunthala2-Feb-23 21:06
piumini sakunthala2-Feb-23 21:06 
QuestionRe: How to develop a game using implement the api Pin
Richard MacCutchan2-Feb-23 21:41
mveRichard MacCutchan2-Feb-23 21:41 
QuestionWordpress shortcode prints wrong value from custom post type Pin
moinmobility9-Oct-22 7:36
moinmobility9-Oct-22 7:36 
Questionimplement ElFinder in PHP language Pin
Alexis Sanchez Vanegas19-May-22 4:28
Alexis Sanchez Vanegas19-May-22 4:28 
QuestionAapanel upload project laravel Pin
marziyeh barooei9-May-22 1:05
marziyeh barooei9-May-22 1:05 
Questionhow do I get total quantity from this code Pin
wixily jnr28-Apr-22 13:29
wixily jnr28-Apr-22 13:29 
AnswerRe: how do I get total quantity from this code Pin
Richard MacCutchan28-Apr-22 21:31
mveRichard MacCutchan28-Apr-22 21:31 
QuestionROLES ET PRIVILEGES UTILISATEURS D'UN SITE Pin
ameb290825-Apr-22 4:06
ameb290825-Apr-22 4:06 
Bonjour, j'ai un soucis avec les privilèges utilisateurs (AUCUN, EDITEUR, ADMINISTRATEUR).

C'est à dire, en fonction des identifiants rentrés, on a accès à certaines liens du menu.

et malheureusement chez moi le menu ne s'affiche pas. Besoin d'aide, merci d'avance.

voici mon code :

class/Usermanager.php

PHP
class Usermanager {

    private $db;
 
    public function __construct($db) {

        $this->setDb($db);
    }

    public function setDb(PDO $dbh) {

        return $this->db = $dbh;
    }

    public function displayMenu($user_role_id) {

         try {

            $sql = 'SELECT A.name, A.slug
                    FROM user_action AS A
                    INNER JOIN user_permission AS P
                    ON A.actionID = P.action_id
                    AND P.min_role_id < :user_role_id';

            $stmnt = $this->db->prepare($sql);
            $stmnt->execute(array(

                ':user_role_id' => $user_role_id
            ));

            while($row = $stmnt->fetch(PDO::FETCH_ASSOC)) {

                $menu_data[] = $row;
            }

            if(isset($menu_data)) {

                return $menu_data;
            }
            else {

                return false;
            }
        }
        catch(PDOException $e) {

            echo MSG_ERROR . $e->getMessage();
        }
    }

    public function checkUserPermission($action_slug, $user_role_id) {

        try {
        
            $sql = 'SELECT P.action_id, P.min_role_id
                    FROM user_permission AS P
                    INNER JOIN user_action AS A
                    ON A.slug = :action_slug
                    AND P.action_id = A.actionID';
                    

            $stmnt = $this->db->prepare($sql);
            $stmnt->execute(array(

                ':action_slug' => $action_slug
            ));

            while($row = $stmnt->fetch(PDO::FETCH_ASSOC)) {

                $min_role_id = $row['P.min_role_id'];

                if($min_role_id > $user_role_id) {

                    return $min_role_id;
                }
            }
        }
        catch(PDOException $e) {

            echo MSG_ERROR . $e->getMessage();
        }
    }
}


process/process-display-menu.php

PHP
$username_form = isset($_SESSION['username_form']) ? $_SESSION['username_form'] : NULL;

$manager = new Usermanager($db);
$menu_items = $manager->displayMenu($username_form);

$menu_html = '';

if(!empty($menu_items)) {

    foreach($menu_items as $menu_item) {

        $name = $menu_item['name'];
        $slug = $menu_item['slug'];

        $menu_html .= '<li><a href="' . $slug . '.php">' . $name . '</a></li>' . "\n";
    }
}


process/process-user-permission.php

PHP
$action_slug = substr($filename, 0, 4);

$username_form = isset($_SESSION['username_form']) ? $_SESSION['username_form'] : NULL;

$manager = new Usermanager($db);
$userPermission = $manager->checkUserPermission($action_slug, $username_form);

if($userPermission === false) {

    echo 'Erreur. Cette page n\'existe pas.';

    exit;
}


admin/menu.php

PHP
require('../process/process-display-menu.php');


HTML
<ul class="menu">
    <?php echo $menu_html; ?>
    <li><a href="../index.php">Site web</a></li>
    <li><a href="logout.php">Déconnexion</a></li>
</ul>


admin/index.php

PHP
require('../include/inc-connexion.php');
require('../include/inc-config.php');
require('../include/inc-identification-user.php');

$filename = basename( __FILE__ );
require('../process/process-user-permission.php');
require('menu.php');

QuestionHow can I do a google search and get results in backend using JS or PHP? Pin
Social Bookmarking Site14-Apr-22 15:27
Social Bookmarking Site14-Apr-22 15:27 
Questionproblem in pagination click Pin
irfankundi7861-Apr-22 23:39
irfankundi7861-Apr-22 23:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.