Location: PHPKode > projects > chillyCMS > chillyCMS/core/backendpage.class.php
<?php
//#################################################################################################
//	Backendpage class
//#################################################################################################
//	chillyCMS - Content Management System
//	Copyright (C) 2008
//	Stefanie Wiegand <hide@address.com> & Johannes Cox <hide@address.com>
//	
//	This program is licensed under the GPL 3.0 license. For more information see LICENSE.txt.
//#################################################################################################
defined('DOIT') or die('Restricted access');

require_once('page.class.php');

class Backendpage extends Page {
	//special variables
	private $login;
	private $menu;
	private $popup;

	function __construct() {
		global $settings,$mysession;

		parent::__construct();
		
		//title
		$this->title = "<title>chillyCMS Backend</title>\n";

		//metatags
		$this->meta .= "\t<meta name=\"author\" content=\"Stefanie Wiegand &amp; Johannes Cox\" />\n".
		"\t<meta name=\"keywords\" content=\"chillyCMS, FrozenPepper, Content Management System\" />\n".
		"\t<meta name=\"description\" content=\"chillyCMS Backend\" />\n".
		"\t<meta name=\"robots\" content=\"noindex,nofollow\" />\n".
		"\t<link rel=\"icon\" href=\"".URL."/style/images/favicon.ico\" type=\"image/vnd.microsoft.icon\"/>\n";
		
		//stylesheets
		$this->stylesheets = "\t<link rel='stylesheet' href='".URL."/style/css/backend.css' type='text/css' />\n".
		"\t<link rel='stylesheet' href='".URL."/style/css/".$settings["backendstyle"].".css' type='text/css' />\n";
		
		//is it a backend login OR a popup (without menu)?
		$this->login = $this->popup = false ;
		
		$this->scripts = "";
		$this->menu = "";
	}
	//Destructor
	function __destruct() {
		$this->login = $this->popup = $this->menu = false;
		parent::__destruct();
	}
	//Getter
	public function __get($name) {
		if (isset($name, $this->$name)) { return $this->$name; }
		else { return false; }	
	}
	
