edgar105 Posted July 9, 2006 Posted July 9, 2006 Hello, I hope someone can help. I've enabled the 'downloads' feature, and as-is, that's fine. However since my store also accepts payment by cheque, the download link is immediately shown after completing the initial part of the transaction (before receving the cheque)! I've tried the following modification: http://www.oscommerce.com/forums/lofiversion/i...hp/t180286.html Where the altered SQL tries to check if the order status is set to a value of '3' (shipped) first - but using the code on the page above gives me an SQL error. Has anyone actually got this working? As it's just what's needed! Cheers,
Guest Posted July 9, 2006 Posted July 9, 2006 yea it's working allright what's the error message you're getting?
edgar105 Posted July 9, 2006 Author Posted July 9, 2006 Hi There, In download.php changing: // Check that order_id, customer_id and filename match $downloads_query = tep_db_query("select date_format(o.date_purchased, '%Y-%m-%d') as date_purchased_day, opd.download_maxdays, opd.download_count, opd.download_maxdays, opd.orders_products_filename from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " opd where o.customers_id = '" . $customer_id . "' and o.orders_id = '" . (int)$HTTP_GET_VARS['order'] . "' and o.orders_id = op.orders_id and op.orders_products_id = opd.orders_products_id and opd.orders_products_download_id = '" . (int)$HTTP_GET_VARS['id'] . "' and opd.orders_products_filename != ''"); if (!tep_db_num_rows($downloads_query)) die; $downloads = tep_db_fetch_array($downloads_query); to: // Check that order_id, customer_id and filename match $downloads_query = tep_db_query("select date_format(o.date_purchased, '%Y-%m-%d') as date_purchased_day, opd.download_maxdays, opd.download_count, opd.download_maxdays, opd.orders_products_filename from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " opd where o.customers_id = '" . $customer_id . "' and o.orders_id = '" . (int)$HTTP_GET_VARS['order'] . "' and o.order_status = '3' and o.orders_id = op.orders_id and op.orders_products_id = opd.orders_products_id and opd.orders_products_download_id = '" . (int)$HTTP_GET_VARS['id'] . "' and opd.orders_products_filename != ''"); if (!tep_db_num_rows($downloads_query)) die; $downloads = tep_db_fetch_array($downloads_query); and when the buyer completes of transaction, the download link is active. However clicking on the download link brings up the following error: There seems to be a problem with the MySQL server, sorry for the inconvenience. We will be back as soon as possible. Thanks.
edgar105 Posted July 9, 2006 Author Posted July 9, 2006 Here it is: <?php /* $Id: download.php,v 1.9 2003/02/13 03:01:48 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ include('includes/application_top.php'); if (!tep_session_is_registered('customer_id')) die; // Check download.php was called with proper GET parameters if ((isset($HTTP_GET_VARS['order']) && !is_numeric($HTTP_GET_VARS['order'])) || (isset($HTTP_GET_VARS['id']) && !is_numeric($HTTP_GET_VARS['id'])) ) { die; } // Check that order_id, customer_id and filename match $downloads_query = tep_db_query("select date_format(o.date_purchased, '%Y-%m-%d') as date_purchased_day, opd.download_maxdays, opd.download_count, opd.download_maxdays, opd.orders_products_filename from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " opd where o.customers_id = '" . $customer_id . "' and o.orders_id = '" . (int)$HTTP_GET_VARS['order'] . "' and o.order_status = '3' and o.orders_id = op.orders_id and op.orders_products_id = opd.orders_products_id and opd.orders_products_download_id = '" . (int)$HTTP_GET_VARS['id'] . "' and opd.orders_products_filename != ''"); if (!tep_db_num_rows($downloads_query)) die; $downloads = tep_db_fetch_array($downloads_query); if (!tep_db_num_rows($downloads_query)) die; $downloads = tep_db_fetch_array($downloads_query); // MySQL 3.22 does not have INTERVAL list($dt_year, $dt_month, $dt_day) = explode('-', $downloads['date_purchased_day']); $download_timestamp = mktime(23, 59, 59, $dt_month, $dt_day + $downloads['download_maxdays'], $dt_year); // Die if time expired (maxdays = 0 means no time limit) if (($downloads['download_maxdays'] != 0) && ($download_timestamp <= time())) die; // Die if remaining count is <=0 if ($downloads['download_count'] <= 0) die; // Die if file is not there if (!file_exists(DIR_FS_DOWNLOAD . $downloads['orders_products_filename'])) die; // Now decrement counter tep_db_query("update " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " set download_count = download_count-1 where orders_products_download_id = '" . (int)$HTTP_GET_VARS['id'] . "'"); // Returns a random name, 16 to 20 characters long // There are more than 10^28 combinations // The directory is "hidden", i.e. starts with '.' function tep_random_name() { $letters = 'abcdefghijklmnopqrstuvwxyz'; $dirname = '.'; $length = floor(tep_rand(16,20)); for ($i = 1; $i <= $length; $i++) { $q = floor(tep_rand(1,26)); $dirname .= $letters[$q]; } return $dirname; } // Unlinks all subdirectories and files in $dir // Works only on one subdir level, will not recurse function tep_unlink_temp_dir($dir) { $h1 = opendir($dir); while ($subdir = readdir($h1)) { // Ignore non directories if (!is_dir($dir . $subdir)) continue; // Ignore . and .. and CVS if ($subdir == '.' || $subdir == '..' || $subdir == 'CVS') continue; // Loop and unlink files in subdirectory $h2 = opendir($dir . $subdir); while ($file = readdir($h2)) { if ($file == '.' || $file == '..') continue; @unlink($dir . $subdir . '/' . $file); } closedir($h2); @rmdir($dir . $subdir); } closedir($h1); } // Now send the file with header() magic header("Expires: Mon, 26 Nov 1962 00:00:00 GMT"); header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Content-Type: Application/octet-stream"); header("Content-disposition: attachment; filename=" . $downloads['orders_products_filename']); if (DOWNLOAD_BY_REDIRECT == 'true') { // This will work only on Unix/Linux hosts tep_unlink_temp_dir(DIR_FS_DOWNLOAD_PUBLIC); $tempdir = tep_random_name(); umask(0000); mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777); symlink(DIR_FS_DOWNLOAD . $downloads['orders_products_filename'], DIR_FS_DOWNLOAD_PUBLIC . $tempdir . '/' . $downloads['orders_products_filename']); tep_redirect(DIR_WS_DOWNLOAD_PUBLIC . $tempdir . '/' . $downloads['orders_products_filename']); } else { // This will work on all systems, but will need considerable resources // We could also loop with fread($fp, 4096) to save memory readfile(DIR_FS_DOWNLOAD . $downloads['orders_products_filename']); } ?>
Guest Posted July 9, 2006 Posted July 9, 2006 this is fine so you may want to ask your host there is a problem with the database privileges. try using this query once see if you can change the priveleges and/or ask your host. grant all privileges on dbase.* to dbase@localhost identified by 'dbasepassword';
edgar105 Posted July 9, 2006 Author Posted July 9, 2006 Thanks, I just don't understand how adding essentially: and o.order_status = '3' would cause it to fall over. I've not had any problems with DB privileges before and everything else works OK?
Guest Posted July 9, 2006 Posted July 9, 2006 ok check this. goto your osc Admin->Configuration->Download by redirect. set it to false and retry. Not sure if the download link will work but check if you see the same error. Is it a *nix server or windows?
edgar105 Posted July 9, 2006 Author Posted July 9, 2006 Worked it out! the code is not: o.order_status = '3 The should be: o.orders_status = '3 - and that works!
Guest Posted July 9, 2006 Posted July 9, 2006 that's strange I would expect to see an sql error for the table column. Then again depends how the error reporting is set. It's good you spotted it though.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.