finishLoanSession();
if ($flush == TRANS_FLUSH_ERROR) {
// write log
utility::writeLogs($dbs, 'member', $memberID, 'circulation', 'ERROR : '.$_SESSION['realname'].' FAILED finish circulation transaction with member ('.$memberID.')');
echo '';
} else {
// write log
utility::writeLogs($dbs, 'member', $memberID, 'circulation', $_SESSION['realname'].' finish circulation transaction with member ('.$memberID.')');
// send message
echo '';
}
exit();
}
// return and extend process
if (isset($_POST['process']) AND isset($_POST['loanID'])) {
$loanID = intval($_POST['loanID']);
// get loan data
$loan_q = $dbs->query('SELECT item_code FROM loan WHERE loan_id='.$loanID);
$loan_d = $loan_q->fetch_row();
// create circulation object
$circulation = new circulation($dbs, $_SESSION['memberID']);
$circulation->ignore_holidays_fine_calc = $sysconf['ignore_holidays_fine_calc'];
$circulation->holiday_dayname = $_SESSION['holiday_dayname'];
$circulation->holiday_date = $_SESSION['holiday_date'];
if ($_POST['process'] == 'return') {
$return_status = $circulation->returnItem($loanID);
// write log
utility::writeLogs($dbs, 'member', $_SESSION['memberID'], 'circulation', $_SESSION['realname'].' return item '.$loan_d[0].' for member ('.$_SESSION['memberID'].')');
echo '';
} else {
// set holiday settings
$circulation->holiday_dayname = $_SESSION['holiday_dayname'];
$circulation->holiday_date = $_SESSION['holiday_date'];
$extend_status = $circulation->extendItemLoan($loanID);
if ($extend_status === ITEM_RESERVED) {
echo '';
} else {
// write log
utility::writeLogs($dbs, 'member', $_SESSION['memberID'], 'circulation', $_SESSION['realname'].' extend loan for item '.$loan_d[0].' for member ('.$_SESSION['memberID'].')');
echo '';
}
}
exit();
}
// add temporary item to session
if (isset($_POST['tempLoanID'])) {
// create circulation object
$circulation = new circulation($dbs, $_SESSION['memberID']);
// set holiday settings
$circulation->holiday_dayname = $_SESSION['holiday_dayname'];
$circulation->holiday_date = $_SESSION['holiday_date'];
// add item to loan session
$add = $circulation->addLoanSession($_POST['tempLoanID']);
if ($add == LOAN_LIMIT_REACHED) {
echo '';
echo '
';
if ($sysconf['loan_limit_override']) {
// hidden form holding item code
echo '';
echo '';
} else {
echo '';
}
echo '';
echo '';
exit();
} else if ($add == ITEM_RESERVED) {
// hidden form holding item code
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
exit();
} else if ($add == ITEM_NOT_FOUND) {
echo '';
} else if ($add == ITEM_UNAVAILABLE) {
echo '';
} else if ($add == LOAN_NOT_PERMITTED) {
echo '';
} else if ($add == LOAN_NOT_PERMITTED_PENDING) {
echo '';
} else if ($add == ITEM_LOAN_FORBID) {
echo '';
} else {
utility::writeLogs($dbs, 'member', $_SESSION['memberID'], 'circulation', $_SESSION['realname'].' insert new loan ('.$_POST['tempLoanID'].') for member ('.$_SESSION['memberID'].')');
echo '';
}
exit();
}
// loan limit override
if (isset($_POST['overrideID']) AND !empty($_POST['overrideID'])) {
// define constant
define('IGNORE_LOAN_RULES', 1);
// create circulation object
$circulation = new circulation($dbs, $_SESSION['memberID']);
// set holiday settings
$circulation->holiday_dayname = $_SESSION['holiday_dayname'];
$circulation->holiday_date = $_SESSION['holiday_date'];
// add item to loan session
$add = $circulation->addLoanSession($_POST['overrideID']);
echo '';
exit();
}
// remove temporary item session
if (isset($_GET['removeID'])) {
// create circulation object
$circulation = new circulation($dbs, $_SESSION['memberID']);
// remove item from loan session
$circulation->removeLoanSession($_GET['removeID']);
echo '';
exit();
}
// quick return proccess
if (isset($_POST['quickReturnID']) AND $_POST['quickReturnID']) {
// get loan data
$loan_info_q = $dbs->query("SELECT l.*,m.member_id,m.member_name,b.title FROM loan AS l
LEFT JOIN item AS i ON i.item_code=l.item_code
LEFT JOIN biblio AS b ON i.biblio_id=b.biblio_id
LEFT JOIN member AS m ON l.member_id=m.member_id
WHERE l.item_code='".$dbs->escape_string($_POST['quickReturnID'])."' AND is_lent=1 AND is_return=0");
if ($loan_info_q->num_rows < 1) {
echo ''.__('This is item already returned or not exists in loan database').'
';
} else {
$return_date = date('Y-m-d');
// get data
$loan_d = $loan_info_q->fetch_assoc();
// create circulation object
$circulation = new circulation($dbs, $loan_d['member_id']);
/* modified by Indra Sutriadi */
$circulation->ignore_holidays_fine_calc = $sysconf['ignore_holidays_fine_calc'];
$circulation->holiday_dayname = $_SESSION['holiday_dayname'];
$circulation->holiday_date = $_SESSION['holiday_date'];
/* end of modification */
// check for overdue
$overdue = $circulation->countOverdueValue($loan_d['loan_id'], $return_date);
// check overdue
if ($overdue) {
$msg = str_replace('{overdueDays}', $overdue['days'],__('OVERDUED for {overdueDays} days(s) with fines value of')); //mfc
$loan_d['title'] .= ''.$msg.$overdue['value'].'
';
}
// return item
$return_status = $circulation->returnItem($loan_d['loan_id']);
if ($return_status === ITEM_RESERVED) {
// get reservation data
$reserve_q = $dbs->query('SELECT r.member_id, m.member_name
FROM reserve AS r
LEFT JOIN member AS m ON r.member_id=m.member_id
WHERE item_code=\''.$loan_d['item_code'].'\' ORDER BY reserve_date ASC LIMIT 1');
$reserve_d = $reserve_q->fetch_row();
$member = $reserve_d[1].' ('.$reserve_d[0].')';
$reserve_msg = str_replace(array('{itemCode}', '{member}'), array($loan_d['item_code'], $member), __('Item {itemCode} is being reserved by member {member}')); //mfc
$loan_d['title'] .= ''.$reserve_msg.'
';
}
// write log
utility::writeLogs($dbs, 'member', $loan_d['member_id'], 'circulation', $_SESSION['realname'].' return item ('.$_POST['quickReturnID'].') with title ('.$loan_d['title'].') with Quick Return method');
// show loan information
include SIMBIO.'simbio_GUI/table/simbio_table.inc.php';
// create table object
$table = new simbio_table();
$table->table_attr = 'class="border" style="width: 100%; margin-bottom: 5px;" cellpadding="5" cellspacing="0"';
// append data to table row
$table->appendTableRow(array('Item '.$_POST['quickReturnID'].__(' successfully returned on').' '.$return_date)); //mfc
$table->appendTableRow(array(__('Title'), $loan_d['title']));
$table->appendTableRow(array(__('Member Name'), $loan_d['member_name'], __('Member ID'), $loan_d['member_id']));
$table->appendTableRow(array(__('Loan Date'), $loan_d['loan_date'], __('Due Date'), $loan_d['due_date']));
// set the cell attributes
$table->setCellAttr(1, 0, 'class="dataListHeader" style="color: #fff; font-weight: bold;" colspan="4"');
$table->setCellAttr(2, 0, 'class="alterCell"');
$table->setCellAttr(2, 1, 'class="alterCell2" colspan="3"');
$table->setCellAttr(3, 0, 'class="alterCell" width="15%"');
$table->setCellAttr(3, 1, 'class="alterCell2" width="35%"');
$table->setCellAttr(3, 2, 'class="alterCell" width="15%"');
$table->setCellAttr(3, 3, 'class="alterCell2" width="35%"');
$table->setCellAttr(4, 0, 'class="alterCell" width="15%"');
$table->setCellAttr(4, 1, 'class="alterCell2" width="35%"');
$table->setCellAttr(4, 2, 'class="alterCell" width="15%"');
$table->setCellAttr(4, 3, 'class="alterCell2" width="35%"');
// print out the table
echo $table->printTable();
}
exit();
}
// add reservation
if (isset($_POST['reserveItemID'])) {
$item_id = trim($_POST['reserveItemID']);
if (!$item_id) {
echo '';
die();
}
// get reservation limit from member type
$reserve_limit_q = $dbs->query('SELECT reserve_limit FROM mst_member_type WHERE member_type_id='.(integer)$_SESSION['memberTypeID']);
$reserve_limit_d = $reserve_limit_q->fetch_row();
// get current reservation data for this member
$current_reserve_q = $dbs->query('SELECT COUNT(reserve_id) FROM reserve WHERE member_id=\''.trim($_SESSION['memberID']).'\'');
$current_reserve_d = $current_reserve_q->fetch_row();
if ($current_reserve_d[0] >= $reserve_limit_d[0]) {
echo '';
die();
}
// get biblio data for this item
$biblio_q = $dbs->query('SELECT i.biblio_id, ist.rules FROM biblio AS b
LEFT JOIN item AS i ON b.biblio_id=i.biblio_id
LEFT JOIN mst_item_status AS ist ON i.item_status_id=ist.item_status_id
WHERE i.item_code=\''.$dbs->escape_string($item_id).'\'');
$biblio_d = $biblio_q->fetch_row();
// check if this item is forbidden
if (!empty($biblio_d[1])) {
$arr_rules = @unserialize($biblio_d[1]);
if ($arr_rules) {
if (in_array(NO_LOAN_TRANSACTION, $arr_rules)) {
echo '';
die();
}
}
}
// get the availability status
$avail_q = $dbs->query('SELECT COUNT(l.loan_id) FROM loan AS l
WHERE l.item_code=\''.$item_id.'\' AND l.is_lent=1 AND l.is_return=0 AND l.member_id!=\''.$_SESSION['memberID'].'\'');
$avail_d = $avail_q->fetch_row();
if ($avail_d[0] > 0) {
// write log
utility::writeLogs($dbs, 'member', $_SESSION['memberID'], 'circulation', $_SESSION['realname'].' reserve item '.$item_id.' for member ('.$_SESSION['memberID'].')');
// add reservation to database
$reserve_date = date('Y-m-d H:i:s');
$dbs->query('INSERT INTO reserve(member_id, biblio_id, item_code, reserve_date) VALUES (\''.$_SESSION['memberID'].'\', \''.$biblio_d[0].'\', \''.$item_id.'\', \''.$reserve_date.'\')');
echo '';
} else {
echo '';
}
exit();
}
// remove reservation item
if (isset($_POST['reserveID']) AND !empty($_POST['reserveID'])) {
$reserveID = intval($_POST['reserveID']);
// get reserve data
$reserve_q = $dbs->query('SELECT item_code FROM reserve WHERE reserve_id='.$reserveID);
$reserve_d = $reserve_q->fetch_row();
// delete reservation record from database
$dbs->query('DELETE FROM reserve WHERE reserve_id='.$reserveID);
// write log
utility::writeLogs($dbs, 'member', $_SESSION['memberID'], 'circulation', $_SESSION['realname'].' remove reservation for item '.$reserve_d[0].' for member ('.$_SESSION['memberID'].')');
echo '';
exit();
}
// removing fines
if (isset($_POST['removeFines'])) {
foreach ($_POST['removeFines'] as $fines_id) {
$fines_id = intval($fines_id);
// change loan data
$dbs->query("DELETE FROM fines WHERE fines_id=$fines_id");
}
echo '';
exit();
}
// transaction is started
if (isset($_POST['memberID']) OR isset($_SESSION['memberID'])) {
// create member object
// if there is already member ID session
if (isset($_SESSION['memberID'])) {
$memberID = trim($_SESSION['memberID']);
} else {
// new transaction proccess
// clear previous sessions
$_SESSION['temp_loan'] = array();
$memberID = trim(preg_replace('@\s*(<.+)$@i', '', $_POST['memberID']));
// write log
utility::writeLogs($dbs, 'member', $memberID, 'circulation', $_SESSION['realname'].' start transaction with member ('.$memberID.')');
}
$member = new member($dbs, $memberID);
if (!$member->valid()) {
# echo 'Member ID '.$memberID.' not valid (unregistered in database)
';
echo ''.__('Member ID').' '.$memberID.' '.__(' not valid (unregistered in database)').'
'; //mfc
} else {
// get member information
$member_type_d = $member->getMemberTypeProp();
// member type ID
$_SESSION['memberTypeID'] = $member->member_type_id;
// save member ID to the sessions
$_SESSION['memberID'] = $member->member_id;
// create renewed/reborrow session array
$_SESSION['reborrowed'] = array();
// check membership expire
$_SESSION['is_expire'] = $member->isExpired();
// check if membership is blacklisted
$_SESSION['is_pending'] = $member->isPending();
// print record
$_SESSION['receipt_record'] = array();
// set HTML buttons disable flag
$disabled = '';
$add_style = '';
// check for expire date and pending state
if ($_SESSION['is_expire'] OR $_SESSION['is_pending']) {
$disabled = ' disabled ';
$add_style = ' disabled';
}
// show the member information
echo '';
echo '
'.__('Circulation').'
';
echo '';
echo ''."\n";
echo ''."\n";
echo '';
echo '
'."\n";
echo ''."\n";
echo ''.__('Member Name').' | '.$member->member_name.' | ';
echo ''.__('Member ID').' | '.$member->member_id.' | ';
// member photo
if ($member->member_image) {
if (file_exists(IMGBS.'persons/'.$member->member_image)) {
echo '';
echo '';
echo ' | ';
}
}
echo '
'."\n";
echo ''."\n";
echo ''.__('Member Email').' | '.$member->member_email.' | ';
echo ''.__('Member Type').' | '.$member->member_type_name.' | ';
echo '
'."\n";
echo ''."\n";
echo ''.__('Register Date').' | '.$member->register_date.' | ';
// give notification about expired membership and pending
$expire_msg = '';
if ($_SESSION['is_expire']) {
$expire_msg .= '('.__('Membership Already Expired').')';
}
echo ''.__('Expiry Date').' | '.$member->expire_date.' '.$expire_msg.' | ';
echo '
'."\n";
// member notes and pending information
if (!empty($member->member_notes) OR $_SESSION['is_pending']) {
echo ''."\n";
echo 'Notes | ';
if ($member->member_notes) {
echo ' '.$member->member_notes.' ';
}
if ($_SESSION['is_pending']) {
echo '('.__('Membership currently in pending state, loan transaction is locked.').') ';
}
echo ' | ';
echo '
'."\n";
}
echo '
'."\n";
// tab and iframe
echo '';
echo ''."\n";
}
exit();
}