Location: PHPKode > projects > SENAYAN Library Automation > senayan3-stable5/admin/modules/reporting/member_report.php


    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
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


/* Reporting section */

// start the session

require '../../../sysconfig.inc.php';
require SIMBIO_BASE_DIR.'simbio_GUI/table/simbio_table.inc.php';

// privileges checking
$can_read = utility::havePrivilege('reporting', 'r');
$can_write = utility::havePrivilege('reporting', 'w');

if (!$can_read) {
    die('<div class="errorBox">'.lang_sys_common_no_privilage.'</div>');

/* loan report */
$table = new simbio_table();
$table->table_attr = 'align="center" class="border" cellpadding="5" cellspacing="0"';

// total number of member
$report_query = $dbs->query('SELECT COUNT(member_id) FROM member');
$report_data = $report_query->fetch_row();
$loan_report[lang_mod_report_member_field_registered] = $report_data[0];

// total number of active member
$report_query = $dbs->query('SELECT COUNT(member_id) FROM member
    WHERE TO_DAYS(expire_date)>TO_DAYS(\''.date('Y-m-d').'\')');
$report_data = $report_query->fetch_row();
$loan_report[lang_mod_report_member_field_active] = $report_data[0];

// total number of active member by membership type
$report_query = $dbs->query('SELECT member_type_name, COUNT(member_id) FROM mst_member_type AS mt
    LEFT JOIN member AS m ON mt.member_type_id=m.member_type_id
    WHERE TO_DAYS(expire_date)>TO_DAYS(\''.date('Y-m-d').'\')
    GROUP BY m.member_type_id ORDER BY COUNT(member_id) DESC');
$report_data = '';
while ($data = $report_query->fetch_row()) {
    $report_data .= '<strong>'.$data[0].'</strong> : '.$data[1].', ';
$loan_report[lang_mod_report_member_field_by_type] = $report_data;

// total expired member
$report_query = $dbs->query('SELECT COUNT(member_id) FROM member
    WHERE TO_DAYS(\''.date('Y-m-d').'\')>TO_DAYS(expire_date)');
$report_data = $report_query->fetch_row();
$loan_report[lang_mod_report_member_field_expired] = $report_data[0];

// 10 most active member
$report_query = $dbs->query('SELECT m.member_name, m.member_id, COUNT(loan_id) FROM loan AS l
    INNER JOIN member AS m ON m.member_id=l.member_id
    WHERE TO_DAYS(\''.date('Y-m-d').'\')>TO_DAYS(expire_date)
    GROUP BY l.member_id ORDER BY COUNT(loan_id) DESC LIMIT 10');
$report_data = '<ul>';
while ($data = $report_query->fetch_row()) {
    $report_data .= '<li>'.$data[0].' ('.$data[1].')</li>';
$loan_report[lang_mod_report_member_field_active_topten] = $report_data;

// table header
$table->table_header_attr = 'class="dataListHeader" colspan="3"';
// initial row count
$row = 1;
foreach ($loan_report as $headings=>$report_data) {
    $table->appendTableRow(array($headings, ':', $report_data));
    // set cell attribute
    $table->setCellAttr($row, 0, 'class="alterCell" valign="top" style="width: 170px;"');
    $table->setCellAttr($row, 1, 'class="alterCell" valign="top" style="width: 1%;"');
    $table->setCellAttr($row, 2, 'class="alterCell2" valign="top" style="width: auto;"');
    // add row count

// if we are in print mode
if (isset($_GET['print'])) {
    // html strings
    $html_str = '<html><head><title>'.$sysconf['library_name'].' Membership General Statistic Report</title>';
    $html_str .= '<style type="text/css">'."\n";
    $html_str .= 'body {padding: 0.2cm}'."\n";
    $html_str .= 'body * {color: black; font-size: 11pt;}'."\n";
    $html_str .= 'table {border: 1px solid #000000;}'."\n";
    $html_str .= '.dataListHeader {background-color: #000000; color: white; font-weight: bold;}'."\n";
    $html_str .= '.alterCell {border-bottom: 1px solid #666666; background-color: #CCCCCC;}'."\n";
    $html_str .= '.alterCell2 {border-bottom: 1px solid #666666; background-color: #FFFFFF;}'."\n";
    $html_str .= '</style>'."\n";
    $html_str .= '</head>';
    $html_str .= '<body>'."\n";
    $html_str .= '<h3>'.$sysconf['library_name'].' - '.lang_mod_report_member_page_head.'</h3>';
    $html_str .= '<hr size="1" />'."\n";
    $html_str .= $table->printTable();
    $html_str .= '<script type="text/javascript">self.print();</script>'."\n";
    $html_str .= '</body></html>'."\n";
    // write to file
    $file_write = @file_put_contents(REPORT_FILE_BASE_DIR.'member_stat_print_result.html', $html_str);
    if ($file_write) {
        // open result in new window
        echo '<script type="text/javascript">parent.openWin(\''.SENAYAN_WEB_ROOT_DIR.'/'.FILES_DIR.'/'.REPORT_DIR.'/member_stat_print_result.html\', \'popMemberReport\', 800, 500, true)</script>';
    } else { utility::jsAlert('ERROR! Membership statistic report failed to generate, possibly because '.REPORT_FILE_BASE_DIR.' directory is not writable'); }

<table id="searchForm" cellpadding="5" cellspacing="0">
    <td class="imageLeft" valign="top" style="background-image: url(<?php echo $sysconf['admin_template']['dir'].'/'.$sysconf['admin_template']['theme'].'/statistic.png'; ?>)">
        <?php echo strtoupper(lang_mod_report_member); ?>
        <hr />
        <form name="printForm" action="<?php echo $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; ?>" target="submitPrint" id="printForm" method="get" style="display: inline;">
        <input type="hidden" name="print" value="true" /><input type="submit" value="<?php echo lang_sys_common_form_report; ?>" class="button" />
        <iframe name="submitPrint" style="visibility: hidden; width: 0; height: 0;"></iframe>
echo $table->printTable();
/* loan report end */
Return current item: SENAYAN Library Automation