/**
  * Get item associated with the object on which the event was raised
  *
  * @param $event  (default '')
  *
  * @return the object associated with the itemtype
  **/
 function getObjectItem($event = '')
 {
     if ($this->obj) {
         $ri = new ReservationItem();
         if ($ri->getFromDB($this->obj->getField('reservationitems_id'))) {
             $itemtype = $ri->getField('itemtype');
             if ($itemtype != NOT_AVAILABLE && $itemtype != '' && ($item = getItemForItemtype($itemtype))) {
                 $item->getFromDB($ri->getField('items_id'));
                 $this->target_object[] = $item;
             }
         }
     }
 }
 function showForm($ID, $options = array())
 {
     global $LANG;
     if (!haveRight("reservation_central", "w")) {
         return false;
     }
     $r = new ReservationItem();
     if ($r->getFromDB($ID)) {
         $type = $r->fields["itemtype"];
         $name = NOT_AVAILABLE;
         if (class_exists($r->fields["itemtype"])) {
             $item = new $r->fields["itemtype"]();
             $type = $item->getTypeName();
             if ($item->getFromDB($r->fields["items_id"])) {
                 $name = $item->getName();
             }
         }
         echo "<div class='center'><form method='post' name=form action='" . $this->getFormURL() . "'>";
         echo "<input type='hidden' name='id' value='{$ID}'>";
         echo "<table class='tab_cadre'>";
         echo "<tr><th colspan='2'>" . $LANG['reservation'][22] . "</th></tr>";
         // Ajouter le nom du materiel
         echo "<tr class='tab_bg_1'><td>" . $LANG['common'][1] . "&nbsp;:</td>";
         echo "<td class='b'>{$type} - {$name}</td></tr>\n";
         echo "<tr class='tab_bg_1'><td>" . $LANG['common'][25] . "&nbsp;:</td>";
         echo "<td><textarea name='comment' cols='30' rows='10' >" . $r->fields["comment"];
         echo "</textarea></td></tr>\n";
         echo "<tr class='tab_bg_2'><td colspan='2' class='top center'>";
         echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][14] . "\" class='submit'>";
         echo "</td></tr>\n";
         echo "</table></form></div>";
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 /**
  * 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 "<div class='firstbloc'>";
     $now = $_SESSION["glpi_currenttime"];
     // Print reservation in progress
     $query = "SELECT `begin`, `end`, `items_id`, `glpi_reservationitems`.`entities_id`,\n                       `users_id`, `glpi_reservations`.`comment`, `reservationitems_id`,\n                       `completename`\n                FROM `glpi_reservations`\n                LEFT JOIN `glpi_reservationitems`\n                  ON `glpi_reservations`.`reservationitems_id` = `glpi_reservationitems`.`id`\n                LEFT JOIN `glpi_entities`\n                  ON  `glpi_reservationitems`.`entities_id` = `glpi_entities`.`id`\n                WHERE `end` > '" . $now . "'\n                      AND `users_id` = '{$ID}'\n                ORDER BY `begin`";
     $result = $DB->query($query);
     $ri = new ReservationItem();
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='6'>" . __('Current and future reservations') . "</th></tr>\n";
     if ($DB->numrows($result) == 0) {
         echo "<tr class='tab_bg_2'>";
         echo "<td class='center' colspan='6'>" . __('No reservation') . "</td></tr\n>";
     } else {
         echo "<tr><th>" . __('Start date') . "</th>";
         echo "<th>" . __('End date') . "</th>";
         echo "<th>" . __('Item') . "</th>";
         echo "<th>" . __('Entity') . "</th>";
         echo "<th>" . __('By') . "</th>";
         echo "<th>" . __('Comments') . "</th><th>&nbsp;</th></tr>\n";
         while ($data = $DB->fetch_assoc($result)) {
             echo "<tr class='tab_bg_2'>";
             echo "<td class='center'>" . Html::convDateTime($data["begin"]) . "</td>";
             echo "<td class='center'>" . Html::convDateTime($data["end"]) . "</td>";
             if ($ri->getFromDB($data["reservationitems_id"])) {
                 $link = "&nbsp;";
                 if ($item = getItemForItemtype($ri->fields['itemtype'])) {
                     if ($item->getFromDB($ri->fields['items_id'])) {
                         $link = $item->getLink();
                     }
                 }
                 echo "<td class='center'>{$link}</td>";
                 echo "<td class='center'>" . $data['completename'] . "</td>";
             } else {
                 echo "<td class='center'>&nbsp;</td>";
             }
             echo "<td class='center'>" . getUserName($data["users_id"]) . "</td>";
             echo "<td class='center'>" . nl2br($data["comment"]) . "</td>";
             echo "<td class='center'>";
             list($annee, $mois, $jour) = explode("-", $data["begin"]);
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/reservation.php?reservationitems_id=" . $data["reservationitems_id"] . "&amp;mois_courant={$mois}&amp;" . "annee_courante={$annee}' title=\"" . __s('See planning') . "\"><img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>";
             echo "</td></tr>\n";
         }
     }
     echo "</table></div>\n";
     // Print old reservations
     $query = "SELECT `begin`, `end`, `items_id`, `glpi_reservationitems`.`entities_id`,\n                       `users_id`, `glpi_reservations`.`comment`, `reservationitems_id`,\n                       `completename`\n                FROM `glpi_reservations`\n                LEFT JOIN `glpi_reservationitems`\n                  ON `glpi_reservations`.`reservationitems_id` = `glpi_reservationitems`.`id`\n                LEFT JOIN `glpi_entities`\n                  ON  `glpi_reservationitems`.`entities_id` = `glpi_entities`.`id`\n                WHERE `end` <= '" . $now . "'\n                      AND `users_id` = '{$ID}'\n                ORDER BY `begin` DESC";
     $result = $DB->query($query);
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='6'>" . __('Past reservations') . "</th></tr>\n";
     if ($DB->numrows($result) == 0) {
         echo "<tr class='tab_bg_2'>";
         echo "<td class='center' colspan='6'>" . __('No reservation') . "</td></tr>\n";
     } else {
         echo "<tr><th>" . __('Start date') . "</th>";
         echo "<th>" . __('End date') . "</th>";
         echo "<th>" . __('Item') . "</th>";
         echo "<th>" . __('Entity') . "</th>";
         echo "<th>" . __('By') . "</th>";
         echo "<th>" . __('Comments') . "</th><th>&nbsp;</th></tr>\n";
         while ($data = $DB->fetch_assoc($result)) {
             echo "<tr class='tab_bg_2'>";
             echo "<td class='center'>" . Html::convDateTime($data["begin"]) . "</td>";
             echo "<td class='center'>" . Html::convDateTime($data["end"]) . "</td>";
             if ($ri->getFromDB($data["reservationitems_id"])) {
                 $link = "&nbsp;";
                 if ($item = getItemForItemtype($ri->fields['itemtype'])) {
                     if ($item->getFromDB($ri->fields['items_id'])) {
                         $link = $item->getLink();
                     }
                 }
                 echo "<td class='center'>{$link}</td>";
                 echo "<td class='center'>" . $data['completename'] . "</td>";
             } else {
                 echo "<td class='center'>&nbsp;</td>";
             }
             echo "<td class='center'>" . getUserName($data["users_id"]) . "</td>";
             echo "<td class='center'>" . nl2br($data["comment"]) . "</td>";
             echo "<td class='center'>";
             list($annee, $mois, $jour) = explode("-", $data["begin"]);
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/reservation.php?reservationitems_id=" . $data["reservationitems_id"] . "&amp;mois_courant={$mois}&amp;annee_courante={$annee}' " . "title=\"" . __s('See planning') . "\">";
             echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png' alt='' title=''></a>";
             echo "</td></tr>\n";
         }
     }
     echo "</table></div>\n";
 }
 /**
  * Display reservations for an user
  *
  * @param $ID ID a the user
  **/
 static function showForUser($ID)
 {
     global $DB, $LANG, $CFG_GLPI;
     $resaID = 0;
     if (!haveRight("reservation_central", "r")) {
         return false;
     }
     echo "<div class='firstbloc'>";
     $now = $_SESSION["glpi_currenttime"];
     // Print reservation in progress
     $query = "SELECT *\n                FROM `glpi_reservations`\n                WHERE `end` > '{$now}'\n                      AND `users_id` = '{$ID}'\n                ORDER BY `begin`";
     $result = $DB->query($query);
     $ri = new ReservationItem();
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='6'>" . $LANG['reservation'][35] . "</th></tr>\n";
     if ($DB->numrows($result) == 0) {
         echo "<tr class='tab_bg_2'>";
         echo "<td class='center' colspan='6'>" . $LANG['reservation'][37] . "</td></tr\n>";
     } else {
         echo "<tr><th>" . $LANG['search'][8] . "</th>";
         echo "<th>" . $LANG['search'][9] . "</th>";
         echo "<th>" . $LANG['common'][1] . "</th>";
         echo "<th>" . $LANG['common'][95] . "</th>";
         echo "<th>" . $LANG['common'][25] . "</th><th>&nbsp;</th></tr>\n";
         while ($data = $DB->fetch_assoc($result)) {
             echo "<tr class='tab_bg_2'>";
             echo "<td class='center'>" . convDateTime($data["begin"]) . "</td>";
             echo "<td class='center'>" . convDateTime($data["end"]) . "</td>";
             if ($ri->getFromDB($data["reservationitems_id"])) {
                 $link = "&nbsp;";
                 if (class_exists($ri->fields['itemtype'])) {
                     $item = new $ri->fields['itemtype']();
                     if ($item->getFromDB($ri->fields['items_id'])) {
                         $link = $item->getLink();
                     }
                 }
                 echo "<td class='center'>{$link}</td>";
             } else {
                 echo "<td class='center'>&nbsp;</td>";
             }
             echo "<td class='center'>" . getUserName($data["users_id"]) . "</td>";
             echo "<td class='center'>" . nl2br($data["comment"]) . "</td>";
             echo "<td class='center'>";
             list($annee, $mois, $jour) = explode("-", $data["begin"]);
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/reservation.php?reservationitems_id=" . $data["reservationitems_id"] . "&amp;mois_courant={$mois}&amp;" . "annee_courante={$annee}' title=\"" . $LANG['reservation'][21] . "\"><img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>";
             echo "</td></tr>\n";
         }
     }
     echo "</table></div>\n";
     // Print old reservations
     $query = "SELECT *\n                FROM `glpi_reservations`\n                WHERE `end` <= '{$now}'\n                      AND `users_id` = '{$ID}'\n                ORDER BY `begin` DESC";
     $result = $DB->query($query);
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='6'>" . $LANG['reservation'][36] . "</th></tr>\n";
     if ($DB->numrows($result) == 0) {
         echo "<tr class='tab_bg_2'>";
         echo "<td class='center' colspan='6'>" . $LANG['reservation'][37] . "</td></tr>\n";
     } else {
         echo "<tr><th>" . $LANG['search'][8] . "</th>";
         echo "<th>" . $LANG['search'][9] . "</th>";
         echo "<th>" . $LANG['common'][1] . "</th>";
         echo "<th>" . $LANG['common'][95] . "</th>";
         echo "<th>" . $LANG['common'][25] . "</th><th>&nbsp;</th></tr>\n";
         while ($data = $DB->fetch_assoc($result)) {
             echo "<tr class='tab_bg_2'>";
             echo "<td class='center'>" . convDateTime($data["begin"]) . "</td>";
             echo "<td class='center'>" . convDateTime($data["end"]) . "</td>";
             if ($ri->getFromDB($data["reservationitems_id"])) {
                 $link = "&nbsp;";
                 if (class_exists($ri->fields['itemtype'])) {
                     $item = new $ri->fields['itemtype']();
                     if ($item->getFromDB($ri->fields['items_id'])) {
                         $link = $item->getLink();
                     }
                 }
                 echo "<td class='center'>{$link}</td>";
             } else {
                 echo "<td class='center'>&nbsp;</td>";
             }
             echo "<td class='center'>" . getUserName($data["users_id"]) . "</td>";
             echo "<td class='center'>" . nl2br($data["comment"]) . "</td>";
             echo "<td class='center'>";
             list($annee, $mois, $jour) = explode("-", $data["begin"]);
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/reservation.php?reservationitems_id=" . $data["reservationitems_id"] . "&amp;mois_courant={$mois}&amp;annee_courante={$annee}' " . "title=\"" . $LANG['reservation'][21] . "\">";
             echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png' alt='' title=''></a>";
             echo "</td></tr>\n";
         }
     }
     echo "</table></div>\n";
 }