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

include ( 'sessioninc.php' );

$userid = $_REQUEST['userid'];

$videono = $_REQUEST['videono'];

if ($_REQUEST['act'] != '') {

	$act = ($_REQUEST['act'] == 'activate')?'Y':'N';

	$osDB->query('update ! set active = ? where userid = ? and videono = ?', array(USER_VIDEOS_TABLE, $act, $userid, $videono) );

	header('location: ?userid='.$userid);

	exit;
}

if( $_GET['del'] == 'yes' ){

	$row =& $osDB->getRow( 'SELECT id, filename FROM ! WHERE userid = ? AND videono = ?', array( USER_VIDEOS_TABLE, $userid, $videono ) );

	@unlink(USER_VIDEO_DIR.$row['filename']);

	$osDB->query('delete from ! where userid = ? and videono = ?',array( USER_VIDEOS_TABLE, $userid, $videono  ) );

	updateLoadedVideosCnt($userid);

	unset($row);

	header('location: ?userid='.$userid);

	exit;
}

$rows =& $osDB->getAll( 'select videono, filename, album_id, active from ! where userid = ? order by videono', array( USER_VIDEOS_TABLE, $userid ) );

$userdata =& $osDB->getRow('select usr.level, usr.username,  mem.allow_videos, mem.videoscnt, mem.allowalbum from ! as usr, ! as mem where mem.roleid = usr.level and usr.id = ?', array(USER_TABLE, MEMBERSHIP_TABLE, $userid ) );

$data = array();
$data[]="  ";
foreach ($rows as $row) {

	$data[] = $row;
	$nextpic = $row['videono'];
}

$nextpic++;

$useralbums =& $osDB->getAll('select id, name from ! where username = ? order by name', array(USERALBUMS_TABLE, $userdata['username'] ) );

if ( function_exists('system')) {
	/* system command is allowed */
	$t->assign('system_allowed','Y');
}


$t->assign('max_picture_cnt', count($data) );

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

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

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

unset($data, $userdata, $useralbums);

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

$t->assign('nextvideo',$nextpic);

$t->assign('album_id', $_POST['album_id']);

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

$t->assign('rendered_page',$t->fetch('uservideos.tpl'));

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

?>