<?php //$Id$
    // get the category drop down form element
    $blogFilter =& new BlogFilter($userid, '', '', $post->courseid);
    if (!isset($post->groupid)) {
        $post->groupid = 0;
    }

    // find all the tags this post uses
    $usedtags = array();
    if (isset($post->postid)) {
        if ($tagsused = get_records('blog_tag_instance', 'entryid', $post->postid)) {
            foreach ($tagsused as $usedtag) {
                $usedtags[] = $usedtag -> tagid;
            }
        }
    }
?>

<!-- the following form is based on moodle/mod/forum/post.html -->

<form name="entry" method="post" action="<?php echo $CFG->wwwroot;?>/blog/edit.php" id="entry" <?php echo $onsubmit; ?> enctype="multipart/form-data">
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
<input type="hidden" name="realcourse" value="0" />
<input type="hidden" name="realgroup" value="0" />

<table border="0" cellpadding="5" id="edittable">
<tr valign="top">
    <td align="right">&nbsp;
    </td>
    <td colspan="2"><strong><?php echo $formHeading; ?></strong>
    </td>
</tr>
<tr valign="top">
    <td align="right"><strong><?php print_string('entrytitle', 'blog'); ?>:</strong></td>
    <td colspan="2">
        <input type="text" name="etitle" size="60" value="<?php p($post->etitle) ?>" id="etitle" />
    </td>
</tr>
<tr valign="top">
    <td align="right">
        <strong><?php print_string('publishto', 'blog'); ?>:</strong>
    </td>
    <td colspan="2">
     <?php
        $options = blog_applicable_publish_states(); //$blogEntry may be null
        choose_from_menu($options, 'publishstate', $post->publishstate, '');
     ?>
    <?php
        helpbutton('publish_state', get_string('helppublish', 'blog'), 'blog');
     ?>
    </td>
</tr>
<tr valign="top">
    <td align="right">
        <strong><?php print_string('tags'); echo ':';?></strong>
    </td>

    <td>
        <table width="100%">
            <tr>
                <td>
                <b><?php print_string('otags','blog'); ?></b>
                </td>
                <td>
                <b><?php print_string('ptags','blog'); ?></b>
                </td>
            </tr>
            <tr>
                <td>
                <select name="otags[]" multiple="multiple" size="8">
                <?php
                    $otags = get_records_sql('SELECT * from '.$CFG->prefix.'tags WHERE type=\'official\' ORDER by text ASC');
                    foreach ($otags as $otag) {
                        if (in_array($otag->id, $usedtags)) {
                            echo '<option value="'.$otag->id.'" selected="selected">'.$otag->text.'</option>';
                        } else {
                            echo '<option value="'.$otag->id.'">'.$otag->text.'</option>';
                        }
                    }
                ?>
                </select>
                &nbsp;&nbsp;</td>

                <td>
                <select name="ptags[]" multiple="multiple" size="8">
                <?php
                    $ptags = get_records_sql('SELECT * from '.$CFG->prefix.'tags WHERE type=\'personal\' ORDER by text ASC');
                    foreach ($ptags as $ptag) {
                        if (in_array($ptag->id, $usedtags)) {
                            echo '<option value="'.$ptag->id.'" selected="selected">'.$ptag->text.'</option>';
                        } else {
                            echo '<option value="'.$ptag->id.'">'.$ptag->text.'</option>';
                        }
                    }
                ?>
                </select>
    <?php link_to_popup_window("/blog/tags.php",'popup',get_string('tagmanagement')); ?>
                </td>
            </tr>
        </table>
    </td>
</tr>



<tr valign="top">
    <td align="right"><strong>
    <?php 
        if (isset($post->useextendedbody) && $post->useextendedbody) {
            print_string('entryexcerpt', 'blog'); 
        } else {
            print_string('entrybody', 'blog');         
        }
    ?>:
    </strong><br /><br />
    <small><small>
    <?php
        helpbutton('reading', get_string('helpreading'), 'moodle', true, true);
        echo '<br />';
        helpbutton('writing', get_string('helpwriting'), 'moodle', true, true);
        echo '<br />';
        helpbutton('questions', get_string('helpquestions'), 'moodle', true, true);
        echo '<br />';
        if ($usehtmleditor) {
           helpbutton('richtext', get_string('helprichtext'), 'moodle', true, true);
        } else {
           emoticonhelpbutton('entry', 'body');
        }
    ?>     
    </small></small>              
    </td>
    <td align="left" colspan="2">
    <?php print_textarea($usehtmleditor, 25, 62, 500, 600, 'body', $post->body, $post->courseid); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><strong><?php print_string('formattexttype'); ?>:</strong></td>
    <td colspan="2">
    <?php
        if ($usehtmleditor) {   /// Trying this out for a while
            print_string('formathtml');
            echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
        } else {
            choose_from_menu(format_text_menu(), "format", $post->format, "");
        }
     ?>
    <small><small>
    <?php
        helpbutton('textformat', get_string('helpformatting'));
     ?>
    </small></small>
    </td>
</tr>
<tr>
    <td align="center" colspan="3">
        <input type="hidden" name="editform" value="1" id="editform" />
        <input type="hidden" name="userid" value="<?php echo $userid; ?>" id="userid" />
        <input type="hidden" name="tem" id="tem" />
<?php
    if (isset($post->postid) && ($post->postid != -1) ) {
?>
        <input type="hidden" name="postid" value="<?php echo $post->postid; ?>" id="postid" />
        <input type="hidden" name="act" value="update" id="act" />
        <input type="submit" value="Update" id="Submit1" name="Submit1" />&nbsp;
        <input type="button" value="Cancel" onclick="javascript:history.go(-1)" id="cancel" name="cancel" />
<?php
    } else { ?>
        <input type="hidden" name="act" value="save" id="act" />
        <input type="submit" value="<?php print_string('savechanges'); ?>" id="savechanges" name="Submit2" />&nbsp;
<?php } ?>
    </td>
</tr>
</table>
</form>
