<?php
// $Id: config.php,v 1.4 2005/10/28 11:56:02 ohwada Exp $

// 2005-08-20 K.OHWADA
// BUG 2863: Fatal error: undefined method xoops_form_extend::start_tray()

// 2005-01-17 K.OHWADA
// print_form_save_rss_view()

// 2004-12-26 K.OHWADA
// tablefield for link_table

//================================================================
// config
// created from v0.9
// 2004-12-05 K.OHWADA
//================================================================

include_once 'admin_header.php';
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
include_once $MODULE_ROOT."/class/xoops_form_extend.php";

$op = '';
if ( isset($_POST['post']) && isset($_POST['op']) )
{
	$op = $_POST['op'];
}
elseif ( isset($_POST['set_rss_default']) )
{
	$op = 'set_rss_default';
}

if ( $op == 'save_auth' )
{
	$tbl_config->save_auth( $_POST ) or $eh->show("0013");

	redirect_header("index.php", 1, _WEBLINKS_AUTH_UPDATED);
	exit();

}
elseif ( $op == 'save_rss' )
{
	$tbl_config->save_rss( $_POST ) or $eh->show("0013");

	redirect_header("index.php", 1, _WEBLINKS_RSS_UPDATED);
	exit();

}
elseif ( $op == 'set_rss_default' )
{
	$arr = get_rss_default();
	$tbl_config->save_rss( $arr ) or $eh->show("0013");

	redirect_header("index.php", 1, _WEBLINKS_RSS_UPDATED);
	exit();

}
elseif ( $op == 'check_rss' )
{
	$white_arr = $tbl_config->check_rss_url( $_POST );

	if ($white_arr)
	{
		xoops_cp_header();
		echo "<h3>"._WEBLINKS_ADMIN_MODULE_CONFIG_2."</h3>\n";
		print_form_rss_white( $white_arr );
		print_form_rss_preview();
		xoops_cp_footer();
		exit();
	}

	$tbl_config->save_rss( $_POST ) or $eh->show("0013");

	redirect_header("index.php", 1, _WEBLINKS_RSS_UPDATED);
	exit();

}
elseif ( $op == 'save_rss_view' )
{
	$tbl_config->save_rss_view( $_POST ) or $eh->show("0013");

	redirect_header("index.php", 1, _WEBLINKS_RSS_UPDATED);
	exit();

}
elseif ( $op == 'save_post' )
{
	$tbl_config->save_post( $_POST ) or $eh->show("0013");

	redirect_header("index.php", 1, _WEBLINKS_POST_UPDATED);
	exit();

}
elseif ( $op == 'save_cat' )
{
	$tbl_config->save_category( $_POST ) or $eh->show("0013");

	redirect_header("index.php", 1, _WEBLINKS_CAT_UPDATED);
	exit();

}
else
{
	xoops_cp_header();
	print_top();

	print_form_auth();
	print_form_category();
	print_form_post();
	print_form_save_rss();
	print_form_rss_view();

}

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


//---------------------------------------------------------
// function
//---------------------------------------------------------
function print_top()
{
	global $xoops_module_mid;
	$url_preferences = XOOPS_URL.'/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod='.$xoops_module_mid;

	echo "<h3>"._WEBLINKS_ADMIN_MODULE_CONFIG_2."</h3>\n";

	echo "<table width='100%' border='0' cellspacing='1' class='outer'>";
	echo "<tr class='odd'><td>";
	echo " - <a href='index.php'>"._WEBLINKS_ADMIN_INDEX."</a>";
	echo "<br /><br />\n";
	echo " - <a href='".$url_preferences."'>"._WEBLINKS_ADMIN_MODULE_CONFIG_1."</a>";
	echo "<br /><br />\n";
	echo " - <b>"._WEBLINKS_ADMIN_MODULE_CONFIG_2."</b>";
	echo "<br /><br />\n";
	echo " --- <a href='#form_auth'>"._WEBLINKS_ADMIN_AUTH."</a>";
	echo "<br /><br />\n";
	echo " --- <a href='#form_cat'>"._WEBLINKS_ADMIN_CAT_SET."</a>";
	echo "<br /><br />\n";
	echo " --- <a href='#form_post'>"._WEBLINKS_ADMIN_POST."</a>";
	echo "<br /><br />\n";
	echo " --- <a href='#form_save_rss'>"._WEBLINKS_ADMIN_RSS."</a>";
	echo "<br /><br />\n";
	echo " --- <a href='#form_save_rss_view'>"._WEBLINKS_ADMIN_RSS_VIEW."</a>";
	echo "<br /><br />\n";	echo"</td></tr></table>\n";

}

