<?php
class links_adult
{
	var $mydirname;
	var $controller_name;
	var $Links;

	var $nav_html = NULL;
	var $navinfo  = NULL;

	/** Constructor
	 *
	**/
	function __construct($mydirname)
	{
		$this->mydirname = $mydirname;
		$this->controller_name = str_replace('links_', '', get_class($this));
		$this->Links = links_Base::getInstance($this->mydirname);
		$this->Links->setControllerName($this->controller_name);
		$this->Links->breadcrumbs();

		if (! $this->Links->isadmin) {
			$this->Links->linksRedirectHeader(XOOPS_URL . '/user.php', 2, _NOPERM);
			exit();
		}
	}

	function index($offset = 0)
	{
		$per_page = 50;

		$this->Links->setWhere('adult', 1, '=');
		$numrows = $this->Links->getCount() ;

		$links = array();
		if ($numrows > 0) {
			$this->Links->setWhere('l.adult', 1, '=');
			$this->Links->setOrder('date DESC');
			$links = $this->Links->getDatas($per_page, $offset);

			if ($numrows > $per_page) {
				$this->_set_navigation($numrows, $per_page, $offset);
			}
		}

		$data = array(
			'links'    => $links,
			'nav'      => $this->nav_html,
			'navinfo'  => $this->navinfo,
			'is_adult' => TRUE,
		);

		$template = $this->Links->getTemplatePrefix() ."_future.html";
		$this->Links->view($template, $data);
	}

	function _set_navigation($numrows, $per_page, $offset = 0)
	{
		$extra_arg = array(
				'p' => $offset,
				'c' => $this->controller_name,
				'm' => 'index'
			);

		$nav = new links_PageNav($numrows, $per_page, $extra_arg, $this->Links->uri_option_arr, $this->mydirname);
		$this->nav_html = $nav->renderNav(5);

		$last = $offset + $per_page;
		if ($last > $numrows) $last = $numrows;
		$this->navinfo = sprintf(_MD_LINKS_NAVINFO, $offset + 1, $last, $numrows);
	}

}
