index.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. require_once 'settings.php';
  3. require_once 'inc/include.php';
  4. require_once 'inc/phpZotero.php';
  5. include_once 'inc/header.php'; // HTML header including css file
  6. $zotero = new phpZotero($API_key);
  7. $ipp=$_REQUEST['ipp'];
  8. if (!($ipp)) $ipp = $def_ipp;
  9. $sort=$_REQUEST['sort'];
  10. if (!($sort)) $sort = $def_sort;
  11. $sortorder=$_REQUEST['sortorder'];
  12. if (!($sortorder)) $sortorder = $def_sortorder;
  13. $page=$_REQUEST['page'];
  14. if (!($page)) $page = 1;
  15. //purge old files from the cache
  16. purge_cache(realpath("./" . $cache_dir), $cache_age);
  17. $i = 0;
  18. $item = array( 0 => array(title=>"", itemKey=>"", creatorSummary=>"", year=>"", numChildren=>""));
  19. // get first set of items from API
  20. $start = ($page - 1) * $ipp;
  21. if ($ipp > $fetchlimit) $limit = $fetchlimit; else $limit = $ipp;
  22. $items = $zotero->getItemsTop($user_ID, array(format=>'atom', content=>'none', start=>$start, limit=>$limit, order=>$sort, sort=>$sortorder));
  23. $totalitems = intval(substr($items,strpos($items, "<zapi:totalResults>") + 19, strpos($items, "</zapi:totalResults>") - strpos($items, "<zapi:totalResults>") - 19));
  24. // MAIN DATA TABLE
  25. // parse result sets, write out data and get more from API if needed
  26. echo("<table class=\"library-items-div\">\n");
  27. echo("<tr><td><b>Attachments</b></td><td><b>Creator</b></td><td><b>Year</b></td><td><b>Title</b></td></tr></b>");
  28. while (($i < ($ipp - 1)) && (strpos($items, "<entry>")>0)) {
  29. $offset=0;
  30. $pos = strpos($items, "<entry>", $offset);
  31. while ($pos !== false) {
  32. $entry = substr($items,strpos($items, "<entry>", $offset), strpos($items, "</entry>", $offset) - strpos($items, "<entry>", $offset) + 8);
  33. $item_title = "";
  34. $item_itemKey = "";
  35. $item_creatorSummary = "";
  36. $item_year = "";
  37. $item_numChildren = "";
  38. if (strpos($entry, "<title>")>0) $item_title = substr($entry,strpos($entry, "<title>") + 7, strpos($entry, "</title>") - strpos($entry, "<title>") - 7);
  39. if (strpos($entry, "<zapi:key>")>0) $item_itemKey = substr($entry,strpos($entry, "<zapi:key>") + 10, strpos($entry, "</zapi:key>") - strpos($entry, "<zapi:key>") - 10);
  40. if (strpos($entry, "<zapi:creatorSummary>")>0) $item_creatorSummary = substr($entry,strpos($entry, "<zapi:creatorSummary>") + 21, strpos($entry, "</zapi:creatorSummary>") - strpos($entry, "<zapi:creatorSummary>") - 21);
  41. if (strpos($entry, "<zapi:year>")>0) $item_year = substr($entry,strpos($entry, "<zapi:year>") + 11, strpos($entry, "</zapi:year>") - strpos($entry, "<zapi:year>") - 11);
  42. if (strpos($entry, "<zapi:numChildren>")>0) $item_numChildren = substr($entry,strpos($entry, "<zapi:numChildren>") + 18, strpos($entry, "</zapi:numChildren>") - strpos($entry, "<zapi:numChildren>") - 18);
  43. $item[$i] = array(title=>$item_title, itemKey=>$item_itemKey, creatorSummary=>$item_creatorSummary, year=>$item_year, numChildren=>$item_numChildren);
  44. echo("<tr>");
  45. echo("<td><a href=\"details.php?itemkey=" . $item[$i]['itemKey'] . "\">" . $item[$i]['numChildren'] . "</a></td>");
  46. echo("<td><a href=\"details.php?itemkey=" . $item[$i]['itemKey'] . "\">" . $item[$i]['creatorSummary'] . "</a></td>");
  47. echo("<td><a href=\"details.php?itemkey=" . $item[$i]['itemKey'] . "\">" . $item[$i]['year'] . "</a></td>");
  48. echo("<td><a href=\"details.php?itemkey=" . $item[$i]['itemKey'] . "\">" . $item[$i]['title'] . "</a></td>");
  49. echo("</tr>\n");
  50. $i = $i +1;
  51. $offset = strpos($items, "</entry>", $offset) + 8;
  52. $pos = strpos($items, "<entry>", $offset);
  53. }
  54. $items = $zotero->getItemsTop($user_ID, array(format=>'atom', content=>'none', start=>($start+$i), limit=>$limit, order=>$sort, sort=>$sortorder));
  55. }
  56. echo("</table><br>\n\n");
  57. echo(($start +1) . " to " . ($start + $i) . " of " . $totalitems);
  58. // NAVIGATION FOOTER
  59. echo("<hr>\n<table>\n");
  60. $parm_ipp = ($ipp == $def_ipp) ? "": "&ipp=$ipp";
  61. $parm_sort = ($sort == $def_sort) ? "": "&sort=$sort";
  62. $parm_sortorder = ($sortorder == $def_sortorder) ? "": "&sortorder=$sortorder";
  63. $i = 1;
  64. echo("<tr><td>Pages</td><td>");
  65. $pages = intval($totalitems / $ipp) + 1;
  66. while ($i <= $pages) {
  67. if ($i != $page) echo("<a href=\"?page=$i" . $parm_ipp . $parm_sort . $parm_sortorder . "\">");
  68. echo ("-$i-");
  69. if ($i != $page) echo("</a>");
  70. echo ("&nbsp;&nbsp;&nbsp;");
  71. $i = $i + 1;
  72. if ($i > 5) {
  73. if ($i < ($page - 2)) {
  74. $i = $page - 2;
  75. echo (" . . . &nbsp;&nbsp;&nbsp;");
  76. }
  77. }
  78. if (($i > ($page + 2)) && ($i > 5)) {
  79. if ($i < ($pages - 4)) {
  80. $i = $pages - 4;
  81. echo (" . . . &nbsp;&nbsp;&nbsp;");
  82. }
  83. }
  84. }
  85. echo ("</td></tr>\n");
  86. echo("<tr><td>Items&nbsp;per&nbsp;Page</td><td>");
  87. $ipp_list = array (1,10,20,50,100,200,500,1000,9999999);
  88. $i = 0;
  89. while ($i <= 7) {
  90. if ($ipp != $ipp_list[$i]) echo("<a href=\"?page=$page&ipp=" . $ipp_list[$i] . $parm_sort . $parm_sortorder . "\">");
  91. echo ("-$ipp_list[$i]-");
  92. if ($ipp != $ipp_list[$i]) echo("</a>");
  93. echo ("&nbsp;&nbsp;&nbsp;");
  94. $j = $i + 1;
  95. if (($ipp > $ipp_list[$i]) && ($ipp < $ipp_list[$j])) echo ("-$ipp-&nbsp;&nbsp;&nbsp;");
  96. $i = $i + 1;
  97. }
  98. echo ("</td></tr>\n");
  99. echo("<tr><td>Sort By</td><td>");
  100. $s_list = array ("dateAdded", "title", "creator", "type", "date", "publisher", "publication", "journalAbbreviation", "language", "dateModified", "accessDate", "libraryCatalog", "callNumber", "rights", "addedBy", "numItems");
  101. $i = 0;
  102. while ($i <= 15) {
  103. if ($sort != $s_list[$i]) echo("<a href=\"?page=$page" . $parm_ipp . "&sort=" . $s_list[$i] . $parm_sortorder . "\">");
  104. echo ("-$s_list[$i]-");
  105. if ($sort != $s_list[$i]) echo("</a>");
  106. echo ("&nbsp;&nbsp;&nbsp;");
  107. $i = $i + 1;
  108. }
  109. echo ("</td></tr>\n");
  110. echo("<tr><td>Sort Order</td><td>");
  111. $so_list = array ("asc", "desc");
  112. $i = 0;
  113. while ($i <= 1) {
  114. if ($sortorder != $so_list[$i]) echo("<a href=\"?page=$page" . $parm_ipp . $parm_sort . "&sortorder=" . $so_list[$i] . "\">");
  115. echo ("-$so_list[$i]-");
  116. if ($sortorder != $so_list[$i]) echo("</a>");
  117. echo ("&nbsp;&nbsp;&nbsp;");
  118. $i = $i + 1;
  119. }
  120. echo ("</td></tr>\n</table>\n");
  121. ?>
  122. </body>
  123. </html>