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

include ( 'sessioninc.php' );

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


if ($_REQUEST['action'] == get_lang('delete') ) {
	foreach( $_POST['txtid'] as $arr )
	{	$id = $arr;
		$displayorder = $osDB->getOne( 'SELECT displayorder FROM ! WHERE id = ?', array( RATINGS_TABLE, $id ) );
		$maxorder = $osDB->getOne( 'select max(displayorder) as maxorder from !', array( RATINGS_TABLE ) );
		//move the records below this record up
		$i = $displayorder + 1;
		while ( $i <= $maxorder['maxorder'] ){
			$osDB->query( 'UPDATE ! SET displayorder = ? WHERE displayorder = ?', array( RATINGS_TABLE, $i - 1, $i ) );
			$i++;
		}
		// Delete ratings
		$osDB->query ( 'DELETE FROM ! WHERE id = ?', array( RATINGS_TABLE, $id ) );
	}
}

header ( 'location: manageratings.php' );

?>