<?php
/*
 **************************************************************************************************
 *    Copyright (c) 2010-2012 Just Another Video script
 *
 * 	  This file is part of Just Another Video Script.
 *    Version 1.4.3
 *    info@justanothervideoscript.com
 **************************************************************************************************
 *    Come to website for support or buying additional plugins/modules.
 *    http://justanothervideoscript.com/
 **************************************************************************************************
 *    By using this software you agree that you have read and acknowledged our End-User License
 *    Agreement available at http://justanothervideoscript.com/license and can be bound by it.
 **********************************************************************************
 */
include 'includes/ajaxfunctions.inc' ;
include_once 'includes/functions.inc' ;
session_start() ;
global $sitepath,$db,$loggedIn;

//new jquery for version 1.4.3

if ($_GET['func']) {
	$vid_id = trim(quote_smart($_GET['vid_id'])) ;
	if ($_GET['func'] == 'flag') {
		$db->query("UPDATE media SET flagged=1 WHERE id=".$vid_id) ;
	}
	if ($_GET['func'] == 'addfav') {
			$db->query("SELECT id FROM member WHERE username = '".$_SESSION['session_username']."'") ;
			$userres = $db->fetch() ;
			$db->query("INSERT INTO favorite (userid,vidid) VALUES (".$userres['id'].",".$vid_id.")") ;
	}
	if ($_GET['func'] == 'download') {
		$replay = '';
		$db->query("SELECT * FROM media WHERE id = '".$vid_id."'") ;
		$videores = $db->fetch() ;
		if ($_SESSION['session_username'] == '') {
			//no username so not logged in
				if ((getSetting("downGuest", $db) == 1) && ($videores['mediatype'] == "video")) {
					$replay .= '<a href="'.$sitepath.'uploads/vids/'.$videores['fileid'].'/'.$videores['fileid'].'.flv" class="down_norm" title="Download normal flv">Download normal</a><br />' ;
				}
				if (($videores['hd'] == 1) && (getSetting("downhdguest", $db) == 1) && ($videores['mediatype'] == "video")) {
					$replay .= '<a href="'.$sitepath.'uploads/vids/'.$videores['fileid'].'/'.$videores['fileid'].'.mp4" class="down_hd" title="Download HD">Download HD</a><br />' ;
				}
				if (($videores['mobile'] == 1) && (getSetting("downmobileguest", $db) == 1) && ($videores['mediatype'] == "video")) {
					$replay .= '<a href="'.$sitepath.'uploads/vids/'.$videores['fileid'].'/mob_'.$videores['fileid'].'.mp4" class="down_mobile" title="Download Mobile">Download Mobile</a>' ;
				}
				if ((getSetting("downGuest", $db) == 0) && (getSetting("downnormalmembers", $db) == 1) && ($videores['mediatype'] == "video")) {
					$replay .= '<h3><a href="'.$sitepath.'login">Login to Download</a><h3>' ;
				}
		} else {
			//there is a username so user must be logged in
				if ((getSetting("downnormalmembers", $db) == 1) && ($videores['mediatype'] == "video")) {
					$replay .= '<a href="'.$sitepath.'uploads/vids/'.$videores['fileid'].'/'.$videores['fileid'].'.flv" class="down_norm" title="Download normal flv">Download normal</a><br />' ;
				}
				if (($videores['hd'] == 1) && (getSetting("downhdmember", $db) == 1) && ($videores['mediatype'] == "video")) {
					$replay .= '<a href="'.$sitepath.'uploads/vids/'.$videores['fileid'].'/'.$videores['fileid'].'.mp4" class="down_hd" title="Download HD">Download HD</a><br />' ;
				}
				if (($videores['mobile'] == 1) && (getSetting("downmobilemember", $db) == 1) && ($videores['mediatype'] == "video")) {
					$replay .= '<a href="'.$sitepath.'uploads/vids/'.$videores['fileid'].'/mob_'.$videores['fileid'].'.mp4" class="down_mobile" title="Download Mobile">Download Mobile</a>' ;
				}
				if ($replay == '') {
					$replay .= '<h3>Downloads Are Not available</h3>';
				}
		}
		echo $replay ;

	}

}


?>