<?php
/**
 * This file is part of Wemag Dashboard Management.
 *
 * Wemag Dashboard Management is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Wemag Dashboard Management is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Wemag Dashboard Management.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Copyright 2008 Aart-Jan Boor <aart-jan@wemag.nl>
 * Wemag Advisering <http://www.wemag.nl>
 */
require_once(KT_LIB_DIR . '/dispatcher.inc.php');

/**
 * Dispatches the reset dashboards page
 */
class ResetDashboardsDispatcher extends KTAdminDispatcher {
	/**
	 * Ask for confirmation
	 *
	 * @return template HTML
	 */
	function do_main(){
		if($_POST['doReset']){ //form submission
			$this->form_submit();
			return "&nbsp;";
		}
			
		//set breadcrumbs
		$this->oPage->setBreadcrumbDetails(_kt('Reset dashboards'));
		 
		//render template
		$oTemplating =& KTTemplating::getSingleton();
		$oTemplate = $oTemplating->loadTemplate("resetDashboards");
		return $oTemplate->render(array());
	}

	/**
	 * Handles the form submission.
	 * Logs out all users, and then deletes all customised dashboards.
	 * Users will be given a new default dashboard when the log in again.
	 */
	function form_submit(){
		DBUtil::runQuery("DELETE FROM `active_sessions`");
		DBUtil::runQuery("DELETE FROM `system_settings` WHERE `name` LIKE 'dashboard-state-%'");
		$this->addInfoMessage(_kt("All dashboards reset to default dashboard"));
	}

}

?>