grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * State Class **/ class State extends CommonTreeDropdown { protected $visibility_fields = array('Computer' => 'is_visible_computer', 'SoftwareVersion' => 'is_visible_softwareversion', 'Monitor' => 'is_visible_monitor', 'Printer' => 'is_visible_printer', 'Peripheral' => 'is_visible_peripheral', 'Phone' => 'is_visible_phone', 'NetworkEquipment' => 'is_visible_networkequipment', 'SoftwareLicense' => 'is_visible_softwarelicense'); public $can_be_translated = true; static $rightname = 'state'; static function getTypeName($nb=0) { return _n('Status of items', 'Statuses of items', $nb); } /** * @since version 0.85 * * @see CommonTreeDropdown::getAdditionalFields() **/ function getAdditionalFields() { $fields = parent::getAdditionalFields(); $fields[] = array('label' => __('Visibility'), 'name' => 'header', 'list' => false); foreach ($this->visibility_fields as $type => $field) { $fields[] = array('name' => $field, 'label' => $type::getTypeName(Session::getPluralNumber()), 'type' => 'bool', 'list' => true); } return $fields; } /** * Dropdown of states for behaviour config * * @param $name select name * @param $lib string to add for -1 value (default '') * @param $value default value (default 0) **/ static function dropdownBehaviour($name, $lib="", $value=0) { global $DB; $elements = array("0" => __('Keep status')); if ($lib) { $elements["-1"] = $lib; } $queryStateList = "SELECT `id`, `name` FROM `glpi_states` ORDER BY `name`"; $result = $DB->query($queryStateList); if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_assoc($result)) { $elements[$data["id"]] = sprintf(__('Set status: %s'), $data["name"]); } } Dropdown::showFromArray($name, $elements, array('value' => $value)); } static function showSummary() { global $DB, $CFG_GLPI; $state_type = $CFG_GLPI["state_types"]; $states = array(); foreach ($state_type as $key=>$itemtype) { if ($item = getItemForItemtype($itemtype)) { if (!$item->canView()) { unset($state_type[$key]); } else { $table = getTableForItemType($itemtype); $query = "SELECT `states_id`, COUNT(*) AS cpt FROM `$table` ". getEntitiesRestrictRequest("WHERE",$table)." AND `is_deleted` = '0' AND `is_template` = '0' GROUP BY `states_id`"; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_assoc($result)) { $states[$data["states_id"]][$itemtype] = $data["cpt"]; } } } } } } if (count($states)) { // Produce headline echo "
| ".__('Status')." | "; foreach ($state_type as $key => $itemtype) { if ($item = getItemForItemtype($itemtype)) { echo "".$item->getTypeName(Session::getPluralNumber())." | "; $total[$itemtype] = 0; } else { unset($state_type[$key]); } } echo "".__('Total')." | "; echo "
|---|---|---|
| --- | "; foreach ($state_type as $itemtype) { echo ""; if (isset($states[0][$itemtype])) { echo $states[0][$itemtype]; $total[$itemtype] += $states[0][$itemtype]; $tot += $states[0][$itemtype]; } else { echo " "; } echo " | "; } echo "$tot |
| "; $opt = array('reset' => 'reset', 'sort' => 1, 'start' => 0, 'criteria' => array('0' => array('value' => '$$$$'.$data['id'], 'searchtype' => 'contains', 'field' => 31))); echo "".$data["completename"]." | "; foreach ($state_type as $itemtype) { echo ""; if (isset($states[$data["id"]][$itemtype])) { echo $states[$data["id"]][$itemtype]; $total[$itemtype] += $states[$data["id"]][$itemtype]; $tot += $states[$data["id"]][$itemtype]; } else { echo " "; } echo " | "; } echo "$tot | "; echo "
| ".__('Total')." | "; $tot = 0; foreach ($state_type as $itemtype) { echo "".$total[$itemtype]." | "; $tot += $total[$itemtype]; } echo "$tot |