. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Common DataBase visibility for items */ abstract class CommonDBVisible extends CommonDBTM { /** * Is the login user have access to item based on visibility configuration * * @since 0.83 * @since 9.2 moved from each class to parent class * * @return boolean **/ public function haveVisibilityAccess() { // Author if ($this->fields['users_id'] == Session::getLoginUserID()) { return true; } // Users if (isset($this->users[Session::getLoginUserID()])) { return true; } // Groups if (count($this->groups) && isset($_SESSION["glpigroups"]) && count($_SESSION["glpigroups"])) { foreach ($this->groups as $data) { foreach ($data as $group) { if (in_array($group['groups_id'], $_SESSION["glpigroups"])) { // All the group if ($group['entities_id'] < 0) { return true; } // Restrict to entities if (Session::haveAccessToEntity($group['entities_id'], $group['is_recursive'])) { return true; } } } } } // Entities if (count($this->entities) && isset($_SESSION["glpiactiveentities"]) && count($_SESSION["glpiactiveentities"])) { foreach ($this->entities as $data) { foreach ($data as $entity) { if (Session::haveAccessToEntity($entity['entities_id'], $entity['is_recursive'])) { return true; } } } } // Profiles if (count($this->profiles) && isset($_SESSION["glpiactiveprofile"]) && isset($_SESSION["glpiactiveprofile"]['id'])) { if (isset($this->profiles[$_SESSION["glpiactiveprofile"]['id']])) { foreach ($this->profiles[$_SESSION["glpiactiveprofile"]['id']] as $profile) { // All the profile if ($profile['entities_id'] < 0) { return true; } // Restrict to entities if (Session::haveAccessToEntity($profile['entities_id'], $profile['is_recursive'])) { return true; } } } } return false; } /** * Count visibilities * * @since 0.83 * @since 9.2 moved from each class to parent class * * @return integer */ public function countVisibilities() { return (count($this->entities) + count($this->users) + count($this->groups) + count($this->profiles)); } /** * Show visibility configuration * * @since 9.2 moved from each class to parent class * * @return void **/ public function showVisibility() { global $CFG_GLPI; $ID = $this->fields['id']; $canedit = $this->canEdit($ID); $rand = mt_rand(); $nb = $this->countVisibilities(); $str_type = strtolower($this::getType()); $fk = static::getForeignKeyField(); if ($canedit) { echo "
| "; $header_top .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header_end .= " | "; } $header_end .= ""._n('Type', 'Types', 1)." | "; $header_end .= ""._n('Recipient', 'Recipients', Session::getPluralNumber())." | "; $header_end .= "
|---|---|---|
| "; Html::showMassiveActionCheckBox($this::getType() . '_User', $data["id"]); echo " | "; } echo "".User::getTypeName(1)." | "; echo "".getUserName($data['users_id'])." | "; echo "
| "; Html::showMassiveActionCheckBox('Group_' . $this::getType(), $data["id"]); echo " | "; } echo "".Group::getTypeName(1)." | "; $names = Dropdown::getDropdownName('glpi_groups', $data['groups_id'], 1); $entname = sprintf(__('%1$s %2$s'), $names["name"], Html::showToolTip($names["comment"], ['display' => false])); if ($data['entities_id'] >= 0) { $entname = sprintf(__('%1$s / %2$s'), $entname, Dropdown::getDropdownName('glpi_entities', $data['entities_id'])); if ($data['is_recursive']) { //TRANS: R for Recursive $entname = sprintf(__('%1$s %2$s'), $entname, "(".__('R').")"); } } echo "".$entname." | "; echo "
| "; Html::showMassiveActionCheckBox('Entity_' . $this::getType(), $data["id"]); echo " | "; } echo "".Entity::getTypeName(1)." | "; $names = Dropdown::getDropdownName('glpi_entities', $data['entities_id'], 1); $tooltip = Html::showToolTip($names["comment"], ['display' => false]); $entname = sprintf(__('%1$s %2$s'), $names["name"], $tooltip); if ($data['is_recursive']) { $entname = sprintf(__('%1$s %2$s'), $entname, "(".__('R').")"); } echo "".$entname." | "; echo "
| "; //Knowledgebase-specific case if ($this::getType() === "KnowbaseItem") { Html::showMassiveActionCheckBox($this::getType() . '_Profile', $data["id"]); } else { Html::showMassiveActionCheckBox('Profile_' . $this::getType(), $data["id"]); } echo " | "; } echo ""._n('Profile', 'Profiles', 1)." | "; $names = Dropdown::getDropdownName('glpi_profiles', $data['profiles_id'], 1); $tooltip = Html::showToolTip($names["comment"], ['display' => false]); $entname = sprintf(__('%1$s %2$s'), $names["name"], $tooltip); if ($data['entities_id'] >= 0) { $entname = sprintf(__('%1$s / %2$s'), $entname, Dropdown::getDropdownName('glpi_entities', $data['entities_id'])); if ($data['is_recursive']) { $entname = sprintf(__('%1$s %2$s'), $entname, "(".__('R').")"); } } echo "".$entname." | "; echo "