<?php
session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:404.php');
}else{
include 'po-component/po-menumanager/includes/config.php';
include 'po-component/po-menumanager/includes/functions.php';
switch($_GET[act]){
  default:
  if ($_SESSION[leveluser]=='admin'){
	$tablemenu = new PoTable('menu_group');
	$menus = $tablemenu->numRow();
	if ($menus != "0"){
		/**
		 * PoController
		 * This is the base class for all controllers
		 * Every controller will extend this class
		 */
		class PoController {
			protected $db;

			/**
			 * Constructor. Initialize database connection
			 */
			public function __construct() {
				include 'po-component/po-menumanager/includes/db.php';
				$this->db = new DB;
				$this->db->Connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
			}

			/**
			 * Includes the view file and display the data
			 *
			 * @param string $view_file
			 * @param array $data
			 */
			protected function view($view_file, $data = '') {
				if (is_array($data)) {
					extract($data);
				}
				$file = 'po-component/po-menumanager/templates/' . $view_file . '.php';
				if (file_exists($file)) {
					include $file;
				} else {
					die("Cannot include $view_file");
				}
			}
		}
		/**
		 * default controller & method
		 */
		$controller = 'menu';
		$method = 'menumanager';

		/**
		 * url structure: index.php?act=controller.method
		 */
		if (isset($_GET['act'])) {
			$act = explode('.', $_GET['act']);
			$controller = $act[0];
			if (isset($act[1])) {
				$method = $act[1];
			}
		}

		$controller_file = 'po-component/po-menumanager/modules/' . $controller . '.php';
		if (file_exists($controller_file)) {
			include $controller_file;
			$Class_name = ucfirst($controller);
			$instance = new $Class_name;
			if (!is_callable(array($instance, $method))) {
				die("Cannot call method $method");
			}
			$instance->$method();
		} else {
			$controller_file = 'po-component/po-menumanager/modules/menu.php';
			include $controller_file;
			$instance = new Menu;
			$instance->menumanager();
		}
		break;
	}else{
		$table = new PoTable('menu_group');
		$table->save(array(
			'id' => '1',
			'title' => 'Main Menu'
		));
		/**
		 * PoController
		 * This is the base class for all controllers
		 * Every controller will extend this class
		 */
		class PoController {
			protected $db;

			/**
			 * Constructor. Initialize database connection
			 */
			public function __construct() {
				include 'po-component/po-menumanager/includes/db.php';
				$this->db = new DB;
				$this->db->Connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
			}

			/**
			 * Includes the view file and display the data
			 *
			 * @param string $view_file
			 * @param array $data
			 */
			protected function view($view_file, $data = '') {
				if (is_array($data)) {
					extract($data);
				}
				$file = 'po-component/po-menumanager/templates/' . $view_file . '.php';
				if (file_exists($file)) {
					include $file;
				} else {
					die("Cannot include $view_file");
				}
			}
		}
		/**
		 * default controller & method
		 */
		$controller = 'menu';
		$method = 'menumanager';

		/**
		 * url structure: index.php?act=controller.method
		 */
		if (isset($_GET['act'])) {
			$act = explode('.', $_GET['act']);
			$controller = $act[0];
			if (isset($act[1])) {
				$method = $act[1];
			}
		}

		$controller_file = 'po-component/po-menumanager/modules/' . $controller . '.php';
		if (file_exists($controller_file)) {
			include $controller_file;
			$Class_name = ucfirst($controller);
			$instance = new $Class_name;
			if (!is_callable(array($instance, $method))) {
				die("Cannot call method $method");
			}
			$instance->$method();
		} else {
			$controller_file = 'po-component/po-menumanager/modules/menu.php';
			include $controller_file;
			$instance = new Menu;
			$instance->menumanager();
		}
	}
	}else{
?>
	<div class="contentTop">
        <span class="pageTitle"><span class="icos-view"></span><?php echo $langmenu28; ?></span>
    </div>
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="admin.php?mod=home"><?php echo $langmenu1; ?></a></li>
                <li class="current"><a><?php echo $langmenu28; ?></a></li>
            </ul>
        </div>
    </div>
    <!-- Main content -->
    <div class="wrapper">
		<div class="wrapper" id="errorWrapperadmin">
			<span class="errorNum">404</span>
			<div class="errorContent">
				<span class="errorDesc"><span class="icon-warning"></span>Ooops! Error Somethings Wrong</span>
				<div class="fluid">
					<?php
						$url = rtrim("http://".$_SERVER['HTTP_HOST'], "/").$_SERVER['PHP_SELF'];
						$url2 = preg_replace("/\/po-admin\/(admin\.php$)/","",$url);
						$siteurl = $url2;
					?>
					<a title="Back to Previous page" class="buttonM bLightBlue grid6" onClick="history.back();">Back to previous page</a>
					<a href="<?php echo $siteurl; ?>" title="Back to the website" class="buttonM bRed grid6">Back to the website</a>
				</div>
			</div>
		</div>
	</div>
<?php
	}
	break;
}
/* End of index.php */
}
?>