HRDIODB
[ class tree: HRDIODB ] [ index: HRDIODB ] [ all elements ]

Source for file file.php

Documentation is available at file.php

  1. <?php
  2. /**
  3.  * File download page.
  4.  * This file is responsible for initiating file compression (if needed) and
  5.  * making the file available for download.
  6.  * @package HRDIODB
  7.  */
  8.  
  9. /**
  10.  * This file is part of HRDIODB.
  11.  *
  12.  * HRDIODB is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * HRDIODB is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with HRDIODB; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25.  */
  26.  
  27. /** Configuration class */
  28. require_once("conf.php");
  29. /** Debugging functions */
  30. require_once("debugging.php");
  31. /** PHP session class */
  32. require_once("session_class.php");
  33. /** HRDI database class */
  34. require_once("hrdi_db_class.php");
  35. /** Download class */
  36. require_once("download_class.php");
  37. /** User class */
  38. require_once("user_class.php");
  39. /** Common class */
  40. require_once("common_class.php");
  41.  
  42. // Create class instances
  43. $session new session();
  44. $hdb new hrdi_db ($dsn);
  45. $user new user($hdb$session);
  46. $download new download($hdb$session$user);
  47.  
  48. // Make sure we're authenticated
  49. if (!$user->authenticated()) {
  50.   // Redirect to the login page
  51.     common::redirect("search.php");
  52. }
  53.  
  54. // Page title
  55. $page_title "";
  56.  
  57. // Include the page header
  58. require_once("header.php");
  59.  
  60. // Get the download file number
  61. $number @$_GET['n'];
  62.  
  63. // Get the number of days per file
  64. $days_per_file @$_GET['dpf'];
  65.  
  66. // Verify the download file number
  67. if (!is_numeric($number|| ($number 0)) {
  68.   error("Archive number is not valid");
  69.   require_once("footer.php");
  70.   exit(0);
  71. }
  72.  
  73. // Verify the number of days per file
  74. if (!is_numeric($days_per_file|| ($days_per_file 1)) {
  75.   error("Days per file is not valid");
  76.   require_once("footer.php");
  77.   exit(0);
  78. }
  79.  
  80. // Set the refresh code, we'll use this a couple of times
  81. $refresh_code '<meta http-equiv="refresh" content="3" url="'.$_SERVER['PHP_SELF'].'">';
  82.  
  83. // First, make sure that we prepare the download properly
  84. if ($download->prepare($number$days_per_file)) {
  85.   if ($download->is_error()) {
  86.     error($download->get_error());
  87.   else {
  88.     // Assume we're going to refresh
  89.         $refresh TRUE;
  90.  
  91.     print "<br/><br/><center><table class=\"hrdi\">";
  92.  
  93.     if ($download->is_available()) {
  94.       /* The archive is available. This could be because the archiving process 
  95.          has finished, or it could be because the file has been created from a 
  96.          previous request */
  97.  
  98.       // Print out the table with the file size, download link and MD5 sum
  99.             print "<tr><td class=\"label\" colspan=\"2\">File is ready ("
  100.           . $download->get_file_size()
  101.           . "): <a href=\""
  102.           . $download->get_download_file_path()
  103.           . "\">&rarr; Download Zip Archive</a></td></tr>
  104.              <tr><td class=\"label\">MD5 Sum</td><td class=\"data\">"
  105.           . $download->get_md5_sum()
  106.           . "</td></tr>";
  107.  
  108.       // Do not refresh this time
  109.             $refresh FALSE;
  110.     else if ($download->is_compressing()) {
  111.       // The archive is still being compressed
  112.  
  113.       // Print out the status message
  114.             print "<tr><td class=\"label\">File compression in progress ("
  115.           . $download->get_temp_file_size()
  116.           . "), please wait...</td></tr>";
  117.     else {
  118.       // Nothing is going on yet, start the download
  119.  
  120.       // Start the compression process
  121.             $download->compress();
  122.  
  123.       // Print out the status message
  124.             print "<tr><td class=\"label\">File compression has started, please wait...</td></tr>";
  125.     }
  126.   
  127.     print "</table></center>";
  128.  
  129.     // Print out the META refresh tag if we will be refreshing the page
  130.         if ($refresh{
  131.       print $refresh_code;
  132.     }
  133.   }
  134. else {
  135.   error("Search results were not found, please redo your search");
  136. }
  137.  
  138. // Include the page footer
  139. require_once("footer.php");
  140. ?>

Documentation generated on Tue, 23 Jan 2007 22:57:48 -0500 by phpDocumentor 1.3.0RC6