<?php
/** View Template: blog entry form template.
 *
 * It's used in the add,edit blog enty pages.
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */
?>
<?php if(isset($this->messages)):foreach($this->messages as $message):?>
<div style="color:blue"><?php echo $message?></div>
<?php endforeach;endif?>

<fieldset style="margin:0;padding:0;border:none">

<?php if(isset($this->formData["id"])):?>
<div>Id: <?php echo $this->formData["id"]?></div>
<?php endif;?>

<div>Title</div>
<input style="width:200px" id="title" name="title" value="<?php echo isset($this->formData["title"]) ? $this->formData["title"] : ""?>" />

<div>Creation datetime</div>
<input id="posted" name="posted"  value="<?php echo isset($this->formData["posted"]) ? $this->formData["posted"] : ""?>" />
<a href="javascript:postedCal.popup();"><img style="border:none" src="<?php echo AppBaseUrl::getBaseUrl()?>/images/calendarimg/cal.gif" alt="Click Here to Pick up the datetime" /></a>

<div>Author</div>
<select id="author_id" name="author_id" size="1">
 <?php foreach($this->authors as $author):?>
  <option value="<?php echo $author->getId()?>"
    <?php
     if (isset($this->formData["author_id"])) {
      if ($this->formData["author_id"]==$author->getId()) echo "selected=\"selected\"";
     }
    ?>
 >
 <?php echo $this->escape($author->getUsername())?></option>
 <?php endforeach;?>
</select>

<div>Format of the text</div>
 <?php foreach(Article::getAvailFormats() as $format):?>
 <div>
  <input type="radio" name="format" value="<?php echo $format?>" <?php echo ($this->formData["format"]==$format ? "checked=\"checked\"" : "") . " />"?> 
  <?php echo $format?>
 </div>
 <?php endforeach?> 

<?php if (!$this->disableTrackback):?>
<div>Send trackback to sites</div>
<div style="font-size:small">url separator is space</div>
<input style="width:300px" id="trackbackURLs" name="trackbackURLs" value="<?php echo isset($this->formData["trackbackURLs"]) ? $this->formData["trackbackURLs"] : ""?>" />
<?php endif;?>

<div>Entry text</div>
<div style="font-size:small">First Paragraph - text between &lt;p&gt; &lt;p/&gt; tags - will be viewed in a list of entries in the
first blog page as blog entry preview.</div>
<textarea style="width:610px" name="text" id="text" rows="25" cols="35"><?php echo isset($this->formData["text"]) ? $this->formData["text"] : ""?></textarea>

<div>Categories</div>
 <table>
  <tr>
   <th>Assigned categories</th><th></th><th>All Categories</th>
  </tr>
  <tr>
  <td style="width:80px">
    <select style="width:100%" id="articleCategories" name="articleCategories[]" multiple="multiple" size="10">
    <?php foreach($this->articleCategories as $category):?>
     <option value="<?php echo $category->getId()?>"><?php echo $category->getName()?></option>
    <?php endforeach;?>
    </select>
  </td>
  <td>
   <div style="float:left; width:110px">
    <input type="button" name="left"  value="&lt;&lt;" onclick="copySelectedOptions(document.getElementById('allCategories'),document.getElementById('articleCategories'),true)" /><br /><br />
    <input type="button" name="leftall" value="All &lt;&lt;" onclick="copyAllOptions(document.getElementById('allCategories'),document.getElementById('articleCategories'),true)" /><br /><br />
    <input type="button" name="remleftsel" value="Remove selected" onclick="removeSelectedOptions(document.getElementById('articleCategories'))" /><br /><br />
   </div>
  </td>
  <td>
    <select style="width:11em" id="allCategories" name="allCategories[]" multiple="multiple" size="10">
     <?php foreach($this->allCategories as $category):?>
     <option value="<?php echo $category->getId()?>"><?php echo $category->getName()?></option>
     <?php endforeach;?>
    </select>
  </td>
  </tr>
 </table>

<!-- button must be in div -->
<div style="margin-top:0.5em">
 <input type="submit" onclick="preselect();return true;" />
 <input type="reset" value="Reset" />
 <input type="button" value="Preview" onclick="doAjaxPreview(); return false;" />
</div>

</fieldset>

<!-- innerHTML works in IE7 most only with DIV -->
<div class="post" style="margin-top:0.5em" id="articlePreview">
</div>

<script type="text/javascript">
<!--
// create calendar object(s) just after form tag closed
var postedCal = new calendar1(document.getElementById('posted'),baseurl);

/**
 * selects all options in the articleCategories multiline select
 */
function preselect()
{
 var obj=document.getElementById('articleCategories');
 for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
 }
}

/**
 * makes ajax preview for an article
 */
function doAjaxPreview()
{
  var ajax = new sack();
  // recomended method of setting data to be parsed.
  ajax.setVar('articleText',document.getElementById("text").value); 
  ajax.setVar('formatType',getFormCheckedVal());
  ajax.requestFile = "<?php echo $this->url(array("action" => "article-preview"),"blogAction")?>";
  ajax.method = "POST";
  ajax.element = 'articlePreview';
  ajax.onLoading = function(){ ajaxWhenLoading('articlePreview') };
  ajax.onLoaded = ajax.onLoading;
  ajax.onInteractive = ajax.onLoading;
  ajax.runAJAX();
}

/**
 * get value of checked radio button for format text type (wiki,html,...)
 */
function getFormCheckedVal()
{
 formatRadioGroup=document.forms['blogEntryForm'].elements['format'];
 return getCheckedValue(formatRadioGroup);
}

//-->
</script>
