<?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 label printing */
// start the session
session_start();
require '../../../sysconfig.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';
// privileges checking
$can_read = utility::havePrivilege('bibliography', 'r');
if (!$can_read) {
die('<div class="errorBox">'.lang_sys_common_unauthorized.'</div>');
}
$max_print = 50;
/* RECORD OPERATION */
if (isset($_POST['itemID']) AND !empty($_POST['itemID']) AND isset($_POST['itemAction'])) {
if (!$can_read) {
die();
}
if (!is_array($_POST['itemID'])) {
// make an array
$_POST['itemID'] = array((integer)$_POST['itemID']);
}
/* LABEL SESSION ADDING PROCESS */
if (isset($_SESSION['labels'])) {
$print_count = count($_SESSION['labels']);
} else {
$print_count = 0;
}
// loop array
foreach ($_POST['itemID'] as $itemID) {
if ($print_count == $max_print) {
$limit_reach = true;
break;
}
$itemID = (integer)$itemID;
if (isset($_SESSION['labels'][$itemID])) {
continue;
}
$_SESSION['labels'][$itemID] = $itemID;
$print_count++;
}
if (isset($limit_reach)) {
$msg = str_replace('{max_print}', $max_print, lang_mod_biblio_alert_print_no_add_queue);
utility::jsAlert($msg);
} else {
// update print queue count object
echo '<script type="text/javascript">parent.$(\'queueCount\').update(\''.$print_count.'\');</script>';
utility::jsAlert(lang_mod_biblio_alert_print_add_ok);
}
exit();
}
// clean print queue
if (isset($_GET['action']) AND $_GET['action'] == 'clear') {
utility::jsAlert(lang_mod_biblio_common_print_cleared);
echo '<script type="text/javascript">parent.$(\'queueCount\').update(\'0\');</script>';
unset($_SESSION['labels']);
exit();
}
// on print action
if (isset($_GET['action']) AND $_GET['action'] == 'print') {
// check if label session array is available
if (!isset($_SESSION['labels'])) {
utility::jsAlert(lang_mod_biblio_common_print_no_data);
die();
}
if (count($_SESSION['labels']) < 1) {
utility::jsAlert(lang_mod_biblio_common_print_no_data);
die();
}
// concat all ID together
$biblio_ids = '';
foreach ($_SESSION['labels'] as $id) {
$biblio_ids .= $id.',';
}
// strip the last comma
$biblio_ids = substr_replace($biblio_ids, '', -1);
// send query to database
$biblio_q = $dbs->query('SELECT call_number FROM biblio WHERE biblio_id IN('.$biblio_ids.')');
$label_data_array = array();
while ($biblio_d = $biblio_q->fetch_row()) {
if ($biblio_d[0]) {
$label_data_array[] = $biblio_d[0];
}
}
// include printed settings configuration file
include SENAYAN_BASE_DIR.'admin'.DIRECTORY_SEPARATOR.'admin_template'.DIRECTORY_SEPARATOR.'printed_settings.inc.php';
// chunk label array
$chunked_label_arrays = array_chunk($label_data_array, $items_per_row);
// create html ouput of images
$html_str = '<html><head><title>Document Label Print Result</title>'."\n";
$html_str .= '<style type="text/css">'."\n";
$html_str .= 'body { padding: 0; margin: '.$page_margin.'cm; width: '.$page_width.'cm }'."\n";
$html_str .= '.labelStyle { width: 100%; position: relative; text-align: center; float: left; margin: '.$items_margin.'cm; border: 1px solid #000000; width: '.$cell_width.'.5cm; }'."\n";
$html_str .= '.labelHeaderStyle { background-color: #CCCCCC; font-weight: bold; padding: 5px; margin-bottom: 5px; }'."\n";
$html_str .= '</style>'."\n";
$html_str .= '</head>'."\n";
$html_str .= '<body>'."\n";
// loop the chunked arrays to row
foreach ($chunked_label_arrays as $label_data) {
$html_str .= '<div style="clear: both;">'."\n";
foreach ($label_data as $label) {
$html_str .= '<div class="labelStyle">';
$html_str .= '<div class="labelHeaderStyle">'.$sysconf['library_name'].'</div>';
// explode label data by space
$sliced_label = explode(' ', $label, 5);
foreach ($sliced_label as $slice_label_item) {
$html_str .= $slice_label_item.'<br />';
}
$html_str .= '</div>';
}
$html_str .= '</div>'."\n";
}
$html_str .= '<script type="text/javascript">self.print();</script>'."\n";
$html_str .= '</body></html>'."\n";
// unset the session
unset($_SESSION['labels']);
// write to file
$file_write = @file_put_contents(FILES_UPLOAD_DIR.'label_print_result.html', $html_str);
if ($file_write) {
echo '<script type="text/javascript">parent.$(\'queueCount\').update(\'0\');</script>';
// open result in new window
echo '<script type="text/javascript">parent.openWin(\''.SENAYAN_WEB_ROOT_DIR.FILES_DIR.'/label_print_result.html\', \'popLabelGen\', 800, 500, true)</script>';
} else { utility::jsAlert('ERROR! Label failed to generate, possibly because '.SENAYAN_BASE_DIR.FILES_DIR.' directory is not writable'); }
exit();
}
/* search form */
?>
<table id="searchForm" cellpadding="5" cellspacing="0">
<tr>
<td class="imageLeft" valign="top" style="background-image: url(<?php echo $sysconf['admin_template']['dir'].'/'.$sysconf['admin_template']['theme'].'/printer.png'; ?>)">
<?php echo lang_mod_biblio_tools_label_print; ?> - <a target="blindSubmit" href="<?php echo MODULES_WEB_ROOT_DIR; ?>bibliography/dl_print.php?action=print" class="headerText2"><?php echo lang_mod_biblio_tools_label_print_select; ?></a>
<a target="blindSubmit" href="<?php echo MODULES_WEB_ROOT_DIR; ?>bibliography/dl_print.php?action=clear" class="headerText2" style="color: #FF0000;"><?php echo lang_mod_biblio_tools_label_print_clear; ?></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_field; ?> :
<input type="text" name="keywords" size="30" />
<input type="button" id="doSearch" onclick="setContent('mainContent', '<?php echo MODULES_WEB_ROOT_DIR; ?>bibliography/dl_print.php?' + $('search').serialize(), 'post')" value="<?php echo lang_sys_common_form_search; ?>" class="button" />
</form>
<div style="margin-top: 3px;">
<?php
echo 'Maximum <font style="color: #FF0000">'.$max_print.'</font> data/labels can be printed at once. Currently there is ';
if (isset($_SESSION['labels'])) {
echo '<font id="queueCount" style="color: #FF0000">'.count($_SESSION['labels']).'</font>';
} else { echo '<font id="queueCount" style="color: #FF0000">0</font>'; }
echo ' in queue waiting to be printed.';
?>
</div>
</td>
</tr>
</table>
<?php
/* search form end */
/* BIBLIOGRAPHY LIST */
// table spec
$table_spec = 'biblio AS b';
// create datagrid
$datagrid = new simbio_datagrid();
if ($can_read) {
$datagrid->setSQLColumn('biblio_id',
'b.title AS \'Title\'',
'b.call_number AS \'Call Number\'');
}
$datagrid->setSQLorder("last_update DESC");
// 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 .= " (b.title LIKE '%$word%' OR b.isbn_issn LIKE '%$word%') AND";
}
// remove the last AND
$concat_sql = substr_replace($concat_sql, '', -3);
$concat_sql .= ') ';
$datagrid->setSQLCriteria($concat_sql);
} else {
$datagrid->setSQLCriteria("b.title LIKE '%$keyword%' OR b.isbn_issn LIKE '%$keyword%'");
}
}
// set table and table header attributes
$datagrid->table_attr = 'align="center" id="dataList" style="width: 100%;" cellpadding="5" cellspacing="0"';
$datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
// edit and checkbox property
$datagrid->edit_property = false;
$datagrid->chbox_property = array('itemID', 'Add');
$datagrid->chbox_action_button = lang_mod_biblio_common_form_print_queue;
$datagrid->chbox_confirm_msg = lang_mod_biblio_common_print_queue_confirm;
// 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);
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 */
?>