page = new Page(); $this->page->title = "Anthem Library"; $this->page->description = "This is the anthem library."; $this->data = new Data("anthem"); } function generate_alpha_links($current_link) { $alpha = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); $result = '

['."\n"; foreach ( $alpha as $letter ) { if ( $letter == $current_link ) { $result .= strtoupper($letter)." \n"; } else { $result .= ''.strtoupper($letter)." \n"; } } $result .= ']

'."\n"; return($result); } function generate_anthem_table($anthems) { $result = "\n"; $result .= " \n"; $result .= " \n"; $result .= " \n"; $result .= " \n"; $result .= " \n"; $count = 1; while ( list($key,$val) = each($anthems) ) { if ( ($count) % 2 == 0 ) { $result .= " \n"; } else { $result .= " \n"; } $result .= ' \n"; $result .= ' \n"; $result .= ' \n"; $result .= " \n"; $count++; } $result .= "
TitleComposerAuthor
' . $val['title'] . "' . $val['composer'] . "' . $val['author'] . "
\n"; return($result); } /* * This method lists all the anthems with a given starting character in the title */ function print_anthems() { if ( !empty($_GET['search']) ) { $search = $_GET['search']; if ( !empty($_GET['type']) && $_GET['type'] == 'author' ) { $sql = 'SELECT * FROM anthem WHERE author LIKE "%'.$search.'%" ORDER BY title'; $achecked = 'checked'; } elseif ( !empty($_GET['type']) && $_GET['type'] == 'composer' ) { $sql = 'SELECT * FROM anthem WHERE composer LIKE "%'.$search.'%" ORDER BY title'; $cchecked = 'checked'; } else { $sql = 'SELECT * FROM anthem WHERE lyrics LIKE "%'.$search.'%" OR title LIKE "%'.$search.'%" ORDER BY title'; $tchecked = 'checked'; } } elseif ( !empty($_GET['alpha']) ) { $alpha = $_GET['alpha']; $sql = 'SELECT * FROM anthem WHERE title LIKE "'.$alpha.'%" ORDER BY title'; $tchecked = 'checked'; } else { $alpha = 'a'; $sql = 'SELECT * FROM anthem WHERE title LIKE "'.$alpha.'%" ORDER BY title'; $tchecked = 'checked'; } $anthems = $this->data->return_array($sql); $anthem_count = $this->data->count_records(); $this->page->content .= "

\n"; $this->page->content .= '

Here are '.count($anthems).' of '.$anthem_count.' anthems.
'."\n"; $this->page->content .= '
'; $this->page->content .= ''; $this->page->content .= '
'; $this->page->content .= ' Title and Lyrics '; $this->page->content .= ' Composer '; $this->page->content .= ' Author'; $this->page->content .= '
'."\n"; $this->page->content .= "

\n"; if ( $_SESSION['login'] ) { $this->page->content .= "

\n"; $this->page->content .= "Add an anthem\n"; $this->page->content .= "

\n"; } $this->page->content .= $this->generate_alpha_links($alpha); $this->page->content .= $this->generate_anthem_table($anthems); $this->page->content .= $this->generate_alpha_links($alpha); $this->page->display(); } function print_anthem() { $anthem = $this->data->get_record_by_id($_GET['id']); $this->page->title = $anthem['title']; $this->page->description = $anthem['title']; $this->page->content .= "

