Updated the 19 build version to 20081217
[moodle.git] / blog / edit_form.php
blob9723a317364c59c972fc9f51096d7d45b49e8247
1 <?php // $Id$
3 require_once($CFG->libdir.'/formslib.php');
5 class blog_edit_form extends moodleform {
7 function definition() {
9 global $CFG, $COURSE, $USER;
10 $mform =& $this->_form;
12 $post = $this->_customdata['existing'];
13 $sitecontext = $this->_customdata['sitecontext'];
15 // the upload manager is used directly in entry processing, moodleform::save_files() is not used yet
16 $this->set_upload_manager(new upload_manager('attachment', true, false, $COURSE, false, 0, true, true, false));
18 $mform->addElement('header', 'general', get_string('general', 'form'));
19 $mform->addElement('text', 'subject', get_string('entrytitle', 'blog'), 'size="60"');
20 $mform->setType('subject', PARAM_TEXT);
21 $mform->addRule('subject', get_string('emptytitle', 'blog'), 'required', null, 'client');
23 $mform->addElement('htmleditor', 'summary', get_string('entrybody', 'blog'), array('rows'=>25));
24 $mform->setType('summary', PARAM_RAW);
25 $mform->addRule('summary', get_string('emptybody', 'blog'), 'required', null, 'client');
26 $mform->setHelpButton('summary', array('writing', 'richtext'), false, 'editorhelpbutton');
28 $mform->addElement('format', 'format', get_string('format'));
30 $mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
32 $mform->addElement('select', 'publishstate', get_string('publishto', 'blog'), blog_applicable_publish_states());
33 $mform->setHelpButton('publishstate', array('publish_state', get_string('publishto', 'blog'), 'blog'));
36 if (!empty($CFG->usetags)) {
37 $mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
38 $mform->createElement('select', 'otags', get_string('otags','tag'));
40 $js_escape = array(
41 "\r" => '\r',
42 "\n" => '\n',
43 "\t" => '\t',
44 "'" => "\\'",
45 '"' => '\"',
46 '\\' => '\\\\'
49 $otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'tag'), array(), 'size="5"');
50 $otagsselEl->setMultiple(true);
51 $this->otags_select_setup();
53 $mform->addElement('textarea', 'ptags', get_string('ptags', 'tag'), array('cols'=>'40', 'rows'=>'5'));
54 $mform->setType('ptagsadd', PARAM_NOTAGS);
57 $this->add_action_buttons();
59 $mform->addElement('hidden', 'action');
60 $mform->setType('action', PARAM_ACTION);
61 $mform->setDefault('action', '');
63 $mform->addElement('hidden', 'courseid');
64 $mform->setType('courseid', PARAM_INT);
66 $mform->addElement('hidden', 'id');
67 $mform->setType('id', PARAM_INT);
68 $mform->setDefault('id', 0);
72 /**
73 * This function sets up options of otag select element. This is called from definition and also
74 * after adding new official tags with the add tag button.
77 function otags_select_setup(){
78 global $CFG;
79 $mform =& $this->_form;
80 if ($otagsselect =& $mform->getElement('otags')) {
81 $otagsselect->removeOptions();
83 $namefield = empty($CFG->keeptagnamecase) ? 'name' : 'rawname';
84 if ($otags = get_records_sql_menu('SELECT id, '.$namefield.' from '.$CFG->prefix.'tag WHERE tagtype=\'official\' ORDER by name ASC')){
85 $otagsselect->loadArray($otags);