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

define( 'PAGE_ID', 'section_mgt' );

if ( !checkAdminPermission( PAGE_ID ) ) {

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

$arr = $_POST[ 'txtcheck' ];

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

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

switch ( $_POST['groupaction']) {

	case  get_lang('enable_selected'):
		foreach ( $arr as $id ) {

			$osDB->query( 'UPDATE ! SET enabled = ? WHERE id = ?', array( SECTIONS_TABLE, 'Y', $id) );
		}

	case get_lang('disable_selected'):

		foreach ( $arr as $id ) {

			$osDB->query( 'UPDATE ! SET enabled = ? WHERE id = ?', array( SECTIONS_TABLE, 'N', $id) );
		}

}


// Editing section
foreach ( $arr as $sectionid ) {

	$row =& $osDB->getRow( 'SELECT id, section, enabled from ! Where id = ?', array( SECTIONS_TABLE, $sectionid) );

	$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('enable_selected') ) {

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

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

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

}

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

?>