	//generate backend menu
	private function make_menu() {
		global $l_menu,$mysession,$is_admin;
		
		$gids = $mysession->user->gids;
		
		//what is the active site?
		$activebackendsite=substr($_SERVER["SCRIPT_FILENAME"],strlen(PATH."/admin/"));
		$activebackendsite=substr($activebackendsite,0,-9);

		$this->menu = "<div class='adminmenu'>\n".
		"\t<div class='adminmenu_left'></div>\n".
		"\t<div class='adminmenu_middle'>\n".
		"\t<ul>\n";
		//settings
		if ($is_admin) {
			$this->menu .= "\t\t<li>";
			if ($activebackendsite=="settings") { $this->menu .= "<div class='active'>"; }
			$this->menu .= "<a class='menu_settings' href='".URL."/admin/settings.site.php'>$l_menu[lbl_settings]</a>";
			if ($activebackendsite=="settings") { $this->menu .= "</div>"; }
			$this->menu .= "</li>\n";
		}
		//content
		$this->menu .= "\t\t<li>";
		if ($activebackendsite=="content" or $activebackendsite=="edit") { $this->menu .= "<div class='active'>"; }
		$this->menu .= "<a class='menu_content' href='".URL."/admin/content.site.php'>$l_menu[lbl_content]</a>";
		if ($activebackendsite=="content" or $activebackendsite=="edit") { $this->menu .= "</div>"; }
		//media
		$this->menu .= "</li>\n\t\t<li>";
		if ($activebackendsite=="media") { $this->menu .= "<div class='active'>"; }
		$this->menu .= "<a class='menu_media' href='".URL."/admin/media.site.php'>$l_menu[lbl_media]</a>";
		if ($activebackendsite=="media") { $this->menu .= "</div>"; }
		$this->menu .= "</li>\n";
		//modules
		if ($is_admin) {
			$this->menu .= "\t\t<li>";
			if ($activebackendsite=="modules" or $activebackendsite=="moduleinfo" or $activebackendsite=="modulesedit")
			{ $this->menu .= "<div class='active'>"; }
			$this->menu .= "<a class='menu_modules' href='".URL."/admin/modules.site.php'>$l_menu[lbl_modules]</a>";
			if ($activebackendsite=="modules" or $activebackendsite=="moduleinfo" or $activebackendsite=="modulesedit")
			{ $this->menu .= "</div>"; }
			$this->menu .= "</li>\n";
		}
		//design
		if ($is_admin) {
			$this->menu .= "\t\t<li>";
			if ($activebackendsite=="design") { $this->menu .= "<div class='active'>"; }
			$this->menu .= "<a class='menu_design' href='".URL."/admin/design.site.php'>$l_menu[lbl_design]</a>";
			if ($activebackendsite=="design") { $this->menu .= "</div>"; }
			$this->menu .= "</li>\n";
		}
		//users/groups
		$this->menu .= "\t\t<li>";
		if ($activebackendsite=="usersgroups" or $activebackendsite=="userform" or $activebackendsite=="groupform") {
			$this->menu .= "<div class='active'>";
		}
		$this->menu .= "<a class='menu_usersgroups' href='".URL."/admin/usersgroups.site.php'>$l_menu[lbl_usersgroups]</a>";
		if ($activebackendsite=="usersgroups" or $activebackendsite=="userform" or $activebackendsite=="groupform") {
			$this->menu .= "</div>";
		}
		//tools
		$this->menu .= "</li>\n\t\t<li>";
		if ($activebackendsite=="tools") { $this->menu .= "<div class='active'>"; }
		$this->menu .= "<a class='menu_tools' href='".URL."/admin/tools.site.php'>$l_menu[lbl_tools]</a>";
		if ($activebackendsite=="tools") { $this->menu .= "</div>"; }

		$this->menu .= "</li>\n\t\t<li class='menu_small'><a class='menu_logout' href='".URL."/admin/login.site.php?".
		"action=logout&amp;reason=logout'>$l_menu[lbl_logout]</a></li>\n".
		"\t\t<li class='menu_small'><a class='menu_preview' href='".URL."/index.php' ".
		"target='_blank'>$l_menu[lbl_preview]</a></li>\n".
		"\t</ul>\n".
		"\t</div>\n".
		"\t<div class='adminmenu_right'></div>\n".
		"</div>\n";
	}	
	