//---------------------------------------------------------
// access control
//---------------------------------------------------------
function print_form_auth()
{
	global $weblinksConfig;
	$submit_arr      = $weblinksConfig['auth_submit_arr'];
	$submit_auto_arr = $weblinksConfig['auth_submit_auto_arr'];
	$modify_arr      = $weblinksConfig['auth_modify_arr'];
	$modify_auto_arr = $weblinksConfig['auth_modify_auto_arr'];
	$ratelink_arr    = $weblinksConfig['auth_ratelink_arr'];
	$passwd          = $weblinksConfig['use_passwd'];
	$use_ratelink    = $weblinksConfig['use_ratelink'];

	global $tbl_config;
	$group_list_1 = $tbl_config->xoops_group_list;
	$group_list_2 = $group_list_1;
	$group_list_2[ WEBLINKS_SUBMITTER_ID ] = _WEBLINKS_SUBMITTER;

	echo "<a name='form_acess'></a>\n";
	echo "<h4>"._WEBLINKS_ADMIN_AUTH."</h4>\n";
	echo "<div><li>"._WEBLINKS_ADMIN_AUTH_TEXT."</li></div><br />\n";

	$builder = new xoops_form_extend();
	$builder->set_param_select(5, true);

	$cap_submit         = $builder->make_caption( _WEBLINKS_AUTH_SUBMIT,      _WEBLINKS_AUTH_SUBMIT_DSC );
	$cap_submit_auto    = $builder->make_caption( _WEBLINKS_AUTH_SUBMIT_AUTO, _WEBLINKS_AUTH_SUBMIT_AUTO_DSC );
	$cap_modify         = $builder->make_caption( _WEBLINKS_AUTH_MODIFY,      _WEBLINKS_AUTH_MODIFY_DSC );
	$cap_modify_auto    = $builder->make_caption( _WEBLINKS_AUTH_MODIFY_AUTO, _WEBLINKS_AUTH_MODIFY_AUTO_DSC );
	$cap_auth_ratelink  = $builder->make_caption( _WEBLINKS_AUTH_RATELINK,    _WEBLINKS_AUTH_RATELINK_DSC );
	$cap_passwd         = $builder->make_caption( _WEBLINKS_USE_PASSWD,       _WEBLINKS_USE_PASSWD_DSC );
	$cap_use_ratelink   = $builder->make_caption( _WEBLINKS_USE_RATELINK,     _WEBLINKS_USE_RATELINK_DSC );

	$builder->start_theme_form( _WEBLINKS_ADMIN_AUTH, 'save_auth' );
	$builder->add_hidden( 'op', 'save_auth' );
	$builder->add_select_array( $cap_submit,      'auth_submit_arr',      $submit_arr,      $group_list_1 );
	$builder->add_select_array( $cap_submit_auto, 'auth_submit_auto_arr', $submit_auto_arr, $group_list_1 );
	$builder->add_select_array( $cap_modify,      'auth_modify_arr',      $modify_arr,      $group_list_2 );
	$builder->add_select_array( $cap_modify_auto, 'auth_modify_auto_arr', $modify_auto_arr, $group_list_2 );
	$builder->add_radio_yn( $cap_passwd, 'use_passwd', $passwd );
	$builder->add_radio_yn( $cap_use_ratelink, 'use_ratelink', $use_ratelink );
	$builder->add_select_array( $cap_auth_ratelink,    'auth_ratelink_arr',    $ratelink_arr,    $group_list_1 );
	$builder->add_submit_button( '', 'post', _WEBLINKS_UPDATE );
	$builder->display();

}


