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

function ChangeTime($id, $newTime, $echo = true)
{
	global $DB, $P, $errorMsg;
	$newTime = trim($newTime);
	$new = explode(':', $newTime);
	$newHour = (int)$new[0];
	$newMin = (int)$new[1];
	$newSec = (int)$new[2];
	$newNewTime = "$newHour:$newMin:$newSec";

	if ('0:0:0' == $newNewTime and '' != $newTime and '00:00:00' != $newTime)
		$badTime = true;
	else
	{
		$badTime = false;
		$newTime = $newNewTime;
	}

	$query = 'SELECT ItemDate, ItemTime, ItemOrderBy, 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>';
		else if ($echo)
			echo $errorMsg;
		return;
	}
	$row = $result->fetch_array();
	if (USER_ID != $row[3] and !USER_IS_ADMIN)
	{
		if (TEST_MODE)
			echo '<p class="error">Invalid Permissions</p>';
		else if ($echo)
			echo $errorMsg;
		return;
	}

	$oldDate = $row[0];
	$oldTime = $row[1];
	$oldOrderBy = $row[2];
	if ($badTime)
		$newTime = $oldTime;

	if ($oldTime != $newTime)
	{
		if ($oldOrderBy == "$oldDate $oldTime")
			$DB->UpdateSingle(ITEM_TABLE, 'ItemOrderBy', "'$oldDate $newTime'", "ItemId='$id'");
		$DB->UpdateSingle(ITEM_TABLE, 'ItemTime', "'$newTime'", "ItemId='$id'");
	}
	if ($echo)
		echo $newTime;
}
?>
Return current item: Kwalbum