Profile_User::showForUser PHP Méthode

showForUser() static public méthode

Show rights of a user
static public showForUser ( User $user )
$user User User object
    static function showForUser(User $user)
    {
        global $DB, $CFG_GLPI;
        $ID = $user->getField('id');
        if (!$user->can($ID, READ)) {
            return false;
        }
        $canedit = $user->canEdit($ID);
        $strict_entities = self::getUserEntities($ID, false);
        if (!Session::haveAccessToOneOfEntities($strict_entities) && !Session::isViewAllEntities()) {
            $canedit = false;
        }
        $canshowentity = Entity::canView();
        $rand = mt_rand();
        if ($canedit) {
            echo "<div class='firstbloc'>";
            echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='";
            echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
            echo "<table class='tab_cadre_fixe'>";
            echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Add an authorization to a user') . "</tr>";
            echo "<tr class='tab_bg_2'><td class='center'>";
            echo "<input type='hidden' name='users_id' value='{$ID}'>";
            Entity::dropdown(array('entity' => $_SESSION['glpiactiveentities']));
            echo "</td><td class='center'>" . self::getTypeName(1) . "</td><td>";
            Profile::dropdownUnder(array('value' => Profile::getDefault()));
            echo "</td><td>" . __('Recursive') . "</td><td>";
            Dropdown::showYesNo("is_recursive", 0);
            echo "</td><td class='center'>";
            echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
            echo "</td></tr>";
            echo "</table>";
            Html::closeForm();
            echo "</div>";
        }
        $query = "SELECT DISTINCT `glpi_profiles_users`.`id` AS linkID,\n                       `glpi_profiles`.`id`,\n                       `glpi_profiles`.`name`,\n                       `glpi_profiles_users`.`is_recursive`,\n                       `glpi_profiles_users`.`is_dynamic`,\n                       `glpi_entities`.`completename`,\n                       `glpi_profiles_users`.`entities_id`\n                FROM `glpi_profiles_users`\n                LEFT JOIN `glpi_profiles`\n                     ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n                LEFT JOIN `glpi_entities`\n                     ON (`glpi_profiles_users`.`entities_id` = `glpi_entities`.`id`)\n                WHERE `glpi_profiles_users`.`users_id` = '{$ID}'\n                ORDER BY `glpi_profiles`.`name`, `glpi_entities`.`completename`";
        $result = $DB->query($query);
        $num = $DB->numrows($result);
        echo "<div class='spaced'>";
        Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
        if ($canedit && $num) {
            $massiveactionparams = array('num_displayed' => $num, 'container' => 'mass' . __CLASS__ . $rand);
            Html::showMassiveActions($massiveactionparams);
        }
        if ($num > 0) {
            echo "<table class='tab_cadre_fixehov'>";
            $header_begin = "<tr>";
            $header_top = '';
            $header_bottom = '';
            $header_end = '';
            if ($canedit) {
                $header_begin .= "<th>";
                $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
                $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
                $header_end .= "</th>";
            }
            $header_end .= "<th>" . _n('Entity', 'Entities', Session::getPluralNumber()) . "</th>";
            $header_end .= "<th>" . sprintf(__('%1$s (%2$s)'), self::getTypeName(Session::getPluralNumber()), __('D=Dynamic, R=Recursive'));
            $header_end .= "</th></tr>";
            echo $header_begin . $header_top . $header_end;
            while ($data = $DB->fetch_assoc($result)) {
                echo "<tr class='tab_bg_1'>";
                if ($canedit) {
                    echo "<td width='10'>";
                    if (in_array($data["entities_id"], $_SESSION['glpiactiveentities'])) {
                        Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
                    } else {
                        echo "&nbsp;";
                    }
                    echo "</td>";
                }
                echo "<td>";
                $link = $data["completename"];
                if ($_SESSION["glpiis_ids_visible"]) {
                    $link = sprintf(__('%1$s (%2$s)'), $link, $data["entities_id"]);
                }
                if ($canshowentity) {
                    echo "<a href='" . Toolbox::getItemTypeFormURL('Entity') . "?id=" . $data["entities_id"] . "'>";
                }
                echo $link . ($canshowentity ? "</a>" : '');
                echo "</td>";
                if (Profile::canView()) {
                    $entname = "<a href='" . Toolbox::getItemTypeFormURL('Profile') . "?id=" . $data["id"] . "'>" . $data["name"] . "</a>";
                } else {
                    $entname = $data["name"];
                }
                if ($data["is_dynamic"] || $data["is_recursive"]) {
                    $entname = sprintf(__('%1$s %2$s'), $entname, "<span class='b'>(");
                    if ($data["is_dynamic"]) {
                        //TRANS: letter 'D' for Dynamic
                        $entname = sprintf(__('%1$s%2$s'), $entname, __('D'));
                    }
                    if ($data["is_dynamic"] && $data["is_recursive"]) {
                        $entname = sprintf(__('%1$s%2$s'), $entname, ", ");
                    }
                    if ($data["is_recursive"]) {
                        //TRANS: letter 'R' for Recursive
                        $entname = sprintf(__('%1$s%2$s'), $entname, __('R'));
                    }
                    $entname = sprintf(__('%1$s%2$s'), $entname, ")</span>");
                }
                echo "<td>" . $entname . "</td>";
                echo "</tr>";
            }
            echo $header_begin . $header_bottom . $header_end;
            echo "</table>";
        } else {
            echo "<table class='tab_cadre_fixe'>";
            echo "<tr><th>" . __('No item found') . "</th></tr>";
            echo "</table>\n";
        }
        if ($canedit && $num) {
            $massiveactionparams['ontop'] = false;
            Html::showMassiveActions($massiveactionparams);
        }
        Html::closeForm();
        echo "</div>";
    }

Usage Example

            break;
        case 3:
            Ticket::showListForUser($_POST["id"]);
            break;
        case 4:
            Group_User::showForUser($user);
            break;
        case 5:
            Document::showAssociated($user);
            break;
        case 6:
            $config = new Config();
            $user->computePreferences();
            $config->showFormUserPrefs($user->fields);
            break;
        case 11:
            Reservation::showForUser($_POST["id"]);
            break;
        case 12:
            Auth::showSynchronizationForm($_POST["id"]);
            break;
        case 13:
            Log::showForItem($user);
            break;
        default:
            if (!Plugin::displayAction($user, $_REQUEST['glpi_tab'])) {
                Profile_User::showForUser($user);
            }
    }
}
ajaxFooter();