/**
  * 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;
         }
     }
 }
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');
            $ri->delete($_POST, 1);
            Event::log($_POST['id'], "reservationitem", 4, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
            Html::back();
        } else {
            if (isset($_POST["restore"])) {
                $ri->check($_POST["id"], 'd');
                $ri->restore($_POST);
                Event::log($_POST['id'], "reservationitem", 4, "inventory", sprintf(__('%s restores an item'), $_SESSION["glpiname"]));
                Html::back();
            } else {
Exemple #3
0
 /**
  * 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);
     }
 }
// 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");
            $ri->update($_REQUEST);
            Event::log($_REQUEST['id'], "reservationitem", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][21]);
            glpi_header($_SERVER['HTTP_REFERER']);
        } else {
            checkRight("reservation_central", "w");
            commonHeader($LANG['Menu'][17], $_SERVER['PHP_SELF'], "utils", "reservation");
            $ri->showForm($_GET["id"]);
        }
    }
}
 /**
  * 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']);
     }
 }
 /**
  * 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']);
     }
 }