<?php
class AdminFunctions{

	var $database;
	
	function AdminFunctions(){
		require_once('Database.php');
		$database =& DatabaseConnect::getInstance();
		$database->query("SET CHARACTER SET utf8");
	}
	
	function &getInstance(){
		static $instance;
        
		if (!is_object($instance))
			$instance = new AdminFunctions();
        
		return $instance;
	}
	
	
	
	function getUserRoles($role){
		switch($role){
			case '0':
				return 'Administrator';
				break;
			case '1':
				return 'Editor';
				break;
			case '2':
				return 'Author';
				break;
			case '3':	
				return 'Subscriber';
				break;
			default:
				return 'Subscriber';
				break;
		}
	}
	
	function dateConversion($datetime){
		$dateArray = explode('-', (substr($datetime, 0, 10)));
	
		$year = $dateArray[0];
			
		switch($dateArray[1]){
			case '01':
				$month = 'januar';
			break;
			case '02':
				$month = 'februar';
			break;
			case '03':
				$month = 'mart';
			break;
			case '04':
				$month = 'april';
			break;
			case '05':
				$month = 'maj';
			break;
			case '06':
				$month = 'jun';
			break;
			case '07':
				$month = 'jul';
			break;
			case '08':
				$month = 'avgust';
			break;
			case '09':
				$month = 'septembar';
			break;
			case '10':
				$month = 'oktobar';
			break;
			case '11':
				$month = 'novembar';
			break;
			case '12':
				$month = 'decembar';
			break;
		}
		
		$day = $dateArray[2];
		
		$date = $day.'. '.$month.' '.$year.'.';
		
		
		
		return $date;
	}
	
	function currentDay($day, $week){
			
		$today = strtolower(date("l"));
		
		switch($today) {
		
			case 'monday':
			
				switch($day) {
					
					case('monday'):
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week, date("Y")));
					
					break;
					
					case 'tuesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 1, date("Y")));
			
					break;
			
					case 'wednesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 2, date("Y")));
			
					break;
			
					case 'thursday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 3, date("Y")));
			
					break;
			
					case 'friday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 4, date("Y")));
			
					break;
			
					case 'saturday':
					
					$result = date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 5, date("Y"))).'/'.date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 6, date("Y"))).'.'.date("m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 6, date("Y")));
			
					break;		
							
				}
			
			break;
			
			case 'tuesday':
			
			switch($day) {
					
					case('monday'):
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 1, date("Y")));
					
					break;
					
					case 'tuesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week, date("Y")));
			
					break;
			
					case 'wednesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 1, date("Y")));
			
					break;
			
					case 'thursday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 2, date("Y")));
			
					break;
			
					case 'friday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 3, date("Y")));
			
					break;
			
					case 'saturday':
					
					$result = date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 4, date("Y"))).'/'.date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 5, date("Y"))).'.'.date("m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 5, date("Y")));
			
					break;		
							
				}
			
			break;
			
			case 'wednesday':
			
			switch($day) {
					
					case('monday'):
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 2, date("Y")));
					
					break;
					
					case 'tuesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 1, date("Y")));
			
					break;
			
					case 'wednesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week, date("Y")));
			
					break;
			
					case 'thursday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 1, date("Y")));
			
					break;
			
					case 'friday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 2, date("Y")));
			
					break;
			
					case 'saturday':
					
					$result = date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 3, date("Y"))).'/'.date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 4, date("Y"))).'.'.date("m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 4, date("Y")));
			
					break;		
							
				}
			
			break;
			
			case 'thursday':
			
			switch($day) {
					
					case('monday'):
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 3, date("Y")));
					
					break;
					
					case 'tuesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 2, date("Y")));
			
					break;
			
					case 'wednesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 1, date("Y")));
			
					break;
			
					case 'thursday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week, date("Y")));
			
					break;
			
					case 'friday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 1, date("Y")));
			
					break;
			
					case 'saturday':
					
					$result = date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 2, date("Y"))).'/'.date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 3, date("Y"))).'.'.date("m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 2, date("Y")));
			
					break;		
							
				}
			
			break;
			
			case 'friday':
			
			switch($day) {
					
					case('monday'):
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 4, date("Y")));
					
					break;
					
					case 'tuesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 3, date("Y")));
			
					break;
			
					case 'wednesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 2, date("Y")));
			
					break;
			
					case 'thursday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 1, date("Y")));
			
					break;
			
					case 'friday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week, date("Y")));
			
					break;
			
					case 'saturday':
					
					$result = date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 1, date("Y"))).'/'.date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 2, date("Y"))).'.'.date("m.Y", mktime(0, 0, 0, date("m"), date("d") + $week + 1, date("Y")));
			
					break;		
							
				}
			
			break;
			
			case 'saturday':
			
			switch($day) {
					
					case('monday'):
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 5, date("Y")));
					
					break;
					
					case 'tuesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 4, date("Y")));
			
					break;
			
					case 'wednesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 3, date("Y")));
			
					break;
			
					case 'thursday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 2, date("Y")));
			
					break;
			
					case 'friday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 1, date("Y")));
			
					break;
			
					case 'saturday':
					
					$result = date("d", mktime(0, 0, 0, date("m"), date("d") + $week, date("Y"))).'/'.date("d", mktime(0, 0, 0, date("m"), date("d") + $week + 1, date("Y"))).'.'.date("m.Y", mktime(0, 0, 0, date("m"), date("d") + $week, date("Y")));
			
					break;		
							
				}
			
			break;
			
			case 'sunday':
			
			switch($day) {
					
					case('monday'):
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 6, date("Y")));
					
					break;
					
					case 'tuesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 5, date("Y")));
			
					break;
			
					case 'wednesday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 4, date("Y")));
			
					break;
			
					case 'thursday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 3, date("Y")));
			
					break;
			
					case 'friday':
					
					$result = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 2, date("Y")));
			
					break;
			
					case 'saturday':
					
					$result = date("d", mktime(0, 0, 0, date("m"), date("d") + $week - 1, date("Y"))).'/'.date("d", mktime(0, 0, 0, date("m"), date("d") + $week, date("Y"))).'.'.date("m.Y", mktime(0, 0, 0, date("m"), date("d") + $week - 1, date("Y")));
			
					break;		
							
				}
			
			break;
			
			
			
		}
		
		return $result;
		
	}
	
	function showDateTime($datetime){
		$explode = explode(" ", $datetime);
		
		$date = explode("-", $explode[0]);
		$time = substr($explode[1], 0, 5);
		
		$year = $date[0];
			
		switch($date[1]){
			case '01':
				$month = 'januar';
			break;
			case '02':
				$month = 'februar';
			break;
			case '03':
				$month = 'mart';
			break;
			case '04':
				$month = 'april';
			break;
			case '05':
				$month = 'maj';
			break;
			case '06':
				$month = 'jun';
			break;
			case '07':
				$month = 'jul';
			break;
			case '08':
				$month = 'avgust';
			break;
			case '09':
				$month = 'septembar';
			break;
			case '10':
				$month = 'oktobar';
			break;
			case '11':
				$month = 'novembar';
			break;
			case '12':
				$month = 'decembar';
			break;
		}
		
		$day = $date[2];
		
		$date = $day.'. '.$month.' '.$year.'. ';
		
		return $date." ".$time;
	}
	
}
?>