<?php
// $Id: index.php,v 1.5 2006/09/11 07:59:26 ohwada Exp $

// 2006-09-01 K.OHWADA
// use XoopsGTicket

// 2006-07-08 K.OHWADA
// use config_base_handler.php etc
// use check_version() for v0.30
// description in main page

// 2006-06-04 K.OHWADA
// change to contant RSSC_ROOT_PATH
// use check_token()

//=========================================================
// RSS Center Module
// 2006-01-01 K.OHWADA
//=========================================================

include_once 'admin_header.php';

include_once XOOPS_ROOT_PATH.'/modules/happy_linux/class/config_base_handler.php';
include_once XOOPS_ROOT_PATH.'/modules/happy_linux/class/config_define_handler.php';
include_once XOOPS_ROOT_PATH.'/modules/happy_linux/class/config_store_handler.php';

include_once RSSC_ROOT_PATH.'/include/rssc_version.php';
include_once RSSC_ROOT_PATH.'/class/rssc_config_define.php';
include_once RSSC_ROOT_PATH.'/class/rssc_config_handler.php';
include_once RSSC_ROOT_PATH.'/admin/admin_config_class.php';

$DIR_CONFIG = RSSC_ROOT_PATH.'/cache';

// class
$config_form  =& admin_config_form::getInstance();
$config_store =& admin_config_store::getInstance();

$op = $config_form->get_post_get_op();

if ($op == 'save')
{
	if( !$config_form->check_token() ) 
	{
		xoops_cp_header();
		xoops_error( "Token Error" );
		echo "<br />\n";
		echo $config_form->get_token_error(1);
		echo "<br />\n";
	}
	else
	{
		$config_store->save();
		redirect_header('index.php', 2, _AM_RSSC_DBUPDATED);
	}
}
elseif ($op == 'init')
{
	if( !$config_form->check_token() ) 
	{
		xoops_cp_header();
		xoops_error( "Token Error" );
		echo "<br />\n";
		echo $config_form->get_token_error(1);
		echo "<br />\n";
	}
	else
	{
		$config_store->init();
		redirect_header('index.php', 2, _AM_RSSC_DBUPDATED);
	}
}
elseif ($op == 'upgrade')
{
	if( !$config_form->check_token() ) 
	{
		xoops_cp_header();
		xoops_error( "Token Error" );
		echo "<br />\n";
		echo $config_form->get_token_error(1);
		echo "<br />\n";
	}
	else
	{
		$config_store->upgrade();
		redirect_header('index.php', 2, _AM_RSSC_DBUPDATED);
	}
}
else
{
	xoops_cp_header();
}

rssc_admin_print_header();

if ( !$config_store->check_init() )
{
	xoops_error( _AM_RSSC_INIT_NOT );
	$config_form->print_form_init();
}
elseif ( !$config_store->check_version() )
{
	$title = sprintf( _AM_RSSC_VERSION_NOT, RSSC_VERSION );
	xoops_error( $title );
	$config_form->print_form_upgrade();
}
elseif ( !is_writable( $DIR_CONFIG ) )
{
	xoops_error( _AM_RSSC_WARNING_NOT_WRITABLE );
	echo "<br />\n";
	echo "$DIR_CONFIG <br /><br />\n";
}
else
{
	rssc_admin_print_menu();
	echo "<h4>"._MI_RSSC_ADMENU_CONFIG."</h4>\n";
	$config_form->set_submit_value( _SAVE );
	$config_form->init_form();

	echo "<h4>"._AM_RSSC_FORM_BASIC."</h4>\n";
	echo _AM_RSSC_FORM_BASIC_DESC."<br />\n";
	$config_form->set_form_title( _AM_RSSC_FORM_BASIC );
	$config_form->show_by_catid( 1 );

	echo "<h4>"._AM_RSSC_FORM_MAIN."</h4>\n";
	echo _AM_RSSC_FORM_MAIN_DESC."<br />\n";

// description in main page
	$config_form->set_form_title( _AM_RSSC_FORM_MAIN );
	$config_form->show_by_catid( 3 );
	echo "<br />\n";

	$config_form->show_main();

	echo "<h4>"._AM_RSSC_FORM_BLOCK."</h4>\n";
	echo _AM_RSSC_FORM_BLOCK_DESC."<br />\n";
	$config_form->show_block();

	echo "<h4>"._AM_RSSC_FORM_BIN."</h4>\n";
	echo _AM_RSSC_FORM_BIN_DESC."<br />\n";
	$config_form->set_form_title( _AM_RSSC_FORM_BIN );
	$config_form->show_by_catid( 2 );

}

rssc_admin_print_footer();
xoops_cp_footer();
exit();
// --- main end ---


?>