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

include ( 'sessioninc.php' );

$userid = $_REQUEST['userid'] > 0? $_REQUEST['userid'] : $_SESSION['UserId'];

$videono = $_REQUEST['videono'];

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 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'];
}
unset($rows);
$nextpic++;

$t->assign('max_picture_cnt', (count($data) < $userdata['videoscnt'])? count($data) : $userdata['videoscnt'] );

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

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

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

unset($data, $userdata);

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

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

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

if ($_REQUEST['msg'] != '') {
	$t->assign("error_message", get_lang('errormsgs',$_GET['msg']) );
}
$t->assign ( 'lang', $lang );

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

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

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


?>