<?php
include('header.php');
$curpage = (isset($_GET['page'])) ? intval($_GET['page']) : '';
$sortby = (isset($_GET['sort'])) ? htmlspecialchars((string)$_GET['sort']) : 'artist';
$total = (isset($_GET['total'])) ? intval($_GET['total']) : '';
$mode = (isset($_GET['mode'])) ? (string)$_GET['mode'] : '';
$id = (isset($_POST['id'])) ? intval($_POST['id']) : (intval($_GET['id']) ? intval($_GET['id']) : '');
$type_sql = (empty($id)) ? '' : 'AND a.IsArtist = ' . (($id == 2) ? 0 : 1);
$selected = $selected1 = $selected2 = '';
if (($curpage == '') || ($curpage < 1))
{
$curpage = 1;
}
if (($total == '') || ($total < 1))
{
$sql = "SELECT COUNT(a.Artist_ID) AS total
FROM " . ARTIST_TABLE . " a
WHERE a.TotalItems > 0
$type_sql";
if( !($result = $db->sql_query($sql)) )
{
die('<hr /><b style="color: red">Could not execute database query #1.</b><br /><br />' . $sql . '<hr /><br />');
}
if ($row = $db->sql_fetchrow($result))
{
$total = $row['total'];
}
$db->sql_freeresult($result);
}
//
// Sorting
//
switch($sortby)
{
case 'artist':
$order_by = "a.ArtistName";
break;
case 'tracks':
$order_by = "a.TotalItems DESC";
break;
case 'country':
$order_by = "c.CountryName";
break;
case 'born':
$order_by = "a.Formed";
break;
case 'died':
$order_by = "a.Disbanded";
break;
case 'pic':
$order_by = "a.ArtistPicture DESC";
break;
case 'bio':
$order_by = "a.Biography DESC";
break;
default:
$order_by = "a.ArtistName";
break;
}
// ----------------------------------------------------------------
// Query Database for Artists
// ----------------------------------------------------------------
$sql2 = "SELECT a.Artist_ID, a.ArtistName, a.Formed, a.Disbanded, a.ArtistPicture, a.Biography, a.TotalItems, c.*
FROM " . ARTIST_TABLE . " AS a
LEFT JOIN " . COUNTRY_TABLE . " AS c ON a.Country_ID = c.Country_ID
WHERE a.TotalItems > 0
$type_sql
GROUP BY a.Artist_ID
ORDER BY $order_by
LIMIT $per_page_limit
OFFSET " . (($curpage - 1) * $per_page_limit);
if( !($result2 = $db->sql_query($sql2)) )
{
die('<hr /><b style="color: red">Could not execute database query #2.</b><br /><br />' . $sql2 . '<hr /><br />');
}
if ($mode == 'thumbview')
{
$content2 = '<table cellpadding="3" class="border" cellspacing="1" width="100%"><form action="artists.php?mode=thumbview" method="post">
<tr>
<td colspan="7" align="center" valign="top">';
while ($row = $db->sql_fetchrow($result2))
{
$picture = '';
$picture = (!empty($row['ArtistPicture'])) ? 'thumb.php?u=' . $row['Artist_ID'] . '&p=1' : 'img/no-artist.gif';
$content2 .= '<a href="artist.php?id=' . $row['Artist_ID'] . '"><img src="' . $picture . '" width="128" height="128" class="picture" alt="' . $row['ArtistName'] . '" title="' . $row['ArtistName'] . '" /></a> ';
}
$content2 .= '</td>
</tr>';
}
else
{
if ($id == 1)
{
$selected1 = ' selected="selected"';
}
else if ($id == 2)
{
$selected2 = ' selected="selected"';
}
else
{
$selected = ' selected="selected"';
}
$content2 = '<table cellpadding="3" cellspacing="1" class="border" width="100%"><form action="artists.php" method="post">
<tr class="c4" height="15">
<td class="smallfont" nowrap="nowrap"> <b><a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=artist&total=' . $total . '">' . (($id == 2) ? 'Group' : (($id) ? 'Artist' : 'Artist/Group')) . ' Name</a></b></td>
<td class="smallfont" nowrap="nowrap" width="50"> <b><a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=tracks&total=' . $total . '">Tracks</a></b></td>
<td class="smallfont" nowrap="nowrap"> <b><a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=country&total=' . $total . '">Country</a></b></td>
<td class="smallfont" nowrap="nowrap" width="50"> <b><a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=born&total=' . $total . '">' . (($id == 2) ? 'Formed' : (($id) ? 'Born' : 'Born/Formed')) . '</a></b></td>
<td class="smallfont" nowrap="nowrap" width="50"> <b><a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=died&total=' . $total . '">' . (($id == 2) ? 'Disbanded' : (($id) ? 'Died' : 'Died/Disbanded')) . '</a></b></td>
<td class="smallfont" nowrap="nowrap" width="25"> <b><a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=pic&total=' . $total . '">Pic</a></b></td>
<td class="smallfont" nowrap="nowrap" width="25"> <b><a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=bio&total=' . $total . '">Bio</a></b></td>
</tr>';
$i = 0;
while ($row = $db->sql_fetchrow($result2))
{
$country = $pic = $bio = '';
$artistcountry = (!empty($row['Country_ID']) && !empty($row['CountryName'])) ? '<a href="country.php?id=' . $row['Country_ID'] . '">' . $row['CountryName'] . '</a>' : $row['CountryName'];
$pic = '<img src="img/' . ((!empty($row['ArtistPicture'])) ? 'pic' : 'pic_dim') . '.gif" alt="' . ((!empty($row['ArtistPicture'])) ? 'Picture' : '') . '" title="' . ((!empty($row['ArtistPicture'])) ? 'Picture' : '') . '" height="16" width="16" />';
$bio = strip_tags($row['Biography']);
$bio = '<img src="img/' . ((!empty($bio)) ? 'bio' : 'bio_dim') . '.gif" alt="' . ((!empty($bio)) ? 'Biography' : '') . '" title="' . ((!empty($bio)) ? 'Biography' : '') . '" height="16" width="16" />';
$content2 .= '<tr class="' . ((($i++)%2==0) ? 'c2' : 'c3') . '" height="15">
<td id="bot" class="smallfont" nowrap="nowrap"><a href="artist.php?id=' . $row['Artist_ID'] . '">' . $row['ArtistName'] . '</a></td>
<td id="bot" class="smallfont" nowrap="nowrap" align="center">' . number_format($row['TotalItems'], 0) . '</td>
<td id="bot" class="smallfont" nowrap="nowrap">' . ((!empty($country)) ? $country : ' ') . '</td>
<td id="bot" class="smallfont" nowrap="nowrap" align="center">' . ((!empty($row['Formed'])) ? '<a href="year.php?id=' . $row['Formed'] . '">' . $row['Formed'] . '</a>' : ' ') . '</td>
<td id="bot" class="smallfont" nowrap="nowrap" align="center">' . ((!empty($row['Disbanded'])) ? '<a href="year.php?id=' . $row['Disbanded'] . '">' . $row['Disbanded'] . '</a>' : ' ') . '</td>
<td id="bot" class="smallfont" nowrap="nowrap" align="center">' . $pic . '</td>
<td id="bot" class="smallfont" nowrap="nowrap" align="center">' . $bio . '</td>
</tr>';
}
}
$db->sql_freeresult($result2);
$content = $content2;
if (empty($total))
{
$content .= '<tr>
<td colspan="7" height="30" align="center">Sorry, no artists found.</td>
</tr>';
}
$i = 0;
$np = ceil($total / $per_page_limit);
$content .= '
<tr class="c4">
<td colspan="7"><table width="100%">
<tr>
<td class="contentfont" nowrap="nowrap" width="10%">Total ' . (($id == 2) ? 'Group' : (($id) ? 'Artist' : 'Artists & Group')) . 's: <b>' . number_format($total) . '</b></td>
<td class="contentfont" align="center" width="80%">';
if ($np == 0)
{
$content .= '<b>[1]</b>';
$np = 1;
}
else if ($curpage <= 1)
{
if ($np > $tfp)
{
for ($i=1; $i <= $tfp; $i++)
{
if ($curpage == $i)
{
$content .= '<b>['.$i.']</b> | ';
}
else
{
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page='.$i.'">'.$i.'</a> | ';
}
}
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page='.$np.'">... Last</a>';
}
else
{
for ($i=1; $i <= $np; $i++)
{
if ($curpage == $i)
{
$content .= '<b>['.$i.']</b>';
}
else
{
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page='.$i.'">'.$i.'</a>';
}
$content .= ' | ';
}
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page='.$np.'">... Last</a>';
}
}
elseif (($curpage >= 2) && ($curpage < $np))
{
$middle = floor($tfp / 2);
$s = $curpage - $middle;
$e = $curpage + $middle;
if ($s < 1)
{
$s = 1;
}
if ($e > $np)
{
$e = $np;
}
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page=1">First ...</a> | ';
for ($i=$s; $i <= $e; $i++)
{
if ($curpage == $i)
{
$content .= '<b>['.$i.']</b> | ';
}
else
{
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page='.$i.'">'.$i.'</a> | ';
}
}
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page='.$np.'">... Last</a>';
}
elseif ($curpage == $np)
{
if ($np > $tfp)
{
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page=1">First ...</a> | ';
for ($i=($curpage - $tfp + 1); $i < $curpage; $i++)
{
if ($curpage == $i)
{
$content .= '<b>['.$i.']</b> | ';
}
else
{
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page='.$i.'">'.$i.'</a> | ';
}
}
$content .= '<b>['.$np.']</b>';
}
else
{
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page=1">First ...</a> | ';
for ($i=1; $i <= $np; $i++)
{
if ($curpage == $i)
{
$content .= '<b>['.$i.']</b>';
}
else
{
$content .= '<a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&' . (($mode == 'thumbview') ? 'mode=thumbview&' : '') . 'total='.$total.'&page='.$i.'">'.$i.'</a>';
}
if ($i != $np)
{
$content .= ' | ';
}
}
}
}
$content .= '</td>
<td class="contentfont" align="right" nowrap="nowrap" width="10%">Total Pages: <b>' . number_format($np) . '</b></td>
</tr>
</table></td>
</tr>
</table>
<br />
<table width="100%">
<tr>
<td valign="middle">[ <a href="artists.php?' . ((!empty($id) ? 'id=' . $id . '&' : '')) . 'sort=' . $sortby . '&total=' . $total . '&page=' . $curpage . (($mode != 'thumbview') ? '&mode=thumbview">Switch to thumbnail' : '">Switch to details') . ' view</a> ]</td>
<td align="right">Show: <select name="id" onchange="this.form.submit();">
<option value=""' . $selected . '>All</option>
<option value="1"' . $selected1 . '>Artists</option>
<option value="2"' . $selected2 . '>Groups</option>>
</select></td>
</tr>
</form></table>';
header7((($id == 2) ? 'Group' : (($id) ? 'Artist' : 'Artists & Group')) . 's In Collection');
echo $content;
include('footer.php'); ?>