<?php
$messages[1] = _LANG_WAF_CUSTOM_MESSAGE1;
$messages[2] = _LANG_WAF_CUSTOM_MESSAGE2;
$messages[3] = _LANG_WAF_CUSTOM_MESSAGE3;
?>
<?php if (isset($_GET['message'])) : ?>
<div class="updated"><p><?php echo $messages[$_GET['message']]; ?></p></div>
<?php endif; ?>
<div class="wrap">
<?php

$allowed_users = explode(" ", trim(get_settings('fileupload_allowedusers')));

$submitbutton_text = 'Save';
$toprow_title = sprintf('Editing Post #%s', $post_id);
if (0 == $post_id) {
	$form_action = 'post';
} else {
	$form_action = 'editpost';
	$form_extra = "<input type='hidden' name='post_id' value='$post_id' />";
}
if (get_settings('use_pingback')) {
	$form_pingback = sprintf(_LANG_EF_PING_FORM, gethelp_link(_LANG_DOC_POST_EDIT, '#pingback'));
	$form_pingback .= '<input type="checkbox" class="checkbox" name="post_pingback" value="1" ';
	if ( get_settings('default_pingback_flag') ) $form_pingback .= 'checked="checked" ';
	$form_pingback .= 'tabindex="7" id="pingback" />';
} else {
	$form_pingback = '';
}

$colspan = 2;
$form_prevstatus = '<input type="hidden" name="prev_status" value="'.$post_status.'" />';
if (get_settings('use_trackback')) {
	$form_trackback = '<p><label for="trackback">'  . sprintf(_LANG_EF_TRACK_FORM, gethelp_link(_LANG_DOC_POST_EDIT, '#trackback')) . '<input type="text" name="trackback_url" style="width: 415px" id="trackback" tabindex="7" value="'. str_replace("\n", ' ', $to_ping) .'" /></p>';
	if ('' != $pinged) {
		$pings .= '<p>'. 'Already pinged:' . '</p><ul>';
		$already_pinged = explode("\n", trim($pinged));
		foreach ($already_pinged as $pinged_url) {
			$pings .= "\n\t<li>$pinged_url</li>";
		}
		$pings .= '</ul>';
	}
} else {
	$form_trackback = '';
}
$saveasdraft = '<input name="save" type="submit" id="save" tabindex="6" value="' . _LANG_EFA_SAVE_CONTINUE . '" />';

if (empty($post_status)) $post_status = 'draft';

?>

<form name="post" action="post.php" method="post" id="post">
<input type="hidden" name="user_id" value="<?php echo $user_id ?>" />
<input type="hidden" name="action" value='<?php echo $form_action ?>' />
<?php echo $form_extra ?>
<?php if (isset($_GET['message']) && 2 > $_GET['message']) : ?>
<script type="text/javascript">
<!--
function focusit() {
	// focus on first input field
	document.post.title.focus();
}
window.onload = focusit;
//-->
</script>
<?php endif; ?>
<div id="poststuff">
    <fieldset id="titlediv">
      <legend><?php printf(_LANG_EF_AD_POSTTITLE, gethelp_link(_LANG_DOC_POST_EDIT, '#title')); ?></legend> 
	  <div><input type="text" name="post_title" size="30" tabindex="1" value="<?php echo $edited_post_title; ?>" id="title" /></div>
    </fieldset>

    <fieldset id="categorydiv">
      <legend><?php printf(_LANG_EF_AD_CATETITLE, gethelp_link(_LANG_DOC_POST_EDIT, '#category')); ?></legend> 
	  <div><?php dropdown_categories(get_settings('default_category')); ?></div>
    </fieldset>

    <fieldset id="poststatusdiv">
      <legend><?php printf(_LANG_EFA_POST_STATUS, gethelp_link(_LANG_DOC_POST_EDIT, '#post_status')); ?></legend>
	  <div><label for="post_status_publish" class="selectit"><input id="post_status_publish" name="post_status" type="radio" value="publish" <?php checked($post_status, 'publish'); ?> /> <?php echo _LANG_EF_AD_PUBLISH; ?></label> 
	  <label for="post_status_draft" class="selectit"><input id="post_status_draft" name="post_status" type="radio" value="draft" <?php checked($post_status, 'draft'); ?> /> <?php echo _LANG_EF_AD_DRAFT; ?></label> 
	  <label for="post_status_private" class="selectit"><input id="post_status_private" name="post_status" type="radio" value="private" <?php checked($post_status, 'private'); ?> /> <?php echo _LANG_EF_AD_PRIVATE; ?></label></div>
    </fieldset>
    <fieldset id="commentstatusdiv">
      <legend><?php printf(_LANG_EFA_DISCUS_STATUS, gethelp_link(_LANG_DOC_POST_EDIT, '#comments')); ?></legend> 
	  <div><label for="comment_status" class="selectit">
	      <input name="comment_status" type="checkbox" id="comment_status" value="open" <?php checked($comment_status, 'open'); ?> />
         <?php echo _LANG_EFA_AD_COMMENTS; ?></label> 
		 <label for="ping_status" class="selectit"><input name="ping_status" type="checkbox" id="ping_status" value="open" <?php checked($ping_status, 'open'); ?> /> <?php echo _LANG_EFA_AD_PINGS; ?></label>
