<?php
$id = isset( $_GET['id'] ) ? (int) $_GET['id'] : 0;
$page = isset( $_GET['page'] ) ? (int) ($_GET['page'] - 1) : 0;
$adult = isset( $_GET['adult'] ) ? true : false;
$_SESSION['adult'] = isset( $_SESSION['adult'] ) ? $_SESSION['adult'] : false;
if( $adult )
{
$_SESSION['adult'] = true;
}
if( !$sql->query("SELECT * FROM `" . CATALOGUE_SECTIONS . "` WHERE `id` = " . $id . ";") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( $sql->num_rows() < 1 )
{
redirect( gen_uri('index') );
}
$section = $sql->fetch_assoc();
$template_vars['header'] = array(
'TITLE' => output($section['name']),
'CSS' => $css
);
$template->set_vars('header', $template_vars['header']);
$template_vars['body'] = array();
if( $section['ao'] == 0 || $_SESSION['adult'] )
{
$query = "SELECT COUNT(*) FROM `" . CATALOGUE_SITES . "` WHERE `section_id` = " . $id . " AND ((`checked` = 1 AND `in_today_all` > 0) OR `owner` = 'admin');";
if( !$sql->query($query) )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$total = $sql->result($sql->result, 0);
$maxpage = maxpage($total, $config['catalogue_onpage']);
$limit = limit($page, $config['catalogue_onpage']);
if( !($qresult = $sql->query("SELECT *, ((`in_today_mp` * 100) / `in_today_all` ) AS `mp_percent` FROM `" . CATALOGUE_SITES . "` WHERE `section_id` = " . $id . " AND ((`checked` = 1 AND `in_today_all` > 0) OR `owner` = 'admin') ORDER BY `in_today_all` DESC, `mp_percent` DESC LIMIT " . $limit . ";")) )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
for( $i = 1; $site = $sql->fetch_assoc($qresult); $i++ )
{
$template->set_block_vars('body', 'site', array(
'PLACE' => $page * $config['catalogue_onpage'] + $i,
'LINK_OUT' => gen_uri('out', $site['id']),
'TITLE' => output( $site['title'] ),
'SITE' => output( $site['site'] ),
'DESCRIPTION' => output( $site['description'] ),
'IN' => $site['owner'] == 'user' ? $site['in_today_all'] . '/' . $site['in'] : 'N/A',
'OUT' => $site['out_today'] . '/' . $site['out']
));
}
$pages = pages($page, $maxpage, $config['catalogue_onpage'], 2, '', gen_uri($m, $id));
$template_vars['body'] = array(
'IN' => $lang['IN'],
'OUT' => $lang['OUT'],
'DESCRIPTION' => $lang['DESCRIPTION'],
'PAGES' => $pages,
'BACK_HREF' => gen_uri('index'),
'BACK' => $lang['BACK']
);
}
else
{
$template->load_template('templates/' . VERSION . '/message.tpl', 'body');
$template->set_vars('body', array('MESSAGE' => $lang['ADULT_CONTENT_WARNING']));
$link = array(
array('HREF' => gen_uri($m, $id, 'adult=true'), 'NAME' => $lang['Y']),
array('HREF' => gen_uri('index'), 'NAME' => $lang['N']),
array('HREF' => gen_uri('index'), 'NAME' => $lang['BACK'])
);
for($i = 0; $i < count($link); $i++)
{
$template->set_block_vars('body', 'link', $link[$i]);
}
}
$template_vars['footer'] = array(
'SWITCH_VERSION' => switch_version($m, $id, $nocache),
'COUNTER' => ''
);
$template->set_vars('body', $template_vars['body']);
$template->set_vars('footer', $template_vars['footer']);
?>