<?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"));

if(!FUSION_V6) { 
	// hide side panels?
	//$settings['exclude_left']="/infusions/".$sp_folder."/sendeplan_mysetcard.php";
	$settings['exclude_right']="/infusions/".$sp_folder."/sendeplan_mysetcard.php";
	require_once THEMES."templates/header.php";	
}
else {
	require_once BASEDIR."subheader.php";
	require_once BASEDIR."side_left.php";
}

require_once "sp_functions.php";

if(!checkgroup($sp_setting['dj_group']) || $sp_setting['setcard_dj']!='1') redirect("../../index.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";
}

$result = @dbquery("SELECT * FROM `".$sendeplan_db['table_djinfos']."` WHERE `user_id` = '".$userdata['user_id']."'");
$tmp = @dbrows($result);
if ($tmp == 0) {
	// create new entry if not exists:
	$result2 = @dbquery("INSERT INTO `".$sendeplan_db['table_djinfos']."` (`user_id`) VALUES (".$userdata['user_id'].")");
}

// save new settings
if(IsSet($_POST['save'])) {
	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/".$userdata['user_id'].".png")) { @unlink($sp_install_folder."images/dj-avatars/".$userdata['user_id'].".png"); }
		elseif(file_exists($sp_install_folder."images/dj-avatars/".$userdata['user_id'].".jpg")) { @unlink($sp_install_folder."images/dj-avatars/".$userdata['user_id'].".jpg"); }
		elseif(file_exists($sp_install_folder."images/dj-avatars/".$userdata['user_id'].".gif")) { @unlink($sp_install_folder."images/dj-avatars/".$userdata['user_id'].".gif"); }			
	}
	
	if(IsSet($_FILES['avatar']) && $_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/".$userdata['user_id'].$filetype);
			$uploaded=true;
		}
	}
	$sql_q = "UPDATE `".$sendeplan_db['table_djinfos']."` SET
	";
	if($uploaded) { $sql_q.="`user_avatar` = '".$userdata['user_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` = '".$userdata['user_id']."' LIMIT 1";
	$result = dbquery($sql_q);
	redirect(FUSION_SELF."?status=success");
	exit;
}

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

	$dj_id = $userdata['user_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."' 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>".$userdata['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>		
		";

closetable();

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