Location: PHPKode > projects > LySite > lysite/songs.php
<?php
/*----------------------------------------------------------

       LySite
       Brad Landis (hide@address.com)

   Copyright (C) 2005 Brad Landis

   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("includes.php");

function show_comments() {
	return $_COOKIE['show_comments']=="1";
}
ob_start();

if(isset($_GET['show_comments'])) {
	if($_GET['show_comments'] == "no") {
		setcookie("show_comments",false,time()-300);
	} else {
		setcookie("show_comments","1",time()+15768000);
	}
	header("Location: songs.php?song=$_GET[song]");
}

if($_GET['author']) {
	$query = "SELECT approved,lid,title,author FROM lyrics WHERE author='$_GET[author]' ".(!is_admin_user()?"AND (approved='y' OR user_id='".get_user_id()."') ":"")."ORDER BY title";
	if($results = mysql_query($query)) {
		echo "<div id='list'>\n<h2>Songs by Author '$_GET[author]'</h2>\n";
		while($line = mysql_fetch_assoc($results)) {
			echo "<a href='songs.php?song=$line[lid]'>$line[title]</a><br>\n";
		}
		echo "</div>\n";
	} else {
		trigger_error(mysql_error());
	}
} else if($_GET['song']) {
	$query = "SELECT lyrics.* FROM lyrics WHERE lid='".$_GET['song']."' LIMIT 1";
	if($result = mysql_query($query)) {
		if(mysql_num_rows($result) > 0) {
			$line = mysql_fetch_assoc($result);
			$subtitle = $line['title'];
			
			echo "<div class='song".($line['approved'] == 'n'?" usong":"")."'>\n";
			echo "<div class='title'>$line[title]</div>\n".($line['author']?"<div class=\"author\">$line[author]</div>\n\n":"");
			
			echo "<div class=\"text\">" . nl2br($line['text']) . "</div>\n";
			echo submitted_by($line['user_id']);
			
			echo "<div class='copyright'>".($line['copyright'] != ''?"&copy; ".$line['copyright']:"&copy Unknown")."</div>\n";
			echo "</div>\n";
			
			if(is_admin_user()) {
				$iconlist[] = "<form action='edit.php' method='post'><input type='hidden' name='id' value='$_GET[song]'>\n"
					.($line['approved'] != 'y'?"<button type='submit' name='approve' title='Approve This Song'><img src='icon/song_approve.jpg'><span>Approve Lyrics</span></button>\n":"")
					."<button type='submit' name='edit' title='Edit This Song'><img src='icon/song_edit.jpg'><span>Edit Lyrics</span></button>\n"
					."<button type='submit' name='delete' value='del' title='Delete This Song'><img src='icon/song_delete.jpg'><span>Delete Lyrics</span></button>\n"
					."</form>\n";
			}
			if(OPT_FAVORITES && is_logged_in() && $line['approved'] == 'y') {
				$query = "SELECT * FROM favs WHERE lid='$line[lid]' AND user_id='".get_user_id()."' LIMIT 1";
				if($results = mysql_query($query)) {
					if(mysql_num_rows($results) == 0) {
						$iconlist[] = "||<form action='favs.php' method='post'><input type='hidden' name='addtofavs' value='$line[lid]'><button type='submit' title='Add This Song To My Favorites'><img src='icon/favorites_add.jpg'><span>Add to Favorites</span></button></form>\n";
					} else {
						$iconlist[] = "||<form action='favs.php' method='post'><input type='hidden' name='delete' value='$line[lid]'><button type='submit' title='Delete This Song From Favorites'><img src='icon/favorites_delete.jpg'><span>Remove from Favorites</span></button></form>\n";
					}
				} else trigger_error(mysql_error());
				//$iconlist[] = "||<form action='categories.php'><button type='submit' title='Add Category to This Song' name='song' value='$line[lid]'><img src='icon/cat_add.jpg'><span>Add Category</span></a></button></form>\n<form action='attachments.php'><input type='hidden' name='upload'><button name='song' value='$line[lid]' type='submit' title='Add Attachment to This Song'><img src='icon/attachment_add.jpg'><span>Add Attachment</span></button></form>\n<form action='albums.php'><button name='song' value='$line[lid]' type='submit' title='Add Album to This Song'><img src='icon/album_add.jpg'><span>Add Album</span></button></form>\n<form action='comments.php'><input type='hidden' name='post'><button type='submit' name='song' value='$line[lid]' title='Add Comment to This Song'><img src='icon/comment_add.jpg'><span>Add Comment</span></button></form>";
			}
			$iconlist[] = "||<form action='print_song.php'><input type='hidden' name='song' value='$_GET[song]'><button type='submit' title='Print Song'><img src='icon/song_print.jpg'><span>Print</span></button></form>";
			
			echo "<table cellspacing='0' class='songinfo noprint'>\n";
			if(OPT_CATEGORIES == true) {
				$query = "SELECT * FROM category_names,category_link WHERE category_link.lid='$_GET[song]' AND category_names.cat_names_id=category_link.cat_names_id".(!is_admin_user()?" AND category_names.approved='y'":"")." ORDER BY cat_name";
				if($results = mysql_query($query)) {
					echo "<tr><td valign='top'>\n<h2>Categories".(can_post()?" <a href='categories.php?song=$_GET[song]' title='Add Category'><img src='icon/small_add.jpg'></a>".(is_admin_user()?"<a href='categories.php?delete_cats=&lid=$line[lid]' title='Remove Categories'><img src='icon/small_edit.jpg'></a>":""):"")."</h2>\n";
					if(mysql_num_rows($results) > 0) {
						while($cats = mysql_fetch_assoc($results)) {
							echo "<a href='categories.php?cat_names_id=$cats[cat_names_id]'".($cats['approved'] != 'y'?" class='unapproved'":"").">$cats[cat_name]</a><br>\n";
						}
					} else {
						echo "None\n";
					}
				} else trigger_error(mysql_error());
			}
			
			if(OPT_ATTACHMENTS == true) {
				$query = "SELECT * FROM attachments WHERE lid='$_GET[song]'".(is_admin_user()?"":" AND (approved='y' OR user_id='".get_user_id()."')");
				if($results = mysql_query($query)) {
					echo "<td valign='top'>\n<h2>Attachments".(can_post()?" <a href='attachments.php?upload=&song=$_GET[song]' title='Add Attachment'><img src='icon/small_add.jpg'></a>":"")."</h2>\n";
					if(mysql_num_rows($results) > 0) {
						while($line = mysql_fetch_assoc($results)) {
							echo "<a href='attachments.php?attachment_id=$line[attachment_id]'".($line['approved'] != 'y'?" class='unapproved'":"").">".($line['filename']?"$line[filename]":url_shorten("$line[url]"))."</a><br>\n";
						}
					} else {
						echo "None";
					}
				} else trigger_error(mysql_error());
			}
			
			if(OPT_ALBUMS == true) {
				$query = "SELECT albums.*,track_num,tid FROM albums,album_tracks WHERE lid='$_GET[song]' AND albums.aid=album_tracks.aid".(!is_admin_user()?" AND (approved='y' OR albums.user_id='".get_user_id()."')":"")." ORDER BY album_title";
				if($results = mysql_query($query)) {
					echo "<tr><td colspan='2'>\n<h2>Albums".(can_post()?" <a href='albums.php?song=$_GET[song]' title='Add Album'><img src='icon/small_add.jpg'></a>":"")."</h2>\n";
					if(mysql_num_rows($results) > 0) {
						echo "<table id='album'>\n";
						while($album = mysql_fetch_assoc($results)) {
							echo "<tr".($album['approved'] != 'y'?" class='unapproved'":"")."><td style='text-align:right;'><img src='album_art/".($album['album_art']?$album['album_art']:'empty.gif')."' class='album_art'><td><a href='albums.php?album=$album[aid]'>$album[album_title]</a><br>$album[album_artist]<br><span>Track #: $album[track_num]</span>\n";
						}
						echo "</table>\n";
					} else {
						echo "None";
					}
				} else {
					trigger_error(mysql_error());
				}
			}
			
			if(OPT_COMMENTS == true) {
				$query = "SELECT * FROM comments WHERE lid='$_GET[song]' ".(is_admin_user()?"":"AND reported_by IS NULL ")."ORDER BY date DESC";
				echo "<tr><td colspan='2'>\n<h2><a href='comments.php?song=$_GET[song]'>Comments</a>".(can_post()?" <a href='comments.php?post=&song=$_GET[song]' title='Add Comment'><img src='icon/small_add.jpg'></a>":"")."</h2>\n";
				if(show_comments()) {
					if($results = mysql_query($query)) {
							if(mysql_num_rows($results) > 0) {
								while($line = mysql_fetch_assoc($results)) {
									echo "<div class='comment'".($line['reported_by'] != NULL?" style='background: #dbb;'":"")."><div style='float:right;'>".($line['reported_by']!=NULL && is_admin_user() ?"<a href='comments.php?comment_id=$line[comment_id]&song=$_GET[song]&report=unreport'>Unreport</a>":"<a href='comments.php?comment_id=$line[comment_id]&song=$_GET[song]&report=' title='If this post has offensive comments, please report it.'>Report</a>")."</div>".get_user_fullname($line['user_id'])." (".date("M-j-Y g:i",strtotime($line['date'])).")\n";
									echo "<div class='comment_body'>".nl2br($line['comment'])."</div>";
									echo "</div>\n";
								}
							} else {
								echo "None";
							}
					} else {
						trigger_error(mysql_error());
					}
				} else {
					echo "<p>Comments are hidden. Would you like to show comments?<p>\n<a href='songs.php?song=$_GET[song]&show_comments=yes'>Yes</a>\n";
				}
			}
			echo "</table>\n";
		} else {
			notice("No song found");
		}
	} else {
		trigger_error(mysql_error());
	}
} else {
	$query = "SELECT approved, lid, title, author FROM lyrics ".(!is_admin_user()?"WHERE (approved='y' OR user_id='".get_user_id()."') ":"")."ORDER BY ".($_GET['order_by'] == "author"?"author,title":"title");
	if($results = mysql_query($query)) {
		echo "<table id='list'><tr><th colspan='2'><h2>Song List</h2>\n<tr><th><a href='songs.php'>Title</a><th style='text-align: right'><a href='songs.php?order_by=author'>Author</a>\n";
		while($line = mysql_fetch_assoc($results)) {
			echo "<tr".($line['approved'] != 'y'?" class='unapproved'":"")."><td><a href='songs.php?song=$line[lid]'>$line[title]</a><td style='text-align: right'>$line[author]\n";
		}
		echo "</table>\n";
	} else {
		trigger_error(mysql_error());
	}
}

$content = ob_get_contents();
ob_end_clean();
include('header.php');
echo $content;
include('footer.php');
?>
Return current item: LySite