Example #1
0
 function MoodleQuickForm_htmleditor($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
 {
     parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
     // set the options, do not bother setting bogus ones
     if (is_array($options)) {
         foreach ($options as $name => $value) {
             if (isset($this->_options[$name])) {
                 if (is_array($value) && is_array($this->_options[$name])) {
                     $this->_options[$name] = @array_merge($this->_options[$name], $value);
                 } else {
                     $this->_options[$name] = $value;
                 }
             }
         }
     }
     if ($this->_options['canUseHtmlEditor'] == 'detect') {
         $this->_options['canUseHtmlEditor'] = can_use_html_editor();
     }
     if ($this->_options['canUseHtmlEditor']) {
         $this->_type = 'htmleditor';
         //$this->_elementTemplateType='wide';
     } else {
         $this->_type = 'textarea';
     }
     $this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor'];
 }
 function display_add_field($recordid = 0)
 {
     global $CFG, $DB;
     $text = '';
     $format = 0;
     if ($recordid) {
         if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
             $text = $content->content;
             $format = $content->content1;
         }
     }
     $str = '<div title="' . $this->field->description . '">';
     if (can_use_html_editor()) {
         // Show a rich text html editor.
         $str .= $this->gen_textarea(true, $text);
         $str .= helpbutton("richtext2", get_string("helprichtext"), 'moodle', true, true, '', true);
         $str .= '<input type="hidden" name="field_' . $this->field->id . '_content1' . '" value="' . FORMAT_HTML . '" />';
     } else {
         // Show a normal textarea. Also let the user specify the format to be used.
         $str .= $this->gen_textarea(false, $text);
         // Get the available text formats for this field.
         $formatsForField = format_text_menu();
         $str .= '<br />';
         $str .= choose_from_menu($formatsForField, 'field_' . $this->field->id . '_content1', $format, 'choose', '', '', true);
         $str .= helpbutton('textformat', get_string('helpformatting'), 'moodle', true, false, '', true);
     }
     $str .= '</div>';
     return $str;
 }
 function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options)
 {
     global $CFG;
     static $htmleditorused = false;
     $answers =& $question->options->answers;
     $readonly = empty($options->readonly) ? '' : 'disabled="disabled"';
     // Only use the rich text editor for the first essay question on a page.
     $usehtmleditor = can_use_html_editor() && !$htmleditorused;
     $formatoptions = new stdClass();
     $formatoptions->noclean = true;
     $formatoptions->para = false;
     $inputname = $question->name_prefix;
     $stranswer = get_string("answer", "quiz") . ': ';
     /// set question text and media
     $questiontext = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course);
     $image = get_question_image($question);
     // feedback handling
     $feedback = '';
     if ($options->feedback && !empty($answers)) {
         foreach ($answers as $answer) {
             $feedback = format_text($answer->feedback, '', $formatoptions, $cmoptions->course);
         }
     }
     // get response value
     if (isset($state->responses[''])) {
         $value = stripslashes_safe($state->responses['']);
     } else {
         $value = "";
     }
     // answer
     if (empty($options->readonly)) {
         // the student needs to type in their answer so print out a text editor
         $answer = print_textarea($usehtmleditor, 18, 80, 630, 400, $inputname, $value, $cmoptions->course, true);
     } else {
         // it is read only, so just format the students answer and output it
         $safeformatoptions = new stdClass();
         $safeformatoptions->para = false;
         $answer = format_text($value, FORMAT_MOODLE, $safeformatoptions, $cmoptions->course);
         $answer = '<div class="answerreview">' . $answer . '</div>';
     }
     include "{$CFG->dirroot}/question/type/essay/display.html";
     if ($usehtmleditor && empty($options->readonly)) {
         use_html_editor($inputname);
         $htmleditorused = true;
     }
 }
Example #4
0
 function display_add_field($recordid = 0)
 {
     global $CFG, $DB, $OUTPUT, $PAGE;
     $text = '';
     $format = 0;
     $str = '<div title="' . $this->field->description . '">';
     editors_head_setup();
     $options = array();
     $options['trusttext'] = false;
     $options['forcehttps'] = false;
     $options['subdirs'] = false;
     $options['maxfiles'] = 0;
     $options['maxbytes'] = 0;
     $options['changeformat'] = 0;
     $options['noclean'] = false;
     $itemid = $this->field->id;
     $field = 'field_' . $itemid;
     if ($recordid && ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) {
         $text = $content->content;
         $format = $content->content1;
         $text = clean_text($text, $format);
     } else {
         if (can_use_html_editor()) {
             $format = FORMAT_HTML;
         } else {
             $format = FORMAT_PLAIN;
         }
     }
     $editor = editors_get_preferred_editor($format);
     $strformats = format_text_menu();
     $formats = $editor->get_supported_formats();
     foreach ($formats as $fid) {
         $formats[$fid] = $strformats[$fid];
     }
     $editor->use_editor($field, $options);
     $str .= '<div><textarea id="' . $field . '" name="' . $field . '" rows="' . $this->field->param3 . '" cols="' . $this->field->param2 . '">' . s($text) . '</textarea></div>';
     $str .= '<div><select name="' . $field . '_content1">';
     foreach ($formats as $key => $desc) {
         $selected = $format == $key ? 'selected="selected"' : '';
         $str .= '<option value="' . s($key) . '" ' . $selected . '>' . $desc . '</option>';
     }
     $str .= '</select>';
     $str .= '</div>';
     $str .= '</div>';
     return $str;
 }
 /**
  * Method to load necessary editor codes to
  * $CFG->editorsrc array.
  *
  * @todo example code.
  * @param mixed $args Course id or associative array holding course id and editor name.
  */
 function loadeditor($args)
 {
     global $CFG, $USER;
     if (is_array($args)) {
         // If args is an array search keys courseid and name.
         // Name represents editor name to load.
         if (!array_key_exists('courseid', $args)) {
             error("Required variable courseid is missing!");
         }
         if (!array_key_exists('name', $args)) {
             error("Required variable name is missing!");
         }
         $courseid = clean_param($args['courseid'], PARAM_INT);
         $editorname = strtolower(clean_param($args['name'], PARAM_ALPHA));
     } else {
         // If only single argument is passed
         // this must be course id.
         $courseid = clean_param($args, PARAM_INT);
     }
     $htmleditor = !empty($editorname) ? $editorname : intval($USER->htmleditor);
     if (can_use_html_editor()) {
         $CFG->editorsrc = array();
         $editorbaseurl = $CFG->httpswwwroot . '/lib/editor';
         $editorbasedir = $CFG->dirroot . '/lib/editor';
         switch ($htmleditor) {
             case 1:
             case 'htmlarea':
                 array_push($CFG->editorsrc, "{$editorbaseurl}/htmlarea/htmlarea.php?id={$courseid}");
                 array_push($CFG->editorsrc, "{$editorbaseurl}/htmlarea/lang/en.php");
                 $classfile = "{$editorbasedir}/htmlarea/htmlarea.class.php";
                 include_once $classfile;
                 return new htmlarea($courseid);
                 break;
             case 2:
             case 'tinymce':
                 array_push($CFG->editorsrc, "{$editorbaseurl}/tinymce/jscripts/tiny_mce/tiny_mce_gzip.php");
                 array_push($CFG->editorsrc, "{$editorbaseurl}/tinymce/moodledialog.js");
                 $classfile = "{$editorbasedir}/tinymce/tinymce.class.php";
                 include_once $classfile;
                 return new tinymce($courseid);
                 break;
         }
     }
 }
 function definition()
 {
     global $CFG, $USER;
     $mform = $this->_form;
     // Informational paragraph
     $a = (object) array('email' => $USER->email, 'fullname' => fullname($USER, true));
     $mform->addElement('static', '', '', get_string('forward_info_' . ($this->_customdata->onlyselected ? 'selected' : 'all'), 'forumng', $a));
     // Email address
     $mform->addElement('text', 'email', get_string('forward_email', 'forumng'), array('size' => 48));
     $mform->setType('email', PARAM_RAW);
     $mform->setHelpButton('email', array('forward_email', get_string('forward_email', 'forumng'), 'forumng'));
     $mform->addRule('email', get_string('required'), 'required', null, 'client');
     // CC me
     $mform->addElement('checkbox', 'ccme', get_string('forward_ccme', 'forumng'));
     // Email subject
     $mform->addElement('text', 'subject', get_string('subject', 'forumng'), array('size' => 48));
     $mform->setType('subject', PARAM_TEXT);
     $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addRule('subject', get_string('required'), 'required', null, 'client');
     $mform->setDefault('subject', $this->_customdata->subject);
     // Special field just to tell javascript that we're trying to use the
     // html editor
     $mform->addElement('hidden', 'tryinghtmleditor', can_use_html_editor() ? 1 : 0);
     // Email message
     $mform->addElement('htmleditor', 'message', get_string('forward_intro', 'forumng'), array('cols' => 50, 'rows' => 15));
     $mform->setType('message', PARAM_RAW);
     $mform->setHelpButton('message', array('reading', 'writing', 'questions', 'richtext'), false, 'editorhelpbutton');
     // Message format
     $mform->addElement('format', 'format', get_string('format'));
     // Hidden fields
     if ($this->_customdata->postids) {
         foreach ($this->_customdata->postids as $postid) {
             $mform->addElement('hidden', 'selectp' . $postid, 1);
         }
     } else {
         $mform->addElement('hidden', 'all', 1);
     }
     $mform->addElement('hidden', 'd', $this->_customdata->discussionid);
     $mform->addElement('hidden', 'clone', $this->_customdata->cloneid);
     $mform->addElement('hidden', 'postselectform', 1);
     $this->add_action_buttons(true, get_string('forward', 'forumng'));
 }
