//error_reporting(0); // Switch off warnings
try
{
$membershipID = 0;
$digitalContentSkuID = 0;
$digitalContentID = 0;
$downloadSourceID = 0;
$setStatusToFalse = true;
$updateLog = true;
$environment = "QA";
// Need better error handling / logging for when query string parameters have not been properly set?
$membershipID = $_GET['membershipid'];
if ($membershipID == null) { $membershipID = 0; }
$digitalContentSkuID = $_GET['digitalcontentskuid'];
if ($digitalContentSkuID == null) { $digitalContentSkuID = 0; }
$digitalContentID = $_GET['digitalcontentid'];
if ($digitalContentID == null) { $digitalContentID = 0; }
$downloadSourceID = $_GET['downloadsourceid'];
if ($downloadSourceID == null) { $downloadSourceID = 0; }
$environment = $_GET['environment'];
if ($environment == null) { $environment = "QA"; }
// Do web service authentication.
$scRLS;
if ( $environment == "QA")
{
//$scRLSAuth = new SoapClient('http://hsapp.exactmobile.com/QA_RadioLoyaltyService/RadioLoyaltyAuthentication.asmx?wsdl');
$scRLS = new SoapClient('http://hsapp.exactmobile.com/QA_RadioLoyaltyService/RadioLoyaltyService.asmx?wsdl');
$setStatusToFalse = false;
}
else
{
//$scRLSAuth = new SoapClient('http://hsapp.exactmobile.com/QA_RadioLoyaltyService/RadioLoyaltyAuthentication.asmx?wsdl');
$scRLS = new SoapClient('http://hsapp.exactmobile.com/RadioLoyaltyService/RadioLoyaltyService.asmx?wsdl');
}
// Do authentication:
/*$username = 'igroup';
$password = 'local';
$token = $scRLSAuth->__soapCall('GetToken',
array(array( 'username' => $username,
'password' => $password
)))->GetTokenResult;
$scRLS->TokenHeader = $token;
echo("
" .$token ."
");
*/
/*
object token = rlaLOCAL.GetToken(username, password);
if (token != null)
{ // Token will be null if authentication has been disabled or if an error has occured.
thLOCAL.Token = token.ToString();
clsWebServiceInitialisation.thLOCAL = thLOCAL;
clsWebServiceInitialisation.rlsLOCAL.TokenHeaderValue = thLOCAL;
}
*/
$filepath = $scRLS->__soapCall('IsMyDownloadActivated',
array(array( 'membershipID' => $membershipID,
'digitalContentSkuID' => $digitalContentSkuID,
'digitalContentID' => $digitalContentID,
'downloadSourceID' => $downloadSourceID,
'setStatusToFalse' => $setStatusToFalse,
'updateLog' => $updateLog
)))->IsMyDownloadActivatedResult;
//echo($filepath);
if (strlen($filepath) == 0 || substr($filepath,0, 1) == '[')
{ // Initiate download.
echo("Download not activated.");
throw new Exception("Download not activated.");
}
else
{
if(!file_exists($filepath))
{
throw new Exception("File not found.");
}
else
{
//echo ($filepath ."\n" );
$filesize = filesize($filepath);
$lastSlashIndex = strrpos($filepath, '/');
$filename = substr($filepath, $lastSlashIndex + 1);
//echo ("Last Slash: " .$lastSlashIndex ."\n");
//echo ($filename ."\n" );
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Length: ' .$filesize);
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename=' .$filename);
// Will this work?
header('Vary: User-Agent');
set_time_limit(0);
readfile($filepath) or die("File not found.");
}
}
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
?>