<?php
if ( !defined( 'SMARTY_DIR' ) ) {
	include_once( '../init.php' );
}

include ( 'sessioninc.php' );

define( 'PAGE_ID', 'event_mgt' );
if ( !checkAdminPermission( PAGE_ID ) ) {
	header( 'location: not_authorize.php' );
	exit;
}

if ($_POST['action'] == get_lang('Approve')) {
/* approve */

	$osDB->query( 'update ! set enabled = ? where id = ?', array( EVENTS_TABLE, 'Y', $_POST['id'] ) );

	$errid = EVENT_APPROVED;

} elseif ($_POST['action'] == get_lang('reject')) {
/* Remove and remove */
	$osDB->query( 'delete from ! where id = ?',array( EVENTS_TABLE, $_POST['id'] ) );
	$errid = EVENT_REJECTED;
}

$items =& $osDB->getAll( 'select * from ! where enabled = ? and private_to = "" and userid <> 0 order by datetime_from', array( EVENTS_TABLE, 'N' ) );
$events = array();
foreach ( $items as $row ) {
	$sql = 'select username, firstname, lastname from ! where id = ?';
	$user =& $osDB->getRow( $sql, array( USER_TABLE, $row['userid'] ) );
	$row['username'] = $user['username'];
	$row['fullname'] = $user['firstname'] . ' '. $user['lastname'];
	$events[] = $row;
}

//print_r($events);
$t->assign('events', $events);

unset($events, $items, $row, $user);

$t->assign('errid',$errid);
$t->assign('rendered_page', $t->fetch('admin/approve_events.tpl'));
$t->display('admin/index.tpl');
?>