. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Reservation Class **/ class Reservation extends CommonDBChild { // From CommonDBChild static public $itemtype = 'ReservationItem'; static public $items_id = 'reservationitems_id'; static $rightname = 'reservation'; static public $checkParentRights = self::HAVE_VIEW_RIGHT_ON_ITEM; /** * @param $nb integer for singular or plural **/ static function getTypeName($nb = 0) { return _n('Reservation', 'Reservations', $nb); } /** * @see CommonGLPI::getTabNameForItem() **/ function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate && Session::haveRight("reservation", READ)) { return self::getTypeName(Session::getPluralNumber()); } return ''; } /** * @param $item CommonGLPI object * @param $tabnum (default1) * @param $withtemplate (default0) **/ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($item->getType() == 'User') { self::showForUser($_GET["id"]); } else { self::showForItem($item); } return true; } function pre_deleteItem() { global $CFG_GLPI; if (isset($this->fields["users_id"]) && (($this->fields["users_id"] === Session::getLoginUserID()) || Session::haveRight("reservation", DELETE))) { // Processing Email if (!isset($this->input['_disablenotif']) && $CFG_GLPI["use_notifications"]) { // Only notify for non-completed reservations if (strtotime($this->fields['end']) > time()) { NotificationEvent::raiseEvent("delete", $this); } } } return true; } /** * @see CommonDBChild::prepareInputForUpdate() **/ function prepareInputForUpdate($input) { $item = 0; if (isset($input['_item'])) { $item = $_POST['_item']; } // Save fields $oldfields = $this->fields; // Needed for test already planned if (isset($input["begin"])) { $this->fields["begin"] = $input["begin"]; } if (isset ($input["end"])) { $this->fields["end"] = $input["end"]; } if (!$this->test_valid_date()) { $this->displayError("date", $item); return false; } if ($this->is_reserved()) { $this->displayError("is_res", $item); return false; } // Restore fields $this->fields = $oldfields; return parent::prepareInputForUpdate($input); } /** * @see CommonDBTM::post_updateItem() **/ function post_updateItem($history = 1) { global $CFG_GLPI; if (count($this->updates) && $CFG_GLPI["use_notifications"] && !isset($this->input['_disablenotif'])) { NotificationEvent::raiseEvent("update", $this); //$mail = new MailingResa($this,"update"); //$mail->send(); } parent::post_updateItem($history); } /** * @see CommonDBChild::prepareInputForAdd() **/ function prepareInputForAdd($input) { // Error on previous added reservation on several add if (isset($input['_ok']) && !$input['_ok']) { return false; } // set new date. $this->fields["reservationitems_id"] = $input["reservationitems_id"]; $this->fields["begin"] = $input["begin"]; $this->fields["end"] = $input["end"]; if (!$this->test_valid_date()) { $this->displayError("date", $input["reservationitems_id"]); return false; } if ($this->is_reserved()) { $this->displayError("is_res", $input["reservationitems_id"]); return false; } return parent::prepareInputForAdd($input); } function post_addItem() { global $CFG_GLPI; if (!isset($this->input['_disablenotif']) && $CFG_GLPI["use_notifications"]) { NotificationEvent::raiseEvent("new", $this); } parent::post_addItem(); } // SPECIFIC FUNCTIONS /** * @param $reservationitems_id **/ function getUniqueGroupFor($reservationitems_id) { global $DB; do { $rand = mt_rand(1, mt_getrandmax()); $result = $DB->request([ 'COUNT' => 'cpt', 'FROM' => 'glpi_reservations', 'WHERE' => [ 'reservationitems_id' => $reservationitems_id, 'group' => $rand ] ])->next(); $count = (int)$result['cpt']; } while ($count > 0); return $rand; } /** * Is the item already reserved ? * *@return boolean **/ function is_reserved() { global $DB; if (!isset($this->fields["reservationitems_id"]) || empty($this->fields["reservationitems_id"])) { return true; } // When modify a reservation do not itself take into account $where = []; if (isset($this->fields["id"])) { $where['id'] = ['<>', $this->fields['id']]; } $result = $DB->request([ 'COUNT' => 'cpt', 'FROM' => $this->getTable(), 'WHERE' => $where + [ 'reservationitems_id' => $this->fields['reservationitems_id'], 'end' => ['>', $this->fields['begin']], 'begin' => ['<', $this->fields['end']] ] ])->next(); return $result['cpt'] > 0; } /** * Current dates are valid ? begin before end * *@return boolean **/ function test_valid_date() { return (!empty($this->fields["begin"]) && !empty($this->fields["end"]) && (strtotime($this->fields["begin"]) < strtotime($this->fields["end"]))); } /** * display error message * * @param $type error type : date / is_res / other * @param $ID ID of the item * * @return void **/ function displayError($type, $ID) { echo "
"; switch ($type) { case "date" : echo __('Error in entering dates. The starting date is later than the ending date'); break; case "is_res" : echo __('The required item is already reserved for this timeframe'); break; default : echo __("Unknown error"); } echo "
".__('Back to planning').""; echo "
"; } /** * @since 0.84 **/ static function canCreate() { return (Session::haveRight(self::$rightname, ReservationItem::RESERVEANITEM)); } /** * @since 0.84 **/ static function canUpdate() { return (Session::haveRight(self::$rightname, ReservationItem::RESERVEANITEM)); } /** * @since 0.84 **/ static function canDelete() { return (Session::haveRight(self::$rightname, ReservationItem::RESERVEANITEM)); } /** * Overload canChildItem to make specific checks * @since 0.84 **/ function canChildItem($methodItem, $methodNotItem) { // Original user always have right if ($this->fields['users_id'] === Session::getLoginUserID()) { return true; } if (!parent::canChildItem($methodItem, $methodNotItem)) { return false; } $ri = $this->getItem(); if ($ri === false) { return false; } $item = $ri->getItem(); if ($item === false) { return false; } return Session::haveAccessToEntity($item->getEntityID()); } function post_purgeItem() { global $DB; if (isset($this->input['_delete_group']) && $this->input['_delete_group']) { $iterator = $DB->request([ 'FROM' => 'glpi_reservations', 'WHERE' => [ 'reservationitems_id' => $this->fields['reservationitems_id'], 'group' => $this->fields['group'] ] ]); $rr = clone $this; while ($data = $iterator->next()) { $rr->delete(['id' => $data['id']]); } } } /** * Show reservation calendar * * @param $ID ID of the reservation item (if empty display all) (default '') **/ static function showCalendar($ID = "") { global $CFG_GLPI; if (!Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) { return false; } if (!isset($_GET["mois_courant"])) { $mois_courant = intval(strftime("%m")); } else { $mois_courant = $_GET["mois_courant"]; } if (!isset($_GET["annee_courante"])) { $annee_courante = strftime("%Y"); } else { $annee_courante = $_GET["annee_courante"]; } $mois_courant = intval($mois_courant); $mois_suivant = $mois_courant+1; $mois_precedent = $mois_courant-1; $annee_suivante = $annee_courante; $annee_precedente = $annee_courante; if ($mois_precedent == 0) { $mois_precedent = 12; $annee_precedente --; } if ($mois_suivant == 13) { $mois_suivant = 1; $annee_suivante ++; } $monthsarray = Toolbox::getMonthsOfYearArray(); $str_suivant = "?reservationitems_id=$ID&mois_courant=$mois_suivant&". "annee_courante=$annee_suivante"; $str_precedent = "?reservationitems_id=$ID&mois_courant=$mois_precedent&". "annee_courante=$annee_precedente"; if (!empty($ID)) { $m = new ReservationItem(); $m->getFromDB($ID); if ((!isset($m->fields['is_active'])) || !$m->fields['is_active']) { echo "
"; echo ""; echo ""; echo ""; echo ""; echo "
".__('Device temporarily unavailable')."
"; Html::displayBackLink(); echo "
"; echo "
"; return false; } $type = $m->fields["itemtype"]; $name = NOT_AVAILABLE; if ($item = getItemForItemtype($m->fields["itemtype"])) { $type = $item->getTypeName(); if ($item->getFromDB($m->fields["items_id"])) { $name = $item->getName(); } $name = sprintf(__('%1$s - %2$s'), $type, $name); } $all = "".__('Show all').""; } else { $type = ""; $name = __('All reservable devices'); $all = " "; } echo "
"; echo ""; echo "
"; echo "".$name."
$all

\n"; // Check bisextile years if (($annee_courante%4) == 0) { $fev = 29; } else { $fev = 28; } $nb_jour = [31, $fev, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; // Datas used to put right information in columns $jour_debut_mois = strftime("%w", mktime(0, 0, 0, $mois_courant, 1, $annee_courante)); if ($jour_debut_mois == 0) { $jour_debut_mois = 7; } $jour_fin_mois = strftime("%w", mktime(0, 0, 0, $mois_courant, $nb_jour[$mois_courant-1], $annee_courante)); echo "
"; echo ""; echo ""; echo "
"; echo "\"".__s('Previous').".sprintf(__('%1$s %2$s'), $monthsarray[$mois_courant], $annee_courante). ""; echo "\"".__s('Next').
\n"; // test echo "
"; echo "
"; // today date $today = getdate(time()); $mois = $today["mon"]; $annee = $today["year"]; $annee_avant = $annee_courante - 1; $annee_apres = $annee_courante + 1; echo "
"; echo "
$annee_avant
"; for ($i=$mois_courant; $i<13; $i++) { echo ""; } echo "
$annee_courante
"; for ($i=1; $i<13; $i++) { if ($i == $mois_courant) { echo "
".$monthsarray[$i]."
\n"; } else { echo "\n"; } } echo "
$annee_apres
\n"; for ($i=1; $i<$mois_courant+1; $i++) { echo "\n"; } echo "
"; echo "
"; echo "
"; // test echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; echo ""; // Insert blank cell before the first day of the month for ($i=1; $i<$jour_debut_mois; $i++) { echo ""; } // voici le remplissage proprement dit if (($mois_courant < 10) && (strlen($mois_courant) == 1)) { $mois_courant = "0".$mois_courant; } for ($i=1; $i<$nb_jour[$mois_courant-1]+1; $i++) { if ($i < 10) { $ii = "0".$i; } else { $ii = $i; } echo ""; // il ne faut pas oublie d'aller a la ligne suivante en fin de semaine if ((($i+$jour_debut_mois)%7) == 1) { echo "\n"; if ($i != $nb_jour[$mois_courant-1]) { echo ""; } } } // on recommence pour finir le tableau proprement pour les m???es raisons if ($jour_fin_mois != 0) { for ($i=0; $i<7-$jour_fin_mois; $i++) { echo ""; } } echo "
".__('Monday')."".__('Tuesday')."".__('Wednesday')."".__('Thursday')."".__('Friday')."".__('Saturday')."".__('Sunday')."
 "; echo "\n"; if (!empty($ID)) { echo "\n"; } echo "
"; echo "".$i."
"; echo ""; echo "\"".
"; self::displayReservationDay($ID, $annee_courante."-".$mois_courant."-".$ii); echo "
\n"; echo "
 
\n"; echo "
\n"; } /** * Display for reservation * * @param $ID ID of the reservation (empty for create new) * @param $options array of possibles options: * - item reservation items ID for creation process * - date date for creation process **/ function showForm($ID, $options = []) { global $CFG_GLPI; if (!Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) { return false; } $resa = new self(); if (!empty($ID)) { if (!$resa->getFromDB($ID)) { return false; } if (!$resa->can($ID, UPDATE)) { return false; } // Set item if not set if ((!isset($options['item']) || (count($options['item']) == 0)) && ($itemid = $resa->getField('reservationitems_id'))) { $options['item'][$itemid] = $itemid; } } else { $resa->getEmpty(); $resa->fields["begin"] = $options['begin']; if (!isset($options['end'])) { $resa->fields["end"] = date("Y-m-d H:00:00", strtotime($resa->fields["begin"])+HOUR_TIMESTAMP); } else { $resa->fields["end"] = $options['end']; } } // No item : problem if (!isset($options['item']) || (count($options['item']) == 0)) { return false; } echo "
"; if (!empty($ID)) { echo ""; } echo ""; echo "\n"; // Add Hardware name $r = new ReservationItem(); echo ""; echo "\n"; $uid = (empty($ID) ? Session::getLoginUserID() : $resa->fields['users_id']); echo ""; echo "\n"; echo "\n"; $default_delay = floor((strtotime($resa->fields["end"])-strtotime($resa->fields["begin"])) /$CFG_GLPI['time_step']/MINUTE_TIMESTAMP) *$CFG_GLPI['time_step']*MINUTE_TIMESTAMP; echo "\n"; if (empty($ID)) { echo ""; echo "\n"; } echo ""; echo "\n"; if (empty($ID)) { echo ""; echo "\n"; } else { if (($resa->fields["users_id"] == Session::getLoginUserID()) || Session::haveRightsOr(static::$rightname, [PURGE, UPDATE])) { echo ""; if (($resa->fields["users_id"] == Session::getLoginUserID()) || Session::haveRight(static::$rightname, PURGE)) { echo ""; } if (($resa->fields["users_id"] == Session::getLoginUserID()) || Session::haveRight(static::$rightname, UPDATE)) { echo ""; } echo "\n"; } } echo "
".__('Reserve an item')."
"._n('Item', 'Items', 1).""; foreach ($options['item'] as $itemID) { $r->getFromDB($itemID); $type = $r->fields["itemtype"]; $name = NOT_AVAILABLE; $item = null; if ($item = getItemForItemtype($r->fields["itemtype"])) { $type = $item->getTypeName(); if ($item->getFromDB($r->fields["items_id"])) { $name = $item->getName(); } else { $item = null; } } echo "".sprintf(__('%1$s - %2$s'), $type, $name)."
"; echo ""; } echo "
".__('By').""; if (!Session::haveRight("reservation", UPDATE) || is_null($item) || !Session::haveAccessToEntity($item->fields["entities_id"])) { echo ""; echo Dropdown::getDropdownName( User::getTable(), $uid ); } else { User::dropdown([ 'value' => $uid, 'entity' => $item->getEntityID(), 'entity_sons' => $item->isRecursive(), 'right' => 'all' ]); } echo "
".__('Start date').""; $rand_begin = Html::showDateTimeField("resa[begin]", ['value' => $resa->fields["begin"], 'maybeempty' => false]); echo "
".__('Duration').""; $rand = Dropdown::showTimeStamp("resa[_duration]", ['min' => 0, 'max' => 24*HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date')]); echo "
"; $params = ['duration' => '__VALUE__', 'end' => $resa->fields["end"], 'name' => "resa[end]"]; Ajax::updateItemOnSelectEvent("dropdown_resa[_duration]$rand", "date_end$rand", $CFG_GLPI["root_doc"]."/ajax/planningend.php", $params); if ($default_delay == 0) { $params['duration'] = 0; Ajax::updateItem("date_end$rand", $CFG_GLPI["root_doc"]."/ajax/planningend.php", $params); } Alert::displayLastAlert('Reservation', $ID); echo "
".__('Repetition').""; $values = ['' => _x('periodicity', 'None'), 'day' => _x('periodicity', 'Daily'), 'week' => _x('periodicity', 'Weekly'), 'month' => _x('periodicity', 'Monthly')]; $rand = Dropdown::showFromArray('periodicity[type]', $values); $field_id = Html::cleanId("dropdown_periodicity[type]$rand"); $params = ['type' => '__VALUE__', 'end' => $resa->fields["end"]]; Ajax::updateItemOnSelectEvent($field_id, "resaperiodcontent$rand", $CFG_GLPI["root_doc"]."/ajax/resaperiod.php", $params); echo "
"; echo "
".__('Comments').""; echo "
"; echo ""; echo "
"; echo ""; if ($resa->fields["group"] > 0) { echo "
 ". __s('Delete all repetition'); } echo "
"; echo ""; echo "
"; Html::closeForm(); echo "
\n"; } /** * compute periodicities for reservation * * @since 0.84 * * @param $begin begin of the initial reservation * @param $end begin of the initial reservation * @param $options array periodicity parameters : must contain : type (day/week/month), end **/ static function computePeriodicities ($begin, $end, $options = []) { $toadd = []; if (isset($options['type']) && isset($options['end'])) { $begin_time = strtotime($begin); $end_time = strtotime($end); $repeat_end = strtotime($options['end'].' 23:59:59'); switch ($options['type']) { case 'day' : $begin_time = strtotime("+1 day", $begin_time); $end_time = strtotime("+1 day", $end_time); while ($begin_time < $repeat_end) { $toadd[date('Y-m-d H:i:s', $begin_time)] = date('Y-m-d H:i:s', $end_time); $begin_time = strtotime("+1 day", $begin_time); $end_time = strtotime("+1 day", $end_time); } break; case 'week' : $dates = []; // No days set add 1 week if (!isset($options['days'])) { $dates = [['begin' => strtotime('+1 week', $begin_time), 'end' => strtotime('+1 week', $end_time)]]; } else { if (is_array($options['days'])) { $begin_hour = $begin_time- strtotime(date('Y-m-d', $begin_time)); $end_hour = $end_time - strtotime(date('Y-m-d', $end_time)); foreach ($options['days'] as $day => $val) { $dates[] = ['begin' => strtotime("next $day", $begin_time)+$begin_hour, 'end' => strtotime("next $day", $end_time)+$end_hour]; } } } foreach ($dates as $key => $val) { $begin_time = $val['begin']; $end_time = $val['end']; while ($begin_time < $repeat_end) { $toadd[date('Y-m-d H:i:s', $begin_time)] = date('Y-m-d H:i:s', $end_time); $begin_time = strtotime('+1 week', $begin_time); $end_time = strtotime('+1 week', $end_time); } } break; case 'month' : if (isset($options['subtype'])) { switch ($options['subtype']) { case 'date': $i=1; $calc_begin_time = strtotime("+$i month", $begin_time); $calc_end_time = strtotime("+$i month", $end_time); while ($calc_begin_time < $repeat_end) { $toadd[date('Y-m-d H:i:s', $calc_begin_time)] = date('Y-m-d H:i:s', $calc_end_time); $i++; $calc_begin_time = strtotime("+$i month", $begin_time); $calc_end_time = strtotime("+$i month", $end_time); } break; case 'day': $dayofweek = date('l', $begin_time); $i = 1; $calc_begin_time = strtotime("+$i month", $begin_time); $calc_end_time = strtotime("+$i month", $end_time); $begin_hour = $begin_time- strtotime(date('Y-m-d', $begin_time)); $end_hour = $end_time - strtotime(date('Y-m-d', $end_time)); $calc_begin_time = strtotime("next $dayofweek", $calc_begin_time) + $begin_hour; $calc_end_time = strtotime("next $dayofweek", $calc_end_time) + $end_hour; while ($calc_begin_time < $repeat_end) { $toadd[date('Y-m-d H:i:s', $calc_begin_time)] = date('Y-m-d H:i:s', $calc_end_time); $i++; $calc_begin_time = strtotime("+$i month", $begin_time); $calc_end_time = strtotime("+$i month", $end_time); $calc_begin_time = strtotime("next $dayofweek", $calc_begin_time) + $begin_hour; $calc_end_time = strtotime("next $dayofweek", $calc_end_time) + $end_hour; } break; } } break; } } return $toadd; } /** * Display for reservation * * @param $ID ID a the reservation item (empty to show all) * @param $date date to display **/ static function displayReservationDay($ID, $date) { global $DB; if (!empty($ID)) { self::displayReservationsForAnItem($ID, $date); } else { $debut = $date." 00:00:00"; $fin = $date." 23:59:59"; $iterator = $DB->request([ 'SELECT' => 'glpi_reservationitems.id', 'DISTINCT' => true, 'FROM' => 'glpi_reservationitems', 'INNER JOIN' => [ 'glpi_reservations' => [ 'ON' => [ 'glpi_reservationitems' => 'id', 'glpi_reservations' => 'reservationitems_id' ] ] ], 'WHERE' => [ 'is_active' => 1, 'end' => ['>', $debut], 'begin' => ['<', $fin] ], 'ORDERBY' => 'begin' ]); if (count($iterator)) { $m = new ReservationItem(); while ($data = $iterator->next()) { $m->getFromDB($data['id']); if (!($item = getItemForItemtype($m->fields["itemtype"]))) { continue; } if ($item->getFromDB($m->fields["items_id"]) && Session::haveAccessToEntity($item->fields["entities_id"])) { $typename = $item->getTypeName(); if ($m->fields["itemtype"] == 'Peripheral') { if (isset($item->fields["peripheraltypes_id"]) && ($item->fields["peripheraltypes_id"] != 0)) { $typename = Dropdown::getDropdownName("glpi_peripheraltypes", $item->fields["peripheraltypes_id"]); } } list($annee,$mois,$jour) = explode("-", $date); echo ""; echo "". sprintf(__('%1$s - %2$s'), $typename, $item->getName())."\n"; echo ""; self::displayReservationsForAnItem($data['id'], $date); echo "\n"; } } } } } /** * Display a reservation * * @param $ID ID a the reservation item * @param $date date to display **/ static function displayReservationsForAnItem($ID, $date) { global $DB; $users_id = Session::getLoginUserID(); $resa = new self(); $user = new User; list($year, $month, $day) = explode("-", $date); $debut = $date." 00:00:00"; $fin = $date." 23:59:59"; $iterator = $DB->request([ 'FROM' => 'glpi_reservations', 'WHERE' => [ 'end' => ['>', $debut], 'begin' => ['<', $fin], 'reservationitems_id' => $ID ], 'ORDER' => 'begin' ]); if (count($iterator)) { echo ""; while ($row = $iterator->next()) { echo ""; $user->getFromDB($row["users_id"]); $display = ""; if ($debut > $row['begin']) { $heure_debut = "00:00"; } else { $heure_debut = get_hour_from_sql($row['begin']); } if ($fin < $row['end']) { $heure_fin = "24:00"; } else { $heure_fin = get_hour_from_sql($row['end']); } if ((strcmp($heure_debut, "00:00") == 0) && (strcmp($heure_fin, "24:00") == 0)) { $display = _n('Day', 'Days', 1); } else if (strcmp($heure_debut, "00:00") == 0) { $display = sprintf(__('To %s'), $heure_fin); } else if (strcmp($heure_fin, "24:00") == 0) { $display = sprintf(__('From %s'), $heure_debut); } else { $display = $heure_debut."-".$heure_fin; } $rand = mt_rand(); $modif = $modif_end = ""; if ($resa->canEdit($row['id'])) { $modif = ""; $modif_end = ""; $modif_end .= Html::showToolTip($row["comment"], ['applyto' => "content_".$ID.$rand, 'display' => false]); } echo "\n"; } echo "
". $modif."".$display."
". formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]); echo "
"; echo $modif_end; echo "
\n"; } } /** * Display reservations for an item * * @param $item CommonDBTM object for which the reservation tab need to be displayed * @param $withtemplate withtemplate param (default 0) **/ static function showForItem(CommonDBTM $item, $withtemplate = 0) { global $DB, $CFG_GLPI; $resaID = 0; if (!Session::haveRight("reservation", READ)) { return false; } echo "
"; ReservationItem::showActivationFormForItem($item); $ri = new ReservationItem(); if ($ri->getFromDBbyItem($item->getType(), $item->getID())) { $now = $_SESSION["glpi_currenttime"]; // Print reservation in progress $iterator = $DB->request([ 'FROM' => 'glpi_reservations', 'WHERE' => [ 'end' => ['>', $now], 'reservationitems_id' => $ri->fields['id'] ], 'ORDER' => 'begin' ]); echo "\n"; if (!count($iterator)) { echo ""; echo "\n"; } else { echo ""; echo ""; echo ""; echo "\n"; while ($data = $iterator->next()) { echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; } } echo "
"; if (count($iterator) && $ri->fields["is_active"] && Session::haveRight('reservation', ReservationItem::RESERVEANITEM)) { echo "".__('Current and future reservations').""; } else { echo __('Current and future reservations'); } echo "
".__('No reservation')."
".__('Start date')."".__('End date')."".__('By')."".__('Comments')." 
".Html::convDateTime($data["begin"])."".Html::convDateTime($data["end"]).""; if (Session::haveRight('user', READ)) { echo "".getUserName($data["users_id"]).""; } else { echo getUserName($data["users_id"]); } echo "".nl2br($data["comment"]).""; if (Session::haveRight('reservation', ReservationItem::RESERVEANITEM)) { list($annee, $mois, $jour) = explode("-", $data["begin"]); echo ""; echo ""; echo "".__('See planning').""; } else { echo " "; } echo "
\n"; // Print old reservations $iterator = $DB->request([ 'FROM' => 'glpi_reservations', 'WHERE' => [ 'end' => ['<=', $now], 'reservationitems_id' => $ri->fields['id'] ], 'ORDER' => 'begin DESC' ]); echo "
\n"; if (!count($iterator)) { echo ""; echo "\n"; } else { echo ""; echo ""; echo ""; echo "\n"; while ($data = $iterator->next()) { echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; } } echo "
"; if (count($iterator) && $ri->fields["is_active"] && Session::haveRight('reservation', ReservationItem::RESERVEANITEM)) { echo "".__('Past reservations').""; } else { echo __('Past reservations'); } echo "
".__('No reservation')."
".__('Start date')."".__('End date')."".__('By')."".__('Comments')." 
".Html::convDateTime($data["begin"])."".Html::convDateTime($data["end"]).""; if (Session::haveRight('user', READ)) { echo "".getUserName($data["users_id"]).""; } else { echo getUserName($data["users_id"]); } echo "".nl2br($data["comment"]).""; if (Session::haveRight('reservation', ReservationItem::RESERVEANITEM)) { list($annee, $mois ,$jour) = explode("-", $data["begin"]); echo ""; echo ""; echo "".__('See planning').""; echo ""; } else { echo " "; } echo "
\n"; } echo "
\n"; } /** * Display reservations for a user * * @param $ID ID a the user **/ static function showForUser($ID) { global $DB, $CFG_GLPI; $resaID = 0; if (!Session::haveRight("reservation", READ)) { return false; } echo "
"; $now = $_SESSION["glpi_currenttime"]; // Print reservation in progress $iterator = $DB->request([ 'SELECT' => [ 'begin', 'end', 'items_id', 'glpi_reservationitems.entities_id', 'users_id', 'glpi_reservations.comment', 'reservationitems_id', 'completename' ], 'FROM' => 'glpi_reservations', 'LEFT JOIN' => [ 'glpi_reservationitems' => [ 'ON' => [ 'glpi_reservationitems' => 'id', 'glpi_reservations' => 'reservationitems_id' ] ], 'glpi_entities' => [ 'ON' => [ 'glpi_reservationitems' => 'entities_id', 'glpi_entities' => 'id' ] ] ], 'WHERE' => [ 'end' => ['>', $now], 'users_id' => $ID ], 'ORDERBY' => 'begin' ]); $ri = new ReservationItem(); echo ""; echo "\n"; if (count($iterator) == 0) { echo ""; echo ""; } else { echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; while ($data = $iterator->next()) { echo ""; echo ""; echo ""; if ($ri->getFromDB($data["reservationitems_id"])) { $link = " "; if ($item = getItemForItemtype($ri->fields['itemtype'])) { if ($item->getFromDB($ri->fields['items_id'])) { $link = $item->getLink(); } } echo ""; echo ""; } else { echo ""; } echo ""; echo ""; echo "\n"; } } echo "
".__('Current and future reservations')."
".__('No reservation')."
".__('Start date')."".__('End date').""._n('Item', 'Items', 1)."".Entity::getTypeName(1)."".__('By')."".__('Comments')." 
".Html::convDateTime($data["begin"])."".Html::convDateTime($data["end"])."$link".$data['completename']." ".getUserName($data["users_id"])."".nl2br($data["comment"]).""; list($annee, $mois, $jour) = explode("-", $data["begin"]); echo ""; echo ""; echo "".__('See planning').""; echo "
\n"; // Print old reservations $iterator = $DB->request([ 'SELECT' => [ 'begin', 'end', 'items_id', 'glpi_reservationitems.entities_id', 'users_id', 'glpi_reservations.comment', 'reservationitems_id', 'completename' ], 'FROM' => 'glpi_reservations', 'LEFT JOIN' => [ 'glpi_reservationitems' => [ 'ON' => [ 'glpi_reservationitems' => 'id', 'glpi_reservations' => 'reservationitems_id' ] ], 'glpi_entities' => [ 'ON' => [ 'glpi_reservationitems' => 'entities_id', 'glpi_entities' => 'id' ] ] ], 'WHERE' => [ 'end' => ['<=', $now], 'users_id' => $ID ], 'ORDERBY' => 'begin DESC' ]); echo "
"; echo ""; echo "\n"; if (count($iterator) == 0) { echo ""; echo "\n"; } else { echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; while ($data = $iterator->next()) { echo ""; echo ""; echo ""; if ($ri->getFromDB($data["reservationitems_id"])) { $link = " "; if ($item = getItemForItemtype($ri->fields['itemtype'])) { if ($item->getFromDB($ri->fields['items_id'])) { $link = $item->getLink(); } } echo ""; echo ""; } else { echo ""; } echo ""; echo ""; echo "\n"; } } echo "
".__('Past reservations')."
".__('No reservation')."
".__('Start date')."".__('End date').""._n('Item', 'Items', 1)."".Entity::getTypeName(1)."".__('By')."".__('Comments')." 
".Html::convDateTime($data["begin"])."".Html::convDateTime($data["end"])."$link".$data['completename']." ".getUserName($data["users_id"])."".nl2br($data["comment"]).""; list($annee, $mois, $jour) = explode("-", $data["begin"]); echo ""; echo ""; echo "".__('See planning').""; echo "
\n"; } static function getIcon() { return "fas fa-calendar-check"; } }