MDL-10181, help files should not be modified, a new file has been created
[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() {
f07b9627 8
2ee60b49 9 global $CFG, $COURSE, $USER;
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());
33 $mform->setHelpButton('publishstate', array('publish_state', get_string('helppublish', 'blog'), 'blog'));
34
35 $mform->addElement('header', 'tagshdr', get_string('tags', 'blog'));
36
37 $mform->createElement('select', 'otags', get_string('otags','blog'));
38
39 $js_escape = array(
40 "\r" => '\r',
41 "\n" => '\n',
42 "\t" => '\t',
43 "'" => "\\'",
44 '"' => '\"',
45 '\\' => '\\\\'
46 );
47
48 $otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'blog'), array(), 'size="5"');
49 $otagsselEl->setMultiple(true);
50 $this->otags_select_setup();
51
52 if (has_capability('moodle/blog:manageofficialtags', $sitecontext)){
53 $deleteotagsmsg = strtr(get_string('deleteotagswarn', 'blog'), $js_escape);
54 $mform->registerNoSubmitButton('deleteotags');
55 $mform->addElement('submit', 'deleteotags', get_string('delete'),
56 array('onclick'=>"return confirm('$deleteotagsmsg');"));
57 $mform->disabledIf('deleteotags', 'otags[]', 'noitemselected');
58 $mform->setAdvanced('deleteotags');
59
60 $mform->registerNoSubmitButton('addotags');
61 $otagsgrp = array();
62 $otagsgrp[] =& $mform->createElement('text', 'otagsadd', get_string('addotags', 'blog'));
63 $otagsgrp[] =& $mform->createElement('submit', 'addotags', get_string('add'));
64 $mform->addGroup($otagsgrp, 'otagsgrp', get_string('addotags','blog'), array(' '), false);
65 $mform->setType('otagsadd', PARAM_NOTAGS);
66 $mform->setAdvanced('otagsgrp');
67 }
68
e295df44 69 $mform->addElement('textarea', 'ptags', get_string('ptags', 'blog'), array('cols'=>'40', 'rows'=>'5'));
f07b9627 70 $mform->setType('ptagsadd', PARAM_NOTAGS);
71
72 $this->add_action_buttons();
73
74 $mform->addElement('hidden', 'action');
2ee60b49 75 $mform->setType('action', PARAM_ACTION);
76 $mform->setDefault('action', '');
77
78 $mform->addElement('hidden', 'courseid');
79 $mform->setType('courseid', PARAM_INT);
80
81 $mform->addElement('hidden', 'id');
82 $mform->setType('id', PARAM_INT);
83 $mform->setDefault('id', 0);
84
85 }
86
87 /**
88 * This function sets up options of otag select element. This is called from definition and also
89 * after adding new official tags with the add tag button.
90 *
91 */
92 function otags_select_setup(){
93 global $CFG;
94 $mform =& $this->_form;
f07b9627 95 $otagsselect =& $mform->getElement('otags');
96 $otagsselect->removeOptions();
97 if ($otags = get_records_sql_menu('SELECT id, text from '.$CFG->prefix.'tags WHERE type=\'official\' ORDER by text ASC')){
98 $otagsselect->loadArray($otags);
e295df44 99 } else {
100 $mform->removeElement('otags');
f07b9627 101 }
2ee60b49 102 }
f07b9627 103
104}
105?>