<?php
require_once "../../maincore.php";
require_once "infusion_db.php";

// Load default settings
$sp_setting = @dbarray(dbquery("SELECT * FROM `".$sendeplan_db['table_settings']."` WHERE `profile` = 'default' LIMIT 1"));

// Check if locale file is available matching the current site locale setting.
if (file_exists($sp_install_folder."locale/".$settings['locale'].".php")) {
	// Load the locale file matching the current site locale setting.
	include $sp_install_folder."locale/".$settings['locale'].".php";
} else {
	// Load the infusion's default locale file.
	include $sp_install_folder."locale/English.php";
}

if(!FUSION_V6) { 
	require_once THEMES."templates/header.php";	
}
else {
	require_once BASEDIR."subheader.php";
	require_once BASEDIR."side_left.php";
}

require_once "sp_functions.php";

if(!IsSet($_GET['dj_id'])) {
opentable($splocale['dj_setcards'].($sp_channelname!="" ? " &raquo; ".htmlentities($sp_channelname) : ''));
?><br />

<?php
$fix_check = @dbquery("SELECT * FROM `".$sendeplan_db['table_djinfos']."` WHERE `user_id` = '0'");
$rows = dbrows($fix_check);
if ($rows == 0) {
	@dbquery("INSERT INTO `".$sendeplan_db['table_djinfos']."` (`user_id`) VALUES ('0');");
}
$result = @dbquery("SELECT * FROM `".$sendeplan_db['table_djinfos']."` WHERE `user_setcard_activated` = '1' ORDER BY `user_id` ASC");
$rows = dbrows($result);
if ($rows != 0) {
	$zaehler=0;
	echo "<table class='tbl-border' cellpadding='0' cellspacing='1' border='0' align='center' width='".($sp_setting['dj_avatar_maxwidth']*4)."'>
				<tr>";
	while ($djinfo = @dbarray($result)) {
    	if($djinfo['user_id']!=0) {
            // Check if user is in dj group
            $checked = false;
            $udata = @dbarray(dbquery("SELECT * FROM `".DB_USERS."` WHERE `user_id` = '".$djinfo['user_id']."' ORDER BY `user_id` LIMIT 1"));
			// user not existent
			if(!$udata) {
				$tmp = @dbquery("DELETE FROM `".$sendeplan_db['table_djinfos']."` WHERE `user_id` = '".$djinfo['user_id']."' LIMIT 1");
                redirect(FUSION_SELF);
                exit;
			}
            $user_groups = (strpos($udata['user_groups'], ".") == 0 ? explode(".", substr($udata['user_groups'], 1)) : explode(".", $udata['user_groups']));
			for ($i = 0; $i < count($user_groups); $i++) {
				if($user_groups[$i] == $sp_setting['dj_group']) { $checked = true; }
			}
            // user no longer in dj team
			if(!$checked) {
            	$tmp = @dbquery("UPDATE `".$sendeplan_db['table_djinfos']."` SET `user_setcard_activated` = '0' WHERE `user_id` = '".$djinfo['user_id']."'");
            	redirect(FUSION_SELF);
            	exit;
            }
		}
					 
			if(Is_Int($zaehler/4)) { echo "</tr><tr>"; }
			?>			
					<td class='tbl2' style='text-align: center; width:<?php echo ($sp_setting['dj_avatar_maxwidth']+10);?>px'>
					<?php
					 $tmpname = getusernick($djinfo['user_id']);
					 if(!$tmpname && $djinfo['user_id']!='0') {
						 $result2 = dbquery("DELETE FROM `".$sendeplan_db['table_djinfos']."` WHERE `user_id` = '".$djinfo['user_id']."'");
						 redirect(FUSION_SELF);
						 exit;
					 }
                     else { echo ($tmpname!="" ? $tmpname : $sp_setting['autodj_name']); }
					 ?>
                     <br />
					<small><?php echo ($djinfo['user_avatar']!="" && file_exists($sp_install_folder."images/dj-avatars/".$djinfo['user_avatar']) ? "<img src='".$sp_install_folder."images/dj-avatars/".$djinfo['user_avatar']."' border='0' alt='DJ Avatar'  style='max-width: ".$sp_setting['dj_avatar_maxwidth']."px; max-height: ".$sp_setting['dj_avatar_maxheight']."px;' /><br />\n" : "<img src='".$sp_install_folder."images/dj-avatars/nopic.png' border='0' alt='DJ Avatar'  style='max-width: ".$sp_setting['dj_avatar_maxwidth']."px; max-height: ".$sp_setting['dj_avatar_maxheight']."px;' /><br />\n").
					($djinfo['user_id']!='0' ? "<a href='".BASEDIR."profile.php?lookup=".$djinfo['user_id']."' title=''>".$splocale['userprofile']."</a> | " : "");?><a href='<?php echo $sp_install_folder;?>sendeplan_setcards.php?dj_id=<?php echo $djinfo['user_id'];?>' title=''><?php echo $splocale['usersetcard']; ?></a></small>
					</td>			
			<?php
			$zaehler++;
	}
	while(!Is_Int($zaehler/4)) { echo "<td class='tbl1'>&nbsp;</td>"; $zaehler++; }
	echo "</tr></table>";
}
}

