View file includes/modules/index.php

File size: 4.06Kb
<?php
$id = isset( $_GET['id'] ) ? (int) $_GET['id'] : 0;

if( $id )
{
	$_SESSION['click'] = isset( $_SESSION['click'] ) ? (int) $_SESSION['click'] : NULL;
	$_SESSION['click_ip'] = isset( $_SESSION['click_ip'] ) ? (string) $_SESSION['click_ip'] : NULL;
	$_SESSION['click_ua'] = isset( $_SESSION['click_ua'] ) ? (string) $_SESSION['click_ua'] : NULL;
	$_SESSION['mp'] = isset( $_SESSION['mp'] ) ? (int) $_SESSION['mp'] : 0;

	$crc_32 = crc32( $_SERVER['REMOTE_ADDR'] . $ua );

	if( $id === $_SESSION['click'] && ($_SESSION['click_ip'] === $_SERVER['REMOTE_ADDR'] && $_SESSION['click_ua'] === $ua) )
	{
		if( $_SESSION['mp'] )
		{
			$query = "UPDATE `" . CATALOGUE_SITES . "` SET `in_today_all` = `in_today_all` + 1, `in_today_mp` = `in_today_mp` + 1, `in` = `in` + 1 WHERE `id` = " . $id . ";";
		}
		else
		{
			$query = "UPDATE `" . CATALOGUE_SITES . "` SET `in_today_all` = `in_today_all` + 1, `in` = `in` + 1 WHERE `id` = " . $id . ";";
		}

		if( !$sql->query($query) )
		{
			put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
		}

		if( !$sql->query("INSERT INTO `" . CATALOGUE_CLICKS . "` SET `site_id` = " . $id . ", `provider_id` = " . $_SESSION['mp'] . ", `dt` = UNIX_TIMESTAMP(), `crc32` = " . $crc_32 . ", `ip` = INET_ATON('" . $_SERVER['REMOTE_ADDR'] . "'), `ua` = '" . $sql->escape_string($ua) . "';") )
		{
			put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
		}

		$_SESSION['click_time'] = time();

		unset( $_SESSION['click'], $_SESSION['click_ip'], $_SESSION['click_ua'] );
	}
}

$template_vars['header'] = array(
'TITLE' => $lang['MAIN_TITLE'],
'CSS' => $css
);

$template->set_vars('header', $template_vars['header']);

$query = 
"SELECT `" . CATALOGUE_SECTIONS . "`.*, `qty_tab`.`qty` AS `sites` FROM `" . CATALOGUE_SECTIONS . "`
	LEFT JOIN (
			SELECT  `" . CATALOGUE_SECTIONS . "`.`id` , COUNT(`" . CATALOGUE_SITES . "`.`id`) AS `qty` FROM `" . CATALOGUE_SECTIONS . "`
			LEFT JOIN `" . CATALOGUE_SITES . "`  ON  (`" . CATALOGUE_SITES . "`.`section_id` = `" . CATALOGUE_SECTIONS . "`.`id` AND ((`" . CATALOGUE_SITES . "`.`in_today_all` > 0 AND `" . CATALOGUE_SITES . "`.`checked` = 1) OR `" . CATALOGUE_SITES . "`.`owner` = 'admin')) GROUP BY `" . CATALOGUE_SECTIONS . "`.`id`
		) AS `qty_tab`
	ON `" . CATALOGUE_SECTIONS . "` .`id` = `qty_tab`.`id`
ORDER BY `" . CATALOGUE_SECTIONS . "`.`reg_access` DESC, `" . CATALOGUE_SECTIONS . "`.`name` ASC";

if( !($qresult = $sql->query($query)) )
{
	put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}

while( $section = $sql->fetch_assoc($qresult) )
{
	$template->set_block_vars('body', 'sections', array(
	'HREF' => gen_uri('section', $section['id']),
	'NAME' => output( $section['name'] ),
	'SITES' => $section['sites']
	));
}

if( !$sql->query("SELECT COUNT(*) FROM `" . CATALOGUE_SESSIONS . "` WHERE `dt` > UNIX_TIMESTAMP() - 300;") )
{
	put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}

$online = $sql->result($sql->result, 0);

$template_vars['body'] = array(
'LOGO' => "<img src='" . PATH . "/i/logo.gif' alt='Bang!' />",
'CATALOGUE_TITLE' =>  output( $config['catalogue_title'] ),
'SEARCH_HREF' => gen_uri('search'),
'SEARCH' => $lang['SEARCH'],
'LOGIN_HREF' => gen_uri('authentication'),
'LOGIN' => $lang['LOGIN'],
'REG_HREF' => gen_uri('rules', '', 'registration'),
'REG' => $lang['REGISTRATION'],
'STAT_HREF' => gen_uri('statistics'),
'STAT' => $lang['STAT'],
'RULES_HREF' => gen_uri('rules'),
'RULES' => $lang['RULES'],
'FEEDBACK_HREF' => gen_uri('feedback'),
'FEEDBACK' => $lang['FEEDBACK'],
'ONLINE_HREF' => gen_uri('online'),
'ONLINE' => $lang['ONLINE'],
'ONLINE_QUANTITY' => $online,
'ADV_HREF' => gen_uri('advertising'),
'ADV' => $lang['ADV'],
'SWITCH_LANGUAGE' => switch_language($m, '', $nocache)
);

$template_vars['footer'] = array(
'SWITCH_VERSION' => switch_version($m, '', $nocache),
'COUNTER' => ''
);

$template->set_vars('body', $template_vars['body']);
$template->set_vars('footer', $template_vars['footer']);
?>