<?php

/*
////////////////////////////////////////////////////////////////////////////////
// JohnCMS                Mobile Content Management System                    //
// Project site:          http://johncms.com                                  //
// Support site:          http://gazenwagen.com                               //
////////////////////////////////////////////////////////////////////////////////
// Lead Developer:        Oleg Kasyanov   (AlkatraZ)  alkatraz@gazenwagen.com //
// Development Team:      Eugene Ryabinin (john77)    john77@gazenwagen.com   //
//                        Dmitry Liseenko (FlySelf)   flyself@johncms.com     //
////////////////////////////////////////////////////////////////////////////////
*/

defined('_IN_JOHNCMS') or die('Error: restricted access');

$textl = $lng['events'];
require('../incfiles/head.php');
echo '<div class="phdr"><b>' . $lng['events'] . '</b> | <a href="profile.php?act=events_set">' . $lng['settings'] . '</a></div>';
$filter = Functions::eventsFilterDef();
Functions::eventsReset();
$out = array();
$sql = '';
foreach ($filter as $key => $name) {
	if($name == 0)
		$out[] = "`type_events`!='".$key."'";
}
if(count($out) > 0)
	$sql = "AND (".implode(' AND ',$out).")";
$total = mysql_result(mysql_query("SELECT COUNT(*)
		FROM `cms_contact`
		LEFT JOIN `cms_events` 
		ON `cms_contact`.`from_id`=`cms_events`.`user_id`
		WHERE `cms_contact`.`user_id`='" . $user_id . "'
		AND `cms_events`.`user_id`!='" . $user_id . "'
		AND `cms_events`.`from_id`!='" . $user_id . "'
		AND `cms_contact`.`type`='2'
		AND `cms_contact`.`friends`='1'
		AND `cms_contact`.`ban`!='1'$sql
	"), 0);
if($total) {
		$query = mysql_query("SELECT `cms_events`.`time` as `etime`, `cms_events`.*
		FROM `cms_contact`
		LEFT JOIN `cms_events` 
		ON `cms_contact`.`from_id`=`cms_events`.`user_id`
		WHERE `cms_contact`.`user_id`='" . $user_id . "'
		AND `cms_contact`.`type`='2'
		AND `cms_events`.`user_id`!='" . $user_id . "'
		AND `cms_events`.`from_id`!='" . $user_id . "'
		AND `cms_contact`.`friends`='1'
		AND `cms_contact`.`ban`!='1'$sql
		ORDER BY `cms_events`.`time` DESC
		LIMIT " . $start . "," . $kmess);
	for ($i = 0; ($row = mysql_fetch_assoc($query)) !== FALSE; ++$i) {
		echo ($i % 2) ? '<div class="list2">' : '<div class="list1">';
		echo '['.functions::display_date($row['etime']).'] '.functions::checkout($row['text'], 1, 1);
		echo '</div>';
	}
	echo '<div class="phdr">' . $lng['total'] . ': ' . $total . '</div>';
	if ($total > $kmess) {
		echo'<p>' . functions::display_pagination('profile.php?act=events&amp;', $start, $total, $kmess) . '</p>' .
		'<p><form action="profile.php" method="get">' .
		'<input type="hidden" name="act" value="events"/>' .
		'<input type="text" name="page" size="2" value="' . $page . '"/>' .
		'<input type="submit" value="' . $lng['to_page'] . ' &gt;&gt;"/></form></p>';
	}
} else {
	echo '<div class="rmenu">Список пуст</div>';
}
