MDL-11515:
[moodle-linuxchix.git] / mod / data / field / textarea / field.class.php
blob92183f06a767f3e0c2e13fbfa213c840c461feb8
1 <?php // $Id$
2 ///////////////////////////////////////////////////////////////////////////
3 // //
4 // NOTICE OF COPYRIGHT //
5 // //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
8 // //
9 // Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
10 // //
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. //
15 // //
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: //
20 // //
21 // http://www.gnu.org/copyleft/gpl.html //
22 // //
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) {
35 global $CFG;
37 $text = '';
38 $format = 0;
40 if ($recordid){
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 . '" />';
55 } else {
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();
61 $str .= '<br />';
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);
68 $str .= '</div>';
69 return $str;
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]
106 } else {
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);
113 } else {
114 return insert_record('data_content', $content);