	//use certain scripts
	public function use_scripts($scripts) {
		if (is_array($scripts)) {
			foreach ($scripts as $script) {
				if ($script=="ckeditor") {
					$this->scripts = "\t<script type='text/javascript' src='".URL."/scripts/specialrightsmenu.js'></script>\n".
					"\t<script type='text/javascript' src='".URL."/modules/ckeditor/ckeditor.js'></script>\n";
				} else {
					$this->scripts .= "\t<script type='text/javascript' src='".URL."/scripts/$script'></script>\n";
				}
			}
		} elseif ($scripts=="ckeditor") {
			$this->scripts = "\t<script type='text/javascript' src='".URL."/scripts/specialrightsmenu.js'></script>\n".
			"\t<script type='text/javascript' src='".URL."/modules/ckeditor/ckeditor.js'></script>\n";
		} else {
			$this->scripts = "\t<script type='text/javascript' src='".URL."/scripts/$scripts'></script>\n";
		}
	}
	//set type of page
	public function set_type($type) {
		if ($type=="login") {
			$this->login = true;
		} elseif ($type=="popup") {
			$this->popup = true;
		}
	}
	//print functions
	public function print_head() {	
		echo $this->doctype.
		"<head>\n".
		$this->title.
		$this->meta.
		$this->stylesheets.
		$this->scripts.
		"</head>\n";
	}
	public function print_body($msg="") {
		global $settings, $is_admin;
		
		//make menu
		if ($this->popup == false && $this->login == false) {
			$this->make_menu();
		}

		echo "<body>\n";
		
		//debug mode?
		if (intval($settings["debug_mode"])==1) {
			//time
			$this->stop_time = microtime(true);
			$this->load_time = round(($this->stop_time - $this->start_time),6)*1000;
			ini_set('display_errors',1);
			error_reporting(E_ALL);
			echo "\t<div class='debug'>\n".
			"\t\t<h3>::: <em>chillyCMS</em> Debug Mode :::</h3>\n";
			
			if ($this->load_time > 1000) {
				echo "\t\t<p>This page was generated in <strong>".($this->load_time/1000)."</strong> s.</p>\n";
			} else {
				echo "\t\t<p>This page was generated in <strong>".$this->load_time."</strong> ms.</p>\n";
			}
			if ($this->num_queries==1) {
				//1 query
				echo "\t\t<p>It took <strong>$this->num_queries</strong> query:</p>\n";
			} else {
				//>1 queries
				echo "\t\t<p>It took <strong>$this->num_queries</strong> queries:</p>\n";
			}
			echo "\t\t<ul>\n";
			//queries
			foreach ($this->queries as $q) {
				echo "\t\t\t<li>$q</li>\n";
			}			
			echo "\t\t</ul>\n";
			//additional debug info
			if ($this->debug_info && $this->debug_info!="") {
				echo "\t\t<br /><p><strong><em>Additional debug information:</em></strong></p><br />\n".$this->debug_info."<br />";
			}
			echo "\t</div>\n";
		}

		if ($this->popup == false) {
			//backend wrapper
			echo "<div class='wrapper'>\n";
			if ($this->login == false) {
				//mainmenu
				echo $this->menu;
			} else {
				echo "<div class=\"adminmenu\"></div>";
			}
			echo "<div class='mainbackend'>\n".
			//message
			"\t<div class='wrapper_top'>\n".
			"\t\t<div class='wrapper_top_left'></div>\n".
			"\t\t<div class='wrapper_top_middle'>\n";
			if (is_array($msg) && sizeof($msg)==2) {
				$mymsg=escape_html($msg[0]);
				$type=escape_html($msg[1]);
				echo "\t\t\t<div class='message'>\n";
				if ($type && $type!="" && $mymsg!="") {
					echo "\t\t\t\t<div class='message_left_".$type."'></div>\n";
					echo "\t\t\t\t<p class='$type'>$mymsg</p>\n";
					echo "\t\t\t\t<div class='message_right_".$type."'></div>\n";
				}
				echo "\t\t\t</div>\n";
			}
			echo "\t\t</div>\n".
			"\t\t<div class='wrapper_top_right'></div>\n".
			"\t</div>\n".
			"\t<div class='clr'></div>\n".
			"\t<div class='admincontent'>\n";
		} else {
			echo "<div class='popup'>\n";
		}
		//content of the backend page
		echo $this->content;
		
		if ($this->popup == false) {
			//sticky footer
			echo "\t</div>\n".
			"\t<div class='clr backendbottom'></div>\n".
			"\t<div class='push'></div>\n".
			"</div>\n";
		} else {
			echo "</div>\n";
		}
		echo "</div>\n";
		
		if ($this->popup == false) {
			//footer
			echo "<div class='footer_full'>\n".
			"\t<div class='footer'>\n".
			"\t\t<div class='footer_inner'>\n".
			"\t\t\t<p class='footerleft'>chillyCMS ";
			if (!$this->login) { echo $settings["version"]." "; }
			echo "&copy;2008 - ".date("Y")." Stefanie Wiegand &amp; Johannes Cox</p>\n";
			if (!$this->login) {
				echo "\t\t\t<p class='footerright'>".
				"<a href='".URL."/admin/credits.site.php'>More Credits</a></p>\n";
			}
			echo "\t\t</div>\n".
			"\t\t</div>\n".
			"\t</div>\n";
		}
		echo "</body>\n".
		"</html>\n";
	}
	
	public function set_style($style) {
		$this->stylesheets = "\t<link rel='stylesheet' href='".URL."/style/css/backend.css' type='text/css' />\n".
		"\t<link rel='stylesheet' href='".URL."/style/css/".$style.".css' type='text/css' />\n";
	}
} ?>
Return current item: chillyCMS