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.

496 lines
29 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: ./cite/formats/cite_html.php
  11. // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/cite/formats/cite_html.php $
  12. // Author(s): Matthias Steffens <mailto:refbase@extracts.de>
  13. //
  14. // Created: 10-Jun-06, 02:30
  15. // Modified: $Date: 2017-04-13 02:00:18 +0000 (Thu, 13 Apr 2017) $
  16. // $Author: karnesky $
  17. // $Revision: 1416 $
  18. // This is a citation format file (which must reside within the 'cite/formats/' sub-directory of your refbase root directory). It contains a
  19. // version of the 'citeRecords()' function that outputs a reference list from selected records in HTML format.
  20. //
  21. // TODO: - use divs + CSS styling (instead of a table-based layout) for _all_ output (not only for 'viewType=Mobile')
  22. // --------------------------------------------------------------------
  23. // --- BEGIN CITATION FORMAT ---
  24. function citeRecords($result, $rowsFound, $query, $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $previousOffset, $nextOffset, $wrapResults, $citeStyle, $citeOrder, $citeType, $orderBy, $headerMsg, $userID, $viewType)
  25. {
  26. global $databaseBaseURL; // these variables are defined in 'ini.inc.php'
  27. global $useVisualEffects;
  28. global $defaultDropDownFieldsEveryone;
  29. global $defaultDropDownFieldsLogin;
  30. global $defaultCiteStyle;
  31. global $additionalFieldsCitationView;
  32. global $displayResultsHeaderDefault;
  33. global $displayResultsFooterDefault;
  34. global $showLinkTypesInCitationView;
  35. global $showFieldItemLinks;
  36. global $maximumBrowseLinks;
  37. global $loc; // '$loc' is made globally available in 'core.php'
  38. global $client;
  39. global $displayType;
  40. $htmlData = ""; // make sure that our buffer variables are empty
  41. $recordData = "";
  42. // First, initialize some variables that we'll need later on
  43. // Calculate the number of all visible columns (which is needed as colspan value inside some TD tags)
  44. if ($showLinks == "1" && preg_match("/^(type|type-year|year)$/i", $citeOrder)) // in citation layout, we simply set it to a fixed value (either '1' or '2', depending on the values of '$showLinks' and '$citeOrder')
  45. $NoColumns = 2; // first column: literature citation, second column: 'display details' link
  46. else
  47. $NoColumns = 1;
  48. if (empty($displayType))
  49. $displayType = $_SESSION['userDefaultView']; // get the default view for the current user
  50. // If the results footer is displayed, we increase the colspan value by 1 to account for the checkbox column:
  51. if ((!preg_match("/^(Print|Mobile)$/i", $viewType)) AND (!preg_match("/^cli/i", $client)) AND ($wrapResults != "0") AND (!isset($displayResultsFooterDefault[$displayType]) OR (isset($displayResultsFooterDefault[$displayType]) AND ($displayResultsFooterDefault[$displayType] != "hidden"))))
  52. $NoColumns++;
  53. // Initialize array variables:
  54. $yearsArray = array();
  55. $typeTitlesArray = array();
  56. // Define inline text markup to be used by the 'citeRecord()' function:
  57. $markupPatternsArray = array("bold-prefix" => "<b>",
  58. "bold-suffix" => "</b>",
  59. "italic-prefix" => "<i>",
  60. "italic-suffix" => "</i>",
  61. "underline-prefix" => "<u>",
  62. "underline-suffix" => "</u>",
  63. "endash" => "&#8211;",
  64. "emdash" => "&#8212;",
  65. "ampersand" => "&",
  66. "double-quote" => '"',
  67. "double-quote-left" => "&ldquo;",
  68. "double-quote-right" => "&rdquo;",
  69. "single-quote" => "'",
  70. "single-quote-left" => "&lsquo;",
  71. "single-quote-right" => "&rsquo;",
  72. "less-than" => "<",
  73. "greater-than" => ">",
  74. "newline" => "\n<br>\n"
  75. );
  76. // Defines field-specific search & replace 'actions' that will be applied to the actual citation
  77. // for all those refbase fields that are listed in the corresponding 'fields' element:
  78. // (These search and replace actions will be performed *in addition* to those specified globally
  79. // in '$searchReplaceActionsArray' (defined in 'ini.inc.php'). Same rules apply as for
  80. // '$searchReplaceActionsArray'.)
  81. $fieldSpecificSearchReplaceActionsArray = array(
  82. array(
  83. 'fields' => array("abstract"),
  84. 'actions' => array("/[\r\n]+/" => "\n<br>\n") // for the 'abstract' field, transform runs of newline ('\n') or return ('\r') characters into a single <br> tag
  85. )
  86. );
  87. // In addition, for the "more info" section, we also substitute contents of the below 'fields'
  88. // with localized field values from variable '$loc'. Since the locales in '$loc' are already
  89. // HTML encoded, we have to exclude these fields from any further HTML encoding (done below).
  90. $fieldSpecificSearchReplaceActionsArray2 = $fieldSpecificSearchReplaceActionsArray;
  91. $fieldSpecificSearchReplaceActionsArray2[] = array(
  92. 'fields' => array("thesis", "approved", "marked", "copy", "selected"),
  93. 'actions' => array("/(.+)/e" => "\$loc['\\1']") // use localized field values (e.g., in case of german we display 'ja' instead of 'yes', etc)
  94. );
  95. static $encodingExceptionsArray = array("thesis", "approved", "marked", "copy", "selected");
  96. // LOOP OVER EACH RECORD:
  97. // Fetch one page of results (or less if on the last page)
  98. // (i.e., upto the limit specified in $showRows) fetch a row into the $row array and ...
  99. for ($rowCounter=0; (($rowCounter < $showRows) && ($row = @ mysqli_fetch_array($result))); $rowCounter++)
  100. {
  101. $encodedRowData = $row; // we keep '$row' in its original (unencoded) form since unencoded data will be required by function 'linkifyFieldItems()' below
  102. // NOTES: - Currently, HTML encoding and search & replace actions are applied separately
  103. // for the citation and the "more info" section underneath the citation. The
  104. // actions in this 'foreach' block concern the actual citation
  105. // - It might be better to pass the unencoded '$row' data to function 'citeRecord()'
  106. // which would then make calls to function 'encodeField()' individually for each
  107. // field (similar to as it is done it 'modsxml.inc.php')
  108. foreach ($encodedRowData as $rowFieldName => $rowFieldValue)
  109. {
  110. // NOTES: - We HTML encode non-ASCII chars for all but the author & editor fields. The author & editor
  111. // fields are excluded here since these fields must be passed *without* HTML entities to the
  112. // 'reArrangeAuthorContents()' function (which will then handle the HTML encoding by itself)
  113. // - Function 'encodeField()' will also apply any field-specific search & replace actions
  114. $encodedRowData[$rowFieldName] = encodeField($rowFieldName, $rowFieldValue, $fieldSpecificSearchReplaceActionsArray, array("author", "editor")); // function 'encodeField()' is defined in 'include.inc.php'
  115. }
  116. // Order attributes according to the chosen output style & record type:
  117. $record = citeRecord($encodedRowData, $citeStyle, $citeType, $markupPatternsArray, true); // function 'citeRecord()' is defined in the citation style file given in '$citeStyleFile' (which, in turn, must reside in the 'cite' directory of the refbase root directory), see function 'generateCitations()'
  118. // Print out the current record:
  119. if (!empty($record)) // unless the record buffer is empty...
  120. {
  121. // Print any section heading(s):
  122. if (preg_match("/year|type/i", $citeOrder))
  123. {
  124. if (preg_match("/^Mobile$/i", $viewType))
  125. {
  126. $headingPrefix = "\n<div class=\"sect\">";
  127. $headingSuffix = "</div>";
  128. }
  129. else
  130. {
  131. $headingPrefix = "\n<tr>"
  132. . "\n\t<td valign=\"top\" colspan=\"$NoColumns\">";
  133. $headingSuffix = "</td>"
  134. . "\n</tr>";
  135. }
  136. list($yearsArray, $typeTitlesArray, $sectionHeading) = generateSectionHeading($yearsArray, $typeTitlesArray, $row, $citeOrder, $headingPrefix, $headingSuffix, "<h4>", "</h4>", "<h5>", "</h5>"); // function 'generateSectionHeading()' is defined in 'cite.inc.php'
  137. $recordData .= $sectionHeading;
  138. }
  139. // Print out the record:
  140. if (is_integer($rowCounter / 2)) // if we currently are at an even number of rows
  141. $rowClass = "even";
  142. else
  143. $rowClass = "odd";
  144. if (preg_match("/^(cli|inc)/i", $client) OR ($wrapResults == "0")) // we use absolute links for CLI clients, for include mechanisms, or when returning only a partial document structure
  145. $baseURL = $databaseBaseURL;
  146. else
  147. $baseURL = "";
  148. $recordPermaLink = $databaseBaseURL . "show.php?record=" . $row["serial"]; // generate a permanent link for the current record
  149. if (preg_match("/^Mobile$/i", $viewType))
  150. {
  151. $recordData .= "\n<div class=\"" . $rowClass . "\">"
  152. . "\n\t<div class=\"citation\">" . $record . "</div>";
  153. }
  154. else
  155. {
  156. $recordData .= "\n<tr class=\"" . $rowClass . "\">";
  157. // Print a column with a checkbox:
  158. // Note: we omit the results footer in print/mobile view ('viewType=Print' or 'viewType=Mobile'), for CLI clients, and when outputting only a partial document structure ('wrapResults=0')!
  159. if ((!preg_match("/^Print$/i", $viewType)) AND (!preg_match("/^cli/i", $client)) AND ($wrapResults != "0") AND (!isset($displayResultsFooterDefault[$displayType]) OR (isset($displayResultsFooterDefault[$displayType]) AND ($displayResultsFooterDefault[$displayType] != "hidden"))))
  160. {
  161. $recordData .= "\n\t<td align=\"center\" valign=\"top\" width=\"10\">";
  162. // - Print a checkbox form element:
  163. if (!isset($displayResultsFooterDefault[$displayType]) OR (isset($displayResultsFooterDefault[$displayType]) AND ($displayResultsFooterDefault[$displayType] != "hidden")))
  164. $recordData .= "\n\t\t<input type=\"checkbox\" onclick=\"updateAllRecs();\" name=\"marked[]\" value=\"" . $row["serial"] . "\" title=\"" . $loc["selectRecord"] . "\">";
  165. if (!empty($row["orig_record"]))
  166. {
  167. if (!isset($displayResultsFooterDefault[$displayType]) OR (isset($displayResultsFooterDefault[$displayType]) AND ($displayResultsFooterDefault[$displayType] != "hidden")))
  168. $recordData .= "\n\t\t<br>";
  169. if ($row["orig_record"] < 0)
  170. $recordData .= "\n\t\t<img src=\"" . $baseURL . "img/ok.gif\" alt=\"(" . $loc["original"] . ")\" title=\"" . $loc["originalRecord"] . "\" width=\"14\" height=\"16\" hspace=\"0\" border=\"0\">";
  171. else // $row["orig_record"] > 0
  172. $recordData .= "\n\t\t<img src=\"" . $baseURL . "img/caution.gif\" alt=\"(" . $loc["duplicate"] . ")\" title=\"" . $loc["duplicateRecord"] . "\" width=\"5\" height=\"16\" hspace=\"0\" border=\"0\">";
  173. }
  174. // - Add <abbr> block which works as a microformat that allows applications to identify objects on web pages; see <http://unapi.info/specs/> for more info
  175. $recordData .= "\n\t\t<div class=\"unapi\"><abbr class=\"unapi-id\" title=\"" . $recordPermaLink . "\"></abbr></div>";
  176. $recordData .= "\n\t</td>";
  177. }
  178. // Print record data as a citation:
  179. $recordData .= "\n\t<td id=\"ref" . $row["serial"] . "\" class=\"citation\" valign=\"top\">"
  180. . "\n\t\t" . $record;
  181. // Display a triangle widget to show more info (keywords, abstract, etc) under each citation:
  182. if (!empty($additionalFieldsCitationView))
  183. {
  184. // Map MySQL field names to localized column names:
  185. $fieldNamesArray = mapFieldNames(); // function 'mapFieldNames()' is defined in 'include.inc.php'
  186. if ($useVisualEffects == "yes")
  187. $toggleVisibilityFunction = "toggleVisibilitySlide";
  188. else
  189. $toggleVisibilityFunction = "toggleVisibility";
  190. $recordData .= "\n\t\t<div class=\"showhide\">"
  191. . "\n\t\t\t<a href=\"javascript:" . $toggleVisibilityFunction . "('moreinfo" . $row["serial"] . "','toggleimg" . $row["serial"] . "','toggletxt" . $row["serial"] . "','more%20info')\" title=\"" . $loc["LinkTitle_ToggleVisibility"] . "\">"
  192. . "<img id=\"toggleimg" . $row["serial"] . "\" class=\"toggleimg\" src=\"" . $baseURL . "img/closed.gif\" alt=\"" . $loc["LinkTitle_ToggleVisibility"] . "\" width=\"9\" height=\"9\" hspace=\"0\" border=\"0\">"
  193. . "</a>"
  194. . "\n\t\t</div>"
  195. . "\n\t\t<div id=\"moreinfo" . $row["serial"] . "\" class=\"moreinfo\" style=\"display: none;\">";
  196. // Print additional fields:
  197. foreach ($additionalFieldsCitationView as $field)
  198. {
  199. if (isset($row[$field]) AND !empty($row[$field]))
  200. {
  201. $recordData .= "\n\t\t\t<div class=\"" . $field . "\"><strong>" . $fieldNamesArray[$field] . ":</strong> ";
  202. // Make field items into clickable search links:
  203. if (in_array($displayType, $showFieldItemLinks))
  204. // Note: Function 'linkifyFieldItems()' will also call function 'encodeField()' to HTML
  205. // encode non-ASCII chars and to apply any field-specific search & replace actions
  206. $recordData .= linkifyFieldItems($field, $row[$field], $userID, $fieldSpecificSearchReplaceActionsArray2, $encodingExceptionsArray, "/\s*[;]+\s*/", "; ", $showQuery, $showLinks, $showRows, $citeStyle, $citeOrder, $wrapResults, $displayType, $viewType); // function 'linkifyFieldItems()' is defined in 'include.inc.php'
  207. else // don't hotlink field items
  208. $recordData .= encodeField($field, $row[$field], $fieldSpecificSearchReplaceActionsArray2, $encodingExceptionsArray); // function 'encodeField()' is defined in 'include.inc.php'
  209. $recordData .= "</div>";
  210. }
  211. }
  212. // Print a row with links for the current record:
  213. $recordData .= "\n\t\t\t<div class=\"reflinks\">";
  214. // - Print the record's permanent URL:
  215. if (preg_match("/^inc/i", $client)) // we open links in a new browser window if refbase data are included somewhere else:
  216. $target = " target=\"_blank\"";
  217. else
  218. $target = "";
  219. $recordData .= "\n\t\t\t\t<div class=\"permalink\"><a href=\"" . $recordPermaLink . "\"" . $target . " title=\"" . $loc["LinkTitle_Permalink"] . "\">";
  220. if (preg_match("/^Print$/i", $viewType)) // for print view, we use the URL as link title
  221. $recordData .= $recordPermaLink;
  222. else
  223. $recordData .= $loc["PermalinkShort"];
  224. $recordData .= "</a></div>";
  225. // - Print additional links to cite/export the current record:
  226. // Note: we omit the additional links in print view ('viewType=Print')
  227. if (!preg_match("/^Print$/i", $viewType))
  228. {
  229. // -- Print cite links:
  230. if (isset($_SESSION['user_permissions']) AND preg_match("/allow_cite/", $_SESSION['user_permissions']) AND isset($_SESSION['user_cite_formats']))
  231. {
  232. $userCiteFormatsArray = preg_split("/ *; */", $_SESSION['user_cite_formats'], -1, PREG_SPLIT_NO_EMPTY); // get a list of the user's cite formats (the 'PREG_SPLIT_NO_EMPTY' flag causes only non-empty pieces to be returned)
  233. $recordData .= "\n\t\t\t\t<div class=\"citelinks\">"
  234. . "&nbsp;|&nbsp;" . $loc["SaveCitation"] . ":";
  235. foreach ($userCiteFormatsArray as $citeFormat)
  236. if (!preg_match("/^html$/i", $citeFormat)) // for now, we exclude the "HTML" cite format (as it's not any different to the regular Citation view HTML output)
  237. $recordData .= "\n\t\t\t\t\t&nbsp;<a href=\"" . $baseURL . generateURL("show.php", $citeFormat, array("record" => $row['serial']), true, "", "", $citeStyle, $citeOrder) . "\" title=\"" . $loc["LinkTitle_SaveCitationFormat_Prefix"] . $citeFormat . $loc["LinkTitle_SaveCitationFormat_Suffix"] . "\">" . $citeFormat . "</a>";
  238. $recordData .= "\n\t\t\t\t</div>";
  239. }
  240. // -- Print export links:
  241. if (isset($_SESSION['user_permissions']) AND preg_match("/allow_export|allow_batch_export/", $_SESSION['user_permissions']) AND isset($_SESSION['user_export_formats']))
  242. {
  243. $userExportFormatsArray = preg_split("/ *; */", $_SESSION['user_export_formats'], -1, PREG_SPLIT_NO_EMPTY); // get a list of the user's export formats
  244. $recordData .= "\n\t\t\t\t<div class=\"exportlinks\">"
  245. . "&nbsp;|&nbsp;" . $loc["ExportRecord"] . ":";
  246. foreach ($userExportFormatsArray as $exportFormat)
  247. $recordData .= "\n\t\t\t\t\t&nbsp;<a href=\"" . $baseURL . generateURL("show.php", $exportFormat, array("record" => $row['serial'], "exportType" => "file"), true, "", "", $citeStyle) . "\" title=\"" . $loc["LinkTitle_ExportRecordFormat_Prefix"] . $exportFormat . $loc["LinkTitle_ExportRecordFormat_Suffix"] . "\">" . $exportFormat . "</a>";
  248. $recordData .= "\n\t\t\t\t</div>";
  249. }
  250. }
  251. $recordData .= "\n\t\t\t</div>"
  252. . "\n\t\t</div>";
  253. }
  254. $recordData .= "\n\t</td>";
  255. }
  256. // Display the regular links column:
  257. if ($showLinks == "1")
  258. {
  259. if (preg_match("/^Mobile$/i", $viewType))
  260. $recordData .= "\n\t<div class=\"links\">";
  261. else
  262. $recordData .= "\n\t<td class=\"links\" valign=\"top\" width=\"42\">";
  263. // Print out available links:
  264. // for Citation view, we'll use the '$showLinkTypesInCitationView' array that's defined in 'ini.inc.php'
  265. // to specify which links shall be displayed (if available and if 'showLinks == 1')
  266. // (for links of type DOI/URL/ISBN/XREF, only one link will be printed; order of preference: DOI, URL, ISBN, XREF)
  267. $recordData .= printLinks($showLinkTypesInCitationView, $row, $showQuery, $showLinks, $wrapResults, $userID, $viewType, $orderBy); // function 'printLinks()' is defined in 'search.php'
  268. if (preg_match("/^Mobile$/i", $viewType))
  269. $recordData .= "\n\t</div>";
  270. else
  271. $recordData .= "\n\t</td>";
  272. }
  273. if (preg_match("/^Mobile$/i", $viewType))
  274. $recordData .= "\n</div>";
  275. else
  276. $recordData .= "\n</tr>";
  277. }
  278. }
  279. // OUTPUT RESULTS:
  280. // Note: we omit the results header, browse links & query form for CLI clients, and when outputting only a partial document structure ('wrapResults=0')
  281. if (!preg_match("/^cli/i", $client) AND ($wrapResults != "0"))
  282. {
  283. // Note: we also omit the results header in print/mobile view ('viewType=Print' or 'viewType=Mobile')
  284. if ((!preg_match("/^(Print|Mobile)$/i", $viewType)) AND (!isset($displayResultsHeaderDefault[$displayType]) OR (isset($displayResultsHeaderDefault[$displayType]) AND ($displayResultsHeaderDefault[$displayType] != "hidden"))))
  285. {
  286. // Extract the first field from the 'WHERE' clause:
  287. if (preg_match("/ WHERE [ ()]*(\w+)/i", $query))
  288. $selectedField = preg_replace("/.+ WHERE [ ()]*(\w+).*/i", "\\1", $query);
  289. else
  290. $selectedField = "author"; // in the 'Search within Results" form, we'll select the 'author' field by default
  291. // Map MySQL field names to localized column names:
  292. $fieldNamesArray = mapFieldNames(true);
  293. $localizedDropDownFieldsArray = array();
  294. if (isset($_SESSION['loginEmail']) AND !empty($defaultDropDownFieldsLogin)) // if a user is logged in -AND- there were any additional fields specified...
  295. $dropDownFieldsArray = array_merge($defaultDropDownFieldsEveryone, $defaultDropDownFieldsLogin); // ...add these additional fields to the list of fields visible in the dropdown menus of the results header
  296. else
  297. $dropDownFieldsArray = $defaultDropDownFieldsEveryone;
  298. foreach ($dropDownFieldsArray as $field)
  299. {
  300. if (isset($fieldNamesArray[$field]))
  301. $localizedDropDownFieldsArray[$field] = $fieldNamesArray[$field];
  302. else // no localized field name exists, so we use the original field name
  303. $localizedDropDownFieldsArray[$field] = $field;
  304. }
  305. // Get all citation styles for the current user:
  306. if (!isset($_SESSION['user_styles']))
  307. $citationStylesArray = array($defaultCiteStyle);
  308. else
  309. {
  310. $citationStylesArray = array();
  311. $citationStylesTempArray = preg_split("/ *; */", $_SESSION['user_styles']); // get the user's list of citation styles
  312. foreach ($citationStylesTempArray as $citationStyle)
  313. $citationStylesArray[$citationStyle] = $citationStyle;
  314. }
  315. // 2) Build forms containing options to show the user's groups, refine the search results or change the displayed columns:
  316. // TODO for 2b+2c: should we allow users to choose via the web interface which columns are included in the popup menus?
  317. // 2a) Build a FORM with a popup containing the user's groups:
  318. $formElementsGroup = buildGroupSearchElements("search.php", $queryURL, $query, $showQuery, $showLinks, $showRows, $citeStyle, $citeOrder, $displayType); // function 'buildGroupSearchElements()' is defined in 'include.inc.php'
  319. // 2b) Build a FORM containing options to refine the search results:
  320. // Call the 'buildRefineSearchElements()' function (defined in 'include.inc.php') which does the actual work:
  321. $formElementsRefine = buildRefineSearchElements("search.php", $queryURL, $showQuery, $showLinks, $showRows, $citeStyle, $citeOrder, $localizedDropDownFieldsArray, $selectedField, $displayType);
  322. // 2c) Build a FORM containing display options (change citation style & sort order, or change the number of records displayed per page):
  323. // Call the 'buildDisplayOptionsElements()' function (defined in 'include.inc.php') which does the actual work:
  324. $formElementsDisplayOptions = buildDisplayOptionsElements("search.php", $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $citeStyle, $citeOrder, $citationStylesArray, $citeStyle, 2, $displayType, $headerMsg);
  325. $htmlData .= displayResultsHeader("search.php", $formElementsGroup, $formElementsRefine, $formElementsDisplayOptions, $displayType); // function 'displayResultsHeader()' is defined in 'results_header.inc.php'
  326. // and insert a divider line (which separates the results header from the browse links & results data below):
  327. $htmlData .= "\n<hr class=\"resultsheader\" align=\"center\" width=\"93%\">";
  328. }
  329. // Build a TABLE with links for "previous" & "next" browsing, as well as links to intermediate pages
  330. // call the 'buildBrowseLinks()' function (defined in 'include.inc.php'):
  331. $BrowseLinks = buildBrowseLinks("search.php", $query, $NoColumns, $rowsFound, $showQuery, $showLinks, $showRows, $rowOffset, $previousOffset, $nextOffset, $wrapResults, $maximumBrowseLinks, "sqlSearch", "Cite", $citeStyle, $citeOrder, $orderBy, $headerMsg, $viewType);
  332. $htmlData .= $BrowseLinks;
  333. if (preg_match("/^Mobile$/i", $viewType))
  334. {
  335. // Extract the original OpenSearch/CQL query that was saved by 'opensearch.php' as a session variable:
  336. if (isset($_SESSION['cqlQuery']))
  337. $cqlQuery = $_SESSION['cqlQuery'];
  338. else
  339. $cqlQuery = "";
  340. // Include an OpenSearch-style (CQL) query form:
  341. $htmlData .= "\n<div id=\"queryform\">"
  342. . "\n\t<form action=\"opensearch.php\" method=\"GET\" name=\"openSearch\">"
  343. . "\n\t\t<input type=\"hidden\" name=\"formType\" value=\"openSearch\">"
  344. . "\n\t\t<input type=\"hidden\" name=\"submit\" value=\"" . $loc["ButtonTitle_Search"] . "\">"
  345. . "\n\t\t<input type=\"hidden\" name=\"viewType\" value=\"" . $viewType . "\">"
  346. . "\n\t\t<input type=\"hidden\" name=\"startRecord\" value=\"1\">"
  347. . "\n\t\t<input type=\"hidden\" name=\"maximumRecords\" value=\"" . $showRows . "\">"
  348. . "\n\t\t<input type=\"hidden\" name=\"recordSchema\" value=\"html\">"
  349. . "\n\t\t<input type=\"text\" name=\"query\" value=\"" . $cqlQuery . "\" size=\"25\" title=\"" . $loc["DescriptionEnterSearchString"] . "\">"
  350. . "\n\t\t<input type=\"submit\" name=\"submit\" value=\"" . $loc["ButtonTitle_Search"] . "\" title=\"" . $loc["DescriptionSearchDB"] . "\">"
  351. . "\n\t</form>"
  352. . "\n</div>";
  353. }
  354. elseif ((!preg_match("/^Print$/i", $viewType)) AND (!isset($displayResultsFooterDefault[$displayType]) OR (isset($displayResultsFooterDefault[$displayType]) AND ($displayResultsFooterDefault[$displayType] != "hidden"))))
  355. {
  356. // Include the 'queryResults' form:
  357. $htmlData .= "\n<form action=\"search.php\" method=\"GET\" name=\"queryResults\">"
  358. . "\n<input type=\"hidden\" name=\"formType\" value=\"queryResults\">"
  359. . "\n<input type=\"hidden\" name=\"submit\" value=\"Cite\">" // provide a default value for the 'submit' form tag (then, if any form element is selected, hitting <enter> will act as if the user clicked the 'Cite' button)
  360. . "\n<input type=\"hidden\" name=\"originalDisplayType\" value=\"" . $displayType . "\">" // embed the original value of the '$displayType' variable
  361. . "\n<input type=\"hidden\" name=\"orderBy\" value=\"" . rawurlencode($orderBy) . "\">" // embed the current ORDER BY parameter so that it can be re-applied when displaying details
  362. . "\n<input type=\"hidden\" name=\"showQuery\" value=\"" . $showQuery . "\">" // embed the current value of '$showQuery' so that it's available on 'display details' (batch display) & 'cite'
  363. . "\n<input type=\"hidden\" name=\"showLinks\" value=\"" . $showLinks . "\">" // embed the current value of '$showLinks' so that it's available on 'display details' (batch display) & 'cite'
  364. . "\n<input type=\"hidden\" name=\"showRows\" value=\"" . $showRows . "\">" // embed the current value of '$showRows' so that it's available on 'display details' (batch display) & 'cite'
  365. . "\n<input type=\"hidden\" name=\"rowOffset\" value=\"" . $rowOffset . "\">" // embed the current value of '$rowOffset' so that it can be re-applied after the user pressed either of the 'Add' or 'Remove' buttons within the 'queryResults' form
  366. // Note: the inclusion of '$rowOffset' here is only meant to support reloading of the same results page again after a user clicked the 'Add' or 'Remove' buttons
  367. // However, '$rowOffset' MUST NOT be set if the user clicked the 'Display' or 'Cite' button! Therefore we'll trap for this case at the top of the script.
  368. . "\n<input type=\"hidden\" name=\"sqlQuery\" value=\"" . $queryURL . "\">"; // embed the current sqlQuery so that it can be re-applied after the user pressed either of the 'Add' or 'Remove' buttons within the 'queryResults' form
  369. }
  370. }
  371. // Output query results:
  372. if (preg_match("/^Mobile$/i", $viewType))
  373. {
  374. $htmlData .= "\n<div id=\"citations\" class=\"results\">"
  375. . $recordData
  376. . "\n</div>";
  377. }
  378. else
  379. {
  380. $htmlData .= "\n<table id=\"citations\" class=\"results\" align=\"center\" border=\"0\" cellpadding=\"7\" cellspacing=\"0\" width=\"95%\" summary=\"This table holds the database results for your query\">"
  381. . $recordData
  382. . "\n</table>";
  383. }
  384. // Append the footer:
  385. // Note: we omit the results footer & browse links in print/mobile view ('viewType=Print' or 'viewType=Mobile'), for CLI clients, and when outputting only a partial document structure ('wrapResults=0')!
  386. if ((!preg_match("/^(Print|Mobile)$/i", $viewType)) AND (!preg_match("/^cli/i", $client)) AND ($wrapResults != "0"))
  387. {
  388. // Again, insert the (already constructed) BROWSE LINKS
  389. // (i.e., a TABLE with links for "previous" & "next" browsing, as well as links to intermediate pages)
  390. $htmlData .= $BrowseLinks;
  391. // Build a results footer with form elements to cite, group or export all/selected records:
  392. if (!isset($displayResultsFooterDefault[$displayType]) OR (isset($displayResultsFooterDefault[$displayType]) AND ($displayResultsFooterDefault[$displayType] != "hidden")))
  393. {
  394. if (isset($_SESSION['user_permissions']) AND ((isset($_SESSION['loginEmail']) AND preg_match("/allow_cite|allow_user_groups|allow_export|allow_batch_export/", $_SESSION['user_permissions'])) OR (!isset($_SESSION['loginEmail']) AND preg_match("/allow_cite/", $_SESSION['user_permissions'])))) // if the 'user_permissions' session variable does contain any of the following: 'allow_cite' -AND- if logged in, aditionally: 'allow_user_groups', 'allow_export', 'allow_batch_export'...
  395. // ...Insert a divider line (which separates the results data from the forms in the footer):
  396. $htmlData .= "\n<hr class=\"resultsfooter\" align=\"center\">";
  397. // Call the 'buildResultsFooter()' function (which does the actual work):
  398. $htmlData .= buildResultsFooter($showRows, $citeStyle, $citeOrder, $displayType, $headerMsg);
  399. }
  400. }
  401. if ((!preg_match("/^(Print|Mobile)$/i", $viewType)) AND (!preg_match("/^cli/i", $client)) AND ($wrapResults != "0") AND (!isset($displayResultsFooterDefault[$displayType]) OR (isset($displayResultsFooterDefault[$displayType]) AND ($displayResultsFooterDefault[$displayType] != "hidden"))))
  402. {
  403. // Finish the form:
  404. $htmlData .= "\n</form>";
  405. }
  406. return $htmlData;
  407. }
  408. // --- END CITATION FORMAT ---
  409. ?>