PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/modules/circulation/loan_list.php

https://github.com/awriel/s3st15_matoa
PHP | 205 lines | 139 code | 16 blank | 50 comment | 23 complexity | 7b769835beebee4ea997b451677562bf MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (C) 2007,2008 Arie Nugraha (dicarve@yahoo.com)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. */
  20. /* loan list iframe content */
  21. // key to authenticate
  22. if (!defined('INDEX_AUTH')) {
  23. define('INDEX_AUTH', '1');
  24. }
  25. // main system configuration
  26. require '../../../sysconfig.inc.php';
  27. // IP based access limitation
  28. require LIB_DIR.'ip_based_access.inc.php';
  29. do_checkIP('smc');
  30. do_checkIP('smc-circulation');
  31. // start the session
  32. require SENAYAN_BASE_DIR.'admin/default/session.inc.php';
  33. require SENAYAN_BASE_DIR.'admin/default/session_check.inc.php';
  34. if (!isset($_SESSION['memberID'])) { die(); }
  35. require SIMBIO_BASE_DIR.'simbio_GUI/form_maker/simbio_form_table_AJAX.inc.php';
  36. require SIMBIO_BASE_DIR.'simbio_GUI/table/simbio_table.inc.php';
  37. require SIMBIO_BASE_DIR.'simbio_GUI/paging/simbio_paging.inc.php';
  38. require SIMBIO_BASE_DIR.'simbio_DB/simbio_dbop.inc.php';
  39. require SIMBIO_BASE_DIR.'simbio_UTILS/simbio_date.inc.php';
  40. require MODULES_BASE_DIR.'membership/member_base_lib.inc.php';
  41. require MODULES_BASE_DIR.'circulation/circulation_base_lib.inc.php';
  42. // page title
  43. $page_title = 'Member Loan List';
  44. // start the output buffering
  45. ob_start();
  46. ?>
  47. <!--loan specific javascript functions-->
  48. <script type="text/javascript">
  49. function confirmProcess(intLoanID, strItemCode, strProcess)
  50. {
  51. if (strProcess == 'return') {
  52. var confirmBox = confirm('<?php echo __('Are you sure you want to return the item'); ?> ' + strItemCode);
  53. } else {
  54. var confirmBox = confirm('<?php echo __('Are you sure to extend loan for'); ?> ' + strItemCode); //mfc
  55. }
  56. if (confirmBox) {
  57. // fill the hidden form value
  58. document.loanHiddenForm.process.value = strProcess;
  59. document.loanHiddenForm.loanID.value = intLoanID;
  60. // submit hidden form
  61. document.loanHiddenForm.submit();
  62. }
  63. }
  64. </script>
  65. <!--loan specific javascript functions end-->
  66. <?php
  67. // check if there is member ID
  68. if (isset($_SESSION['memberID'])) {
  69. $memberID = trim($_SESSION['memberID']);
  70. $circulation = new circulation($dbs, $memberID);
  71. $loan_list_query = $dbs->query(sprintf("SELECT L.loan_id, b.title, c.coll_type_name,
  72. i.item_code, L.loan_date, L.due_date, L.return_date, L.renewed
  73. FROM loan AS L
  74. LEFT JOIN item AS i ON L.item_code=i.item_code
  75. LEFT JOIN mst_coll_type AS ct ON i.coll_type_id=ct.coll_type_id
  76. LEFT JOIN member AS m ON L.member_id=m.member_id
  77. LEFT JOIN biblio AS b ON i.biblio_id=b.biblio_id
  78. LEFT JOIN mst_coll_type AS c ON i.coll_type_id=c.coll_type_id
  79. WHERE L.is_lent=1 AND L.is_return=0 AND L.member_id='%s'", $memberID));
  80. // create table object
  81. $loan_list = new simbio_table();
  82. $loan_list->table_attr = 'align="center" width="100%" cellpadding="3" cellspacing="0"';
  83. $loan_list->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  84. $loan_list->highlight_row = true;
  85. // table header
  86. $headers = array(__('Return'), __('Extend'), __('Item Code'), __('Title'), __('Col. Type'), __('Loan Date'), __('Due Date'));
  87. $loan_list->setHeader($headers);
  88. // row number init
  89. $row = 1;
  90. $is_overdue = false;
  91. while ($loan_list_data = $loan_list_query->fetch_assoc()) {
  92. // alternate the row color
  93. $row_class = ($row%2 == 0)?'alterCell':'alterCell2';
  94. // return link
  95. $return_link = '<a href="#" onclick="confirmProcess('.$loan_list_data['loan_id'].', \''.$loan_list_data['item_code'].'\', \'return\')" title="'.__('Return this item').'" class="returnLink">&nbsp;</a>';
  96. // extend link
  97. // check if membership already expired
  98. if ($_SESSION['is_expire']) {
  99. $extend_link = '<span class="noExtendLink" title="'.__('No Extend').'">&nbsp;</span>';
  100. } else {
  101. // check if this loan just already renewed
  102. if ($loan_list_data['return_date'] == date('Y-m-d')) {
  103. $extend_link = '<span class="noExtendLink" title="'.__('No Extend').'">&nbsp;</span>';
  104. } else if (in_array($loan_list_data['loan_id'], $_SESSION['reborrowed'])) {
  105. $extend_link = '<span class="noExtendLink" title="'.__('No Extend').'">&nbsp;</span>';
  106. } else {
  107. $extend_link = '<a href="#" onclick="confirmProcess('.$loan_list_data['loan_id'].', \''.$loan_list_data['item_code'].'\', \'extend\')" title="'.__('Extend loan for this item').'" class="extendLink">&nbsp;</a>';
  108. }
  109. }
  110. // renewed flag
  111. if ($loan_list_data['renewed'] > 0) {
  112. $loan_list_data['title'] = $loan_list_data['title'].' - <strong style="color: blue;">'.__('Extended').'</strong>';
  113. }
  114. // check for overdue
  115. $curr_date = date('Y-m-d');
  116. $overdue = $circulation->countOverdueValue($loan_list_data['loan_id'], $curr_date);
  117. if ($overdue) {
  118. $is_overdue = true;
  119. $loan_list_data['title'] .= '<div style="color: red; font-weight: bold;">'.__('OVERDUED for').' '.$overdue['days'].' '.__('days(s) with fines value').' '.$overdue['value'].'</div>'; //mfc
  120. }
  121. // row colums array
  122. $fields = array(
  123. $return_link,
  124. $extend_link,
  125. $loan_list_data['item_code'],
  126. $loan_list_data['title'],
  127. $loan_list_data['coll_type_name'],
  128. $loan_list_data['loan_date'],
  129. $loan_list_data['due_date']
  130. );
  131. // append data to table row
  132. $loan_list->appendTableRow($fields);
  133. // set the HTML attributes
  134. $loan_list->setCellAttr($row, null, "valign='top' class='$row_class'");
  135. $loan_list->setCellAttr($row, 0, "valign='top' align='center' class='$row_class' style='width: 5%;'");
  136. $loan_list->setCellAttr($row, 1, "valign='top' align='center' class='$row_class' style='width: 5%;'");
  137. $loan_list->setCellAttr($row, 2, "valign='top' class='$row_class' style='width: 10%;'");
  138. $loan_list->setCellAttr($row, 3, "valign='top' class='$row_class' style='width: 50%;'");
  139. $loan_list->setCellAttr($row, 4, "valign='top' class='$row_class' style='width: 15%;'");
  140. $row++;
  141. }
  142. // show reservation alert if any
  143. if (isset($_GET['reserveAlert']) AND !empty($_GET['reserveAlert'])) {
  144. $reservedItem = $dbs->escape_string(trim($_GET['reserveAlert']));
  145. // get reservation data
  146. $reserve_q = $dbs->query(sprintf('SELECT r.member_id, m.member_name
  147. FROM reserve AS r
  148. LEFT JOIN member AS m ON r.member_id=m.member_id
  149. WHERE item_code=\'%s\' ORDER BY reserve_date ASC LIMIT 1', $reservedItem));
  150. $reserve_d = $reserve_q->fetch_row();
  151. $member = $reserve_d[1].' ('.$reserve_d[0].')';
  152. $reserve_msg = str_replace(array('{itemCode}', '{member}'), array('<b>'.$reservedItem.'</b>', '<b>'.$member.'</b>'), __('Item {itemCode} is being reserved by member {member}'));
  153. echo '<div class="infoBox">'.$reserve_msg.'</div>';
  154. }
  155. // create e-mail lin if there is overdue
  156. if ($is_overdue) {
  157. echo '<div style="padding: 5px; background: #ccc;"><div id="emailStatus"></div><a class="sendEmail usingAJAX" href="'.MODULES_WEB_ROOT_DIR.'membership/overdue_mail.php'.'" postdata="memberID='.$memberID.'" loadcontainer="emailStatus">'.__('Send overdues notice e-mail').'</a></div>'."\n";
  158. }
  159. echo $loan_list->printTable();
  160. // hidden form for return and extend process
  161. echo '<form name="loanHiddenForm" method="post" action="circulation_action.php"><input type="hidden" name="process" value="return" /><input type="hidden" name="loanID" value="" /></form>';
  162. ?>
  163. <script type="text/javascript">
  164. // registering event for send email button
  165. $(document).ready(function() {
  166. $('a.usingAJAX').click(function(evt) {
  167. evt.preventDefault();
  168. var anchor = $(this);
  169. // get anchor href
  170. var url = anchor.attr('href');
  171. var postData = anchor.attr('postdata');
  172. var loadContainer = anchor.attr('loadcontainer');
  173. if (loadContainer) { container = jQuery('#'+loadContainer); }
  174. // set ajax
  175. if (postData) {
  176. container.simbioAJAX(url, {method: 'post', addData: postData});
  177. } else {
  178. container.simbioAJAX(url, {addData: {ajaxload: 1}});
  179. }
  180. });
  181. });
  182. </script>
  183. <?php
  184. }
  185. // get the buffered content
  186. $content = ob_get_clean();
  187. // include the page template
  188. require SENAYAN_BASE_DIR.'/admin/'.$sysconf['admin_template']['dir'].'/notemplate_page_tpl.php';
  189. ?>