<?php

	if(in_array($_SESSION['my_id'], $admins))
	{
		$actions = array('on', 'off', 'sort');
		$action = (key_exists('action', $_GET) && in_array($_GET['action'], $actions)) ? $_GET['action'] : '';
		
		if($action == 'on')
		{
			session_register('hry_edit');
			header('location: '.$HTTP_REFERER);
		}
		
		if($action == 'off')
		{
			session_unregister('hry_edit');
			header('location: '.$HTTP_REFERER);
		}
		
		if($action == 'sort')
		{
			if(isset($_POST['sort']))
			{
				$fp = fopen('lib/log/hry_sort.txt', 'a');
				foreach($_POST['sort'] as $game_id => $new_genre)
				{	
					$query = "UPDATE mobile_games SET genre='$new_genre' WHERE ID='$game_id' limit 1";
					$dba->ExecuteQuery($query);
					fputs($fp, $query."\n");	
				}
				fclose($fp);
			}
			header('location: '.$HTTP_REFERER);
		}
	}
?>