Location: PHPKode > scripts > ezStats for PlayStation Network > ezStats2_psn/admin/index.php
<?php
	require '../tmp/sql.php';
	require '../classes/mysql.php';
	
	$sql = new MySQL(); if ($sql->debug) error_reporting (E_ALL|E_STRICT); else error_reporting (0);
	
	require '../plugins/phpQuery.php';
	require '../classes/settings.php';
	require '../classes/security.php';
	require '../classes/functions.php';
	require '../classes/session.php';
	require '../classes/login.php';
	require '../classes/template.php';
	
	$secure = new Security();
	$settings = new Settings();
	$func = new Functions();
	$login = new Login(Session::getSID());
	$tpl = new Templates();
	$tpl->load_phrases("gui", true);
	$tpl->load_phrases("admin", true);
	$tpl->load_phrases("_psn_admin", true);
	
	// Standard-Variablen belegen
	if (trim($settings->get("clanname") != "")) $headline = $tpl->phrase("headline_clanname")." ".$settings->get("clanname"); else $headline = $tpl->phrase("headline_noclanname");
	date_default_timezone_set($settings->get("timezone"));
	$sid = session::getSID();
	
	
	### LOGINSCREEN // PLAYER SELFADD // STANDARDS ###
	if(!$login->logged_in()) {
		// Seitentemplate
		eval ("\$html = \"".$tpl->template("_index")."\";");  $html = phpQuery::newDocumentHTML($html);
		pq('nav')->addClass('hidden');
		
		// Player-Selfadd (Spieler können sich selber dem Leaderboard hinzufügen)
		if (isset($_GET['selfadd']) AND $settings->get("selfadd")) {
			// Template laden
			eval ("\$addplayer = \"".$tpl->template("addplayer")."\";");
			$addplayer = phpQuery::newDocumentHTML($addplayer);
			
			// Plattform
			$sql->query('SELECT value FROM '.$sql->prefix.'settings WHERE name = "platform"');
			$result = $sql->fetchRow();
			pq('#platform option[value='.$result['value'].']')->attr('selected', 'selected');
			
			// Seite ausgeben
			phpQuery::selectDocument($html);
			pq('#wrap')->append($addplayer);
			die ($html);
		}
		
		// Installationsordner vorhanden
		if (!$sql->debug AND file_exists('../install/index.php')) {
			$path = $_SERVER['HTTP_HOST']."/".str_replace(array($_SERVER['DOCUMENT_ROOT'], "admin/index.php"), array("", "install/"), $_SERVER['SCRIPT_FILENAME']);
			$path = str_replace("//", "/", $path);
			
			eval ("\$foldercheck = \"".$tpl->template("foldercheck")."\";");
			$foldercheck = phpQuery::newDocumentHTML($foldercheck);
			
			phpQuery::selectDocument($html);
			pq('#wrap')->append($foldercheck);
			die ($html);
		}
		
		// Loginformular einblenden (Installationsordner nicht vorhanden)
		else {
			// Fehlermeldung, falls falscher Username/Password eingegeben wurde
			if (isset($_POST['login'])) pq("aside")->text($tpl->phrase("error_login"))->attr("style", "display: block");
			
			
			// Variablen
			$installed = $settings->get("version");
			$ch = curl_init("http://curl.ezstats.org/?version&game=psn"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			$actual = curl_exec($ch); curl_close($ch);
			
			
			// Loginformular einbinden
			eval ("\$login = \"".$tpl->template("login")."\";");
			$login = phpQuery::newDocumentHTML($login);
			
			
			// PHP-Info bei Debug=1
			if ($sql->debug) {
				ob_start();
				phpinfo();
				
				$phpinfo = ob_get_clean();
				$phpinfo = phpQuery::newDocumentHTML($phpinfo);
				$phpinfo = pq('.center')->html();
				
				$info = '<div class="clear"></div><section>'.$phpinfo.'</section>';
			} else $info = "";
			
			
			// Seiten-Ausgabe
			phpQuery::selectDocument($html);
			pq('#wrap')->append($login)->append($info);
			die ($html);
		}
	}
	else {
		// Informationen über den eingeloggten User
		$sql->query('SELECT * FROM '.$sql->prefix.'users WHERE session = "'.$sid.'"');
		$user = $sql->fetchRow();
		
		// Seitentemplate
		eval ("\$html = \"".$tpl->template("_index")."\";");  $html = phpQuery::newDocumentHTML($html);
		if ($user['adminpower'] != "1") pq('nav li[rel=admin]')->addClass('hidden'); // Anzeige der weiteren Nav-Optionen nur mit voller Adminpower
	}
	
	
	### STARTSEITE ###
	if (!count($_GET)) {
		// Template laden
		eval ("\$addplayer = \"".$tpl->template("addplayer")."\";");
		$addplayer = phpQuery::newDocumentHTML($addplayer);
		
		// Sonstiges
		pq('section')->addClass('mtop150');
		
		// Seite ausgeben
		phpQuery::selectDocument($html);
		pq('#wrap')
			->append('<div class="explain_add"></div>') // Erklärpic
			->append($addplayer);
		pq('nav li:first')
			->append('<div class="explain_nav"></div>'); // Erklärpic
		die ($html);
	}
	
	
	### SPIELERVERWALTUNG ###
	if (isset($_GET['player'])) {
		### SPIELER HINZUFÜGEN ###
		// Template laden
		eval ("\$addplayer = \"".$tpl->template("addplayer")."\";");
		$addplayer = phpQuery::newDocumentHTML($addplayer);
		
		
		### SPIELER AKTUALISIEREN ###
		// Voreinstellungen
		$var = $settings->all();
		$lastcheckall = date("d.m.Y - H:i", (int)$settings->get("lastcheckall"));
		$max_execution_time = ini_get("max_execution_time");
		$message = $tpl->phrase("update_help_4");
		eval ( "\$message = \"$message\";" );
		
		// Template laden
		eval ("\$updateplayer = \"".$tpl->template("updateplayer")."\";");
		$updateplayer = phpQuery::newDocumentHTML($updateplayer);
		
		
		### SPIELER VERWALTEN ###
		eval ("\$editplayer = \"".$tpl->template("editplayer")."\";");
		$editplayer = phpQuery::newDocumentHTML($editplayer);
		
		
		// Seite ausgeben
		phpQuery::selectDocument($html);
		pq('#wrap')->append($addplayer);
		pq('#wrap')->append($updateplayer);
		pq('#wrap')->append($editplayer);
		die ($html);
	}
	
	
	### ALLGEMEINE EINSTELLUNGEN ###
	if (isset($_GET['settings'])) {
		// Gespeicherte Settings laden
		$preset = $func->load_settings("settings");
		$preset['debug'] = $sql->debug;
		
		
		// Template laden
		eval ("\$settings = \"".$tpl->template("settings")."\";");
		$settings = phpQuery::newDocumentHTML($settings);
		
		
		// Voreinstellungen setzen (Radiobuttons)
		$radio = Array("selfadd", "ov_averages", "ov_median", "ov_summary", "ov_infobox", "ov_brand", "debug");
		foreach ($radio as $name)
			pq('[name='.$name.']')->filter('[value='.$preset[$name].']')->attr("checked", "checked");
		
		
		// Voreinstellungen setzen (Sprache)
		$languages = Array();
		$sql->query('SHOW COLUMNS FROM '.$sql->prefix.'localization');
		
		while ($row = $sql->fetchRow()) {
			if ($row['Field'] != "id" AND $row['Field'] != "category" AND $row['Field'] != "wildcard") 
			$languages[] = $row['Field'];
		}
		
		foreach ($languages as $lang) {
			if ($lang == $preset['language'])
				 pq('<option/>')->text($lang)->attr('selected', 'selected')->appendTo('#language');
			else pq('<option/>')->text($lang)->appendTo('#language');
		}
		
		
		// Voreinstellungen setzen (Zeitzone)
		pq('#timezone')->append($func->select_timezone($preset['timezone']));
		
		
		// Seite ausgeben
		phpQuery::selectDocument($html);
		pq('#wrap')->append($settings);
		die ($html);
	}
	
	
	### CUSTOMIZATION ###
	if (isset($_GET['custom'])) {
		// Gespeicherte Settings laden
		$columns = $func->load_settings("overview");
		
		
		// Template laden
		eval ("\$custom = \"".$tpl->template("custom")."\";");
		$custom = phpQuery::newDocumentHTML($custom);
		
		
		// Listenelemente generieren
		foreach ($columns as $colname => $value) {
			if ($value)	$string = '<li><input type="checkbox" name="custom" value="'.$colname.'" checked="checked "/> <span>'.$tpl->phrase($colname).'</span></li>';
			else 		$string = '<li><input type="checkbox" name="custom" value="'.$colname.'" /> <span>'.$tpl->phrase($colname).'</span></li>';
			pq('ul')->append($string);
		}
		
		
		// Seite ausgeben
		phpQuery::selectDocument($html);
		pq('#wrap')->append($custom);
		die ($html);
	}
	
	
	### CMS-Plugins ###
	if (isset($_GET['plugin'])) {
		// Pfad erzeugen
		if (!$settings->get("path")) {
			$path = $_SERVER['HTTP_HOST']."/".str_replace($_SERVER['DOCUMENT_ROOT'], "", $_SERVER['SCRIPT_FILENAME']);
			$path = str_replace("\\", "/", $path);
			$path = str_replace("//", "/", $path);
			$path = str_replace("admin/index.php", "", $path);
			
			$path = substr($path, -1)   != "/"       ? $path."/"       : $path;
			$path = substr($path, 0, 7) != "http://" ? "http://".$path : $path;
			
			$settings->set('path', $path, true);
		} else {
			$path = $settings->get('path');
			$settings->set('path', $path, true);
		}
		
		
		// CMS-Plugin-Liste generieren
		$plugins = ""; 
		$sql->query('SELECT code, name FROM '.$sql->prefix.'plugins ORDER BY id');
		
		while ($row = $sql->fetchRow()) {
			if ($settings->get('cms') == $row['code'])
				 $plugins .= '<option selected="selected" value="'.$row['code'].'">'.$row['name'].'</code>';
			else $plugins .= '<option value="'.$row['code'].'">'.$row['name'].'</code>';
		}
		
		
		// Template laden
		eval ("\$plugin = \"".$tpl->template("plugin")."\";");
		$plugin = phpQuery::newDocumentHTML($plugin);
		
		// Seite ausgeben
		phpQuery::selectDocument($html);
		pq('#wrap')->append($plugin);
		die ($html);
	}
	
	
	### STYLE ### 
	if (isset($_GET['style'])) {
		$tpl->load_phrases("style", true);
		$preset = $func->load_settings("style");
		
		// Template laden
		eval ("\$style = \"".$tpl->template("style")."\";");
		$style = phpQuery::newDocumentHTML($style);
		
		
		// Listenelemente generieren
		foreach ($preset as $name => $value) {
			$cutename = ucwords(str_replace("_", " ", $name));
			
			if ($name == "section_bg_image") {
				pq('ul')->append('
					<li>
						<label style="width: 260px" for="'.$name.'">'.$cutename.'</label>
						<select name="'.$name.'" id="'.$name.'"></select>
						<legend style="margin: 0">'.$tpl->phrase($name).'</legend>
					</li>
				');
				
				$files = Array("images/bg/light10.png", "images/bg/light20.png", "images/bg/light30.png", "images/bg/light40.png", "images/bg/light50.png", "images/bg/light60.png", "images/bg/light70.png", "images/bg/light80.png", "images/bg/light90.png", "images/bg/dark10.png", "images/bg/dark20.png", "images/bg/dark30.png", "images/bg/dark40.png", "images/bg/dark50.png", "images/bg/dark60.png", "images/bg/dark70.png", "images/bg/dark80.png", "images/bg/dark90.png");
				
				foreach ($files as $file) {
					if ($file == $value)
						 pq('<option/>')->text($file)->attr('selected', 'selected')->appendTo('#'.$name);
					else pq('<option/>')->text($file)->appendTo('#'.$name);
				}
			} else {
				pq('ul')->append('
					<li>
						<label style="width: 260px" for="'.$name.'">'.$cutename.'</label>
						<input type="text" size="25" name="'.$name.'" value="'.$value.'" />
						<legend style="margin: 0">'.$tpl->phrase($name).'</legend>
					</li>
				');
			}
		}
		
		
		// Seite ausgeben
		phpQuery::selectDocument($html);
		pq('#wrap')->append($style);
		die ($html);
	}
	
	
	### USER ###
	if (isset($_GET['user'])) {
		### USER HINZUFÜGEN ###
		// Template laden
		eval ("\$adduser = \"".$tpl->template("adduser")."\";");
		$adduser = phpQuery::newDocumentHTML($adduser);
		
		
		### SPIELER VERWALTEN ###
		eval ("\$edituser = \"".$tpl->template("edituser")."\";");
		$edituser = phpQuery::newDocumentHTML($edituser);
		
		
		// Seite zusammenstellen
		eval ("\$user = \"".$tpl->template("user")."\";");
		$user = phpQuery::newDocumentHTML($user);
		pq('#user')->append($adduser);
		pq('#user')->append($edituser);
		
		// Seite ausgeben
		phpQuery::selectDocument($html);
		pq('#wrap')->append($user);
		die ($html);
	}
	
	
	### SIGNATUREN ###
	if (isset($_GET['signatures'])) {
		// CHMOD-Test
		if (!is_writable("../signatures")) {
			$path = "'http://".$_SERVER['HTTP_HOST'].str_replace("admin/index.php", "signatures/'", $_SERVER['PHP_SELF']);
			$message = $tpl->phrase("signatures_chmod");
			eval ( "\$message = \"$message\";" );
			$message = phpQuery::newDocumentHTML('<section>'.$message.'</section>');
			
			phpQuery::selectDocument($html);
			pq('#wrap')->append($message);
			die ($html);
		}
		
		// Variablen laden (Signatur-Update)
		$var = $settings->all();
		$sig_lastupdate = date("d.m.Y - H:i", (int)$var->sig_lastupdate);
		$max_execution_time = ini_get("max_execution_time");
		$message = $tpl->phrase("update_help_4");
		eval ( "\$message = \"$message\";" );
		
		// Template laden
		eval ("\$signatures = \"".$tpl->template("signatures")."\";");
		$signatures = phpQuery::newDocumentHTML($signatures);
		
		// Voreinstellungen setzen (Signatur-Aktivierung)
		pq('[name=signatures]')->filter('[value='.$settings->get("signatures").']')->attr("checked", "checked");
		
		// Listenelemente generieren (Signatur-Modifizierung)
		$preset = $func->load_settings("signatures");
		foreach ($preset as $name => $value) {
			$type      = substr($name, 0, strpos($name, "_"));
			$shortname = substr($name, strpos($name, "_")+1);
			$cutename  = ucwords(str_replace("_", " ", $shortname));
			
			if ($shortname != "signature_type") {
				pq('ul[rel='.$type.']')->append('
					<li>
						<label style="width: 260px" for="'.$name.'">'.$cutename.'</label>
						<input type="text" size="25" name="'.$name.'" value="'.$value.'" />
					</li>
				');
			}
		}
		
		
		// Seite ausgeben
		phpQuery::selectDocument($html);
		pq('#wrap')->append($signatures);
		die ($html);
	}
	
	/*
	echo "<pre>";
	print_r(time());
	var_dump($_POST);
	echo $settings->get("version");
	echo "<br><br>";
	$settings->set("version", "foo");
	echo $settings->get("version");
	*/
?>
Return current item: ezStats for PlayStation Network