<?php

include './core.php';

if( !isset( $user ) ) access_error();

if( isset( $_POST['delete_choice'] ) )
{
    foreach( $_POST['checked'] as $accountid )
    {
        $rem_picture = $MySQL->query_first( "SELECT * FROM user_pictures WHERE accountid = ".intval( $accountid ) );
        $imgurl = combine_path( $settings['user_gallery_dir'], $rem_picture['accountid'].'.'.$rem_picture['extension'] );
        unlink( $imgurl );

        $MySQL->query( "DELETE FROM user_pictures WHERE accountid = ".$rem_picture['accountid'] );
    }
}

if( isset( $_POST['activate_choice'] ) )
{
    foreach( $_POST['checked'] as $accountid )
    {
        $MySQL->query( "UPDATE user_pictures SET activation = 1 WHERE accountid = '".$accountid."'" );
    }
}

$pictures_na_res = $MySQL->query( "SELECT user_pictures.*, server.accounts.name AS picture_owner FROM user_pictures, server.accounts WHERE user_pictures.activation != 1 && user_pictures.accountid = server.accounts.accountid ORDER BY server.accounts.name" );
$pictures_na = array();
while( $row = $MySQL->fetch_array( $pictures_na_res ) )
{
    $row['imgurl'] = combine_path( $settings['user_gallery_dir'], $row['accountid'].'.'.$row['extension'] );
    $row['imgsize'] = @getimagesize( $row['imgurl'] );

    $pictures_na[] = $row;
}
$Smarty->assign( 'pictures_na', $pictures_na );

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

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

?>