static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) { global $DB, $CFG_GLPI; $ID = $item->getField('id'); $type = get_class($item); if (!Session::haveRight("reservation_central", "r")) { return; } $user = new User(); $ri = new ReservationItem(); $pdf->setColumnsSize(100); if ($ri->getFromDBbyItem($type, $ID)) { $now = $_SESSION["glpi_currenttime"]; $query = "SELECT *\n FROM `glpi_reservationitems`\n INNER JOIN `glpi_reservations`\n ON (`glpi_reservations`.`reservationitems_id` = `glpi_reservationitems`.`id`)\n WHERE `end` > '" . $now . "'\n AND `glpi_reservationitems`.`items_id` = '{$ID}'\n ORDER BY `begin`"; $result = $DB->query($query); $pdf->setColumnsSize(100); $pdf->displayTitle("<b>" . __('Current and future reservations') . "</b>"); if (!$DB->numrows($result)) { $pdf->displayLine("<b>" . __('No reservation') . "</b>"); } else { $pdf->setColumnsSize(14, 14, 26, 46); $pdf->displayTitle('<i>' . __('Start date'), __('End date'), __('By'), __('Comments') . '</i>'); while ($data = $DB->fetch_assoc($result)) { if ($user->getFromDB($data["users_id"])) { $name = formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]); } else { $name = "(" . $data["users_id"] . ")"; } $pdf->displayLine(Html::convDateTime($data["begin"]), Html::convDateTime($data["end"]), $name, str_replace(array("\r", "\n"), " ", $data["comment"])); } } $query = "SELECT *\n FROM `glpi_reservationitems`\n INNER JOIN `glpi_reservations`\n ON (`glpi_reservations`.`reservationitems_id` = `glpi_reservationitems`.`id`)\n WHERE `end` <= '" . $now . "'\n AND `glpi_reservationitems`.`items_id` = '{$ID}'\n ORDER BY `begin`\n DESC"; $result = $DB->query($query); $pdf->setColumnsSize(100); $pdf->displayTitle("<b>" . __('Past reservations') . "</b>"); if (!$DB->numrows($result)) { $pdf->displayLine("<b>" . __('No reservation') . "</b>"); } else { $pdf->setColumnsSize(14, 14, 26, 46); $pdf->displayTitle('<i>' . __('Start date'), __('End date'), __('By'), __('Comments') . '</i>'); while ($data = $DB->fetch_assoc($result)) { if ($user->getFromDB($data["users_id"])) { $name = formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]); } else { $name = "(" . $data["users_id"] . ")"; } $pdf->displayLine(Html::convDateTime($data["begin"]), Html::convDateTime($data["end"]), $name, str_replace(array("\r", "\n"), " ", $data["comment"])); } } } $pdf->displaySpace(); }
/** * 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; } } } }
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -------------------------------------------------------------------------- */ // ---------------------------------------------------------------------- // Original Author of file: // Purpose of file: // ---------------------------------------------------------------------- define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; checkCentralAccess(); $ri = new ReservationItem(); if (isset($_REQUEST["add"])) { checkRight("reservation_central", "w"); if ($newID = $ri->add($_REQUEST)) { Event::log($newID, "reservationitem", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][20] . " " . $_REQUEST["itemtype"] . "-" . $_REQUEST["items_id"] . "."); } glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_REQUEST["delete"])) { checkRight("reservation_central", "w"); $ri->delete($_REQUEST); Event::log($_REQUEST['id'], "reservationitem", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][22]); glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_REQUEST["update"])) { checkRight("reservation_central", "w");
/** * 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> </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 = " "; 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'> </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"] . "&mois_courant={$mois}&" . "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> </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 = " "; 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'> </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"] . "&mois_courant={$mois}&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"; }
/** * @param $type * @param $model_id * @param $tab_ids * @param $location **/ static function replace($type, $model_id, $tab_ids, $location) { global $DB, $CFG_GLPI, $PLUGIN_HOOKS; $model = new PluginUninstallModel(); $model->getConfig($model_id); $overwrite = $model->fields["overwrite"]; echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'><tr><th>" . __('Replacement', 'uninstall') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>"; $count = 0; $tot = count($tab_ids); Html::createProgressBar(__('Please wait, replacement is running...', 'uninstall')); foreach ($tab_ids as $olditem_id => $newitem_id) { $count++; $olditem = new $type(); $olditem->getFromDB($olditem_id); $newitem = new $type(); $newitem->getFromDB($newitem_id); //Hook to perform actions before item is being replaced $olditem->fields['_newid'] = $newitem_id; $olditem->fields['_uninstall_event'] = $model_id; $olditem->fields['_action'] = 'replace'; Plugin::doHook("plugin_uninstall_replace_before", $olditem); // Retrieve informations //States if ($model->fields['states_id'] != 0) { $olditem->update(array('id' => $olditem_id, 'states_id' => $model->fields['states_id']), false); } // METHOD REPLACEMENT 1 : Archive if ($model->fields['replace_method'] == self::METHOD_PURGE) { $name_out = str_shuffle(Toolbox::getRandomString(5) . time()); $plugin = new Plugin(); if ($plugin->isActivated('PDF')) { // USE PDF EXPORT $plugin->load('pdf', true); include_once GLPI_ROOT . "/lib/ezpdf/class.ezpdf.php"; //Get all item's tabs $tab = array_keys($olditem->defineTabs()); //Tell PDF to also export item's main tab, and in first position array_unshift($tab, "_main_"); $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($olditem); $out = $itempdf->generatePDF(array($olditem_id), $tab, 1, false); $name_out .= ".pdf"; } else { //TODO Which datas ? Add Defaults... $out = __('Replacement', 'uninstall') . "\r\n"; $datas = $olditem->fields; unset($datas['comment']); foreach ($datas as $k => $v) { $out .= $k . ";"; } $out .= "\r\n"; foreach ($datas as $k => $v) { $out .= $v . ";"; } // USE CSV EXPORT $name_out .= ".csv"; } // Write document $out_file = GLPI_DOC_DIR . "/_uploads/" . $name_out; $open_file = fopen($out_file, 'a'); fwrite($open_file, $out); fclose($open_file); // Compute comment text $comment = __('This document is the archive of this replaced item', 'uninstall') . " " . self::getCommentsForReplacement($olditem, false, false); // Create & Attach new document to current item $doc = new Document(); $input = array('name' => addslashes(__('Archive of old material', 'uninstall')), 'upload_file' => $name_out, 'comment' => addslashes($comment), 'add' => __('Add'), 'entities_id' => $newitem->getEntityID(), 'is_recursive' => $newitem->isRecursive(), 'link' => "", 'documentcategories_id' => 0, 'items_id' => $olditem_id, 'itemtype' => $type); //Attached the document to the old item, to generate an accurate name $document_added = $doc->add($input); //Attach the document to the new item, once the document's name is correct $docItem = new Document_Item(); $docItemId = $docItem->add(array('documents_id' => $document_added, 'itemtype' => $type, 'items_id' => (int) $newitem_id)); } // General Informations - NAME if ($model->fields["replace_name"]) { if ($overwrite || empty($newitem->fields['name'])) { $newitem->update(array('id' => $newitem_id, 'name' => $olditem->getField('name')), false); } } $data['id'] = $newitem->getID(); // General Informations - SERIAL if ($model->fields["replace_serial"]) { if ($overwrite || empty($newitem->fields['serial'])) { $newitem->update(array('id' => $newitem_id, 'serial' => $olditem->getField('serial')), false); } } // General Informations - OTHERSERIAL if ($model->fields["replace_otherserial"]) { if ($overwrite || empty($newitem->fields['otherserial'])) { $newitem->update(array('id' => $newitem_id, 'otherserial' => $olditem->getField('otherserial')), false); } } // Documents if ($model->fields["replace_documents"] && in_array($type, $CFG_GLPI["document_types"])) { $doc_item = new Document_Item(); foreach (self::getAssociatedDocuments($olditem) as $document) { $doc_item->update(array('id' => $document['assocID'], 'itemtype' => $type, 'items_id' => $newitem_id), false); } } // Contracts if ($model->fields["replace_contracts"] && in_array($type, $CFG_GLPI["contract_types"])) { $contract_item = new Contract_Item(); foreach (self::getAssociatedContracts($olditem) as $contract) { $contract_item->update(array('id' => $contract['id'], 'itemtype' => $type, 'items_id' => $newitem_id), false); } } // Infocoms if ($model->fields["replace_infocoms"] && in_array($type, $CFG_GLPI["infocom_types"])) { $infocom = new Infocom(); if ($overwrite) { // Delete current Infocoms of new item if ($infocom->getFromDBforDevice($type, $newitem_id)) { //Do not log infocom deletion in the new item's history $infocom->dohistory = false; $infocom->deleteFromDB(1); } } // Update current Infocoms of old item if ($infocom->getFromDBforDevice($type, $olditem_id)) { $infocom->update(array('id' => $infocom->getID(), 'itemtype' => $type, 'items_id' => $newitem_id), false); } } // Reservations if ($model->fields["replace_reservations"] && in_array($type, $CFG_GLPI["reservation_types"])) { $resaitem = new ReservationItem(); if ($overwrite) { // Delete current reservation of new item $resa_new = new Reservation(); $resa_new->getFromDB($newitem_id); if ($resa_new->is_reserved()) { $resa_new = new ReservationItem(); $resa_new->getFromDBbyItem($type, $newitem_id); if (count($resa_new->fields)) { $resa_new->deleteFromDB(1); } } } // Update old reservation for attribute to new item $resa_old = new Reservation(); $resa_old->getFromDB($olditem_id); if ($resa_old->is_reserved()) { $resa_old = new ReservationItem(); $resa_old->getFromDBbyItem($type, $olditem_id); if (count($resa_old->fields)) { $resa_old->update(array('id' => $resa_old->getID(), 'itemtype' => $type, 'items_id' => $newitem_id), false); } } } // User if ($model->fields["replace_users"] && in_array($type, $CFG_GLPI["linkuser_types"])) { $data = array(); $data['id'] = $newitem->getID(); if ($newitem->isField('users_id') && ($overwrite || empty($data['users_id']))) { $data['users_id'] = $olditem->getField('users_id'); } if ($newitem->isField('contact') && ($overwrite || empty($data['contact']))) { $data['contact'] = $olditem->getField('contact'); } if ($newitem->isField('contact_num') && ($overwrite || empty($data['contact_num']))) { $data['contact_num'] = $olditem->getField('contact_num'); } $newitem->update($data, false); } // Group if ($model->fields["replace_groups"] && in_array($type, $CFG_GLPI["linkgroup_types"])) { if ($newitem->isField('groups_id') && ($overwrite || empty($data['groups_id']))) { $newitem->update(array('id' => $newitem_id, 'groups_id' => $olditem->getField('groups_id')), false); } } // Tickets if ($model->fields["replace_tickets"] && in_array($type, $CFG_GLPI["ticket_types"])) { $ticket_item = new Item_Ticket(); foreach (self::getAssociatedTickets($type, $olditem_id) as $ticket) { $ticket_item->update(array('id' => $ticket['id'], 'items_id' => $newitem_id), false); } } //Array netport_types renamed in networkport_types in GLPI 0.80 if (isset($CFG_GLPI["netport_types"])) { $netport_types = $CFG_GLPI["netport_types"]; } else { $netport_types = $CFG_GLPI["networkport_types"]; } // NetPorts if ($model->fields["replace_netports"] && in_array($type, $netport_types)) { $netport_item = new NetworkPort(); foreach (self::getAssociatedNetports($type, $olditem_id) as $netport) { $netport_item->update(array('id' => $netport['id'], 'itemtype' => $type, 'items_id' => $newitem_id), false); } } // Directs connections if ($model->fields["replace_direct_connections"] && in_array($type, array('Computer'))) { $comp_item = new Computer_Item(); foreach (self::getAssociatedItems($olditem) as $itemtype => $connections) { foreach ($connections as $connection) { $comp_item->update(array('id' => $connection['id'], 'computers_id' => $newitem_id, 'itemtype' => $itemtype), false); } } } // Location if ($location != 0 && $olditem->isField('locations_id')) { $olditem->getFromDB($olditem_id); switch ($location) { case -1: break; default: $olditem->update(array('id' => $olditem_id, 'locations_id' => $location), false); break; } } $plug = new Plugin(); if ($plug->isActivated('ocsinventoryng')) { //Delete computer from OCS if ($model->fields["remove_from_ocs"] == 1) { PluginUninstallUninstall::deleteComputerInOCSByGlpiID($olditem_id); } //Delete link in glpi_ocs_link if ($model->fields["delete_ocs_link"] || $model->fields["remove_from_ocs"]) { PluginUninstallUninstall::deleteOcsLink($olditem_id); } } if ($plug->isActivated('fusioninventory')) { if ($model->fields['raz_fusioninventory']) { PluginUninstallUninstall::deleteFusionInventoryLink(get_class($olditem), $olditem_id); } } // METHOD REPLACEMENT 1 : Purge if ($model->fields['replace_method'] == self::METHOD_PURGE) { // Retrieve, Compute && Update NEW comment field $comment = self::getCommentsForReplacement($olditem, true); $comment .= "\n- " . __('See attached document', 'uninstall'); $newitem->update(array('id' => $newitem_id, 'comment' => addslashes($comment)), false); // If old item is attached in PDF/CSV // Delete AND Purge it in DB if ($document_added) { $olditem->delete(array('id' => $olditem_id), true); } } // METHOD REPLACEMENT 2 : Delete AND Comment if ($model->fields['replace_method'] == self::METHOD_DELETE_AND_COMMENT) { //Add comment on the new item first $comment = self::getCommentsForReplacement($olditem, true); $newitem->update(array('id' => $newitem_id, 'comment' => Toolbox::addslashes_deep($comment)), false); // Retrieve, Compute && Update OLD comment field $comment = self::getCommentsForReplacement($newitem, false); $olditem->update(array('id' => $olditem_id, 'comment' => Toolbox::addslashes_deep($comment)), false); // Delete OLD item from DB (not PURGE) PluginUninstallUninstall::addUninstallLog($type, $olditem_id, 'replaced_by'); $olditem->delete(array('id' => $olditem_id), 0, false); } //Plugin hook after replacement Plugin::doHook("plugin_uninstall_replace_after", $olditem); //Add history PluginUninstallUninstall::addUninstallLog($type, $newitem_id, 'replace'); Html::changeProgressBarPosition($count, $tot + 1); } Html::changeProgressBarPosition($count, $tot, __('Replacement successful', 'uninstall')); echo "</td></tr>"; echo "</table></div>"; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param ReservationItem $value A ReservationItem object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(ReservationItem $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * 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> </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 = " "; 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'> </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"] . "&mois_courant={$mois}&" . "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> </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 = " "; 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'> </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"] . "&mois_courant={$mois}&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"; }
GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkCentralAccess(); Session::checkRight("reservation_central", "w"); if (!isset($_GET["id"])) { $_GET["id"] = ''; } $ri = new ReservationItem(); if (isset($_POST["add"])) { $ri->check(-1, 'w', $_POST); if ($newID = $ri->add($_POST)) { Event::log($newID, "reservationitem", 4, "inventory", sprintf(__('%1$s adds the item %2$s (%3$d)'), $_SESSION["glpiname"], $_POST["itemtype"], $_POST["items_id"])); } Html::back(); } else { if (isset($_POST["delete"])) { $ri->check($_POST["id"], 'd'); $ri->delete($_POST); Event::log($_POST['id'], "reservationitem", 4, "inventory", sprintf(__('%s deletes an item'), $_SESSION["glpiname"])); Html::back(); } else { if (isset($_POST["purge"])) { $ri->check($_POST["id"], 'd');
/** * Delete reservations for an itemtype * @param $itemtype * @return nothing */ static function deleteReservationItems($itemtype) { $reservationItem = new ReservationItem(); $reservationItem->deleteByCriteria(array('itemtype' => $itemtype), true); }
GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkCentralAccess(); Session::checkRightsOr('reservation', array(CREATE, UPDATE, DELETE, PURGE)); if (!isset($_GET["id"])) { $_GET["id"] = ''; } $ri = new ReservationItem(); if (isset($_POST["add"])) { $ri->check(-1, CREATE, $_POST); if ($newID = $ri->add($_POST)) { Event::log($newID, "reservationitem", 4, "inventory", sprintf(__('%1$s adds the item %2$s (%3$d)'), $_SESSION["glpiname"], $_POST["itemtype"], $_POST["items_id"])); } Html::back(); } else { if (isset($_POST["delete"])) { $ri->check($_POST["id"], DELETE); $ri->delete($_POST); Event::log($_POST['id'], "reservationitem", 4, "inventory", sprintf(__('%s deletes an item'), $_SESSION["glpiname"])); Html::back(); } else { if (isset($_POST["purge"])) { $ri->check($_POST["id"], PURGE);
/** * Clean the date in the relation tables for the deleted item * Clear N/N Relation **/ function cleanRelationTable() { global $CFG_GLPI, $DB; // If this type have INFOCOM, clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['infocom_types'])) { $infocom = new Infocom(); if ($infocom->getFromDBforDevice($this->getType(), $this->fields['id'])) { $infocom->delete(array('id' => $infocom->fields['id'])); } } // If this type have NETPORT, clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['networkport_types'])) { $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE (`items_id` = '" . $this->fields['id'] . "'\n AND `itemtype` = '" . $this->getType() . "')"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $q = "DELETE\n FROM `glpi_networkports_networkports`\n WHERE (`networkports_id_1` = '" . $data["id"] . "'\n OR `networkports_id_2` = '" . $data["id"] . "')"; $result2 = $DB->query($q); } $query = "DELETE\n FROM `glpi_networkports`\n WHERE (`items_id` = '" . $this->fields['id'] . "'\n AND `itemtype` = '" . $this->getType() . "')"; $result = $DB->query($query); } // If this type is RESERVABLE clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['reservation_types'])) { $rr = new ReservationItem(); if ($rr->getFromDBbyItem($this->getType(), $this->fields['id'])) { $rr->delete(array('id' => $infocom->fields['id'])); } } // If this type have CONTRACT, clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['contract_types'])) { $ci = new Contract_Item(); $ci->cleanDBonItemDelete($this->getType(), $this->fields['id']); } // If this type have DOCUMENT, clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI["document_types"])) { $di = new Document_Item(); $di->cleanDBonItemDelete($this->getType(), $this->fields['id']); } }
GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkRightsOr('reservation', array(READ, ReservationItem::RESERVEANITEM)); if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") { Html::helpHeader(__('Simplified interface'), $_SERVER['PHP_SELF'], $_SESSION["glpiname"]); } else { Html::header(Reservation::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "tools", "reservationitem"); } $res = new ReservationItem(); $res->display($_GET); if (isset($_POST['submit'])) { $_SESSION['glpi_saved']['ReservationItem'] = $_POST; } else { unset($_SESSION['glpi_saved']['ReservationItem']); } if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") { Html::helpFooter(); } else { Html::footer(); }
/** * Clean the date in the relation tables for the deleted item * Clear N/N Relation **/ function cleanRelationTable() { global $CFG_GLPI, $DB; // If this type have INFOCOM, clean one associated to purged item if (Infocom::canApplyOn($this)) { $infocom = new Infocom(); if ($infocom->getFromDBforDevice($this->getType(), $this->fields['id'])) { $infocom->delete(array('id' => $infocom->fields['id'])); } } // If this type have NETPORT, clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['networkport_types'])) { // If we don't use delete, then cleanDBonPurge() is not call and the NetworkPorts are not // clean properly $networkPortObject = new NetworkPort(); $networkPortObject->cleanDBonItemDelete($this->getType(), $this->getID()); // Manage networkportmigration if exists if (TableExists('glpi_networkportmigrations')) { $networkPortMigObject = new NetworkPortMigration(); $networkPortMigObject->cleanDBonItemDelete($this->getType(), $this->getID()); } } // If this type is RESERVABLE clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['reservation_types'])) { $rr = new ReservationItem(); if ($rr->getFromDBbyItem($this->getType(), $this->fields['id'])) { $rr->delete(array('id' => $infocom->fields['id'])); } } // If this type have CONTRACT, clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['contract_types'])) { $ci = new Contract_Item(); $ci->cleanDBonItemDelete($this->getType(), $this->fields['id']); } // If this type have DOCUMENT, clean one associated to purged item if (Document::canApplyOn($this)) { $di = new Document_Item(); $di->cleanDBonItemDelete($this->getType(), $this->fields['id']); } // If this type have NOTEPAD, clean one associated to purged item if ($this->usenotepad) { $note = new Notepad(); $note->cleanDBonItemDelete($this->getType(), $this->fields['id']); } }
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] . " :</td>"; echo "<td class='b'>{$type} - {$name}</td></tr>\n"; echo "<tr class='tab_bg_1'><td>" . $LANG['common'][25] . " :</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; } }
/** * Delete all loans associated with a itemtype * @param the itemtype * @return nothing */ public static function deleteLoans($itemtype) { $reservation_item = new ReservationItem(); foreach ($reservation_item->find("`itemtype`='{$itemtype}'") as $data) { $reservation_item->delete($data); } }
/** * to list infos in debug tab **/ function showDebugInfo() { global $CFG_GLPI; $class = $this->getType(); if (method_exists($class, 'showDebug')) { $this->showDebug(); } if (InfoCom::canApplyOn($class)) { $infocom = new Infocom(); if ($infocom->getFromDBforDevice($class, $this->fields['id'])) { $infocom->showDebug(); } } if (in_array($class, $CFG_GLPI["reservation_types"])) { $resitem = new ReservationItem(); if ($resitem->getFromDBbyItem($class, $this->fields['id'])) { $resitem->showDebugResa(); } } }
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -------------------------------------------------------------------------- */ // ---------------------------------------------------------------------- // Original Author of file: // Purpose of file: // ---------------------------------------------------------------------- define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; checkSeveralRightsOr(array("reservation_central" => "r", "reservation_helpdesk" => "1")); if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") { helpHeader($LANG['Menu'][31], $_SERVER['PHP_SELF'], $_SESSION["glpiname"]); } else { commonHeader($LANG['Menu'][17], $_SERVER['PHP_SELF'], "utils", "reservation"); } if (!haveRight("reservation_central", "r")) { ReservationItem::showListSimple(); } else { Search::show('ReservationItem'); } if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") { helpFooter(); } else { commonFooter(); }
/** * Transfer reservations of an item * * @param $itemtype original type of transfered item * @param $ID original ID of the item * @param $newID new ID of the item **/ function transferReservations($itemtype, $ID, $newID) { global $DB; $ri = new ReservationItem(); if ($ri->getFromDBbyItem($itemtype, $ID)) { switch ($this->options['keep_reservation']) { // delete case 0: // Same item -> delete if ($ID == $newID) { $ri->delete(array('id' => $ri->fields['id'])); } // Copy : nothing to do break; // Keep // Keep default: // Copy : set item as reservable if ($ID != $newID) { $input['itemtype'] = $itemtype; $input['items_id'] = $newID; $input['is_active'] = $ri->fields['is_active']; unset($ri->fields); $ri->add($input); } // Same item -> nothing to do break; } } }
/** * Exclude object from result * * @param ReservationItem $reservationItem Object to remove from the list of results * * @return ReservationItemQuery The current query, for fluid interface */ public function prune($reservationItem = null) { if ($reservationItem) { $this->addUsingAlias(ReservationItemPeer::ID, $reservationItem->getId(), Criteria::NOT_EQUAL); } return $this; }