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

define( 'PAGE_ID', 'calendar_mgt' );

if ( !checkAdminPermission( PAGE_ID ) ) {

	header( 'location: not_authorize.php' );
	exit;
}

$arr = $_POST[ 'txtcheck' ];

if ( count( $arr ) == 0 ) {

	header( 'location: calendar.php?msg=' . urlencode(get_lang('no_select_msg')) );
	exit;
}

if ( $_POST['groupaction'] == get_lang('enable_selected') ) {

	foreach ( $arr as $id ) {

		$osDB->query( $sql, array( CALENDARS_TABLE, 'Y', $id) );
	}
	header ( 'location: calendar.php' );
	exit;

} elseif ($_POST['groupaction'] == get_lang('disable_selected') ) {

	foreach ( $arr as $id ) {

		$osDB->query( $sql, array( CALENDARS_TABLE, 'N', $id) );
	}
	header ( 'location: calendar.php' );
	exit;

}

// Editing calendar
foreach ( $arr as $calendarid ) {

	$row =& $osDB->getRow( 'SELECT id, calendar, enabled from ! Where id = ?', array( CALENDARS_TABLE, $calendarid) );

	$data[] = $row;

}

$t->assign( 'lang', $lang );

$t->assign( 'error', get_lang('admin_error_msgs', $_GET['errid'] ) );

$t->assign( 'data', $data );

unset($data, $arr);

if ( $_POST['groupaction'] == get_lang('change_selected') ) {

	$t->assign('rendered_page', $t->fetch('admin/groupcalendaredit.tpl' ));

} elseif ($_POST['groupaction'] == get_lang('delete_selected') ) {

	$t->assign('rendered_page', $t->fetch('admin/groupcalendardel.tpl' ));

}

$t->display('admin/index.tpl');

?>