PageRenderTime 37ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/modules/bibliography/dl_print.php

https://gitlab.com/mucill/sman7
PHP | 312 lines | 231 code | 17 blank | 64 comment | 50 complexity | d930e4e2f97798820c91c2a929ff272a 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 3 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. /* Bibliography label printing */
  21. // key to authenticate
  22. define('INDEX_AUTH', '1');
  23. // main system configuration
  24. require '../../../sysconfig.inc.php';
  25. // IP based access limitation
  26. require LIB.'ip_based_access.inc.php';
  27. do_checkIP('smc');
  28. do_checkIP('smc-bibliography');
  29. // start the session
  30. require SB.'admin/default/session.inc.php';
  31. require SIMBIO.'simbio_GUI/table/simbio_table.inc.php';
  32. require SIMBIO.'simbio_GUI/form_maker/simbio_form_table_AJAX.inc.php';
  33. require SIMBIO.'simbio_GUI/paging/simbio_paging.inc.php';
  34. require SIMBIO.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
  35. // privileges checking
  36. $can_read = utility::havePrivilege('bibliography', 'r');
  37. if (!$can_read) {
  38. die('<div class="errorBox">'.__('You are not authorized to view this section').'</div>');
  39. }
  40. $max_print = 50;
  41. /* RECORD OPERATION */
  42. if (isset($_POST['itemID']) AND !empty($_POST['itemID']) AND isset($_POST['itemAction'])) {
  43. if (!$can_read) {
  44. die();
  45. }
  46. if (!is_array($_POST['itemID'])) {
  47. // make an array
  48. $_POST['itemID'] = array($_POST['itemID']);
  49. }
  50. /* LABEL SESSION ADDING PROCESS */
  51. $print_count = 0;
  52. if (isset($_SESSION['labels']['biblio'])) {
  53. $print_count_biblio = count($_SESSION['labels']['biblio']);
  54. }
  55. if (isset($_SESSION['labels']['item'])) {
  56. $print_count_item = count($_SESSION['labels']['item']);
  57. }
  58. // loop array
  59. foreach ($_POST['itemID'] as $itemID) {
  60. if ($print_count == $max_print) {
  61. $limit_reach = true;
  62. break;
  63. }
  64. if (stripos($itemID, 'b', 0) !== false) {
  65. // Biblio ID
  66. $biblioID = str_ireplace('b', '', $itemID);
  67. if (isset($_SESSION['labels']['biblio'][$biblioID])) {
  68. continue;
  69. }
  70. $_SESSION['labels']['biblio'][$biblioID] = $biblioID;
  71. $print_count_biblio++;
  72. } else {
  73. // Item ID
  74. $itemID = (integer)$itemID;
  75. if (isset($_SESSION['labels']['item'][$itemID])) {
  76. continue;
  77. }
  78. $_SESSION['labels']['item'][$itemID] = $itemID;
  79. $print_count_item++;
  80. }
  81. }
  82. $print_count = $print_count_item + $print_count_biblio;
  83. echo '<script type="text/javascript">top.$(\'#queueCount\').html(\''.$print_count.'\');</script>';
  84. if (isset($limit_reach)) {
  85. $msg = str_replace('{max_print}', $max_print, __('Selected items NOT ADDED to print queue. Only {max_print} can be printed at once'));
  86. utility::jsAlert($msg);
  87. } else {
  88. // update print queue count object
  89. utility::jsAlert(__('Selected items added to print queue'));
  90. }
  91. exit();
  92. }
  93. // clean print queue
  94. if (isset($_GET['action']) AND $_GET['action'] == 'clear') {
  95. utility::jsAlert(__('Print queue cleared!'));
  96. echo '<script type="text/javascript">top.$(\'#queueCount\').html(\'0\');</script>';
  97. unset($_SESSION['labels']);
  98. exit();
  99. }
  100. // on print action
  101. if (isset($_GET['action']) AND $_GET['action'] == 'print') {
  102. // check if label session array is available
  103. if (!isset($_SESSION['labels']['item']) && !isset($_SESSION['labels']['biblio'])) {
  104. utility::jsAlert(__('There is no data to print!'));
  105. die();
  106. }
  107. // concat item ID
  108. $item_ids = '';
  109. if (isset($_SESSION['labels']['item'])) {
  110. foreach ($_SESSION['labels']['item'] as $id) {
  111. $item_ids .= $id.',';
  112. }
  113. }
  114. // concat biblio ID
  115. $biblio_ids = '';
  116. if (isset($_SESSION['labels']['biblio'])) {
  117. foreach ($_SESSION['labels']['biblio'] as $id) {
  118. $biblio_ids .= $id.',';
  119. }
  120. }
  121. // strip the last comma
  122. $item_ids = substr_replace($item_ids, '', -1);
  123. $biblio_ids = substr_replace($biblio_ids, '', -1);
  124. // SQL criteria
  125. if ($item_ids) {
  126. $criteria = "i.item_id IN($item_ids)";
  127. }
  128. if ($biblio_ids) {
  129. $criteria = "b.biblio_id IN($biblio_ids)";
  130. }
  131. if ($item_ids && $biblio_ids) {
  132. $criteria = "i.item_id IN($item_ids) OR b.biblio_id IN($biblio_ids)";
  133. }
  134. // send query to database
  135. $biblio_q = $dbs->query('SELECT IF(i.call_number<>\'\', i.call_number, b.call_number) FROM biblio AS b LEFT JOIN item AS i ON b.biblio_id=i.biblio_id WHERE '.$criteria);
  136. // echo 'SELECT IF(i.call_number!=\'\', i.call_number, b.call_number) FROM biblio AS b LEFT JOIN item AS i ON b.biblio_id=i.biblio_id WHERE '.$criteria;
  137. $label_data_array = array();
  138. while ($biblio_d = $biblio_q->fetch_row()) {
  139. if ($biblio_d[0]) { $label_data_array[] = $biblio_d[0]; }
  140. }
  141. // include printed settings configuration file
  142. include SB.'admin'.DS.'admin_template'.DS.'printed_settings.inc.php';
  143. // check for custom template settings
  144. $custom_settings = SB.'admin'.DS.$sysconf['admin_template']['dir'].DS.$sysconf['template']['theme'].DS.'printed_settings.inc.php';
  145. if (file_exists($custom_settings)) {
  146. include $custom_settings;
  147. }
  148. // load print settings from database to override value from printed_settings file
  149. loadPrintSettings($dbs, 'label');
  150. // chunk label array
  151. $chunked_label_arrays = array_chunk($label_data_array, $sysconf['print']['label']['items_per_row']);
  152. // create html ouput of images
  153. $html_str = '<!DOCTYPE html>'."\n";
  154. $html_str .= '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Document Label Print Result</title>'."\n";
  155. $html_str .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
  156. $html_str .= '<meta http-equiv="Pragma" content="no-cache" /><meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, post-check=0, pre-check=0" /><meta http-equiv="Expires" content="Sat, 26 Jul 1997 05:00:00 GMT" />';
  157. $html_str .= '<style type="text/css">'."\n";
  158. $html_str .= 'body { padding: 0; margin: 1cm; font-family: '.$sysconf['print']['label']['fonts'].'; font-size: '.$sysconf['print']['label']['font_size'].'pt; background: #fff; }'."\n";
  159. $html_str .= '.labelStyle { width: '.$sysconf['print']['label']['box_width'].'cm; height: '.$sysconf['print']['label']['box_height'].'cm; text-align: center; margin: '.$sysconf['print']['label']['items_margin'].'cm; padding: 0; border: '.$sysconf['print']['label']['border_size'].'px solid #000000; }'."\n";
  160. $html_str .= '.labelHeaderStyle { background-color: #CCCCCC; font-weight: bold; padding: 5px; margin-bottom: 5px; }'."\n";
  161. $html_str .= '</style>'."\n";
  162. $html_str .= '</head>'."\n";
  163. $html_str .= '<body>'."\n";
  164. $html_str .= '<a href="#" onclick="window.print()">Print Again</a>'."\n";
  165. $html_str .= '<table style="margin: 0; padding: 0;" cellspacing="0" cellpadding="0">'."\n";
  166. // loop the chunked arrays to row
  167. foreach ($chunked_label_arrays as $label_data) {
  168. $html_str .= '<tr>'."\n";
  169. foreach ($label_data as $label) {
  170. $html_str .= '<td valign="top">';
  171. $html_str .= '<div class="labelStyle" valign="top">';
  172. if ($sysconf['print']['label']['include_header_text']) { $html_str .= '<div class="labelHeaderStyle">'.($sysconf['print']['label']['header_text']?$sysconf['print']['label']['header_text']:$sysconf['library_name']).'</div>'; }
  173. // explode label data by space
  174. $sliced_label = explode(' ', $label, 5);
  175. foreach ($sliced_label as $slice_label_item) {
  176. $html_str .= $slice_label_item.'<br />';
  177. }
  178. $html_str .= '</div>';
  179. $html_str .= '</td>';
  180. }
  181. $html_str .= '</tr>'."\n";
  182. }
  183. $html_str .= '</table>'."\n";
  184. $html_str .= '<script type="text/javascript">self.print();</script>'."\n";
  185. $html_str .= '</body></html>'."\n";
  186. // unset the session
  187. unset($_SESSION['labels']);
  188. // write to file
  189. $print_file_name = 'label_print_result_'.strtolower(str_replace(' ', '_', $_SESSION['uname'])).'.html';
  190. $file_write = @file_put_contents(UPLOAD.$print_file_name, $html_str);
  191. if ($file_write) {
  192. echo '<script type="text/javascript">parent.$(\'#queueCount\').html(\'0\');</script>';
  193. // open result in new window
  194. echo '<script type="text/javascript">top.$.colorbox({href: "'.SWB.FLS.'/'.$print_file_name.'", iframe: true, width: 800, height: 500, title: "Label Print Result"})</script>';
  195. } else { utility::jsAlert('ERROR! Label failed to generate, possibly because '.SB.FLS.' directory is not writable'); }
  196. exit();
  197. }
  198. /* search form */
  199. ?>
  200. <fieldset class="menuBox">
  201. <div class="menuBoxInner printIcon">
  202. <div class="per_title">
  203. <h2><?php echo __('Labels Printing'); ?></h2>
  204. </div>
  205. <div class="sub_section">
  206. <div class="btn-group">
  207. <a target="blindSubmit" href="<?php echo MWB; ?>bibliography/dl_print.php?action=clear" class="notAJAX btn btn-default"><i class="glyphicon glyphicon-trash"></i>&nbsp;<?php echo __('Clear Print Queue'); ?></a>
  208. <a target="blindSubmit" href="<?php echo MWB; ?>bibliography/dl_print.php?action=print" class="notAJAX btn btn-default"><i class="glyphicon glyphicon-print"></i>&nbsp;<?php echo __('Print Labels for Selected Data'); ?></a>
  209. <a href="<?php echo MWB; ?>bibliography/pop_print_settings.php?type=label" class="notAJAX btn btn-default openPopUp" title="<?php echo __('Change print barcode settings'); ?>"><i class="glyphicon glyphicon-wrench"></i></a>
  210. </div>
  211. <form name="search" action="<?php echo MWB; ?>bibliography/dl_print.php" id="search" method="get" style="display: inline;"><?php echo __('Search'); ?> :
  212. <input type="text" name="keywords" size="30" />
  213. <input type="submit" id="doSearch" value="<?php echo __('Search'); ?>" class="btn btn-default" />
  214. </form>
  215. </div>
  216. <div class="infoBox">
  217. <?php
  218. echo __('Maximum').' <font style="color: #FF0000">'.$max_print.'</font> '.__('records can be printed at once. Currently there is').' ';
  219. if (isset($_SESSION['labels'])) {
  220. echo '<font id="queueCount" style="color: #FF0000">'.@( count($_SESSION['labels']['item'])+count($_SESSION['labels']['biblio']) ).'</font>';
  221. } else { echo '<font id="queueCount" style="color: #FF0000">0</font>'; }
  222. echo ' '.__('in queue waiting to be printed.');
  223. ?>
  224. </div>
  225. </div>
  226. </fieldset>
  227. <?php
  228. /* search form end */
  229. // create datagrid
  230. $datagrid = new simbio_datagrid();
  231. /* BIBLIOGRAPHY LIST */
  232. require SIMBIO.'simbio_UTILS/simbio_tokenizecql.inc.php';
  233. require LIB.'biblio_list_model.inc.php';
  234. // index choice
  235. if ($sysconf['index']['type'] == 'index' || ($sysconf['index']['type'] == 'sphinx' && file_exists(LIB.'sphinx/sphinxapi.php'))) {
  236. if ($sysconf['index']['type'] == 'sphinx') {
  237. require LIB.'sphinx/sphinxapi.php';
  238. require LIB.'biblio_list_sphinx.inc.php';
  239. } else {
  240. require LIB.'biblio_list_index.inc.php';
  241. }
  242. // table spec
  243. $table_spec = 'search_biblio AS `index` LEFT JOIN `item` ON `index`.biblio_id=`item`.biblio_id';
  244. if ($can_read) {
  245. $datagrid->setSQLColumn('IF(item.item_id IS NOT NULL, item.item_id, CONCAT(\'b\', index.biblio_id))', 'index.title AS `'.__('Title').'`',
  246. 'IF(item.call_number<>\'\', item.call_number, index.call_number) AS `'.__('Call Number').'`');
  247. }
  248. } else {
  249. require LIB.'biblio_list.inc.php';
  250. // table spec
  251. $table_spec = 'biblio LEFT JOIN item ON biblio.biblio_id=item.biblio_id';
  252. if ($can_read) {
  253. $datagrid->setSQLColumn('IF(item.item_id IS NOT NULL, item.item_id, CONCAT(\'b\', biblio.biblio_id))', 'biblio.title AS `'.__('Title').'`',
  254. 'IF(item.call_number<>\'\', item.call_number, biblio.call_number) AS `'.__('Call Number').'`');
  255. }
  256. }
  257. $datagrid->setSQLorder('item.last_update DESC');
  258. // is there any search
  259. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  260. $keywords = $dbs->escape_string(trim($_GET['keywords']));
  261. $searchable_fields = array('title', 'author', 'class', 'callnumber', 'itemcode');
  262. $search_str = '';
  263. // if no qualifier in fields
  264. if (!preg_match('@[a-z]+\s*=\s*@i', $keywords)) {
  265. foreach ($searchable_fields as $search_field) {
  266. $search_str .= $search_field.'='.$keywords.' OR ';
  267. }
  268. } else {
  269. $search_str = $keywords;
  270. }
  271. $biblio_list = new biblio_list($dbs, 20);
  272. $criteria = $biblio_list->setSQLcriteria($search_str);
  273. }
  274. if (isset($criteria)) {
  275. $datagrid->setSQLcriteria('('.$criteria['sql_criteria'].')');
  276. }
  277. // set table and table header attributes
  278. $datagrid->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
  279. $datagrid->table_header_attr = 'class="dataListHeader" style="font-weight: bold;"';
  280. // edit and checkbox property
  281. $datagrid->edit_property = false;
  282. $datagrid->chbox_property = array('itemID', __('Add'));
  283. $datagrid->chbox_action_button = __('Add To Print Queue');
  284. $datagrid->chbox_confirm_msg = __('Add to print queue?');
  285. // set delete proccess URL
  286. $datagrid->chbox_form_URL = $_SERVER['PHP_SELF'];
  287. $datagrid->column_width = array(0 => '75%', 1 => '20%');
  288. // put the result into variables
  289. $datagrid_result = $datagrid->createDataGrid($dbs, $table_spec, 20, $can_read);
  290. if (isset($_GET['keywords']) AND $_GET['keywords']) {
  291. $msg = str_replace('{result->num_rows}', $datagrid->num_rows, __('Found <strong>{result->num_rows}</strong> from your keywords'));
  292. echo '<div class="infoBox">'.$msg.' : "'.$_GET['keywords'].'"<div>'.__('Query took').' <b>'.$datagrid->query_time.'</b> '.__('second(s) to complete').'</div></div>';
  293. }
  294. echo $datagrid_result;
  295. /* main content end */