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

require_once "infusion_db.php";

if(!FUSION_V6) { 
	if (!checkrights("SP3".($sp_install_number=='' ? '0' : $sp_install_number)) || !defined("iAUTH") || $_GET['aid'] != iAUTH) { redirect("../../index.php"); }
	require_once THEMES."templates/admin_header.php";
	include LOCALE.LOCALESET."admin/infusions.php";
}
else {
	if (!checkrights("IP")) redirect("../../index.php");
	require_once BASEDIR."subheader.php";
	require_once ADMIN."navigation.php";
}

require_once $sp_install_folder."sp_functions.php";

// 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";
}

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

// save new settings
if(IsSet($_POST['save']) && IsNum($_GET['dj_id'])) {
	unset($uploaded);
	if(IsSet($_POST['del_pic']) && $_POST['del_pic']=='1'){
		// delete stored avatar if found
		if(file_exists($sp_install_folder."images/dj-avatars/".$_GET['dj_id'].".png")) { @unlink($sp_install_folder."images/dj-avatars/".$_GET['dj_id'].".png"); }
		elseif(file_exists($sp_install_folder."images/dj-avatars/".$_GET['dj_id'].".jpg")) { @unlink($sp_install_folder."images/dj-avatars/".$_GET['dj_id'].".jpg"); }
		elseif(file_exists($sp_install_folder."images/dj-avatars/".$_GET['dj_id'].".gif")) { @unlink($sp_install_folder."images/dj-avatars/".$_GET['dj_id'].".gif"); }			
	}
	
	if(IsSet($_FILES['avatar'])) {
		$pic = $_FILES['avatar'];
		$bildinfos = @getimagesize($pic['tmp_name']);
		if($bildinfos[2]>=1 && $bildinfos[2]<=3) {
			// define filetype
			if($bildinfos[2]==1) { $filetype=".gif"; }
			elseif($bildinfos[2]==2) { $filetype=".jpg"; }
			elseif($bildinfos[2]==3) { $filetype=".png"; }
			// save new avatarfile
			copy($pic['tmp_name'], $sp_install_folder."images/dj-avatars/".$_GET['dj_id'].$filetype);
			$uploaded=true;
		}
	}
	$sql_q = "UPDATE `".$sendeplan_db['table_djinfos']."` SET
	";
	if(IsSet($uploaded)) { $sql_q.="`user_avatar` = '".stripinput($_GET['dj_id']).$filetype."',"; }
	elseif(IsSet($_POST['del_pic']) && $_POST['del_pic']=='1') { $sql_q.="`user_avatar` = '',"; }
	$sql_q.="`user_realname` = '".addslashes(stripinput($_POST['realname']))."',
	`user_gender` = '".@addslashes(stripinput($_POST['gender']))."',
	`user_location` = '".@addslashes(stripinput($_POST['location']))."',
	`user_genre` = '".@addslashes(stripinput($_POST['genre']))."',
	`user_hobbies` = '".@addslashes(stripinput($_POST['hobbies']))."',
	`user_whyhere` = '".@addslashes(stripinput($_POST['whyhere']))."',
	`user_bookable` = '".@addslashes(stripinput($_POST['bookable']))."',
	`user_homepage` = '".@addslashes(stripinput($_POST['homepage']))."',
	`user_mod_or_dj` = '".@addslashes(stripinput($_POST['mod_or_dj']))."',
	`user_equipment` = '".@addslashes(stripinput($_POST['equipment']))."',
	`user_infotext` = '".@addslashes(stripinput($_POST['infotext']))."',
	`user_setcard_activated` = '".@addslashes(stripinput($_POST['setcard_activated']))."'
	WHERE `user_id` = '".@stripinput($_GET['dj_id'])."' LIMIT 1";
	$result = @dbquery($sql_q);
	redirect(FUSION_SELF.$aidlink."&dj_id=".$_GET['dj_id']."&status=success");
	exit;
}

opentable($splocale['djsetcards_administration'].($sp_channelname!="" ? " &raquo; ".htmlentities($sp_channelname) : ''));
include $sp_install_folder."admin_headermenu.php";
?><br />
<h3 align='center'><?php echo $splocale['choose_djsetcard']; ?></h3>
<br />
<?php 
if(IsSet($_GET['status']) && $_GET['status']=="success") {
	echo "<div class='admin-message'>".$splocale['setcard_successfully_saved']."</div><br />\n";
}

