Commit | Line | Data |
---|---|---|
1adbd2c3 | 1 | <?php |
35bcb325 | 2 | /////////////////////////////////////////////////////////////////////////// |
3 | // // | |
4 | // NOTICE OF COPYRIGHT // | |
5 | // // | |
6 | // Moodle - Modular Object-Oriented Dynamic Learning Environment // | |
7 | // http://moodle.org // | |
8 | // // | |
0997e51a | 9 | // Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com // |
35bcb325 | 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 // | |
601104f2 | 14 | // (at your option) any later version. // // // |
35bcb325 | 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: // | |
19 | // // | |
20 | // http://www.gnu.org/copyleft/gpl.html // | |
21 | // // | |
22 | /////////////////////////////////////////////////////////////////////////// | |
23 | ||
35bcb325 | 24 | class data_field_textarea extends data_field_base { |
25 | ||
26 | var $type = 'textarea'; | |
aab98aaf | 27 | |
0997e51a | 28 | function display_add_field($recordid=0) { |
601104f2 | 29 | global $CFG, $DB, $OUTPUT; |
0997e51a | 30 | |
423bd918 | 31 | $text = ''; |
32 | $format = 0; | |
33 | ||
0997e51a | 34 | if ($recordid){ |
a656d951 | 35 | if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { |
423bd918 | 36 | $text = $content->content; |
37 | $format = $content->content1; | |
38 | } | |
35bcb325 | 39 | } |
0997e51a | 40 | |
423bd918 | 41 | $str = '<div title="'.$this->field->description.'">'; |
aab98aaf | 42 | |
59fa45d0 | 43 | if (can_use_html_editor()) { |
f1ad19bc | 44 | // Show a rich text html editor. |
0997e51a | 45 | $str .= $this->gen_textarea(true, $text); |
4102b449 | 46 | $str .= $OUTPUT->help_icon(moodle_help_icon::make("richtext2", get_string("helprichtext"), 'moodle', true)); |
0997e51a | 47 | $str .= '<input type="hidden" name="field_' . $this->field->id . '_content1' . '" value="' . FORMAT_HTML . '" />'; |
48 | ||
49 | } else { | |
f1ad19bc | 50 | // Show a normal textarea. Also let the user specify the format to be used. |
0997e51a | 51 | $str .= $this->gen_textarea(false, $text); |
52 | ||
f1ad19bc | 53 | // Get the available text formats for this field. |
54 | $formatsForField = format_text_menu(); | |
11378212 | 55 | $str .= '<br />'; |
601104f2 | 56 | $select = html_select( $formatsForField, 'field_' . $this->field->id . '_content1', $format); |
57 | $select->nothingvalue = ''; | |
58 | $str .= $OUTPUT->select($select); | |
0997e51a | 59 | |
4102b449 | 60 | $str .= $OUTPUT->help_icon(moodle_help_icon::make('textformat', get_string('helpformatting'), 'moodle')); |
11378212 | 61 | } |
bbe39b6c | 62 | $str .= '</div>'; |
35bcb325 | 63 | return $str; |
64 | } | |
1adbd2c3 PS |
65 | |
66 | ||
7900ecb0 | 67 | function display_search_field($value = '') { |
1adbd2c3 | 68 | return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />'; |
7900ecb0 | 69 | } |
1adbd2c3 | 70 | |
7900ecb0 | 71 | function parse_search_field() { |
72 | return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS); | |
73 | } | |
1adbd2c3 | 74 | |
7900ecb0 | 75 | function generate_sql($tablealias, $value) { |
e3487936 | 76 | global $DB; |
77 | ||
78 | $ILIKE = $DB->sql_ilike(); | |
79 | ||
80 | static $i=0; | |
81 | $i++; | |
82 | $name = "df_picture_$i"; | |
83 | return array(" ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content $ILIKE :$name) ", array($name=>"%$value%")); | |
7900ecb0 | 84 | } |
1adbd2c3 | 85 | |
0997e51a | 86 | function gen_textarea($usehtmleditor, $text='') { |
aab98aaf | 87 | return print_textarea($usehtmleditor, $this->field->param3, $this->field->param2, |
e357c206 | 88 | '', '', 'field_'.$this->field->id, $text, '', true, 'field_' . $this->field->id); |
f1ad19bc | 89 | } |
aab98aaf | 90 | |
91 | ||
f1ad19bc | 92 | function print_after_form() { |
f1ad19bc | 93 | } |
aab98aaf | 94 | |
95 | ||
0997e51a | 96 | function update_content($recordid, $value, $name='') { |
a656d951 | 97 | global $DB; |
98 | ||
0997e51a | 99 | $content = new object; |
100 | $content->fieldid = $this->field->id; | |
101 | $content->recordid = $recordid; | |
0997e51a | 102 | |
103 | $names = explode('_', $name); | |
104 | if (!empty($names[2])) { | |
105 | $content->$names[2] = clean_param($value, PARAM_NOTAGS); // content[1-4] | |
106 | } else { | |
505d3123 | 107 | $content->content = clean_param($value, PARAM_CLEAN); |
11378212 | 108 | } |
0997e51a | 109 | |
a656d951 | 110 | if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { |
11378212 | 111 | $content->id = $oldcontent->id; |
a656d951 | 112 | return $DB->update_record('data_content', $content); |
0997e51a | 113 | } else { |
a656d951 | 114 | return $DB->insert_record('data_content', $content); |
11378212 | 115 | } |
116 | } | |
35bcb325 | 117 | } |
1adbd2c3 | 118 |