PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/modules/reporting/customs/item_titles_list.php

https://gitlab.com/mucill/majalengka
PHP | 302 lines | 251 code | 17 blank | 34 comment | 28 complexity | e84d2806f69e696fefeabd90de2917b8 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * Copyright (C) 2007,2008 Arie Nugraha (dicarve@yahoo.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. /* Item List */
  22. // key to authenticate
  23. define('INDEX_AUTH', '1');
  24. // main system configuration
  25. require '../../../../sysconfig.inc.php';
  26. // IP based access limitation
  27. require LIB.'ip_based_access.inc.php';
  28. do_checkIP('smc');
  29. do_checkIP('smc-reporting');
  30. // start the session
  31. require SB.'admin/default/session.inc.php';
  32. require SB.'admin/default/session_check.inc.php';
  33. // privileges checking
  34. $can_read = utility::havePrivilege('reporting', 'r');
  35. $can_write = utility::havePrivilege('reporting', 'w');
  36. if (!$can_read) {
  37. die('<div class="errorBox">'.__('You don\'t have enough privileges to access this area!').'</div>');
  38. }
  39. require SIMBIO.'simbio_GUI/table/simbio_table.inc.php';
  40. require SIMBIO.'simbio_GUI/paging/simbio_paging.inc.php';
  41. require SIMBIO.'simbio_GUI/form_maker/simbio_form_element.inc.php';
  42. require SIMBIO.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
  43. require MDLBS.'reporting/report_dbgrid.inc.php';
  44. $page_title = 'Items/Copies Report';
  45. $reportView = false;
  46. $num_recs_show = 20;
  47. if (isset($_GET['reportView'])) {
  48. $reportView = true;
  49. }
  50. if (!$reportView) {
  51. ?>
  52. <!-- filter -->
  53. <fieldset>
  54. <div class="per_title">
  55. <h2><?php echo __('Items Title List'); ?></h2>
  56. </div>
  57. <div class="infoBox">
  58. <?php echo __('Report Filter'); ?>
  59. </div>
  60. <div class="sub_section">
  61. <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" target="reportView">
  62. <div id="filterForm">
  63. <div class="divRow">
  64. <div class="divRowLabel"><?php echo __('Title/ISBN'); ?></div>
  65. <div class="divRowContent">
  66. <?php echo simbio_form_element::textField('text', 'title', '', 'style="width: 50%"'); ?>
  67. </div>
  68. </div>
  69. <div class="divRow">
  70. <div class="divRowLabel"><?php echo __('Item Code'); ?></div>
  71. <div class="divRowContent">
  72. <?php echo simbio_form_element::textField('text', 'itemCode', '', 'style="width: 50%"'); ?>
  73. </div>
  74. </div>
  75. <div class="divRow">
  76. <div class="divRowLabel"><?php echo __('Classification'); ?></div>
  77. <div class="divRowContent">
  78. <?php echo simbio_form_element::textField('text', 'class', '', 'style="width: 50%"'); ?>
  79. </div>
  80. </div>
  81. <div class="divRow">
  82. <div class="divRowLabel"><?php echo __('GMD'); ?></div>
  83. <div class="divRowContent">
  84. <?php
  85. $gmd_q = $dbs->query('SELECT gmd_id, gmd_name FROM mst_gmd');
  86. $gmd_options[] = array('0', __('ALL'));
  87. while ($gmd_d = $gmd_q->fetch_row()) {
  88. $gmd_options[] = array($gmd_d[0], $gmd_d[1]);
  89. }
  90. echo simbio_form_element::selectList('gmd[]', $gmd_options, '','multiple="multiple" size="5"');
  91. ?> <?php echo __('Press Ctrl and click to select multiple entries'); ?>
  92. </div>
  93. </div>
  94. <div class="divRow">
  95. <div class="divRowLabel"><?php echo __('Collection Type'); ?></div>
  96. <div class="divRowContent">
  97. <?php
  98. $coll_type_q = $dbs->query('SELECT coll_type_id, coll_type_name FROM mst_coll_type');
  99. $coll_type_options = array();
  100. $coll_type_options[] = array('0', __('ALL'));
  101. while ($coll_type_d = $coll_type_q->fetch_row()) {
  102. $coll_type_options[] = array($coll_type_d[0], $coll_type_d[1]);
  103. }
  104. echo simbio_form_element::selectList('collType[]', $coll_type_options, '', 'multiple="multiple" size="5"');
  105. ?>
  106. </div>
  107. </div>
  108. <div class="divRow">
  109. <div class="divRowLabel"><?php echo __('Item Status'); ?></div>
  110. <div class="divRowContent">
  111. <?php
  112. $status_q = $dbs->query('SELECT item_status_id, item_status_name FROM mst_item_status');
  113. $status_options = array();
  114. $status_options[] = array('0', __('ALL'));
  115. while ($status_d = $status_q->fetch_row()) {
  116. $status_options[] = array($status_d[0], $status_d[1]);
  117. }
  118. echo simbio_form_element::selectList('status', $status_options);
  119. ?>
  120. </div>
  121. </div>
  122. <div class="divRow">
  123. <div class="divRowLabel"><?php echo __('Location'); ?></div>
  124. <div class="divRowContent">
  125. <?php
  126. $loc_q = $dbs->query('SELECT location_id, location_name FROM mst_location');
  127. $loc_options = array();
  128. $loc_options[] = array('0', __('ALL'));
  129. while ($loc_d = $loc_q->fetch_row()) {
  130. $loc_options[] = array($loc_d[0], $loc_d[1]);
  131. }
  132. echo simbio_form_element::selectList('location', $loc_options);
  133. ?>
  134. </div>
  135. </div>
  136. <div class="divRow">
  137. <div class="divRowLabel"><?php echo __('Publish year'); ?></div>
  138. <div class="divRowContent">
  139. <?php echo simbio_form_element::textField('text', 'publishYear', '', 'style="width: 50%"'); ?>
  140. </div>
  141. </div>
  142. <div class="divRow">
  143. <div class="divRowLabel"><?php echo __('Record each page'); ?></div>
  144. <div class="divRowContent"><input type="text" name="recsEachPage" size="3" maxlength="3" value="<?php echo $num_recs_show; ?>" /> <?php echo __('Set between 20 and 200'); ?></div>
  145. </div>
  146. </div>
  147. <div style="padding-top: 10px; clear: both;">
  148. <input type="button" name="moreFilter" value="<?php echo __('Show More Filter Options'); ?>" />
  149. <input type="submit" name="applyFilter" value="<?php echo __('Apply Filter'); ?>" />
  150. <input type="hidden" name="reportView" value="true" />
  151. </div>
  152. </form>
  153. </div>
  154. </fieldset>
  155. <!-- filter end -->
  156. <div class="dataListHeader" style="padding: 3px;"><span id="pagingBox"></span></div>
  157. <iframe name="reportView" id="reportView" src="<?php echo $_SERVER['PHP_SELF'].'?reportView=true'; ?>" frameborder="0" style="width: 100%; height: 500px;"></iframe>
  158. <?php
  159. } else {
  160. ob_start();
  161. // table spec
  162. $table_spec = 'item AS i
  163. LEFT JOIN biblio AS b ON i.biblio_id=b.biblio_id
  164. LEFT JOIN mst_coll_type AS ct ON i.coll_type_id=ct.coll_type_id';
  165. // create datagrid
  166. $reportgrid = new report_datagrid();
  167. $reportgrid->setSQLColumn('i.item_code AS \''.__('Item Code').'\'',
  168. 'b.title AS \''.__('Title').'\'',
  169. 'ct.coll_type_name AS \''.__('Collection Type').'\'',
  170. 'i.item_status_id AS \''.__('Item Status').'\'',
  171. 'b.call_number AS \''.__('Call Number').'\'', 'i.biblio_id');
  172. $reportgrid->setSQLorder('b.title ASC');
  173. // is there any search
  174. $criteria = 'b.biblio_id IS NOT NULL ';
  175. if (isset($_GET['title']) AND !empty($_GET['title'])) {
  176. $keyword = $dbs->escape_string(trim($_GET['title']));
  177. $words = explode(' ', $keyword);
  178. if (count($words) > 1) {
  179. $concat_sql = ' AND (';
  180. foreach ($words as $word) {
  181. $concat_sql .= " (b.title LIKE '%$word%' OR b.isbn_issn LIKE '%$word%') AND";
  182. }
  183. // remove the last AND
  184. $concat_sql = substr_replace($concat_sql, '', -3);
  185. $concat_sql .= ') ';
  186. $criteria .= $concat_sql;
  187. } else {
  188. $criteria .= ' AND (b.title LIKE \'%'.$keyword.'%\' OR b.isbn_issn LIKE \'%'.$keyword.'%\')';
  189. }
  190. }
  191. if (isset($_GET['itemCode']) AND !empty($_GET['itemCode'])) {
  192. $item_code = $dbs->escape_string(trim($_GET['itemCode']));
  193. $criteria .= ' AND i.item_code LIKE \'%'.$item_code.'%\'';
  194. }
  195. if (isset($_GET['collType'])) {
  196. $coll_type_IDs = '';
  197. foreach ($_GET['collType'] as $id) {
  198. $id = (integer)$id;
  199. if ($id) {
  200. $coll_type_IDs .= "$id,";
  201. }
  202. }
  203. $coll_type_IDs = substr_replace($coll_type_IDs, '', -1);
  204. if ($coll_type_IDs) {
  205. $criteria .= " AND i.coll_type_id IN($coll_type_IDs)";
  206. }
  207. }
  208. if (isset($_GET['gmd']) AND !empty($_GET['gmd'])) {
  209. $gmd_IDs = '';
  210. foreach ($_GET['gmd'] as $id) {
  211. $id = (integer)$id;
  212. if ($id) {
  213. $gmd_IDs .= "$id,";
  214. }
  215. }
  216. $gmd_IDs = substr_replace($gmd_IDs, '', -1);
  217. if ($gmd_IDs) {
  218. $criteria .= " AND b.gmd_id IN($gmd_IDs)";
  219. }
  220. }
  221. if (isset($_GET['status']) AND $_GET['status']!='0') {
  222. $status = $dbs->escape_string(trim($_GET['status']));
  223. $criteria .= ' AND i.item_status_id=\''.$status.'\'';
  224. }
  225. if (isset($_GET['class']) AND ($_GET['class'] != '')) {
  226. $class = $dbs->escape_string($_GET['class']);
  227. $criteria .= ' AND b.classification LIKE \''.$class.'%\'';
  228. }
  229. if (isset($_GET['location']) AND !empty($_GET['location'])) {
  230. $location = $dbs->escape_string(trim($_GET['location']));
  231. $criteria .= ' AND i.location_id=\''.$location.'\'';
  232. }
  233. if (isset($_GET['publishYear']) AND !empty($_GET['publishYear'])) {
  234. $publish_year = $dbs->escape_string(trim($_GET['publishYear']));
  235. $criteria .= ' AND b.publish_year LIKE \'%'.$publish_year.'%\'';
  236. }
  237. if (isset($_GET['recsEachPage'])) {
  238. $recsEachPage = (integer)$_GET['recsEachPage'];
  239. $num_recs_show = ($recsEachPage >= 20 && $recsEachPage <= 200)?$recsEachPage:$num_recs_show;
  240. }
  241. $reportgrid->setSQLCriteria($criteria);
  242. // callback function to show title and authors
  243. function showTitleAuthors($obj_db, $array_data)
  244. {
  245. if (!$array_data[5]) {
  246. return;
  247. }
  248. // author name query
  249. $_biblio_q = $obj_db->query('SELECT b.title, a.author_name FROM biblio AS b
  250. LEFT JOIN biblio_author AS ba ON b.biblio_id=ba.biblio_id
  251. LEFT JOIN mst_author AS a ON ba.author_id=a.author_id
  252. WHERE b.biblio_id='.$array_data[5]);
  253. $_authors = '';
  254. while ($_biblio_d = $_biblio_q->fetch_row()) {
  255. $_title = $_biblio_d[0];
  256. $_authors .= $_biblio_d[1].' - ';
  257. }
  258. $_authors = substr_replace($_authors, '', -3);
  259. $_output = $_title.'<br /><i>'.$_authors.'</i>'."\n";
  260. return $_output;
  261. }
  262. function showStatus($obj_db, $array_data)
  263. {
  264. $q = $obj_db->query('SELECT item_status_name FROM mst_item_status WHERE item_status_id=\''.$array_data[3].'\'');
  265. $d = $q->fetch_row();
  266. $s = $d[0];
  267. $output = $s;
  268. if (!$s) {
  269. $output = __('Available');
  270. }
  271. return $output;
  272. }
  273. // modify column value
  274. $reportgrid->modifyColumnContent(1, 'callback{showTitleAuthors}');
  275. $reportgrid->modifyColumnContent(3, 'callback{showStatus}');
  276. $reportgrid->invisible_fields = array(5);
  277. // put the result into variables
  278. echo $reportgrid->createDataGrid($dbs, $table_spec, $num_recs_show);
  279. echo '<script type="text/javascript">'."\n";
  280. echo 'parent.$(\'#pagingBox\').html(\''.str_replace(array("\n", "\r", "\t"), '', $reportgrid->paging_set).'\');'."\n";
  281. echo '</script>';
  282. $content = ob_get_clean();
  283. // include the page template
  284. require SB.'/admin/'.$sysconf['admin_template']['dir'].'/printed_page_tpl.php';
  285. }