Location: PHPKode > projects > TraffStats > TraffStats-0.11.3/traffstats.php
<?php
/*
 * Project:    traffstats
 * Author:     Klaus Zerwes
 * (c) 2006 - 2007 Klaus Zerwes zero-sys.net
 * 
 * $Id: traffstats.php,v 1.13 2008-03-17 18:21:48 zerwes Exp $
 */

// basedir
define ( "ZEROSYS__PROJECTROOT", dirname(__FILE__) );


// ALL OTHER CONFIGPARAMS ARE SET INSIDE THIS FILE !
require_once(ZEROSYS__PROJECTROOT."/config/config.php");



// start with the debug-obj
require_once(ZEROSYS__BASESYSROOT."debug.class.php");
$debug = new debug();
$debug->msg ( "started the debug_obj ... ".(int)ZEROSYS__DEBUG );
// debug superglobals
if ( count ( $_POST ) > 0 ) $debug->debugarray ( &$_POST, 'POST' );
if ( count ( $_GET ) > 0 ) $debug->debugarray ( &$_GET, 'GET' );
if ( count ( $_FILES ) > 0 ) $debug->debugarray ( &$_FILES, 'FILES' );
$debug->debugarray ( &$_SERVER, '_SERVER' );


// timing reading of files
$debug->mark ( "start reading of files" );
require_once(ZEROSYS__BASESYSROOT."parse_gp.inc.php");
require_once(ZEROSYS__BASESYSROOT."includeallclasses.inc.php");
require_once(ZEROSYS__CLASSROOT."includeallclasses.inc.php");
$debug->mark ( "done reading of files" );




// start session
session_name("SESSION".ZEROSYS__PROJECTNAME);
$sessionname = session_name();
$cookiepath = dirname($_SERVER["REQUEST_URI"]);
if(substr($cookiepath, -1) != "/") {
	$cookiepath .= "/";
}
session_set_cookie_params (0, $cookiepath);
$debug->msg( "start SESSION ... $sessionname : $cookiepath" );
session_start();
$debug->debugarray ( &$_SESSION, "SESSION" );




// time init basic objects
$debug->mark ( "start init basic objects" );
$debug->filestart("db-load");
$db = new mysqldatabase();
// db struct // in production-state, simply use structsession
if(ZEROSYS__DEBUG) {
	$db->loadtables();
	$db->loadstruct();
	//unset($_SESSION["db"]);
} else {
	$db->structsession();
}
$debug->fileend("db-load");
$debug->filestart("basesys-load");
$actionstack = new actions();
$html = new xhtml(true);
$auth = new auth();
$language = new languagefile();
$debug->fileend("basesys-load");
$debug->mark ( "done init basic objects" );





// login stuff
//$debug->msg( "start parsing: ".ZEROSYS__BASESYSROOT."login.inc.php" );
require_once(ZEROSYS__BASESYSROOT."login.inc.php");
//$debug->msg( "finished parsing of: ".ZEROSYS__BASESYSROOT."login.inc.php" );




if($userobj === NULL){
	$debug->msg( "userobj: NULL" );
	$actionstack->set_displayaction("login");
	if(!$auth->login_allowed()){
		$actionstack->set_displayaction("loginlocked");
	}
}else{
	$debug->msg( "userobj set" );
	// test if userob is admin
	if(!is_a($userobj, "admin")) {
		$actionstack->set_displayaction("login");
		$action_msg = $language->translate("wronguserobjectinsession");
	}
}





// save switch
$action_msg = ""; // saves messages
$save_act = $actionstack->get_saveaction( TRUE );
if(strlen($save_act) > 0){
	$debug->msg( "start save-switch w/ action set to:'$save_act'" );
	$includefile = $actionstack->getincludefile("save",$save_act);
	
	$debug->filestart("save_switch","'$includefile'");
	
	if(strlen($includefile) > 0){
		require_once(ZEROSYS__INCLUDEROOT.$includefile);
	}else{
		$debug->debugmsg("empty includefile '$includefile' for save::$save_act",1);
		$action_msg = $language->translate("error");
	}
	
	$debug->fileend("save_switch",$action_msg);
	unset($includefile);
}
// END save switch


$debug->msg( "finished save switch!" );






$debug->filestart("html-doc", "language: ".$language->getlanguage());
// css stuff
require_once(ZEROSYS__CONFIGROOT."css.inc.php");

$html->css->css_alertunset = false;
$html->no_css = true;
$debug->debugarray($db->getdata("style"), "stylearr");
foreach($db->getfancydata("style") as $arr) {
	$isdefaultstyle = false;
	if($userobj === NULL){
		if($arr["style_key"] == 1) {
			$isdefaultstyle = true;
		}
	} else {
		if($arr["style_key"] == $userobj->_data["style_fkey"]) {
			$isdefaultstyle = true;
		}
	}
	$cssfile = str_replace(" ","-",$arr["style"]).".css";
	if($isdefaultstyle) {
		$html->meta->new_meta ( "link", array("rel"=>"stylesheet", "title"=>$arr["style"], "type"=>"text/css", "href"=>"css/$cssfile") );
	} else {
		$html->meta->new_meta ( "link", array("rel"=>"alternate stylesheet", "title"=>$arr["style"], "type"=>"text/css", "href"=>"css/$cssfile") );
	}
}


