<?php
if (!get_magic_quotes_gpc())
{
foreach ($collection_variables as $insert_variable)
$$insert_variable = addslashes($$insert_variable);
}
$before_collection_types = array();
$query = "SELECT CollectionTypeID FROM CollectionTypesToCollection WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_collection_types[] = $row[0];
$before_curators = array();
$query = "SELECT PersonID FROM PersonToCollections WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_curators[] = $row[0];
if ($action == "data_uk")
{
$update = "UPDATE CollectionDataByLanguage SET Title = '$collectionname_uk', AlternativeTitle = '$collection_alt_name_uk', Description = '$collectionabstract_uk', DescriptionForSpecialists = '$collection_spec_abstract_uk', Notes = '$notes_uk', Provenance = '$provenance_uk', CiteAs = '$cite_uk' WHERE CollectionID = $collectionid AND LanguageID = 'eng'";
mysql_query($update) or die(mysql_error());
$anchor = $action;
}
else if ($action == "data_nl")
{
$update = "UPDATE CollectionDataByLanguage SET Title = '$collectionname_nl', AlternativeTitle = '$collection_alt_name_nl', Description = '$collectionabstract_nl', DescriptionForSpecialists = '$collection_spec_abstract_nl', Notes = '$notes_nl', Provenance = '$provenance_nl', CiteAs = '$cite_nl' WHERE CollectionID = $collectionid AND LanguageID = '$second_language_id'";
mysql_query($update) or die(mysql_error());
$anchor = $action;
}
else if ($action == "data_gen")
{
$update = "UPDATE Collections SET PrimaryGroupingPrincipleID = '$primary_grouping_principle_id', PrimaryPurposeID = '$primary_purpose_id', KnownToContainTypes = '$includetypes', IsPartOfCollectionID = '$collection_parentid', RelatedCollections = '$related_collections', Rights = '$collection_rights', AccessRights = '$collection_access_rights', UsageRestrictions = '$collection_usage_restrictions' WHERE ID = $collectionid";
mysql_query($update) or die(mysql_error());
$anchor = $action;
}
else if ($action == "add_type")
{
if (!in_array($selected_collection_type, $before_collection_types) && $selected_collection_type != "")
{
$update = "INSERT INTO CollectionTypesToCollection (CollectionID, CollectionTypeID) VALUES ($collectionid, $selected_collection_type)";
mysql_query($update) or die(mysql_error());
}
$anchor = "types";
}
else if ($action == "remove_type")
{
if (count($before_collection_types) > 1)
{
$update = "DELETE FROM CollectionTypesToCollection WHERE CollectionID = $collectionid AND CollectionTypeID = $selected_collection_type";
mysql_query($update) or die(mysql_error());
$types_error = "";
}
else
$types_error = "<tr><td></td><td class=\"error\">At least one collection type should be selected!</td></tr>\n";
$anchor = "types";
}
else if ($action == "add_conservation")
{
$before_conservation_statuses = array();
$query = "SELECT ConservationStatusID, ConservationStatusDate FROM CollectionConservationStatuses WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$before_conservation_statuses[] = $row[0];
$before_conservation_status_date = $row[1];
}
if (count($before_conservation_statuses) == 0)
$conservation_status_date = $currentdate;
else
$conservation_status_date = $before_conservation_status_date;
if (!in_array($selected_conservation_status, $before_conservation_statuses))
{
$update = "INSERT INTO CollectionConservationStatuses (CollectionID, ConservationStatusID, ConservationStatusDate) VALUES ($collectionid, $selected_conservation_status, '$conservation_status_date')";
mysql_query($update) or die(mysql_error());
}
$anchor = "conservation";
}
else if ($action == "remove_conservation")
{
$update = "DELETE FROM CollectionConservationStatuses WHERE CollectionID = $collectionid AND ConservationStatusID = $selected_conservation_status";
mysql_query($update) or die(mysql_error());
$anchor = "conservation";
}
else if ($action == "update_conservation_date")
{
$date_extra = $date_error = $date_check = "";
if ($conservation_status_date != $currentdate && $conservation_status_year.$conservation_status_month.$conservation_status_day != "")
{
$conservation_status_date = $conservation_status_year."-".$conservation_status_month."-".$conservation_status_day;
if (is_numeric($conservation_status_year) && is_numeric($conservation_status_month) && is_numeric($conservation_status_day))
$date_check = checkdate($conservation_status_month, $conservation_status_day, $conservation_status_year);
if ($date_check == "" || $date_check != TRUE || strtotime($conservation_status_date) > strtotime($currentdate))
{
$date_extra = "class=\"missing\"";
$date_error = "<span class=\"error\">Date incorrect or in the future!</span>";
$conservation_status_date = "";
$display_month = $conservation_status_month;
$display_day = $conservation_status_day;
$display_year = $conservation_status_year;
}
}
if ($conservation_status_date != "")
{
$update = "UPDATE CollectionConservationStatuses SET ConservationStatusDate = '$conservation_status_date' WHERE CollectionID = $collectionid";
mysql_query($update) or die(mysql_error());
}
$anchor = "conservation";
}
else if ($action == "add_development")
{
$update = "UPDATE Collections SET DevelopmentStatusID = '$development_status_id' WHERE ID = $collectionid";
mysql_query($update) or die(mysql_error());
$anchor = "development";
}
else if ($action == "remove_development")
{
$update = "UPDATE Collections SET DevelopmentStatusID = '0' WHERE ID = $collectionid";
mysql_query($update) or die(mysql_error());
$anchor = "development";
}
else if ($action == "add_collector")
{
$before_collectors = array();
$query = "SELECT CollectorName FROM CollectionCollectorNameCoverage WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_collectors[] = $row[0];
if ($selected_collector != "" && !in_array($selected_collector, $before_collectors))
{
$update = "INSERT INTO CollectionCollectorNameCoverage (CollectionID, CollectorName) VALUES ($collectionid, '$selected_collector')";
mysql_query($update) or die(mysql_error());
}
$anchor = "collector";
}
else if ($action == "remove_collector")
{
$update = "DELETE FROM CollectionCollectorNameCoverage WHERE CollectionID = $collectionid AND CollectorName = '$selected_collector'";
mysql_query($update) or die(mysql_error());
$anchor = "collector";
}
else if ($action == "add_expedition")
{
$before_expeditions = array();
$query = "SELECT ExpeditionName, LanguageID FROM CollectionExpeditionNameCoverage WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_expeditions[] = $row[0].$row[1];
if ($selected_expedition != "" && !in_array($selected_expedition.$selected_language_id, $before_expeditions))
{
$update = "INSERT INTO CollectionExpeditionNameCoverage (CollectionID, ExpeditionName, LanguageID) VALUES ($collectionid, '$selected_expedition', '$selected_language_id')";
mysql_query($update) or die(mysql_error());
}
$anchor = "expedition";
}
else if ($action == "remove_expedition")
{
$update = "DELETE FROM CollectionExpeditionNameCoverage WHERE CollectionID = $collectionid AND ExpeditionName = '$selected_expedition' AND LanguageID = '$selected_language_id'";
mysql_query($update) or die(mysql_error());
$anchor = "expedition";
}
else if ($action == "add_formation")
{
$before_formation = array();
$query = "SELECT FormationPeriod, LanguageID FROM CollectionFormationPeriods WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_formation[] = $row[0].$row[1];
if ($selected_formation_period != "" && !in_array($selected_formation_period.$selected_language_id, $before_formation))
{
$update = "INSERT INTO CollectionFormationPeriods (CollectionID, FormationPeriod, LanguageID) VALUES ($collectionid, '$selected_formation_period', '$selected_language_id')";
mysql_query($update) or die(mysql_error());
}
$anchor = "formation";
}
else if ($action == "remove_formation")
{
$update = "DELETE FROM CollectionFormationPeriods WHERE CollectionID = $collectionid AND FormationPeriod = '$selected_formation_period' AND LanguageID = '$selected_language_id'";
mysql_query($update) or die(mysql_error());
$anchor = "formation";
}
else if ($action == "add_extent")
{
$before_extents = array();
$query = "SELECT Size, UnitOfMeasure, LanguageID FROM CollectionExtents WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_extents[] = $row[0].$row[1].$row[2];
if (!is_numeric($extent_number) || $extent_number == "")
$extra1 = "class=\"missing\"";
else
$extra1 = "";
if ($extent_name == "")
$extra2 = "class=\"missing\"";
else
$extra2 = "";
if ($extent_number == "" || !is_numeric($extent_number) || $extent_name == "")
{
$extent_error = "<span class=\"error\">";
if ($extent_number == "")
$extent_error .= "Number missing";
else if (!is_numeric($extent_number))
$extent_error .= "Not a number";
if ($extent_number == "" || !is_numeric($extent_number) && $extent_name == "")
$extent_error .= " and unit of measure missing";
else if ($extent_name == "")
$extent_error .= "Unit of measure missing";
$extent_error .= "!</span>";
$display_name = stripslashes(str_replace("\"", """, $extent_name));
$display_number = stripslashes(str_replace("\"", """, $extent_number));
}
else if ($extent_number.$extent_name != "" && !in_array($extent_number.$extent_name.$selected_language_id, $before_extents))
{
$update = "INSERT INTO CollectionExtents (CollectionID, Size, UnitOfMeasure, LanguageID) VALUES ($collectionid, '$extent_number', '$extent_name', '$selected_language_id')";
mysql_query($update) or die(mysql_error());
$display_name = $display_number = "";
}
$anchor = "extent";
}
else if ($action == "remove_extent")
{
$update = "DELETE FROM CollectionExtents WHERE CollectionID = $collectionid AND Size = '$extent_number' AND UnitOfMeasure = '$extent_name' AND LanguageID = '$selected_language_id'";
mysql_query($update) or die(mysql_error());
$anchor = "extent";
}
else if ($action == "add_kingdom")
{
$before_kingdoms = array();
$query = "SELECT KingdomID FROM CollectionKingdomCoverage WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_kingdoms[] = $row[0];
if (!in_array($selected_kingdom, $before_kingdoms))
{
$update = "INSERT INTO CollectionKingdomCoverage (CollectionID, KingdomID) VALUES ($collectionid, $selected_kingdom)";
mysql_query($update) or die(mysql_error());
}
$anchor = "kingdom";
}
else if ($action == "remove_kingdom")
{
$update = "DELETE FROM CollectionKingdomCoverage WHERE KingdomID = $selected_kingdom AND CollectionID = $collectionid";
mysql_query($update) or die(mysql_error());
$anchor = "kingdom";
}
else if ($action == "add_taxa")
{
$before_taxa = array();
$query = "SELECT Taxon, Strength FROM CollectionTaxonCoverage WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$before_strength = $row[1];
if ($before_strength == 0)
$before_strength = "";
$before_taxa[] = $row[0].$before_strength;
}
if ($selected_taxon != "" && !in_array($selected_taxon.$strength, $before_taxa))
{
$update = "INSERT INTO CollectionTaxonCoverage (CollectionID, Taxon, Strength) VALUES ($collectionid, '$selected_taxon', '$strength')";
mysql_query($update) or die(mysql_error());
}
$anchor = "taxa";
}
else if ($action == "remove_taxa")
{
$update = "DELETE FROM CollectionTaxonCoverage WHERE Taxon = '$selected_taxon' AND Strength = '$strength' AND CollectionID = $collectionid";
mysql_query($update) or die(mysql_error());
$anchor = "taxa";
}
else if ($action == "add_common_names")
{
$before_common_names = array();
$query = "SELECT CommonName, Strength, LanguageID FROM CollectionCommonNameCoverage WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$before_strength = $row[1];
if ($before_strength == 0)
$before_strength = "";
$before_common_names[] = $row[0].$before_strength.$row[2];
}
if ($selected_common_name != "" && !in_array($selected_common_name.$strength.$selected_language_id, $before_common_names))
{
$update = "INSERT INTO CollectionCommonNameCoverage (CollectionID, CommonName, Strength, LanguageID) VALUES
($collectionid, '$selected_common_name', '$strength', '$selected_language_id')";
mysql_query($update) or die(mysql_error());
}
$anchor = "common_names";
}
else if ($action == "remove_common_names")
{
$update = "DELETE FROM CollectionCommonNameCoverage WHERE CommonName = '$selected_common_name' AND Strength = '$strength'
AND LanguageID = '$selected_language_id' AND CollectionID = $collectionid";
mysql_query($update) or die(mysql_error());
$anchor = "common_names";
}
else if ($action == "add_geo")
{
$before_geo = array();
$query = "SELECT AreaOrLocation, Strength, LanguageID FROM CollectionGeospatialCoverage WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$before_strength = $row[1];
if ($before_strength == 0)
$before_strength = "";
$before_geo[] = $row[0].$before_strength.$row[2];
}
if ($selected_geo_coverage != "" && !in_array($selected_geo_coverage.$strength.$selected_language_id, $before_geo))
{
$update = "INSERT INTO CollectionGeospatialCoverage (CollectionID, AreaOrLocation, Strength, LanguageID) VALUES
($collectionid, '$selected_geo_coverage', '$strength', '$selected_language_id')";
mysql_query($update) or die(mysql_error());
}
$anchor = "geo";
}
else if ($action == "remove_geo")
{
$update = "DELETE FROM CollectionGeospatialCoverage WHERE AreaOrLocation = '$selected_geo_coverage' AND Strength = '$strength'
AND LanguageID = '$selected_language_id' AND CollectionID = $collectionid";
mysql_query($update) or die(mysql_error());
$anchor = "geo";
}
else if ($action == "add_time")
{
$before_time = array();
$query = "SELECT LivingTimePeriod, Strength, LanguageID FROM CollectionLivingTimePeriodCoverage WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$before_strength = $row[1];
if ($before_strength == 0)
$before_strength = "";
$before_time[] = $row[0].$before_strength.$row[2];
}
if ($selected_time_period != "" && !in_array($selected_time_period.$strength.$selected_language_id, $before_time))
{
$update = "INSERT INTO CollectionLivingTimePeriodCoverage (CollectionID, LivingTimePeriod, Strength, LanguageID) VALUES
($collectionid, '$selected_time_period', '$strength', '$selected_language_id')";
mysql_query($update) or die(mysql_error());
}
$anchor = "time";
}
else if ($action == "remove_time")
{
$update = "DELETE FROM CollectionLivingTimePeriodCoverage WHERE LivingTimePeriod = '$selected_time_period' AND Strength = '$strength'
AND LanguageID = '$selected_language_id' AND CollectionID = $collectionid";
mysql_query($update) or die(mysql_error());
$anchor = "time";
}
else if ($action == "add_preservation")
{
$before_preservation = array();
$query = "SELECT SpecimenPreservationMethodID FROM CollectionSpecimenPreservationMethods WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_preservation[] = $row[0];
if ($selected_preservation_method != "" && !in_array($selected_preservation_method, $before_preservation))
{
$update = "INSERT INTO CollectionSpecimenPreservationMethods (CollectionID, SpecimenPreservationMethodID) VALUES ($collectionid, $selected_preservation_method)";
mysql_query($update) or die(mysql_error());
}
$anchor = "preservation";
}
else if ($action == "remove_preservation")
{
$update = "DELETE FROM CollectionSpecimenPreservationMethods WHERE SpecimenPreservationMethodID = $selected_preservation_method AND CollectionID = $collectionid";
mysql_query($update) or die(mysql_error());
$anchor = "preservation";
}
else if ($action == "add_media")
{
$before_media = array();
$query = "SELECT Medium FROM CollectionMedia WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_media[] = $row[0];
if ($selected_medium != "" && !in_array($selected_medium, $before_media))
{
$update = "INSERT INTO CollectionMedia (CollectionID, Medium) VALUES ($collectionid, '$selected_medium')";
mysql_query($update) or die(mysql_error());
}
$anchor = "media";
}
else if ($action == "remove_media")
{
$update = "DELETE FROM CollectionMedia WHERE CollectionID = $collectionid AND Medium = '$selected_medium'";
mysql_query($update) or die(mysql_error());
$anchor = "media";
}
else if ($action == "add_format")
{
$before_formats = array();
$query = "SELECT FileFormat FROM CollectionFileFormats WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_formats[] = $row[0];
if ($selected_format != "" && !in_array($selected_format, $before_formats))
{
$update = "INSERT INTO CollectionFileFormats (CollectionID, FileFormat) VALUES ($collectionid, '$selected_format')";
mysql_query($update) or die(mysql_error());
}
$anchor = "format";
}
else if ($action == "remove_format")
{
$update = "DELETE FROM CollectionFileFormats WHERE CollectionID = $collectionid AND FileFormat = '$selected_format'";
mysql_query($update) or die(mysql_error());
$anchor = "format";
}
else if ($action == "add_item")
{
$before_items = array();
$query = "SELECT ItemLevelAccess, ItemLevelAccessDescription FROM CollectionItemLevelAccess WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_items[] = $row[0].$row[1];
if ($selected_item != "" && !in_array($selected_item.$item_description, $before_items))
{
$update = "INSERT INTO CollectionItemLevelAccess (CollectionID, ItemLevelAccess, ItemLevelAccessDescription) VALUES ($collectionid, '$selected_item', '$item_description')";
mysql_query($update) or die(mysql_error());
}
$anchor = "item";
}
else if ($action == "remove_item")
{
$update = "DELETE FROM CollectionItemLevelAccess WHERE ItemLevelAccess = '$selected_item' AND ItemLevelAccessDescription = '$item_description' AND CollectionID = $collectionid";
mysql_query($update) or die(mysql_error());
$anchor = "item";
}
else if ($action == "add_relation")
{
$before_relations = array();
$query = "SELECT Resource FROM CollectionRelations WHERE CollectionID = $collectionid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
$before_relations[] = $row[0];
if ($selected_relation != "" && !in_array($selected_relation, $before_relations))
{
$update = "INSERT INTO CollectionRelations (CollectionID, Resource) VALUES ($collectionid, '$selected_relation')";
mysql_query($update) or die(mysql_error());
}
$anchor = "relation";
}
else if ($action == "remove_relation")
{
$update = "DELETE FROM CollectionRelations WHERE CollectionID = $collectionid AND Resource = '$selected_relation'";
mysql_query($update) or die(mysql_error());
$anchor = "relation";
}
else if ($action == "add_person")
{
if ($selected_curator != "" && !in_array($selected_curator, $before_curators))
{
$update = "INSERT INTO PersonToCollections (CollectionID, PersonID) VALUES ($collectionid, '$selected_curator')";
mysql_query($update) or die(mysql_error());
}
$anchor = "person";
}
else if ($action == "remove_person")
{
if (count($before_curators) > 1)
{
$update = "DELETE FROM PersonToCollections WHERE CollectionID = $collectionid AND PersonID = '$selected_curator'";
mysql_query($update) or die(mysql_error());
$curator_error = "";
}
else
$curator_error = "<tr><td></td><td class=\"error\" colspan=\"2\">At least one person should be selected!</td></tr>\n";
$anchor = "person";
}
else if ($action == "private_collector")
{
if (!get_magic_quotes_gpc())
{
foreach ($private_collector_variables as $insert_variable)
$$insert_variable = addslashes($$insert_variable);
}
if ($update_givenname == "" || $update_familyname == "" || ($update_personstreet == "" && $update_personpostbox == "") ||
$update_personzip == "" || $update_persontown == "" || $update_country_id == "" || $update_personemail == "")
$missing_data = "y";
if ($missing_data != "y")
{
$query = "UPDATE Persons SET
Modified = '$currentdate',
ModifierID = $userid,
GivenNames = '$update_givenname',
Prefix = '$update_prefix',
Suffix = '$update_suffix',
Title = '$update_title',
OtherNames = '$update_additionalnames',
FamilyName = '$update_familyname'
WHERE ID = $personid";
mysql_query($query) or die(mysql_error());
$query = "UPDATE PrivateCollectorAddresses SET
Street = '$update_personstreet',
Extadd = '$update_personaddressext',
Pcode = '$update_personzip',
Locality = '$update_persontown',
Region = '$update_personregion',
CountryID = '$update_country_id',
Telephone = '$update_persontelephone',
Fax = '$update_personfax',
Email = '$update_personemail',
WebsiteURL = '$update_personwebsiteurl'
WHERE PersonID = $personid";
mysql_query($query) or die(mysql_error());
}
$anchor = "private_collector";
}
$update = "UPDATE Collections SET Modified = '$currentdate', ModifierID = $userid WHERE ID = $collectionid";
mysql_query($update) or die(mysql_error());
erase ($collection_variables);
unset($_SESSION["selected_extents"]);
$selected_extents = array();
?>