protected function question_survey_display($data, $descendantsdata, $blankquestionnaire = false)
 {
     $output = '';
     // Essay.
     // Columns and rows default values.
     $cols = 80;
     $rows = 15;
     // Use HTML editor or not?
     if ($this->precise == 0) {
         $canusehtmleditor = true;
         $rows = $this->length == 0 ? $rows : $this->length;
     } else {
         $canusehtmleditor = false;
         // Prior to version 2.6, "precise" was used for rows number.
         $rows = $this->precise > 1 ? $this->precise : $this->length;
     }
     $name = 'q' . $this->id;
     if (isset($data->{'q' . $this->id})) {
         $value = $data->{'q' . $this->id};
     } else {
         $value = '';
     }
     if ($canusehtmleditor) {
         $editor = editors_get_preferred_editor();
         $editor->use_editor($name, questionnaire_get_editor_options($this->context));
         $texteditor = html_writer::tag('textarea', $value, array('id' => $name, 'name' => $name, 'rows' => $rows, 'cols' => $cols));
     } else {
         $editor = FORMAT_PLAIN;
         $texteditor = html_writer::tag('textarea', $value, array('id' => $name, 'name' => $name, 'rows' => $rows, 'cols' => $cols));
     }
     $output .= $texteditor;
     return $output;
 }
Пример #2
0
 public function manual_comment_fields(question_attempt $qa, question_display_options $options)
 {
     $inputname = $qa->get_behaviour_field_name('comment');
     $id = $inputname . '_id';
     list($commenttext, $commentformat) = $qa->get_current_manual_comment();
     $editor = editors_get_preferred_editor($commentformat);
     $strformats = format_text_menu();
     $formats = $editor->get_supported_formats();
     foreach ($formats as $fid) {
         $formats[$fid] = $strformats[$fid];
     }
     $commenttext = format_text($commenttext, $commentformat, array('para' => false));
     $editor->set_text($commenttext);
     $editor->use_editor($id, array('context' => $options->context));
     $commenteditor = html_writer::tag('div', html_writer::tag('textarea', s($commenttext), array('id' => $id, 'name' => $inputname, 'rows' => 10, 'cols' => 60)));
     $editorformat = '';
     if (count($formats) == 1) {
         reset($formats);
         $editorformat .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $inputname . 'format', 'value' => key($formats)));
     } else {
         $editorformat = html_writer::start_tag('div', array('class' => 'fitem'));
         $editorformat .= html_writer::start_tag('div', array('class' => 'fitemtitle'));
         $editorformat .= html_writer::tag('label', get_string('format'), array('for' => 'menu' . $inputname . 'format'));
         $editorformat .= html_writer::end_tag('div');
         $editorformat .= html_writer::start_tag('div', array('class' => 'felement fhtmleditor'));
         $editorformat .= html_writer::select($formats, $inputname . 'format', $commentformat, '');
         $editorformat .= html_writer::end_tag('div');
         $editorformat .= html_writer::end_tag('div');
     }
     $comment = html_writer::tag('div', html_writer::tag('div', html_writer::tag('label', get_string('comment', 'question'), array('for' => $id)), array('class' => 'fitemtitle')) . html_writer::tag('div', $commenteditor, array('class' => 'felement fhtmleditor')), array('class' => 'fitem'));
     $comment .= $editorformat;
     $mark = '';
     if ($qa->get_max_mark()) {
         $currentmark = $qa->get_current_manual_mark();
         $maxmark = $qa->get_max_mark();
         $fieldsize = strlen($qa->format_max_mark($options->markdp)) - 1;
         $markfield = $qa->get_behaviour_field_name('mark');
         $attributes = array('type' => 'text', 'size' => $fieldsize, 'name' => $markfield, 'id' => $markfield);
         if (!is_null($currentmark)) {
             $attributes['value'] = $currentmark;
         }
         $a = new stdClass();
         $a->max = $qa->format_max_mark($options->markdp);
         $a->mark = html_writer::empty_tag('input', $attributes);
         $markrange = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $qa->get_behaviour_field_name('maxmark'), 'value' => $maxmark)) . html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $qa->get_control_field_name('minfraction'), 'value' => $qa->get_min_fraction())) . html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $qa->get_control_field_name('maxfraction'), 'value' => $qa->get_max_fraction()));
         $error = $qa->validate_manual_mark($currentmark);
         $errorclass = '';
         if ($error !== '') {
             $erroclass = ' error';
             $error = html_writer::tag('span', $error, array('class' => 'error')) . html_writer::empty_tag('br');
         }
         $mark = html_writer::tag('div', html_writer::tag('div', html_writer::tag('label', get_string('mark', 'question'), array('for' => $markfield)), array('class' => 'fitemtitle')) . html_writer::tag('div', $error . get_string('xoutofmax', 'question', $a) . $markrange, array('class' => 'felement ftext' . $errorclass)), array('class' => 'fitem'));
     }
     return html_writer::tag('fieldset', html_writer::tag('div', $comment . $mark, array('class' => 'fcontainer clearfix')), array('class' => 'hidden'));
 }
 /**
  * Returns an XHTML string for the editor
  *
  * @param string $data
  * @param string $query
  * @return string XHTML string for the editor
  */
 public function output_html($data, $query = '')
 {
     global $USER;
     $default = $this->get_defaultsetting();
     $defaultinfo = $default;
     if (!is_null($default) and $default !== '') {
         $defaultinfo = "\n" . $default;
     }
     $ctx = context_user::instance($USER->id);
     $editor = editors_get_preferred_editor(FORMAT_HTML);
     $options = $this->get_options();
     $draftitemid = file_get_unused_draft_itemid();
     $component = is_null($this->plugin) ? 'core' : $this->plugin;
     $data = file_prepare_draft_area($draftitemid, $options['context']->id, $component, $this->get_full_name() . '_draftitemid', $draftitemid, $options, $data);
     $fpoptions = array();
     $args = new stdClass();
     // need these three to filter repositories list
     $args->accepted_types = array('web_image');
     $args->return_types = $options['return_types'];
     $args->context = $ctx;
     $args->env = 'filepicker';
     // advimage plugin
     $image_options = initialise_filepicker($args);
     $image_options->context = $ctx;
     $image_options->client_id = uniqid();
     $image_options->maxbytes = $options['maxbytes'];
     $image_options->areamaxbytes = $options['areamaxbytes'];
     $image_options->env = 'editor';
     $image_options->itemid = $draftitemid;
     // moodlemedia plugin
     $args->accepted_types = array('video', 'audio');
     $media_options = initialise_filepicker($args);
     $media_options->context = $ctx;
     $media_options->client_id = uniqid();
     $media_options->maxbytes = $options['maxbytes'];
     $media_options->areamaxbytes = $options['areamaxbytes'];
     $media_options->env = 'editor';
     $media_options->itemid = $draftitemid;
     // advlink plugin
     $args->accepted_types = '*';
     $link_options = initialise_filepicker($args);
     $link_options->context = $ctx;
     $link_options->client_id = uniqid();
     $link_options->maxbytes = $options['maxbytes'];
     $link_options->areamaxbytes = $options['areamaxbytes'];
     $link_options->env = 'editor';
     $link_options->itemid = $draftitemid;
     $fpoptions['image'] = $image_options;
     $fpoptions['media'] = $media_options;
     $fpoptions['link'] = $link_options;
     $editor->use_editor($this->get_id(), $options, $fpoptions);
     return format_admin_setting($this, $this->visiblename, '<div class="form-textarea"><textarea rows="' . $this->rows . '" cols="' . $this->cols . '" id="' . $this->get_id() . '" name="' . $this->get_full_name() . '" spellcheck="true">' . s($data) . '</textarea></div>
     <input value="' . $draftitemid . '" name="' . $this->get_full_name() . '_draftitemid" type="hidden" />', $this->description, true, '', $defaultinfo, $query);
 }
Пример #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;
 }