//---------------------------------------------------------
// rss control
//---------------------------------------------------------
function print_form_save_rss()
{
	global $weblinksConfig;
	global $myts;

	$arr = array(
		'rss_mode_auto'    => $weblinksConfig['rss_mode_auto'],
		'rss_mode_data'    => $weblinksConfig['rss_mode_data'],
		'rss_cache_time'   => $weblinksConfig['rss_cache_time'],
		'rss_limit'        => $weblinksConfig['rss_limit'],
		'rss_site'         => $myts->makeTareaData4Save( $weblinksConfig['rss_site'] ),
		'rss_black'        => $myts->makeTareaData4Save( $weblinksConfig['rss_black'] ),
		'rss_white'        => $myts->makeTareaData4Save( $weblinksConfig['rss_white'] ),
	);

	echo "<a name='form_save_rss'></a>\n";
	echo "<h4>"._WEBLINKS_ADMIN_RSS."</h4>\n";

	print_form_rss_com('check_rss', $arr);
}

function print_form_rss_com($form_name, $arr)
{

	$rss_auto    = $arr['rss_mode_auto'];
	$rss_data    = $arr['rss_mode_data'];
	$rss_cache   = $arr['rss_cache_time'];
	$rss_limit   = $arr['rss_limit'];
	$rss_site    = $arr['rss_site'];
	$rss_black   = $arr['rss_black'];
	$rss_white   = $arr['rss_white'];

	$opt_data = array(
		0 => 'ATOM FEED',
		1 => 'XML'
		);

	$builder = new xoops_form_extend();
	$builder->set_param_textarea(5, 50);

	$cap_auto    = $builder->make_caption( _WEBLINKS_RSS_MODE_AUTO,    _WEBLINKS_RSS_MODE_AUTO_DSC );
	$cap_data    = $builder->make_caption( _WEBLINKS_RSS_MODE_DATA,    _WEBLINKS_RSS_MODE_DATA_DSC );
	$cap_cache   = $builder->make_caption( _WEBLINKS_RSS_CACHE,    _WEBLINKS_RSS_CACHE_DSC );
	$cap_limit   = $builder->make_caption( _WEBLINKS_RSS_LIMIT,    _WEBLINKS_RSS_LIMIT_DSC );
	$cap_site    = $builder->make_caption( _WEBLINKS_RSS_SITE,     _WEBLINKS_RSS_SITE_DSC );
	$cap_black   = $builder->make_caption( _WEBLINKS_RSS_BLACK,    _WEBLINKS_RSS_BLACK_DSC );
	$cap_white   = $builder->make_caption( _WEBLINKS_RSS_WHITE,    _WEBLINKS_RSS_WHITE_DSC );

	$builder->start_theme_form( _WEBLINKS_ADMIN_RSS, $form_name );
	$builder->add_hidden( 'op', $form_name );
	$builder->add_radio_yn(    $cap_auto,  'rss_mode_auto',  $rss_auto);
	$builder->add_radio_array( $cap_data,  'rss_mode_data',  $rss_data, $opt_data);
	$builder->add_text( $cap_cache, 'rss_cache_time', $rss_cache);
	$builder->add_text( $cap_limit, 'rss_limit',      $rss_limit);
	$builder->add_textarea( $cap_site,  'rss_site',  $rss_site);
	$builder->add_textarea( $cap_black, 'rss_black', $rss_black);
	$builder->add_textarea( $cap_white, 'rss_white', $rss_white);

//	$builder->add_submit_button( '', 'post', _WEBLINKS_UPDATE );

// BUG 2863: Fatal error: undefined method xoops_form_extend::start_tray()
//	$builder->start_tray('');
//	$builder->add_tray_submit_button('', 'post',            _WEBLINKS_UPDATE );
//	$builder->add_tray_submit_button('', 'set_rss_default', _WEBLINKS_SET_DEFAULT );
//	$builder->add_element_tray();

	$builder->add_submit_submit_button('', 'post', _WEBLINKS_UPDATE, 'set_rss_default', _WEBLINKS_SET_DEFAULT );

	$builder->display();

}

