<?php include("../includes/config.php");
include("../classes/common.class.php"); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Select Icon</title>
<style>
body {
	font-family:Verdana,Arial,sans-serif;
	font-size:12px;
	margin:0;
	padding:0;
}

.tr_bgcolor {
	background-color:#dcdcdc;
}

.tr_bgcolor2 {
	background-color:#f5f5f5;
}

table tr td {
	font-family:Verdana,Arial,sans-serif;
	font-size:12px;
}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
function closeOpenWindow() {
		//window.close();
		$('#GB_overlay', window.parent.document).hide();
		$('#GB_window', window.parent.document).hide();
	}
function selectIcon(icon)
	{
		parent.document.getElementById('icon').value = icon;
		parent.document.getElementById('icon_sec').innerHTML = '<img src="../images/icons/'+icon+'"/>';
	}
</script>

</head>

<body>
	<?php
	if(isset($_POST['btn_ok']))
	{
		$icon_upload = $_FILES['icon_upload'];
		if($icon_upload['tmp_name'] != '')
		{
			$icon_name 	 = $icon_upload['name'];
			$icon_check  = explode('.',$icon_name);
			$target_path = "../images/icons/";
			if(($icon_check[1] == 'PNG' || $icon_check[1] == 'png' ) && $icon_upload['size'] <= 5000)
			{
				move_uploaded_file($icon_upload['tmp_name'],$target_path.$icon_name);	
			}
			else
			{
				echo "<center><font color='red'>Please Select PNG Image with size 32X32</font></center>";
			}
		}
		else
		{
			echo "<script>closeOpenWindow()</script>";
		}
	}
	
	$image_file_path = '../images/icons/';
	$dir = dir($image_file_path) or die("Wrong path: $image_file_path");
	
	$icon_html = '';
	//List files in images directory
	 $i=0;
	 while (($file = $dir->read()) !== false)
		{
			if ($file != '.' && $file != '..' && !is_dir($image_file_path.$file) && $file != '_notes' && $file !='Thumbs.db'){ 
				$i ++;
				//$fname = substr($file,0, stripos($file,"."));
				$fname = $file;
				
				if (i == 1) $icon_html .= '<tr>';
				
				$icon_html .= '<td align="center"><input type="radio" name="icons" onclick="selectIcon(\''.$fname.'\');" /><img src="../images/icons/'.$fname.'" alt="'.$fname.'"></td>';
				
				if ($i == 2) { $icon_html .= '</tr>'; $i=0; }
			}
			
		} 
		
	$dir->close();
	
	?>
	<form method="post" action="" enctype="multipart/form-data">
 	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="2">
		<tr class="tr_bgcolor" style="line-height:30px;">
			<th>Select Icon from the list below </th>
		</tr>
		<tr class="tr_bgcolor2">
			<td align="center">
				<table align="center" width="80%" cellpadding="2" cellspacing="2">
					<?php echo $icon_html ?>
				</table>
			</td>
		</tr>
		<tr class="tr_bgcolor2">
			<td align="center">
				Upload:&nbsp;<input type="file" id="icon_upload" name="icon_upload" value="" />
			</td>
		</tr>
		<tr class="tr_bgcolor">
			<td>&nbsp;</td>
		</tr>
		<tr class="tr_bgcolor2" align="center">
			<td>
				<!--<input type="Submit" name="btn_ok" id="btn_ok" value="Submit" onclick="closeOpenWindow();" />-->
				<input type="Submit" name="btn_ok" id="btn_ok" value="Submit"  />
			</td>
		</tr>
		<tr class="tr_bgcolor">
			<td>&nbsp;</td>
		</tr>
	</table>
	</form>
</body>
</html>
