<?php
//include top of the page
include_once('top.php');

// main
// gather all data
	// get dj_types
	$sql = 'SELECT * FROM dj_types ORDER BY type_id';
	$types = $db->query($sql);
	// get DJs
	$sql = 'SELECT dj_id, type_id, name, picture FROM djs WHERE priority < 5 ORDER BY type_id, priority, dj_id';
	$djs = $db->query($sql);

// diplay data
if($_GET['dj_id']) {
	$sql = 'SELECT dj_id, type, name, picture, description, note FROM djs, dj_types WHERE dj_id='.$_GET['dj_id'].' AND djs.type_id = dj_types.type_id';
	$result = $db->query($sql);
	$thedj = $result->fetch_assoc();
	echo '<ul id="types">';
	while($row = $types->fetch_assoc()) {
		echo '<li><a href="djs.php#'.strtolower($row['type']).'" id="l_'.strtolower($row['type']).'">'.$row['type'].'</a></li>';
	}
	echo '</ul>'."\n";
	echo '<div id="alldjs">';
	$types->data_seek(0);
	while($type = $types->fetch_assoc()) {
		echo '<div id="fl_'.strtolower($type['type']).'" class="floater"><dl>';
		$djs->data_seek(0);
		while($dj = $djs->fetch_assoc()) {
			if($dj['type_id'] == $type['type_id']) {
				echo '<a href="djs.php?dj_id='.$dj['dj_id'].'"><dt><img src="';
				echo $dj['picture'] ? substr($dj['picture'], 0, -4).'_th.jpg" alt="'.$dj['name'].'"' : 'images/djs/nopic_th.gif" alt="DJ has no picture"';
				echo ' width="100" haight="150" /></dt><dd>'.$dj['name'].'</dd></a>'."\n";
			}
		}
		echo '</dl>'."\n";
		echo '</div>';
	}
	echo '</div>';
	// display selected dj
	echo '<div id="thedj">';
	// get associations for given DJ
	$sql = 'SELECT name, website FROM associations, associates WHERE dj_id='.$thedj['dj_id'].' AND associations.associate_id = associates.associate_id ORDER BY priority';
	$result = $db->query($sql);
	echo $thedj['picture'] ? '<img src="'.$thedj['picture'].'" alt="'.$thedj['name'].'"' : '<img src="images/djs/nopic.gif" alt="DJ has no picture"';
	echo ' width="200" haight="300" /><div class="details">';
	echo '<h3>'.$thedj['name'].' <span class="minor">('.$thedj['type'].')</span></h3>';
	echo $thedj['note'] ? '<p class="djnote">'.$thedj['note'].'<p>' : '';
	if($result->num_rows) {
		echo '<ul>';
		while($row = $result->fetch_assoc()) {
			echo $row['website'] ? '<li><a href="'.$row['website'].'" target="new">'.$row['name'].'</a></li>' : '<li>'.$row['name'].'</li>';
		}
		echo '</ul>';
	}
	echo $thedj['description'] ? '<p class="djdesc">'.$thedj['description'].'<p>' : '';
	echo '</div>'."\n".'<div class="links">';
	// get links for given DJ
	$sql = 'SELECT link, title FROM dj_links WHERE dj_id='.$thedj['dj_id'].' ORDER BY priority';
	$result = $db->query($sql);
	if($result->num_rows) {
		echo '<p>'.$thedj['name'].'\'s links:</p>';
		echo '<ul>';
		while($row = $result->fetch_assoc()) {
			echo '<li><a href="'.$row['link'].'" target="new">'.$row['title'].'</a></li>';
		}
		echo '</ul>';
	}
	echo '</div>';
	echo '</div>';
} else {
	//display all DJs
	echo '<div id="alldjs">';
	echo '<h1>&gt;&gt; DJs &lt;&lt;</h1>';
	while($type = $types->fetch_assoc()) {
		echo '<div id="'.strtolower($type['type']).'" class="djtype">';
		// echo '<h3>'.$type['type'].'</h3>'."\n".'<dl>';
		$djs->data_seek(0);
		while($dj = $djs->fetch_assoc()) {
			if($dj['type_id'] == $type['type_id']) {
				echo '<a href="djs.php?dj_id='.$dj['dj_id'].'"><dt><img src="';
				echo $dj['picture'] ? substr($dj['picture'], 0, -4).'_th.jpg" alt="'.$dj['name'].'"' : 'images/djs/nopic.gif" alt="DJ has no picture"';
				echo ' width="100" haight="150" /></dt><dd>'.$dj['name'].'</dd></a>'."\n";
			}
		}
		echo '</dl>'."\n";
		echo '</div>';
	}
	echo '</div>';
}

//include bottom
include_once('bottom.php');
?>