<?php use_helper('Object', 'tvtl', 'Validation', 'I18N') ?>
<?php $blogCode = array(blogStore::$blogId, blogStore::isAdministator()); ?>
<script language="javascript">
  var idBlog = '<?php echo blogStore::$blogId ?>';
  var canChangeImage = '<?php echo md5(serialize($blogCode)) ?>';
</script>

<script>
  function validate() {
    var ret = true;
    ret &= checkError('entry_title', '3<=v.length && v.length<=128', 'Tên bài viết từ 3 đến 128 ký tự');
    tinyMCE.triggerSave();
    ret &= checkError('entry_content', '20<=v.length', 'Nội dung bài viết quá ngắn');
    if (!ret) window.location = '#entry_title_bookmark';

    if (ret) {
      $('update').submit();
    }
    return ret;
  }
</script>

<?php echo form_tag('/entry/update', array('id'=>'update', 'onsubmit'=>'return false;')) ?>
<?php echo input_hidden_tag('entry_id', $entry_id) ?>
<?php $tinymce_options = '
  plugins: "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,visualblocks,ibrowser,equation",
  theme_advanced_buttons1: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,code,|,undo,redo,|,link,table,charmap,|,sub,sup,equation,|,emotions,ibrowser",
  theme_advanced_buttons2: "fontsizeselect,bold,italic,underline,forecolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,outdent,indent,|,image,removeformat",
  theme_advanced_buttons3: "",
  height: 700, width: 510'; ?>
  <div class="form">
    <h2>
      <?php echo (null===@$created)?'Tạo mới bài viết':'Chỉnh sửa bài viết' ?>
    </h2>
    <div>
      <fieldset>
        <?php include_component('entry', 'selectfolder', array('cat_id'=>$cat_id)); ?>
        <?php echo gridTable(array(array(12, 12),
          array('<a name="entry_title_bookmark"/>Tiêu đề*', form_error('entry_title') . object_input_tag($tblblogentry, 'getEntryTitle', array('size'=>50,'maxlength' =>255, 'style'=>'width: 500px'))),
          array('Nội dung*', form_error('entry_content') . object_textarea_tag($tblblogentry, 'getEntryContent', array (
                'control_name' => 'entry_content', 'rich' => true, 'tinymce_options' => $tinymce_options)))
        )); ?>
      </fieldset>
    </div>
  </div>

  <center>
    <?php echo submit_tag(__('Save'), array('size'=>'20','onclick'=>'this.disabled = validate()')) ?>
    <?php if ($entry_id): ?>
      &nbsp;<?php echo link_to('delete', 'entry/delete?entry_id='.$entry_id, array('confirm'=>'Bạn có chắc chắn xóa bài viết này?')) ?>
      &nbsp;<?php echo link_to('cancel', 'entry/show?entry_id='.$entry_id) ?>
    <?php else: ?>
      &nbsp;<?php echo link_to('cancel', 'entry/list?cat_id='.$cat_id) ?>
    <?php endif; ?>
  </center>
</form>