\n"; if ( !empty($anthem['composer']) ) { $this->page->content .= 'Composer: ' . $anthem['composer'] . "
\n"; } if ( !empty($anthem['author']) ) { $this->page->content .= 'Author: ' . $anthem['author'] . "
\n"; } if ( !empty($anthem['arranger']) ) { $this->page->content .= 'Arranger: ' . $anthem['arranger'] . "
\n"; } if ( !empty($anthem['publisher']) ) { $this->page->content .= 'Publisher: ' . $anthem['publisher'] . "
\n"; } if ( !empty($anthem['scripture']) ) { $this->page->content .= 'Scripture Allusion: ' . $anthem['scripture'] . "
\n"; } if ( !empty($anthem['voicing']) ) { $this->page->content .= 'Voicing: ' . $anthem['voicing'] . "
\n"; } if ( !empty($anthem['pages']) ) { $this->page->content .= 'Pages: ' . $anthem['pages'] . "
\n"; } if ( !empty($anthem['length']) ) { $this->page->content .= 'Length: ' . $anthem['length'] . "
\n"; } if ( !empty($anthem['copies']) ) { $this->page->content .= 'Copies: ' . $anthem['copies'] . "
\n"; } if ( !empty($anthem['publish_date']) ) { $this->page->content .= 'Publish Date: ' . $anthem['publish_date'] . "
\n"; } if ( !empty($anthem['purchase_date']) ) { $this->page->content .= 'Purchase Date: ' . $anthem['purchase_date'] . "
\n"; } if ( !empty($anthem['lyrics']) ) { $this->page->content .= "

\n"; $this->page->content .= "

Lyrics

\n"; $this->page->content .= "

\n"; $this->page->content .= nl2br($anthem['lyrics']) . "
\n"; $this->page->content .= "

\n"; } if ( !empty($anthem['notes']) ) { $this->page->content .= "

Notes

\n"; $this->page->content .= "

\n"; $this->page->content .= nl2br($anthem['notes']) . "
\n"; $this->page->content .= "

\n"; } if ( $_SESSION['login'] ) { $this->page->content .= "

\n"; $this->page->content .= "[Edit this anthem]\n"; $this->page->content .= "[Delete this anthem]\n"; $this->page->content .= "

\n"; } $this->page->display(); } /* * This method prints the add/edit confirmation form */ function print_anthem_form() { if ( $anthem['action'] == 'add' || $_GET['action'] == 'add' ) { $action = 'add'; } elseif ( $anthem['action'] == 'edit' || $_GET['action'] == 'edit' ) { list( $anthem['inId'], $anthem['inAccount'], $anthem['inTitle'], $anthem['inComposer'], $anthem['inAuthor'], $anthem['inArranger'], $anthem['inPublisher'], $anthem['inScripture'], $anthem['inVoicing'], $anthem['inPages'], $anthem['inLength'], $anthem['inCopies'], $anthem['inPublish_date'], $anthem['inPurchase_date'], $anthem['inLyrics'], $anthem['inNotes'] ) = array_values($this->data->get_record_by_id($_GET['id'])); $action = 'edit'; } else { redirect('./'.$_POST['backto']); } $this->page->title = ucwords($action) . " Anthem"; $this->page->description = ucwords($action) . "ing Anthem."; if (!$_SESSION['login'] ) { redirect($anthem['inId']); } if (!$anthem['inAccount']) { $anthem['inAccount'] = $_SESSION['login']; } if ($this->error_string) { $this->page->content .= "

" . $this->error_string . "

\n"; } require_once('Form.class'); $form = new Form('index.php','post'); $form->hidden('action',$action); $form->hidden('inId',$anthem['inId']); $form->hidden('inAccount',$anthem['inAccount']); $form->text('Title','inTitle',$anthem['inTitle'],60,200); $form->text('Composer','inComposer',$anthem['inComposer'],60,200); $form->text('Author','inAuthor',$anthem['inAuthor'],60,200); $form->text('Arranger','inArranger',$anthem['inArranger'],60,200); $form->text('Publisher','inPublisher',$anthem['inPublisher'],60,200); $form->text('Scripture','inScripture',$anthem['inScripture'],60,200); $form->text('Voicing','inVoicing',$anthem['inVoicing'],60,200); $form->text('Length in Pages','inPages',$anthem['inPages'],60,6); $form->text('Length in Seconds','inLength',$anthem['inLength'],60,6); $form->text('Copies','inCopies',$anthem['inCopies'],60,6); $form->text('Published Date','inPublish_date',$anthem['inPublish_date'],60,32); $form->text('Purchase Date','inPurchase_date',$anthem['inPurchase_date'],60,32); $form->textarea('Lyrics','inLyrics',$anthem['inLyrics'],10,80); $form->textarea('Notes','inNotes',$anthem['inNotes'],10,80); $form->submit('submit',ucwords($action)); $form->submit('submit','Cancel'); $this->page->content .= $form->render(); $this->page->display(); } /* * This method prints a delete confirmation form */ function print_anthem_delete_confirmation($id) { $anthem = $this->data->get_record_by_id($id); $this->page->title = "Delete Anthem"; $this->page->description = "Anthem deletion confirmation"; $this->page->content .= "

