[TEP-COMMIT] [CVS catalog] use the new database class

hpdl-OfajU3CKLf1/[email protected] 23 Feb 2005 15:53:43 -0000
Newsgroups gmane.comp.web.oscommerce.cvs
Message-ID <[email protected]>
<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>catalog/catalog</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt><a href="#file1">download.php</a></tt></td><td align="right" id="added">+31</td><td align="right" id="removed">-18</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/download.php?rev=1.10&amp;content-type=text/vnd.viewcvs-markup">1.10</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/download.php.diff?r1=1.10&amp;r2=1.11">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/download.php?rev=1.11&amp;content-type=text/vnd.viewcvs-markup">1.11</a></td></tr>
</table>
<pre class="comment">
use the new database class
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a><br /></span>
<div class="fileheader"><big><b>download.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/download.php?rev=1.10&amp;content-type=text/vnd.viewcvs-markup">1.10</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/download.php.diff?r1=1.10&amp;r2=1.11">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/download.php?rev=1.11&amp;content-type=text/vnd.viewcvs-markup">1.11</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.10 -r1.11
--- download.php	2003/11/17 21:02:24	1.10
+++ download.php	2005/02/23 15:53:41	1.11
@@ -5,7 +5,7 @@
</small></pre><pre class="diff" id="context">   osCommerce, Open Source E-Commerce Solutions
   http://www.oscommerce.com
 
</pre><pre class="diff" id="removed">-  Copyright (c) 200<span id="removedchars">3</span> osCommerce
</pre><pre class="diff" id="added">+  Copyright (c) 200<span id="addedchars">5</span> osCommerce
</pre><pre class="diff" id="context"> 
   Released under the GNU General Public License
 */
</pre><pre class="diff"><small id="info">@@ -20,42 +20,55 @@
</small></pre><pre class="diff" id="context">   }
 
 // Check that order_id, customer id and filename match
</pre><pre class="diff" id="removed">-  $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 = '" . $osC_Customer-&gt;id . "' and o.orders_id = '" . (int)$_GET['order'] . "' and o.orders_id = op.orders_id and op.orders_products_id = opd.orders_products_id and opd.orders_products_download_id = '" . (int)$_GET['id'] . "' and opd.orders_products_filename != ''");
-  if (!tep_db_num_rows($downloads_query)) die;
-  $downloads = tep_db_fetch_array($downloads_query);
</pre><pre class="diff" id="added">+  $Qdownloads = $osC_Database-&gt;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 = :customers_id and o.orders_id = :orders_id and o.orders_id = op.orders_id and op.orders_products_id = opd.orders_products_id and opd.orders_products_download_id = :orders_products_download_id and opd.orders_products_filename != ""');
+  $Qdownloads-&gt;bindTable(':table_orders', TABLE_ORDERS);
+  $Qdownloads-&gt;bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
+  $Qdownloads-&gt;bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
+  $Qdownloads-&gt;bindInt(':customers_id', $osC_Customer-&gt;id);
+  $Qdownloads-&gt;bindInt(':orders_id', $_GET['order']);
+  $Qdownloads-&gt;bindInt(':orders_products_download_id', $_GET['id']);
+  $Qdownloads-&gt;execute();
+
+  if ($Qdownloads-&gt;numberOfRows() &lt; 1) {
+    die();
+  }
+
</pre><pre class="diff" id="context"> // MySQL 3.22 does not have INTERVAL
</pre><pre class="diff" id="removed">-  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);
</pre><pre class="diff" id="added">+  list($dt_year, $dt_month, $dt_day) = explode('-', $Qdownloads-&gt;value('date_purchased_day'));
+  $download_timestamp = mktime(23, 59, 59, $dt_month, $dt_day + $Qdownloads-&gt;value('download_maxdays'), $dt_year);
</pre><pre class="diff" id="context"> 
 // Die if time expired (maxdays = 0 means no time limit)