Пример #5
0
 /**
  * Tests the installation of event handlers from file
  */
 public function test_get_preferred_editor()
 {
     // Fake a user agent.
     $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.21     5 Safari/534.10';
     $enabled = editors_get_enabled();
     // Array assignment is always a clone.
     $editors = $enabled;
     $first = array_shift($enabled);
     // Get the default editor which should be the first in the list.
     set_user_preference('htmleditor', '');
     $preferred = editors_get_preferred_editor();
     $this->assertEquals($first, $preferred);
     foreach ($editors as $key => $editor) {
         // User has set a preference for a specific editor.
         set_user_preference('htmleditor', $key);
         $preferred = editors_get_preferred_editor();
         $this->assertEquals($editor, $preferred);
     }
 }
Пример #6
0
 public function response_area_input($name, $qa, $step, $lines, $context)
 {
     global $CFG;
     require_once $CFG->dirroot . '/repository/lib.php';
     $inputname = $qa->get_qt_field_name($name);
     $responseformat = $step->get_qt_var($name . 'format');
     $id = $inputname . '_id';
     $editor = editors_get_preferred_editor($responseformat);
     $strformats = format_text_menu();
     $formats = $editor->get_supported_formats();
     foreach ($formats as $fid) {
         $formats[$fid] = $strformats[$fid];
     }
     list($draftitemid, $reponse) = $this->prepare_response_for_editing($name, $step, $context);
     $editor->use_editor($id, $this->get_editor_options($context), $this->get_filepicker_options($context, $draftitemid));
     $output = '';
     $output .= html_writer::start_tag('div', array('class' => $this->class_name() . ' qtype_essay_response'));
     $output .= html_writer::tag('div', html_writer::tag('textarea', s($reponse), array('id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60)));
     $output .= html_writer::start_tag('div');
     if (count($formats == 1)) {
         reset($formats);
         $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $inputname . 'format', 'value' => key($formats)));
     } else {
         $output .= html_writer::select($formats, $inputname . 'format', $responseformat, '');
     }
     $output .= html_writer::end_tag('div');
     $output .= $this->filepicker_html($inputname, $draftitemid);
     $output .= html_writer::end_tag('div');
     return $output;
 }
Пример #7
0
    data_generate_default_template($data, 'singletemplate');
    data_generate_default_template($data, 'listtemplate');
    data_generate_default_template($data, 'addtemplate');
    data_generate_default_template($data, 'asearchtemplate');
    //Template for advanced searches.
    data_generate_default_template($data, 'rsstemplate');
}
editors_head_setup();
$format = FORMAT_HTML;
if ($mode === 'csstemplate' or $mode === 'jstemplate') {
    $disableeditor = true;
}
if ($disableeditor) {
    $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];
}
$options = array();
$options['trusttext'] = false;
$options['forcehttps'] = false;
$options['subdirs'] = false;
$options['maxfiles'] = 0;
$options['maxbytes'] = 0;
$options['changeformat'] = 0;
$options['noclean'] = false;
echo '<form id="tempform" action="templates.php?d=' . $data->id . '&amp;mode=' . $mode . '" method="post">';
echo '<div>';
Пример #8
0
    /**
     * Returns HTML for editor form element.
     *
     * @return string
     */
    function toHtml() {
        global $CFG, $PAGE, $OUTPUT;
        require_once($CFG->dirroot.'/repository/lib.php');

        if ($this->_flagFrozen) {
            return $this->getFrozenHtml();
        }

        $ctx = $this->_options['context'];

        $id           = $this->_attributes['id'];
        $elname       = $this->_attributes['name'];

        $subdirs      = $this->_options['subdirs'];
        $maxbytes     = $this->_options['maxbytes'];
        $areamaxbytes = $this->_options['areamaxbytes'];
        $maxfiles     = $this->_options['maxfiles'];
        $changeformat = $this->_options['changeformat']; // TO DO: implement as ajax calls

        $text         = $this->_values['text'];
        $format       = $this->_values['format'];
        $draftitemid  = $this->_values['itemid'];

        // security - never ever allow guest/not logged in user to upload anything
        if (isguestuser() or !isloggedin()) {
            $maxfiles = 0;
        }

        $str = $this->_getTabs();
        $str .= '<div>';

        $editor = editors_get_preferred_editor($format);
        $strformats = format_text_menu();
        $formats =  $editor->get_supported_formats();
        foreach ($formats as $fid) {
            $formats[$fid] = $strformats[$fid];
        }

        // get filepicker info
        //
        $fpoptions = array();
        if ($maxfiles != 0 ) {
            if (empty($draftitemid)) {
                // no existing area info provided - let's use fresh new draft area
                require_once("$CFG->libdir/filelib.php");
                $this->setValue(array('itemid'=>file_get_unused_draft_itemid()));
                $draftitemid = $this->_values['itemid'];
            }

            $args = new stdClass();
            // need these three to filter repositories list
            $args->accepted_types = array('web_image');
            $args->return_types = $this->_options['return_types'];
            $args->context = $ctx;
            $args->env = 'filepicker';
            // advimage plugin
            $image_options = initialise_filepicker($args);
            $image_options->context = $ctx;
            $image_options->client_id = uniqid();
            $image_options->maxbytes = $this->_options['maxbytes'];
            $image_options->areamaxbytes = $this->_options['areamaxbytes'];
            $image_options->env = 'editor';
            $image_options->itemid = $draftitemid;

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

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

            $args->accepted_types = array('.vtt');
            $subtitle_options = initialise_filepicker($args);
            $subtitle_options->context = $ctx;
            $subtitle_options->client_id = uniqid();
            $subtitle_options->maxbytes  = $this->_options['maxbytes'];
            $subtitle_options->areamaxbytes  = $this->_options['areamaxbytes'];
            $subtitle_options->env = 'editor';
            $subtitle_options->itemid = $draftitemid;

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

        //If editor is required and tinymce, then set required_tinymce option to initalize tinymce validation.
        if (($editor instanceof tinymce_texteditor)  && !is_null($this->getAttribute('onchange'))) {
            $this->_options['required'] = true;
        }

        // print text area - TODO: add on-the-fly switching, size configuration, etc.
        $editor->set_text($text);
        $editor->use_editor($id, $this->_options, $fpoptions);

        $rows = empty($this->_attributes['rows']) ? 15 : $this->_attributes['rows'];
        $cols = empty($this->_attributes['cols']) ? 80 : $this->_attributes['cols'];

        //Apply editor validation if required field
        $context = [];
        $context['rows'] = $rows;
        $context['cols'] = $cols;
        $context['frozen'] = $this->_flagFrozen;
        foreach ($this->getAttributes() as $name => $value) {
            $context[$name] = $value;
        }
        $context['hasformats'] = count($formats) > 1;
        $context['formats'] = [];
        if (($format === '' || $format === null) && count($formats)) {
            $format = key($formats);
        }
        foreach ($formats as $formatvalue => $formattext) {
            $context['formats'][] = ['value' => $formatvalue, 'text' => $formattext, 'selected' => ($formatvalue == $format)];
        }
        $context['id'] = $id;
        $context['value'] = $text;
        $context['format'] = $format;

        if (!is_null($this->getAttribute('onblur')) && !is_null($this->getAttribute('onchange'))) {
            $context['changelistener'] = true;
        }

        $str .= $OUTPUT->render_from_template('core_form/editor_textarea', $context);

        // during moodle installation, user area doesn't exist
        // so we need to disable filepicker here.
        if (!during_initial_install() && empty($CFG->adminsetuppending)) {
            // 0 means no files, -1 unlimited
            if ($maxfiles != 0 ) {
                $str .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $elname.'[itemid]',
                        'value' => $draftitemid));

                // used by non js editor only
                $editorurl = new moodle_url("$CFG->wwwroot/repository/draftfiles_manager.php", array(
                    'action'=>'browse',
                    'env'=>'editor',
                    'itemid'=>$draftitemid,
                    'subdirs'=>$subdirs,
                    'maxbytes'=>$maxbytes,
                    'areamaxbytes' => $areamaxbytes,
                    'maxfiles'=>$maxfiles,
                    'ctx_id'=>$ctx->id,
                    'course'=>$PAGE->course->id,
                    'sesskey'=>sesskey(),
                    ));
                $str .= '<noscript>';
                $str .= "<div><object type='text/html' data='$editorurl' height='160' width='600' style='border:1px solid #000'></object></div>";
                $str .= '</noscript>';
            }
        }


        $str .= '</div>';

        return $str;
    }