// start doc
//$debug->msg( "start DOC!" );
$html->title(ZEROSYS__PROJECTNAME." ".ZEROSYS__PROJECTVERSION);
$html->start_doc ();
$html->meta->new_meta("link", array("rel"=>"shortcut icon", "href"=>"favicon.ico"));
$debug->fileend("html-doc");



// menu
$adminmenu = new menu();


$debug->filestart("html-form");
// FORM
$form = $html->start_form ( ZEROSYS__FORMNAME );
$html->element("enctype","multipart/form-data", $form);
$html->element("accept-charset","utf-8", $form);
$html->element( "onsubmit", "return sendform();", $form );
$html->js->jsadd("var the_form_name = '".ZEROSYS__FORMNAME."';");
$debug->fileend("html-form");

// display switch
$display = -1;
$dsp_act = $actionstack->get_displayaction( TRUE );
if($dsp_act == ""){
	$dsp_act = "main";
}

// set mainmenu from action
$adminmenu->setmainmenufromaction($dsp_act);


$debug->msg( "start display-switch w/ action set to:'$dsp_act'" );
$includefile = $actionstack->getincludefile("display", $dsp_act);

$debug->filestart("display_switch", "'$includefile'");
if(strlen($includefile) > 0){
	require_once(ZEROSYS__INCLUDEROOT.$includefile);
}else{
	$debug->debugmsg("empty includefile '$includefile' for display::$dsp_act",1);
}
$debug->fileend("display_switch","pointer to display: '$display'");

unset($includefile);
// END display switch



// build page
// adds the display-page to the content of form
$debug->filestart("buildpage");
if ( $display >= 0 ) {
	if ( $dsp_act == "login" || $dsp_act == "loginlocked" ) {
		$h = $html->new_element("h3", ZEROSYS__PROJECTNAME." ".ZEROSYS__PROJECTVERSION);
		$html->element("style", "text-align: center;", $h);
		$html->merge_elements($form, $h);
		$html->merge_elements($form, $display );
	}else{
		$debug->filestart("build pagetable");
		
		$h = $html->new_element("h3", ZEROSYS__PROJECTNAME." ".ZEROSYS__PROJECTVERSION);
		$html->merge_elements($form, $h);
		
		$pagetab = new table();
		$pagetab->set_colcount(2);
		$pagetab->settablestyle( array( 
					"width" => "100%",
					"align" => "center",
					"cellpadding" => "0",
					"cellspacing" => "0"
					)
				);
		
		
		
		$tr = $pagetab->newtr();
		$mm = $adminmenu->buildmainmenue();
		$html->element("class","mainmenutable",$mm);
		$html->element("cellpadding","0",$mm);
		$html->element("cellspacing","0",$mm);
		$pagetab->settd($html->get_element($mm),$tr);
		$pagetab->setstyle_td(array("colspan"=>"2"),$tr,0);
		
		
		
		$tr = $pagetab->newtr();
		$pagetab->settd($action_msg,$tr);
		$pagetab->setstyle_td(array("colspan"=>"2","class"=>"errormessagetd"),$tr,0);
		if (strlen(trim($action_msg)) > 0){
			$pagetab->setstyle_td(array("colspan"=>"2","id"=>"error"),$tr,0);
		}
		unset($action_msg);
		
		$tr = $pagetab->settr(
			array(
				$html->get_element($adminmenu->buildsubmenue()),
				$html->get_element($display)
				)
		);
		//$pagetab->setstyle_tr(array("class"=>"pagetr"),$tr);
		$pagetab->setstyle_td(array("width"=>"100%"),$tr,1);
		$pagetab->setstyle_td(array("class"=>"pagetab"),$tr,1);
		$pagetab->setstyle_td(array("class"=>"submenuetd"),$tr,0);
		
		unset($td);
		unset($tr);
		
		$html->merge_elements ( $form, $pagetab->makehtmlelement(false));
		$debug->fileend("build pagetable");
	}
} else {
	$debug->debugmsg("Ohgh - I lost my display ;-)", 1);
}
$debug->fileend("buildpage");

// close form
$html->end_form ( $form );

// (c)
if(defined("ZEROSYS__COPYLEFT") && strlen(ZEROSYS__COPYLEFT)>0) {
	$div = $html->new_element();
	$html->element( "style", "text-align:right; padding:2px;", $div );
	$copyleft = $html->new_element( "a", "&copy; ".ZEROSYS__COPYLEFT );
	$html->element( "href", "http://www.zero-sys.net", $copyleft );
	$html->element( "target", "_blank", $copyleft );
	$html->element( "class", "copyleft", $copyleft );
	$html->element( "title", ZEROSYS__PROJECTNAME." ".ZEROSYS__PROJECTVERSION." &copy; ".ZEROSYS__COPYLEFT, $copyleft );
	$html->merge_elements( $div, $copyleft );
	$html->print_element($div);
}

$debug->debugarray ( &$_SESSION, "SESSION_om_end_of_".__FILE__ );

// close doc
$debug->filestart("printpage");
$html->print_html_out ();
$debug->fileend("printpage");

$debug->debugprintout (1);

$html->end_doc ();


?>
Return current item: TraffStats