<?php
//Timing for the page
//echo $_SERVER['HTTP_REFERER'];
error_reporting(E_ERROR | E_PARSE);

//error_reporting(E_ALL);

$logitus = fopen("log/serverlog.log","a+");
$time = microtime(true);
ini_set('session.gc_probability',2);
include('inc/global_funcs.php');
//Setup to show online users, so start a session first
session_save_path("sessions");
session_start();

//fwrite($logitus,print_r($_SERVER,1));
//fwrite($logitus,print_r($_SESSION,1));
fclose($logitus);
if(isset($_GET['category']) && is_numeric($_GET['category'])) {
	$cat = 1;
	if($_GET['category'] == 10) $cat = 10;
	if($_GET['category'] == 11) $cat = 11;
	if($_GET['category'] == 1) $cat = 1;
	if($_GET['category'] == 2) $cat = 2;
	if($_GET['category'] == 3) $cat = 3;
	if($_GET['category'] == 4) $cat = 4;
	setcookie("category",$cat,time()+28800,"/",".ircpics.com");
}
	

if(!isset($_COOKIE['category']) || !is_numeric($_COOKIE['category'])) setcookie("category",1,time()+28800,"/",".ircpics.com");

//Set max idle time
define("MAX_IDLE_TIME",5);
$_SESSION['time'] = microtime(true);

// Defining base directories, change APPDIR to point to physical location remember to add trailing /
define ('APPDIR', '/var/www/html/');
define ('SMARTY_CORE_DIR', APPDIR . 'smarty/internals/');

// Setting up Smarty
include(APPDIR . 'smarty/Smarty.class.php');
$smarty = new Smarty;

$smarty->template_dir = APPDIR . 'template';
$smarty->compile_dir = APPDIR . 'smarty/templates_c';
$smarty->cache_dir = APPDIR . 'smarty/cache';
$smarty->config_dir = APPDIR . 'smarty/configs';
// Start doing things

include('inc/mysql.class.inc.php');
$country = $dbcon->get_country($_SERVER['REMOTE_ADDR']);
//ini_set('display_errors', 1);

//if($_SESSION[ccode2] == "RU") exit;

if($_GET['showpix'] && is_numeric($_GET['showpix'])) {
	$picshowing = "
	<script type=\"text/javascript\">
	function init() {
		if (arguments.callee.done) return;
		arguments.callee.done = true;
		showbox(" . $_GET['showpix'] . ");
	};

	/* for Mozilla */
	if (document.addEventListener) {
		document.addEventListener(\"DOMContentLoaded\", init, false);
	}

	/* for Internet Explorer */
	/*@cc_on @*/
	/*@if (@_win32)
	/*document.write(\"<script defer src=ie_onload.js><\"+\"/script>\");*/
	/*@end @*/

	/* for other browsers */
	window.onload = init;
	</script>";
	$smarty->assign('showpic_js',$picshowing);
	$_SESSION['showpix'] = $_GET['showpix'];
}

switch ($_GET['p']) {
	case "showpix": 
		$data = file_get_contents("template/showpic.tpl");
		$smarty->assign('content',$data);
		break;
	case "today":
		if(!$_GET['index']) {
			$index = 1;
		}
		else {
			if(is_numeric($_GET['index'])) $index = $_GET['index'];
			
		}
		$smarty->assign('content',$dbcon->Today_div($index));
		break;
	case "random":		
		$smarty->assign('content',$dbcon->Random_div());
		break;
	case "browse":
		if(!$_GET['index']) {
			$index = 1;
		}
		else {
			if(is_numeric($_GET['index'])) $index = $_GET['index'];
		}
		$smarty->assign('content',$dbcon->Browse_div($index));
		break;
	case "best":
		$data = file_get_contents("template/disclaimer.tpl");
		$smarty->assign('content',$data);
		break;
	case "worst":
		$data = file_get_contents("template/disclaimer.tpl");
		$smarty->assign('content',$data);
		break;
	case "disc":
		$data = file_get_contents("template/disclaimer.tpl");
		$smarty->assign('content',$data);
		break;
	case "faq":
		$data = file_get_contents("template/disclaimer.tpl");
		$smarty->assign('content',$data);
		break;
	case "howto":
		$data = file_get_contents("template/howto.tpl");
		$smarty->assign('content',$data);
		break;
	case "changes":
		$data = file_get_contents("template/updates.tpl");
		$smarty->assign('content',$data);
		break;
	case "forsale";
		$data = file_get_contents("template/forsale.tpl");
		$smarty->assign('content',$data);
		break;
	default:
		$data = file_get_contents("template/disclaimer.tpl");
		$smarty->assign('content',$data);
}

// Print out page
$smarty->assign('menu',getMenu($_GET['p']));
$smarty->assign('loggers',$dbcon->logging_users());
$smarty->assign('channels',$dbcon->logging_channels());
$smarty->assign('viewedamount',$dbcon->sum_viewed());
$smarty->assign('addedtoday',$dbcon->added_today());
$smarty->assign('loggedusers',getOnlineUsers());
$smarty->assign('country',$country);
$smarty->assign('time',round((microtime(true) - $time), 4));
$ads = $dbcon->get_ads();
$smarty->assign('topad', $ads['top']);
$smarty->assign('bottomad', $ads['bottom']);

//$smarty->assign('leftad', $ads['left']);
//$smarty->assign('leftad', "");
//$smarty->clear_cache('index.tpl');
$smarty->display('index.tpl');

//mysqli_close();


?>