</pre><pre class="diff" id="removed">-  if (($downloads['download_maxdays'] != 0) &amp;&amp; ($download_timestamp &lt;= time())) die;
</pre><pre class="diff" id="added">+  if (($Qdownloads-&gt;value('download_maxdays') != 0) &amp;&amp; ($download_timestamp &lt;= time())) die;
</pre><pre class="diff" id="context"> // Die if remaining count is &lt;=0
</pre><pre class="diff" id="removed">-  if ($downloads['download_count'] &lt;= 0) die;
</pre><pre class="diff" id="added">+  if ($Qdownloads-&gt;value('download_count') &lt;= 0) die;
</pre><pre class="diff" id="context"> // Die if file is not there
</pre><pre class="diff" id="removed">-  if (!file_exists(DIR_FS_DOWNLOAD . $downloads['orders_products_filename'])) die;
</pre><pre class="diff" id="added">+  if (!file_exists(DIR_FS_DOWNLOAD . $Qdownloads-&gt;value('orders_products_filename'))) die;
</pre><pre class="diff" id="context"> 
 // Now decrement counter
</pre><pre class="diff" id="removed">-  tep_db_query("update " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " set download_count = download_count-1 where orders_products_download_id = '" . (int)$_GET['id'] . "'");
</pre><pre class="diff" id="added">+  $Qupdate = $osC_Database-&gt;query('update :table_orders_products_download set download_count = download_count-1 where orders_products_download_id = :orders_products_download_id');
+  $Qupdate-&gt;bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
+  $Qupdate-&gt;bindInt(':orders_products_download_id', $_GET['id']);
+  $Qupdate-&gt;execute();
</pre><pre class="diff" id="context"> 
 // Returns a random name, 16 to 20 characters long
 // There are more than 10^28 combinations
 // The directory is "hidden", i.e. starts with '.'
</pre><pre class="diff" id="removed">-function tep_random_name()
-{
</pre><pre class="diff" id="added">+function tep_random_name() {
</pre><pre class="diff" id="context">   $letters = 'abcdefghijklmnopqrstuvwxyz';
   $dirname = '.';
   $length = floor(tep_rand(16,20));
</pre><pre class="diff" id="added">+
</pre><pre class="diff" id="context">   for ($i = 1; $i &lt;= $length; $i++) {
    $q = floor(tep_rand(1,26));
    $dirname .= $letters[$q];
   }
</pre><pre class="diff" id="added">+
</pre><pre class="diff" id="context">   return $dirname;
 }
 
 // Unlinks all subdirectories and files in $dir
 // Works only on one subdir level, will not recurse
</pre><pre class="diff" id="removed">-function tep_unlink_temp_dir($dir)
-{
</pre><pre class="diff" id="added">+function tep_unlink_temp_dir($dir) {
</pre><pre class="diff" id="context">   $h1 = opendir($dir);
   while ($subdir = readdir($h1)) {
 // Ignore non directories
</pre><pre class="diff"><small id="info">@@ -81,7 +94,7 @@
</small></pre><pre class="diff" id="context">   header("Cache-Control: no-cache, must-revalidate");
   header("Pragma: no-cache");
   header("Content-Type: Application/octet-stream");
</pre><pre class="diff" id="removed">-  header("Content-disposition: attachment; filename=" . $downloads['orders_products_filename']);
</pre><pre class="diff" id="added">+  header("Content-disposition: attachment; filename=" . $Qdownloads-&gt;value('orders_products_filename'));
</pre><pre class="diff" id="context"> 
   if (DOWNLOAD_BY_REDIRECT == 'true') {
 // This will work only on Unix/Linux hosts
</pre><pre class="diff"><small id="info">@@ -89,11 +102,11 @@
</small></pre><pre class="diff" id="context">     $tempdir = tep_random_name();
     umask(0000);
     mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777);
</pre><pre class="diff" id="removed">-    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']);
</pre><pre class="diff" id="added">+    symlink(DIR_FS_DOWNLOAD . $Qdownloads-&gt;value('orders_products_filename'), DIR_FS_DOWNLOAD_PUBLIC . $tempdir . '/' . $Qdownloads-&gt;value('orders_products_filename'));
+    tep_redirect(DIR_WS_DOWNLOAD_PUBLIC . $tempdir . '/' . $Qdownloads-&gt;value('orders_products_filename'));
</pre><pre class="diff" id="context">   } else {
 // This will work on all systems, but will need considerable resources
 // We could also loop with fread($fp, 4096) to save memory
</pre><pre class="diff" id="removed">-    readfile(DIR_FS_DOWNLOAD . $downloads['orders_products_filename']);
</pre><pre class="diff" id="added">+    readfile(DIR_FS_DOWNLOAD . $Qdownloads-&gt;value('orders_products_filename'));
</pre><pre class="diff" id="context">   }
 ?&gt;
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.9</small></center>
</body></html>


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click