Advertisement
Guest User

buku_induk_perpustakaan.php

a guest
Oct 19th, 2017
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.21 KB | None | 0 0
  1. <?php
  2. /**
  3.  *
  4.  * Copyright (C) 2007,2008  Arie Nugraha (dicarve@yahoo.com)
  5.  * Modified for Excel output (C) 2010 by Wardiyono (wynerst@gmail.com)
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  */
  22.  
  23. /* Report By Titles */
  24.  
  25. // key to authenticate
  26. define('INDEX_AUTH', '1');
  27.  
  28. // main system configuration
  29. require '../../../../sysconfig.inc.php';
  30. // IP based access limitation
  31. require LIB.'ip_based_access.inc.php';
  32. do_checkIP('smc');
  33. do_checkIP('smc-reporting');
  34. // start the session
  35. require SB.'admin/default/session.inc.php';
  36. require SB.'admin/default/session_check.inc.php';
  37. // privileges checking
  38. $can_read = utility::havePrivilege('reporting', 'r');
  39. $can_write = utility::havePrivilege('reporting', 'w');
  40.  
  41. if (!$can_read) {
  42.     die('<div class="errorBox">'.__('You don\'t have enough privileges to access this area!').'</div>');
  43. }
  44.  
  45. require SIMBIO.'simbio_GUI/table/simbio_table.inc.php';
  46. require SIMBIO.'simbio_GUI/paging/simbio_paging.inc.php';
  47. require SIMBIO.'simbio_GUI/form_maker/simbio_form_element.inc.php';
  48. require SIMBIO.'simbio_DB/datagrid/simbio_dbgrid.inc.php';
  49. require MDLBS.'reporting/report_dbgrid.inc.php';
  50.  
  51. $page_title = 'BUKU INDUK PERPUSTAKAAN';
  52. $reportView = false;
  53. $num_recs_show = 10;
  54. if (isset($_GET['reportView'])) {
  55.     $reportView = true;
  56. }
  57.  
  58. if (!$reportView) {
  59. ?>
  60.     <!-- filter -->
  61.     <fieldset>
  62.     <div class="per_title">
  63.         <h2><?php echo __('Buku Induk Perpustakaan'); ?></h2>
  64.       </div>
  65.     <div class="infoBox">
  66.     <?php echo __('Report Filter'); ?>
  67.     </div>
  68.     <div class="sub_section">
  69.     <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" target="reportView">
  70.     <div id="filterForm">
  71.         <div class="divRow">
  72.             <div class="divRowLabel"><?php echo __('Title/ISBN'); ?></div>
  73.             <div class="divRowContent">
  74.             <?php echo simbio_form_element::textField('text', 'title', '', 'style="width: 50%"'); ?>
  75.             </div>
  76.         </div>
  77.         <div class="divRow">
  78.             <div class="divRowLabel"><?php echo __('Author'); ?></div>
  79.             <div class="divRowContent">
  80.             <?php echo simbio_form_element::textField('text', 'author', '', 'style="width: 50%"'); ?>
  81.             </div>
  82.         </div>
  83.         <div class="divRow">
  84.             <div class="divRowLabel"><?php echo __('Classification'); ?></div>
  85.             <div class="divRowContent">
  86.             <?php echo simbio_form_element::textField('text', 'class', '', 'style="width: 50%"'); ?>
  87.             </div>
  88.         </div>
  89.         <div class="divRow">
  90.             <div class="divRowLabel"><?php echo __('GMD'); ?></div>
  91.             <div class="divRowContent">
  92.             <?php
  93.             $gmd_q = $dbs->query('SELECT gmd_id, gmd_name FROM mst_gmd');
  94.             $gmd_options[] = array('0', __('ALL'));
  95.             while ($gmd_d = $gmd_q->fetch_row()) {
  96.                 $gmd_options[] = array($gmd_d[0], $gmd_d[1]);
  97.             }
  98.             echo simbio_form_element::selectList('gmd[]', $gmd_options, '','multiple="multiple" size="5"');
  99.             ?> <?php echo __('Press Ctrl and click to select multiple entries'); ?>
  100.             </div>
  101.         </div>
  102.         <div class="divRow">
  103.             <div class="divRowLabel"><?php echo __('Collection Type'); ?></div>
  104.             <div class="divRowContent">
  105.             <?php
  106.             $coll_type_q = $dbs->query('SELECT coll_type_id, coll_type_name FROM mst_coll_type');
  107.             $coll_type_options = array();
  108.             $coll_type_options[] = array('0', __('ALL'));
  109.             while ($coll_type_d = $coll_type_q->fetch_row()) {
  110.                 $coll_type_options[] = array($coll_type_d[0], $coll_type_d[1]);
  111.             }
  112.             echo simbio_form_element::selectList('collType[]', $coll_type_options, '', 'multiple="multiple" size="5"');
  113.             ?>
  114.             </div>
  115.         </div>
  116.         <div class="divRow">
  117.             <div class="divRowLabel"><?php echo __('Language'); ?></div>
  118.             <div class="divRowContent">
  119.             <?php
  120.             $lang_q = $dbs->query('SELECT language_id, language_name FROM mst_language');
  121.             $lang_options = array();
  122.             $lang_options[] = array('0', __('ALL'));
  123.             while ($lang_d = $lang_q->fetch_row()) {
  124.                 $lang_options[] = array($lang_d[0], $lang_d[1]);
  125.             }
  126.             echo simbio_form_element::selectList('language', $lang_options);
  127.             ?>
  128.             </div>
  129.         </div>
  130.         <div class="divRow">
  131.             <div class="divRowLabel"><?php echo __('Location'); ?></div>
  132.             <div class="divRowContent">
  133.             <?php
  134.             $loc_q = $dbs->query('SELECT location_id, location_name FROM mst_location');
  135.             $loc_options = array();
  136.             $loc_options[] = array('0', __('ALL'));
  137.             while ($loc_d = $loc_q->fetch_row()) {
  138.                 $loc_options[] = array($loc_d[0], $loc_d[1]);
  139.             }
  140.             echo simbio_form_element::selectList('location', $loc_options);
  141.             ?>
  142.             </div>
  143.         </div>
  144.         <div class="divRow">
  145.             <div class="divRowLabel"><?php echo __('Publish year'); ?></div>
  146.             <div class="divRowContent">
  147.             <?php echo simbio_form_element::textField('text', 'publishYear', '', 'style="width: 50%"'); ?>
  148.             </div>
  149.         </div>
  150.         <div class="divRow">
  151.             <div class="divRowLabel"><?php echo __('Record each page'); ?></div>
  152.             <div class="divRowContent"><input type="text" name="recsEachPage" size="3" maxlength="3" value="<?php echo $num_recs_show; ?>" /> <?php echo __('Set between 10 and 200'); ?></div>
  153.         </div>
  154.     </div>
  155.     <div style="padding-top: 10px; clear: both;">
  156.     <input type="button" name="moreFilter" value="<?php echo __('Show More Filter Options'); ?>" />
  157.     <input type="submit" name="applyFilter" value="<?php echo __('Apply Filter'); ?>" />
  158.     <input type="hidden" name="reportView" value="true" />
  159.     </div>
  160.     </form>
  161.     </div>
  162.     </fieldset>
  163.     <!-- filter end -->
  164.     <div class="dataListHeader" style="padding: 3px;"><span id="pagingBox"></span></div>
  165.     <iframe name="reportView" id="reportView" src="<?php echo $_SERVER['PHP_SELF'].'?reportView=true'; ?>" frameborder="0" style="width: 100%; height: 500px;"></iframe>
  166. <?php
  167. } else {
  168.     ob_start();
  169.     // create datagrid
  170.     $reportgrid = new report_datagrid();
  171.     $reportgrid->setSQLColumn('b.biblio_id', 'b.title AS \''.__('Title').'\'', 'COUNT(item_id) AS \''.__('Copies').'\'',  
  172.         'b.biblio_id AS \''.__('Author').'\'',
  173.         'b.edition AS \''.__('Edition').'\'',
  174.         'b.publish_year AS \''.__('Year').'\'',
  175.         'pb.publisher_name AS \''.__('Publisher').'\'',
  176.         'pl.place_name AS \''.__('Place').'\'',
  177.         'b.language_id AS \''.__('Language').'\'',
  178.         'b.collation AS \''.__('Collation').'\'',
  179.         'b.isbn_issn AS \''.__('ISBN/ISSN').'\'',
  180.         'b.call_number AS \''.__('No.Panggil').'\'',
  181.         'i.price AS \''.__('Price').'\'',
  182.         'i.source AS \''.__('Sumber').'\'',
  183.         'b.input_date AS \''.__('Data Masuk').'\'',
  184.         'ct.coll_type_name AS \''.__('Collection Type').'\'',
  185.         'mg.gmd_name AS \''.__('GMD').'\'');
  186.     $reportgrid->setSQLorder('b.title ASC');
  187.     $reportgrid->invisible_fields = array(0);
  188.  
  189.     // is there any search
  190.     $criteria = 'bsub.biblio_id IS NOT NULL ';
  191.     $outer_criteria = 'b.biblio_id > 0 ';
  192.     if (isset($_GET['title']) AND !empty($_GET['title'])) {
  193.         $keyword = $dbs->escape_string(trim($_GET['title']));
  194.         $words = explode(' ', $keyword);
  195.         if (count($words) > 1) {
  196.             $concat_sql = ' AND (';
  197.             foreach ($words as $word) {
  198.                 $concat_sql .= " (bsub.title LIKE '%$word%' OR bsub.isbn_issn LIKE '%$word%') AND";
  199.             }
  200.             // remove the last AND
  201.             $concat_sql = substr_replace($concat_sql, '', -3);
  202.             $concat_sql .= ') ';
  203.             $criteria .= $concat_sql;
  204.         } else {
  205.             $criteria .= ' AND (bsub.title LIKE \'%'.$keyword.'%\' OR bsub.isbn_issn LIKE \'%'.$keyword.'%\')';
  206.         }
  207.     }
  208.     if (isset($_GET['author']) AND !empty($_GET['author'])) {
  209.         $author = $dbs->escape_string($_GET['author']);
  210.         $criteria .= ' AND ma.author_name LIKE \'%'.$author.'%\'';
  211.     }
  212.     if (isset($_GET['publish_year']) AND !empty($_GET['publish_year'])) {
  213.         $publish_year = $dbs->escape_string($_GET['publish_year']);
  214.         $criteria .= ' AND bsub.publish_year LIKE \'%'.$publish_year.'%\'';
  215.     }
  216.     if (isset($_GET['class']) AND !empty($_GET['class'])) {
  217.         $class = $dbs->escape_string($_GET['class']);
  218.         $criteria .= ' AND bsub.classification LIKE \''.$class.'%\'';
  219.     }
  220.     if (isset($_GET['gmd']) AND !empty($_GET['gmd'])) {
  221.         $gmd_IDs = '';
  222.         foreach ($_GET['gmd'] as $id) {
  223.             $id = (integer)$id;
  224.             if ($id) {
  225.                 $gmd_IDs .= "$id,";
  226.             }
  227.         }
  228.         $gmd_IDs = substr_replace($gmd_IDs, '', -1);
  229.         if ($gmd_IDs) {
  230.             $outer_criteria .= " AND b.gmd_id IN($gmd_IDs)";
  231.         }
  232.     }
  233.     if (isset($_GET['collType'])) {
  234.         $coll_type_IDs = '';
  235.         foreach ($_GET['collType'] as $id) {
  236.             $id = (integer)$id;
  237.             if ($id) {
  238.                 $coll_type_IDs .= "$id,";
  239.             }
  240.         }
  241.         $coll_type_IDs = substr_replace($coll_type_IDs, '', -1);
  242.         if ($coll_type_IDs) {
  243.             $outer_criteria .= " AND i.coll_type_id IN($coll_type_IDs)";
  244.         }
  245.     }
  246.     if (isset($_GET['language']) AND !empty($_GET['language'])) {
  247.         $language = $dbs->escape_string(trim($_GET['language']));
  248.         $criteria .= ' AND bsub.language_id=\''.$language.'\'';
  249.     }
  250.     if (isset($_GET['location']) AND !empty($_GET['location'])) {
  251.         $location = $dbs->escape_string(trim($_GET['location']));
  252.         $outer_criteria .= ' AND i.location_id=\''.$location.'\'';
  253.     }
  254.     if (isset($_GET['source']) AND !empty($_GET['source'])) {
  255.         $source_options = $dbs->escape_string(trim($_GET['source']));
  256.         $criteria .= ' AND i.source=\''.$source_options.'\'';
  257.     }
  258.     if (isset($_GET['recsEachPage'])) {
  259.         $recsEachPage = (integer)$_GET['recsEachPage'];
  260.         $num_recs_show = ($recsEachPage >= 20 && $recsEachPage <= 200)?$recsEachPage:$num_recs_show;
  261.     }
  262.  
  263.     // subquery/view string
  264.     $subquery_str = '(SELECT DISTINCT bsub.*
  265.        FROM biblio AS bsub
  266.        LEFT JOIN biblio_author AS ba ON bsub.biblio_id = ba.biblio_id
  267.        LEFT JOIN mst_author AS ma ON ba.author_id = ma.author_id
  268.        LEFT JOIN biblio_topic AS bt ON bsub.biblio_id = bt.biblio_id
  269.        LEFT JOIN mst_topic AS mt ON bt.topic_id = mt.topic_id WHERE '.$criteria.')';
  270.  
  271.     // table spec
  272.     $table_spec = $subquery_str.' AS b
  273.        LEFT JOIN item AS i ON b.biblio_id=i.biblio_id
  274.         LEFT JOIN mst_coll_type AS ct ON i.coll_type_id=ct.coll_type_id
  275.         LEFT JOIN mst_place AS pl ON b.publish_place_id=pl.place_id
  276.        LEFT JOIN biblio_author ba ON ba.biblio_id=b.biblio_id
  277.        LEFT JOIN mst_author ma ON ma.author_id=ba.author_id
  278.         LEFT JOIN mst_publisher AS pb ON b.publisher_id=pb.publisher_id
  279.        LEFT JOIN mst_gmd mg ON mg.gmd_id=b.gmd_id';
  280.  
  281.     // set group by
  282.     $reportgrid->sql_group_by = 'b.biblio_id';
  283.     $reportgrid->setSQLCriteria($outer_criteria);
  284.  
  285.     // callback function to show title and authors
  286.     function showTitleAuthors($obj_db, $array_data){
  287.         // author name query
  288.         $_biblio_author = $obj_db->query('SELECT author_name FROM mst_author ma
  289.            LEFT JOIN biblio_author ba ON ba.author_id=ma.author_id
  290.            LEFT JOIN biblio b ON b.biblio_id=ba.biblio_id
  291.            WHERE b.biblio_id='.$array_data[3]);
  292.         $_authors = '';
  293.         if($_biblio_author->num_rows > 0){
  294.             while ($_author_name = $_biblio_author->fetch_row()) {
  295.                 $_authors .= ' - '.$_author_name[0].', ';
  296.             }
  297.         }
  298.         $_authors = substr_replace($_authors, '', -2);
  299.         $_output = '<i>'.$_authors.'</i>'."\n";
  300.         return $_output;
  301.     }
  302.     // modify column value
  303.     $reportgrid->modifyColumnContent(3, 'callback{showTitleAuthors}');
  304.  
  305.     // put the result into variables
  306.     echo $reportgrid->createDataGrid($dbs, $table_spec, $num_recs_show);
  307.  
  308.     echo '<script type="text/javascript">'."\n";
  309.     echo 'parent.$(\'#pagingBox\').html(\''.str_replace(array("\n", "\r", "\t"), '', $reportgrid->paging_set).'\');'."\n";
  310.     echo '</script>';
  311.  
  312.     $xlsquery = 'SELECT b.biblio_id, b.input_date, b.title AS \''.__('Title').'\''.
  313.         ', COUNT(item_id) AS \''.__('Copies').'\''.
  314.         ', GROUP_CONCAT(DISTINCT ma.author_name SEPARATOR \' - \') AS \''.__('Author').'\''.
  315.         ', b.edition AS \''.__('Edition').'\''.
  316.         ', b.publish_year AS \''.__('Year').'\''.
  317.         ', pb.publisher_name AS \''.__('Publisher').'\''.
  318.         ', pl.place_name AS \''.__('Publishing Place').'\''.
  319.         ', b.language_id AS \''.__('Language').'\''.
  320.         ', b.collation AS \''.__('Collation').'\''.
  321.         ', i.price AS \''.__('Price').'\''.
  322.         ', i.source AS \''.__('Source').'\''.
  323.         ', ct.coll_type_name AS \''.__('Collection Type').'\''.
  324.         ',  b.isbn_issn AS \''.__('ISBN/ISSN').'\', b.call_number AS \''.__('Call Number').'\' FROM '.
  325.         $table_spec . ' WHERE '. $outer_criteria . ' group by b.biblio_id';
  326.         // echo $xlsquery;
  327.         unset($_SESSION['xlsdata']);
  328.         $_SESSION['xlsquery'] = $xlsquery;
  329.         $_SESSION['tblout'] = "buku_induk_perpustakaan";
  330.  
  331.     echo '<p><a href="../xlsoutput.php" class="button">'.__('Export to spreadsheet format').'</a></p>';
  332.  
  333.     $content = ob_get_clean();
  334.     // include the page template
  335.     require SB.'/admin/'.$sysconf['admin_template']['dir'].'/printed_page_tpl.php';
  336. }
  337. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement