grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * ReservationItem Class **/ class ReservationItem extends CommonDBChild { /// From CommonDBChild static public $itemtype = 'itemtype'; static public $items_id = 'items_id'; static public $checkParentRights = self::HAVE_VIEW_RIGHT_ON_ITEM; static $rightname = 'reservation'; const RESERVEANITEM = 1024; public $get_item_to_display_tab = false; public $showdebug = false; /** * @since version 0.85 **/ static function canView() { global $CFG_GLPI; return Session::haveRightsOr(self::$rightname, array(READ, self::RESERVEANITEM)); } static function getTypeName($nb=0) { return _n('Reservable item', 'Reservable items',$nb); } /** * @see CommonGLPI::getMenuName() * * @since version 0.85 **/ static function getMenuName() { return Reservation::getTypeName(Session::getPluralNumber()); } /** * @see CommonGLPI::getForbiddenActionsForMenu() * * @since version 0.85 **/ static function getForbiddenActionsForMenu() { return array('add'); } /** * @see CommonGLPI::getAdditionalMenuLinks() * * @since version 0.85 **/ static function getAdditionalMenuLinks() { if (static::canView()) { return array('showall' => Reservation::getSearchURL(false)); } return false; } /** * @since 0.84 **/ // static function canView() { // return true; // } // From CommonDBTM /** * Retrieve an item from the database for a specific item * * @param $itemtype type of the item * @param $ID ID of the item * * @return true if succeed else false **/ function getFromDBbyItem($itemtype, $ID) { return $this->getFromDBByQuery("WHERE `".$this->getTable()."`.`itemtype` = '$itemtype' AND `".$this->getTable()."`.`items_id` = '$ID'"); } function cleanDBonPurge() { $class = new Reservation(); $class->cleanDBonItemDelete($this->getType(), $this->fields['id']); $class = new Alert(); $class->cleanDBonItemDelete($this->getType(), $this->fields['id']); } function getSearchOptions() { $tab = array(); $tab[4]['table'] = $this->getTable(); $tab[4]['field'] = 'comment'; $tab[4]['name'] = __('Comments'); $tab[4]['datatype'] = 'text'; $tab[5]['table'] = $this->getTable(); $tab[5]['field'] = 'is_active'; $tab[5]['name'] = __('Active'); $tab[5]['datatype'] = 'bool'; $tab['common'] = __('Characteristics'); $tab[1]['table'] = 'reservation_types'; $tab[1]['field'] = 'name'; $tab[1]['name'] = __('Name'); $tab[1]['datatype'] = 'itemlink'; $tab[1]['massiveaction'] = false; $tab[1]['addobjectparams'] = array('forcetab' => 'Reservation$1'); $tab[2]['table'] = 'reservation_types'; $tab[2]['field'] = 'id'; $tab[2]['name'] = __('ID'); $tab[2]['massiveaction'] = false; $tab[2]['datatype'] = 'number'; $tab[9]['table'] = 'glpi_reservationitems'; $tab[9]['field'] = '_virtual'; $tab[9]['name'] = __('Planning'); $tab[9]['datatype'] = 'specific'; $tab[9]['massiveaction'] = false; $tab[9]['nosearch'] = true; $tab[9]['nosort'] = true; $tab[9]['additionalfields'] = array('is_active'); $loc = Location::getSearchOptionsToAdd(); // Force massive actions to false foreach ($loc as $key => $val) { $tab[$key] = $val; $tab[$key]['massiveaction'] = false; } $tab[6]['table'] = 'reservation_types'; $tab[6]['field'] = 'otherserial'; $tab[6]['name'] = __('Inventory number'); $tab[6]['datatype'] = 'string'; $tab[16]['table'] = 'reservation_types'; $tab[16]['field'] = 'comment'; $tab[16]['name'] = __('Comments'); $tab[16]['datatype'] = 'text'; $tab[16]['massiveaction'] = false; $tab[70]['table'] = 'glpi_users'; $tab[70]['field'] = 'name'; $tab[70]['name'] = __('User'); $tab[70]['datatype'] = 'dropdown'; $tab[70]['right'] = 'all'; $tab[70]['massiveaction'] = false; $tab[71]['table'] = 'glpi_groups'; $tab[71]['field'] = 'completename'; $tab[71]['name'] = __('Group'); $tab[71]['datatype'] = 'dropdown'; $tab[71]['massiveaction'] = false; $tab[19]['table'] = 'reservation_types'; $tab[19]['field'] = 'date_mod'; $tab[19]['name'] = __('Last update'); $tab[19]['datatype'] = 'datetime'; $tab[19]['massiveaction'] = false; $tab[23]['table'] = 'glpi_manufacturers'; $tab[23]['field'] = 'name'; $tab[23]['name'] = __('Manufacturer'); $tab[23]['datatype'] = 'dropdown'; $tab[23]['massiveaction'] = false; $tab[24]['table'] = 'glpi_users'; $tab[24]['field'] = 'name'; $tab[24]['linkfield'] = 'users_id_tech'; $tab[24]['name'] = __('Technician in charge of the hardware'); $tab[24]['datatype'] = 'dropdown'; $tab[24]['right'] = 'interface'; $tab[24]['massiveaction'] = false; $tab[80]['table'] = 'glpi_entities'; $tab[80]['field'] = 'completename'; $tab[80]['name'] = __('Entity'); $tab[80]['massiveaction'] = false; $tab[80]['datatype'] = 'dropdown'; $tab[80]['massiveaction'] = false; return $tab; } /** * @param $item CommonDBTM object **/ static function showActivationFormForItem(CommonDBTM $item) { if (!self::canUpdate()) { return false; } if ($item->getID()) { // Recursive type case => need entity right if ($item->isRecursive()) { if (!Session::haveAccessToEntity($item->fields["entities_id"])) { return false; } } } else { return false; } $ri = new self(); echo "
| ".__('Reserve an item')." | ||
|---|---|---|
| "; //Switch reservation state if ($ri->fields["is_active"]) { Html::showSimpleForm(static::getFormURL(), 'update', __('Make unavailable'), array('id' => $ri->fields['id'], 'is_active' => 0)); } else { Html::showSimpleForm(static::getFormURL(), 'update', __('Make available'), array('id' => $ri->fields['id'], 'is_active' => 1)); } echo ' | '; Html::showSimpleForm(static::getFormURL(), 'purge', __('Prohibit reservations'), array('id' => $ri->fields['id']),'','', array(__('Are you sure you want to return this non-reservable item?'), __('That will remove all the reservations in progress.'))); echo " | "; } else { echo ""; Html::showSimpleForm(static::getFormURL(), 'add', __('Authorize reservations'), array('items_id' => $item->getID(), 'itemtype' => $item->getType(), 'entities_id' => $item->getEntityID(), 'is_recursive' => $item->isRecursive(),)); echo " | "; } echo "