<?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;
}

foreach( $_POST['txtid'] as $arr ) {

	$id = $arr;

	$displayorder = $osDB->getOne( 'SELECT displayorder FROM ! WHERE id = ?', array( SECTIONS_TABLE, $id ) );

	$maxorder = $osDB->getOne( 'select max(displayorder) as maxorder from !', array( SECTIONS_TABLE ) );

	//move the records below this record up
	$i = $displayorder + 1;

	while ( $i <= $maxorder['maxorder'] ){

		$osDB->query( 'UPDATE ! SET displayorder = ? WHERE displayorder = ?', array( SECTIONS_TABLE, $i - 1, $i ) );

		$i++;
	}

	$osDB->query ( 'DELETE FROM ! WHERE id = ?', array( SECTIONS_TABLE, $id ) );
}

header ( 'location: section.php' );

?>