<?php
/*
script: includes/config.inc.php
purpose: includes utility classes and initializes all stuff used by the other scripts.
				This script is included at the beginning of all the other scripts.
copyright: copyright 2004 Php Image Host. All Rights Reserved. You may modify this file for use on your
					site running a licenced copy of the Php Image Host scripts.
					You must not distribute this file or derivations of it.
Nullified By CrAcKlOvE

*/

// turn full error reporting on / off

error_reporting(E_ALL);

// start sessions

session_start();

// include the database initialization stuff

require_once(dirname(__FILE__).'/db.inc.php');

// include the ace utility class

require_once(dirname(__FILE__).'/../classes/ace.class.php');

$ace =& new ace($conn);

// load all configuration settings

$config = $ace->loadsettings();

if( $config == 0 || $config->installed == 0 ){
	header('Location: install/index.php');
	exit();
}

// include the pagecontent class and initialize it with all the variables that can be displayed
// in the templates.
// this is used by most scripts on the site to display page content which can be edited from the
// page content page in the site admin area.

require_once(dirname(__FILE__).'/../classes/pagecontent.class.php');

$pagecontent =& new pagecontent($ace);

require_once(dirname(__FILE__).'/../classes/users.class.php');
$users =& new users($ace);

$users->resetbandwidth();
$users->checkbandwidth();

// include the code that checks if users are logged in and processes login / logout attempts.

require_once(dirname(__FILE__).'/login.inc.php');

// more initialization stuff

$sql = "SELECT * FROM account_types  ";
$res = $ace->query($sql, 'Get Account Types');

if( mysql_num_rows($res)<2 ) die("Error retrieving account details from database.");

$plans = array();
while( $p = mysql_fetch_object($res) ) $plans[$p->type_type] = $p;

$config->price_1 = $plans['paid']->cost_1;
$config->price_3 = $plans['paid']->cost_3;
$config->price_6 = $plans['paid']->cost_6;
$config->price_12 = $plans['paid']->cost_12;

$vars = array();
foreach( $config as $n=>$v ){
	if( !is_array($v) ) $vars[$n] = $v;
}
foreach( $plans as $type=>$p ){
	foreach( $p as $n=>$v ){
		$vars[$type.'_'.$n] = $v;
		if( in_array($n, array('bandwidth', 'storage', 'max_images') ) && $v == 0 )$vars[$type.'_'.$n] = 'unlimited';
	}
}

$uptype = $loggedin ? $user->account_type : 'free';
foreach( $plans[$uptype] as $n=>$v ){
	$vars['user_'.$n] = $v;
}
$vars['username'] = $vars['email'] = '';
$vars['paid_account_name'] = $plans['paid']->type_name;
$vars['paid_account_cost'] = number_format($plans['paid']->cost_1,2);
$vars['free_account_name'] = $plans['free']->type_name;
if( $user != 0 ){
	$vars['username'] = $user->username;
	$vars['email'] = $user->email;
	foreach( $user as $n=>$v ){
		if( !is_array($v) && !isset($vars['user_'.$n])){
			$vars['user_'.$n] = $v;
		}
		if( in_array($n, array('bandwidth', 'storage', 'max_images') ) && $v == 0 ){
			$vars['user_'.$n] = 'unlimited';
		}
	}
}
$pagecontent->setvars($vars);

?>
