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.

178 lines
7.0 KiB

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