else {
	opentable($splocale['setcard'].($sp_channelname!="" ? " &raquo; ".htmlentities($sp_channelname) : ''));	
	$dj_id = stripinput($_GET['dj_id']);
	$djinfo = @dbarray(dbquery("SELECT * FROM `".$sendeplan_db['table_djinfos']."` WHERE `user_id` = '$dj_id' AND `user_setcard_activated` = '1'"));
	if(!$djinfo) { redirect(FUSION_SELF); exit; }
        
		echo "
			<table class='tbl-border' cellpadding='0' cellspacing='1' border='0' align='center' >
				<tr>
					<td class='tbl2' align='center' align='left' width='200'>
					<big><strong>".($djinfo['user_id']!='0' ? getusernick($djinfo['user_id']) : $sp_setting['autodj_name'])."</strong></big>
					</td>
					<td class='tbl2' align='center' align='left' width='300'>
						".($djinfo['user_avatar']!="" && file_exists($sp_install_folder."images/dj-avatars/".$djinfo['user_avatar']) ? "<img src='".$sp_install_folder."images/dj-avatars/".$djinfo['user_avatar']."' border='0' alt='DJ Avatar' style='max-width: ".$sp_setting['dj_avatar_maxwidth']."px; max-height: ".$sp_setting['dj_avatar_maxheight']."px;' />" : "<img src='".$sp_install_folder."images/dj-avatars/nopic.png' border='0' alt='' style='max-width: ".$sp_setting['dj_avatar_maxwidth']."px; max-height: ".$sp_setting['dj_avatar_maxheight']."px;' />")."<br />
					</td>
				</tr>
				<tr>
					<td class='tbl1'>
						<strong>".$splocale['user_real_name']."</strong>
					</td>
					<td class='tbl1' align='left'>
						".stripslashes($djinfo['user_realname'])."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_gender']."</strong>
					</td>
					<td class='tbl1' align='left'>
						";
						if($djinfo['user_gender']=="m") { echo $splocale['user_gender_male']; }
						elseif($djinfo['user_gender']=="f") { echo $splocale['user_gender_female']; }
						else { echo "<em>".$splocale['not_given']."</em>"; }
						echo "
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_location']."</strong>
					</td>
					<td class='tbl1' align='left'>
						".stripslashes($djinfo['user_location'])."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_genre']."</strong>
					</td>
					<td class='tbl1' align='left'>
						".stripslashes($djinfo['user_genre'])."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_hobbies']."</strong>
					</td>
					<td class='tbl1' align='left'>
						".nl2br(stripslashes($djinfo['user_hobbies']))."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_why_at']." ".$settings['sitename']."?</strong>
					</td>
					<td class='tbl1' align='left'>
						".nl2br(stripslashes($djinfo['user_whyhere']))."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_is_bookable']."</strong>
					</td>
					<td class='tbl1' align='left'>
						";
						if($djinfo['user_bookable']=="1") { echo "Ja"; }
						else { echo "Nein"; }
						echo "
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_homepage']."</strong>
					</td>
					<td class='tbl1' align='left'>
						".(stripslashes($djinfo['user_homepage'])!="" ? "<a href='http://".str_replace("http://","",stripslashes($djinfo['user_homepage']))."' target='blank'>".str_replace("http://","",stripslashes($djinfo['user_homepage']))."</a>" : "<em>keine Angabe</em>")."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['moderator_or_livedj']."</strong>
					</td>
					<td class='tbl1' align='left'>
						".($djinfo['user_mod_or_dj']=="dj" ? $splocale['livedj'] : $splocale['moderator'])."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['equipment']."</strong>
					</td>
					<td class='tbl1' align='left'>
						".nl2br(stripslashes($djinfo['user_equipment']))."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['more_infos']."</strong>
					</td>
					<td class='tbl1' align='left'>
						".nl2br(stripslashes($djinfo['user_infotext']))."
					</td>
				</tr>
			</table>
		</form>		
		";

}
closetable();

if(!FUSION_V6) { require_once THEMES."templates/footer.php"; }
else {
	require_once BASEDIR."side_right.php";
	require_once BASEDIR."footer.php";
}
?>
