<?php
session_start();
require_once ("connect.inc.php");
require_once ("library.inc.php");
require_once ("authentification.inc.php");
require_once ("language.inc.php");
if (isset($_REQUEST["delete"]))
$delete = $_REQUEST["delete"];
else
$delete = "";
if (isset($_REQUEST["orphan"]))
$orphan = $_REQUEST["orphan"];
else
$orphan = "";
if (isset($_REQUEST["collectorid"]))
$collectorid = $_REQUEST["collectorid"];
else
$collectorid = "";
$menu = "delete";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link href="ncd.css" rel="stylesheet" media="screen" type="text/css">
<script type="text/javascript" src="library.js"></script>
<title>NCD toolkit - Delete private collector</title>
</head>
<body>
<div id="main_container">
<div id="banner"><?php include("banner.inc.php"); ?></div>
<div id="content_container">
<div id="content">
<?php
// Present login window if no user data in session
if ($auth != "authenticated")
include ("login.inc.php");
else
{
// Delete record after confirmation
if ($collectorid != "" && $delete == "y")
{
$query = "SELECT Prefix, Title, Suffix, GivenNames, OtherNames, FamilyName FROM Persons WHERE ID = $collectorid";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$list_givenname = $row["GivenNames"];
$list_additionalnames = $row["OtherNames"];
$list_familyname = $row["FamilyName"];
$list_title = $row["t4.Title"];
$list_prefix = $row["Prefix"];
$list_suffix = $row["Suffix"];
$removed_collector = fullname($list_title, $list_prefix, $list_givenname, $list_additionalnames, $list_familyname, $list_suffix);
$remove = "DELETE FROM PrivateCollectorAddresses WHERE PersonID = $collectorid";
mysql_query($remove) or die(mysql_error());
// Test if person is connected to institutions, if not delete completely
$query2 = "SELECT * FROM PersonToInstitutions WHERE PersonID = $collectorid";
$result2 = mysql_query($query2) or die(mysql_error());
if (mysql_num_rows ($result2) == 0)
{
$remove = "DELETE FROM Persons WHERE ID = $collectorid";
mysql_query($remove) or die(mysql_error());
}
$query = "SELECT CollectionID FROM PrivateCollections WHERE PersonID = $collectorid";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$collectionid = $row["CollectionID"];
$remove = "DELETE FROM CollectionAlternativeIDs WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionCollectorNameCoverage WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionCommonNameCoverage WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionConservationStatuses WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionDataByLanguage WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionExpeditionNameCoverage WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionExtents WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionFileFormats WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionFormationPeriods WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionGeospatialCoverage WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionItemLevelAccess WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionKingdomCoverage WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionLivingTimePeriodCoverage WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionMedia WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionRelations WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM Collections WHERE ID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionSpecimenPreservationMethods WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionsToInstitutions WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionTaxonCoverage WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM CollectionTypesToCollection WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM PersonToCollections WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
$remove = "DELETE FROM PrivateCollections WHERE CollectionID = $collectionid";
mysql_query($remove) or die(mysql_error());
}
$collectorid = $delete = "";
}
if ($collectorid != "" && $delete != "y")
{
// First verify collector
check_creator($collectorid, "Persons");
if (in_array($current_creatorid, $permission_group))
{
// Then verify all collections
$collection_no_permission = array();
$nr_of_collections = 0;
$query = "SELECT CollectionID FROM PrivateCollections WHERE PersonID = $collectorid";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$nr_of_collections++;
$collectionid = $row["CollectionID"];
check_creator($collectionid, "Collections");
if (!in_array($current_creatorid, $permission_group))
$collection_no_permission[] = $collectionid;
}
if (count($collection_no_permission) == 0 && $nr_of_collections > 0)
{
$query = "SELECT Prefix, Title, Suffix, GivenNames, OtherNames, FamilyName FROM Persons WHERE ID = $collectorid";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$list_givenname = $row["GivenNames"];
$list_additionalnames = $row["OtherNames"];
$list_familyname = $row["FamilyName"];
$list_title = $row["t4.Title"];
$list_prefix = $row["Prefix"];
$list_suffix = $row["Suffix"];
$fullname = fullname($list_title, $list_prefix, $list_givenname, $list_additionalnames, $list_familyname, $list_suffix);
echo "<h1>Delete private collector</h1>\n";
echo "<p>Are you sure you want to delete $fullname and the ";
if ($nr_of_collections == 1)
echo "single private collection ";
else
echo "$nr_of_collections private collections ";
echo "associated with this person? ";
$query2 = "SELECT * FROM PersonToInstitutions WHERE PersonID = $collectorid";
$result2 = mysql_query($query2) or die(mysql_error());
if (mysql_num_rows ($result2) == 0)
echo "$fullname is not associated with any institutions, so this person will be removed completely!</p>\n";
else
echo "$fullname also is associated with one or more institutions, so this person will not have been completely removed after you click 'Delete private collector'. If you want to delete $fullname completely from the system, please use the 'Delete a person associated with an institution' option as well.</p>\n";
echo "<table>\n<tr>\n<td height=\"50\" class=\"indent\"><form method=\"post\" action=\"delete_private_collector.php\">".
"<input type=\"submit\" value=\"Cancel\">".
"</form></td>\n".
"<td class=\"bottom\"><form method=\"post\" action=\"delete_private_collector.php\">".
"<input type=\"submit\" value=\"Delete private collector\">".
"<input type=\"hidden\" name=\"collectorid\" value=\"$collectorid\">".
"<input type=\"hidden\" name=\"delete\" value=\"y\">".
"</form></td>\n</tr>\n</table>\n";
}
}
else
{
echo "<h1>Delete a private collector</h1>\n";
echo "<p>Sorry, this private collector has already been deleted or you have no permission to delete this private collector. <a href=\"index.php\">Return to the main index</a>.</p>\n";
}
}
else
{
echo "<h1>Delete a private collector</h1>\n";
if ($removed_collector != "")
echo "<p><b>$removed_collector has been deleted.</b></p>\n";
$old_fullname = $collector_table = $no_access_collector_table = "";
$collection_no_permission = array();
$c = $d = $e = 0;
$query = "SELECT t1.CollectionID, t2.Title as CollectionName, t3.PersonID, t4.Prefix, t4.Suffix, t4.Title as Title, t4.GivenNames, t4.OtherNames, t4.FamilyName FROM PrivateCollections t1, CollectionDataByLanguage t2, PersonToCollections t3, Persons t4 WHERE t1.CollectionID = t2.CollectionID AND t1.CollectionID = t3.CollectionID AND t4.ID = t3.PersonID AND t2.LanguageID = '$mdb_lang_id' ORDER BY t4.FamilyName, t4.OtherNames, t4.GivenNames, t2.Title";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$c++;
$collectionid = $row["CollectionID"];
$collectorid = $row["PersonID"];
$collectionname = $row["CollectionName"];
$givenname = $row["GivenNames"];
$additionalnames = $row["OtherNames"];
$familyname = $row["FamilyName"];
$title = $row["Title"];
$prefix = $row["Prefix"];
$suffix = $row["Suffix"];
$fullname = fullname($title, $prefix, $givenname, $additionalnames, $familyname, $suffix);
// Check for permission for collection
check_creator($collectionid, "Collections");
$collection_creator_id = $current_creatorid;
// Check for permission for collector
check_creator($collectorid, "Persons");
$person_creator_id = $current_creatorid;
if (!in_array($collection_creator_id, $permission_group))
$collection_no_permission[] = $collectionid;
if ($fullname != $old_fullname)
{
if (count($collection_no_permission) == 0)
{
$d++;
$collector_table .= "$d. <a href=\"delete_private_collector.php?collectorid=$collectorid\">$fullname</a><br>\n";
}
else
{
$e++;
$no_access_collector_table .= "$e. $fullname<br>\n";
}
$collection_no_permission = array();
}
$old_fullname = $fullname;
}
if ($c == 0)
echo "<p>No private collectors available yet.</p>\n";
else
{
echo "<p>Click a private collector's name to delete this person and all of his/her private collections (a confirmation window follows!). ";
if ($d > 0)
{
echo "<br><br></p>\n<p>";
echo "$collector_table<br><br></p>\n";
}
if ($e > 0)
{
if ($d > 0)
echo "<p>";
echo "You cannot delete the following private collectors, because you don't have permission to delete the person or one or more of his/her collections. <br><br></p>\n<p>$no_access_collector_table</p>";
}
}
}
}
?>
</div>
</div>
<div id="menu"><?php include("menu.inc.php"); ?></div>
<div id="footer"><?php include("footer.inc.php"); ?></div>
</div>
</body>
</html>