if((IsSet($_POST['dj_id']) && IsNum($_POST['dj_id'])) || (IsSet($_GET['dj_id']) && IsNum($_GET['dj_id']))) {
	if(IsSet($_POST['dj_id'])) { $dj_id = stripinput($_POST['dj_id']); }
	elseif(IsSet($_GET['dj_id'])) { $dj_id = stripinput($_GET['dj_id']); }
	echo "<p align='center'><a href='".FUSION_SELF.$aidlink."'>zur&uuml;ck</a></p><br />\n";
	$dj_id=stripinput($dj_id);
	$result = @dbquery("SELECT * FROM `".$sendeplan_db['table_djinfos']."` WHERE `user_id` = '$dj_id'");
		$rows = @dbrows($result);
		$djinfo = dbarray($result);
		$result = @dbquery("SELECT * FROM `".DB_USERS."` WHERE `user_id` = '$dj_id'");
		$djdata = dbarray($result);
		echo "
		<form method='post' action='".FUSION_SELF.$aidlink."&amp;dj_id=".$djinfo['user_id']."' enctype='multipart/form-data'>
			<table class='tbl-border' cellpadding='0' cellspacing='1' border='0' align='center'>
				<tr>
					<td class='tbl2' colspan='2' align='left'>
					<big>Setcard: &quot;<strong>".($djdata['user_id']==0 ? $sp_setting['autodj_name'] : $djdata['user_name'])."</strong>&quot;</big>
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left' width='150'>
						<strong>".$splocale['setcard_dj_picture']."</strong>
					</td>
					<td class='tbl1' align='left'>
						".($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 /><input name='del_pic' type='checkbox' value='1' />".$splocale['delete_picture']."<br />" : "")."
						<input type='file' name='avatar' class='textbox' size='25' />
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_real_name']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<input type='text' class='textbox' name='realname' size='35' value='".stripslashes($djinfo['user_realname'])."' />
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_gender']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<input name='gender' type='radio' value='m'".($djinfo['user_gender']=="m" ? " checked" : "")." />".$splocale['user_gender_male']."
						<input name='gender' type='radio' value='f'".($djinfo['user_gender']=="f" ? " checked" : "")." />".$splocale['user_gender_female']."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_location']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<input type='text' class='textbox' name='location' size='35' value='".stripslashes($djinfo['user_location'])."' />
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_genre']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<input type='text' class='textbox' name='genre' size='35' value='".stripslashes($djinfo['user_genre'])."' />
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_hobbies']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<input type='text' class='textbox' name='hobbies' size='35' value='".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'>
						<textarea class='textbox' name='whyhere' cols='35' rows='5'>".stripslashes($djinfo['user_whyhere'])."</textarea>
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_is_bookable']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<input name='bookable' type='radio' value='1'".($djinfo['user_bookable']=="1" ? " checked" : "")." />".$splocale['yes']."
						<input name='bookable' type='radio' value='0'".($djinfo['user_bookable']=="0" ? " checked" : "")." />".$splocale['no']."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['user_homepage']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<input type='text' class='textbox' name='homepage' size='35' value='".stripslashes($djinfo['user_homepage'])."' />
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['moderator_or_livedj']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<input name='mod_or_dj' type='radio' value='mod'".($djinfo['user_mod_or_dj']=="mod" ? " checked" : "")." />".$splocale['moderator']."
						<input name='mod_or_dj' type='radio' value='dj'".($djinfo['user_mod_or_dj']=="dj" ? " checked" : "")." />".$splocale['livedj']."
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['equipment']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<textarea class='textbox' name='equipment' cols='35' rows='3'>".stripslashes($djinfo['user_equipment'])."</textarea>
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['more_infos']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<textarea class='textbox' name='infotext' cols='35' rows='8'>".stripslashes($djinfo['user_infotext'])."</textarea>
					</td>
				</tr>
				<tr>
					<td class='tbl1' align='left'>
						<strong>".$splocale['activate_setcard']."</strong>
					</td>
					<td class='tbl1' align='left'>
						<input name='setcard_activated' type='radio' value='1'".($djinfo['user_setcard_activated']=="1" ? " checked" : "")." />".$splocale['yes']."
						<input name='setcard_activated' type='radio' value='0'".($djinfo['user_setcard_activated']=="0" ? " checked" : "")." />".$splocale['no']."
					</td>
				</tr>
				
				<tr>
					<td class='tbl2' colspan='2' align='center'>
						<input type='submit' name='save' value='".$splocale['save']."' class='button' />
					</td>
				</tr>
			</table>
		</form>		
		";
	
}
else { ?>
<table cellpadding='0' cellspacing='0' border='0' align='center'>
	<tr>
		<td align='center'>
			<?php
			if($sp_setting['dj_group'] && IsNum($sp_setting['dj_group'])) {
				// get dj dropdown
				$result = dbquery("SELECT * FROM `".DB_USERS."` WHERE `user_groups` REGEXP('^\\\.".$sp_setting['dj_group']."$|\\\.".$sp_setting['dj_group']."\\\.|\\\.".$sp_setting['dj_group']."$') ORDER BY `user_name` ASC");
				$rows = dbrows($result);
				if ($rows != 0) {
					echo "
					<form method='post' action='".FUSION_SELF.$aidlink."' enctype='multipart/form-data'>
					DJ bearbeiten: <select name='dj_id' class='textbox' size='1'>\n<option value='0'>-".$sp_setting['autodj_name']."-</option>\n";
					while($djdata = dbarray($result)) {
						$result2 = @dbquery("SELECT * FROM `".$sendeplan_db['table_djinfos']."` WHERE `user_id` = '".$djdata['user_id']."'");
						$tmp = @dbrows($result2);
						if ($tmp == 0) {
							// create new entry if not exists:
							$result3 = dbquery("INSERT INTO `".$sendeplan_db['table_djinfos']."` (`user_id`, `user_avatar`) VALUES (".$djdata['user_id'].", 'nopic.png')");
						}
						echo "<option value='".$djdata['user_id']."'>".$djdata['user_name']."</option>						
						";
					}
					echo "</select><input type='submit' class='button' name='edit_dj' value='OK' />
					</form>
					";
				}
				else { echo 'Die DJ-Benutzergruppe enth&auml;lt noch keine Mitglieder'; }
			}
			else { echo "<em>noch keine DJ-Benutzergruppe festgelegt</em>"; }
			?>
		</td>
	</tr>
</table>
<?php
}

closetable();

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