<?
// called from: newtypes.php
// description: deletes types from TYPE table
include("connect.inc");
include("reqlogin.inc");
include("userprefs.inc");
// if the user hit the DELETE key, delete the entry
if ($Delete) {
$TypesSQL = "DELETE FROM types WHERE type_id = '$id'";
$Types = mysql_query($TypesSQL);
$Message = "Type Deleted";
include("newtypes.php");
exit;
}
// see if the entry is used anywhere
$CheckSQL = "SELECT type_name, type_source FROM types WHERE type_id=$id";
$Check = mysql_query($CheckSQL);
$check = mysql_fetch_array($Check);
$source = $check["type_source"];
?>
<html>
<title>Delete Type <?echo $check["type_name"]?></title>
<body bgcolor=<? echo $userdata["bgcolor"] ?> text=<? echo $userdata["txtcolor"]?>>
<?
include("links.inc");
printf("<form action=\"deltype.php?id=%s\" method=\"post\">", $id);
if ($source == "Contact") {
$exist = 0;
$CheckContactSQL = "SELECT contact_id, first, last FROM contact WHERE contact_type=$id";
$CheckContact = mysql_query($CheckContactSQL);
if ($checkcontact = mysql_fetch_array($CheckContact)) {
$exist=1;
printf("<br><br>The following contacts will be affected by deleting type %s:<br><br>", $check["type_name"]);
do {
printf("<a href=\"display.php?id=%s\">%s %s</a><br>", $checkcontact["contact_id"], $checkcontact["first"], $checkcontact["last"]);
} while ($checkcontact = mysql_fetch_array($CheckContact));
}
}
elseif ($source == "Address") {
$exist = 0;
$CheckAddressSQL = "SELECT contact_id, first, last FROM contact, address WHERE address_type=$id AND fk_contact_id=contact_id";
$CheckAddress = mysql_query($CheckAddressSQL);
if ($checkaddress = mysql_fetch_array($CheckAddress)) {
$exist=1;
printf("<br><br>The following contacts will be affected by deleting type %s:<br><br>", $check["type_name"]);
do {
printf("<a href=\"display.php?id=%s\">%s %s</a><br>", $checkaddress["contact_id"], $checkaddress["first"], $checkaddress["last"]);
} while ($checkaddress = mysql_fetch_array($CheckAddress));
}
}
elseif ($source == "Phone") {
$exist = 0;
$CheckPhoneSQL = "SELECT contact_id, first, last FROM contact, phone WHERE phone_type=$id AND fk_contact_id=contact_id";
$CheckPhone = mysql_query($CheckPhoneSQL);
if ($checkphone = mysql_fetch_array($CheckPhone)) {
$exist=1;
printf("<br><br>The following contacts will be affected by deleting type %s:<br><br>", $check["type_name"]);
do {
printf("<a href=\"display.php?id=%s\">%s %s</a><br>", $checkphone["contact_id"], $checkphone["first"], $checkphone["last"]);
} while ($checkphone = mysql_fetch_array($CheckPhone));
}
}
elseif ($source == "Project") {
$exist = 0;
$CheckProjectSQL = "SELECT proj_id, name FROM project WHERE type=$id";
$CheckProject = mysql_query($CheckProjectSQL);
if ($checkproj = mysql_fetch_array($CheckProject)) {
$exist=1;
printf("<br><br>The following project will be affected by deleting type %s:<br><br>", $check["type_name"]);
do {
printf("<a href=\"projectdisplay.php?id=%s\">%s</a><br>", $checkproj["proj_id"], $checkproj["name"]);
} while ($checkproj = mysql_fetch_array($CheckProject));
}
}
elseif ($source == "ProjectStatus") {
$exist = 0;
$CheckProjectSQL = "SELECT proj_id, name FROM project WHERE status=$id";
$CheckProject = mysql_query($CheckProjectSQL);
if ($checkproj = mysql_fetch_array($CheckProject)) {
$exit=1;
printf("<br><br>The following project will be affected by deleting type %s:<br><br>", $check["type_name"]);
do {
printf("<a href=\"projectdisplay.php?id=%s\">%s</a><br>", $checkproj["proj_id"], $checkproj["name"]);
} while ($checkproj = mysql_fetch_array($CheckProject));
}
}
if ($exist == 0) {
printf("%s is not being used and can safely be deleted. Hit Delete to continue.", $check["type_name"]);
}
?>
<br>
<input type=submit name="Delete" value="Delete Type <?echo $check["type_name"]?>">
</table>
</table>
</form>
<?
include("links.inc");
?>
</body>
</html>