Example #7
0
 /**
  * Class constructor
  *
  * @param     string    Select name attribute
  * @param     mixed     Label(s) for the select
  * @param     mixed     Either a typical HTML attribute string or an associative array
  * @param     mixed     Either a string returned from can_use_html_editor() or false for no html editor
  *                      default 'detect' tells element to use html editor if it is available.
  * @access    public
  * @return    void
  */
 function MoodleQuickForm_format($elementName = null, $elementLabel = null, $attributes = null, $useHtmlEditor = null)
 {
     if ($elementName == null) {
         $elementName = 'format';
     }
     if ($elementLabel == null) {
         $elementLabel = get_string('format');
     }
     HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
     $this->_type = 'format';
     $this->_useHtmlEditor = $useHtmlEditor;
     if ($this->_useHtmlEditor === null) {
         $this->_useHtmlEditor = can_use_html_editor();
     }
     $this->setPersistantFreeze($this->_useHtmlEditor);
     if ($this->_useHtmlEditor) {
         $this->freeze();
     } else {
         $this->unfreeze();
     }
 }
Example #8
0
/**
 * Edit existing comments
 */
function glossary_comment_edit()
{
    global $CFG, $USER;
    $cid = optional_param('cid', 0, PARAM_INT);
    // Comment ID
    if (!($comment = get_record('glossary_comments', 'id', $cid))) {
        error('Comment is incorrect');
    }
    if (!($entry = get_record('glossary_entries', 'id', $comment->entryid))) {
        error('Entry is incorrect');
    }
    if (!($glossary = get_record('glossary', 'id', $entry->glossaryid))) {
        error('Incorrect glossary');
    }
    if (!($cm = get_coursemodule_from_instance('glossary', $glossary->id))) {
        error('Course Module ID was incorrect');
    }
    if (!($course = get_record('course', 'id', $cm->course))) {
        error('Course is misconfigured');
    }
    require_login($course->id, false, $cm);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    if (!$glossary->allowcomments and !has_capability('mod/glossary:managecomments', $context)) {
        error('You can\'t edit comments in this glossary!');
    }
    if ($comment->userid != $USER->id and !has_capability('mod/glossary:managecomments', $context)) {
        error('You can\'t edit other people\'s comments!');
    }
    $ineditperiod = time() - $comment->timemodified < $CFG->maxeditingtime || $glossary->editalways;
    if ((!has_capability('mod/glossary:comment', $context) or !$ineditperiod) and !has_capability('mod/glossary:managecomments', $context)) {
        error('You can\'t edit this. Time expired!');
    }
    $mform = new mod_glossary_comment_form();
    trusttext_prepare_edit($comment->entrycomment, $comment->format, can_use_html_editor(), $context);
    $mform->set_data(array('cid' => $cid, 'action' => 'edit', 'entrycomment' => $comment->entrycomment, 'format' => $comment->format));
    if ($data = $mform->get_data()) {
        trusttext_after_edit($data->entrycomment, $context);
        $updatedcomment = new object();
        $updatedcomment->id = $cid;
        $updatedcomment->entrycomment = $data->entrycomment;
        $updatedcomment->format = $data->format;
        $updatedcomment->timemodified = time();
        if (!update_record('glossary_comments', $updatedcomment)) {
            error('Could not update this comment');
        } else {
            add_to_log($course->id, 'glossary', 'update comment', "comments.php?id={$cm->id}&amp;eid={$entry->id}", "{$updatedcomment->id}", $cm->id);
        }
        redirect("comments.php?id={$cm->id}&amp;eid={$entry->id}");
    } else {
        glossary_comment_print_header($course, $cm, $glossary, $entry, 'edit');
        $mform->display();
        print_footer($course);
        die;
    }
}
Example #9
0
function ewiki_page_edit_form(&$id, &$data, &$hidden_postdata)
{
    global $ewiki_plugins, $ewiki_config, $moodle_format;
    $content = optional_param('content', '');
    $version = optional_param('version', '');
    $o = '';
    #-- previously edited, or db fetched content
    if ($content || $version) {
        $data = array("version" => $version, "content" => $content);
    } else {
        if (empty($data["version"])) {
            $data["version"] = 1;
        }
        @($data["content"] .= "");
    }
    #-- normalize to DOS newlines
    $data["content"] = str_replace("\r\n", "\n", $data["content"]);
    $data["content"] = str_replace("\r", "\n", $data["content"]);
    $data["content"] = str_replace("\n", "\r\n", $data["content"]);
    $hidden_postdata["version"] =& $data["version"];
    #-- edit textarea/form
    // deleted name="ewiki", can not find the reference, and it's breaking xhtml
    $o .= ewiki_t("EDIT_FORM_1") . '<form method="post" enctype="multipart/form-data" action="' . ewiki_script("edit", $id) . '" ' . ' accept-charset="' . EWIKI_CHARSET . '">' . "\n";
    $o .= '<div>';
    #-- additional POST vars
    foreach ($hidden_postdata as $name => $value) {
        $o .= '<input type="hidden" name="' . $name . '" value="' . $value . '" />' . "\n";
    }
    ($cols = strtok($ewiki_config["edit_box_size"], "x*/,;:")) && ($rows = strtok("x, ")) || ($cols = 70) && ($rows = 15);
    global $ewiki_use_editor, $ewiki_editor_content;
    $ewiki_editor_content = 1;
    if ($ewiki_use_editor) {
        ob_start();
        $usehtmleditor = can_use_html_editor();
        echo '<table><tr><td>';
        if ($usehtmleditor) {
            //clean and convert before editing
            $options = new object();
            $options->smiley = false;
            $options->filter = false;
            $oldtext = format_text(ewiki_format($data["content"]), $moodle_format, $options);
        } else {
            $oldtext = ewiki_format($data["content"]);
        }
        print_textarea($usehtmleditor, $rows, $cols, 680, 400, "content", $oldtext);
        echo '</td></tr></table>';
        $o .= ob_get_contents();
        ob_end_clean();
    } else {
        ##### END MOODLE ADDITION #####
        $o .= '<textarea wrap="soft" id="ewiki_content" name="content" rows="' . $rows . '" cols="' . $cols . '">' . s($data["content"]) . "</textarea>" . $GLOBALS["ewiki_t"]["C"]["EDIT_TEXTAREA_RESIZE_JS"];
        ##### BEGIN MOODLE ADDITION #####
    }
    ##### END MOODLE ADDITION #####
    #-- more <input> elements before the submit button
    if ($pf_a = $ewiki_plugins["edit_form_insert"]) {
        foreach ($pf_a as $pf) {
            $o .= $pf($id, $data, $action);
        }
    }
    ##### BEGIN MOODLE ADDITION (Cancel Editing into Button) #####
    $o .= "\n<br />\n" . '<input type="submit" name="save" value="' . ewiki_t("SAVE") . '" />' . "\n" . '<input type="submit" name="preview" value="' . ewiki_t("PREVIEW") . '" />' . "\n" . '<input type="submit" name="canceledit" value="' . ewiki_t("CANCEL_EDIT") . '" />' . "\n";
    #      . ' &nbsp; <a href="'. ewiki_script("", $id) . '">' . ewiki_t("CANCEL_EDIT") . '</a>';
    ##### END MOODLE ADDITION #####
    #-- additional form elements
    if ($pf_a = $ewiki_plugins["edit_form_append"]) {
        foreach ($pf_a as $pf) {
            $o .= $pf($id, $data, $action);
        }
    }
    $o .= "\n</div></form>\n";
    //   . ewiki_t("EDIT_FORM_2");  // MOODLE DELETION
    return '<div class="edit-box">' . $o . '</div>';
}
Example #10
0
    echo '<li>';
    message_contact_link($user->id, 'add', false, 'discussion.php?id=' . $user->id . '&amp;noframesjs=' . $noframesjs . '&amp;newonly=' . $newonly . '&amp;last=' . $last, true);
    echo '</li><li>';
    message_contact_link($user->id, 'block', false, 'discussion.php?id=' . $user->id . '&amp;noframesjs=' . $noframesjs . '&amp;newonly=' . $newonly . '&amp;last=' . $last, true);
    echo '</li>';
}
echo '<li>';
message_history_link($user->id, 0, false, '', '', 'both');
echo '</li>';
echo '</ul>';
echo '</div>';
echo '</div>';
// class="userinfo"
echo '<div id="send">';
echo '<form id="editing" method="post" action="discussion.php">';
$usehtmleditor = can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0);
echo '<h1><label for="edit-message">' . get_string('sendmessage', 'message') . '</label></h1>';
echo '<div>';
if ($usehtmleditor) {
    print_textarea(true, 8, 34, 100, 100, 'message', $refreshedmessage);
    use_html_editor('message', 'formatblock subscript superscript copy cut paste clean undo redo justifyleft justifycenter justifyright justifyfull lefttoright righttoleft insertorderedlist insertunorderedlist outdent indent inserthorizontalrule createanchor nolink inserttable');
    echo '<input type="hidden" name="format" value="' . FORMAT_HTML . '" />';
} else {
    print_textarea(false, 8, 50, 0, 0, 'message', $refreshedmessage);
    echo '<input type="hidden" name="format" value="' . FORMAT_MOODLE . '" />';
}
echo '</div><div>';
echo '<input type="hidden" name="id" value="' . $user->id . '" />';
echo '<input type="hidden" name="start" value="' . $start . '" />';
echo '<input type="hidden" name="noframesjs" value="' . $noframesjs . '" />';
echo '<input type="hidden" name="last" value="' . time() . '" />';
Example #11
0
     } else {
         $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
     }
     if (!($forum->type == 'news' && !$post->parent && $discussion->timestart > time())) {
         if (time() - $post->created > $CFG->maxeditingtime and !has_capability('mod/forum:editanypost', $modcontext)) {
             error(get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime)));
         }
     }
     if ($post->userid != $USER->id and !has_capability('mod/forum:editanypost', $modcontext)) {
         error("You can't edit other people's posts!");
     }
     // Load up the $post variable.
     $post->edit = $edit;
     $post->course = $course->id;
     $post->forum = $forum->id;
     trusttext_prepare_edit($post->message, $post->format, can_use_html_editor(), $modcontext);
     unset($SESSION->fromdiscussion);
 } else {
     if (!empty($delete)) {
         // User is deleting a post
         if (!($post = forum_get_post_full($delete))) {
             error("Post ID was incorrect");
         }
         if (!($discussion = get_record("forum_discussions", "id", $post->discussion))) {
             error("This post is not part of a discussion!");
         }
         if (!($forum = get_record("forum", "id", $discussion->forum))) {
             error("The forum number was incorrect ({$discussion->forum})");
         }
         if (!($cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course))) {
             error('Could not get the course module for the forum instance.');
	<input type="hidden" name="id_podcast"  value="<?php 
    p($podcast->id);
    ?>
" />
	<input type="hidden" name="tab"         value="view" />
	<input type="hidden" name="action"      value="create" />
	<input type="hidden" name="pubdate"     value="<?php 
    echo podcast_date_format();
    ?>
" />
	<input type="hidden" name="date_html"      value="<?php 
    echo podcast_date_format_html($podcast->lang);
    ?>
" />
	<input type="hidden" name="duration"    value="00:00:00" />
	<input type="hidden" name="length"      value="000000" />
	<input type="submit" value="<?php 
    print_string('add_item', "podcast");
    ?>
" />
</center>
</form>
<?php 
}
// Editer un article
function podcast_edit_item($podcast, $id)
{
    global $CFG;
    global $USER;
    if (!($cm = get_record("course_modules", "id", $id))) {
        error("Course Module ID was incorrect");
    }
    get_item_podcast($podcast, $id);
}
// Afficher la liste des articles e editer
function get_item_podcast($podcast, $id)
{
    global $CFG;
    $browse = get_string('browse', 'podcast');
    $usehtmleditor = can_use_html_editor();
    if ($items = get_records("podcast_structure", "id_podcast", $podcast->id)) {
        foreach ($items as $item) {
            ?>
			<form name="form<?php 
            echo $item->id;
            ?>
" method="post" action="view.php">
			<center>
			<table cellpadding="5">
			<tr>
				<td align="right" valign="top"><b><?php 
            print_string("title", "podcast");
            ?>
</b></td>
				<td align="left"><input type="text" name="title" size="30" value="<?php 
            p(stripslashes($item->title));
            ?>
" />
				<a href="?id=<?php 
            echo $id;
            ?>
&amp;tab=edit&amp;action=delete&amp;id_item=<?php 
            echo $item->id;
            ?>
" style="color:red;font-size:0.8em;font-weight:bold;">
					<?php 
            print_string('delete', "podcast");
            ?>
function print_instruction_form($url, $opt, $label, $selects, $course, $instrid, $edittext = '', $editselect = '', $disabled = false)
{
    // Display Add Instruction Form
    print_box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel');
    $options = array('courseid' => $course->id, 'add' => $opt, 'instrid' => $instrid);
    echo "<table border='0' cellpadding='5' cellspacing='5' width='650px'>";
    echo "<tr><td>";
    print_form_start($url, "post");
    echo "<table border='0' cellpadding='5' cellspacing='5' width='650px'>";
    echo "<tr><th colspan='2' align='left'>Add Instructions</th></tr>";
    echo "<tr>";
    echo "<td>Instruction Type:</td>";
    echo "<td>";
    choose_from_menu($selects, 'typeid', $editselect, 'choose', '', '0', false, $disabled);
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>Instruction Text:</td>";
    echo "<td>";
    //print_textfield ('addkeyword', '','',25);
    //print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name);
    print_textarea(can_use_html_editor(), 15, 45, 371, 167, 'instr', $edittext);
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    print_button($label . " Instructions", $options);
    print_form_end();
    print_single_button($url, array('courseid' => $course->id), "Cancel");
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    print_box_end();
}
Example #14
0
/**
 * Compatibility stub to provide backward compatibility
 *
 * Determines if the HTML editor is enabled.
 * @deprecated Use {@link can_use_html_editor()} instead.
 */
function can_use_richtext_editor()
{
    return can_use_html_editor();
}
Example #15
0
 /**
  * Constructor for the base assignment class
  *
  * Constructor for the base assignment class.
  * If cmid is set create the cm, course, assignment objects.
  * If the assignment is hidden and the user is not a teacher then
  * this prints a page header and notice.
  *
  * @param cmid   integer, the current course module id - not set for new assignments
  * @param assignment   object, usually null, but if we have it we pass it to save db access
  * @param cm   object, usually null, but if we have it we pass it to save db access
  * @param course   object, usually null, but if we have it we pass it to save db access
  */
 function assignment_base($cmid = 'staticonly', $assignment = NULL, $cm = NULL, $course = NULL)
 {
     if ($cmid == 'staticonly') {
         //use static functions only!
         return;
     }
     global $CFG;
     if ($cm) {
         $this->cm = $cm;
     } else {
         if (!($this->cm = get_coursemodule_from_id('assignment', $cmid))) {
             error('Course Module ID was incorrect');
         }
     }
     $this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     if ($course) {
         $this->course = $course;
     } else {
         if (!($this->course = get_record('course', 'id', $this->cm->course))) {
             error('Course is misconfigured');
         }
     }
     if ($assignment) {
         $this->assignment = $assignment;
     } else {
         if (!($this->assignment = get_record('assignment', 'id', $this->cm->instance))) {
             error('assignment ID was incorrect');
         }
     }
     $this->assignment->cmidnumber = $this->cm->id;
     // compatibility with modedit assignment obj
     $this->assignment->courseid = $this->course->id;
     // compatibility with modedit assignment obj
     $this->strassignment = get_string('modulename', 'assignment');
     $this->strassignments = get_string('modulenameplural', 'assignment');
     $this->strsubmissions = get_string('submissions', 'assignment');
     $this->strlastmodified = get_string('lastmodified');
     $this->navigation[] = array('name' => $this->strassignments, 'link' => "index.php?id={$this->course->id}", 'type' => 'activity');
     $this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strassignment . ': ' . format_string($this->assignment->name, true));
     // visibility
     $context = get_context_instance(CONTEXT_MODULE, $cmid);
     if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
         $pagetitle = strip_tags($this->course->shortname . ': ' . $this->strassignment);
         $this->navigation[] = array('name' => $this->strassignment, 'link' => '', 'type' => 'activityinstance');
         $navigation = build_navigation($this->navigation);
         print_header($pagetitle, $this->course->fullname, $this->navigation, "", "", true, '', navmenu($this->course, $this->cm));
         notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}");
     }
     $this->currentgroup = groups_get_activity_group($this->cm);
     /// Set up things for a HTML editor if it's needed
     if ($this->usehtmleditor = can_use_html_editor()) {
         $this->defaultformat = FORMAT_HTML;
     } else {
         $this->defaultformat = FORMAT_MOODLE;
     }
 }
Example #16
0
function forum_restore_mods($mod, $restore)
{
    global $CFG, $DB;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Forum', $restore, $info['MOD']['#'], array('ASSESSTIMESTART', 'ASSESSTIMEFINISH'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the FORUM record structure
        $forum->course = $restore->course_id;
        $forum->type = backup_todb($info['MOD']['#']['TYPE']['0']['#']);
        $forum->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $forum->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        // These get dropped in Moodle 1.7 when the new Roles System gets
        // set up. Therefore they might or not be there depending on whether
        // we are restoring a 1.6+ forum or a 1.7 or later forum backup.
        if (isset($info['MOD']['#']['OPEN']['0']['#'])) {
            $forum->open = backup_todb($info['MOD']['#']['OPEN']['0']['#']);
        }
        if (isset($info['MOD']['#']['ASSESSPUBLIC']['0']['#'])) {
            $forum->assesspublic = backup_todb($info['MOD']['#']['ASSESSPUBLIC']['0']['#']);
        }
        $forum->assessed = backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
        $forum->assesstimestart = backup_todb($info['MOD']['#']['ASSESSTIMESTART']['0']['#']);
        $forum->assesstimefinish = backup_todb($info['MOD']['#']['ASSESSTIMEFINISH']['0']['#']);
        $forum->maxbytes = backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']);
        $forum->scale = backup_todb($info['MOD']['#']['SCALE']['0']['#']);
        $forum->forcesubscribe = backup_todb($info['MOD']['#']['FORCESUBSCRIBE']['0']['#']);
        $forum->trackingtype = backup_todb($info['MOD']['#']['TRACKINGTYPE']['0']['#']);
        $forum->rsstype = backup_todb($info['MOD']['#']['RSSTYPE']['0']['#']);
        $forum->rssarticles = backup_todb($info['MOD']['#']['RSSARTICLES']['0']['#']);
        $forum->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $forum->warnafter = isset($info['MOD']['#']['WARNAFTER']['0']['#']) ? backup_todb($info['MOD']['#']['WARNAFTER']['0']['#']) : '';
        $forum->blockafter = isset($info['MOD']['#']['BLOCKAFTER']['0']['#']) ? backup_todb($info['MOD']['#']['BLOCKAFTER']['0']['#']) : '';
        $forum->blockperiod = isset($info['MOD']['#']['BLOCKPERIOD']['0']['#']) ? backup_todb($info['MOD']['#']['BLOCKPERIOD']['0']['#']) : '';
        $forum->completiondiscussions = isset($info['MOD']['#']['COMPLETIONDISCUSSIONS']['0']['#']) ? backup_todb($info['MOD']['#']['COMPLETIONDISCUSSIONS']['0']['#']) : 0;
        $forum->completionreplies = isset($info['MOD']['#']['COMPLETIONREPLIES']['0']['#']) ? backup_todb($info['MOD']['#']['COMPLETIONREPLIES']['0']['#']) : 0;
        $forum->completionposts = isset($info['MOD']['#']['COMPLETIONPOSTS']['0']['#']) ? backup_todb($info['MOD']['#']['COMPLETIONPOSTS']['0']['#']) : 0;
        //We have to recode the scale field if it's <0 (positive is a grade, not a scale)
        if ($forum->scale < 0) {
            $scale = backup_getid($restore->backup_unique_code, "scale", abs($forum->scale));
            if ($scale) {
                $forum->scale = -$scale->new_id;
            }
        }
        $newid = $DB->insert_record("forum", $forum);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "forum") . " \"" . format_string($forum->name, true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            $forum->id = $newid;
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'forum', $mod->id)) {
                //Restore forum_subscriptions
                $status = forum_subscriptions_restore_mods($newid, $info, $restore);
                if ($status) {
                    //Restore forum_discussions
                    $status = forum_discussions_restore_mods($newid, $info, $restore);
                }
                if ($status) {
                    //Restore forum_read
                    $status = forum_read_restore_mods($newid, $info, $restore);
                }
            }
            // If forum type is single, just recreate the initial discussion/post automatically
            // if it hasn't been created still (because no user data was selected on backup or
            // restore.
            if ($forum->type == 'single' && !$DB->record_exists('forum_discussions', array('forum' => $newid))) {
                //Load forum/lib.php
                require_once $CFG->dirroot . '/mod/forum/lib.php';
                // Calculate the default format
                if (can_use_html_editor()) {
                    $defaultformat = FORMAT_HTML;
                } else {
                    $defaultformat = FORMAT_MOODLE;
                }
                //Create discussion/post data
                $sd = new stdClass();
                $sd->course = $forum->course;
                $sd->forum = $newid;
                $sd->name = $forum->name;
                $sd->intro = $forum->intro;
                $sd->assessed = $forum->assessed;
                $sd->messageformat = $defaultformat;
                $sd->mailnow = false;
                //Insert dicussion/post data
                $sdid = forum_add_discussion($sd, $sd->intro, $forum);
                //Now, mark the initial post of the discussion as mailed!
                if ($sdid) {
                    $DB->set_field('forum_posts', 'mailed', '1', array('discussion' => $sdid));
                }
            }
        } else {
            $status = false;
        }
        // If the backup contained $forum->open and $forum->assesspublic,
        // we need to convert the forum to use Roles. It means the backup
        // was made pre Moodle 1.7.
        if (isset($forum->open) && isset($forum->assesspublic)) {
            $forummod = $DB->get_record('modules', array('name' => 'forum'));
            if (!($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW))) {
                notice('Default teacher role was not found. Roles and permissions ' . 'for all your forums will have to be manually set.');
            }
            if (!($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW))) {
                notice('Default student role was not found. Roles and permissions ' . 'for all your forums will have to be manually set.');
            }
            if (!($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW))) {
                notice('Default guest role was not found. Roles and permissions ' . 'for teacher forums will have to be manually set.');
            }
            require_once $CFG->dirroot . '/mod/forum/lib.php';
            forum_convert_to_roles($forum, $forummod->id, $teacherroles, $studentroles, $guestroles, $restore->mods['forum']->instances[$mod->id]->restored_as_course_module);
        }
    } else {
        $status = false;
    }
    return $status;
}
/**
 * Print the edit message form using the given
 * NanoGong message object.
 **/