</div>
</fieldset>
<fieldset id="slugdiv">
<legend><?php printf(_LANG_EFA_POST_SLUG, gethelp_link(_LANG_DOC_POST_EDIT, '#postslug')); ?></legend>
<div><input name="post_name" type="text" size="17" id="post_name" value="<?php echo $post_name ?>" /></div>
</fieldset>
    <fieldset id="postpassworddiv">
      <legend><?php printf(_LANG_EFA_POST_PASSWORD, gethelp_link(_LANG_DOC_POST_EDIT, '#post_password')); ?></legend> 
	  <div><input name="post_password" type="text" size="13" id="post_password" value="<?php echo $post_password ?>" /></div>
    </fieldset>

<br />
<fieldset style="clear:both">
<legend><?php printf(_LANG_EFA_POST_EXCERPT, gethelp_link(_LANG_DOC_POST_EDIT, '#excerpt')); ?></legend>
<div><textarea rows="2" cols="40" name="excerpt" tabindex="4" id="excerpt"><?php echo $excerpt ?></textarea></div>
</fieldset>

<fieldset id="postdiv">
       <legend><?php printf(_LANG_EF_AD_POSTAREA, gethelp_link(_LANG_DOC_POST_EDIT, '#post')); ?></legend>
		<div id="quicktags">
<?php
	printf(_LANG_EF_AD_POSTQUICK, gethelp_link(_LANG_DOC_POST_EDIT, '#quicktags'));
	include('quicktags.php');
?>
</div>
<?php
 $rows = get_settings('default_post_edit_rows');
 if (($rows < 3) || ($rows > 100)) {
     $rows = 10;
 }
?>
<div><textarea rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="5" id="content"><?php echo $content ?></textarea></div>
</fieldset>

<?php
?>
<script type="text/javascript" language="JavaScript">
<!--
edCanvas = document.getElementById('content');
//-->
</script>
<?php
if ($action != 'editcomment') {
    if (get_settings('use_geo_positions')) {
        if (empty($edited_lat)) {
            if (get_settings('use_default_geourl')) {
                $edited_lat = get_settings('default_geourl_lat');
                $edited_lon = get_settings('default_geourl_lon');
            }
        }
?>
<label for="post_latf"><?php echo _LANG_EFA_POST_LATITUDE; ?></label><input size="8" type="text" value="<?php echo $edited_lat; ?>" name="post_latf">&nbsp;
<label for="post_lonf"><?php echo _LANG_EFA_POST_LONGITUDE; ?></label><input size="8" type="text" value="<?php echo $edited_lon; ?>" name="post_lonf">&nbsp; <a href="http://www.geourl.org/resources.html" rel="external" ><?php echo _LANG_EFA_POST_GEOINFO; ?></a>
<br>
<?php
    }
}
?>

<?php echo $form_pingback ?>
<?php echo $form_prevstatus ?>
<?php echo $form_trackback; ?>



<p class="submit"><?php echo $saveasdraft; ?> <input type="submit" name="submit" value="<?php echo _LANG_EF_AD_DRAFT; ?>" tabindex="6" /> 
<?php 
if ('publish' != $post_status || 0 == $post_id) {
?>
	<input name="publish" type="submit" id="publish" tabindex="10" value="<?php echo _LANG_EF_AD_PUBLISH; ?>" /> 
<?php
}
?>
	<input name="referredby" type="hidden" id="referredby" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
</p>
<?php
if ('' != $pinged) {
	echo $pings;
}

// if the level is 5+, allow user to edit the timestamp - not on 'new post' screen though
// if (($user_level > 4) && ($action != "post"))
if ($user_level > 4) {
	touch_time(($action == 'edit'));
}
?>
<fieldset id="postcustom">
<legend><?php printf(_LANG_EFA_POST_CUSTOM, gethelp_link(_LANG_DOC_POST_EDIT, '#custom_fields')); ?></legend>
<?php 
if($metadata = has_meta($post_id)) {
?>
<?php
	list_meta($metadata); 
?>
<?php
}
	meta_form();
?>
</fieldset>
</div>
</form>
<?php if ('edit' == $action) echo "
<p><a class='delete' href='post.php?action=delete&amp;post=$post_id' onclick=\"return confirm('" . sprintf("You are about to delete this post \'%s\'\\n  \'Cancel\' to stop, \'OK\' to delete.", addslashes($edited_post_title)) . "')\">" .  _LANG_EFA_DEL_THISPOST . "</a></p>";
?>
</div>