Пример #9
0
/**
 * Returns users preferred text format.
 * @return int standard text format
 */
function editors_get_preferred_format()
{
    global $USER;
    $editor = editors_get_preferred_editor();
    return $editor->get_preferred_format();
}
Пример #10
0
 private function essay_survey_display($data)
 {
     // Essay.
     $cols = $this->length;
     $rows = $this->precise;
     $str = '';
     // If NO cols or rows specified: use HTML editor (if available in this context).
     if (!$cols || !$rows) {
         $cols = 60;
         $rows = 5;
         $canusehtmleditor = $this->usehtmleditor;
         // If cols & rows specified, do not use HTML editor but plain text box
         // use default (60 cols and 5 rows) OR user-specified values.
     } else {
         $canusehtmleditor = false;
     }
     $name = 'q' . $this->id;
     if (isset($data->{'q' . $this->id})) {
         $value = $data->{'q' . $this->id};
     } else {
         $value = '';
     }
     if ($canusehtmleditor) {
         $editor = editors_get_preferred_editor();
         $editor->use_editor($name, questionnaire_get_editor_options($this->context));
         $texteditor = html_writer::tag('textarea', $value, array('id' => $name, 'name' => $name, '', ''));
         echo $texteditor;
     } else {
         $str .= '<textarea class="form-textarea" id="edit-' . $name . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . s($value) . '</textarea>';
         echo $str;
     }
 }
