<?php
session_start();
include("../../connection.php");
/********************************
*
*	THIS FILE GIVES YOU AN EXAMPLE OF HOW A POPUP WINDOW FOR EVENT EDIT COULD LOOK LIKE
*
********************************/

// Input to this file:	$_GET['id'] which is the id of the node that you are about to edit


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Edit event</title>
<style type="text/css">
body{
	margin:5px;
	padding:0px;
	font-family:arial;
	font-size:0.8em;	
	height:100%;
	width:100%;
	background-color:#E2EBED;
}

textarea,input,select{
	width:400px;
}
textarea{
	height:300px;
}

.colorDiv{
	width:15px;
	height:15px;
	margin:1px;
	float:left;
	border:1px solid #000;
}
.colorDivSelected{
	width:13px;
	height:13px;
	margin:1px;
	float:left;
	border:2px solid #000;

}

.aButton{
	width:75px;
}
fieldset{
	width:470px;
}
.buttonDiv{
	float:right;
	margin-top:5px;
	padding-right:15px;
}
</style>
<?php

// Saving event
if(isset($_GET['save'])){
	
	$sql = "update MINICLICK.CALENDAR set Description='".$_GET['eventDescription']."',Color='".$_GET['bgColorCode']."' where Calendar_Id='".$_GET['id']."'";
	mysql_query($sql);
	// Closing window
	
	?>
	<script type="text/javascript">
	self.close();
	</script>
	<?php
	exit;
}

?>

<script type="text/javascript">


function confirmSave()
{
	if(confirm('Click OK to save')){
		if(window.opener){
			var id = <?php echo $_GET['id']; ?>;
			var formObj = document.forms[0];			
			opener.setElement_txt(id,formObj.eventDescription.value);	// Calling function in week planner - update content
			if(formObj.color.value.length>0)opener.setElement_color(id,formObj.color.value);	// Calling function in week planner - updating color
		}
		
		return true;
	}	
	return false;
}

// This function doesn't do anything with the week planner - it only updates color on this page. The confirmSave() function sends the color value back
// to the week planner
var activeColorObj = false;
function selectColor(inputObj,color)
{
	if(activeColorObj)activeColorObj.className='colorDiv';
	inputObj.className='colorDivSelected';
	activeColorObj = inputObj;
	document.forms[0].color.value = color; 
	
}

</script>
</head>
<body>

<?php
$inf = array();
if(isset($_GET['id'])){
	$res = mysql_query("select * from MINICLICK.CALENDAR where Calendar_Id='".$_GET['id']."'");
	$inf = mysql_fetch_array($res);
}else{
	die("no id sent to this window");
}

/* Values for this example only 

You will typically pull these variables from a database(look above) instead of setting them fixed as I have done in this example.

*/


$colors = array("#CCCCCC","#FFFFFF","#E2EBED");	// array of colors the user could choose from


?>

<!-- Example of a form --->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
<input type="hidden" name="color" value="">
<fieldset>
	<legend>Edit event</legend>
	<table border="0" cellpadding="2" cellpadding="0">
		<tr>
			<td>
				<label for="eventDescription">Event:</label>
			</td>
			<td>
				<textarea id="eventDescription" name="eventDescription"><?php echo $inf["Description"]; ?></textarea>
			</td>
		</tr>	
		<tr>
			<td>Color:</td>
			<td><?php
			for($no=0;$no<count($colors);$no++){
				echo "<div class=\"colorDiv\" onclick=\"selectColor(this,'".$colors[$no]."')\" style=\"background-color:".$colors[$no]."\"><span></span></div>";
			}
			?>
			</td>
		</tr>

	</table>	
</fieldset>
<div class="buttonDiv">
	<input type="submit" value="Save" name="save" class="aButton" onclick="return confirmSave()">
	<input type="button" value="Close" class="aButton" onclick="self.close()">
</div>
		
		
</form>
</body>
</html>