MDL-14679: fix regression in tag library
[moodle.git] / blog / edit_form.php
CommitLineData
f07b9627 1<?php // $Id$
2
3require_once($CFG->libdir.'/formslib.php');
4
5class blog_edit_form extends moodleform {
6
2ee60b49 7 function definition() {
2ee60b49 8 global $CFG, $COURSE, $USER;
45df7de3 9
2ee60b49 10 $mform =& $this->_form;
f07b9627 11
2ee60b49 12 $post = $this->_customdata['existing'];
f07b9627 13 $sitecontext = $this->_customdata['sitecontext'];
14
feaf5d06 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));
f07b9627 17
18 $mform->addElement('header', 'general', get_string('general', 'form'));
2ee60b49 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');
f07b9627 22
2ee60b49 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');
18a77361 26 $mform->setHelpButton('summary', array('writing', 'richtext'), false, 'editorhelpbutton');
f07b9627 27
28 $mform->addElement('format', 'format', get_string('format'));
29
30 $mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
31
32 $mform->addElement('select', 'publishstate', get_string('publishto', 'blog'), blog_applicable_publish_states());
d4175332 33 $mform->setHelpButton('publishstate', array('publish_state', get_string('publishto', 'blog'), 'blog'));
f07b9627 34
93bbdd50 35
36 if (!empty($CFG->usetags)) {
3d535996 37 $mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
38 $mform->createElement('select', 'otags', get_string('otags','tag'));
93bbdd50 39
40 $js_escape = array(
41 "\r" => '\r',
42 "\n" => '\n',
43 "\t" => '\t',
44 "'" => "\\'",
45 '"' => '\"',
46 '\\' => '\\\\'
47 );
48
3d535996 49 $otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'tag'), array(), 'size="5"');
93bbdd50 50 $otagsselEl->setMultiple(true);
51 $this->otags_select_setup();
52
3d535996 53 $mform->addElement('textarea', 'ptags', get_string('ptags', 'tag'), array('cols'=>'40', 'rows'=>'5'));
93bbdd50 54 $mform->setType('ptagsadd', PARAM_NOTAGS);
f07b9627 55 }
93bbdd50 56
f07b9627 57 $this->add_action_buttons();
58
59 $mform->addElement('hidden', 'action');
2ee60b49 60 $mform->setType('action', PARAM_ACTION);
61 $mform->setDefault('action', '');
62
63 $mform->addElement('hidden', 'courseid');
64 $mform->setType('courseid', PARAM_INT);
65
66 $mform->addElement('hidden', 'id');
67 $mform->setType('id', PARAM_INT);
68 $mform->setDefault('id', 0);
69
70 }
71
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.
75 *
76 */
77 function otags_select_setup(){
45df7de3 78 global $CFG, $DB;
79
2ee60b49 80 $mform =& $this->_form;
bd1f4559 81 if ($otagsselect =& $mform->getElement('otags')) {
82 $otagsselect->removeOptions();
83 }
4c7fa6ce 84 $namefield = empty($CFG->keeptagnamecase) ? 'name' : 'rawname';
45df7de3 85 if ($otags = $DB->get_records_sql_menu("SELECT id, $namefield FROM {tag} WHERE tagtype='official' ORDER by name ASC")){
f07b9627 86 $otagsselect->loadArray($otags);
87 }
2ee60b49 88 }
f07b9627 89
90}
91?>