Пример #11
0
 /**
  * Returns an XHTML string for the editor
  *
  * @param string $data
  * @param string $query
  * @return string XHTML string for the editor
  */
 public function output_html($data, $query='') {
     $editor = editors_get_preferred_editor(FORMAT_HTML);
     $editor->set_text($data);
     $editor->use_editor($this->get_id(), array('noclean'=>true));
     return parent::output_html($data, $query);
 }
         echo '</fieldset>';
     }
 }
 if (has_capability('mod/questionnaire:message', $context)) {
     // Message editor.
     // Prepare data.
     echo '<fieldset class="clearfix">';
     if ($action == 'sendmessage' && (empty($subject) || empty($message))) {
         echo $OUTPUT->notification(get_string('allfieldsrequired'));
     }
     echo '<legend class="ftoggler">' . get_string('send_message', 'questionnaire') . '</legend>';
     $id = 'message' . '_id';
     $subjecteditor = '&nbsp;&nbsp;&nbsp;<input type="text" id="questionnaire_subject" size="65"
         maxlength="255" name="subject" value="' . $subject . '" />';
     $format = '';
     $editor = editors_get_preferred_editor();
     $editor->use_editor($id, questionnaire_get_editor_options($context));
     $texteditor = html_writer::tag('div', html_writer::tag('textarea', $message, array('id' => $id, 'name' => "message", 'rows' => '10', 'cols' => '60')));
     echo '<input type="hidden" name="format" value="' . FORMAT_HTML . '" />';
     // Print editor.
     $table = new html_table();
     $table->align = array('left', 'left');
     $table->data[] = array('<strong>' . get_string('subject', 'questionnaire') . '</strong>', $subjecteditor);
     $table->data[] = array('<strong>' . get_string('messagebody') . '</strong>', $texteditor);
     echo html_writer::table($table);
     // Send button.
     echo $OUTPUT->box_start('mdl-left');
     echo '<div class="buttons">';
     echo '<input type="submit" name="send_message" value="' . get_string('send', 'questionnaire') . '" />';
     echo '</div>';
     echo $OUTPUT->box_end();
Пример #13
0
 public function advanced_editor()
 {
     // Only output editor if preferred editor is Atto - tiny mce not supported yet.
     editors_head_setup();
     $editor = editors_get_preferred_editor(FORMAT_HTML);
     if (get_class($editor) == 'atto_texteditor') {
         $editor->use_editor('hiddenadvancededitor');
         return '<div id="hiddenadvancededitorcont"><textarea style="display:none" id="hiddenadvancededitor"></textarea></div>';
     }
     return '';
 }
 public static function format_editor_field($datafield, $title, $rows = 3, $cols = 40)
 {
     $content = $datafield->contentparam;
     $format = $datafield->formatparam;
     $context = $datafield->context;
     $field = $datafield->field;
     $itemid = $field->id;
     $name = 'field_' . $itemid;
     editors_head_setup();
     $options = self::get_fileoptions($context);
     if ($itemid) {
         $draftitemid = 0;
         $text = clean_text($field->{$content}, $field->{$format});
         $text = file_prepare_draft_area($draftitemid, $context->id, 'mod_data', 'content', $itemid, $options, $text);
     } else {
         $draftitemid = file_get_unused_draft_itemid();
         $text = '';
     }
     // get filepicker options, if required
     if (empty($options['maxfiles'])) {
         $filepicker_options = array();
     } else {
         $filepicker_options = self::get_filepicker_options($context, $draftitemid, $options['maxbytes']);
     }
     // set up editor
     $editor = editors_get_preferred_editor($field->{$format});
     $editor->set_text($text);
     $editor->use_editor('id_' . $name . '_content', $options, $filepicker_options);
     // format editor
     $output = '';
     $output .= self::format_editor_content($draftitemid, $name, $field->{$content}, $rows, $cols);
     $output .= self::format_editor_formats($editor, $name, $field->{$format});
     return html_writer::tag('div', $output, array('title' => $title));
 }
Пример #15
0
/**
 * Prints a basic textarea field.
 *
 * @deprecated since Moodle 2.0
 *
 * When using this function, you should
 *
 * @global object
 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
 * @param int $rows Number of rows to display  (minimum of 10 when $height is non-null)
 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
 * @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored.
 * @param null $height (Deprecated) Height of the element; if a value is passe, the minimum value for $rows will be 10. Value is otherwise ignored.
 * @param string $name Name to use for the textarea element.
 * @param string $value Initial content to display in the textarea.
 * @param int $obsolete deprecated
 * @param bool $return If false, will output string. If true, will return string value.
 * @param string $id CSS ID to add to the textarea element.
 * @return string|void depending on the value of $return
 */
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
    /// $width and height are legacy fields and no longer used as pixels like they used to be.
    /// However, you can set them to zero to override the mincols and minrows values below.

    // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
    // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');

    global $CFG;

    $mincols = 65;
    $minrows = 10;
    $str = '';

    if ($id === '') {
        $id = 'edit-'.$name;
    }

    if ($usehtmleditor) {
        if ($height && ($rows < $minrows)) {
            $rows = $minrows;
        }
        if ($width && ($cols < $mincols)) {
            $cols = $mincols;
        }
    }

    if ($usehtmleditor) {
        editors_head_setup();
        $editor = editors_get_preferred_editor(FORMAT_HTML);
        $editor->use_editor($id, array('legacy'=>true));
    } else {
        $editorclass = '';
    }

    $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
    if ($usehtmleditor) {
        $str .= htmlspecialchars($value); // needed for editing of cleaned text!
    } else {
        $str .= s($value);
    }
    $str .= '</textarea>'."\n";

    if ($return) {
        return $str;
    }
    echo $str;
}
Пример #16
0
 function toHtml()
 {
     global $CFG, $PAGE;
     require_once $CFG->dirroot . '/repository/lib.php';
     if ($this->_flagFrozen) {
         return $this->getFrozenHtml();
     }
     $ctx = $this->_options['context'];
     $id = $this->_attributes['id'];
     $elname = $this->_attributes['name'];
     $subdirs = $this->_options['subdirs'];
     $maxbytes = $this->_options['maxbytes'];
     $maxfiles = $this->_options['maxfiles'];
     $changeformat = $this->_options['changeformat'];
     // TO DO: implement as ajax calls
     $text = $this->_values['text'];
     $format = $this->_values['format'];
     $draftitemid = $this->_values['itemid'];
     // security - never ever allow guest/not logged in user to upload anything
     if (isguestuser() or !isloggedin()) {
         $maxfiles = 0;
     }
     $str = $this->_getTabs();
     $str .= '<div>';
     $editor = editors_get_preferred_editor($format);
     $strformats = format_text_menu();
     $formats = $editor->get_supported_formats();
     foreach ($formats as $fid) {
         $formats[$fid] = $strformats[$fid];
     }
     // get filepicker info
     //
     $fpoptions = array();
     if ($maxfiles != 0) {
         if (empty($draftitemid)) {
             // no existing area info provided - let's use fresh new draft area
             require_once "{$CFG->libdir}/filelib.php";
             $this->setValue(array('itemid' => file_get_unused_draft_itemid()));
             $draftitemid = $this->_values['itemid'];
         }
         $args = new stdClass();
         // need these three to filter repositories list
         $args->accepted_types = array('image');
         $args->return_types = FILE_INTERNAL | FILE_EXTERNAL;
         $args->context = $ctx;
         $args->env = 'filepicker';
         // advimage plugin
         $image_options = initialise_filepicker($args);
         $image_options->context = $ctx;
         $image_options->client_id = uniqid();
         $image_options->maxbytes = $this->_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 = $ctx;
         $media_options->client_id = uniqid();
         $media_options->maxbytes = $this->_options['maxbytes'];
         $media_options->env = 'editor';
         $media_options->itemid = $draftitemid;
         // advlink plugin
         $args->accepted_types = '*';
         $link_options = initialise_filepicker($args);
         $link_options->context = $ctx;
         $link_options->client_id = uniqid();
         $link_options->maxbytes = $this->_options['maxbytes'];
         $link_options->env = 'editor';
         $link_options->itemid = $draftitemid;
         $fpoptions['image'] = $image_options;
         $fpoptions['media'] = $media_options;
         $fpoptions['link'] = $link_options;
     }
     //If editor is required and tinymce, then set required_tinymce option to initalize tinymce validation.
     if ($editor instanceof tinymce_texteditor && !is_null($this->getAttribute('onchange'))) {
         $this->_options['required'] = true;
     }
     /// print text area - TODO: add on-the-fly switching, size configuration, etc.
     $editor->use_editor($id, $this->_options, $fpoptions);
     $rows = empty($this->_attributes['rows']) ? 15 : $this->_attributes['rows'];
     $cols = empty($this->_attributes['cols']) ? 80 : $this->_attributes['cols'];
     //Apply editor validation if required field
     $editorrules = '';
     if (!is_null($this->getAttribute('onblur')) && !is_null($this->getAttribute('onchange'))) {
         $editorrules = 'onblur="' . htmlspecialchars($this->getAttribute('onblur')) . '" onchange="' . htmlspecialchars($this->getAttribute('onchange')) . '"';
     }
     $str .= '<div><textarea id="' . $id . '" name="' . $elname . '[text]" rows="' . $rows . '" cols="' . $cols . '"' . $editorrules . '>';
     $str .= s($text);
     $str .= '</textarea></div>';
     $str .= '<div>';
     if (count($formats) > 1) {
         $str .= html_writer::select($formats, $elname . '[format]', $format, false);
     } else {
         $str .= html_writer::empty_tag('input', array('name' => $elname . '[format]', 'type' => 'hidden', 'value' => array_pop(array_keys($formats))));
     }
     $str .= '</div>';
     // during moodle installation, user area doesn't exist
     // so we need to disable filepicker here.
     if (!during_initial_install() && empty($CFG->adminsetuppending)) {
         // 0 means no files, -1 unlimited
         if ($maxfiles != 0) {
             $str .= '<input type="hidden" name="' . $elname . '[itemid]" value="' . $draftitemid . '" />';
             // used by non js editor only
             $editorurl = new moodle_url("{$CFG->wwwroot}/repository/draftfiles_manager.php", array('action' => 'browse', 'env' => 'editor', 'itemid' => $draftitemid, 'subdirs' => $subdirs, 'maxbytes' => $maxbytes, 'maxfiles' => $maxfiles, 'ctx_id' => $ctx->id, 'course' => $PAGE->course->id, 'sesskey' => sesskey()));
             $str .= '<noscript>';
             $str .= "<div><object type='text/html' data='{$editorurl}' height='160' width='600' style='border:1px solid #000'></object></div>";
             $str .= '</noscript>';
         }
     }
     $str .= '</div>';
     return $str;
 }