function nanogong_print_edit_message_form($id, $nanogong, $nanogong_message)
{
    global $CFG, $USER;
    if (isstudent($nanogong->course) && $nanogong_message->locked) {
        error(get_string("lockerror", "nanogong"), "view.php?id={$id}");
        return;
    }
    $usehtmleditor = can_use_html_editor();
    ?>
    <form method="post">
    <center>
    <h3><?php 
    print_string("editmessage", "nanogong");
    ?>
</h3>
    </center>
    <?php 
    print_simple_box_start("center");
    ?>
    <center>
    <table cellpadding="5">
    <tr valign="top">
        <td align="right"><strong><?php 
    print_string("submitdate", "nanogong");
    ?>
:</strong></td>
        <td align="left"><?php 
    p(userdate($nanogong_message->timestamp));
    ?>
</td>
    </tr>
    <tr valign="top">
        <td align="right"><strong><?php 
    print_string("title", "nanogong");
    ?>
:</strong></td>
        <td align="left"><input id="title" name="title" type="text" maxlength="255" size="80" value="<?php 
    p($nanogong_message->title);
    ?>
" /></td>
    </tr>
    <tr valign="top">
        <td align="right"><strong><?php 
    print_string("audiomessage", "nanogong");
    ?>
:</strong></td>
        <td align="left">
            <applet archive="<?php 
    p("{$CFG->wwwroot}/mod/nanogong/nanogong.jar");
    ?>
"
                id="recorder" name="recorder" code="gong.NanoGong" width="180px" height="40px">
<?php 
    if ($CFG->slasharguments) {
        $url = "{$CFG->wwwroot}/file.php{$nanogong_message->path}";
    } else {
        $url = "{$CFG->wwwroot}/file.php?file={$nanogong_message->path}";
    }
    ?>
                <param name="SoundFileURL" value="<?php 
    p($url);
    ?>
" />
<?php 
    if (!empty($nanogong->color)) {
        ?>
                <param name="Color" value="<?php 
        p($nanogong->color);
        ?>
" />
<?php 
    }
    if (!empty($nanogong->maxduration)) {
        ?>
                <param name="MaxDuration" value="<?php 
        p($nanogong->maxduration);
        ?>
" />
<?php 
    }
    ?>
								<param name="ShowTime" value="true" />
            </applet></td>
    </tr>
    <tr valign="top">
        <td align="right"><strong><?php 
    print_string("textmessage", "nanogong");
    ?>
:</strong></td>
        <td align="left" valign="top">
        <?php 
    print_textarea($usehtmleditor, 20, 60, 680, 400, "message", $nanogong_message->message);
    ?>
        </td>
    </tr>
<?php 
    if (isteacheredit($nanogong->course)) {
        ?>
    <tr valign="top">
        <td align="right"><strong><?php 
        print_string("comments", "nanogong");
        ?>
:</strong></td>
        <td align="left">
        <?php 
        print_textarea($usehtmleditor, 20, 60, 680, 400, "comments", $nanogong_message->comments);
        ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><strong><?php 
        print_string("score", "nanogong");
        ?>
:</strong></td>
        <td align="left"><input type="text" id="score" name="score" size="7" maxsize="7" value="<?php 
        p($nanogong_message->score);
        ?>
" /></td>
    </tr>
    <tr valign="top">
        <td align="right"><strong><?php 
        print_string("locked", "nanogong");
        ?>
:</strong></td>
        <td align="left">
<?php 
        $options = array();
        $options[0] = get_string('no');
        $options[1] = get_string('yes');
        choose_from_menu($options, 'locked', $nanogong_message->locked, '');
        ?>
</td>
    </tr>
<?php 
    }
    ?>
    </table>
    <?php 
    nanogong_print_submit_form_script($nanogong);
    ?>
    <input id="path" name="path" type="hidden" value="<?php 
    p($nanogong_message->path);
    ?>
" />
    <input id="action" name="action" type="hidden" value="editsubmit" />
    <input id="messageid" name="messageid" type="hidden" value="<?php 
    p($nanogong_message->id);
    ?>
" />
    <input type="submit" value="<?php 
    print_string("updatemessage", "nanogong");
    ?>
" onclick="return submitMessage()" />
    <input type="button" value="<?php 
    print_string("cancel");
    ?>
" onclick="location.replace('view.php?id=<?php 
    p($id);
    ?>
')" />
    <br />&nbsp;
    </center>
    <?php 
    print_simple_box_end();
    ?>
    </form>
<?php 
    if ($usehtmleditor) {
        use_html_editor("message");
        if (isteacheredit($nanogong->course)) {
            use_html_editor("comments");
        }
    }
}
Example #18
0
 protected function display_grading_interface($slot, $questionid, $grade, $pagesize, $page, $shownames, $showidnumbers, $order)
 {
     global $OUTPUT;
     // Make sure there is something to do.
     $statecounts = $this->get_question_state_summary(array($slot));
     $counts = null;
     foreach ($statecounts as $record) {
         if ($record->questionid == $questionid) {
             $counts = $record;
             break;
         }
     }
     // If not, redirect back to the list.
     if (!$counts || $counts->{$grade} == 0) {
         redirect($this->list_questions_url(), get_string('alldoneredirecting', 'quiz_grading'));
     }
     if ($pagesize * $page >= $counts->{$grade}) {
         $page = 0;
     }
     list($qubaids, $count) = $this->get_usage_ids_where_question_in_state($grade, $slot, $questionid, $order, $page, $pagesize);
     $attempts = $this->load_attempts_by_usage_ids($qubaids);
     // Prepare the form.
     $hidden = array('id' => $this->cm->id, 'mode' => 'grading', 'slot' => $slot, 'qid' => $questionid, 'page' => $page);
     if (array_key_exists('includeauto', $this->viewoptions)) {
         $hidden['includeauto'] = $this->viewoptions['includeauto'];
     }
     $mform = new quiz_grading_settings($hidden, $counts, $shownames, $showidnumbers);
     // Tell the form the current settings.
     $settings = new stdClass();
     $settings->grade = $grade;
     $settings->pagesize = $pagesize;
     $settings->order = $order;
     $mform->set_data($settings);
     // Print the heading and form.
     echo question_engine::initialise_js();
     $a = new stdClass();
     $a->number = $this->questions[$slot]->number;
     $a->questionname = format_string($counts->name);
     echo $OUTPUT->heading(get_string('gradingquestionx', 'quiz_grading', $a));
     echo html_writer::tag('p', html_writer::link($this->list_questions_url(), get_string('backtothelistofquestions', 'quiz_grading')), array('class' => 'mdl-align'));
     $mform->display();
     // Paging info.
     $a = new stdClass();
     $a->from = $page * $pagesize + 1;
     $a->to = min(($page + 1) * $pagesize, $count);
     $a->of = $count;
     echo $OUTPUT->heading(get_string('gradingattemptsxtoyofz', 'quiz_grading', $a), 3);
     if ($count > $pagesize && $order != 'random') {
         echo $OUTPUT->paging_bar($count, $page, $pagesize, $this->grade_question_url($slot, $questionid, $grade, false));
     }
     // Display the form with one section for each attempt.
     $usehtmleditor = can_use_html_editor();
     $sesskey = sesskey();
     $qubaidlist = implode(',', $qubaids);
     echo html_writer::start_tag('form', array('method' => 'post', 'action' => $this->grade_question_url($slot, $questionid, $grade, $page), 'class' => 'mform', 'id' => 'manualgradingform')) . html_writer::start_tag('div') . html_writer::input_hidden_params(new moodle_url('', array('qubaids' => $qubaidlist, 'slots' => $slot, 'sesskey' => $sesskey)));
     foreach ($qubaids as $qubaid) {
         $attempt = $attempts[$qubaid];
         $quba = question_engine::load_questions_usage_by_activity($qubaid);
         $displayoptions = quiz_get_review_options($this->quiz, $attempt, $this->context);
         $displayoptions->hide_all_feedback();
         $displayoptions->history = question_display_options::HIDDEN;
         $displayoptions->manualcomment = question_display_options::EDITABLE;
         $heading = $this->get_question_heading($attempt, $shownames, $showidnumbers);
         if ($heading) {
             echo $OUTPUT->heading($heading, 4);
         }
         echo $quba->render_question($slot, $displayoptions, $this->questions[$slot]->number);
     }
     echo html_writer::tag('div', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('saveandnext', 'quiz_grading'))), array('class' => 'mdl-align')) . html_writer::end_tag('div') . html_writer::end_tag('form');
 }
