You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
6.9 KiB

  1. <?php
  2. // Project: Web Reference Database (refbase) <http://www.refbase.net>
  3. // Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
  4. // original author(s).
  5. //
  6. // This code is distributed in the hope that it will be useful,
  7. // but WITHOUT ANY WARRANTY. Please see the GNU General Public
  8. // License for more details.
  9. //
  10. // File: ./receipt.php
  11. // Repository: $HeadURL$
  12. // Author(s): Matthias Steffens <mailto:refbase@extracts.de>
  13. //
  14. // Created: 09-May-08, 12:00
  15. // Modified: $Date: 2012-02-27 20:25:30 +0000 (Mon, 27 Feb 2012) $
  16. // $Author$
  17. // $Revision: 1337 $
  18. // This php script will display a query history for the user's
  19. // current session, i.e. it will display links to any previous
  20. // search results
  21. // TODO: I18n
  22. // Incorporate some include files:
  23. include 'initialize/db.inc.php'; // 'db.inc.php' is included to hide username and password
  24. include 'includes/header.inc.php'; // include header
  25. include 'includes/footer.inc.php'; // include footer
  26. include 'includes/include.inc.php'; // include common functions
  27. include 'initialize/ini.inc.php'; // include common variables
  28. // --------------------------------------------------------------------
  29. // START A SESSION:
  30. // call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables:
  31. start_session(true);
  32. // --------------------------------------------------------------------
  33. // Initialize preferred display language:
  34. // (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function)
  35. include 'includes/locales.inc.php'; // include the locales
  36. // --------------------------------------------------------------------
  37. // [ Extract form variables sent through POST/GET by use of the '$_REQUEST' variable ]
  38. // [ !! NOTE !!: for details see <http://www.php.net/release_4_2_1.php> & <http://www.php.net/manual/en/language.variables.predefined.php> ]
  39. // If there's no stored message available:
  40. if (!isset($_SESSION['HeaderString']))
  41. $HeaderString = "Recall a query from your current session:"; // Provide the default message
  42. else
  43. {
  44. $HeaderString = $_SESSION['HeaderString']; // extract 'HeaderString' session variable (only necessary if register globals is OFF!)
  45. // Note: though we clear the session variable, the current message is still available to this script via '$HeaderString':
  46. deleteSessionVariable("HeaderString"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
  47. }
  48. // Extract the view type requested by the user (either 'Mobile', 'Print', 'Web' or ''):
  49. // ('' will produce the default 'Web' output style)
  50. if (isset($_REQUEST['viewType']))
  51. $viewType = $_REQUEST['viewType'];
  52. else
  53. $viewType = "";
  54. if (isset($_REQUEST['wrapResults']) AND ($_REQUEST['wrapResults'] == "0"))
  55. $wrapResults = "0"; // 'wrapResults=0' causes refbase to output only a partial document structure containing solely the query history (i.e. everything is omitted except for the <div id="queryhistory">)
  56. else
  57. $wrapResults = "1"; // we'll output a full HTML document structure unless the 'wrapResults' parameter is set explicitly to "0"
  58. // Get the query URL of the formerly displayed results page:
  59. if (isset($_SESSION['oldQuery']))
  60. $oldQuery = $_SESSION['oldQuery'];
  61. else
  62. $oldQuery = array();
  63. // Get any saved links to previous search results:
  64. if (isset($_SESSION['queryHistory']))
  65. $queryHistory = $_SESSION['queryHistory'];
  66. else
  67. $queryHistory = array();
  68. // Check if there's any query history available:
  69. if (empty($queryHistory))
  70. {
  71. // return an appropriate error message:
  72. $HeaderString = returnMsg("No query history available!", "warning", "strong", "HeaderString"); // function 'returnMsg()' is defined in 'include.inc.php'
  73. header("Location: " . $referer); // variable '$referer' is globally defined in function 'start_session()' in 'include.inc.php'
  74. exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  75. }
  76. // --------------------------------------------------------------------
  77. // (4) DISPLAY HEADER & RESULTS
  78. // (NOTE: Since there's no need to query the database here, we won't perform any of the following: (1) OPEN CONNECTION, (2) SELECT DATABASE, (3) RUN QUERY, (5) CLOSE CONNECTION)
  79. // Show the login status:
  80. showLogin(); // (function 'showLogin()' is defined in 'include.inc.php')
  81. // (4a) DISPLAY header:
  82. // Call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'):
  83. if ($wrapResults != "0")
  84. {
  85. displayHTMLhead(encodeHTML($officialDatabaseName) . " -- Query History", "noindex,nofollow", "Displays links to previous search results", "", false, "", $viewType, array());
  86. if (!preg_match("/^(Print|Mobile)$/i", $viewType)) // Note: we omit the visible header in print/mobile view ('viewType=Print' or 'viewType=Mobile')
  87. showPageHeader($HeaderString);
  88. echo "\n";
  89. }
  90. // (4b) DISPLAY results:
  91. echo "<div id=\"queryhistory\">";
  92. // Print a link to the current query:
  93. if (!empty($oldQuery))
  94. {
  95. echo "\n\t<div id=\"currentquery\">"
  96. . "\n\t\t<h5>Current Query</h5>";
  97. // Extract the 'WHERE' clause from the current SQL query:
  98. $queryWhereClause = extractWHEREclause($oldQuery["sqlQuery"]); // function 'extractWHEREclause()' is defined in 'include.inc.php'
  99. $queryTitle = encodeHTML(explainSQLQuery($queryWhereClause)); // functions 'encodeHTML()' and 'explainSQLQuery()' are defined in 'include.inc.php'
  100. // Generate a 'search.php' URL that points to the current query:
  101. $queryURL = generateURL("search.php", "html", $oldQuery, true); // function 'generateURL()' is defined in 'include.inc.php'
  102. echo "\n\t\t<div class=\"even\">"
  103. . "\n\t\t\t<a href=\"" . $queryURL . "\">" . $queryTitle . "</a>"
  104. . "\n\t\t</div>"
  105. . "\n\t</div>";
  106. }
  107. // Print links to any previous search results:
  108. if (!empty($queryHistory))
  109. {
  110. echo "\n\t<div id=\"previousqueries\">"
  111. . "\n\t\t<h5>Previous Queries</h5>";
  112. $queryHistory = array_reverse($queryHistory);
  113. // Display links to previous search results:
  114. for ($i = 0; $i < count($queryHistory); $i++)
  115. {
  116. if (is_integer($i / 2)) // if we currently are at an even number of rows
  117. $rowClass = "even";
  118. else
  119. $rowClass = "odd";
  120. echo "\n\t\t<div class=\"" . $rowClass . "\">"
  121. . "\n\t\t\t" . $queryHistory[$i]
  122. . "\n\t\t</div>";
  123. }
  124. echo "\n\t</div>";
  125. }
  126. echo "\n</div>";
  127. // --------------------------------------------------------------------
  128. // DISPLAY THE HTML FOOTER:
  129. // Call the 'showPageFooter()' and 'displayHTMLfoot()' functions (which are defined in 'footer.inc.php')
  130. if ($wrapResults != "0")
  131. {
  132. if (!preg_match("/^(Print|Mobile)$/i", $viewType)) // Note: we omit the visible footer in print/mobile view ('viewType=Print' or 'viewType=Mobile')
  133. showPageFooter($HeaderString);
  134. displayHTMLfoot();
  135. }
  136. // --------------------------------------------------------------------
  137. ?>