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

// 2005-09-04 K.OHWADA
// BUG 2932: dont work correctly when register_long_arrays = off

// 2004-01-20 K.OHWADA
// weblinks_pagenavi.php

// 2004-11-28 K.OHWADA
// add rss mode

//================================================================
// view link by mark ( mutual site, recommend site )
// 2004-10-20 K.OHWADA
//================================================================

include "header.php";

include_once $MODULE_ROOT."/class/pagenavi.php";
include_once $MODULE_ROOT."/class/weblinks_pagenavi.php";
$pagenavi = new weblinks_pagenavi();

$xoopsOption['template_main'] = $MODULE_DIRNAME."_viewmark.html";

include XOOPS_ROOT_PATH."/header.php";

assignIndex();

// BUG 2932: dont work correctly when register_long_arrays = off
$mark = get_get('mark');

if ($mark == 'rss')
{
	$title = _WLS_SITE_RSS;
}
elseif ($mark == 'mutual')
{
	$title = _WLS_SITE_MUTUAL;
}
else
{
	$mark = 'recommend';
	$title = _WLS_SITE_RECOMMEND;
}

$pagenavi->get_get_parm();
$orderby = $pagenavi->get_orderby();

$xoopsTpl->assign('lang_mark_title', $title);
$xoopsTpl->assign('mark',            $mark);

// --- link list ---
$tbl_category->getAll();

if ($mark == 'rss')
{
	$total = $tbl_link->getNumRssFlag();
}
else
{
	$total = $tbl_link->getNumByMark($mark);
}

$xoopsTpl->assign('mark_total', $total);

if ($total > 0)
{
	$limit  = $pagenavi->get_show();
	$offset = $pagenavi->get_start($total);

	if ($offset == -1)
	{
		echo "system error: total = $total <br>\n";
		include XOOPS_ROOT_PATH.'/footer.php';
		exit();
	}

	$xoopsTpl->assign('show_links', true);
	assignDisplayLink();

// link id array
	if ($mark == 'rss')
	{
		$lid_arr = $tbl_link->getLidArrayByRssFlag($orderby, $limit, $offset);
	}
	else
	{
		$lid_arr = $tbl_link->getLidArrayByMark($mark, $orderby, $limit, $offset);
	}

// each link
	foreach ($lid_arr as $lid) 
	{
		$record = $tbl_link->getRowByLid($lid);
		$link   = $tbl_link->makeDisplay($record);
		$xoopsTpl->append('links', $link);
	}

//if 2 or more items in result, show the sort menu
	if($total > 1)
	{
		$script = $MODULE_URL."/viewmark.php?mark=$mark";
		$navi   = $pagenavi->build_navi($script, $total);

		if ($navi == -1)
		{
			echo "system error: script = $script, total = $total <br>\n";
			include XOOPS_ROOT_PATH.'/footer.php';
			exit();
		}

		$pagenavi->assign_navi($xoopsTpl, $navi);
	}

}

include XOOPS_ROOT_PATH.'/footer.php';
exit();


?>
