<?php

include './core.php';

if( !isset( $user ) || !$user->can_access( 'betastatus_admin' ) ) access_error();

if( isset( $_POST['send_form'] ) )
{
	$stats = $MySQL->fetch_complete( "SELECT * FROM betastatus ORDER BY `group`" );

    foreach( $stats as $row )
    {
    	if( isset( $_POST[$row['statusID'].'_percent'] ) && isset( $_POST[$row['statusID'].'_comment'] ) )
        {
        	$MySQL->query( sprintf("UPDATE betastatus SET percent = %d, comment = '%s' WHERE statusID=%d", intval( $_POST[$row['statusID'].'_percent'] ), me_escape( $_POST[$row['statusID'].'_comment'] ), $row['statusID'] ));
        }
    }

    $Smarty->assign( 'saved', true );
}

$stats = $MySQL->fetch_complete( "SELECT * FROM betastatus ORDER BY `group`" );
$Smarty->assign( 'stats', $stats );

$page['content'] = $Smarty->fetch( 'betastatus_admin.tpl' );

$Smarty->assign( 'page', $page );
$Smarty->display( 'main.tpl' );

?>