function print_form_rss_preview()
{
	global $myts;

	$arr = array(
		'rss_mode_auto'    => intval( $_POST['rss_mode_auto'] ),
		'rss_mode_data'    => intval( $_POST['rss_mode_data'] ),
		'rss_cache_time'   => intval( $_POST['rss_cache_time'] ),
		'rss_limit'        => intval( $_POST['rss_limit'] ),
		'rss_site'         => $myts->makeTareaData4PreviewInForm( $_POST['rss_site'] ),
		'rss_black'        => $myts->makeTareaData4PreviewInForm( $_POST['rss_black'] ),
		'rss_white'        => $myts->makeTareaData4PreviewInForm( $_POST['rss_white'] ),
	);

	print_form_rss_com('save_rss', $arr);

}

function print_form_rss_white( $white_arr )
{
	$list = '';

	foreach ($white_arr as $value)
	{
		$list .= $value."\n";
	}

	echo "<h4><font color='red'>"._WEBLINKS_RSS_URL_CHECK."</font></h4><br />\n";
	echo _WEBLINKS_RSS_URL_CHECK_DSC."<br /><br />\n";

	$builder = new xoops_form_extend();

	$builder->start_theme_form( _WEBLINKS_RSS_WHITE, 'rss_white' );
	$builder->add_textarea( '', 'rss_white', $list);
	$builder->display();

}

function get_rss_default()
{
	global $XOOPS_LANGUAGE;
	if ($XOOPS_LANGUAGE == 'japanese')
	{
		$rss_site = "http://rss.sf.livedoor.com/search?q=xoops&sf=update_date&start=0\nhttp://bulkfeeds.net/app/search2.rdf?q=xoops\nhttp://naoya.dyndns.org/feedback/app/rss?keyword=xoops\n";
		$rss_black = "http://blog.livedoor.jp/[a-z]{10,}/\nhttp://[a-z]{10,}.seesaa.net/\n";
	}
	else
	{
		$rss_site  = '';
		$rss_black = '';
	}

	$arr = array(
		'rss_mode_auto'    => 1,
		'rss_mode_data'    => 0,
		'rss_cache_time'   => 24,
		'rss_limit'        => 1000,
		'rss_site'         => $rss_site,
		'rss_black'        => $rss_black,
		'rss_white'        => '',
	);	

	return $arr;
}

//---------------------------------------------------------
// rss view control
//---------------------------------------------------------
function print_form_rss_view()
{
	global $weblinksConfig;

	echo "<a name='form_save_rss_view'></a>\n";
	echo "<h4>"._WEBLINKS_ADMIN_RSS_VIEW."</h4>\n";

	$rss_mode_t  = $weblinksConfig['rss_mode_title'];
	$rss_mode_c  = $weblinksConfig['rss_mode_content'];
	$rss_new     = $weblinksConfig['rss_new'];
	$rss_perpage = $weblinksConfig['rss_perpage'];
	$rss_num_c   = $weblinksConfig['rss_num_content'];
	$rss_max_c   = $weblinksConfig['rss_max_content'];
	$rss_max_s   = $weblinksConfig['rss_max_summary'];

	$builder = new xoops_form_extend();

	$cap_mode_t  = $builder->make_caption( _WEBLINKS_RSS_MODE_TITLE,   _WEBLINKS_RSS_MODE_TITLE_DSC );
	$cap_mode_c  = $builder->make_caption( _WEBLINKS_RSS_MODE_CONTENT, _WEBLINKS_RSS_MODE_CONTENT_DSC );
	$cap_num_c   = $builder->make_caption( _WEBLINKS_RSS_NUM_CONTENT,  _WEBLINKS_RSS_NUM_CONTENT_DSC );
	$cap_max_c   = $builder->make_caption( _WEBLINKS_RSS_MAX_CONTENT,  _WEBLINKS_RSS_MAX_CONTENT_DSC );
	$cap_max_s   = $builder->make_caption( _WEBLINKS_RSS_MAX_SUMMARY,  _WEBLINKS_RSS_MAX_SUMMARY_DSC );
	$cap_new     = $builder->make_caption( _WEBLINKS_RSS_NEW,      _WEBLINKS_RSS_NEW_DSC );
	$cap_perpage = $builder->make_caption( _WEBLINKS_RSS_PERPAGE,  _WEBLINKS_RSS_PERPAGE_DSC );

	$builder->start_theme_form( _WEBLINKS_ADMIN_RSS_VIEW, 'save_rss_view' );
	$builder->add_hidden( 'op', 'save_rss_view' );
	$builder->add_radio_yn( $cap_mode_t,  'rss_mode_title',   $rss_mode_t);
	$builder->add_radio_yn( $cap_mode_c,  'rss_mode_content', $rss_mode_c);
	$builder->add_text( $cap_new,     'rss_new',          $rss_new);
	$builder->add_text( $cap_perpage, 'rss_perpage',      $rss_perpage);
	$builder->add_text( $cap_num_c,   'rss_num_content',  $rss_num_c);
	$builder->add_text( $cap_max_c,   'rss_max_content',  $rss_max_c);
	$builder->add_text( $cap_max_s,   'rss_max_summary',  $rss_max_s);
	$builder->add_submit_button('', 'post', _WEBLINKS_UPDATE );

	$builder->display();

}


