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

function ChangeContributor($id, $newUserId, $echo = true)
{
	global $DB, $P, $errorMsg;

	if (!USER_IS_ADMIN)
	{
		if (TEST_MODE)
			echo '<p class="error">Invalid Permissions</p>';
		elseif ($echo)
			echo $errorMsg;
		return;
	}

	$query = 'SELECT 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">Item ID ('.$id.') was not found in the DB.</p>';
		elseif ($echo)
			echo $errorMsg;
		return;
	}
	$row = $result->fetch_array();
	$oldUserId = $row[0];

	if (0 < $newUserId)
	{
		$query = 'SELECT UserTitle FROM '.USER_TABLE.' WHERE UserId='.$newUserId;
		$result = $DB->Query($query);
		if (0 == $result->num_rows)
		{
			if (TEST_MODE)
				echo '<p class="error">User ID ('.$newUserId.') was not found in the DB.</p>';
			elseif ($echo)
				echo $errorMsg;
			return;
		}
		$row = $result->fetch_array();
		$newUserTitle = $row[0];
	}
	else
	{
		$newUserId = 0;
		$newUserTitle = 'unknown';
	}

	if ($oldUserId != $newUserId)
		$DB->UpdateSingle(ITEM_TABLE, 'ItemUserIdFk', "'$newUserId'", "ItemId='$id'");

	if ($echo)
		echo $newUserTitle;
}
?>
Return current item: Kwalbum