Example #19
0
function webquest_print_upload_form($webquest)
{
    global $CFG;
    if (!($course = get_record("course", "id", $webquest->course))) {
        error("Course is misconfigured");
    }
    if (!($cm = get_coursemodule_from_instance("webquest", $webquest->id, $course->id))) {
        error("Course Module ID was incorrect");
    }
    $usehtmleditor = can_use_html_editor();
    echo "<div align=\"center\">";
    echo "<form enctype=\"multipart/form-data\" method=\"POST\" action=\"upload.php\">";
    echo " <input type=\"hidden\" name=\"id\" value=\"{$cm->id}\" />";
    echo "<table celpadding=\"5\" border=\"1\" align=\"center\">\n";
    // now get the submission
    echo "<tr valign=\"top\"><td><b>" . get_string("title", "webquest") . ":</b>\n";
    echo "<input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"\" />\n";
    echo "</td></tr><tr><td><b>" . get_string("submission", "webquest") . ":</b><br />\n";
    print_textarea($usehtmleditor, 25, 70, 630, 400, "description");
    use_html_editor("description");
    echo "</td></tr><tr><td>\n";
    if ($webquest->nattachments) {
        require_once $CFG->dirroot . '/lib/uploadlib.php';
        for ($i = 0; $i < $webquest->nattachments; $i++) {
            $iplus1 = $i + 1;
            $tag[$i] = get_string("attachment", "webquest") . " {$iplus1}:";
        }
        upload_print_form_fragment($webquest->nattachments, null, $tag, false, null, $course->maxbytes, $webquest->maxbytes, false);
    }
    echo "</td></tr></table>\n";
    echo " <input type=\"submit\" name=\"save\" value=\"" . get_string("submitassignment", "webquest") . "\" />";
    echo "</form>";
    echo "</div>";
}
Example #20
0
 private function survey_render($section = 1, $message = '', &$formdata)
 {
     $this->usehtmleditor = null;
     if (empty($section)) {
         $section = 1;
     }
     $numsections = isset($this->questionsbysec) ? count($this->questionsbysec) : 0;
     if ($section > $numsections) {
         $formdata->sec = $numsections;
         echo '<div class=warning>' . get_string('finished', 'questionnaire') . '</div>';
         return false;
         // Invalid section.
     }
     // Check to see if there are required questions.
     $hasrequired = $this->has_required($section);
     // Find out what question number we are on $i New fix for question numbering.
     $i = 0;
     if ($section > 1) {
         for ($j = 2; $j <= $section; $j++) {
             foreach ($this->questionsbysec[$j - 1] as $question) {
                 if ($question->type_id < QUESPAGEBREAK) {
                     $i++;
                 }
             }
         }
     }
     $this->print_survey_start($message, $section, $numsections, $hasrequired, '', 1);
     foreach ($this->questionsbysec[$section] as $question) {
         if ($question->type_id == QUESESSAY) {
             $this->usehtmleditor = can_use_html_editor();
         }
         if ($question->type_id != QUESSECTIONTEXT) {
             $i++;
         }
         $question->survey_display($formdata, $descendantsdata = '', $i, $this->usehtmleditor);
         // Bug MDL-7292 - Don't count section text as a question number.
         // Process each question.
     }
     // End of questions.
     $this->print_survey_end($section, $numsections);
     return;
 }
