<?php
/*
VERSION : 3.0
CODENAME : SENAYAN
AUTHOR :
Code and Programming : ARIE NUGRAHA (hide@address.com)
Database Design : HENDRO WICAKSONO (hide@address.com) & WARDIYONO (hide@address.com)
SENAYAN Library Automation System
Copyright (C) 2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (GPL License.txt); if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Bibliography Management section */
// start the session
session_start();
require '../../../sysconfig.inc.php';
require SENAYAN_BASE_DIR.'admin/default/session_check.inc.php';
require SIMBIO_BASE_DIR.'simbio_GUI/table/simbio_table.inc.php';
require SIMBIO_BASE_DIR.'simbio_GUI/form_maker/simbio_form_table_AJAX.inc.php';
require SIMBIO_BASE_DIR.'simbio_GUI/paging/simbio_paging_ajax.inc.php';
require SIMBIO_BASE_DIR.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
require SIMBIO_BASE_DIR.'simbio_DB/simbio_dbop.inc.php';
require SIMBIO_BASE_DIR.'simbio_FILE/simbio_file_upload.inc.php';
// privileges checking
$can_read = utility::havePrivilege('bibliography', 'r');
$can_write = utility::havePrivilege('bibliography', 'w');
if (!$can_read) {
die('<div class="errorBox">'.lang_sys_common_unauthorized.'</div>');
}
$in_pop_up = false;
// check if we are inside pop-up window
if (isset($_GET['inPopUp'])) {
$in_pop_up = true;
}
/* RECORD OPERATION */
if (isset($_POST['saveData']) AND $can_read AND $can_write) {
$title = trim(strip_tags($_POST['title']));
// check form validity
if (empty($title)) {
utility::jsAlert(lang_mod_biblio_alert_title_empty);
exit();
} else {
$data['title'] = $dbs->escape_string($title);
$data['edition'] = trim($dbs->escape_string(strip_tags($_POST['edition'])));
$data['gmd_id'] = $_POST['gmdID'];
$data['isbn_issn'] = trim($dbs->escape_string(strip_tags($_POST['isbn_issn'])));
$data['classification'] = trim($dbs->escape_string(strip_tags($_POST['class'])));
// check publisher
if ($_POST['publisherID'] != '0') {
$data['publisher_id'] = intval($_POST['publisherID']);
} else {
if (!empty($_POST['publ_search_str'])) {
$new_publisher = trim(strip_tags($_POST['publ_search_str']));
$new_id = utility::getID($dbs, 'mst_publisher', 'publisher_id', 'publisher_name', $new_publisher);
if ($new_id) {
$data['publisher_id'] = $new_id;
} else {
$data['publisher_id'] = 'literal{NULL}';
}
} else {
$data['publisher_id'] = 'literal{NULL}';
}
}
$data['publish_year'] = trim($dbs->escape_string(strip_tags($_POST['year'])));
$data['collation'] = trim($dbs->escape_string(strip_tags($_POST['collation'])));
$data['series_title'] = trim($dbs->escape_string(strip_tags($_POST['seriesTitle'])));
$data['call_number'] = trim($dbs->escape_string(strip_tags($_POST['callNumber'])));
$data['language_id'] = trim($dbs->escape_string(strip_tags($_POST['languageID'])));
// check place
if ($_POST['placeID'] != '0') {
$data['publish_place_id'] = intval($_POST['placeID']);
} else {
if (!empty($_POST['plc_search_str'])) {
$new_place = trim(strip_tags($_POST['plc_search_str']));
$new_id = utility::getID($dbs, 'mst_place', 'place_id', 'place_name', $new_place);
if ($new_id) {
$data['publish_place_id'] = $new_id;
} else {
$data['publish_place_id'] = 'literal{NULL}';
}
} else {
$data['publish_place_id'] = 'literal{NULL}';
}
}
$data['notes'] = trim($dbs->escape_string(strip_tags($_POST['notes'])));
$data['input_date'] = date('Y-m-d H:i:s');
$data['last_update'] = date('Y-m-d H:i:s');
// image uploading
if (!empty($_FILES['image']) AND $_FILES['image']['size']) {
// create upload object
$image_upload = new simbio_file_upload();
$image_upload->setAllowableFormat($sysconf['allowed_images']);
$image_upload->setMaxSize($sysconf['max_image_upload']*1024);
$image_upload->setUploadDir(IMAGES_BASE_DIR.'docs');
$img_upload_status = $image_upload->doUpload('image');
if ($img_upload_status == UPLOAD_SUCCESS) {
$data['image'] = $dbs->escape_string($_FILES['image']['name']);
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', $_SESSION['realname'].' upload image file '.$image_upload->new_filename);
utility::jsAlert(lang_mod_biblio_alert_image_uploaded);
} else {
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', 'ERROR : '.$_SESSION['realname'].' FAILED TO upload image file '.$image_upload->new_filename.', with error ('.$image_upload->error.')');
utility::jsAlert(lang_mod_biblio_alert_image_uploaded);
}
}
// file uploading
if (!empty($_FILES['attachment']) AND $_FILES['attachment']['size']) {
// create upload object
$file_upload = new simbio_file_upload();
$file_upload->setAllowableFormat($sysconf['allowed_file_att']);
$file_upload->setMaxSize($sysconf['max_upload']*1024);
$file_upload->setUploadDir(FILE_ATT_DIR);
$file_upload_status = $file_upload->doUpload('attachment');
if ($file_upload_status == UPLOAD_SUCCESS) {
$data['file_att'] = $dbs->escape_string($_FILES['attachment']['name']);
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', $_SESSION['realname'].' upload file '.$file_upload->new_filename);
utility::jsAlert(lang_mod_biblio_alert_attach_uploaded);
} else {
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', 'ERROR : '.$_SESSION['realname'].' FAILED TO upload file '.$file_upload->new_filename.', with error ('.$file_upload->error.')');
utility::jsAlert(lang_mod_biblio_alert_attach_not_uploaded);
}
}
// create sql op object
$sql_op = new simbio_dbop($dbs);
if (isset($_POST['updateRecordID'])) {
/* UPDATE RECORD MODE */
// remove input date
unset($data['input_date']);
// filter update record ID
$updateRecordID = (integer)$_POST['updateRecordID'];
// update the data
$update = $sql_op->update('biblio', $data, 'biblio_id='.$updateRecordID);
// send an alert
if ($update) {
utility::jsAlert(lang_mod_biblio_alert_updated_ok);
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', $_SESSION['realname'].' update bibliographic data ('.$data['title'].') with biblio_id ('.$_POST['itemID'].')');
// close window OR redirect main page
if ($in_pop_up) {
echo '<script type="text/javascript">parent.opener.setContent(\'mainContent\', parent.opener.getLatestAJAXurl(), \'post\', \'itemID='.$_POST['itemCollID'].'&detail=true\');</script>';
echo '<script type="text/javascript">parent.window.close();</script>';
} else {
echo '<script type="text/javascript">parent.setContent(\'mainContent\', parent.getPreviousAJAXurl(), \'get\');</script>';
}
} else { utility::jsAlert(lang_mod_biblio_alert_failed_to_update."\n".$sql_op->error); }
exit();
} else {
/* INSERT RECORD MODE */
// insert the data
$insert = $sql_op->insert('biblio', $data);
if ($insert) {
// get auto id of this record
$last_biblio_id = $sql_op->insert_id;
// add authors
if ($_SESSION['biblioAuthor']) {
foreach ($_SESSION['biblioAuthor'] as $author) {
$sql_op->insert('biblio_author', array('biblio_id' => $last_biblio_id, 'author_id' => $author[0], 'level' => $author[1]));
}
}
// add topics
if ($_SESSION['biblioTopic']) {
foreach ($_SESSION['biblioTopic'] as $topic) {
$sql_op->insert('biblio_topic', array('biblio_id' => $last_biblio_id, 'topic_id' => $topic[0], 'level' => $topic[1]));
}
}
utility::jsAlert(lang_mod_biblio_alert_new_added);
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', $_SESSION['realname'].' insert bibliographic data ('.$data['title'].') with biblio_id ('.$last_biblio_id.')');
// clear related sessions
$_SESSION['biblioAuthor'] = array();
$_SESSION['biblioTopic'] = array();
echo '<script type="text/javascript">parent.setContent(\'mainContent\', \''.MODULES_WEB_ROOT_DIR.'bibliography/index.php\', \'post\', \'itemID='.$last_biblio_id.'&detail=true\');</script>';
} else { utility::jsAlert(lang_mod_biblio_alert_failed_to_save."\n".$sql_op->error); }
exit();
}
}
exit();
} else if (isset($_POST['itemID']) AND !empty($_POST['itemID']) AND isset($_POST['itemAction'])) {
if (!($can_read AND $can_write)) {
die();
}
/* DATA DELETION PROCESS */
// create sql op object
$sql_op = new simbio_dbop($dbs);
$failed_array = array();
$error_num = 0;
$still_have_item = array();
if (!is_array($_POST['itemID'])) {
// make an array
$_POST['itemID'] = array((integer)$_POST['itemID']);
}
// loop array
foreach ($_POST['itemID'] as $itemID) {
$itemID = (integer)$itemID;
// check if this biblio data still have an item
$biblio_item_q = $dbs->query('SELECT b.title, COUNT(item_id) FROM biblio AS b
LEFT JOIN item AS i ON b.biblio_id=i.biblio_id
WHERE b.biblio_id='.$itemID.' GROUP BY title');
$biblio_item_d = $biblio_item_q->fetch_row();
if ($biblio_item_d[1] < 1) {
if (!$sql_op->delete('biblio', "biblio_id=$itemID")) {
$error_num++;
} else {
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'bibliography', $_SESSION['realname'].' DELETE bibliographic data ('.$biblio_item_d[0].') with biblio_id ('.$itemID.')');
// delete related data
$sql_op->delete('biblio_topic', "biblio_id=$itemID");
$sql_op->delete('biblio_author', "biblio_id=$itemID");
}
} else {
$still_have_item[] = substr($biblio_item_d[0], 0, 45).'... still have '.$biblio_item_d[1].' copies';
$error_num++;
}
}
if ($still_have_item) {
$titles = '';
foreach ($still_have_item as $title) {
$titles .= $title."\n";
}
utility::jsAlert(lang_mod_biblio_alert_list_not_deleted."\n".$titles);
exit();
}
// error alerting
if ($error_num == 0) {
utility::jsAlert(lang_mod_biblio_alert_data_selected_deleted);
echo '<script type="text/javascript">parent.setContent(\'mainContent\', \''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\', \'post\');</script>';
} else {
utility::jsAlert(lang_mod_biblio_alert_data_selected_not_deleted);
echo '<script type="text/javascript">parent.setContent(\'mainContent\', \''.$_SERVER['PHP_SELF'].'?'.$_POST['lastQueryStr'].'\', \'post\');</script>';
}
exit();
}
/* RECORD OPERATION END */
if (!$in_pop_up) {
/* search form */
?>
<table id="searchForm" cellpadding="5" cellspacing="0">
<tr>
<td class="imageLeft" valign="top">
<?php echo strtoupper(lang_mod_biblio); ?> - <a href="#" onclick="setContent('mainContent', '<?php echo MODULES_WEB_ROOT_DIR; ?>bibliography/index.php?action=detail', 'get');" class="headerText2"><?php echo lang_mod_biblio_add; ?></a>
<a href="#" onclick="setContent('mainContent', '<?php echo MODULES_WEB_ROOT_DIR; ?>bibliography/index.php', 'post');" class="headerText2"><?php echo lang_mod_biblio_list; ?></a>
<hr />
<form name="search" action="blank.html" target="blindSubmit" onsubmit="$('doSearch').click();" id="search" method="get" style="display: inline;"><?php echo lang_sys_common_form_search; ?> :
<input type="text" name="keywords" id="keywords" size="30" />
<select name="field"><option value="0">All Field</option><option value="title">Title</option><option value="series_title">Series Title</option><option value="topic">Topics</option><option value="author_name">Authors</option><option value="isbn_issn">ISBN</option></select>
<input type="button" id="doSearch" onclick="setContent('mainContent', '<?php echo MODULES_WEB_ROOT_DIR; ?>bibliography/index.php?' + $('search').serialize(), 'post')" value="<?php echo lang_sys_common_form_search; ?>" class="button" />
</form>
</td>
</tr>
</table>
<script type="text/javascript">
// focus member ID text field
$('keywords').focus();
</script>
<?php
/* search form end */
}
/* main content */
if (isset($_POST['detail']) OR (isset($_GET['action']) AND $_GET['action'] == 'detail')) {
if (!($can_read AND $can_write)) {
die('<div class="errorBox">'.lang_sys_common_unauthorized.'</div>');
}
/* RECORD FORM */
// try query
$itemID = (integer)isset($_POST['itemID'])?$_POST['itemID']:0;
$rec_q = $dbs->query('SELECT b.*, p.publisher_name, pl.place_name FROM biblio AS b
LEFT JOIN mst_publisher AS p ON b.publisher_id=p.publisher_id
LEFT JOIN mst_place AS pl ON b.publish_place_id=pl.place_id
WHERE biblio_id='.$itemID);
$rec_d = $rec_q->fetch_assoc();
// create new instance
$form = new simbio_form_table_AJAX('mainForm', $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], 'post');
$form->submit_button_attr = 'name="saveData" value="'.lang_sys_common_form_save.'" class="button"';
// form table attributes
$form->table_attr = 'align="center" id="dataList" style="width: 100%;" cellpadding="5" cellspacing="0"';
$form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
$form->table_content_attr = 'class="alterCell2"';
$visibility = 'makeVisible';
// edit mode flag set
if ($rec_q->num_rows > 0) {
$form->edit_mode = true;
// record ID for delete process
if (!$in_pop_up) {
// form record id
$form->record_id = $itemID;
} else {
$form->addHidden('updateRecordID', $itemID);
$form->addHidden('itemCollID', $_POST['itemCollID']);
$form->back_button = false;
}
// form record title
$form->record_title = $rec_d['title'];
// detail icon
$form->record_detail_icon = SENAYAN_WEB_ROOT_DIR.'admin/'.$sysconf['admin_template']['dir'].'/'.$sysconf['admin_template']['theme'].'/edit_record.png';
// submit button attribute
$form->submit_button_attr = 'name="saveData" value="'.lang_sys_common_form_update.'" class="button"';
// element visibility class toogle
$visibility = 'makeHidden';
}
/* Form Element(s) */
// biblio title
$form->addTextField('textarea', 'title', lang_mod_biblio_field_title, $rec_d['title'], 'rows="1" style="width: 100%; overflow: auto;"');
// biblio edition
$form->addTextField('text', 'edition', lang_mod_biblio_field_edition, $rec_d['edition'], 'style="width: 40%;"');
// biblio item add
if (!$in_pop_up AND $form->edit_mode) {
$str_input = '<div class="makeHidden"><a href="javascript: openWin(\''.MODULES_WEB_ROOT_DIR.'bibliography/pop_item.php?inPopUp=true&action=detail&biblioID='.$rec_d['biblio_id'].'\', \'popItem\', 600, 400, true)">'.lang_mod_biblio_link_item_add.'</a></div>';
$str_input .= '<iframe name="itemIframe" id="itemIframe" class="borderAll" style="width: 100%; height: 70px;" src="'.MODULES_WEB_ROOT_DIR.'bibliography/iframe_item_list.php?biblioID='.$rec_d['biblio_id'].'"></iframe>'."\n";
$form->addAnything('Item(s) Data', $str_input);
}
// biblio authors
$str_input = '<div class="'.$visibility.'"><a href="javascript: openWin(\''.MODULES_WEB_ROOT_DIR.'bibliography/pop_author.php?biblioID='.$rec_d['biblio_id'].'\', \'popAuthor\', 500, 200, true)">'.lang_mod_biblio_link_author_add.'</a></div>';
$str_input .= '<iframe name="authorIframe" id="authorIframe" class="borderAll" style="width: 100%; height: 70px;" src="'.MODULES_WEB_ROOT_DIR.'bibliography/iframe_author.php?biblioID='.$rec_d['biblio_id'].'"></iframe>';
$form->addAnything(lang_mod_biblio_field_authors, $str_input);
// biblio gmd
// get gmd data related to this record from database
$gmd_q = $dbs->query('SELECT gmd_id, gmd_name FROM mst_gmd');
$gmd_options = array();
while ($gmd_d = $gmd_q->fetch_row()) {
$gmd_options[] = array($gmd_d[0], $gmd_d[1]);
}
$form->addSelectList('gmdID', lang_mod_biblio_field_gmd, $gmd_options, $rec_d['gmd_id']);
// biblio ISBN/ISSN
$form->addTextField('text', 'isbn_issn', lang_mod_biblio_field_isbn, $rec_d['isbn_issn'], 'style="width: 40%;"');
// biblio classification
$form->addTextField('text', 'class', lang_mod_biblio_field_class, $rec_d['classification'], 'style="width: 40%;"');
// biblio publisher
// AJAX expression
$ajax_exp = "ajaxFillSelect('AJAX_lookup_handler.php', 'mst_publisher', 'publisher_id:publisher_name', 'publisherID', $('publ_search_str').getValue())";
if ($rec_d['publisher_name']) {
$publ_options[] = array($rec_d['publisher_id'], $rec_d['publisher_name']);
}
$publ_options[] = array('0', lang_mod_biblio_field_publisher);
// string element
$str_input = simbio_form_element::selectList('publisherID', $publ_options, '', 'id="publisherID" style="width: 50%;"');
$str_input .= ' ';
$str_input .= simbio_form_element::textField('text', 'publ_search_str', '', 'id="publ_search_str" style="width: 45%;" onkeyup="'.$ajax_exp.'"');
$form->addAnything(lang_mod_biblio_field_publisher, $str_input);
// biblio publish year
$form->addTextField('text', 'year', lang_mod_biblio_field_publish_year, $rec_d['publish_year'], 'style="width: 40%;"');
// biblio publish place
// AJAX expression
$ajax_exp = "ajaxFillSelect('AJAX_lookup_handler.php', 'mst_place', 'place_id:place_name', 'placeID', $('plc_search_str').getValue())";
// string element
if ($rec_d['place_name']) {
$plc_options[] = array($rec_d['publish_place_id'], $rec_d['place_name']);
}
$plc_options[] = array('0', lang_mod_biblio_field_publish_place);
$str_input = simbio_form_element::selectList('placeID', $plc_options, '', 'id="placeID" style="width: 50%;"');
$str_input .= ' ';
$str_input .= simbio_form_element::textField('text', 'plc_search_str', '', 'id="plc_search_str" style="width: 45%;" onkeyup="'.$ajax_exp.'"');
$form->addAnything(lang_mod_biblio_field_publish_place, $str_input);
// biblio collation
$form->addTextField('text', 'collation', lang_mod_biblio_field_collation, $rec_d['collation'], 'style="width: 40%;"');
// biblio series title
$form->addTextField('textarea', 'seriesTitle', lang_mod_biblio_field_series, $rec_d['series_title'], 'rows="1" style="width: 100%;"');
// biblio call_number
$form->addTextField('text', 'callNumber', lang_mod_biblio_field_call_number, $rec_d['call_number'], 'style="width: 40%;"');
// biblio topics
$str_input = '<div class="'.$visibility.'"><a href="javascript: openWin(\''.MODULES_WEB_ROOT_DIR.'bibliography/pop_topic.php?biblioID='.$rec_d['biblio_id'].'\', \'popTopic\', 500, 200, true)">'.lang_mod_biblio_link_topic_add.'</a></div>';
$str_input .= '<iframe name="topicIframe" id="topicIframe" class="borderAll" style="width: 100%; height: 70px;" src="'.MODULES_WEB_ROOT_DIR.'bibliography/iframe_topic.php?biblioID='.$rec_d['biblio_id'].'"></iframe>';
$form->addAnything(lang_mod_biblio_field_topic, $str_input);
// biblio language
// get language data related to this record from database
$lang_q = $dbs->query("SELECT language_id, language_name FROM mst_language");
$lang_options = array();
while ($lang_d = $lang_q->fetch_row()) {
$lang_options[] = array($lang_d[0], $lang_d[1]);
}
$form->addSelectList('languageID', lang_mod_biblio_field_lang, $lang_options, $rec_d['language_id']);
// biblio note
$form->addTextField('textarea', 'notes', lang_mod_biblio_field_notes, $rec_d['notes'], 'style="width: 100%;" rows="2"');
// biblio cover image
if (!trim($rec_d['image'])) {
$str_input = simbio_form_element::textField('file', 'image');
$str_input .= ' Maximum '.$sysconf['max_image_upload'].' KB';
$form->addAnything(lang_mod_biblio_field_image, $str_input);
} else {
$str_input = '<a href="'.SENAYAN_WEB_ROOT_DIR.'images/docs/'.$rec_d['image'].'" target="_blank"><strong>'.$rec_d['image'].'</strong></a><br />';
$str_input .= simbio_form_element::textField('file', 'image');
$str_input .= ' Maximum '.$sysconf['max_image_upload'].' KB';
$form->addAnything(lang_mod_biblio_field_image, $str_input);
}
// biblio file attachment
if (!trim($rec_d['file_att'])) {
$str_input = simbio_form_element::textField('file', 'attachment');
$str_input .= ' Maximum '.$sysconf['max_upload'].' KB';
$form->addAnything(lang_mod_biblio_field_attachment, $str_input);
} else {
$str_input = '<div id="fileAtt"><a href="view.php?f='.urlencode($rec_d['file_att']).'" target="_blank"><strong>'.$rec_d['file_att'].'</strong></a> <a title="Delete file '.$rec_d['file_att'].'" href="javascript: setContent(\'fileAtt\', \''.MODULES_WEB_ROOT_DIR.'bibliography/delete_file.php?itemID='.$rec_d['biblio_id'].'\', \'post\');" style="font-weight: bold; color: #FF0000;">Delete File</a></div>';
$str_input .= simbio_form_element::textField('file', 'attachment');
$str_input .= ' Maximum '.$sysconf['max_upload'].' KB';
$form->addAnything(lang_mod_biblio_field_attachment, $str_input);
}
// edit mode messagge
if ($form->edit_mode) {
echo '<div class="infoBox" style="overflow: auto;">'
.'<div style="float: left; width: 80%;">'.lang_mod_biblio_common_edit_message.' : <b>'.$rec_d['title'].'</b> <br />'.lang_mod_biblio_common_last_update.$rec_d['last_update'].'</div>';
if ($rec_d['image']) {
if (file_exists(IMAGES_BASE_DIR.'docs/'.$rec_d['image'])) {
$upper_dir = '';
if ($in_pop_up) {
$upper_dir = '../../';
}
echo '<div style="float: right;"><img src="'.$upper_dir.'../lib/phpthumb/phpThumb.php?src=../../images/docs/'.urlencode($rec_d['image']).'&w=53" style="border: 1px solid #999999" /></div>';
}
}
echo '</div>'."\n";
}
// print out the form object
echo $form->printOut();
// block iframes on edit mode
if ($form->edit_mode) {
echo '<script type="text/javascript">registerBlockedIframes([\'itemIframe\', \'authorIframe\', \'topicIframe\']);</script>';
}
} else {
/* BIBLIOGRAPHY LIST */
// create datagrid
$datagrid = new simbio_datagrid();
if ($can_read AND $can_write) {
$datagrid->setSQLColumn('b.biblio_id',
'b.title AS \''.lang_mod_biblio_field_title.'\'',
'b.isbn_issn AS \''.lang_mod_biblio_field_isbn.'\'',
'IF(COUNT(i.item_id)>0, COUNT(i.item_id), \'<strong style="color: #FF0000;">None</strong>\') AS \'Copies\'',
'b.last_update AS \'Last Update\'');
} else {
$datagrid->setSQLColumn('b.title AS \''.lang_mod_biblio_field_title.'\'',
'b.isbn_issn AS \''.lang_mod_biblio_field_isbn.'\'',
'IF(COUNT(i.item_id)>0, COUNT(i.item_id), \'<strong style="color: #FF0000;">None</strong>\') AS \'Copies\'',
'b.last_update AS \'Last Update\'');
}
$datagrid->setSQLorder("b.last_update DESC");
// table alias and field relation
$tables['bsub'] = array('title', 'isbn_issn', 'series_title');
$tables['ma'] = array('author_name');
$tables['mt'] = array('topic');
if (isset($_GET['field']) AND !empty($_GET['field'])) {
foreach ($tables as $table_alias=>$fields) {
if (!in_array($_GET['field'], $fields)) {
// remove unneeded array
unset($tables[$table_alias]);
}
}
// check if fields array is empty to prevent SQL error
if (!$tables) {
$tables['bsub'] = array('title', 'isbn_issn', 'series_title');
$tables['ma'] = array('author_name');
$tables['mt'] = array('topic');
}
}
// set default criteria
$criteria = 'bsub.biblio_id IS NOT NULL';
// is there any search
if (isset($_GET['keywords']) AND $_GET['keywords']) {
$keyword = $dbs->escape_string(trim($_GET['keywords']));
$words = explode(' ', $keyword);
if (count($words) > 1) {
$concat_sql = ' (';
foreach ($words as $word) {
$concat_sql .= '(';
foreach ($tables as $table_alias=>$fields) {
foreach ($fields as $field) {
$concat_sql .= $table_alias.'.'.$field." LIKE '%$word%' OR ";
}
}
// remove the last OR
$concat_sql = substr_replace($concat_sql, '', -4);
$concat_sql .= ') AND';
// $concat_sql .= " (bsub.title LIKE '%$word%' OR bsub.isbn_issn LIKE '%$word%' OR ma.author_name LIKE '%$word%' OR mt.topic LIKE '%$word%') AND";
}
// remove the last AND
$concat_sql = substr_replace($concat_sql, '', -3);
$concat_sql .= ') ';
$criteria = $concat_sql;
} else {
$concat_sql = '';
foreach ($tables as $table_alias=>$fields) {
foreach ($fields as $field) {
$concat_sql .= $table_alias.'.'.$field." LIKE '%$keyword%' OR ";
}
}
// remove the last OR
$concat_sql = substr_replace($concat_sql, '', -4);
$criteria = $concat_sql;
// $criteria = "bsub.title LIKE '%$keyword%' OR bsub.isbn_issn LIKE '%$keyword%' OR ma.author_name LIKE '%$keyword%' OR mt.topic LIKE '%$keyword%'";
}
}
// subquery/view string
$subquery_str = '(SELECT DISTINCT bsub.biblio_id, bsub.title, bsub.isbn_issn, bsub.last_update
FROM biblio AS bsub
LEFT JOIN biblio_author AS ba ON bsub.biblio_id = ba.biblio_id
LEFT JOIN mst_author AS ma ON ba.author_id = ma.author_id
LEFT JOIN biblio_topic AS bt ON bsub.biblio_id = bt.biblio_id
LEFT JOIN mst_topic AS mt ON bt.topic_id = mt.topic_id WHERE '.$criteria.')';
// table spec
$table_spec = $subquery_str.' AS b
LEFT JOIN item AS i ON b.biblio_id=i.biblio_id';
// set group by
$datagrid->sql_group_by = 'b.biblio_id';
// $datagrid->disableSort('Copies');
// set table and table header attributes
$datagrid->icon_edit = SENAYAN_WEB_ROOT_DIR.'admin/'.$sysconf['admin_template']['dir'].'/'.$sysconf['admin_template']['theme'].'/edit.gif';
$datagrid->table_attr = 'align="center" id="dataList" style="width: 100%;" cellpadding="5" cellspacing="0"';
$datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
// set delete proccess URL
$datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
// put the result into variables
$datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, ($can_read AND $can_write));
if (isset($_GET['keywords']) AND $_GET['keywords']) {
$msg = str_replace('{result->num_rows}', $datagrid->num_rows, lang_sys_common_search_result_info);
echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"</div>';
}
echo $datagrid_result;
}
/* main content end */
?>