Profile_User::showForEntity PHP 메소드

showForEntity() 정적인 공개 메소드

Show users of an entity
static public showForEntity ( Entity $entity )
$entity Entity Entity object
    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') . "&nbsp;";
            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>&nbsp;</td>";
                        if ($canedit) {
                            echo "<td>&nbsp;</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>";
    }

Usage Example

예제 #1
0
 /**
  * Display content of Tab
  *
  * @param $ID of the item
  * @param $tab number of the tab
  *
  * @return true if handled (for class stack)
  */
 function showTabContent($ID, $tab)
 {
     global $CFG_GLPI;
     if (!$this->isNewID($ID)) {
         switch ($tab) {
             case -1:
                 // All
                 $this->showChildren($ID);
                 EntityData::showStandardOptions($this);
                 Profile_User::showForEntity($this);
                 $collection = new RuleRightCollection();
                 if ($collection->canList()) {
                     $ldaprule = new RuleRight();
                     $ldaprule->showAndAddRuleForm($this);
                 }
                 $collection = new RuleOcsCollection();
                 if ($collection->canList()) {
                     $ocsrule = new RuleOcs();
                     $ocsrule->showAndAddRuleForm($this);
                 }
                 $collection = new RuleMailCollectorCollection();
                 if ($collection->canList()) {
                     $mailcollector = new RuleMailCollector();
                     $mailcollector->showAndAddRuleForm($this);
                 }
                 Document::showAssociated($this);
                 EntityData::showNotificationOptions($this);
                 EntityData::showHelpdeskOptions($this);
                 EntityData::showInventoryOptions($this);
                 Plugin::displayAction($this, $tab);
                 break;
             case 2:
                 EntityData::showStandardOptions($this);
                 break;
             case 3:
                 Profile_User::showForEntity($this);
                 break;
             case 4:
                 $collection = new RuleRightCollection();
                 if ($collection->canList()) {
                     $ldaprule = new RuleRight();
                     $ldaprule->showAndAddRuleForm($this);
                 }
                 $collection = new RuleOcsCollection();
                 if ($collection->canList()) {
                     $ocsrule = new RuleOcs();
                     $ocsrule->showAndAddRuleForm($this);
                 }
                 $collection = new RuleMailCollectorCollection();
                 if ($collection->canList()) {
                     $mailcollector = new RuleMailCollector();
                     $mailcollector->showAndAddRuleForm($this);
                 }
                 break;
             case 5:
                 EntityData::showAdvancedOptions($this);
                 break;
             case 6:
                 Document::showAssociated($this);
                 break;
             case 7:
                 EntityData::showNotificationOptions($this);
                 break;
             case 8:
                 EntityData::showHelpdeskOptions($this);
                 break;
             case 9:
                 EntityData::showInventoryOptions($this);
                 break;
             case 10:
                 showNotesForm(getItemTypeFormURL('EntityData'), 'EntityData', $_POST["id"]);
                 break;
             default:
                 if (!Plugin::displayAction($this, $tab)) {
                     $this->showChildren($ID);
                 }
                 return false;
         }
     }
     return false;
 }