adding current groupid to grade_export class - soon to be used in plugins
[moodle-pu.git] / blog / edit_form.php
blob9510100a9dff237c4eff791b857eda85903d5949
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('helppublish', 'blog'), 'blog'));
37 if (!empty($CFG->usetags)) {
38 $mform->addElement('header', 'tagshdr', get_string('tags', 'blog'));
39 $mform->createElement('select', 'otags', get_string('otags','blog'));
41 $js_escape = array(
42 "\r" => '\r',
43 "\n" => '\n',
44 "\t" => '\t',
45 "'" => "\\'",
46 '"' => '\"',
47 '\\' => '\\\\'
50 $otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'blog'), array(), 'size="5"');
51 $otagsselEl->setMultiple(true);
52 $this->otags_select_setup();
54 if (has_capability('moodle/blog:manageofficialtags', $sitecontext)){
55 $deleteotagsmsg = strtr(get_string('deleteotagswarn', 'blog'), $js_escape);
56 $mform->registerNoSubmitButton('deleteotags');
57 $mform->addElement('submit', 'deleteotags', get_string('delete'),
58 array('onclick'=>"return confirm('$deleteotagsmsg');"));
59 $mform->disabledIf('deleteotags', 'otags[]', 'noitemselected');
60 $mform->setAdvanced('deleteotags');
62 $mform->registerNoSubmitButton('addotags');
63 $otagsgrp = array();
64 $otagsgrp[] =& $mform->createElement('text', 'otagsadd', get_string('addotags', 'blog'));
65 $otagsgrp[] =& $mform->createElement('submit', 'addotags', get_string('add'));
66 $mform->addGroup($otagsgrp, 'otagsgrp', get_string('addotags','blog'), array(' '), false);
67 $mform->setType('otagsadd', PARAM_NOTAGS);
68 $mform->setAdvanced('otagsgrp');
71 $mform->addElement('textarea', 'ptags', get_string('ptags', 'blog'), array('cols'=>'40', 'rows'=>'5'));
72 $mform->setType('ptagsadd', PARAM_NOTAGS);
75 $this->add_action_buttons();
77 $mform->addElement('hidden', 'action');
78 $mform->setType('action', PARAM_ACTION);
79 $mform->setDefault('action', '');
81 $mform->addElement('hidden', 'courseid');
82 $mform->setType('courseid', PARAM_INT);
84 $mform->addElement('hidden', 'id');
85 $mform->setType('id', PARAM_INT);
86 $mform->setDefault('id', 0);
90 /**
91 * This function sets up options of otag select element. This is called from definition and also
92 * after adding new official tags with the add tag button.
95 function otags_select_setup(){
96 global $CFG;
97 $mform =& $this->_form;
98 if ($otagsselect =& $mform->getElement('otags')) {
99 $otagsselect->removeOptions();
101 if ($otags = get_records_sql_menu('SELECT id, name from '.$CFG->prefix.'tag WHERE tagtype=\'official\' ORDER by name ASC')){
102 $otagsselect->loadArray($otags);
103 } else {
104 // removing this causes errors
105 //$mform->removeElement('otags');