Example #21
0
 function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options)
 {
     global $CFG;
     $context = $this->get_context_by_category_id($question->category);
     $answers =& $question->options->answers;
     $readonly = empty($options->readonly) ? '' : 'disabled="disabled"';
     // Only use the rich text editor for the first essay question on a page.
     $formatoptions = new stdClass();
     $formatoptions->noclean = true;
     $formatoptions->para = false;
     $inputname = $question->name_prefix;
     $stranswer = get_string("answer", "quiz") . ': ';
     /// set question text and media
     $questiontext = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course);
     // feedback handling
     $feedback = '';
     if ($options->feedback && !empty($answers)) {
         foreach ($answers as $answer) {
             $feedback = quiz_rewrite_question_urls($answer->feedback, 'pluginfile.php', $context->id, 'question', 'answerfeedback', array($state->attempt, $state->question), $answer->id);
             $feedback = format_text($feedback, $answer->feedbackformat, $formatoptions, $cmoptions->course);
         }
     }
     // get response value
     if (isset($state->responses[''])) {
         $value = $state->responses[''];
     } else {
         $value = '';
     }
     // answer
     if (empty($options->readonly)) {
         // the student needs to type in their answer so print out a text editor
         $answer = print_textarea(can_use_html_editor(), 18, 80, 630, 400, $inputname, $value, $cmoptions->course, true);
     } else {
         // it is read only, so just format the students answer and output it
         $safeformatoptions = new stdClass();
         $safeformatoptions->para = false;
         $answer = format_text($value, FORMAT_MOODLE, $safeformatoptions, $cmoptions->course);
         $answer = '<div class="answerreview">' . $answer . '</div>';
     }
     include "{$CFG->dirroot}/question/type/essay/display.html";
 }
