Example #1
0
/*
 * If the download type is order then check to make sure that the 
 * customer has access to download the file by doing these checks.
 */
if ($download['downloadType'] == 'order') {
    $maxDownloadAttempts = ($config['settings']['dl_attempts'] == 0 or $download['collectionDownload'] == 1) ? 9999 : $config['settings']['dl_attempts'];
    // Find the max download attempts - if unlimited use 999
    //echo $maxDownloadAttempts; exit;
    // Check authorization
    if ($_SESSION['downloadAuthorization'] != k_encrypt($download['downloadTypeID'])) {
        echo "You are not authorized to download this file";
        exit;
    } else {
        try {
            $invoice = new invoiceTools();
            $digitalItem = $invoice->getSingleInvoiceItem($download['invoiceItemID']);
            // Check expiration
            if ($nowGMT > $digitalItem['expires'] and $digitalItem['expires'] != '0000-00-00 00:00:00') {
                echo "This download has expired";
                exit;
            }
            // Check download count
            if ($digitalItem['downloads'] >= $maxDownloadAttempts) {
                echo "You have reached the maximum number of downloads for this file.";
                exit;
            }
        } catch (Exception $e) {
            echo $e->getMessage();
            exit;
        }
        //print_k($digitalItem); // Testing
 // Parse the query string
 //$downloadKey['collectionID'];
 //$downloadKey['uorderID'];
 if ($config['EncryptIDs']) {
     $downloadKey['collectionID'] = k_decrypt($downloadKey['collectionID']);
     // Collection ID
     $downloadKey['uorderID'] = k_decrypt($downloadKey['uorderID']);
     // Order ID
     $downloadKey['invoiceItemID'] = k_decrypt($downloadKey['invoiceItemID']);
     // Invoice Item ID
 }
 //print_r($downloadKey); exit;
 $invoice = new invoiceTools();
 $invoice->setOrderID($downloadKey['uorderID']);
 // Set the order ID
 $invoiceItem = $invoice->getSingleInvoiceItem($downloadKey['invoiceItemID']);
 //echo $downloadKey['invoiceItemID']; exit;
 if ($orderInfo = $invoice->getOrderDetails()) {
     $collectionResult = mysqli_query($db, "\t\t\t\r\n\t\t\t\tSELECT SQL_CALC_FOUND_ROWS *\r\n\t\t\t\tFROM {$dbinfo[pre]}collections \r\n\t\t\t\tWHERE coll_id = '{$downloadKey[collectionID]}'\r\n\t\t\t");
     if ($returnRows = getRows()) {
         $collection = mysqli_fetch_array($collectionResult);
         $collectionArray = collectionsList($collection);
         $smarty->assign('collectionRows', $returnRows);
         $smarty->assign('collection', $collectionArray);
         if ($collection['colltype'] == 1) {
             $collectionGalleriesResult = mysqli_query($db, "SELECT gallery_id FROM {$dbinfo[pre]}item_galleries WHERE mgrarea = 'collections' AND item_id = '{$downloadKey[collectionID]}'");
             while ($collectionGallery = mysqli_fetch_array($collectionGalleriesResult)) {
                 $collectionGalleriesArray[] = $collectionGallery['gallery_id'];
             }
             $collectionGalleries = implode(",", $collectionGalleriesArray);
             $sql = "\r\n\t\t\t\t\t\t\tSELECT SQL_CALC_FOUND_ROWS * \r\n\t\t\t\t\t\t\tFROM {$dbinfo[pre]}media \r\n\t\t\t\t\t\t\tLEFT JOIN {$dbinfo[pre]}media_galleries \r\n\t\t\t\t\t\t\tON {$dbinfo[pre]}media.media_id = {$dbinfo[pre]}media_galleries.gmedia_id \r\n\t\t\t\t\t\t\tWHERE {$dbinfo[pre]}media_galleries.gallery_id IN ({$collectionGalleries})\r\n\t\t\t\t\t\t\tAND {$dbinfo[pre]}media.active = 1 \r\n\t\t\t\t\t\t\tAND {$dbinfo[pre]}media.approval_status = 1 \r\n\t\t\t\t\t\t\tGROUP BY {$dbinfo[pre]}media.media_id\r\n\t\t\t\t\t\t\tORDER BY {$dbinfo[pre]}media.date_added DESC\r\n\t\t\t\t\t\t";