Profile_User::showForProfile PHP Method

showForProfile() static public method

Show the User having a profile, in allowed Entity
static public showForProfile ( Profile $prof )
$prof Profile Profile object
    static function showForProfile(Profile $prof)
    {
        global $DB, $CFG_GLPI;
        $ID = $prof->fields['id'];
        $canedit = Session::haveRightsOr("user", array(CREATE, UPDATE, DELETE, PURGE));
        $rand = mt_rand();
        if (!$prof->can($ID, READ)) {
            return false;
        }
        $query = "SELECT `glpi_users`.*,\n                       `glpi_profiles_users`.`entities_id` AS entity,\n                       `glpi_profiles_users`.`id` AS linkID,\n                       `glpi_profiles_users`.`is_dynamic`,\n                       `glpi_profiles_users`.`is_recursive`\n                FROM `glpi_profiles_users`\n                LEFT JOIN `glpi_entities`\n                     ON (`glpi_entities`.`id`=`glpi_profiles_users`.`entities_id`)\n                LEFT JOIN `glpi_users`\n                     ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n                WHERE `glpi_profiles_users`.`profiles_id` = '{$ID}'\n                      AND `glpi_users`.`is_deleted` = '0' " . getEntitiesRestrictRequest("AND", "glpi_profiles_users", 'entities_id', $_SESSION['glpiactiveentities'], true) . "\n                ORDER BY `glpi_entities`.`completename`";
        $result = $DB->query($query);
        $nb = $DB->numrows($result);
        echo "<div class='spaced'>";
        if ($canedit && $nb) {
            Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
            $massiveactionparams = array('num_displayed' => $nb, 'container' => 'mass' . __CLASS__ . $rand);
            Html::showMassiveActions($massiveactionparams);
        }
        echo "<table class='tab_cadre_fixe'><tr>";
        echo "<th>" . sprintf(__('%1$s: %2$s'), __('Profile'), $prof->fields["name"]) . "</th></tr>\n";
        echo "<tr><th colspan='2'>" . sprintf(__('%1$s (%2$s)'), _n('User', 'Users', Session::getPluralNumber()), __('D=Dynamic, R=Recursive')) . "</th></tr>";
        echo "</table>\n";
        echo "<table class='tab_cadre_fixe'>";
        $i = 0;
        $nb_per_line = 3;
        $rand = mt_rand();
        // Just to avoid IDE warning
        $canedit_entity = false;
        if ($nb) {
            $temp = -1;
            while ($data = $DB->fetch_assoc($result)) {
                if ($data["entity"] != $temp) {
                    while ($i % $nb_per_line != 0) {
                        if ($canedit_entity) {
                            echo "<td width='10'>&nbsp;</td>";
                        }
                        echo "<td class='tab_bg_1'>&nbsp;</td>\n";
                        $i++;
                    }
                    if ($i != 0) {
                        echo "</table>";
                        echo "</div>";
                        echo "</td></tr>\n";
                    }
                    // New entity
                    $i = 0;
                    $temp = $data["entity"];
                    $canedit_entity = $canedit && in_array($temp, $_SESSION['glpiactiveentities']);
                    $rand = mt_rand();
                    echo "<tr class='tab_bg_2'>";
                    echo "<td>";
                    echo "<a href=\"javascript:showHideDiv('entity{$temp}{$rand}','imgcat{$temp}', '" . $CFG_GLPI['root_doc'] . "/pics/folder.png','" . $CFG_GLPI['root_doc'] . "/pics/folder-open.png');\">";
                    echo "<img alt='' name='imgcat{$temp}' src=\"" . $CFG_GLPI['root_doc'] . "/pics/folder.png\">&nbsp;";
                    echo "<span class='b'>" . Dropdown::getDropdownName('glpi_entities', $data["entity"]) . "</span>";
                    echo "</a>";
                    echo "</td></tr>\n";
                    echo "<tr class='tab_bg_2'><td>";
                    echo "<div class='center' id='entity{$temp}{$rand}' style='display:none;'>\n";
                    echo Html::checkAllAsCheckbox("entity{$temp}{$rand}") . __('All');
                    echo "<table class='tab_cadre_fixe'>\n";
                }
                if ($i % $nb_per_line == 0) {
                    if ($i != 0) {
                        echo "</tr>\n";
                    }
                    echo "<tr class='tab_bg_1'>\n";
                    $i = 0;
                }
                if ($canedit_entity) {
                    echo "<td width='10'>";
                    Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
                    echo "</td>";
                }
                $username = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], 1);
                if ($data["is_dynamic"] || $data["is_recursive"]) {
                    $username = sprintf(__('%1$s %2$s'), $username, "<span class='b'>(");
                    if ($data["is_dynamic"]) {
                        $username = sprintf(__('%1$s%2$s'), $username, __('D'));
                    }
                    if ($data["is_dynamic"] && $data["is_recursive"]) {
                        $username = sprintf(__('%1$s%2$s'), $username, ", ");
                    }
                    if ($data["is_recursive"]) {
                        $username = sprintf(__('%1$s%2$s'), $username, __('R'));
                    }
                    $username = sprintf(__('%1$s%2$s'), $username, ")</span>");
                }
                echo "<td class='tab_bg_1'>" . $username . "</td>\n";
                $i++;
            }
            if ($i % $nb_per_line != 0) {
                while ($i % $nb_per_line != 0) {
                    if ($canedit_entity) {
                        echo "<td width='10'>&nbsp;</td>";
                    }
                    echo "<td class='tab_bg_1'>&nbsp;</td>";
                    $i++;
                }
            }
            if ($i != 0) {
                echo "</table>";
                echo "</div>";
                echo "</td></tr>\n";
            }
        } else {
            echo "<tr class='tab_bg_2'><td class='tab_bg_1 center'>" . __('No user found') . "</td></tr>\n";
        }
        echo "</table>";
        if ($canedit && $nb) {
            $massiveactionparams['ontop'] = false;
            Html::showMassiveActions($massiveactionparams);
            Html::closeForm();
        }
        echo "</div>\n";
    }

Usage Example

Example #1
0
                }
        }
    } else {
        switch ($_REQUEST['glpi_tab']) {
            case -1:
                $prof->showFormInventory($_POST['target'], true, false);
                $prof->showFormTracking($_POST['target'], false, false);
                $prof->showFormAdmin($_POST['target'], false, true);
                Profile_User::showForProfile($prof);
                Plugin::displayAction($prof, $_REQUEST['glpi_tab']);
                break;
            case 2:
                $prof->showFormTracking($_POST['target']);
                break;
            case 3:
                $prof->showFormAdmin($_POST['target']);
                break;
            case 4:
                Profile_User::showForProfile($prof);
                break;
            case 12:
                Log::showForItem($prof);
                break;
            default:
                if (!Plugin::displayAction($prof, $_REQUEST['glpi_tab'])) {
                    $prof->showFormInventory($_POST['target']);
                }
        }
    }
}
ajaxFooter();