//---------------------------------------------------------
// use link field
//---------------------------------------------------------
function print_form_post()
{

	global $weblinksConfig;
	$post_url     = $weblinksConfig['post_url'];
	$post_desc    = $weblinksConfig['post_desc'];
	$post_banner  = $weblinksConfig['post_banner'];
	$post_rss_url = $weblinksConfig['post_rss_url'];
	$post_name    = $weblinksConfig['post_name'];
	$post_mail    = $weblinksConfig['post_mail'];
	$post_company = $weblinksConfig['post_company'];
	$post_zip     = $weblinksConfig['post_zip'];
	$post_state   = $weblinksConfig['post_state'];
	$post_city    = $weblinksConfig['post_city'];
	$post_addr    = $weblinksConfig['post_addr'];
	$post_addr2   = $weblinksConfig['post_addr2'];
	$post_tel     = $weblinksConfig['post_tel'];
	$post_fax     = $weblinksConfig['post_fax'];
	$post_usercomment = $weblinksConfig['post_usercomment'];
	$type_desc    = $weblinksConfig['type_desc'];
	$check_double = $weblinksConfig['check_double'];

	$opt = array(
		0 => " "._WEBLINKS_NO_USE."&nbsp; ",
		1 => " "._WEBLINKS_USE."&nbsp; ",
		2 => " "._WEBLINKS_INDISPENSABLE."&nbsp; ",
		);

	echo "<a name='form_post'></a>\n";
	echo "<h4>"._WEBLINKS_ADMIN_POST."</h4>\n";
	echo "<div>";
	echo "<li>"._WEBLINKS_ADMIN_POST_TEXT_1."</li>\n";
	echo "<li>"._WEBLINKS_ADMIN_POST_TEXT_2."</li>\n";
	echo "<li>"._WEBLINKS_ADMIN_POST_TEXT_3."</li>\n";
	echo "</div><br />\n";

	$builder = new xoops_form_extend();

	$cap_type_desc    = $builder->make_caption( _WEBLINKS_TYPE_DESC,    _WEBLINKS_TYPE_DESC_DSC );
	$cap_check_double = $builder->make_caption( _WEBLINKS_CHECK_DOUBLE, _WEBLINKS_CHECK_DOUBLE_DSC );

	$builder->start_theme_form( _WEBLINKS_ADMIN_POST, 'save_post' );
	$builder->add_hidden( 'op', 'save_post' );
	$builder->add_label( "* "._WLS_SITETITLE." *", " "._WEBLINKS_INDISPENSABLE );
	$builder->add_label( "* "._WLS_CATEGORY." *",  " "._WEBLINKS_INDISPENSABLE );
	$builder->add_radio_array( "* "._WLS_SITEURL." *",      'post_url',   $post_url,  $opt );
	$builder->add_radio_array( "* "._WLS_DESCRIPTION." *",  'post_desc',  $post_desc, $opt );
	$builder->add_radio_array( _WLS_BANNERURL, 'post_banner',  $post_banner,  $opt );
	$builder->add_radio_array( _WLS_RSS_URL,   'post_rss_url', $post_rss_url, $opt );
	$builder->add_radio_array( _WLS_NAME,      'post_name',    $post_name,    $opt );
	$builder->add_radio_array( _WLS_EMAIL,     'post_mail',    $post_mail,    $opt );
	$builder->add_radio_array( _WLS_COMPANY,   'post_company', $post_company, $opt );
	$builder->add_radio_array( _WLS_ZIP,       'post_zip',     $post_zip,     $opt );
	$builder->add_radio_array( _WLS_STATE,     'post_state',   $post_state,   $opt );
	$builder->add_radio_array( _WLS_CITY,      'post_city',    $post_city,    $opt );
	$builder->add_radio_array( _WLS_ADDR,      'post_addr',    $post_addr,    $opt );
	$builder->add_radio_array( _WLS_ADDR2,     'post_addr2',   $post_addr2,   $opt );
	$builder->add_radio_array( _WLS_TEL,       'post_tel',     $post_tel,     $opt );
	$builder->add_radio_array( _WLS_FAX,       'post_fax',     $post_fax,     $opt );
	$builder->add_radio_array( _WLS_USER_COMMENT, 'post_usercomment', $post_usercomment, $opt );
	$builder->add_radio_yn( $cap_type_desc,    'type_desc',    $type_desc );
	$builder->add_radio_yn( $cap_check_double, 'check_double', $check_double );
	$builder->add_submit_button( '', 'post', _WEBLINKS_UPDATE );
	$builder->display();

}


