static function showForEntity(Entity $entity)
{
$ID = $entity->getField('id');
if (!$entity->can($ID, READ)) {
return false;
}
$canedit = $entity->canEdit($ID);
$canshowuser = User::canView();
$nb_per_line = 3;
$rand = mt_rand();
if ($canedit) {
$headerspan = $nb_per_line * 2;
} else {
$headerspan = $nb_per_line;
}
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_1'><td class='tab_bg_2 center'>" . __('User') . " ";
echo "<input type='hidden' name='entities_id' value='{$ID}'>";
User::dropdown(array('right' => 'all'));
echo "</td><td class='tab_bg_2 center'>" . self::getTypeName(1) . "</td><td>";
Profile::dropdownUnder(array('value' => Profile::getDefault()));
echo "</td><td class='tab_bg_2 center'>" . __('Recursive') . "</td><td>";
Dropdown::showYesNo("is_recursive", 0);
echo "</td><td class='tab_bg_2 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`.`id`, `glpi_profiles`.`name`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_profiles`\n ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n AND `glpi_users`.`is_deleted` = '0'";
$result = $DB->query($query);
$nb = $DB->numrows($result);
echo "<div class='spaced'>";
if ($canedit && $nb) {
Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
$massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
Html::showMassiveActions($massiveactionparams);
}
echo "<table class='tab_cadre_fixehov'>";
echo "<thead><tr>";
echo "<th class='noHover' colspan='{$headerspan}'>";
printf(__('%1$s (%2$s)'), _n('User', 'Users', Session::getPluralNumber()), __('D=Dynamic, R=Recursive'));
echo "</th></tr></thead>";
if ($nb) {
Session::initNavigateListItems('User', sprintf(__('%1$s = %2$s'), Entity::getTypeName(1), $entity->getName()));
while ($data = $DB->fetch_assoc($result)) {
echo "<tbody><tr class='noHover'>";
$reduce_header = 0;
if ($canedit && $nb) {
echo "<th width='10'>";
echo Html::checkAllAsCheckbox("profile" . $data['id'] . "_{$rand}");
echo "</th>";
$reduce_header++;
}
echo "<th colspan='" . ($headerspan - $reduce_header) . "'>";
printf(__('%1$s: %2$s'), __('Profile'), $data["name"]);
echo "</th></tr></tbody>";
echo "<tbody id='profile" . $data['id'] . "_{$rand}'>";
$query = "SELECT `glpi_users`.*,\n `glpi_profiles_users`.`id` AS linkID,\n `glpi_profiles_users`.`is_recursive`,\n `glpi_profiles_users`.`is_dynamic`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n AND `glpi_users`.`is_deleted` = '0'\n AND `glpi_profiles_users`.`profiles_id` = '" . $data['id'] . "'\n ORDER BY `glpi_profiles_users`.`profiles_id`,\n `glpi_users`.`name`,\n `glpi_users`.`realname`,\n `glpi_users`.`firstname`";
$result2 = $DB->query($query);
if ($DB->numrows($result2) > 0) {
$i = 0;
while ($data2 = $DB->fetch_assoc($result2)) {
Session::addToNavigateListItems('User', $data2["id"]);
if ($i % $nb_per_line == 0) {
if ($i != 0) {
echo "</tr>";
}
echo "<tr class='tab_bg_1'>";
}
if ($canedit) {
echo "<td width='10'>";
Html::showMassiveActionCheckBox(__CLASS__, $data2["linkID"]);
echo "</td>";
}
$username = formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"], $canshowuser);
if ($data2["is_dynamic"] || $data2["is_recursive"]) {
$username = sprintf(__('%1$s %2$s'), $username, "<span class='b'>(");
if ($data2["is_dynamic"]) {
$username = sprintf(__('%1$s%2$s'), $username, __('D'));
}
if ($data2["is_dynamic"] && $data2["is_recursive"]) {
$username = sprintf(__('%1$s%2$s'), $username, ", ");
}
if ($data2["is_recursive"]) {
$username = sprintf(__('%1$s%2$s'), $username, __('R'));
}
$username = sprintf(__('%1$s%2$s'), $username, ")</span>");
}
echo "<td>" . $username . "</td>";
$i++;
}
while ($i % $nb_per_line != 0) {
echo "<td> </td>";
if ($canedit) {
echo "<td> </td>";
}
$i++;
}
echo "</tr>";
echo "</tbody>";
} else {
echo "<tr colspan='{$headerspan}'>" . __('Item not found') . "</tr>";
}
}
}
echo "</table>";
if ($canedit && $nb) {
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
Html::closeForm();
}
echo "</div>";
}