{assign var=editor value=1}
{assign var=htmlarea value=$blogsettings->getValue("htmlarea_enabled")}
{include file="$admintemplatepath/header.template"}
{include file="$admintemplatepath/navigation.template" showOpt=editPosts title=$locale->tr("editPost")}
<link rel="stylesheet" type="text/css" media="all" href="js/jscalendar/calendar-win2k-cold-1.css" title="win2k-cold-1" />
<script type="text/javascript" src="js/jscalendar/calendar_stripped.js"></script>
<script type="text/javascript" src="js/jscalendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="js/jscalendar/calendar-setup_stripped.js"></script>
<script type="text/javascript" src="js/ui/plogui.js"></script>
 <script type="text/javascript">
  
  // some messages that we are going to need in the functions above 
  var htmlAreaEnabled = {if $htmlarea==0 || !$htmlarea}false{else}true{/if};
  var msgSaving = "{$locale->tr("saving_message")}";  
  var preview = false;

{literal} 
function selectOperation( t )
{
	if( preview ) {	
		document.newPost.op.value="previewPost";
		window.open("", t, "scrollbars=yes,resizable=yes,toolbar=no" );
		return true;
	}
	else {
		document.newPost.op.value="updatePost";
		document.newPost.target="";
		document.newPost.action="admin.php";
		return true;
	}
}
{/literal}
 </script>
  <form name="newPost" id="newPost" action="admin.php" method="post" onSubmit="return selectOperation(this.target);" target="admin">   
   <fieldset class="inputField">
   <legend>{$locale->tr("editPost")}</legend>
   <div id="mainPanel" style="float:left; width: 73%; border-right: 1px solid #DEDEDE;">  
     {include file="$admintemplatepath/formvalidate.template"}    
	 
	   <div class="field">
	     <label for="postTopic">{$locale->tr("topic")}</label>
		 <span class="required">*</span>
		 <div class="formHelp">{$locale->tr("topic_help")}</div>
	     <input type="text" id="postTopic" name="postTopic" style="width:100%" value="{$postTopic|escape:"html"}" />
	     {include file="$admintemplatepath/validate.template" field=postTopic message=$locale->tr("error_missing_post_topic")}
	   </div>
	   
	   <!-- text field custom fields -->
	   {include file="$admintemplatepath/newpost_customfields.template" type=1 fields=$customfields}	   
	   
	   
	   <div class="field">
	     <label for="postText">{$locale->tr("text")}</label>
		 <span class="required">*</span>
		 <div class="formHelp">{$locale->tr("text_help")}</div>
	     {if !$htmlarea}<script type="text/javascript">var ed1 = new Lifetype.UI.Editor('postText','ed1');</script>{/if}
	     <textarea {if $htmlarea==1}rows="20"{else}rows="15"{/if} id="postText" name="postText" style="width:100%">{$postText}</textarea>
	     <a href="{if $htmlarea}javascript:tinyMCE.execInstanceCommand('mce_editor_0','mceinsertresource',true);{else}javascript:ed1.execute('postText','7_but_res',''){/if}">{$locale->tr("insert_media")}</a> |
             <a href="{if $htmlarea}javascript:tinyMCE.execInstanceCommand('mce_editor_0','mcemoremore');{else}javascript:ed1.execute('postText','8_but_more',''){/if}">{$locale->tr("insert_more")}</a>
	     {include file="$admintemplatepath/validate.template" field=postText message=$locale->tr("error_missing_post_text")}   
	   </div>
	   
	   <!-- text area custom fields -->
      {include file="$admintemplatepath/newpost_customfields.template" type=2 fields=$customfields}
   </div>	   
   
   <div id="optionPanel" style="float:left; width: 23%; margin-left: 8px;">   
	 
	   <div class="field">
	     <label for="postSlug">{$locale->tr("post_slug")}</label>
		 <div class="formHelp">{$locale->tr("post_slug_help")}</div>
	     <input type="text" name="postSlug" id="postSlug" style="width:100%" value="{$postSlug|escape:"html"}" />
	   </div>
	   
       <div class="field">
   	     <label for="postDateTime">{$locale->tr("date")}</label>
		 <span class="required">*</span>
		 <div class="formHelp">{$locale->tr("post_date_help")}</div>
		 <input name="postDateTime" id="postDateTime" class="dateTime" readonly="true" type="text" size="16" value="{$postDay}/{$postMonth}/{$postYear} {$postHour}:{$postMinutes}" style="margin-bottom: 4px;" />
         <img src="imgs/admin/cal.jpg" id="postDateTimeSelector" alt="{$locale->tr("date")}" style="cursor: pointer; border: 0px; width: 16px; height: 14px; padding: 0;" />
	   </div>

	   <script type="text/javascript">
	   var MondayFirstDay = ( {$locale->firstDayOfWeek()} == 1);
       {literal}
	       Calendar.setup({
	           inputField  : "postDateTime",
	           ifFormat    : "%d/%m/%Y %H:%M",
	           button      : "postDateTimeSelector",
	           showsTime   : true,
	           timeFormat  : "24",
	           electric    : false,
	           align       : "Bl",
	           firstDay    : MondayFirstDay,
	           singleClick : true
	       });
	   {/literal}
	   </script>
	   
	   <!-- date custom fields -->
	   {include file="$admintemplatepath/newpost_customfields.template" type=4 fields=$customfields}	   

	   <div class="field">
         <label for="postStatus">{$locale->tr("status")}</label>
		 <span class="required">*</span>		 
		 <div class="formHelp">{$locale->tr("post_status_help")}</div>
		 <select name="postStatus" id="postStatus">
		   {foreach from=$poststatus key=name item=status}
		   <option value="{$status}" {if $postStatus == $status} selected="selected"{/if}>{$locale->tr($name)}</option>
		   {/foreach}
         </select>	   
	   </div>
	
	  <!-- user field -->
	  {check_perms perm=update_all_user_articles}
	   <div class="field">
        <label for="postUser">{$locale->tr("posted_by")}</label>
		 <span class="required">*</span>		 
		 <div class="formHelp">{$locale->tr("posted_by_help")}</div>
		 <select name="postUser" id="postUser">
		   {foreach from=$blog->getUsersInfo() item=bloguser}
			<option value="{$bloguser->getId()}" {if $postUser==$bloguser->getId()}selected="selected"{/if}>{$bloguser->getUserName()}</option>
		   {/foreach}
        </select>	   
	   </div>
	   {/check_perms}	
	   
	   <div class="field">
         <label for="postCategories[]">{$locale->tr("categories")}</label>
		 <span class="required">*</span>
		 <div class="formHelp">{$locale->tr("post_categories_help")}</div>
         <select name="postCategories[]" id="postCategories" size="5" multiple="multiple" style="width:100%">
           {foreach from=$categories item=category}
           <option value="{$category->getId()}" {foreach from=$postCategories item=categoryId}{if $category->getId() == $categoryId} selected="selected" {/if}{/foreach}>{$category->getName()}</option>
           {/foreach}
         </select>
         <input type="text" name="newArticleCategory" id="newArticleCategory" style="width:100px; margin-top:3px;" size="16" value="" />
         <input type="button" name="addArticleCategory" id="addArticleCategory" style="width:auto;margin-top:3px;" value="{$locale->tr("add")}" onclick="javascript:addArticleCategoryAjax()" />
        {include file="$admintemplatepath/validate.template" field=postCategories message=$locale->tr("error_no_categories")}	   
	   </div>
	   
      <div class="field">
         <label for="globalArticleCategoryId">{$locale->tr("global_category")}</label>
		 <span class="required">*</span>
		 <div class="formHelp">{$locale->tr("global_article_category_help")}</div>
	    <select name="globalArticleCategoryId" id="globalArticleCategoryId" size="1" style="width:100%">
	       <option value="0" {if 0 == $globalArticleCategoryId} selected="selected" {/if}>{$locale->tr("none")}</option>
           {foreach from=$globalcategories item=globalcategory}
           <option value="{$globalcategory->getId()}" {if $globalcategory->getId() == $globalArticleCategoryId} selected="selected" {/if}>{$globalcategory->getName()}</option>
           {/foreach}
         </select>
        {include file="$admintemplatepath/validate.template" field=globalArticleCategoryId message=$locale->tr("error_no_global_article_category_selected")}	   
       </div>   

	   <!-- list custom fields -->
	   {include file="$admintemplatepath/newpost_customfields.template" type=5 fields=$customfields}
	      
       <div class="field_checkbox">
         <input class="checkbox" type="checkbox" id="commentsEnabled" name="commentsEnabled" value="1" {if $postCommentsEnabled} checked="checked" {/if}/>
		 <label for="commentsEnabled">{$locale->tr("post_comments_enabled_help")}</label>
	   </div>
	   
       <div class="field_checkbox">
	     <input class="checkbox" type="checkbox" id="sendNotification" name="sendNotification" value="1" {if $sendNotification} checked="checked" {/if}/>
		 <label for="sendNotification">{$locale->tr("send_notification_help")}</label>
	   </div>
	   
       <div class="field_checkbox">
	     <input class="checkbox" type="checkbox" id="sendTrackbacks" name="sendTrackbacks" value="1" {if $sendTrackbacks} checked="checked" {/if}/>  
		 <label for="sendTrackbacks">{$locale->tr("send_trackback_pings_help")}</label>
	   </div>
	   
       {if $xmlRpcPingEnabled}
  	    <div class="field_checkbox">	
		 <input class="checkbox" type="checkbox" name="sendPings" id="sendPings" value="1" {if $sendPings} checked="checked" {/if}/>
		 <label for="sendPings">{$locale->tr("send_xmlrpc_pings_help")}</label>
        </div>
       {/if}
	  
  	  <!-- checkbox custom fields -->
      {include file="$admintemplatepath/newpost_customfields.template" type=3 fields=$customfields}	  

	</div>
	</fieldset>
	<div class="buttons">  
      <input type="submit" name="previewPost" value="{$locale->tr("preview")}" onClick="preview=true" />	
      <input type="submit" name="updatePost" value="{$locale->tr("update")}" onClick="preview=false"/>
      <input type="hidden" name="op" value="updatePost"/>
      <input type="hidden" name="postId" id="postId" value="{$postId}"/>
	</div>  	
  </form>
{include file="$admintemplatepath/footernavigation.template"}
{include file="$admintemplatepath/footer.template"}
