// // Alternatively, the contents of this file may be used under the terms of // either the GNU General Public License Version 2 or later (the "GPL"), or // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), // in which case the provisions of the GPL or the LGPL are applicable instead // of those above. If you wish to allow use of your version of this file only // under the terms of either the GPL or the LGPL, and not to allow others to // use your version of this file under the terms of the MPL, indicate your // decision by deleting the provisions above and replace them with the notice // and other provisions required by the GPL or the LGPL. If you do not delete // the provisions above, a recipient may use your version of this file under // the terms of any one of the MPL, the GPL or the LGPL. // // ***** END LICENSE BLOCK ***** ?> '$maxlife' AND `type`='download' LIMIT 1"; $sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE); if (mysql_num_rows($sql_result)=="0") { //Insert a record of this download for the next 10 minutes anyway. :-) $today=date("YmdHis"); $sql = "INSERT INTO `downloads` (`ID`,`date`,`vID`, `user_ip`, `user_agent`, `type`) VALUES ('$id','$today','$vid', '$remote_addr', '$_SERVER[HTTP_USER_AGENT]', 'download');"; $sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE); //Cleanup the Individual Downloads part of the table for old records $sql = "DELETE FROM `downloads` WHERE `date`<'$maxlife' AND `type`='download'"; $sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE); $today=date("Ymd")."000000"; //Per day download tracking -- Record hits for this day in the record (if it doesn't exist create it) $sql = "SELECT `dID` FROM `downloads` WHERE `ID`='$id' AND `date`='$today' AND `type`='count' LIMIT 1"; $sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE); if (mysql_num_rows($sql_result)=="0") { $sql = "INSERT INTO `downloads` (`ID`,`date`,`downloadcount`,`type`) VALUES ('$id','$today','1','count');"; } else { $row = mysql_fetch_array($sql_result); $sql = "UPDATE `downloads` SET `downloadcount`=downloadcount+1 WHERE `dID`='$row[dID]' LIMIT 1"; } $sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE); //Download Statistic Management Code -- Maintain the last 7 days record count $mindate = date("Ymd", mktime(0, 0, 0, date("m"), date("d")-7, date("Y")))."000000"; $downloadcount="0"; $sql = "SELECT `downloadcount` FROM `downloads` WHERE `ID`='$id' AND `date`>='$mindate' AND `type`='count' ORDER BY `date` DESC"; $sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE); while ($row = mysql_fetch_array($sql_result)) { $downloadcount = $downloadcount+$row["downloadcount"]; } //Update the 7 day count in the main record. $sql = "UPDATE `main` SET `downloadcount`='$downloadcount' WHERE `ID`='$id' LIMIT 1"; $sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE); //Update the total downloadcount in the main record. $sql = "UPDATE `main` SET `TotalDownloads`=TotalDownloads+1 WHERE `ID`='$id' LIMIT 1"; $sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE); //Clean up the Counts per day for >8 days. $sql = "DELETE FROM `downloads` WHERE `ID`='$id' AND `date`<'$mindate' AND `type`='count'"; $sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE); } //Send User on their way to the file, if requested... if ($_GET["passthrough"]=="yes") { header("Location: $uri"); } ?>