<?php
session_start();
echo 'extensions:"'.ini_get('extensions').'"';
include_once "../includes/bdd.php";
include_once "../includes/inter.php";
include_once "megaapi.php";

$permissions = array (
		FALSE,
		FALSE,
		FALSE,
		FALSE 
);
$connected = isConnected ();
$owner = FALSE;
$adminLevel = - 1;
$data = NULL;
if (isset ( $_GET ['id'] ) && isset ( $_GET ['v'] )) {
	$data = getProjectVersionData( $_GET ['id'], $_GET ['v'] );
	if ($data != NULL) {
		$permissions = getPermissions( $data );
	} else {
		header('Location:../40A.php');
		goto end;
	}
} else {
	header('Location:../40A.php');
	goto end;
}
if (! $connected) {
	header( 'Location:../401.php' );
	goto end;
}

$owner = preg_match ( '#[^0-9]?' . $_SESSION ['session_id'] . '[^0-9]?#', $data ['owners'] );
$adminLevel = getAdminLevel ();
if (! $owner && $adminLevel < 12) {
	header( 'Location:../403.php' );
	goto end;
}

$megaapi = new MegaApiPHP("mA9D1IQQ", "PHP bernard.com");
$megaapi->login("bernard.lafayette63@gmail.com", "*******************");
$node = $megaapi->getNodeByPath('imageFinal.jpg', $megaapi->getRootNode());
$megaapi->startDownload($node, './');

end: