<?php

$GLOBALS['HidePermissionPanel'] = 'none';

if (!defined('CLASS_DIR')) {
	die("CLASS_DIR is not defined <br />\n");
}

class AKB_ENGINE
{

	/**
		* HandlePage
		* Work out what to do with the current page do it
		*
		* @return void
		*/
	function HandlePage()
	{
		$todo = isset($_REQUEST['ToDo']) ? $_REQUEST['ToDo'] : '';
		$GLOBALS['QS'] = '0';

		// XML OPERATION
		if((isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == "application/xml") || (isset($_SERVER['CONTENT_TYPE']) &&
		$_SERVER['CONTENT_TYPE'] == "application/xml")) {
			include(CLASS_DIR.'/class.userxml.php');
			include(CLASS_DIR.'/class.groupxml.php');
			// Retrieve the XML Input
			$GLOBALS['xmlRequest'] = XmlGetRequest();
			if ($GLOBALS['xmlRequest']) {
				// display error message for the installation XML if it's already installed
				if (isset($GLOBALS["isSetup"]) && $GLOBALS["isSetup"] == true && isset($GLOBALS['xmlRequest']->install)) {
					$errors = array(
					0 => array(
					"code" => 'ApplicationInstalled',
					"message" => GetLang('ApplicationInstalled')
					)
					);
					XmlShowError(GetLang('ApplicationInstalled'), $errors);
					exit;
				}

				// XML Operation
				if (isset($GLOBALS['xmlRequest']->todo) && $GLOBALS['xmlRequest']->todo != '') {
					if ($GLOBALS['AKB_CLASS_AUTH']->ProcessXmlLogin()) {
						switch (strtolower($GLOBALS['xmlRequest']->todo)) {
							case 'getgroups' :
							$xmlgroup = new AKB_GROUPXML();
							if(!$xmlgroup->GetGroups()) {
								$errors = array(
								0 => array(
								"code" => 'XMLGetGroupsError',
								"message" => GetLang('XMLGetGroupsError')
								)
								);
								XmlShowError(GetLang('XMLGetGroupsFailed'), $errors);
								return false;
							}
							break;
							case 'savenewuser' :
							$xmluser = new AKB_XMLUSER();
							$xmluser->SaveNewUser();
							break;
							case 'getusers' :
							$xmluser = new AKB_XMLUSER();
							$xmluser->GetUsers();
							break;
							case 'deleteuser' :
							$xmluser = new AKB_XMLUSER();
							$xmluser->DeleteUser();
							break;
							case 'saveupdateduser':
							$_POST['userid'] = (isset($GLOBALS['xmlRequest']->userdetails->userid)) ? strval($GLOBALS['xmlRequest']->userdetails->userid) : '';
							if ($_POST['userid'] != '') {
								if ($_SESSION['user']->verify('user', 'edit')) {
									$xmluser = new AKB_XMLUSER();
									$xmluser->SaveUpdatedUser();
								} else if ($_SESSION['user']->userid == $_POST['userid']) {
									$xmluser = new AKB_XMLUSER();
									$xmluser->SaveUpdatedUser(true);
								} else {
									$errors = array(
									0 => array(
									"code" => 'XMLNoPermission',
									"message" => GetLang('XMLNoPermission')
									)
									);
									XmlShowError(GetLang('XMLUserEditFailed'), $errors);
								}
							} else {
								$errors = array(
								0 => array(
								"code" => 'XMLNoUserId',
								"message" => GetLang('XMLNoUserId')
								)
								);
								XmlShowError(GetLang('XMLUserEditFailed'), $errors);
							}
							break;
							default:
							// Show Error Non valid Action
							$errors = array(
							0 => array(
							"code" => 'XMLInvalidAction',
							"message" => GetLang('XMLInvalidAction')
							)
							);
							XmlShowError(GetLang('XMLQueryFailed'), $errors);
							break;
						}
					} else {
						$errors = array(
						0 => array(
						"code" => 'XmlBadLogin',
						"message" => GetLang('XmlBadLogin')
						)
						);
						XmlShowError(GetLang('XMLQueryFailed'), $errors);
					}

				} else {
					// Show No Action Error
					$errors = array(
					0 => array(
					"code" => 'XMLNoAction',
					"message" => GetLang('XMLNoAction')
					)
					);
					XmlShowError(GetLang('XMLQueryFailed'), $errors);
				}
			}
			exit;
		}

		if ($GLOBALS['AKB_CLASS_AUTH']->IsLoggedIn()) {
			// Its all good so load up their permissions if they havn't
			// already been loaded into the session
			if (empty($_SESSION['user']->groups)) {
				$_SESSION['user']->loadPerms();
			}
		} elseif ($todo == 'processLogin') {
			$GLOBALS['AKB_CLASS_AUTH']->ProcessLogin();
			die();
		} elseif (in_array($todo, array('forgotPass', 'sendPassword', 'confirmPasswordChange', 'resetPassword', 'drawLogo', 'viewHelp', 'upgradeFinish'))) {
			include(CLASS_DIR."/class.forgotpass.php");
			$fp = new AKB_FORGOTPASS();

			switch ($todo) {
				case 'forgotPass':
				$fp->ShowForm();
				break;

				case 'sendPassword':
				$fp->SendLink();
				break;

				case 'drawLogo':
				DrawLogo();
				break;

				case 'confirmPasswordChange':
				$fp->ConfirmPasswordChange();
				break;

				case 'resetPassword':
				$fp->ResetPassword();
				break;

				case 'upgradeFinish':
				$GLOBALS['UpgradeCompleteMessage'] = sprintf(GetLang("UpgradeComplete"),VERSION_NUMBER);

				$GLOBALS['ProductMessages'] = "";
				if (isset($_SESSION['_upgrade'])) {
					foreach ($_SESSION['_upgrade'] as $version=>$message) {
						if ($message != "") {
							$message = str_replace("\\n","\n",$message);

							$GLOBALS['ProductMessages'] .= trim($version)."\n---------------\n".$message."\n\n";
						}
					}
				}

				$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('upgradeFinish');
				$GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();

				break;

				default:
				break;

			}

			die();
		} else if ($todo == 'nojs') {
			PrintHeader();
			$GLOBALS['Title'] = GetLang('JavascriptRequiredTitle');
			$GLOBALS['Message'] = MessageBox(GetLang("JavascriptRequired"), MSG_ERROR);
			$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('message');
			$GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();
			PrintFooter();
			die();
		} else {
			if (count($_POST) > 0) {
				//Store the previous post vars.
				$_SESSION['__prevPostVars'] = $_POST;
			}

			//If we're not actually "logged out" already and we have HTTP referrer, continue.
			if ((!isset($_REQUEST['loggedout'])) && (isset($_SERVER['HTTP_REFERER'])) && ($todo != "")) {
				//If we came from the admin, then its more than likely that we've been logged out.
				//Chuck the loggedout var on the end to make sure we can notify them as such.
				if (strpos($_SERVER['HTTP_REFERER'],$GLOBALS['pathToKB']."/admin/") !== false) {
					$_SESSION['__prevPostVars'] = $_POST; // (TODO:: Possibly superfluous?)

					if (!isset($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == '') {
						$_SERVER['REQUEST_URI'] = $_SERVER["SCRIPT_NAME"] .'?'.
						$_SERVER['QUERY_STRING'];
					}

					header("location: ".$_SERVER['REQUEST_URI']."&loggedout=true");
					die();
				}
			}

			$GLOBALS['AKB_CLASS_AUTH']->DoLogin();
			die();
		}

		//Check if there are post vars we need to repopulate
		if ((isset($_SESSION['__prevPostVars'])) && (is_array($_SESSION['__prevPostVars'])) && (count($_SESSION['__prevPostVars']) > 0)) {
			$_POST = $_SESSION['__prevPostVars'];
			unset($_SESSION['__prevPostVars']);
		}

		//Start the breadcrumbs
		$GLOBALS['BreadcrumEntries'] = array(GetLang("Home") => "index.php");

		switch ($todo) {
			case 'saveSettings':
			if ($_SESSION['user']->verify('setting', 'edit')) {
				include(CLASS_DIR.'/class.settings.php');
				$GLOBALS['AKB_CLASS_SETTINGS'] = new AKB_SETTINGS();
				PrintHeader();
				$GLOBALS['AKB_CLASS_SETTINGS']->SaveSettings();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;

			case 'systemInfo':
			$this->DisplaySystemInfo();

			break;

			case 'versionCheck':
			$this->DisplayVersionCheck();

			break;

			case 'phpSystemInfo':
			phpInfo();

			break;
			case 'editSettings':
			if ($_SESSION['user']->verify('setting', 'edit')) {
				include(CLASS_DIR.'/class.settings.php');
				$GLOBALS['AKB_CLASS_SETTINGS'] = new AKB_SETTINGS();
				PrintHeader();
				$GLOBALS['AKB_CLASS_SETTINGS']->checkRequired();

				$GLOBALS['BreadcrumEntries'][GetLang("ManageSettings")] = "";

				$GLOBALS['AKB_CLASS_SETTINGS']->UpdateSettings();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'stopQuickStart':
			$this->StopQuickStart();
			break;
			case 'quickStart':
			$this->QuickStartPage();
			break;
			case 'drawLogo':
			DrawLogo();
			break;
			case 'updateCommentStatus':
			if ($_SESSION['user']->verify('comment', 'edit')) {
				include(CLASS_DIR.'/class.comment.php');
				$GLOBALS['AKB_CLASS_COMMENT'] = new AKB_COMMENT();
				$GLOBALS['BreadcrumEntries'][GetLang("ViewComments")] = "";
				PrintHeader();
				$GLOBALS['AKB_CLASS_COMMENT']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'deleteComment':
			if ($_SESSION['user']->verify('comment', 'delete')) {
				include(CLASS_DIR.'/class.comment.php');
				$GLOBALS['AKB_CLASS_COMMENT'] = new AKB_COMMENT();
				$GLOBALS['BreadcrumEntries'][GetLang("ViewComments")] = "";
				PrintHeader();
				$GLOBALS['AKB_CLASS_COMMENT']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'editComment':
			if ($_SESSION['user']->verify('comment', 'edit')) {
				include(CLASS_DIR.'/class.comment.php');
				$GLOBALS['AKB_CLASS_COMMENT'] = new AKB_COMMENT();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("EditCommentTitle")] = "";

				$GLOBALS['AKB_CLASS_COMMENT']->EditComment();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'saveUpdatedComment':
			if ($_SESSION['user']->verify('comment', 'edit')) {
				include(CLASS_DIR.'/class.comment.php');
				$GLOBALS['AKB_CLASS_COMMENT'] = new AKB_COMMENT();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("ViewComments")] = "";

				$GLOBALS['AKB_CLASS_COMMENT']->SaveUpdatedComment();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'advCommentSearch':
			case 'viewComments':
			if ($_SESSION['user']->verify('comment', 'edit')
			|| $_SESSION['user']->verify('comment', 'delete')) {
				include(CLASS_DIR.'/class.comment.php');
				$GLOBALS['AKB_CLASS_COMMENT'] = new AKB_COMMENT();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("ViewComments")] = "";

				$GLOBALS['AKB_CLASS_COMMENT']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;

			case "viewRatings":
			if ($_SESSION['user']->verify('rating', 'edit')
			|| $_SESSION['user']->verify('rating', 'delete')) {
				include(CLASS_DIR.'/class.rating.php');
				$GLOBALS['AKB_CLASS_RATING'] = new AKB_RATING();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("ManageRatings")] = "";

				$GLOBALS['AKB_CLASS_RATING']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;

			case 'saveUpdatedGlossaryTerm':
			case 'editGlossaryTerm':
			case 'deleteGlossaryTerm':
			case 'viewGlossary':
			case 'saveNewGlossaryTerm':
			case 'createGlossaryTerm':
			include(CLASS_DIR.'/class.glossary.php');
			$g = new AKB_GLOSSARY();
			PrintHeader();
			$g->HandlePage();
			PrintFooter();
			break;
			case 'saveUpdatedCategory':
			if ($_SESSION['user']->verify('category', 'edit')) {
				PrintHeader();
				$GLOBALS["AKB_CLASS_CATEGORY"]->SaveUpdatedCategory();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'editCategory':
			if ($_SESSION['user']->verify('category', 'edit')) {
				PrintHeader();
				$GLOBALS["AKB_CLASS_CATEGORY"]->EditCategory();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'deleteCategory':
			if ($_SESSION['user']->verify('category', 'delete')) {
				PrintHeader();
				$GLOBALS["AKB_CLASS_CATEGORY"]->DeleteCategory();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'saveNewCategory':
			if ($_SESSION['user']->verify('category', 'edit')) {
				PrintHeader();
				$GLOBALS["AKB_CLASS_CATEGORY"]->SaveNewCategory();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'saveNewNews':
			if ($_SESSION['user']->verify('news', 'edit')) {
				PrintHeader();
				$GLOBALS["AKB_CLASS_NEWS"]->SaveNewNews();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'saveUpdatedNews':
			if ($_SESSION['user']->verify('news', 'edit')) {
				$GLOBALS['AKB_CLASS_NEWS'] = new AKB_NEWS();
				PrintHeader();
				$GLOBALS['AKB_CLASS_NEWS']->SaveUpdatedNews();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'createNews':
			if ($_SESSION['user']->verify('news', 'edit')) {
				PrintHeader();
				$GLOBALS["AKB_CLASS_NEWS"]->ShowNewNews();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'editNews':
			if ($_SESSION['user']->verify('news', 'edit')) {
				PrintHeader();
				$GLOBALS["AKB_CLASS_NEWS"]->EditNews();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'deleteNews':
			if ($_SESSION['user']->verify('news', 'delete')) {
				PrintHeader();
				$GLOBALS["AKB_CLASS_NEWS"]->DeleteNews();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'viewNews':
			if ($_SESSION['user']->verify('news', 'edit')
			|| $_SESSION['user']->verify('news', 'delete')) {
				PrintHeader();
				$GLOBALS['AKB_CLASS_NEWS']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'updateNewsVisible':
			if ($_SESSION['user']->verify('news', 'edit')) {
				$GLOBALS['AKB_CLASS_NEWS'] = new AKB_NEWS();
				PrintHeader();
				$GLOBALS['AKB_CLASS_NEWS']->UpdateVisible();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;

			case 'createCategory':
			if ($_SESSION['user']->verify('category', 'edit')) {
				PrintHeader();
				$GLOBALS["AKB_CLASS_CATEGORY"]->ShowNewCategory();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'viewCategories':
			if ($_SESSION['user']->verify('category', 'edit')
			|| $_SESSION['user']->verify('category', 'delete')) {
				PrintHeader();
				$GLOBALS['AKB_CLASS_CATEGORY']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}

			break;

			case 'viewCustomFields':
			case 'createCustomField':
			case 'editCustomField':
			case 'saveCustomField':
			case 'deleteCustomField':
			if ($_SESSION['user']->verify('question', 'edit')) {
				PrintHeader();
				$GLOBALS['AKB_CLASS_CUSTOMFIELDS']->HandlePage();
				PrintFooter();
			}
			break;

			case 'logOut':
			$GLOBALS['AKB_CLASS_AUTH']->LogOut();

			break;
			case 'updateQuestionVisible':
			case 'updatePendingQuestionVisible':
			if ($_SESSION['user']->verify('question', 'approve')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->UpdateVisible();
				if ($todo == 'updatePendingQuestionVisible') {
					$GLOBALS['AKB_CLASS_QUESTION']->ShowWorkflowQuestionList();
				} else {
					$GLOBALS['AKB_CLASS_QUESTION']->ShowQuestionList();
				}
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'editQuestion':
			if ($_SESSION['user']->verify('question', 'edit')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageQuestions")] = "index.php?ToDo=viewQuestions";
				$GLOBALS['BreadcrumEntries'][GetLang("EditQuestionTitle")] = "";

				$GLOBALS['AKB_CLASS_QUESTION']->EditQuestion();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;

			case 'copyQuestion':
			if ($_SESSION['user']->verify('question', 'edit')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->CopyQuestion();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;

			case 'copyUser':
			if ($_SESSION['user']->verify('user', 'edit')) {
				include(CLASS_DIR.'/class.user.php');
				$GLOBALS['AKB_CLASS_USER'] = new AKB_USER();
				PrintHeader();
				$GLOBALS['AKB_CLASS_USER']->CopyUser();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;

			case 'copyGroup':
			if ($_SESSION['user']->verify('group', 'edit')) {
				include(CLASS_DIR.'/class.group.php');
				$GLOBALS['AKB_CLASS_GROUP'] = new AKB_GROUP();
				PrintHeader();
				$GLOBALS['AKB_CLASS_GROUP']->CopyGroup();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;

			case 'saveUpdatedQuestion':
			if ($_SESSION['user']->verify('question', 'edit')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();

				if (isset($_POST['SaveAsNew'])) {
					$newid = $GLOBALS['AKB_CLASS_QUESTION']->SaveUpdatedQuestion(true);
					if (isset($_POST['SubmitEditButton1']) || isset($_POST['SubmitEditButton2'])) {
						$GLOBALS['AKB_CLASS_QUESTION']->EditQuestion((int) $newid, sprintf(GetLang($GLOBALS['SuccessMesg']),htmlspecialchars($_POST['title'],ENT_QUOTES,$GLOBALS['charset'])), MSG_SUCCESS);
					} else {
						$GLOBALS['AKB_CLASS_QUESTION']->ShowQuestionList(sprintf(GetLang($GLOBALS['SuccessMesg']),htmlspecialchars($_POST['title'],ENT_QUOTES,$GLOBALS['charset'])), MSG_SUCCESS);
					}

				} else {
					$GLOBALS['AKB_CLASS_QUESTION']->SaveUpdatedQuestion(false);
				}

				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'importQuestions':
			if ($_SESSION['user']->verify('question', 'edit')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("ImportQuestions")] = "";

				$GLOBALS['AKB_CLASS_QUESTION']->ImportQuestions();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'deleteQuestion':
			if ($_SESSION['user']->verify('question', 'delete')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->DeleteQuestion();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'questionImportAnswers':
			if ($_SESSION['user']->verify('question', 'edit')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				$GLOBALS['AKB_CLASS_QUESTION']->ShowImportErrors();
			} else {
				$this->NoPermission();
			}
			break;
			case 'previewFullQuestion':
			include(CLASS_DIR.'/class.question.php');
			$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
			$GLOBALS['AKB_CLASS_QUESTION']->PreviewFullQuestion();
			break;
			case 'viewQuestionChanges':
			include(CLASS_DIR.'/class.question.php');
			$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
			$GLOBALS['AKB_CLASS_QUESTION']->viewQuestionChanges();
			break;
			case 'previewQuestion':
			include(CLASS_DIR.'/class.question.php');
			$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
			$GLOBALS['AKB_CLASS_QUESTION']->PreviewQuestion();
			break;
			case 'saveNewQuestion':
			if ($_SESSION['user']->verify('question', 'edit')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['SuccessMesg'] = '';
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();
				$newQuestionId = 0;
				if ($newQuestionId = $GLOBALS['AKB_CLASS_QUESTION']->SaveNewQuestion()) {
					if (isset($_POST['SubmitEditButton1']) || isset($_POST['SubmitEditButton2'])) {
						$GLOBALS['BreadcrumEntries'][GetLang("UserManageQuestions")] = "index.php?ToDo=viewQuestions";
						$GLOBALS['BreadcrumEntries'][GetLang("EditQuestionTitle")] = "";
						$GLOBALS['AKB_CLASS_QUESTION']->EditQuestion((int) $newQuestionId, sprintf(GetLang($GLOBALS['SuccessMesg']),htmlspecialchars($_POST['title'],ENT_QUOTES,$GLOBALS['charset'])), MSG_SUCCESS);
					} else {
						$GLOBALS['AKB_CLASS_QUESTION']->ShowQuestionList(sprintf(GetLang($GLOBALS['SuccessMesg']),htmlspecialchars($_POST['title'],ENT_QUOTES,$GLOBALS['charset'])), MSG_SUCCESS);
					}
				}
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'saveNewQuestionAndNotify':
			if ($_SESSION['user']->verify('question', 'edit')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->SaveNewQuestion();
				$GLOBALS['AKB_CLASS_QUESTION']->NotifySubmitterNewQuestion($GLOBALS['newid']);
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'createQuestion':
			if ($_SESSION['user']->verify('question', 'edit')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageQuestions")] = "index.php?ToDo=viewQuestions";
				$GLOBALS['BreadcrumEntries'][GetLang("CreateQuestion")] = "";

				$GLOBALS['AKB_CLASS_QUESTION']->ShowNewQuestion();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'approvalEmail':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				$GLOBALS['AKB_CLASS_QUESTION']->ShowApprovalEmailForm();
			} else {
				$this->NoPermission();
			}
			break;
			case 'advSearch':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->AdvancedSearch();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'workflowAdvSearch':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->WorkFlowAdvancedSearch();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'viewQuestions':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')
			|| $_SESSION['user']->verify('question', 'approve')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageQuestions")] = "";

				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'viewWorkflowQuestions':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')
			|| $_SESSION['user']->verify('question', 'approve')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();

				$GLOBALS['BreadcrumEntries'][GetLang("ManageWorkflowArticles")] = "";

				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'sendApprovalEmail':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')
			|| $_SESSION['user']->verify('question', 'approve')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageQuestions")] = "";

				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'viewUsers':
			if ($_SESSION['user']->verify('user', 'edit')
			|| $_SESSION['user']->verify('user', 'delete')) {
				include(CLASS_DIR.'/class.user.php');
				$GLOBALS['AKB_CLASS_USER'] = new AKB_USER();

				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageUsers")] = "";

				$GLOBALS['AKB_CLASS_USER']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'createUser':
			if ($_SESSION['user']->verify('user', 'edit')) {
				include(CLASS_DIR.'/class.user.php');
				$GLOBALS['AKB_CLASS_USER'] = new AKB_USER();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageUsers")] = "index.php?ToDo=viewUsers";
				$GLOBALS['BreadcrumEntries'][GetLang("AddUserTitle")] = "";

				$GLOBALS['AKB_CLASS_USER']->ShowNewUser();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'saveNewUser':
			if ($_SESSION['user']->verify('user', 'edit')) {
				include(CLASS_DIR.'/class.user.php');
				$GLOBALS['AKB_CLASS_USER'] = new AKB_USER();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageUsers")] = "";

				$GLOBALS['AKB_CLASS_USER']->SaveNewUser();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'saveUpdatedUser':
			if ($_SESSION['user']->verify('user', 'edit')) {
				include(CLASS_DIR.'/class.user.php');
				$GLOBALS['AKB_CLASS_USER'] = new AKB_USER();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageUsers")] = "";

				$GLOBALS['AKB_CLASS_USER']->SaveUpdatedUser();
				PrintFooter();
			} else {
				if ($_SESSION['user']->userid == $_POST['userid']) {
					include(CLASS_DIR.'/class.user.php');
					$GLOBALS['AKB_CLASS_USER'] = new AKB_USER();
					PrintHeader();

					$GLOBALS['BreadcrumEntries'][GetLang("UserManageUsers")] = "";

					$GLOBALS['AKB_CLASS_USER']->SaveUpdatedUser(true);
					PrintFooter();
				} else {
					$this->NoPermission();
				}
			}
			break;
			case 'deleteUser':
			if ($_SESSION['user']->verify('user', 'delete')) {
				include(CLASS_DIR.'/class.user.php');
				$GLOBALS['AKB_CLASS_USER'] = new AKB_USER();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageUsers")] = "";

				$GLOBALS['AKB_CLASS_USER']->DeleteUser();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'editUser':
			if ($_SESSION['user']->verify('user', 'edit')) {
				include(CLASS_DIR.'/class.user.php');
				$GLOBALS['AKB_CLASS_USER'] = new AKB_USER();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageUsers")] = "index.php?ToDo=viewUsers";
				$GLOBALS['BreadcrumEntries'][GetLang("EditUserTitle")] = "";

				$GLOBALS['AKB_CLASS_USER']->ShowEditUser();
				PrintFooter();
			} else {
				if ($_SESSION['user']->userid == $_GET['userid']) {
					include(CLASS_DIR.'/class.user.php');
					$GLOBALS['AKB_CLASS_USER'] = new AKB_USER();
					PrintHeader();

					$GLOBALS['BreadcrumEntries'][GetLang("MyAccount")] = "";

					$GLOBALS['AKB_CLASS_USER']->ShowEditUser(true);
					PrintFooter();
				} else {
					$this->NoPermission();
				}
			}
			break;
			case 'updateUserStatus':
			if ($_SESSION['user']->verify('user', 'edit')) {
				include(CLASS_DIR.'/class.user.php');
				$GLOBALS['AKB_CLASS_USER'] = new AKB_USER();
				PrintHeader();
				$GLOBALS['AKB_CLASS_USER']->UpdateUserStatus();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'viewGroups':
			if ($_SESSION['user']->verify('group', 'edit')
			|| $_SESSION['user']->verify('group', 'delete')) {
				include(CLASS_DIR.'/class.group.php');
				$GLOBALS['AKB_CLASS_GROUP'] = new AKB_GROUP();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("GroupManageGroups")] = "";

				$GLOBALS['AKB_CLASS_GROUP']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'createGroup':
			if ($_SESSION['user']->verify('group', 'edit')) {
				include(CLASS_DIR.'/class.group.php');
				$GLOBALS['AKB_CLASS_GROUP'] = new AKB_GROUP();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("GroupManageGroups")] = "index.php?ToDo=viewGroups";
				$GLOBALS['BreadcrumEntries'][GetLang("AddGroupTitle")] = "";

				$GLOBALS['AKB_CLASS_GROUP']->ShowNewGroup();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'saveNewGroup':
			if ($_SESSION['user']->verify('group', 'edit')) {
				include(CLASS_DIR.'/class.group.php');
				$GLOBALS['AKB_CLASS_GROUP'] = new AKB_GROUP();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("GroupManageGroups")] = "";

				$GLOBALS['AKB_CLASS_GROUP']->SaveNewGroup();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'saveUpdatedGroup':
			if ($_SESSION['user']->verify('group', 'edit')) {
				include(CLASS_DIR.'/class.group.php');
				$GLOBALS['AKB_CLASS_GROUP'] = new AKB_GROUP();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("GroupManageGroups")] = "";

				$GLOBALS['AKB_CLASS_GROUP']->SaveUpdatedGroup();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'deleteGroup':
			if ($_SESSION['user']->verify('group', 'delete')) {
				include(CLASS_DIR.'/class.group.php');
				$GLOBALS['AKB_CLASS_GROUP'] = new AKB_GROUP();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("GroupManageGroups")] = "";

				$GLOBALS['AKB_CLASS_GROUP']->DeleteGroup();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'editGroup':
			if ($_SESSION['user']->verify('group', 'edit')) {
				include(CLASS_DIR.'/class.group.php');
				$GLOBALS['AKB_CLASS_GROUP'] = new AKB_GROUP();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("GroupManageGroups")] = "index.php?ToDo=viewGroups";
				$GLOBALS['BreadcrumEntries'][GetLang("EditGroupTitle")] = "";

				$GLOBALS['AKB_CLASS_GROUP']->ShowEditGroup();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'reviewSubmittedQuestions':
			if ($_SESSION['user']->verify('question', 'review')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'previewSubmittedQuestion':
			if ($_SESSION['user']->verify('question', 'review')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				$GLOBALS['AKB_CLASS_QUESTION']->PreviewSubmittedQuestion();
			} else {
				$this->NoPermission();
			}
			break;
			case 'deleteSubmittedQuestion':
			if ($_SESSION['user']->verify('question', 'review')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->DeleteSubmittedQuestion();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'viewTemplates':
			if ($_SESSION['user']->verify('template', 'edit')) {
				include(CLASS_DIR.'/class.layout.php');
				$GLOBALS['AKB_CLASS_LAYOUT'] = new AKB_LAYOUT();
				PrintHeader();
				$GLOBALS['AKB_CLASS_LAYOUT']->ManageLayouts();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'editTemplate':
			if ($_SESSION['user']->verify('template', 'edit')) {
				include(CLASS_DIR.'/class.layout.php');
				$GLOBALS['AKB_CLASS_LAYOUT'] = new AKB_LAYOUT();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("ManageTemplates")] = "index.php?ToDo=viewTemplates";
				$GLOBALS['BreadcrumEntries'][GetLang("EditTemplateTitle")] = "";

				$GLOBALS['AKB_CLASS_LAYOUT']->EditLayout();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'saveUpdatedTemplate':
			if ($_SESSION['user']->verify('template', 'edit')) {
				include(CLASS_DIR.'/class.layout.php');
				$GLOBALS['AKB_CLASS_LAYOUT'] = new AKB_LAYOUT();
				PrintHeader();
				$GLOBALS['AKB_CLASS_LAYOUT']->SaveUpdatedTemplate();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'restoreTemplate':
			if ($_SESSION['user']->verify('template', 'edit')) {
				include(CLASS_DIR.'/class.layout.php');
				$GLOBALS['AKB_CLASS_LAYOUT'] = new AKB_LAYOUT();
				PrintHeader();
				$GLOBALS['AKB_CLASS_LAYOUT']->RestoreTemplate();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'questionImportTutorial':
			$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('help.questionimport');
			$GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();
			break;

			case 'previewTemplate':
			$GLOBALS['previewTemplate'] = $_GET['template'];
			$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('settings.previewtemplate');
			$GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();
			break;

			case 'viewStats':

			header("location: index.php?ToDo=viewStatsQuestions");
			die();

			break;
			case 'viewStatsQuestions':
			if ($_SESSION['user']->verify('stats', 'viewarticle')) {

				include(CLASS_DIR.'/class.stats.php');
				$GLOBALS['AKB_CLASS_STATS'] = new AKB_STATS();

				PrintHeader();
				$GLOBALS['AKB_CLASS_STATS']->ShowStatsQuestions();
				PrintFooter();
			} else {
				$this->NoPermission('NoPermViewStatsQuestions');
			}
			break;
			case 'viewStatsUsers':
			if ($_SESSION['user']->verify('stats', 'viewuser')) {
				include(CLASS_DIR.'/class.stats.php');
				$GLOBALS['AKB_CLASS_STATS'] = new AKB_STATS();
				PrintHeader();
				$GLOBALS['AKB_CLASS_STATS']->ShowStatsUsers();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'statsUserPerArticlesXml':
			GenerateXML($todo, $_GET['from'], $_GET['to']);
			break;
			case 'viewStatsCategories':
			if ($_SESSION['user']->verify('stats', 'viewcategory')) {

				include(CLASS_DIR.'/class.stats.php');
				$GLOBALS['AKB_CLASS_STATS'] = new AKB_STATS();

				PrintHeader();
				$GLOBALS['AKB_CLASS_STATS']->ShowStatsCategories();
				PrintFooter();

			} else {
				$this->NoPermission();
			}
			break;

			case 'viewStatsSearch':
			if ($_SESSION['user']->verify('stats', 'viewsearch')) {

				include(CLASS_DIR.'/class.stats.php');
				$GLOBALS['AKB_CLASS_STATS'] = new AKB_STATS();

				PrintHeader();
				$GLOBALS['AKB_CLASS_STATS']->ShowStatsSearches();
				PrintFooter();

			} else {
				$this->NoPermission();
			}
			break;

			case 'viewQuestionHistory':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("UserManageQuestions")] = "index.php?ToDo=viewQuestions";
				$GLOBALS['BreadcrumEntries'][sprintf(GetLang("ManageQuestionHistory"),$_GET['questionid'])] = "";

				$GLOBALS['AKB_CLASS_QUESTION']->ViewHistory();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'previewQuestionHistory':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				$GLOBALS['AKB_CLASS_QUESTION']->PreviewQuestionHistory($_GET['versionid']);
			} else {
				$this->NoPermission();
			}
			break;
			case 'revertQuestion':
			if ($_SESSION['user']->verify('question', 'edit')) {
				include(CLASS_DIR.'/class.question.php');
				$GLOBALS['AKB_CLASS_QUESTION'] = new AKB_QUESTION();
				PrintHeader();
				$GLOBALS['AKB_CLASS_QUESTION']->RollBack($_GET['questionid'], $_GET['versionid']);
				$GLOBALS['AKB_CLASS_QUESTION']->HandlePage();
				PrintFooter();
			}
			break;
			case 'upgrade':
			if ($_SESSION['user']->userid == 1) {
				include_once(dirname(__FILE__).'/../../../lib/upgrade_factory.php');
				$uf = new Upgrade_Factory();
				PrintHeader();
				$uf->RunUpgrades('NX');
				PrintFooter();
			}
			break;
			case 'viewSubscribers':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')) {
				include(CLASS_DIR.'/class.subscriber.php');
				$GLOBALS['AKB_CLASS_SUBSCRIBER'] = new AKB_SUBSCRIBER();
				PrintHeader();

				$GLOBALS['AKB_CLASS_SUBSCRIBER']->HandlePage();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'editSubscriber':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')) {
				include(CLASS_DIR.'/class.subscriber.php');
				$GLOBALS['AKB_CLASS_SUBSCRIBER'] = new AKB_SUBSCRIBER();
				PrintHeader();

				$GLOBALS['BreadcrumEntries'][GetLang("ManageSubscribers")] = "index.php?ToDo=viewSubscribers";
				$GLOBALS['BreadcrumEntries'][GetLang("SubscriberTitle")] = "";

				$GLOBALS['AKB_CLASS_SUBSCRIBER']->ShowEdit();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;

			case 'updateSubscriber':
			if ($_SESSION['user']->verify('question', 'edit')
			|| $_SESSION['user']->verify('question', 'delete')) {
				include(CLASS_DIR.'/class.subscriber.php');
				$GLOBALS['AKB_CLASS_SUBSCRIBER'] = new AKB_SUBSCRIBER();
				PrintHeader();
				$GLOBALS['AKB_CLASS_SUBSCRIBER']->Update();
				PrintFooter();
			} else {
				$this->NoPermission();
			}
			break;
			case 'indexAttachments':
			case 'manageBackups':
			case 'backupConfig':
			case 'backupDatabase':
			case 'deleteBackup':
			case 'backupDone':
			PrintHeader();
			include(CLASS_DIR.DS.'class.tools.php');
			$t = new AKB_TOOLS();
			$t->HandlePage();
			PrintFooter();
			break;
			case 'indexAttachmentsInit':
			include(CLASS_DIR.DS.'class.tools.php');
			$t = new AKB_TOOLS();
			$t->HandlePage();
			break;
			case 'backupDatabaseInit':
			include(CLASS_DIR.DS.'class.tools.php');
			$t = new AKB_TOOLS();
			$t->HandlePage();
			break;
			case 'indexDone':
			PrintHeader();
			include(CLASS_DIR.DS.'class.tools.php');
			$t = new AKB_TOOLS();
			$t->HandlePage();
			PrintFooter();
			break;
			case 'doDbBackup':
			include(CLASS_DIR.DS.'class.tools.php');
			$t = new AKB_TOOLS();
			$t->HandlePage();
			break;
			case 'doIndexAttachment':
			include(CLASS_DIR.DS.'class.tools.php');
			$t = new AKB_TOOLS();
			$t->HandlePage();
			break;
			case 'doBackupDatabase':
			include(CLASS_DIR.DS.'class.tools.php');
			$t = new AKB_TOOLS();
			$t->HandlePage();
			break;

			case 'download':
			if (isset($_GET['data'])) {
				list($type, $filename) = explode('|', base64_decode($_GET['data']), 2);
				switch ($type) {

					case 'backup':
					if ($_SESSION['user']->verify('backup', 'create') || $_SESSION['user']->verify('backup', 'delete')) {
						$dir = dirname(__FILE__).'/../../../attachments/backups';
						$file = $dir.'/'.$filename;
						$dir_of_file = dirname(realpath($file));

						if (realpath($dir) == $dir_of_file) {
							while (ob_get_level()) {
								ob_end_clean();
							}
							header('Pragma: private');
							header('Expires: 0');
							header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
							header('Content-Type: application/force-download');
							header('Content-Type: application/octet-stream');
							header('Content-Type: application/download');
							header('Content-Disposition: attachment; filename="'.$filename.'";');
							header('Content-Transfer-Encoding: binary');
							header('Content-Length: '.filesize($file));
							readfile($file);
							die();
						} else {
							$this->NoPermission();
						}
					} else {
						$this->NoPermission();
					}
				}
			}
			break;

			default:
			$GLOBALS['AKB_CLASS_AUTH']->SetupHomePageLinks();

			if (isset($GLOBALS['BreadcrumEntries'])) {
				unset($GLOBALS['BreadcrumEntries']);
			}

			PrintHeader();
			$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('home');
			$GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();
			PrintFooter();
		}
	}

	/**
		*	Launch the knowledge base help window for StoreSuite
		*/
	function ViewHelp()
	{
		if (isset($_GET['helpLink']) && $_GET['helpLink'] != "") {
			$GLOBALS['HelpLink'] = $_GET['helpLink'] . "?inlinehelp=true";
		}

		$GLOBALS["SearchValue"] = "Type Question Here";
		$GLOBALS["AKB_CLASS_TEMPLATE"]->SetTemplate("help");
		$GLOBALS["AKB_CLASS_TEMPLATE"]->ParseTemplate();
	}

	/**
		* NoPermission
		* Display the no permissiong page
		*
		* @return void
		*/
	function NoPermission($message='')
	{
		// Should we launch the quick start window?
		$GLOBALS["HidePermissionPanel"] = "inline";
		$GLOBALS['BreadcrumEntries'] = array();
		$GLOBALS["AKB_CLASS_AUTH"]->SetupHomePageLinks();
		if ($message != '') {
			$GLOBALS['Message'] = MessageBox(GetLang($message), MSG_INFORMATION).'<br/>';
		}
		PrintHeader();
		$GLOBALS["AKB_CLASS_TEMPLATE"]->SetTemplate("home");
		$GLOBALS["AKB_CLASS_TEMPLATE"]->ParseTemplate();
		PrintFooter();
	}

	/**
		* QuickStartPage
		* Display the quickstart popup page
		*
		* @return void
		*/
	function QuickStartPage()
	{
		// Show the quick startpage
		$GLOBALS["AKB_CLASS_TEMPLATE"]->SetTemplate("quickstart");
		$GLOBALS["AKB_CLASS_TEMPLATE"]->ParseTemplate();
	}

	/**
		* StopQuickStart
		* Stop the quickstart page from being displayed
		*
		* @return void
		*/
	function StopQuickStart()
	{
		setcookie($GLOBALS['cookiePrefix']."qs", 1, time() + 3600*24*365);
		echo "<script type=\"text/javascript\" lanugage=\"javascript\">document.location.href='index.php';</script>";
		die();
	}

	function DisplaySystemInfo() {
		PrintHeader();

		$GLOBALS['BreadcrumEntries'][GetLang("SystemInfo")] = "";

		$this->deriveSystemInfo();
		$GLOBALS['el'] = $GLOBALS['e'];
		if (strtolower($GLOBALS['e']) == strtolower(GetLang('pNal'))) {
			$GLOBALS['el'] .= " (<a target=\"_blank\" href=\"".GetLang('hpKBSoftwareLink')."\">".GetLang('Upgrade').")</a>";
		}
		$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('systeminfo');
		$GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();
		PrintFooter();
	}

	function DisplayVersionCheck() {
		PrintHeader();

		$GLOBALS['BreadcrumEntries'][GetLang("VersionCheck")] = "";

		$this->VersionCheck();
		PrintFooter();
	}

	function VersionCheck()
	{

		$GLOBALS['CheckVersion'] = $latestVersion = false;
		// path to check
		$path = dirname(__FILE__).'/../../../admin/tmp/LatestVersion.php';

		if (is_file($path)) {
			@include($path);
		}

		if(!isset($versionCache) || !$versionCache) {
			$GLOBALS['CheckVersion'] = true;
		}
		else if($versionCache['lastCheck'] < time()-86400) {
			$GLOBALS['CheckVersion'] = true;
		}

		$GLOBALS['VersionCheckMessage'] = sprintf(GetLang('VersionNumber'), VERSION_NUMBER);
		$GLOBALS['VersionCheckClass'] = "UpToDate";

		if(isset($versionCache['latest']) && version_compare($versionCache['latest'], VERSION_NUMBER) == 1) {
			$GLOBALS['VersionCheckMessage'] = sprintf(GetLang('VersionIsOutOfDate'), VERSION_NUMBER, $versionCache['latest']);
			$GLOBALS['VersionCheckClass'] = "OutOfDate";
		}

		$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('tools.versioncheck');
		return $GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();
	}

	/**
	* GDEnabled
	* Function to detect if the GD extension for PHP is enabled.
	*
	* @return Boolean
	*/

	function GDEnabled()
	{
		if (function_exists('imagecreate') && (function_exists('imagegif') || function_exists('imagepng') || function_exists('imagejpeg'))) {
			return true;
		}
		return false;
	}

	function deriveSystemInfo() {
		// Server Information
		$GLOBALS['ProductVersion'] = VERSION_NUMBER;
		$GLOBALS['PHPVersion'] = phpversion();
		$GLOBALS['MySQLVersion'] = $GLOBALS['databaseVersion'];
		$GLOBALS['ServerSoftware'] = $_SERVER["SERVER_SOFTWARE"];

		if ($this->GDEnabled()) {
			$php_mods = parsePHPModules();
			$GLOBALS['GDVersion'] = $php_mods['gd']['GD Version'];
		} else {
			$GLOBALS['GDVersion'] = "GD Not Detected";
		}

		if((bool)ini_get('safe_mode') == true) {
			$GLOBALS['SafeMode'] = GetLang('Enabled');
		}
		else {
			$GLOBALS['SafeMode'] = GetLang('Disabled');
		}

		$GLOBALS['MultiByteFunctions'] = array();
		if (function_exists("mb_strpos")) {
			$GLOBALS['MultiByteFunctions'][] = "Multibyte";
		}

		if (function_exists("iconv_strpos")) {
			$GLOBALS['MultiByteFunctions'][] = "iconv";
		}
		$GLOBALS['MultiByteFunctions'] = implode("<br />", $GLOBALS['MultiByteFunctions']);

		if (!$GLOBALS['MultiByteFunctions']) {
			$GLOBALS['MultiByteFunctions'] = GetLang('NotSupported');
		}

		$GLOBALS['RemoteConnections'] = array();
		if (function_exists("curl_init")) {
			$GLOBALS['RemoteConnections'][] = "CURL";
		}

		if (!(bool)ini_get('safe_mode') && ini_get('allow_url_fopen')) {
			$GLOBALS['RemoteConnections'][] = GetLang('RemoteFOpen');
		}
		$GLOBALS['RemoteConnections'] = implode("<br />", $GLOBALS['RemoteConnections']);

		if (!$GLOBALS['RemoteConnections']) {
			$GLOBALS['RemoteConnections'] = GetLang('NoneSupported');
		}

		$GLOBALS['OperatingSystem'] = php_uname();
	}

}

?>