Location: PHPKode > projects > Kwalbum > kwalbum/include/funcChangeVisibility.php
<?php
// 2.0
function ChangeVisibility($id, $newVis, $echo = true)
{
	global $DB, $P, $errorMsg;

	if (0 > $newVis or 3 < $newVis)
		$badVis = true;
	else
		$badVis = false;

	$query = 'SELECT ItemIsHidden, ItemUserIdFk FROM ' . ITEM_TABLE .
	" WHERE ItemId='$id'" .
	" LIMIT 1";
	$result = $DB->Query($query);
	if (0 == $result->num_rows)
	{
		if (TEST_MODE)
			echo '<p class="error">'.pathinfo(__FILE__, PATHINFO_FILENAME).': Item ID ('.$id.') was not found in the DB.</p>';
		else if ($echo)
			echo $errorMsg;
		return;
	}
	$row = $result->fetch_array();
	if (!USER_IS_ADMIN and (USER_ID != $row[1] or 3 == $newVis))
	{
		if (TEST_MODE)
			echo '<p class="error">Invalid Permissions</p>';
		else if ($echo)
			echo $errorMsg;
		return;
	}

	$oldVis = $row[0];
	if ($badVis)
		$newVis = $oldVis;

	if ($oldVis != $newVis)
	{
		$DB->UpdateSingle(ITEM_TABLE, 'ItemIsHidden', "'$newVis'", "ItemId='$id'");
	}
	if ($echo)
	{
		switch ($newVis)
		{
			case 0:
				echo 'Public'; break;
			case 1:
				echo 'Members Only'; break;
			case 2:
				echo 'Privileged Only'; break;
			case 3:
				echo 'Admin Only'; break;
			default:
				echo 'unknown level ('.$newVis.')';
		}
	}
}
?>
Return current item: Kwalbum