I've added a bit to the customer/dowload.php file to track the number of successful downloads for each download key. First I added a number_downloads (tinyint,not null,default 0) field to my xcart_download_keys table. Then I modified my customer/downloads.php file to update the count after a file is successfully downloaded. The code below was already a heavily modified version of the customer/download.php page before I added the download counter code...the original version supplied with x-cart didn't work for me...note, that this is for xcart version 3.3.1, but might work with newer releases, you'll have to decide that for yourself.
Code:
<?
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart |
| Copyright (c) 2001-2002 Ruslan R. Fazliev. All rights reserved. |
+-----------------------------------------------------------------------------+
| The Ruslan R. Fazliev forbids, under any circumstances, the unauthorized |
| reproduction of software or use of illegally obtained software. Making |
| illegal copies of software is prohibited. Individuals who violate copyright |
| law and software licensing agreements may be subject to criminal or civil |
| action by the owner of the copyright. |
| |
| 1. It is illegal to copy a software, and install that single program for |
| simultaneous use on multiple machines. |
| |
| 2. Unauthorized copies of software may not be used in any way. This applies |
| even though you yourself may not have made the illegal copy. |
| |
| 3. Purchase of the appropriate number of copies of a software is necessary |
| for maintaining legal status. |
| |
| DISCLAIMER |
| |
| THIS SOFTWARE IS PROVIDED BY Ruslan R. Fazliev ``AS IS'' AND ANY |
| EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| DISCLAIMED. IN NO EVENT SHALL Ruslan R. Fazliev OR ITS |
| CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
| The Initial Developer of the Original Code is Ruslan R. Fazliev. |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2002 |
| Ruslan R. Fazliev. All Rights Reserved. |
+-----------------------------------------------------------------------------+
\*****************************************************************************/
#
# $Id: download.php,v 1.11 2002/12/03 07:53:51 matr Exp $
#
# This module adds support for downloading electronicaly distributed goods
#
require "../smarty.php";
require "../config.php";
if (empty($id)) exit();
$query = "SELECT * FROM $sql_tbl[download_keys] WHERE download_key = '$id'";
$res = func_query_first($query);
$number_downloads=$res['number_downloads']+1;
# If there is corresponding key in database and not expired
if ((count($res) > 0) AND ($res['expires'] > time())) {
# check if there is valid distribution for this product
$productid = $res['productid'];
$result = func_query_first("SELECT distribution, product, provider FROM $sql_tbl[products] WHERE productid = '$productid'");
$distribution = $result['distribution'];
$provider = $result['provider'];
if (empty($provider) || $single_mode){
//echo "provider empty or single mode: ".$files_dir_name."/$provider".$distribution;
//$distribution = $files_dir_name.$distribution;
$distribution = $files_dir_name."/$provider".$distribution;
}else{
//echo $files_dir_name."/$provider".$distribution;
$distribution = $files_dir_name."/$provider".$distribution;
}
if ($fd = fopen ($distribution, "r")){
#
# Bugfix - content corrupted
# $contents = addslashes($contents);
#
$size=filesize($distribution);
$fname = basename ($distribution);
//This is some really weak code I used just to redirect to the file before I fixed
//this problem
//echo "
size: $size";
//echo "
fname: $fname";
//header("Location: $distribution");
//fclose ($fd);
//exit;
header("Pragma: ");
header("Cache-Control: ");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$fname."\"");
header("Content-length: $size");
while(!feof($fd)) {
$buffer = fread($fd, 2048);
print $buffer;
}
fclose ($fd);
$query="UPDATE $sql_tbl[download_keys] SET number_downloads='$number_downloads' WHERE download_key='$id'";
db_query($query);
exit;
}else {
# If no such distributive
$smarty->assign("product", $result['product']);
$smarty->display("modules/Egoods/no_distributive.tpl");
exit;
}
} else {
$smarty->display("modules/Egoods/wrong_key.tpl");
exit;
}
?>
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.