<?
$page = "edit_template.php";
include "manager_header.php";

// CHECK IF EDIT TEMPLATE IS DISABLED BY ADMIN
if($owner_group_info[allow_edittemplate] != "1") { exit(); }

if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "none"; }
if($user_status == "member") { exit(); }



if($task == "doedit") {
$template = $_POST['template'];

//CAPITALIZE ALL VARS AND CONTAINERS
$template = variable_replace($template);

//CHANGE <, >, and "
$template = str_replace("<", "&lt;", $template);
$template = str_replace(">", "&gt;", $template);
$template = str_replace("\"", "&quot;", $template);

mysql_query("UPDATE bhost_weblogs SET template='$template' WHERE w_id='$weblog_info[w_id]'");

echo $head;
echo "
<h2>$edit_template1</h2>
$edit_template2
<br><br>
<form action='edit_template.php' method='POST'>
<input type='submit' class='button' value='$edit_template3'>
</form>
";
echo $foot;
exit();
}




if($task == "none") {
echo $head;
echo "

<script language='JavaScript'>
<!-- 
function fill() {
window.document.preview.template.value = window.document.info.template.value;
}
// -->
</script>

<h2>$edit_template4</h2>
$edit_template5
<br>

<form action='edit_template.php' method='POST' name='info'>
<textarea name='template' wrap='off' rows='23' cols='100' class='edit_template'>$weblog_info[template]</textarea>

<br>

<table cellpadding='0' cellspacing='0'>
<tr>
<td>
<input type='submit' class='button' value='$edit_template6'>&nbsp;
<input type='hidden' name='task' value='doedit'>
</td>
</form>
<form action='../preview.php' method='POST' target='_blank' name='preview'>
<td>
<input type='submit' class='button' value='$edit_template7' onClick='fill();'>&nbsp;
<input type='hidden' name='template' value=''>
</td>
<td>
<input type='button' class='button' value='$edit_template8' onClick='window.document.info.reset();'>
</td>
</form>
</tr>
</table>
";

echo $foot;
}
?>