<?php
include('header.php');
	if (isset($_POST['submit'])) {
	if (!empty($_FILES['avatar']['name'])) {
	$up = new fileDir('../uploads/avatar/');
	$avatar_image = $up->upload($_FILES['avatar']);
	} else {
	$avatar_image = $_POST['avatar_image'];
	}
	if (!empty($_FILES['banner']['name'])) {
	$up = new fileDir('../uploads/avatar/');
	$banner_image = $up->upload($_FILES['banner']);
	} else {
	$banner_image = $_POST['banner_image'];
	}
	$update = mysql_query("UPDATE setting SET avatar_image='$avatar_image',banner_image='$banner_image' WHERE id='1'");
	if ($update) {
	$message = $general->notification('success','Setting Is Saved Successfully');
	} else {
	$message = $general->notification('error','Error Happened');
	}
	}
	$query = mysql_query("SELECT avatar_image,banner_image FROM setting WHERE id='1'");
	$row = mysql_fetch_array($query);
	echo '<div class="page_title"><h3>Avatar</h3></div>';
	echo '<form method="POST" action="" enctype="multipart/form-data">';
	if (isset($message)) {echo $message;}
	echo '<table width="100%" cellpadding="5" cellspacing="0" style="margin-bottom:30px;">
	<tr>
		<td colspan="2" class="divider_td">Avatar</td>
	</tr>
	<tr>';
		if (!empty($row['avatar_image'])) {
		echo '<td class="input_td" width="70" id="avatar"><img src="../uploads/avatar/'.$row['avatar_image'].'" height="60" width="60" /></td>';
		}
		echo '<td class="input_td" valign="top"><input type="file" name="avatar" />';
		if (!empty($row['banner_image'])) {
		echo '<a href="javascript:void();" class="delete_avatar">Delete Avatar</a>';
		}
		echo '</td>
	</tr>
	<tr>
		<td colspan="2" class="divider_td">Profile Banner</td>
	</tr>
	<tr>
		<td class="input_td" colspan="2">
		<input type="file" name="banner" />';
		if (!empty($row['banner_image'])) {
		echo '<a href="javascript:void();" class="delete_banner">Delete Banner</a>';
		}
		echo '</td>
	</tr>';
		if (!empty($row['banner_image'])) {
		echo '<tr>
		<td class="input_td" colspan="2"><img src="../uploads/avatar/'.$row['banner_image'].'" height="120" width="730" id="banner" /></td>
	</tr>';
	}
	echo '<tr>
		<td colspan="2">
		<input type="hidden" name="avatar_image" value="'.$row['avatar_image'].'" />
		<input type="hidden" name="banner_image" value="'.$row['banner_image'].'" />
		<input type="submit" name="submit" value="Save" class="inputbutton grey" />
		</td>
	</tr>
	</table>
	</form>';
include('footer.php');
?>