//---------------------------------------------------------
// category
//---------------------------------------------------------
function print_form_category()
{
	global $weblinksConfig;
	$cat_sel        = $weblinksConfig['cat_sel'];
	$cat_sub        = $weblinksConfig['cat_sub'];
	$cat_img_mode   = $weblinksConfig['cat_img_mode'];
	$cat_img_width  = $weblinksConfig['cat_img_width'];
	$cat_img_height = $weblinksConfig['cat_img_height'];

	$opt_img_mode = array(
		0 => " "._WEBLINKS_CAT_IMG_MODE_0."&nbsp; ",
		1 => " "._WEBLINKS_CAT_IMG_MODE_1."&nbsp; ",
		2 => " "._WEBLINKS_CAT_IMG_MODE_2."&nbsp; ",
		);

	echo "<a name='form_cat'></a>\n";
	echo "<h4>"._WEBLINKS_ADMIN_CAT_SET."</h4>\n";

	$builder = new xoops_form_extend();

	$cap_sel        = $builder->make_caption( _WEBLINKS_CAT_SEL,        _WEBLINKS_CAT_SEL_DSC );
	$cap_sub        = $builder->make_caption( _WEBLINKS_CAT_SUB,        _WEBLINKS_CAT_SUB_DSC );
	$cap_img_mode   = $builder->make_caption( _WEBLINKS_CAT_IMG_MODE,   _WEBLINKS_CAT_IMG_MODE_DSC );
	$cap_img_width  = $builder->make_caption( _WEBLINKS_CAT_IMG_WIDTH,  _WEBLINKS_CAT_IMG_SIZE_DSC );
	$cap_img_height = $builder->make_caption( _WEBLINKS_CAT_IMG_HEIGHT, _WEBLINKS_CAT_IMG_SIZE_DSC );

	$builder->start_theme_form( _WEBLINKS_ADMIN_CAT_SET, 'save_cat' );
	$builder->add_hidden( 'op', 'save_cat' );
	$builder->add_text( $cap_sel, 'cat_sel',  $cat_sel);
	$builder->add_text( $cap_sub, 'cat_sub',  $cat_sub);
	$builder->add_radio_array( $cap_img_mode, 'cat_img_mode', $cat_img_mode, $opt_img_mode);
	$builder->add_text( $cap_img_width,  'cat_img_width',  $cat_img_width  );
	$builder->add_text( $cap_img_height, 'cat_img_height', $cat_img_height );
	$builder->add_submit_button( '', 'post', _WEBLINKS_UPDATE );
	$builder->display();

}

?>
