/*
##################################################
#
# Filename..........: $RCSfile: Hymnal.class,v $
# Original Author...: Anthony L. Awtrey
# Version...........: $Revision: 0.1 $
# Last Modified By..: $Author: aawtrey $
# Last Modified.....: $Date: 2006/09/21 09:34:00 $
#
# Copyright 2006 Anthony Awtrey
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
*/
/*
* This class provides the methods to load and query hymnal of the
* Hymnal stored in XML.
*/
class Hymnal {
var $error;
var $file;
var $hymnal;
/*
* Class initialization
*/
function Hymnal($file='the_hymnbook-1955') {
global $_SERVER;
global $_SESSION;
global $_REQUEST;
global $_POST;
global $_GET;
return $this->setHymnal($file);
}
/*
* Loads a hymnal
*/
function setHymnal($file) {
$this->file = $file;
if ( is_file(constant("RELPATH").'include/hymnals/'.$this->file.'.xml') ) {
$this->hymnal = @simplexml_load_file(constant("RELPATH").'include/hymnals/'.$this->file.'.xml');
return(true);
} else {
$this->hymnal = false;
return(false);
}
}
function getHymnal() {
return($this->file);
}
/*
* Prints the hymns in the hymnal
*/
function print_hymnal() {
require_once('Table.class');
$t = new Table();
$t->add_headers(array('#', 'Title', 'Scripture'));
foreach ( $this->hymnal->xpath('//hymns/hymn') as $hymn) {
$t->add_cell( $hymn->number );
$title_string = ''.$hymn->title.'';
$t->add_cell( $title_string );
$scripture = '';
foreach ( explode('; ',$hymn->scripture) as $s ) {
$scripture .= ''.$s.'
';
}
$t->add_cell( $scripture );
$t->add_row();
}
return( $t->render() );
}
/*
* Prints a hymn from the hymnal
*/
function print_hymn( $number ) {
$hymn = $this->hymnal->xpath('//hymn[number='.$number.']');
$hymn = $hymn[0];
$result = "
\n";
if ( $hymn->number != '' ) { $result .= "Number: ". $hymn->number ."
\n"; }
if ( $hymn->title != '' ) { $result .= "Title: ". $hymn->title ."
\n"; }
if ( $hymn->tune != '' ) { $result .= "Tune: ". $hymn->tune ."
\n"; }
if ( $hymn->composer != '' ) { $result .= "Composer: ". $hymn->composer ."
\n"; }
if ( $hymn->author != '' ) { $result .= "Author: ". $hymn->author ."
\n"; }
if ( $hymn->scripture != '' ) {
$result .= "Scripture: ";
foreach ( explode('; ',$hymn->scripture) as $s ) {
$result .= ''.$s.' ';
}
$result .= "
";
}
if ( $hymn->topic != '' ) { $result .= "Topic: ". $hymn->topic ."
\n"; }
if ( $hymn->tags != '' ) { $result .= "Tags: ". $hymn->tags ."
\n"; }
if ( $hymn->theme != '' ) { $result .= "Theme: ". $hymn->theme ."
\n"; }
$result .= "
". $hymn->lyrics ."\n"; } return($result); } } ?>