<?php
if (!file_exists('connect.php')) {
$folder=$_SERVER['SCRIPT_NAME'];
 $folder=str_replace('/index.php','',$folder);
header("Location: $folder/install");
}
session_start();
include('connect.php');
require('libs/Smarty.class.php');
require('class.php');

$scode_upandsell = new scode_upandsell();
$site_template=$scode_upandsell->get_value_settings('site_template');
$scode_upandsell->template_dir = "templates/$site_template/";
	if(!isset($_GET['lang'])){
		$site_lang=$scode_upandsell->get_value_settings('site_language');
	}else{
		$site_lang=$_GET['lang'];
	}
include("language/$site_lang/lang.tpl");
$scode_upandsell->force_compile = true;
$scode_upandsell->caching = true;
$scode_upandsell->cache_lifetime = 120;
$website=$scode_upandsell->get_value_settings("site_url");
$site_meta_description=$scode_upandsell->get_value_settings("site_meta_description");
$site_meta_keywords=$scode_upandsell->get_value_settings("site_meta_keywords");
$scode_upandsell->assign("website",$website);
$scode_upandsell->assign("site_meta_description",$site_meta_description);
$scode_upandsell->assign("site_meta_keywords",$site_meta_keywords);
$scode_upandsell->assign("site_header",$scode_upandsell->get_value_settings('site_header'));
$scode_upandsell->assign("site_footer",$scode_upandsell->get_value_settings('site_footer'));
$scode_upandsell->assign("lang",$LANG);
$scode_upandsell->assign("site_lang",$site_lang);
$scode_upandsell->assign("custom_logo",$scode_upandsell->get_value_settings('custom_logo'));
$scode_upandsell->assign("title","Upload And SELL");
$scode_upandsell->assign("teste",$_SERVER);
$scode_upandsell->assign("displayfiles",$scode_upandsell->displayfiles());
switch($_GET['id']){
	case 'contact':
		$scode_upandsell->display('contact.tpl');
	break;
	case 'gopro':
		$scode_upandsell->display('gopro.tpl');
	break;
	case 'howitworks':
		$scode_upandsell->display('howitworks.tpl');
	break;
	case 'user':
		if($scode_upandsell->checklogin()){	
			$scode_upandsell->display('panel.tpl');
		}else{
			$scode_upandsell->display('index.tpl');
		}
	break;
	case 'stats':
		if($scode_upandsell->checklogin()){
			$scode_upandsell->verifystats();
			$scode_upandsell->display('stats.tpl');
		}else{
			$scode_upandsell->display('index.tpl');
		}
	break;
	case 'files':
		if($scode_upandsell->checklogin()){
			$scode_upandsell->display('files.tpl');
		}else{
			$scode_upandsell->display('index.tpl');
		}
	break;
	case 'settings':
		if($scode_upandsell->checklogin()){
			$scode_upandsell->assign("settings_username",$scode_upandsell->accuser);
			$scode_upandsell->verifysettings();
			$scode_upandsell->display('settings.tpl');
		}else{
			$scode_upandsell->display('index.tpl');
		}
	break;
	case 'logout':
		session_destroy();
		
		echo "<script type=\"text/javascript\">window.location = \"$website\"</script>";
	break;
	case 'successbuy':
		$scode_upandsell->display('success_buy.tpl');
	break;
	case 'register':
		$scode_upandsell->verifyregister();	
		$scode_upandsell->verifylogin();	
		$scode_upandsell->display('register.tpl');
	break;
	case 'download':
			if(is_numeric($_GET['id2'])){
				$id2=$_GET['id2'];
				$downfetch=$scode_upandsell->fetcharray("SELECT * FROM `download` WHERE `id`='$id2' AND `active`='1'");

				if($downfetch[id] > 0){
					$prod=$scode_upandsell->fetcharray("SELECT * FROM `products` WHERE `id`='$downfetch[idp]'");
					$sales=$scode_upandsell->fetcharray("SELECT * FROM `sales` WHERE `id`='$downfetch[ids]'");
					$expire_download=$scode_upandsell->get_value_settings('expire_download');
					$expire=$expire_download * 3600;
					$timetofinish=$sales['date']+ $expire;
					$scode_upandsell->assign("down_prod",$prod);
					$scode_upandsell->assign("downid",$id2);
					$scode_upandsell->assign("down_sales",$sales);
					$scode_upandsell->assign("timetofinish",$timetofinish);
					if(isset($_GET['downnow'])){
						$datenow=time();
						$datesales=$sales['date'];
						$total=$datenow - $datesales;
						
							if($total > 0 && $total < $expire){
							echo "<iframe src=\"".$scode_upandsell->get_value_settings('site_url')."/dw.php?dw=$prod[file]\" frameborder=\"0\" style=\"display:none\"></iframe>";


							
							}else{
								$expirat=true;
							}
					}
						if($expirat==true){
							$scode_upandsell->display('index.tpl');
						}else{
							$scode_upandsell->display('download.tpl');
						}
				}else{
					$scode_upandsell->display('index.tpl');
				}
			}else{
				$scode_upandsell->display('index.tpl');
			}
	break;
	case 'buypage':
		if(is_numeric($_GET['id2'])){
			$id2=$_GET['id2'];
			$buy_details=$scode_upandsell->fetcharray("SELECT * FROM `products` WHERE `id`='$id2'");
			if($buy_details){
				if($_GET['id3'] =="redirect"){
			
			
			?>
			<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
					<input type="hidden" name="cmd" value="_xclick">
					<input type="hidden" name="business" value="<?=$buy_details[contact_paypal]?>">
					<input type="hidden" name="currency_code" value="<?=$buy_details[price_value]?>">
					<input type="hidden" name="item_name" value="<?=$buy_details[name]?>">
					<input type="hidden" name="amount" value="<?=$buy_details[price]?>">
					<input type="hidden" name="return" value="<?=$website?>/page/successbuy">
					<input type="hidden" name="custom" value="<?=$buy_details[idu]?>-<?=$buy_details[id]?>">
					<input type="hidden" name="notify_url" value="<?=$website?>/payment/paypal/script/ipn.php">

				</form>
<script type="text/javascript">
  document._xclick.submit();
</script>
			<?php
				}else{
			
					$scode_upandsell->assign("buy_details",$buy_details);
					$scode_upandsell->display('buy.tpl');
				}
				}else{
					$scode_upandsell->display('index.tpl');
				}
			
		}else{
			$scode_upandsell->display('index.tpl');
		}
	break;
	case 'page':
			$scode_upandsell->display('page.tpl');
	break;
	case 'tos':
			$scode_upandsell->display('tos.tpl');
	break;
	default:
	if($scode_upandsell->checklogin()){
			$scode_upandsell->assign("settings_username",$scode_upandsell->accuser);
	}
		$scode_upandsell->verifyfile();
		$scode_upandsell->display('index.tpl');
	break;
}
?>
