Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Keeping track of number of e-goods downloads

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 04-10-2003, 11:45 AM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default Keeping track of number of e-goods downloads

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.
Reply With Quote
  #2  
Old 04-11-2003, 10:03 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

minorgod,

good mod

have you built a module to be able to view these results in the orders area to see whether every order has been satisfied?
__________________
ex x-cart guru
Reply With Quote
  #3  
Old 04-11-2003, 10:12 AM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default nope, but...

No, I haven't been that motivated to do it. I've been building some x-cart admin tools that reside completely outside of x-cart so that in the future, when I upgrade x-cart, I don't have to customize the entire admin side of it in addition to the customer front-end. At worst I'll just have to change how a few of my own scripts interact with x-cart, but since I wrote them all, I know it will be easier than modding some of the x-cart code which is just plain difficult in some cases...like creating a custom login page. GRRRRRRR. I'm still working on that login problem which I will be posting example code for in the next hour or so. No progress, but I'm simplifying the code to be a generic gateway so you can quickly install and test on your server by just changing a few variables in a config file. It'll be ready shortly so hopefully you'll have time to take a look at it and see if you can see why it doesn't work right.
__________________
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.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:43 PM.

   

 
X-Cart forums © 2001-2020