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

// 2005-01-20 K.OHWADA
// link_broken_check.php -> link_check.php

// 2004-11-22 K.OHWADA
// use admin_header.php

//=========================================================
// check link broken
// 2004-10-20 K.OHWADA
//=========================================================

include 'admin_header.php';
include_once XOOPS_ROOT_PATH."/include/xoopscodes.php";
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
include_once $MODULE_ROOT."/class/xoops_form_extend.php";
include_once $MODULE_ROOT.'/class/class.rss_atom_parser_base.php';
include_once $MODULE_ROOT.'/class/class.rss_parser.php';
include_once $MODULE_ROOT.'/class/class.atom_parser.php';
include_once $MODULE_ROOT.'/class/rss_atom_collect.php';
include_once $MODULE_ROOT.'/class/link_check.php';
include_once $MODULE_ROOT."/admin/admin_functions.php";

// class
$check  =& link_check::getInstance();

$op = '';
if ( isset($_POST['op']) )  $op = $_POST['op'];

$limit  = 0;
$offset = 0;
if ( isset($_POST['limit']) )   $limit  = intval( $_POST['limit'] );
if ( isset($_POST['offset']) )  $offset = intval( $_POST['offset'] );

if ($limit  < 0)  $limit  = 0;
if ($offset < 0)  $offset = 0;

$total_link = $tbl_link->getNumAll();

xoops_cp_header();
echo "<h3>"._WEBLINKS_ADMIN_LINK_BROKEN_CHECK."</h3>\n";
printf(_WLS_THEREARE, $total_link);
echo "<br /><br />\n";
print_link_index();

print_form($limit, $offset);

// link check
if ($op == 'check')
{
	echo "<hr>\n";
	$check->check($limit, $offset);

// next
	$next = $offset + $limit;
	if (($limit > 0) && ($next < $total_link))
	{	print_form_next($limit, $next);	}

}

echo "<hr>\n";
xoops_cp_footer();
exit();


//---------------------------------------------------------
// function
//---------------------------------------------------------
function print_form($limit, $offset)
{
	echo "<br />\n";
	echo _WEBLINKS_ADMIN_RSS_REFRESH_NOTE."<br /><br />\n";
	echo _WEBLINKS_ADMIN_LINK_BROKEN_CHECK_CAUTION."<br />\n";

	$builder = new xoops_form_extend();
	$builder->start_theme_form( _WEBLINKS_ADMIN_LINK_BROKEN_CHECK, 'check' );
	$builder->add_hidden( 'op',  'check' );
	$builder->add_text( _WEBLINKS_ADMIN_LIMIT,  'limit',  $limit,  true );
	$builder->add_text( _WEBLINKS_ADMIN_OFFSET, 'offset', $offset, true );
	$builder->add_submit_button( '', 'post', _WEBLINKS_CHECK );
	$builder->display();

	echo "<h4>"._WEBLINKS_ADMIN_BROKEN_RESULT."</h4>\n";
	echo " - <a href='link_view.php?sortid=1'>"._WEBLINKS_ADMIN_LINK_BROKEN."</a><br /><br />\n";

}

function print_form_next($limit, $offset)
{
	$action = xoops_getenv('PHP_SELF');
	$submit = sprintf(_WEBLINKS_ADMIN_CHECK_NEXT, $limit);

?>
<br />
<form action='<?php echo $action; ?>' method='post'>
<input type='hidden' name='op' value='check'>
<input type='hidden' name='limit' value='<?php echo $limit; ?>'>
<input type='hidden' name='offset' value='<?php echo $offset; ?>'>
<input type='submit' value='<?php echo $submit; ?>'>
</form>
<?php

}

?>
