<?php

require_once 'DatabaseConnector.php';

class Tracking extends DatabaseConnector
{
	function updateTracking($userID, $videoID)
	{
		$link = $this->getConnection();

		$count = 1;
		
		$query = sprintf("SELECT count FROM tracking WHERE userID=%d AND videoID=%d", $userID, $videoID);
		$result = mysql_query($query, $link);
		
		if(mysql_num_rows($result) > 0)
		{
			$row = mysql_fetch_row($result);
			
			$count = $row[0];
			$count++;
			
			$queryUpdate = sprintf("UPDATE tracking SET count=%d WHERE userID=%d AND videoID=%d", $count, $userID, $videoID);
			mysql_query($queryUpdate, $link);
			
			return '';
		}
		else
		{
			$queryInsert = sprintf("INSERT INTO tracking (userId, videoId, count) VALUES (%d, %d, %d)", $userID, $videoID, $count);
			mysql_query($queryInsert, $link);
			
			return '';
		}
		
		return '';
	}
}

?>
