Here is the Hymnal class. It may run out to the right a bit.
<?php
/*
##################################################
#
# Filename..........: $RCSfile: Hymnal.php,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 __construct($file='the_united_methodist_hymnal-1989') {
global $_SERVER;
global $_SESSION;
global $_REQUEST;
global $_POST;
global $_GET;
return $this->setHymnal($file);
}
function __destruct()
{
}
/*
* 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.php');
$t = new Table();
$t->add_headers(array('#', 'Title', 'Scripture'));
foreach ( $this->hymnal->xpath('//hymns/hymn') as $hymn) {
$t->add_cell( $hymn->number );
if ( $hymn->lyrics != '' ) {
$title_string = '<a href="?hymnal='.$this->file.'&number='.$hymn->number.'">'.$hymn->title.'*</a>';
} else {
$title_string = '<a href="?hymnal='.$this->file.'&number='.$hymn->number.'">'.$hymn->title.'</a>';
}
$t->add_cell( $title_string );
$scripture = '';
foreach ( explode(';',$hymn->scripture) as $s ) {
$scripture .= '<a href="../bible/?verse='.urlencode($s).'">'.$s.'</a><br />';
}
$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 = "";
$result .= "<div>n";
if ( $hymn->number != '' ) {
$result .= '<span class="float-left"><b>' . $hymn->number . "</b></span>n";
}
if ( $hymn->title != '' ) {
$result .= '<p class="center-text"><b>' . $hymn->title ."</b></p>n";
}
if ( $hymn->lyrics != '' ) { $result .= "<pre>". $hymn->lyrics ."</pre>n"; }
$result .= "<p>n";
if ( $hymn->author != '' ) { $result .= "<b>WORDS:</b> ". str_replace( ';','; ',$hymn->author) ."<br />n"; }
if ( $hymn->composer != '' ) { $result .= "<b>MUSIC:</b> ". str_replace( ';','; ',$hymn->composer) ."<br />n"; }
if ( $hymn->tune != '' ) { $result .= "<b>TUNE:</b> ". $hymn->tune ."<br />n"; }
if ( $hymn->scripture != '' ) {
$result .= "<b>Scripture:</b> ";
foreach ( explode(';',$hymn->scripture) as $s ) {
$result .= '<a href="../bible/?verse='.urlencode($s).'">'.$s.'</a> ';
}
$result .= "<br /> ";
}
if ( $hymn->topic != '' ) { $result .= "<b>Topic:</b> ". str_replace(';','; ',$hymn->topic) ."<br />n"; }
if ( $hymn->tags != '' ) { $result .= "<b>Tags:</b> ". str_replace(';','; ',$hymn->tags) ."<br />n"; }
if ( $hymn->theme != '' ) { $result .= "<b>Theme:</b> ". str_replace(';','; ',$hymn->theme) ."<br />n"; }
$result .= "</p>n";
$result .= "</div>n";
return($result);
}
}
?>