<?
require_once("../init.php");
if(!permission("adminpanel")){
	echo "<pre>".$langadmin['nopermsinlineshots'];
	exit();
}

function MakeInFn() {
	$fn = time().mt_rand(0, 1000000000);
	if(file_exists("../../uploads/inlineshots/".$fn)) {
		return MakeInFn();
	} else {
		return $fn;
	}
}

if($_REQUEST['action']=="add_inline") {
	$array = unserialize(base64_decode($_REQUEST['code']));
	$id = MakeInFn();
	$fn = "../../uploads/inlineshots/" . $id;
	
	$array[] = array(
	'titel' => stripslashes($_REQUEST['titel']),
	'text'  => stripslashes($_REQUEST['text']),
	'id'    => $id
	);
	
	move_uploaded_file($_FILES['shot']['tmp_name'], $fn);
	
	$_REQUEST['code'] = base64_encode(serialize($array));
	$_REQUEST['action'] = "inline_screens";
}

if($_REQUEST['action']=="rm_inline") {
	$array = unserialize(base64_decode($_REQUEST['code']));
	
	$entry = $array[$_REQUEST['id']];
	unset($array[$_REQUEST['id']]);
	unlink("../../uploads/inlineshots/" . $entry['id']);
	
	$_REQUEST['code'] = base64_encode(serialize($array));
	$_REQUEST['action'] = "inline_screens";
}

if($_REQUEST['action']=="inline_screens") {
	if(!isset($_REQUEST['code'])) {
		$code = serialize(array());
	} else {
		$code = base64_decode($_REQUEST['code']);
	}
	
	
	if($_REQUEST['is']!=""){
		$code  = unserialize(base64_decode($_REQUEST['is']));
	} else {
		$code  .= unserialize(base64_decode($_REQUEST['is']));
	}
	$array = unserialize($code);
	
	?>
	<script>
	<!--
	parent.document.getElementById('inline_screens').value = '<?php echo(base64_encode(serialize($array))); ?>';
	//-->
	</script><?=ADMINTHEME;?>
	<link href="../templates/original/style.css" rel="stylesheet" type="text/css">
	
	<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><table width="100%" border="0" cellpadding="3" cellspacing="1" class="theader">
	<tr>
	<td class="header">Titel</td>
	<td class="header">Text</td>
	<td class="header">Bild</td>
	<td class="header">&nbsp;</td>
	<td class="header">&nbsp;</td>
	</tr>
	<?php
	while(list($key,$val) = each($array)) {
		?>
		<form action="?action=rm_inline" method="post">
		<input type="hidden" name="code" value="<?php echo(base64_encode(serialize($array))); ?>" />
		<input type="hidden" name="id" value="<?php echo($key); ?>" />
		<tr class="c1">
		<td class="c1"><?php echo(htmlspecialchars($val['titel'])); ?></td>
		<td class="c1"><?php echo(htmlspecialchars($val['text'])); ?></td>
		<td class="c1"><img src="../../system/thumb.php?type=inline&img_id=<?php echo($val['id']); ?>" width="80" height="80" border="0" /></td>
		<td><div align="center">[SCREEN:<?php echo($key); ?>]</div></td>
		<td><div align="center">
		<? if(permission("inlineshotdelete")) { ?>
			<input type="submit" class="button" value="L&ouml;schen" />
		<? } ?>
		<input type="button" class="button" onclick="parent.frames['edtext2'].insertHtml('[SCREEN:<?php echo($key); ?>]');" value="Einf&uuml;gen" />
		</div></td>
		</tr>
		</form>
		<?php
	} if(permission("inlineshotupload")) { 
		?>
		<form action="?action=add_inline" method="post" enctype="multipart/form-data">
		<input type="hidden" name="code" value="<?php echo(base64_encode(serialize($array))); ?>" />
		
		<tr class="secondrow">
		<td><input type="text" name="titel" size="32" style="width:120px;" /></td>
		<td><input type="text" name="text" size="32" style="width:120px;" /></td>
		<td><input type="file" name="shot" /></td>
		<td>&nbsp;</td>
		<td>
		
		<div align="center">
		<input type="submit" class="button" value="Hochladen" />
		</div></td>
		</tr>
		</form>
	<? } ?>
	</table>
	<?php
}
?>