<?php
/* $Id: system.php,v 1.14 2003/12/10 10:44:43 k-fish Exp $ */
$myEnv["module"] = "admin";
$myEnv['stdsmenu'] = false;
$myEnv["output"] = "html";

include("../../config.inc.php");
include(INCLUDEPATH . "container.inc.php");

// adding file revision into global array
revisionInit("\$Revision: 1.14 $", __FILE__);

require_once('inc/SystemTools.class.php');

if(isset($_POST["action"]) && isset($_POST["config"])) {
    queryRights2("root_modules_admin_systemtools_sysconfedit");

    if ($fp = @fopen(ROOTPATH."/config.inc.php", "w")) {
        if(get_magic_quotes_gpc())
	    fwrite($fp, stripslashes($_POST['config']));
	else
	    fwrite($fp, $_POST['config']);
	fclose($fp);
	chmod(ROOTPATH."/config.inc.php", octdec(600));
	$GLOBALS['notify']->message(Lang::getLanguageString('writeconfigsuccess'), NOTIFY_SCREEN);
	$GLOBALS['log']->message(MGW_NOTICE, 'config.inc.php written to filesystem.', __LINE__, __FILE__);
    }
    else{
	$GLOBALS['notify']->message(Lang::getLanguageString('writeconfigerror'), NOTIFY_SCREEN);
	$GLOBALS['log']->message(MGW_WARNING, 'config.inc.php not written to filesystem.', __LINE__, __FILE__);
    }
}
elseif (isset($_GET["action"]) && $_GET["action"] == "seqcheck") {
    queryRights2("root_modules_admin_systemtools_sequencetablecheck");

    $res = SystemTools::seqCheck();
    $GLOBALS['log']->message(MGW_NOTICE, 'Sequence check has been run.', __LINE__, __FILE__);

    $smarty->assign('errors',$res['errors']);
    $smarty->assign('result',$res['result']);
    $smarty->display('system_seqcheck.tpl');
    exit();
} elseif (isset($_GET["action"]) && $_GET["action"] == "sysinfo") {
    queryRights2("root_modules_admin_systemtools_systeminformation");

    $res = showSystemInfo();
    $GLOBALS['log']->message(MGW_NOTICE, 'System info has been fetched.', __LINE__, __FILE__);

    $smarty->assign('result',$res);
    $smarty->display('system_sysinfo.tpl');
    exit();
} elseif (isset($_GET["action"]) && $_GET["action"] == "sysconfedit") {
    queryRights2("root_modules_admin_systemtools_sysconfedit");

    if (is_writeable(ROOTPATH."/config.inc.php")) {
	$smarty->assign('config', implode("",file(ROOTPATH."/config.inc.php")));
	$smarty->display('system_sysconfedit.tpl');
	exit();
    }
    else
	$GLOBALS['notify']->message(Lang::getLanguageString('confignotwritable'), NOTIFY_SCREEN);
}

$smarty->display("system.tpl");
?>