\n"; $this->page->content .= "Warning! You are about to delete the anthem entitled:

\n"; $this->page->content .= "\"" . $anthem['title'] . "\"

\n"; $this->page->content .= "Click 'Delete' again if you are sure.\n"; $this->page->content .= "

\n"; require_once('Form.class'); $form = new Form('index.php','post'); $form->hidden('action','delete'); $form->hidden('inId',$anthem['id']); $form->submit('submit','Delete'); $form->submit('submit','Cancel'); $this->page->content .= $form->render(); $this->page->display(); } /* * This is the method that processing POST/GET events for this object. */ function run() { if ( $_SERVER["REQUEST_METHOD"] == 'POST' ) { if ( ! $_SESSION['login'] ) { redirect($_POST['inId']); } if ( $_POST['submit'] == 'Cancel' ) { redirect('./'.$_POST['backto']); } if ( $_POST['action'] == 'add' || $_POST['action'] == 'edit' ) { if ( $_POST['inAccount'] && $_POST['inTitle'] ) { $this->data->set_attribute('id', $_POST['inId']); $this->data->set_attribute('account', $_POST['inAccount']); $this->data->set_attribute('title', $_POST['inTitle']); $this->data->set_attribute('composer', $_POST['inComposer']); $this->data->set_attribute('author', $_POST['inAuthor']); $this->data->set_attribute('arranger', $_POST['inArranger']); $this->data->set_attribute('publisher', $_POST['inPublisher']); $this->data->set_attribute('scripture', $_POST['inScripture']); $this->data->set_attribute('voicing', $_POST['inVoicing']); $this->data->set_attribute('pages', $_POST['inPages']); $this->data->set_attribute('length', $_POST['inLength']); $this->data->set_attribute('copies', $_POST['inCopies']); $this->data->set_attribute('publish_date', $_POST['inPublish_date']); $this->data->set_attribute('purchase_date', $_POST['inPurchase_date']); $this->data->set_attribute('lyrics', $_POST['inLyrics']); $this->data->set_attribute('notes', $_POST['inNotes']); if ( $this->data->save() ) { $url = ''; if ( !empty($_POST['inId']) ) { $url = '?id='.$_POST['inId']; } else { $url = '?alpha='.strtolower($_POST['inTitle'][0]); } redirect("./index.php".$url); } else { $this->page->title = "An Error Occurred!"; $this->page->title = "An error occurred when trying to save a comment."; $this->page->content = "Unable to save anthem!"; $this->page->display(); } } else { $this->error_string = "You must provide input for each field!\n"; $this->print_anthem_form($_POST); } } elseif ( $_POST['action'] == 'delete' ) { if ( $this->data->delete_record_by_id($_POST['inId']) ) { redirect('./'); } else { $this->page->title = "An Error Occurred!"; $this->page->title = "An error occurred when trying to delete an anthem."; $this->page->content = "Unable to delete anthem!"; $this->page->display(); } } } elseif ( $_GET['action'] == 'add' && $_SESSION['login'] ) { $this->print_anthem_form(); } elseif ( $_GET['action'] == 'edit' && $_SESSION['login'] && isset($_GET['id']) ) { $this->print_anthem_form(); } elseif ( $_GET['action'] == 'delete' && $_SESSION['login'] && isset($_GET['id']) ) { $this->print_anthem_delete_confirmation($_GET['id']); } elseif ( isset($_GET['id']) ) { $this->print_anthem(); } else { $this->print_anthems($_GET['alpha']); } } } ?>