PageRenderTime 68ms CodeModel.GetById 21ms RepoModel.GetById 6ms app.codeStats 0ms

/admin/modules/bibliography/item_barcode_generator.php

https://github.com/hendrowicaksono/s3st12-soap
PHP | 265 lines | 192 code | 12 blank | 61 comment | 33 complexity | b96ae351c0febee17407af070d28fb2d 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. /* Item barcode print */
  21. // main system configuration
  22. require '../../../sysconfig.inc.php';
  23. // start the session
  24. require SENAYAN_BASE_DIR.'admin/default/session.inc.php';
  25. require SIMBIO_BASE_DIR.'simbio_GUI/table/simbio_table.inc.php';
  26. require SIMBIO_BASE_DIR.'simbio_GUI/form_maker/simbio_form_table_AJAX.inc.php';
  27. require SIMBIO_BASE_DIR.'simbio_GUI/paging/simbio_paging_ajax.inc.php';
  28. require SIMBIO_BASE_DIR.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
  29. require SIMBIO_BASE_DIR.'simbio_DB/simbio_dbop.inc.php';
  30. // privileges checking
  31. $can_read = utility::havePrivilege('bibliography', 'r');
  32. if (!$can_read) {
  33. die('<div class="errorBox">'.__('You are not authorized to view this section').'</div>');
  34. }
  35. $max_print = 50;
  36. /* RECORD OPERATION */
  37. if (isset($_POST['itemID']) AND !empty($_POST['itemID']) AND isset($_POST['itemAction'])) {
  38. if (!$can_read) {
  39. die();
  40. }
  41. if (!is_array($_POST['itemID'])) {
  42. // make an array
  43. $_POST['itemID'] = array((integer)$_POST['itemID']);
  44. }
  45. // loop array
  46. if (isset($_SESSION['barcodes'])) {
  47. $print_count = count($_SESSION['barcodes']);
  48. } else {
  49. $print_count = 0;
  50. }
  51. // barcode size
  52. $size = 2;
  53. // create AJAX request
  54. echo '<script type="text/javascript" src="'.JS_WEB_ROOT_DIR.'prototype.js"></script>';
  55. echo '<script type="text/javascript">';
  56. // loop array
  57. foreach ($_POST['itemID'] as $itemID) {
  58. if ($print_count == $max_print) {
  59. $limit_reach = true;
  60. break;
  61. }
  62. if (isset($_SESSION['barcodes'][$itemID])) {
  63. continue;
  64. }
  65. if (!empty($itemID)) {
  66. $barcode_text = trim($itemID);
  67. /* replace space */
  68. $barcode_text = str_replace(array(' ', '/', '\/'), '_', $barcode_text);
  69. /* replace invalid characters */
  70. $barcode_text = str_replace(array(':', ',', '*', '@'), '', $barcode_text);
  71. // send ajax request
  72. echo 'new Ajax.Request(\''.SENAYAN_WEB_ROOT_DIR.'lib/phpbarcode/barcode.php?code='.$itemID.'&encoding='.$sysconf['barcode_encoding'].'&scale='.$size.'&mode=png\', { method: \'get\', onFailure: function(sendAlert) { alert(\'Error creating barcode!\'); } });'."\n";
  73. // add to sessions
  74. $_SESSION['barcodes'][$itemID] = $itemID;
  75. $print_count++;
  76. }
  77. }
  78. echo '</script>';
  79. sleep(2);
  80. if (isset($limit_reach)) {
  81. $msg = str_replace('{max_print}', $max_print, __('Selected items NOT ADDED to print queue. Only {max_print} can be printed at once')); //mfc
  82. utility::jsAlert($msg);
  83. } else {
  84. // update print queue count object
  85. echo '<script type="text/javascript">parent.$(\'queueCount\').update(\''.$print_count.'\');</script>';
  86. utility::jsAlert(__('Selected items added to print queue'));
  87. }
  88. exit();
  89. }
  90. // clean print queue
  91. if (isset($_GET['action']) AND $_GET['action'] == 'clear') {
  92. // update print queue count object
  93. echo '<script type="text/javascript">parent.$(\'queueCount\').update(\'0\');</script>';
  94. utility::jsAlert(__('Print queue cleared!'));
  95. unset($_SESSION['barcodes']);
  96. exit();
  97. }
  98. // barcode pdf download
  99. if (isset($_GET['action']) AND $_GET['action'] == 'print') {
  100. // check if label session array is available
  101. if (!isset($_SESSION['barcodes'])) {
  102. utility::jsAlert(__('There is no data to print!'));
  103. die();
  104. }
  105. if (count($_SESSION['barcodes']) < 1) {
  106. utility::jsAlert(__('There is no data to print!'));
  107. die();
  108. }
  109. // concat all ID together
  110. $item_ids = '';
  111. foreach ($_SESSION['barcodes'] as $id) {
  112. $item_ids .= '\''.$id.'\',';
  113. }
  114. // strip the last comma
  115. $item_ids = substr_replace($item_ids, '', -1);
  116. // send query to database
  117. $item_q = $dbs->query('SELECT b.title, i.item_code FROM item AS i
  118. LEFT JOIN biblio AS b ON i.biblio_id=b.biblio_id
  119. WHERE i.item_code IN('.$item_ids.')');
  120. $item_data_array = array();
  121. while ($item_d = $item_q->fetch_row()) {
  122. if ($item_d[0]) {
  123. $item_data_array[] = $item_d;
  124. }
  125. }
  126. // include printed settings configuration file
  127. require SENAYAN_BASE_DIR.'admin'.DIRECTORY_SEPARATOR.'admin_template'.DIRECTORY_SEPARATOR.'printed_settings.inc.php';
  128. // check for custom template settings
  129. $custom_settings = SENAYAN_BASE_DIR.'admin'.DIRECTORY_SEPARATOR.$sysconf['admin_template']['dir'].DIRECTORY_SEPARATOR.$sysconf['template']['theme'].DIRECTORY_SEPARATOR.'printed_settings.inc.php';
  130. if (file_exists($custom_settings)) {
  131. include $custom_settings;
  132. }
  133. // chunk barcode array
  134. $chunked_barcode_arrays = array_chunk($item_data_array, $barcode_items_per_row);
  135. // create html ouput
  136. $html_str = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
  137. $html_str .= '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Item Barcode Label Print Result</title>'."\n";
  138. $html_str .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n";
  139. $html_str .= '<style type="text/css">'."\n";
  140. $html_str .= 'body { padding: 0; margin: 1cm; font-family: '.$barcode_fonts.' }'."\n";
  141. $html_str .= '.labelStyle { width: '.$barcode_box_width.'cm; height: '.$barcode_box_height.'cm; text-align: center; margin: '.$barcode_items_margin.'cm; border: '.$barcode_border_size.'px solid #000000;}'."\n";
  142. $html_str .= '.labelHeaderStyle { background-color: #CCCCCC; font-weight: bold; padding: 5px; margin-bottom: 5px; }'."\n";
  143. $html_str .= '</style>'."\n";
  144. $html_str .= '</head>'."\n";
  145. $html_str .= '<body>'."\n";
  146. $html_str .= '<table style="margin: 0; padding: 0;" cellspacing="0" cellpadding="0">'."\n";
  147. // loop the chunked arrays to row
  148. foreach ($chunked_barcode_arrays as $barcode_rows) {
  149. $html_str .= '<tr>'."\n";
  150. foreach ($barcode_rows as $barcode) {
  151. $html_str .= '<td valign="top">';
  152. $html_str .= '<div class="labelStyle">';
  153. if ($barcode_include_header_text) { $html_str .= '<div class="labelHeaderStyle">'.($barcode_header_text?$barcode_header_text:$sysconf['library_name']).'</div>'; }
  154. // document title
  155. $html_str .= '<div style="font-size: 7pt;">';
  156. if ($barcode_cut_title) {
  157. $html_str .= substr($barcode[0], 0, $barcode_cut_title).'...';
  158. } else { $html_str .= $barcode[0]; }
  159. $html_str .= '</div>';
  160. $html_str .= '<img src="'.SENAYAN_WEB_ROOT_DIR.IMAGES_DIR.'/barcodes/'.str_replace(array(' '), '_', $barcode[1]).'.png" style="width: '.$barcode_scale.'%;" border="0" />';
  161. $html_str .= '</div>';
  162. $html_str .= '</td>';
  163. }
  164. $html_str .= '<tr>'."\n";
  165. }
  166. $html_str .= '</table>'."\n";
  167. $html_str .= '<script type="text/javascript">self.print();</script>'."\n";
  168. $html_str .= '</body></html>'."\n";
  169. // unset the session
  170. unset($_SESSION['barcodes']);
  171. // write to file
  172. $file_write = @file_put_contents(FILES_UPLOAD_DIR.'item_barcode_gen_print_result.html', $html_str);
  173. if ($file_write) {
  174. // update print queue count object
  175. echo '<script type="text/javascript">parent.$(\'queueCount\').update(\'0\');</script>';
  176. // open result in window
  177. echo '<script type="text/javascript">parent.openWin(\''.SENAYAN_WEB_ROOT_DIR.FILES_DIR.'/item_barcode_gen_print_result.html\', \'popItemBarcodeGen\', 800, 500, true)</script>';
  178. } else { utility::jsAlert('ERROR! Item barcodes failed to generate, possibly because '.SENAYAN_BASE_DIR.FILES_DIR.' directory is not writable'); }
  179. exit();
  180. }
  181. ?>
  182. <fieldset class="menuBox">
  183. <div class="menuBoxInner printIcon">
  184. <?php echo __('Item Barcodes Printing'); ?> - <a target="blindSubmit" href="<?php echo MODULES_WEB_ROOT_DIR; ?>bibliography/item_barcode_generator.php?action=print" class="headerText2"><?php echo __('Print Barcodes for Selected Data');?></a>
  185. &nbsp; <a href="#" onclick="<?php echo MODULES_WEB_ROOT_DIR; ?>bibliography/item_barcode_generator.php?action=clear" class="headerText2" style="color: #FF0000;"><?php echo __('Clear Print Queue'); ?></a>
  186. <hr />
  187. <form name="search" action="blank.html" target="blindSubmit" onsubmit="$('doSearch').click();" id="search" method="get" style="display: inline;"><?php echo __('Search'); ?> :
  188. <input type="text" name="keywords" size="30" />
  189. <input type="button" id="doSearch" onclick="setContent('mainContent', '<?php echo MODULES_WEB_ROOT_DIR; ?>bibliography/item_barcode_generator.php?' + $('search').serialize(), 'post')" value="<?php echo __('Search'); ?>" class="button" />
  190. </form>
  191. <div style="margin-top: 3px;">
  192. <?php
  193. echo __('Maximum').' <font style="color: #FF0000">'.$max_print.'</font> '.__('records can be printed at once. Currently there is').' '; //mfc
  194. if (isset($_SESSION['barcodes'])) {
  195. echo '<font id="queueCount" style="color: #FF0000">'.count($_SESSION['barcodes']).'</font>';
  196. } else { echo '<font id="queueCount" style="color: #FF0000">0</font>'; }
  197. echo ' '.__('in queue waiting to be printed.'); //mfc
  198. ?>
  199. </div>
  200. </div>
  201. </fieldset>
  202. <?php
  203. /* search form end */
  204. /* ITEM LIST */
  205. require SIMBIO_BASE_DIR.'simbio_UTILS/simbio_tokenizecql.inc.php';
  206. require LIB_DIR.'biblio_list.inc.php';
  207. // table spec
  208. $table_spec = 'item LEFT JOIN biblio ON item.biblio_id=biblio.biblio_id';
  209. // create datagrid
  210. $datagrid = new simbio_datagrid();
  211. $datagrid->setSQLColumn('item.item_code',
  212. 'item.item_code AS \''.__('Item Code').'\'',
  213. 'biblio.title AS \''.__('Title').'\'');
  214. $datagrid->setSQLorder('item.last_update DESC');
  215. // is there any search
  216. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  217. $keywords = $dbs->escape_string(trim($_GET['keywords']));
  218. $searchable_fields = array('title', 'author', 'subject', 'itemcode');
  219. $search_str = '';
  220. // if no qualifier in fields
  221. if (!preg_match('@[a-z]+\s*=\s*@i', $keywords)) {
  222. foreach ($searchable_fields as $search_field) {
  223. $search_str .= $search_field.'='.$keywords.' OR ';
  224. }
  225. } else {
  226. $search_str = $keywords;
  227. }
  228. $biblio_list = new biblio_list($dbs);
  229. $criteria = $biblio_list->setSQLcriteria($search_str);
  230. }
  231. if (isset($criteria)) {
  232. $datagrid->setSQLcriteria('('.$criteria['sql_criteria'].')');
  233. }
  234. // set table and table header attributes
  235. $datagrid->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  236. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  237. // edit and checkbox property
  238. $datagrid->edit_property = false;
  239. $datagrid->chbox_property = array('itemID', __('Add'));
  240. $datagrid->chbox_action_button = __('Add To Print Queue');
  241. $datagrid->chbox_confirm_msg = __('Add to print queue?');
  242. $datagrid->column_width = array('10%', '85%');
  243. // set checkbox action URL
  244. $datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
  245. // put the result into variables
  246. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, $can_read);
  247. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  248. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords')); //mfc
  249. echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"<div>'.__('Query took').' <b>'.$datagrid->query_time.'</b> '.__('second(s) to complete').'</div></div>'; //mfc
  250. }
  251. echo $datagrid_result;
  252. /* main content end */
  253. ?>