Пример #17
0
 /**
  * Returns an XHTML string for the editor
  *
  * @param string $data
  * @param string $query
  * @return string XHTML string for the editor
  */
 public function output_html($data, $query = '')
 {
     $default = $this->get_defaultsetting();
     $defaultinfo = $default;
     if (!is_null($default) and $default !== '') {
         $defaultinfo = "\n" . $default;
     }
     $editor = editors_get_preferred_editor(FORMAT_HTML);
     $editor->use_editor($this->get_id(), array('noclean' => true));
     return format_admin_setting($this, $this->visiblename, '<div class="form-textarea"><textarea rows="' . $this->rows . '" cols="' . $this->cols . '" id="' . $this->get_id() . '" name="' . $this->get_full_name() . '">' . s($data) . '</textarea></div>', $this->description, true, '', $defaultinfo, $query);
 }
Пример #18
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;
    }
Пример #19
0
    /**
     * Loads the user interface
     */
    function load_ui($mailbox)
    {
        global $CFG;
        $mystrings = array('subject', 'check', 'new' => 'newmail', 'inbox', 'drafts' => 'draft', 'sent' => 'sent', 'bin', 'toapprove', 'approve', 'delete', 'mymailboxes', 'reply', 'move', 'forward', 'print', 'addlabel', 'to', 'cc', 'bcc', 'send', 'save', 'more', 'preferences', 'markread', 'markunread', 'addlabel', 'replytoall' => 'replyall', 'receivecopies', 'subscription', 'none', 'selected');
        foreach ($mystrings as $key => $value) {
            $varname = 'str';
            $varname .= is_numeric($key) ? $value : $key;
            ${$varname} = get_string($value, 'block_jmail');
        }
        $strfirstname = get_string('firstname');
        $strlastname = get_string('lastname');
        $strroles = get_string('roles');
        $strgroups = get_string('groups');
        $strall = get_string('all');
        $strname = get_string('name');
        $stredit = get_string('edit');
        $cansend = $mailbox->cansend;
        $loadingicon = $this->plugin_icon('loading');
        // TODO - Making it works for AJAX added new labels
        $optionslabels = '';
        if ($labels = $mailbox->get_labels()) {
            foreach ($labels as $l) {
                $optionslabels .= '<option value="' . $l->id . '">' . $l->name . '</option>';
            }
        }
        $alphabetfilter = '<a href="#" class="alphabetreset">' . $strall . '</a> ';
        $alphabet = explode(',', get_string('alphabet', 'langconfig'));
        list($groups, $roles) = $mailbox->get_groups_roles();
        $groupsselect = '';
        $rolesselect = '';
        if (count($groups) > 0) {
            $selector = html_writer::select($groups, 'groupselector', '', array('' => 'choosedots'), array('id' => 'groupselector'));
            $groupsselect = '<input type="submit" id="groupselectorb" name="groupselectorb" value="' . $strgroups . '">' . $selector;
        }
        if (count($roles) > 1) {
            $selector = html_writer::select($roles, 'rolesselector', '', null, array('id' => 'rolesselector'));
            $rolesselect = '<input type="submit" id="rolesselectorb" name="rolesselectorb" value="' . $strroles . '">' . $selector;
        }
        foreach ($alphabet as $letter) {
            $alphabetfilter .= '<a href="#" class="alphabet">' . $letter . '</a> ';
        }
        // Main toolbar html
        $toolbar = '<button type="button" id="deleteb" name="deleteb" value="' . $strdelete . '">' . $strdelete . '</button>';
        $toolbar .= '<button type="button" id="editb" name="editb" value="' . $stredit . '">' . $stredit . '</button>';
        if (!empty($mailbox->config->approvemode) and has_capability('block/jmail:approvemessages', $mailbox->blockcontext)) {
            $toolbar .= '<button type="button" id="approveb" name="approveb" value="' . $strapprove . '">' . $strapprove . '</button>';
        }
        if ($cansend) {
            $toolbar .= '<button type="button" id="replyb" name="replyb" value="' . $strreply . '">' . $strreply . '</button>';
            $toolbar .= '<button type="button" id="replytoallb" name="replytoallb" value="' . $strreplytoall . '">' . $strreplytoall . '</button>';
            $toolbar .= '<button type="button" id="forwardb" name="forwardb" value="' . $strforward . '">' . $strforward . '</button>';
        }
        $toolbar .= '<button type="button" id="moveb" name="moveb" value="' . $strmove . '">' . $strmove . '</button>';
        $toolbar .= '    <select id="labelsmenu" name="labelsmenu">
                                <option value="inbox">' . $strinbox . '</option>
                            </select> ';
        $toolbar .= '<button type="button" id="moreb" name="moreb" value="' . $strmore . '">' . $strmore . '</button>';
        $toolbar .= '    <select id="moremenu" name="moremenu">
                                <option value="markread">' . $strmarkread . '</option>
                                <option value="markunread">' . $strmarkunread . '</option>
                            </select> ';
        $toolbar .= '<button type="button" id="printb" name="printb" value="' . $strprint . '">' . $strprint . '</button>';
        // Action buttons html
        $actionbuttons = '<button type="button" id="checkmail" name="checkmail" value="' . $strcheck . '">' . $strcheck . '</button>';
        if ($cansend) {
            $actionbuttons .= '<button type="button" id="newmail" name="newmail" value="' . $strnew . '">' . $strnew . '</button>';
        }
        // Contacts html
        $contacts = '';
        if ($cansend) {
            $contacts = '
                    <div id="contact_list_filter">
                        <div>' . $groupsselect . '</div>
                        <div>' . $rolesselect . '</div>
                        <b>' . $strfirstname . '</b>
                        <div id="firstnamefilter">' . $alphabetfilter . '</div>
                        <b>' . $strlastname . '</b>
                        <div id="lastnamefilter">' . $alphabetfilter . '</div>
                    </div>
                    <div id="contact_list">
                        <div id="contact_list_users">' . $loadingicon . '</div>
                        <div id="selbuttons" style="clear: both">
                            <input type="checkbox" id="selectall">' . $strselected . '
                            <input type="button" class="selto" value=" ' . $strto . ' ">&nbsp;
                            <input type="button" class="selcc" value=" ' . $strcc . ' ">&nbsp;
                            <input type="button" class="selbcc" value=" ' . $strbcc . ' ">
                        </div>
                    </div>
                    ';
        }
        $approvelabel = '';
        if (!empty($mailbox->config->approvemode) and has_capability('block/jmail:approvemessages', $mailbox->blockcontext)) {
            $approvelabel = '
            <li class="inbox">
                <em></em>
                <a href="#" id="toapprove">' . $strtoapprove . '</a>
            </li>';
        }
        // Preferences and labels
        $preferences = '';
        if ($mailbox->canmanagelabels) {
            $preferences .= '<p><img src="' . $this->output->pix_url('add', 'block_jmail') . '"><a href="#" id="addlabel">&nbsp;&nbsp;' . $straddlabel . '</a></p>';
        }
        if ($mailbox->canmanagepreferences) {
            $preferences .= '<p><img src="' . $this->output->pix_url('settings', 'block_jmail') . '"><a href="#" id="preferences">&nbsp;&nbsp;' . $strpreferences . '</a></p>';
        }
        // My mailboxes
        $mymailboxes = '';
        if ($mailboxes = $mailbox::get_my_mailboxes()) {
            $mymailboxes .= '<button type="button" id="mailboxesb" name="mailboxesb" value="' . $strmymailboxes . '">' . $strmymailboxes . '</button>';
            $mymailboxes .= '<select id="mailboxesmenu" name="mailboxesmenu">';
            $counter = 0;
            foreach ($mailboxes as $box) {
                if ($box->id == $mailbox->course->id) {
                    continue;
                }
                $counter++;
                // Apply some pad to the menu elements, we fill with white spaces.
                $boxname = str_replace(' ', "&nbsp;", str_pad(format_string($box->shortname), strlen($strmymailboxes) * 2));
                $mymailboxes .= '<option value="' . $box->id . '">' . $boxname . '</option>';
            }
            $mymailboxes .= '</select> ';
            if (!$counter) {
                $mymailboxes = '';
            }
        }
        // Tinymce editor
        $editor = editors_get_preferred_editor(FORMAT_HTML);
        $editor->use_editor('body');
        // Moodle 2.3 and onwards
        if ($CFG->version >= 2012062500) {
            $script = '//<![CDATA[
                M.yui.add_module({"core_dndupload":{"name":"core_dndupload","fullpath":"' . $CFG->wwwroot . '/lib\\/form\\/dndupload.js","requires":["node","event","json","core_filepicker"]},"form_filemanager":{"name":"form_filemanager","fullpath":"' . $CFG->wwwroot . '/lib\\/form\\/filemanager.js","requires":["core_filepicker","base","io-base","node","json","core_dndupload","panel","resize-plugin","dd-plugin"]}});

                //]]>';
        } else {
            $script = '//<![CDATA[
                M.yui.add_module({"editor_tinymce":{"name":"editor_tinymce","fullpath":"' . $CFG->wwwroot . '/lib\\/editor\\/tinymce\\/module.js","requires":[]},"form_filemanager":{"name":"form_filemanager","fullpath":"' . $CFG->wwwroot . '/lib\\/form\\/filemanager.js","requires":["core_filepicker","base","io","node","json","yui2-button","yui2-container","yui2-layout","yui2-menu","yui2-treeview"]}});

                //]]>';
        }
        $warnings = '';
        if (debugging('', DEBUG_NORMAL) and !empty($CFG->debugdisplay)) {
            $warnings = $this->output->error_text(get_string('errordebugging', 'block_jmail')) . '<br />';
        }
        return '

    <script type="text/javascript">
    ' . $script . '
    </script>
            ' . $warnings . '
            <div id="jmailui">
                <div id="jmailleft">
                    <div id="action_buttons">
                        ' . $actionbuttons . '
                    </div>
                    <div id="search_bar">
                        <input type="text" name="search" id="input_search"><span id="search_button"></span>
                    </div>
                    <div id="label_list">
                        <ul>
                            <li class="inbox">
                                <em></em>
                                <a href="#" id="inbox">' . $strinbox . '</a>
                            </li>
                            <li class="draft">
                                <em></em>
                                <a href="#" id="draft">' . $strdrafts . '</a>
                            </li>
                            <li class="sent">
                                <em></em>
                                <a href="#" id="sent">' . $strsent . '</a>
                            </li>
                            <li class="trash">
                                <em></em>
                                <a href="#" id="trash">' . $strbin . '</a>
                            </li>
                            ' . $approvelabel . '
                        </ul>
                        <div id="user_labels">
                        ' . $loadingicon . '
                        </div>
                        <div id="menulabel">
                        </div>

                        ' . $preferences . '

                        <div id="mymailboxes">
                        ' . $mymailboxes . '
                        </div>

                        <div id="loginfo" style="overflow: auto; width: 100%; height: 200px; border: solid 1px red; display: none">
                        </div>
                    </div>
                </div>
                <div id="jmailcenter">
                    <div id="mailarea">
                        <div id="jmailtoolbar">
                            ' . $toolbar . '
                        </div>
                        <div id="maillist">
                        </div>
                    </div>
                    <div id="mailcontents">
                    </div>
                </div>
                <div id="jmailright">
                    ' . $contacts . '
                </div>
            </div>
            <div id="messagepanel"></div>
            <div id="newemailpanel" style="display: none">
                <div class="hd">' . $strnew . '</div>
                <div id="newemailform" class="bd mform">
                    <div class="fitem">
                        <div class="fitemtitle">
                            <label for="composetoac">' . $strto . '</label>
                        </div>
                        <div class="felement ftext">
                            <input type="text" name="composetoac" id="composetoac" value=""  size="50">
                            <div id="composetolist" class="composelist"></div>
                        </div>
                    </div>
                    <div class="fitem">
                        <div class="fitemtitle">
                            <label for="composeccac">' . $strcc . '</label>
                        </div>
                        <div class="felement ftext">
                            <input type="text" name="composeccac" id="composeccac" value=""  size="50">
                            <div id="composecclist" class="composelist"></div>
                        </div>
                    </div>
                    <div class="fitem">
                        <div class="fitemtitle">
                            <label for="composebccac">' . $strbcc . '</label><br>
                        </div>
                        <div class="felement ftext">
                            <input type="text" name="composebccac" id="composebccac" value=""  size="50">
                            <div id="composebcclist" class="composelist"></div>
                        </div>
                    </div>
                    <div class="fitem">
                        <div class="fitemtitle">
                            <label for="subject">' . $strsubject . '</label><br>
                        </div>
                        <div class="felement ftext">
                            <input type="text" name="subject" id="subject" value=""  size="50">
                        </div>
                    </div>

                    <div id="newemailformremote"></div>

                    <div class="fitem">
                        <div class="fitemtitle">
                        </div>
                        <div class="felement ftext">
                            <input type="button" name="sendbutton" id="sendbutton" value="' . $strsend . '">
                            <input type="button" name="savebutton" id="savebutton" value="' . $strsave . '">
                        </div>
                    </div>

                    <input type="hidden" name="to" id="hiddento">
                    <input type="hidden" name="cc" id="hiddencc">
                    <input type="hidden" name="bcc" id="hiddenbcc">
                </div>
                <div class="ft"></div>
            </div>
            <div id="newlabelpanel" style="display: none">
                <div class="yui3-widget-bd">
                    <form>
                        <fieldset>
                            <p>
                                <label for="id">' . $strname . '</label><br/>
                                <input type="text" name="newlabelname" id="newlabelname" placeholder="" maxlength="16">
                            </p>
                        </fieldset>
                    </form>
                </div>
            </div>
            <div id="preferencespanel" style="display: none">
                <div id="panelContent">
                    <div class="yui3-widget-bd">
                        <form>
                            <fieldset>
                                <p>
                                    <label for="subscription">' . $strsubscription . '</label><br/>
                                    <select name="subscription" id="subscription">
                                        <option value="">' . $strnone . '</option>
                                        <option value="receivecopies">' . $strreceivecopies . '</option>
                                    </select>
                                </p>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
            <div id="rendertarget"></div>
        ';
    }