Example #22
0
 /**
  * Returns XHTML for the field plus wrapping div
  *
  * @param string $data The current value
  * @param string $query
  * @return string The XHTML output
  */
 public function output_html($data, $query = '')
 {
     global $CFG;
     $CFG->adminusehtmleditor = can_use_html_editor();
     $return = '<div class="form-htmlarea">' . print_textarea($CFG->adminusehtmleditor, 15, 60, 0, 0, $this->get_full_name(), $data, 0, true, 'summary') . '</div>';
     return format_admin_setting($this, $this->visiblename, $return, $this->description, false, '', NULL, $query);
 }
Example #23
0
 /**
  * Constructor for the base assignment class
  *
  * Constructor for the base assignment class.
  * If cmid is set create the cm, course, assignment objects.
  * If the assignment is hidden and the user is not a teacher then
  * this prints a page header and notice.
  *
  * @global object
  * @global object
  * @param int $cmid the current course module id - not set for new assignments
  * @param object $assignment usually null, but if we have it we pass it to save db access
  * @param object $cm usually null, but if we have it we pass it to save db access
  * @param object $course usually null, but if we have it we pass it to save db access
  */
 function assignment_base($cmid = 'staticonly', $assignment = NULL, $cm = NULL, $course = NULL)
 {
     global $COURSE, $DB;
     if ($cmid == 'staticonly') {
         //use static functions only!
         return;
     }
     global $CFG;
     if ($cm) {
         $this->cm = $cm;
     } else {
         if (!($this->cm = get_coursemodule_from_id('assignment', $cmid))) {
             print_error('invalidcoursemodule');
         }
     }
     $this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     if ($course) {
         $this->course = $course;
     } else {
         if ($this->cm->course == $COURSE->id) {
             $this->course = $COURSE;
         } else {
             if (!($this->course = $DB->get_record('course', array('id' => $this->cm->course)))) {
                 print_error('invalidid', 'assignment');
             }
         }
     }
     if ($assignment) {
         $this->assignment = $assignment;
     } else {
         if (!($this->assignment = $DB->get_record('assignment', array('id' => $this->cm->instance)))) {
             print_error('invalidid', 'assignment');
         }
     }
     $this->assignment->cmidnumber = $this->cm->id;
     // compatibility with modedit assignment obj
     $this->assignment->courseid = $this->course->id;
     // compatibility with modedit assignment obj
     $this->strassignment = get_string('modulename', 'assignment');
     $this->strassignments = get_string('modulenameplural', 'assignment');
     $this->strsubmissions = get_string('submissions', 'assignment');
     $this->strlastmodified = get_string('lastmodified');
     $this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strassignment . ': ' . format_string($this->assignment->name, true));
     // visibility handled by require_login() with $cm parameter
     // get current group only when really needed
     /// Set up things for a HTML editor if it's needed
     if ($this->usehtmleditor = can_use_html_editor()) {
         $this->defaultformat = FORMAT_HTML;
     } else {
         $this->defaultformat = FORMAT_MOODLE;
     }
 }
}
/// Print the header stuff
admin_externalpage_print_header();
/// Print the appropriate form
if (file_exists($filename)) {
    // We are in maintenance mode
    echo '<div style="margin-left:auto;margin-right:auto">';
    echo '<form action="maintenance.php" method="post">';
    echo '<input type="hidden" name="action" value="disable" />';
    echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
    echo '<p><input type="submit" value="' . get_string('disable') . '" /></p>';
    echo '</form>';
    echo '</div>';
} else {
    // We are not in maintenance mode
    $usehtmleditor = can_use_html_editor();
    echo '<div style="text-align:center;margin-left:auto;margin-right:auto">';
    echo '<form action="maintenance.php" method="post">';
    echo '<div>';
    echo '<input type="hidden" name="action" value="enable" />';
    echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
    echo '<p><input type="submit" value="' . get_string('enable') . '" /></p>';
    echo '<p>' . get_string('optionalmaintenancemessage', 'admin') . ':</p>';
    echo '<table><tr><td>';
    print_textarea($usehtmleditor, 20, 50, 600, 400, "text");
    echo '</td></tr></table>';
    echo '</div>';
    echo '</form>';
    echo '</div>';
    if ($usehtmleditor) {
        use_html_editor();
Example #25
0
    function display_add_field($recordid=0) {
        global $CFG, $DB, $OUTPUT, $PAGE;

        $text   = '';
        $format = 0;

        $str = '<div title="'.$this->field->description.'">';

        editors_head_setup();
        $options = $this->get_options();

        $itemid = $this->field->id;
        $field = 'field_'.$itemid;

        if ($recordid && $content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))){
            $format = $content->content1;
            $text = clean_text($content->content, $format);
            $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text);
        } else {
            $draftitemid = file_get_unused_draft_itemid();
            if (can_use_html_editor()) {
                $format = FORMAT_HTML;
            } else {
                $format = FORMAT_PLAIN;
            }
        }

        // get filepicker info
        //
        $fpoptions = array();
        if ($options['maxfiles'] != 0 ) {
            $args = new stdClass();
            // need these three to filter repositories list
            $args->accepted_types = array('web_image');
            $args->return_types = (FILE_INTERNAL | FILE_EXTERNAL);
            $args->context = $this->context;
            $args->env = 'filepicker';
            // advimage plugin
            $image_options = initialise_filepicker($args);
            $image_options->context = $this->context;
            $image_options->client_id = uniqid();
            $image_options->maxbytes = $options['maxbytes'];
            $image_options->env = 'editor';
            $image_options->itemid = $draftitemid;

            // moodlemedia plugin
            $args->accepted_types = array('video', 'audio');
            $media_options = initialise_filepicker($args);
            $media_options->context = $this->context;
            $media_options->client_id = uniqid();
            $media_options->maxbytes  = $options['maxbytes'];
            $media_options->env = 'editor';
            $media_options->itemid = $draftitemid;

            // advlink plugin
            $args->accepted_types = '*';
            $link_options = initialise_filepicker($args);
            $link_options->context = $this->context;
            $link_options->client_id = uniqid();
            $link_options->maxbytes  = $options['maxbytes'];
            $link_options->env = 'editor';
            $link_options->itemid = $draftitemid;

            $fpoptions['image'] = $image_options;
            $fpoptions['media'] = $media_options;
            $fpoptions['link'] = $link_options;
        }

        $editor = editors_get_preferred_editor($format);
        $strformats = format_text_menu();
        $formats =  $editor->get_supported_formats();
        foreach ($formats as $fid) {
            $formats[$fid] = $strformats[$fid];
        }
        $editor->use_editor($field, $options, $fpoptions);
        $str .= '<input type="hidden" name="'.$field.'_itemid" value="'.$draftitemid.'" />';
        $str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="'.$this->field->param3.'" cols="'.$this->field->param2.'">'.s($text).'</textarea></div>';
        $str .= '<div><select name="'.$field.'_content1">';
        foreach ($formats as $key=>$desc) {
            $selected = ($format == $key) ? 'selected="selected"' : '';
            $str .= '<option value="'.s($key).'" '.$selected.'>'.$desc.'</option>';
        }
        $str .= '</select>';
        $str .= '</div>';

        $str .= '</div>';
        return $str;
    }
