Location: PHPKode > projects > SENAYAN Library Automation > senayan3-stable5/lib/detail.inc.php
<?php
/**
 * detail class
 * Class for document/record detail
 *
 * Copyright (C) 2007,2008  Arie Nugraha (hide@address.com)
 *
 * 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; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

require 'content_list.inc.php';

class detail extends content_list
{
    private $obj_db = false;
    private $record_detail = array();
    private $detail_id = 0;
    private $error = false;
    public $record_title;


    /**
     * Class Constructor
     *
     * @param   object  $obj_db
     * @param   integer $int_detail_id
     * @param   boolean $bool_xml_mode
     * @return  void
     */
    public function __construct($obj_db, $int_detail_id, $bool_xml_mode = false)
    {
        // get global configuration vars array
        global $sysconf;

        $this->obj_db = $obj_db;
        $this->detail_id = $int_detail_id;
        $_sql = "SELECT b.*, l.language_name, p.publisher_name, pl.place_name AS 'publish_place', gmd.gmd_name FROM biblio AS b
            LEFT JOIN mst_gmd AS gmd ON b.gmd_id=gmd.gmd_id
            LEFT JOIN mst_language AS l ON b.language_id=l.language_id
            LEFT JOIN mst_publisher AS p ON b.publisher_id=p.publisher_id
            LEFT JOIN mst_place AS pl ON b.publish_place_id=pl.place_id
            WHERE biblio_id=$int_detail_id";
        // for debugging purpose only
        // die($_sql);
        // query the data to database
        $_det_q = $obj_db->query($_sql);
        if ($obj_db->error) {
            $this->error = true;
        } else {
            $this->record_detail = $_det_q->fetch_assoc();
            // get title and set it to public record_title property
            $this->record_title = $this->record_detail['title'];
            // free the memory
            $_det_q->free_result();

            // change all html entities characters
            foreach ($this->record_detail as $idx=>$data) {
                $data = strip_tags($data);
                if ($bool_xml_mode) {
                    $this->record_detail[$idx] = htmlspecialchars($data);
                }
            }

            // check image
            if (!empty($this->record_detail['image'])) {
                $this->record_detail['image'] = '<img src="./lib/phpthumb/phpThumb.php?src=../../images/docs/'.urlencode($this->record_detail['image']).'&w=200" border="0" />';
            } else {
                $this->record_detail['image'] = '<img src="./'.$sysconf['template']['dir'].'/'.$sysconf['template']['theme'].'/image.png" border="0" />';
            }

            // check file attachment
            if (!empty($this->record_detail['file_att']) AND $sysconf['allow_file_download']) {
                $this->record_detail['file_att'] = '<a href="index.php?p=fstream&fid='.$this->record_detail['biblio_id'].'" target="_blank">Download/View File</a>';
            } else {
                $this->record_detail['file_att'] = '<em>'.lang_mod_biblio_field_attachment_nothing.'</em>';
            }

            // get the authors data
            $_biblio_authors_q = $obj_db->query("SELECT author_name FROM mst_author AS a
                LEFT JOIN biblio_author AS ba ON a.author_id=ba.author_id WHERE ba.biblio_id=".$this->detail_id);
            $authors = '';
            while ($data = $_biblio_authors_q->fetch_row()) {
                if ($bool_xml_mode) {
                    $authors .= '<author>'.$data[0].'</author>'."\n";
                } else {
                    $authors .= '<a href="?author='.urlencode('"'.$data[0].'"').'&search=Search" title="'.lang_mod_biblio_link_author_search.'">'.$data[0]."</a><br />";
                }
            }
            $this->record_detail['authors'] = $authors;
            // free memory
            $_biblio_authors_q->free_result();

            // get the topics data
            $_biblio_topics_q = $obj_db->query("SELECT topic FROM mst_topic AS a
                LEFT JOIN biblio_topic AS ba ON a.topic_id=ba.topic_id WHERE ba.biblio_id=".$this->detail_id);
            $topics = '';
            while ($data = $_biblio_topics_q->fetch_row()) {
                if ($bool_xml_mode) {
                    $topics .= '<subject>'.$data[0].'</subject>'."\n";
                } else {
                    $topics .= '<a href="?subject='.urlencode('"'.$data[0].'"').'&search=Search" title="'.lang_mod_biblio_link_topic_search.'">'.$data[0]."</a><br />";
                }
            }
            $this->record_detail['subjects'] = $topics;
            // free memory
            $_biblio_topics_q->free_result();

            // get the availability status
            /*
            // count how many copy this record have
            $_copy_q = $obj_db->query("SELECT COUNT(item_code) FROM item AS i
                WHERE i.biblio_id=".$this->detail_id);
            $_copy_d = $_copy_q->fetch_row();
            $_copy_loan_q = $obj_db->query("SELECT COUNT(l.item_code) FROM loan AS l
                INNER JOIN item AS i ON l.item_code=i.item_code
                WHERE l.is_lent=1 AND l.is_return=0 AND i.biblio_id=".$this->detail_id);
            $_copy_loan_d = $_copy_loan_q->fetch_row();
            $_is_avail = $_copy_d[0]-$_copy_loan_d[0];
            if ($_copy_d[0] < 1) {
                $this->record_detail['availability'] = '<strong style="color: red; font-weight: bold;">'.lang_mod_biblio_field_no_item.'</strong>';
            } else if ($_is_avail < 1) {
                $msg = str_replace('{copy}', $_copy_d[0], lang_mod_biblio_item_common_opac_status_1);
                $this->record_detail['availability'] = '<strong style="color: red; font-weight: bold;">'.$msg.'</strong>';
            } else {
                $msg = str_replace('{copy}', $_copy_d[0], lang_mod_biblio_item_common_opac_status_2);
                $this->record_detail['availability'] = $msg.' : <br />';
                $this->record_detail['availability'] .= '<strong>'.$_is_avail.'</strong> '. lang_mod_biblio_item_common_opac_status_3. ' <br />';
                $this->record_detail['availability'] .= '<strong style="color: red; font-weight: bold;">'.$_copy_loan_d[0].'</strong> '.lang_mod_biblio_item_common_opac_status_4.' <br />';
            }
            */
            $this->record_detail['availability'] = '<div id="listLoad">LOADING LIST...</div>'."\n";
            $this->record_detail['availability'] .= '<script type="text/javascript">new Ajax.Updater(\'listLoad\', \''.SENAYAN_WEB_ROOT_DIR.'lib/contents/item_list.inc.php\', {method: \'post\', parameters: \'id='.$this->detail_id.'\'});</script>';

            // get location data
            $_item_loc_q = $obj_db->query("SELECT loc.location_name, COUNT(i.location_id) AS item_num FROM item AS i
                LEFT JOIN mst_location AS loc ON i.location_id=loc.location_id
                WHERE i.biblio_id=".$this->detail_id." GROUP BY i.location_id");
            if ($_item_loc_q->num_rows < 1) {
                if ($bool_xml_mode) {
                    $this->record_detail['location'] = lang_mod_biblio_field_no_item;
                } else {
                    $this->record_detail['location'] = '<strong style="color: red; font-weight: bold;">'.lang_mod_biblio_field_no_item.'</strong>';
                }
            } else {
                $this->record_detail['location'] = '';
                while ($_item_loc_d = $_item_loc_q->fetch_row()) {
                    if ($bool_xml_mode) {
                        $this->record_detail['location'] .= '<location>'.$_item_loc_d[1].' '.lang_mod_biblio_item_common_location_status_1.' '.$_item_loc_d[0].'</location>';
                    } else {
                        $this->record_detail['location'] .= '<strong>'.$_item_loc_d[1].' </strong> '.lang_mod_biblio_item_common_location_status_1.' <strong>'.$_item_loc_d[0].'</strong><br />';
                    }
                }
            }
        }
    }


    /**
     * Method to print out the document detail based on template
     *
     * @return  void
     */
    public function showDetail()
    {
        if ($this->error) {
            return '<div style="padding: 5px; margin: 3px; border: 1px dotted #FF0000; color: #FF0000;">Error Fetching data for record detail</div>';
        } else if (!empty($this->list_template)) {
            return parent::parseListTemplate($this->record_detail);
        } else {
            return null;
        }
    }
}
?>
Return current item: SENAYAN Library Automation