<?php
class General
{
	function notification($type,$message)
	{
	return '<div class="notification '.$type.'">'.$message.'</div>';
	}
	
	function portfolio_categories()
	{
	$sql = "SELECT * FROM portfolio_categories ORDER BY category_id ASC";
	$query = mysql_query($sql);
	$isthere = mysql_num_rows($query);
	if ($isthere == 0) {
	return 0;
	} else {
	while ($row = mysql_fetch_array($query)) {
		$rows[] = $row;
	}
	return $rows;
	}
	}
	
	function portfolio_category($id)
	{
	$sql = "SELECT * FROM portfolio_categories WHERE category_id='$id' LIMIT 1";
	$query = mysql_query($sql);
	$row = mysql_fetch_array($query);
	return $row;
	}
	
	function skills()
	{
	$sql = "SELECT * FROM skills ORDER BY skill_id ASC";
	$query = mysql_query($sql);
	$isthere = mysql_num_rows($query);
	if ($isthere == 0) {
	return 0;
	} else {
	while ($row = mysql_fetch_array($query)) {
		$rows[] = $row;
	}
	return $rows;
	}
	}
	
	function skill($id)
	{
	$sql = "SELECT * FROM skills WHERE skill_id='$id' LIMIT 1";
	$query = mysql_query($sql);
	$row = mysql_fetch_array($query);
	return $row;
	}
	
	function portfolio_item($id)
	{
	$sql = "SELECT * FROM portfolio WHERE work_id='$id' LIMIT 1";
	$query = mysql_query($sql);
	$row = mysql_fetch_array($query);
	return $row;
	}
	
	function slider_item($id)
	{
	$sql = "SELECT * FROM slider WHERE slider_id='$id' LIMIT 1";
	$query = mysql_query($sql);
	$row = mysql_fetch_array($query);
	return $row;
	}
	
	function unreaded_messages_number()
	{
	$sql = "SELECT message_readed FROM messages WHERE message_readed='0'";
	$query = mysql_query($sql);
	$number = mysql_num_rows($query);
	return $number;
	}
	
	function get_message($id)
	{
	$sql = "SELECT * FROM messages WHERE message_id='$id'";
	$query = mysql_query($sql);
	$row = mysql_fetch_array($query);
	return $row;
	}
	
	function period($day,$month,$year,$number)
	{
		$datetime = $number*86400;
		$thetime = time()-$datetime;
		$sql = "SELECT datetime,day,month,year FROM analytics WHERE datetime > $thetime GROUP BY day ORDER BY month DESC, day DESC";
		$query = mysql_query($sql);
			while ($row = mysql_fetch_array($query)) {
			$rows[] = $row;
			}
		return $rows;
	}
		
	function daily_visits($day,$month,$year)
	{
		$sql = "SELECT COUNT(*) AS total,day,month,year FROM analytics WHERE day='$day' AND month='$month' AND year='$year' GROUP BY day";
		$query = mysql_query($sql);
		$row = mysql_fetch_array($query);
		return $row['total'];
	}
	
	function daily_visitors($day,$month,$year)
	{
		$sql = "SELECT day,month,year,ip FROM analytics WHERE day='$day' AND month='$month' AND year='$year' GROUP BY ip";
		$query = mysql_query($sql);
		$number = mysql_num_rows($query);
		return $number;
	}
	
	
}
?>