khanat-opennel-code/code/ryzom/tools/server/ryzom_ams/www/html/index.php

127 lines
3.6 KiB
PHP
Raw Normal View History

<?php
/**
* Core that runs the entire system.
* The index.php page handles:
* -# checks what page to load
* -# if a $_POST['function'] is set try to execute that function in the matching php file located in the func folder.
* -# else load the inc's folder matching function related to the page
* -# set the permission and other smarty related settings
* -# call the helper function to load the page.
* @author Daan Janssens, mentored by Matthew Lagoe
*/
//load required pages and turn error reporting on/off
error_reporting(E_ALL);
ini_set('display_errors', 'on');
require_once( '../../ams_lib/libinclude.php' );
if (!@include '../config.php') {
//if config doesnt exist run setup
2013-10-22 06:57:27 +00:00
require( 'installer/libsetup.php' );
} elseif ($_POST["function"] == "do_install") {
echo "Can't run setup while file '../is_installed' exists, please remove that file if you wish to run the install"
exit
} else {
//if config exists then include it
require( '../config.php' );
}
session_start();
2013-06-15 14:01:11 +00:00
//Running Cron?
if ( isset( $_GET["cron"]) ){
if ($_GET["cron"] == "true"){
Sync::syncdata(false);
}
}
//Always try to sync on page load, ie "lazy" cron
Sync::syncdata(false);
//Decide what page to load
if ( ! isset( $_GET["page"]) ){
if(isset($_SESSION['user'])){
if(Ticket_User::isMod(unserialize($_SESSION['ticket_user']))){
$page = 'dashboard';
}else{
$page = 'show_user';
}
}else{
//default page
$page = 'login';
}
}else{
if(isset($_SESSION['user'])){
$page = $_GET["page"];
}else{
2013-09-20 21:36:19 +00:00
switch($_GET["page"]){
case 'register':
$page = 'register';
break;
case 'forgot_password':
$page = 'forgot_password';
break;
case 'reset_password':
$page = 'reset_password';
break;
case 'error':
$page = 'error';
break;
default:
$page = 'login';
break;
}
}
}
2013-09-17 02:24:57 +00:00
//check if ingame & page= register
//this is needed because the ingame register can't send a hidden $_POST["function"]
if ( Helpers::check_if_game_client() && ($page == "register")){
2013-09-17 02:24:57 +00:00
require( "func/add_user.php" );
$return = add_user();
}
//perform an action in case one is specified
//else check if a php page is included in the inc folder, else just set page to the get param
if ( isset( $_POST["function"] ) ){
require( "func/" . $_POST["function"] . ".php" );
$return = $_POST["function"]();
}else{
$filename = 'inc/' . $page . '.php';
if(is_file($filename)){
require_once($filename);
$return = $page();
}
}
//add username to the return array in case logged in.
if(isset($_SESSION['user'])){
$return['username'] = $_SESSION['user'];
}
2013-06-15 14:01:11 +00:00
//Set permission
if(isset($_SESSION['ticket_user'])){
$return['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
}else{
//default permission
$return['permission'] = 0;
}
//hide sidebar + topbar in case of login/register
2013-09-20 21:36:19 +00:00
if($page == 'login' || $page == 'register' || $page == 'logout' || $page == 'forgot_password' || $page == 'reset_password'){
$return['no_visible_elements'] = 'TRUE';
}else{
$return['no_visible_elements'] = 'FALSE';
}
//handle error page
if($page == 'error'){
$return['permission'] = 0;
$return['no_visible_elements'] = 'FALSE';
}
//load the template with the variables in the $return array
helpers :: loadTemplate( $page , $return );