|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * @version $Id: $ |
| 4 | + ------------------------------------------------------------------------- |
| 5 | + LICENSE |
| 6 | +
|
| 7 | + This file is part of GestStock plugin for GLPI. |
| 8 | +
|
| 9 | + GestStock is free software: you can redistribute it and/or modify |
| 10 | + it under the terms of the GNU Affero General Public License as published by |
| 11 | + the Free Software Foundation, either version 3 of the License, or |
| 12 | + (at your option) any later version. |
| 13 | +
|
| 14 | + GestStock is distributed in the hope that it will be useful, |
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + GNU Affero General Public License for more details. |
| 18 | +
|
| 19 | + You should have received a copy of the GNU Affero General Public License |
| 20 | + along with GestStock. If not, see <http://www.gnu.org/licenses/>. |
| 21 | +
|
| 22 | + @package geststock |
| 23 | + @author Nelly Mahu-Lasson |
| 24 | + @copyright Copyright (c) 2017 GestStock plugin team |
| 25 | + @license AGPL License 3.0 or (at your option) any later version |
| 26 | + http://www.gnu.org/licenses/agpl-3.0-standalone.html |
| 27 | + @link |
| 28 | + @since version 1.0.0 |
| 29 | + -------------------------------------------------------------------------- |
| 30 | + */ |
| 31 | + |
| 32 | +include ("../../../inc/includes.php"); |
| 33 | + |
| 34 | +Session::checkRight("plugin_geststock", READ); |
| 35 | + |
| 36 | +if (!isset($_GET["id"])) { |
| 37 | + $_GET["id"] = ""; |
| 38 | +} |
| 39 | + |
| 40 | +$PluginReservation = new PluginGeststockReservation(); |
| 41 | +$PluginItem = new PluginGeststockReservation_Item(); |
| 42 | +$PluginFup = new PluginGeststockFollowup(); |
| 43 | +$Fup = new TicketFollowup(); |
| 44 | + |
| 45 | +if (isset($_POST["add"])) { |
| 46 | + $PluginReservation->check(-1, CREATE, $_POST); |
| 47 | + if (empty($_POST['users_id'])) { |
| 48 | + $_POST['users_id'] = Session::getLoginUserID(); |
| 49 | + } |
| 50 | + if (isset($_GET['tickets_id'])) { |
| 51 | + $_POST['tickets_id'] = $_GET['tickets_id']; |
| 52 | + } |
| 53 | + $newID = $PluginReservation->add($_POST); |
| 54 | + if ($newID) { |
| 55 | + Event::log($newID, "geststock", 4, "tools", |
| 56 | + sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $newID)); |
| 57 | + } |
| 58 | + |
| 59 | + if (isset($_POST['_nbrereserv'])) { |
| 60 | + foreach ($_POST['_nbrereserv'] as $lieu => $val) { |
| 61 | + if ($val > 0) { |
| 62 | + $newIDitem = $PluginItem->add(['plugin_geststock_reservations_id' => $newID, |
| 63 | + 'itemtype' => $_POST['_itemtype'], |
| 64 | + 'models_id' => $_POST['_model'], |
| 65 | + 'nbrereserv' => $val, |
| 66 | + 'locations_id_stock' => $lieu]); |
| 67 | + |
| 68 | + if ($newIDitem) { |
| 69 | + $PluginFup->add(['plugin_geststock_reservations_id' => $newID, |
| 70 | + 'plugin_geststock_reservations_items_id' => $newIDitem, |
| 71 | + 'locations_id_old' => $lieu, |
| 72 | + 'users_id' => Session::getLoginUserID()]); |
| 73 | + |
| 74 | + $Fup->add(['tickets_id' => $_POST['tickets_id'], |
| 75 | + 'content' => sprintf(__('%1$s %2$s'), |
| 76 | + __('New reservation created on ', 'geststock'), |
| 77 | + sprintf(__('%1$s (%2$s)'), |
| 78 | + $_SESSION["glpi_currenttime"], |
| 79 | + $newID)), |
| 80 | + 'date' => $_SESSION["glpi_currenttime"], |
| 81 | + 'users_id' => Session::getLoginUserID()]); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + if ($_SESSION['glpibackcreated']) { |
| 87 | + Html::redirect($PluginReservation->getFormURL()."?id=".$newID); |
| 88 | + } |
| 89 | + |
| 90 | + $ticket = new Ticket(); |
| 91 | + Html::redirect($ticket->getFormURL()."?id=".$_POST['tickets_id']); |
| 92 | + |
| 93 | + |
| 94 | +} else if (isset($_POST["update"])) { |
| 95 | + $PluginReservation->check($_POST['id'], UPDATE); |
| 96 | + $PluginReservation->update($_POST); |
| 97 | + Html::back(); |
| 98 | + |
| 99 | +} else if (isset($_POST["delete"])) { |
| 100 | + $PluginReservation->check($_POST['id'], DELETE); |
| 101 | + $PluginReservation->delete($_POST); |
| 102 | + Html::redirect($CFG_GLPI["root_doc"]."/plugins/geststock/front/reservation.php"); |
| 103 | + |
| 104 | +} else if (isset($_POST["restore"])) { |
| 105 | + $PluginReservation->check($_POST['id'], PURGE); |
| 106 | + $PluginReservation->restore($_POST); |
| 107 | + Html::back(); |
| 108 | + |
| 109 | +} else if (isset($_POST["purge"])) { |
| 110 | + $PluginReservation->check($_POST['id'], PURGE); |
| 111 | + if ($PluginReservation->delete($_POST, 1)) { |
| 112 | + Event::log($_POST["id"], "plugingeststockreservation", 4, "tools", |
| 113 | + sprintf(__('%s purges an item'), $_SESSION["glpiname"])); |
| 114 | + } |
| 115 | + Html::redirect($CFG_GLPI["root_doc"]."/plugins/geststock/front/reservation.php"); |
| 116 | + |
| 117 | +} else { |
| 118 | + Html::header(PluginGeststockReservation::getTypeName(1), '', "tools", "plugingeststockmenu"); |
| 119 | + $PluginReservation->display($_GET); |
| 120 | + Html::footer(); |
| 121 | +} |
0 commit comments