Пример #20
-1
    function display_add_field($recordid = 0, $formdata = null) {
        global $CFG, $DB, $OUTPUT, $PAGE;

        $text   = '';
        $format = 0;
        $str = '<div title="' . s($this->field->description) . '">';
        $str .= '<label for="field_' . $this->field->id . '" class="accesshide">';
        $str .= html_writer::span($this->field->name);
        if ($this->field->required) {
            $image = html_writer::img($OUTPUT->pix_url('req'), get_string('requiredelement', 'form'),
                                     array('class' => 'req', 'title' => get_string('requiredelement', 'form')));
            $str .= html_writer::div($image, 'inline-req');
        }
        $str .= '</label>';

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

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

        if ($formdata) {
            $fieldname = 'field_' . $this->field->id . '_content1';
            if (isset($formdata->$fieldname)) {
                $format = $formdata->$fieldname;
            } else {
                $format = file_get_unused_draft_itemid();
            }
            $fieldname = 'field_' . $this->field->id . '_itemid';
            if (isset($formdata->$fieldname)) {
                $draftitemid = clean_param($formdata->$fieldname, PARAM_INT);
            } else {
                $draftitemid = file_get_unused_draft_itemid();
            }
            $fieldname = 'field_' . $this->field->id;
            if (isset($formdata->$fieldname)) {
                $text = $formdata->$fieldname;
            }
        } else 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();
            $format = FORMAT_HTML;
        }

        // 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->set_text($text);
        $editor->use_editor($field, $options, $fpoptions);
        $str .= '<input type="hidden" name="'.$field.'_itemid" value="'.s($draftitemid).'" />';
        $str .= '<div class="mod-data-input">';
        $str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="'.$this->field->param3.'" cols="'.$this->field->param2.'" spellcheck="true">'.s($text).'</textarea></div>';
        $str .= '<div><label class="accesshide" for="' . $field . '_content1">' . get_string('format') . '</label>';
        $str .= '<select id="' . $field . '_content1" 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>';
        $str .= '</div>';
        return $str;
    }