<?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_SNAP_TABLE, 'Y', $_POST['id'] ) );

	$errid = PICTURE_APPROVED;

} elseif ($_POST['action'] == get_lang('reject')) {
/* Remove the picture entry */
	$osDB->query( 'update ! set active = ? where id = ?',array( USER_SNAP_TABLE, 'R', $_POST['id'] ) );
	$errid = PICTURE_REJECTED;
}elseif ($_POST['groupaction'] == get_lang('Approve')) {
	if (count($_POST['txtchk']) > 0) {
		foreach($_POST['txtchk'] as $picid) {
			$osDB->query( 'update ! set active = ? where id = ?', array( USER_SNAP_TABLE, 'Y', $picid ) );
		}
		$errid = PICTURE_APPROVED;
	}
}elseif ($_POST['groupaction'] == get_lang('reject')) {
	if (count($_POST['txtchk']) > 0) {
		foreach($_POST['txtchk'] as $picid) {
			$osDB->query( 'update ! set active = ? where id = ?', array( USER_SNAP_TABLE, 'R', $picid ) );
		}
		$errid = PICTURE_APPROVED;
	}
}

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

$user_pics = array();

foreach ( $pics 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_pics[] = $row;
}

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

unset($pics, $user_pics, $user);

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

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

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

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




?>