<?php
#    IRM - The Information Resource Manager
#    Copyright (C) 1999 Yann Ramin
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program 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 (in file COPYING) for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
################################################################################

include("../include/irm.inc");
require_once 'lib/Config.php';
require_once 'include/i18n.php';

AuthCheck("tech");
header("Location: ".Config::AbsLoc('users/computers-index.php'));

$track = new Tracking();
$trackIDs = $track->getByComputerID($ID);
PRINT "trackIDs = $trackIDs\n";
$trackIDsSize = sizeof($trackIDs);
for($i=0;$i<$trackIDsSize;$i++)
{
	$track2 = new Tracking($trackIDs[$i]);
	$track2->delete();
}
$DB = Config::Database();
$qID = $DB->getTextValue($ID);
$query = "DELETE FROM computers WHERE (ID = $qID)";
$DB->query($query);
$query = "DELETE FROM inst_software WHERE (cID = $qID)";
$DB->query($query);
// Wipe out all wire relating to ports on this PC
$ports = $DB->getCol("SELECT ID FROM networking_ports WHERE (device_on=$qID AND device_type=1)");
foreach ($ports as $p)
{
	$qp = $DB->getTextValue($p);
	$query = "DELETE FROM networking_wire WHERE end1=$qp OR end2=$qp";
	$DB->query($query);
}
$query = "DELETE FROM networking_ports WHERE (device_on = $qID AND device_type = 1)";
$DB->query($query);
logevent($ID, _("computers"), 4, _("database"), sprintf(_("%s deleted record"), $IRMName)); 
