Location: PHPKode > projects > Kwalbum > kwalbum/include/funcDeleteItem.php
<?php
// 2.0

function DeleteItem($itemId, $echo = true)
{
	global $DB, $errorMsg;

	$query = 'SELECT ItemDate, ItemUserIdFk, ItemLocationIdFk FROM ' . ITEM_TABLE .
	" WHERE ItemId='$itemId'" .
	" LIMIT 1";
	$result = $DB->Query($query);
	if (0 == $result->num_rows)
	{
		if (TEST_MODE)
			echo '<p class="error">Item ID ('.$itemId.') was not found in the DB.</p>';
		elseif ($echo)
			echo $errorMsg;
		return;
	}
	$row = $result->fetch_array();
	if (USER_ID != $row[1] and !USER_IS_ADMIN)
	{
		if (TEST_MODE)
			echo '<p class="error">Invalid Permissions</p>';
		else if ($echo)
			echo $errorMsg;
		return;
	}
	$old = explode('-', $row[0]);
	$year = $old[0];
	$month = $old[1];
	$locationId = $row[2];
	// date
	$DB->UpdateSingle(DATE_TABLE, 'DateCount', 'DateCount-1', "DateYear='$year' AND DateMonth='$month'");
	// location
	$DB->UpdateSingle(LOCATION_TABLE, 'LocationCount', 'LocationCount-1', "LocationId=$locationId");
	// tags
	$DB->UpdateSingle(TAG_TABLE, 'TagCount', 'TagCount-1', "TagId IN " .
			"(SELECT TagIdFk FROM " . TAG_MAP_TABLE .
			" WHERE ItemIdFk=$itemId)");
	//$query = 'DELETE FROM ' . TAG_MAP_TABLE .
	//		" WHERE ItemIdFk=$itemId";
	//$DB->query($query);
	// people
	$DB->UpdateSingle(PEOPLE_TABLE, 'PeopleCount', 'PeopleCount-1', "PeopleId IN " .
			"(SELECT PeopleIdFk FROM " . PEOPLE_MAP_TABLE .
			" WHERE ItemIdFk=$itemId)");
	//$query = 'DELETE FROM ' . PEOPLE_MAP_TABLE .
	//		" WHERE ItemIdFk=$itemId";
	//$DB->query($query);
	// visibility
	$DB->UpdateSingle(ITEM_TABLE, 'ItemIsHidden', "'5'", "ItemId='$itemId'");
	if ($echo)
		echo 'Item Deleted';
}
Return current item: Kwalbum