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

include ( 'sessioninc.php' );

define( 'PAGE_ID', 'snaps_require_approval' );

if ( !checkAdminPermission( PAGE_ID ) ) {

	header( 'location: not_authorize.php' );
	exit;
}

if ($_POST['action'] == get_lang('Approve')) {
/* approve picture */

	$osDB->query( 'update ! set active = ? where id = ?', array( USER_VIDEOS_TABLE, 'Y', $_POST['id'] ) );

	$errid = VIDEO_APPROVED;

} elseif ($_POST['action'] == get_lang('reject')) {
/* Remove the picture entry */

	$osDB->query( 'update ! set active = ? where id = ?',array( USER_VIDEOS_TABLE, 'R', $_POST['id'] ) );
	$errid = VIDEO_REJECTED;
}


/* Now select the pictures which are not yet approved.. */
$videos =& $osDB->getAll( 'select id, userid, videono, album_id, filename from ! where active = ? order by ins_time', array( USER_VIDEOS_TABLE, 'N' ) );

$user_videos = array();

foreach ( $videos as $row ) {

	$user =& $osDB->getRow( 'select username, firstname, lastname from ! where id = ?', array( USER_TABLE, $row['userid'] ) );

	$row['username'] = $user['username'];

	$row['fullname'] = $user['firstname'] . ' '. $user['lastname'];

	$row['album_name'] = $osDB->getOne('select name from ! where id = ?', array(USERALBUMS_TABLE, $row['album_id']));

	$user_videos[] = $row;
}

$t->assign('user_videos', $user_videos);

unset($videos, $user_videos, $user);

$t->assign('errid',$errid);

$t->assign("error_message", get_lang('errormsgs', $errid) );

$t->assign('rendered_page', $t->fetch('admin/approve_videos.tpl'));

$t->display('admin/index.tpl');


?>