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. // // //
15 // This program is distributed in the hope that it will be useful, //
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
18 // GNU General Public License for more details: //
20 // http://www.gnu.org/copyleft/gpl.html //
22 ///////////////////////////////////////////////////////////////////////////
24 require_once($CFG->dirroot.'/lib/filelib.php');
25 require_once($CFG->dirroot.'/repository/lib.php');
27 class data_field_textarea extends data_field_base {
29 var $type = 'textarea';
31 function display_add_field($recordid=0) {
32 global $CFG, $DB, $OUTPUT, $PAGE;
37 $str = '<div title="'.$this->field->description.'">';
42 $options['trusttext'] = false;
43 $options['forcehttps'] = false;
44 $options['subdirs'] = false;
45 $options['maxfiles'] = 0;
46 $options['maxbytes'] = 0;
47 $options['changeformat'] = 0;
48 $options['noclean'] = false;
50 $itemid = $this->field->id;
51 $field = 'field_'.$itemid;
53 if ($recordid && $content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))){
54 $text = $content->content;
55 $format = $content->content1;
56 } else if (can_use_html_editor()) {
57 $format = FORMAT_HTML;
59 $format = FORMAT_PLAIN;
62 $editor = get_preferred_texteditor($format);
63 $strformats = format_text_menu();
64 $formats = $editor->get_supported_formats();
65 foreach ($formats as $fid) {
66 $formats[$fid] = $strformats[$fid];
68 $editor->use_editor($field, $options);
69 $str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="15" cols="80">'.s($text).'</textarea></div>';
70 $str .= '<div><select name="'.$field.'_content1">';
71 foreach ($formats as $key=>$desc) {
72 $selected = ($format == $key) ? 'selected="selected"' : '';
73 $str .= '<option value="'.s($key).'" '.$selected.'>'.$desc.'</option>';
76 $str .= $OUTPUT->help_icon('textformat', get_string('helpformatting'), 'moodle');
84 function display_search_field($value = '') {
85 return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';
88 function parse_search_field() {
89 return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
92 function generate_sql($tablealias, $value) {
95 $ILIKE = $DB->sql_ilike();
99 $name = "df_picture_$i";
100 return array(" ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content $ILIKE :$name) ", array($name=>"%$value%"));
103 function print_after_form() {
107 function update_content($recordid, $value, $name='') {
110 $content = new object;
111 $content->fieldid = $this->field->id;
112 $content->recordid = $recordid;
114 $names = explode('_', $name);
115 if (!empty($names[2])) {
116 $content->$names[2] = clean_param($value, PARAM_NOTAGS); // content[1-4]
118 $content->content = clean_param($value, PARAM_CLEAN);
121 if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
122 $content->id = $oldcontent->id;
123 return $DB->update_record('data_content', $content);
125 return $DB->insert_record('data_content', $content);