Merge branch 'MDL-27515_m19' of git://github.com/rwijaya/moodle into MOODLE_19_STABLE
[moodle.git] / blog / edit_form.php
blob64a73965282c99e70f7cf62dba6f0820929cfb3f
1 <?php // $Id$
3 if (!defined('MOODLE_INTERNAL')) {
4 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
7 require_once($CFG->libdir.'/formslib.php');
9 class blog_edit_form extends moodleform {
11 function definition() {
13 global $CFG, $COURSE, $USER;
14 $mform =& $this->_form;
16 $post = $this->_customdata['existing'];
17 $sitecontext = $this->_customdata['sitecontext'];
19 // the upload manager is used directly in entry processing, moodleform::save_files() is not used yet
20 $this->set_upload_manager(new upload_manager('attachment', true, false, $COURSE, false, 0, true, true, false));
22 $mform->addElement('header', 'general', get_string('general', 'form'));
23 $mform->addElement('text', 'subject', get_string('entrytitle', 'blog'), 'size="60"');
24 $mform->setType('subject', PARAM_TEXT);
25 $mform->addRule('subject', get_string('emptytitle', 'blog'), 'required', null, 'client');
27 $mform->addElement('htmleditor', 'summary', get_string('entrybody', 'blog'), array('rows'=>25));
28 $mform->setType('summary', PARAM_RAW);
29 $mform->addRule('summary', get_string('emptybody', 'blog'), 'required', null, 'client');
30 $mform->setHelpButton('summary', array('writing', 'richtext'), false, 'editorhelpbutton');
32 $mform->addElement('format', 'format', get_string('format'));
34 $mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
36 $mform->addElement('select', 'publishstate', get_string('publishto', 'blog'), blog_applicable_publish_states());
37 $mform->setHelpButton('publishstate', array('publish_state', get_string('publishto', 'blog'), 'blog'));
40 if (!empty($CFG->usetags)) {
41 $mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
42 $mform->createElement('select', 'otags', get_string('otags','tag'));
44 $js_escape = array(
45 "\r" => '\r',
46 "\n" => '\n',
47 "\t" => '\t',
48 "'" => "\\'",
49 '"' => '\"',
50 '\\' => '\\\\'
53 $otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'tag'), array(), 'size="5"');
54 $otagsselEl->setMultiple(true);
55 $this->otags_select_setup();
57 $mform->addElement('textarea', 'ptags', get_string('ptags', 'tag'), array('cols'=>'40', 'rows'=>'5'));
58 $mform->setType('ptagsadd', PARAM_NOTAGS);
61 $this->add_action_buttons();
63 $mform->addElement('hidden', 'action');
64 $mform->setType('action', PARAM_ACTION);
65 $mform->setDefault('action', '');
67 $mform->addElement('hidden', 'courseid');
68 $mform->setType('courseid', PARAM_INT);
70 $mform->addElement('hidden', 'id');
71 $mform->setType('id', PARAM_INT);
72 $mform->setDefault('id', 0);
76 /**
77 * This function sets up options of otag select element. This is called from definition and also
78 * after adding new official tags with the add tag button.
81 function otags_select_setup(){
82 global $CFG;
83 $mform =& $this->_form;
84 if ($otagsselect =& $mform->getElement('otags')) {
85 $otagsselect->removeOptions();
87 $namefield = empty($CFG->keeptagnamecase) ? 'name' : 'rawname';
88 if ($otags = get_records_sql_menu('SELECT id, '.$namefield.' from '.$CFG->prefix.'tag WHERE tagtype=\'official\' ORDER by name ASC')){
89 $otagsselect->loadArray($otags);