Example #26
0
 /**
  * Prints questions with comment and grade form underneath each question
  *
  * @return void
  * @todo Finish documenting this function
  **/
 function print_questions_and_form($quiz, $question, $userid, $attemptid, $gradeungraded, $gradenextungraded, $ungraded)
 {
     global $CFG, $DB, $OUTPUT;
     $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     $questions[$question->id] =& $question;
     $usehtmleditor = can_use_html_editor();
     list($select, $from, $where, $params) = $this->attempts_sql($quiz->id, false, $question->id, $userid, $attemptid, $gradeungraded, $gradenextungraded);
     $sort = 'ORDER BY u.firstname, u.lastname, qa.attempt ASC';
     if ($gradenextungraded) {
         $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params, 0, QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE);
     } else {
         $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params);
     }
     if ($attempts) {
         $firstattempt = current($attempts);
         $fullname = fullname($firstattempt);
         if ($gradeungraded) {
             // getting all ungraded attempts
             echo $OUTPUT->heading(get_string('gradingungraded', 'quiz_grading', $ungraded), 3);
         } else {
             if ($gradenextungraded) {
                 // getting next ungraded attempts
                 echo $OUTPUT->heading(get_string('gradingnextungraded', 'quiz_grading', QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE), 3);
             } else {
                 if ($userid) {
                     echo $OUTPUT->heading(get_string('gradinguser', 'quiz_grading', $fullname), 3);
                 } else {
                     if ($attemptid) {
                         $a = new object();
                         $a->fullname = $fullname;
                         $a->attempt = $firstattempt->attempt;
                         echo $OUTPUT->heading(get_string('gradingattempt', 'quiz_grading', $a), 3);
                     } else {
                         echo $OUTPUT->heading(get_string('gradingall', 'quiz_grading', count($attempts)), 3);
                     }
                 }
             }
         }
         // Display the form with one part for each selected attempt
         echo '<form method="post" action="report.php" class="mform" id="manualgradingform">' . '<input type="hidden" name="mode" value="grading" />' . '<input type="hidden" name="q" value="' . $quiz->id . '" />' . '<input type="hidden" name="sesskey" value="' . sesskey() . '" />' . '<input type="hidden" name="questionid" value="' . $question->id . '" />';
         foreach ($attempts as $attempt) {
             // Load the state for this attempt (The questions array was created earlier)
             $states = get_question_states($questions, $quiz, $attempt);
             // The $states array is indexed by question id but because we are dealing
             // with only one question there is only one entry in this array
             $state =& $states[$question->id];
             $options = quiz_get_reviewoptions($quiz, $attempt, $context);
             unset($options->questioncommentlink);
             $options->readonly = 1;
             if (question_state_is_graded($state)) {
                 $gradedclass = 'main highlightgraded';
                 $gradedstring = ' ' . get_string('graded', 'quiz_grading');
             } else {
                 $gradedclass = 'main';
                 $gradedstring = '';
             }
             $a = new object();
             $a->fullname = fullname($attempt, true);
             $a->attempt = $attempt->attempt;
             // print the user name, attempt count, the question, and some more hidden fields
             echo '<div class="boxaligncenter" width="80%" style="clear:left;padding:15px;">';
             echo $OUTPUT->heading(get_string('gradingattempt', 'quiz_grading', $a) . $gradedstring, 3, $gradedclass);
             // Print the question, without showing any previous comment.
             $copy = $state->manualcomment;
             $state->manualcomment = '';
             $options->noeditlink = true;
             print_question($question, $state, '', $quiz, $options);
             // The print the comment and grade fields, putting back the previous comment.
             $state->manualcomment = $copy;
             question_print_comment_fields($question, $state, 'manualgrades[' . $attempt->uniqueid . ']', $quiz, get_string('manualgrading', 'quiz'));
             echo '</div>';
         }
         echo '<div class="boxaligncenter"><input type="submit" value="' . get_string('savechanges') . '" /></div>' . '</form>';
     } else {
         echo $OUTPUT->notification(get_string('noattemptstoshow', 'quiz'));
     }
 }
