2 ///////////////////////////////////////////////////////////////////////////
4 // NOTICE OF COPYRIGHT //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
9 // Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details: //
21 // http://www.gnu.org/copyleft/gpl.html //
23 ///////////////////////////////////////////////////////////////////////////
25 class data_field_textarea
extends data_field_base
{
27 var $type = 'textarea';
29 function data_field_textarea($field=0, $data=0) {
30 parent
::data_field_base($field, $data);
34 function display_add_field($recordid=0) {
41 if ($content = get_record('data_content', 'fieldid', $this->field
->id
, 'recordid', $recordid)) {
42 $text = $content->content
;
43 $format = $content->content1
;
47 $str = '<div title="'.$this->field
->description
.'">';
49 if (can_use_richtext_editor()) {
50 // Show a rich text html editor.
51 $str .= $this->gen_textarea(true, $text);
52 $str .= helpbutton("richtext", get_string("helprichtext"), 'moodle', true, true, '', true);
53 $str .= '<input type="hidden" name="field_' . $this->field
->id
. '_content1' . '" value="' . FORMAT_HTML
. '" />';
56 // Show a normal textarea. Also let the user specify the format to be used.
57 $str .= $this->gen_textarea(false, $text);
59 // Get the available text formats for this field.
60 $formatsForField = format_text_menu();
63 $str .= choose_from_menu($formatsForField, 'field_' . $this->field
->id
.
64 '_content1', $format, 'choose', '', '', true);
66 $str .= helpbutton('textformat', get_string('helpformatting'), 'moodle', true, false, '', true);
73 function display_search_field($value = '') {
74 return '<input type="text" size="16" name="f_'.$this->field
->id
.'" value="'.$value.'" />';
77 function parse_search_field() {
78 return optional_param('f_'.$this->field
->id
, '', PARAM_NOTAGS
);
81 function generate_sql($tablealias, $value) {
82 return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') ";
85 function gen_textarea($usehtmleditor, $text='') {
86 return print_textarea($usehtmleditor, $this->field
->param3
, $this->field
->param2
,
87 '', '', 'field_'.$this->field
->id
, $text, '', true, 'field_' . $this->field
->id
);
91 function print_after_form() {
92 if (can_use_richtext_editor()) {
93 use_html_editor('field_' . $this->field
->id
, '', 'field_' . $this->field
->id
);
98 function update_content($recordid, $value, $name='') {
99 $content = new object;
100 $content->fieldid
= $this->field
->id
;
101 $content->recordid
= $recordid;
103 $names = explode('_', $name);
104 if (!empty($names[2])) {
105 $content->$names[2] = clean_param($value, PARAM_NOTAGS
); // content[1-4]
107 $content->content
= clean_param($value, PARAM_CLEAN
);
110 if ($oldcontent = get_record('data_content','fieldid', $this->field
->id
, 'recordid', $recordid)) {
111 $content->id
= $oldcontent->id
;
112 return update_record('data_content', $content);
114 return insert_record('data_content', $content);