Example #27
0
        }
    }
    redirect("view.php?id={$cm->id}&amp;mode=entry&amp;hook={$todb->id}");
} else {
    if ($e) {
        $fromdb = get_record("glossary_entries", "id", $e);
        $toform = new object();
        if ($categoriesarr = get_records_menu("glossary_entries_categories", "entryid", $e, '', 'id, categoryid')) {
            $toform->categories = array_values($categoriesarr);
        } else {
            $toform->categories = array(0);
        }
        $toform->concept = $fromdb->concept;
        $toform->definition = $fromdb->definition;
        $toform->format = $fromdb->format;
        trusttext_prepare_edit($toform->definition, $toform->format, can_use_html_editor(), $context);
        $toform->approved = $glossary->defaultapproval or has_capability('mod/glossary:approve', $context);
        $toform->usedynalink = $fromdb->usedynalink;
        $toform->casesensitive = $fromdb->casesensitive;
        $toform->fullmatch = $fromdb->fullmatch;
        $toform->aliases = '';
        $ineditperiod = time() - $fromdb->timecreated < $CFG->maxeditingtime || $glossary->editalways;
        if (!$ineditperiod || $USER->id != $fromdb->userid and !has_capability('mod/glossary:manageentries', $context)) {
            if ($USER->id != $fromdb->userid) {
                print_error('errcannoteditothers', 'glossary');
            } elseif (!$ineditperiod) {
                print_error('erredittimeexpired', 'glossary');
            }
            die;
        }
        if ($aliases = get_records_menu("glossary_alias", "entryid", $e, '', 'id, alias')) {
Example #28
0
    }
    if ($comment->recordid != $record->id) {
        print_error('commentmisconf');
    }
    if (!has_capability('mod/data:managecomments', $context) && $comment->userid != $USER->id) {
        print_error('cannoteditcomment');
    }
} else {
    $comment = false;
}
$mform = new mod_data_comment_form();
$mform->set_data(array('mode' => $mode, 'page' => $page, 'rid' => $record->id, 'commentid' => $commentid));
if ($comment) {
    $format = $comment->format;
    $content = $comment->content;
    if (can_use_html_editor()) {
        $options = new object();
        $options->smiley = false;
        $options->filter = false;
        $content = format_text($content, $format, $options);
        $format = FORMAT_HTML;
    }
    $mform->set_data(array('content' => $content, 'format' => $format));
}
if ($mform->is_cancelled()) {
    redirect('view.php?rid=' . $record->id . '&amp;page=' . $page);
}
switch ($mode) {
    case 'add':
        if (!($formadata = $mform->get_data())) {
            break;
Example #29
0
function question_print_comment_fields($question, $state, $prefix, $cmoptions, $caption = '')
{
    global $QTYPES;
    $idprefix = preg_replace('/[^-_a-zA-Z0-9]/', '', $prefix);
    $otherquestionsinuse = '';
    if (!empty($cmoptions->questions)) {
        $otherquestionsinuse = $cmoptions->questions;
    }
    if (!question_state_is_graded($state) && $QTYPES[$question->qtype]->is_question_manual_graded($question, $otherquestionsinuse)) {
        $grade = '';
    } else {
        $grade = question_format_grade($cmoptions, $state->last_graded->grade);
    }
    $maxgrade = question_format_grade($cmoptions, $question->maxgrade);
    $fieldsize = strlen($maxgrade) - 1;
    if (empty($caption)) {
        $caption = format_string($question->name);
    }
    ?>
<fieldset class="que comment clearfix">
    <legend class="ftoggler"><?php 
    echo $caption;
    ?>
</legend>
    <div class="fcontainer clearfix">
        <div class="fitem">
            <div class="fitemtitle">
                <label for="<?php 
    echo $idprefix;
    ?>
_comment_box"><?php 
    print_string('comment', 'quiz');
    ?>
</label>
            </div>
            <div class="felement fhtmleditor">
                <?php 
    print_textarea(can_use_html_editor(), 15, 60, 630, 300, $prefix . '[comment]', $state->manualcomment, 0, false, $idprefix . '_comment_box');
    ?>
            </div>
        </div>
        <div class="fitem">
            <div class="fitemtitle">
                <label for="<?php 
    echo $idprefix;
    ?>
_grade_field"><?php 
    print_string('grade', 'quiz');
    ?>
</label>
            </div>
            <div class="felement ftext">
                <input type="text" name="<?php 
    echo $prefix;
    ?>
[grade]" size="<?php 
    echo $fieldsize;
    ?>
" id="<?php 
    echo $idprefix;
    ?>
_grade_field" value="<?php 
    echo $grade;
    ?>
" /> / <?php 
    echo $maxgrade;
    ?>
            </div>
        </div>
    </div>
</fieldset>
    <?php 
}
 function definition()
 {
     global $CFG, $USER;
     $mform = $this->_form;
     $params = $this->_customdata['params'];
     $forum = $this->_customdata['forum'];
     $edit = $this->_customdata['edit'];
     $isdiscussion = $this->_customdata['isdiscussion'];
     $isroot = $this->_customdata['isroot'];
     $ispost = $this->_customdata['ispost'];
     $islock = $this->_customdata['islock'];
     $post = $this->_customdata['post'];
     $ajaxversion = $this->_customdata['ajaxversion'];
     $timelimit = isset($this->_customdata['timelimit']) ? $this->_customdata['timelimit'] : 0;
     $draft = isset($this->_customdata['draft']) ? $this->_customdata['draft'] : null;
     if (!$ajaxversion) {
         $ajaxversion = '';
     }
     if ($ajaxversion && !array_key_exists('draft', $params)) {
         $params['draft'] = 0;
     }
     // Keeps track of whether we add a group selector box
     $groupselector = false;
     if ($ispost) {
         $mform->addElement('header', 'general' . $ajaxversion, '');
         if ($edit && ($timelimit || $ajaxversion)) {
             // For AJAX version, add empty string, which will be
             // populated when retrieving each message. Otherwise,
             // display a 'slightly safer' version of the time limit. (30
             // seconds will display as 1 minute before the real one usually;
             // I used 30 seconds becuase it makes more logical, if not
             // practical, sense compared to the option for a 1-minute timeout.)
             $mform->addElement('static', '', '', '<div id="id_editlimit' . $ajaxversion . '">' . ($timelimit ? get_string('editlimited', 'forumng', userdate($timelimit - 30, get_string('strftimetime', 'langconfig'))) : '') . '</div>');
         }
         $quotaleft = $forum->get_remaining_post_quota();
         if (!$edit && $quotaleft != forum::QUOTA_DOES_NOT_APPLY && ($quotaleft <= 2 || $ajaxversion)) {
             $a = (object) array('posts' => $quotaleft, 'period' => $forum->get_max_posts_period(true, true));
             $text = '';
             $script = '';
             if ($ajaxversion) {
                 $script = '<script type="text/javascript">forumng_quotaleft = ' . $quotaleft . '</script>';
             } else {
                 $text = $quotaleft <= 2 ? get_string($quotaleft == 1 ? 'quotaleft_singular' : 'quotaleft_plural', 'forumng', $a) : '';
             }
             $mform->addElement('static', '', '', '<div id="id_postlimit' . $ajaxversion . '">' . $text . $script . '</div>');
         }
         $mform->addElement('text', 'subject', $isroot ? get_string('subject', 'forumng') : get_string('optionalsubject', 'forumng'), array('size' => 48, 'id' => 'id_subject' . $ajaxversion));
         $mform->setType('subject', PARAM_TEXT);
         $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
         if ($isroot) {
             $mform->addRule('subject', get_string('required'), 'required', null, 'client');
             $mform->addRule('subject', get_string('required'), 'regex', '/\\S+/', 'client');
         }
         if ($islock) {
             $mform->setDefault('subject', get_string('locksubject', 'forumng'));
         }
         // Special field just to tell javascript that we're trying to use the
         // html editor
         $mform->addElement('hidden', 'tryinghtmleditor', can_use_html_editor() ? 1 : 0);
         if (class_exists('ouflags')) {
             $message_type = 'htmleditor';
             $message_rows = 30;
             if (ou_get_is_mobile()) {
                 $message_type = 'textarea';
                 $message_rows = 20;
             }
             $mform->addElement($message_type, 'message', get_string('message', 'forumng'), array('cols' => 50, 'rows' => $ajaxversion ? 15 : $message_rows), array('id' => 'id_message' . $ajaxversion));
         } else {
             $mform->addElement('htmleditor', 'message', get_string('message', 'forumng'), array('cols' => 50, 'rows' => $ajaxversion ? 15 : 30), array('id' => 'id_message' . $ajaxversion));
         }
         $mform->setType('message', PARAM_RAW);
         $mform->addRule('message', get_string('required'), 'required', null, 'client');
         $mform->setHelpButton('message', array('reading', 'writing', 'questions', 'richtext'), false, 'editorhelpbutton');
         $showformat = true;
         if ($showformat) {
             $mform->addElement('format', 'format', get_string('format'), array('id' => 'id_format' . $ajaxversion));
         }
         // If you can create attachments...
         if ($forum->can_create_attachments()) {
             $mform->addElement('header', 'id_attachments' . $ajaxversion, '');
             $attachmentlist = '';
             $attachmentnames = array();
             if ($edit && $post) {
                 $attachmentnames = $post->get_attachment_names();
             } else {
                 if ($draft) {
                     $attachmentnames = $draft->get_attachment_names();
                 }
             }
             $filenum = 0;
             foreach ($attachmentnames as $name) {
                 $id = 'id_deletefile' . $ajaxversion . '_' . $filenum++;
                 $attachmentlist .= '<li>' . htmlspecialchars($name) . ' ' . '<span class="forumng-deletefilecheck">' . '<input type="checkbox" name="deletefile[]" value="' . htmlspecialchars($name) . '" id="' . $id . '" /> <label for="' . $id . '">' . get_string('delete') . '</label></span></li>';
             }
             if (!$ajaxversion) {
                 // ...the non-AJAX version shows boxes for three new ones
                 // and a 'Delete existing' checkbox with the existing info
                 if ($edit || $draft) {
                     if ($attachmentlist) {
                         $mform->addElement('static', '', get_string('existingattachments', 'forumng'), '<ul class="forumng-form-attachments">' . $attachmentlist . '</ul>');
                     }
                 }
                 $this->set_upload_manager($forum->get_upload_manager());
                 for ($k = 0; $k < 3; $k++) {
                     $mform->addElement('file', 'attachment_' . $k, get_string('attachmentnum', 'forumng', $k + 1), array('id' => 'id_attachment' . $ajaxversion . '_' . $k));
                     if (!$k) {
                         $mform->setHelpButton('attachment_' . $k, array('attachment', get_string('attachment', 'forumng'), 'forumng'));
                     }
                 }
             } else {
                 // ...the AJAX version includes a magic AJAX attachments
                 // component
                 // Create a playspace for editing attachments. (Note that
                 // this logic would NOT work in a normal form which can
                 // be submitted more than once.)
                 if (!$attachmentlist) {
                     $attachmentlist = '<li class="forumng-deleteme"></li>';
                 }
                 $mform->addElement('static', '', '<span class="forumng-attachments-label">' . get_string('attachments', 'forumng') . '</span>', '<ul class="forumng-form-attachments">' . $attachmentlist . '</ul>');
                 $mform->addElement('hidden', 'attachmentplayspace', 0);
                 $mform->setType('attachmentplayspace', PARAM_SEQUENCE);
             }
         }
         // If you can mail now, we show this option
         $mform->addElement('header', 'id_importance' . $ajaxversion, '');
         $attachmentlist = '';
         if (!$edit && $forum->can_mail_now()) {
             $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forumng'));
             $mform->setHelpButton('mailnow', array('mailnow', get_string('mailnow', 'forumng'), 'forumng'));
         }
         if ($forum->can_set_important() && !$isdiscussion && !$isroot && !$islock) {
             $mform->addElement('checkbox', 'setimportant', get_string('setimportant', 'forumng'));
         }
     }
     // Additional options apply only to discussion
     if ($isdiscussion && $forum->can_manage_discussions()) {
         // Restrict to specific time period
         $mform->addElement('header', 'id_displayperiod', get_string('displayperiod', 'forumng'));
         $mform->addElement('date_selector', 'timestart', get_string('timestart', 'forumng'), array('optional' => true));
         $mform->setHelpButton('timestart', array('displayperiod', get_string('displayperiod', 'forumng'), 'forumng'));
         $mform->addElement('date_selector', 'timeend', get_string('timeend', 'forumng'), array('optional' => true));
         // Discussion options...
         $mform->addElement('header', 'id_stickyoptions', get_string('discussionoptions', 'forumng'));
         // Sticky discussion
         $options = array();
         $options[0] = get_string('sticky_no', 'forumng');
         $options[1] = get_string('sticky_yes', 'forumng');
         $mform->addElement('select', 'sticky', get_string('sticky', 'forumng'), $options);
         $mform->setHelpButton('sticky', array('sticky', get_string('sticky', 'forumng'), 'forumng'));
         // Group
         if ($forum->get_group_mode()) {
             // Group ID comes from the post (if provided) or the params
             if ($post) {
                 $groupid = $post->get_discussion()->get_group_id();
             } else {
                 $groupid = $params['group'];
             }
             // Display as static or dropdown
             if (has_capability('moodle/site:accessallgroups', $forum->get_context())) {
                 // Users with 'access all groups' can move discussions, so
                 // show dropdown with all groups
                 $cm = $forum->get_course_module();
                 $groups = groups_get_all_groups($cm->course, has_capability('moodle/site:accessallgroups', $forum->get_context()) ? 0 : $USER->id, $cm->groupingid);
                 $options = array();
                 $options[forum::ALL_GROUPS] = get_string('allparticipants');
                 foreach ($groups as $group) {
                     $options[$group->id] = format_string($group->name);
                 }
                 $mform->addElement('select', 'group', get_string('group'), $options);
                 $mform->setDefault('group', $groupid);
                 $groupselector = true;
             } else {
                 // Users without 'access all groups' only see the current
                 // group of the discussion
                 if ($groupid == forum::ALL_GROUPS) {
                     $groupname = get_string('allparticipants');
                 } else {
                     $group = groups_get_group($groupid);
                     $groupname = format_string($group->name);
                 }
                 $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
             }
         }
         // Note: Lock/unlock is not available here. When locking a
         // discussion you are prompted to give a reason (=new post).
         // This is available from the discussion page. Unlocking is
         // available from a link in the special 'discussion is locked'
         // message that appears at the top of the discussion page.
     }
     // Post / save changes button
     if ($edit) {
         $submitlabel = get_string('savechanges');
     } else {
         if ($islock) {
             $submitlabel = get_string('lockdiscussionbutton', 'forumng');
         } else {
             if ($isdiscussion) {
                 $submitlabel = get_string('postdiscussion', 'forumng');
             } else {
                 $submitlabel = get_string('postreply', 'forumng');
             }
         }
     }
     $buttonarray = array();
     $buttonarray[] =& $mform->createElement('submit', 'submitbutton', $submitlabel, array('id' => 'id_submitbutton' . $ajaxversion));
     $buttonarray[] =& $mform->createElement('cancel', '', '', array('id' => 'id_cancel' . $ajaxversion));
     if (!$edit) {
         // Can't save draft while editing
         $buttonarray[] =& $mform->createElement('submit', 'savedraft', get_string('savedraft', 'forumng'), array('id' => 'id_savedraft' . $ajaxversion));
     }
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
     // Hidden fields
     foreach ($params as $param => $value) {
         // If there's a group selector, don't duplicate the group param
         if ($param == 'group' && $groupselector) {
             continue;
         }
         $mform->addElement('hidden', $param, $value);
     }
     if (!$ajaxversion) {
         // Prevent multiple submits (except of AJAX version)
         $mform->addElement('hidden', 'random', rand());
     }
 }