fixes (MDL-8449) Quiz start and close times should allow the teacher to select a...
[moodle.git] / mod / data / field / textarea / field.class.php
CommitLineData
0997e51a 1<?php // $Id$
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 //
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///////////////////////////////////////////////////////////////////////////
24
35bcb325 25class data_field_textarea extends data_field_base {
26
27 var $type = 'textarea';
aab98aaf 28
0997e51a 29 function data_field_textarea($field=0, $data=0) {
30 parent::data_field_base($field, $data);
35bcb325 31 }
aab98aaf 32
33
0997e51a 34 function display_add_field($recordid=0) {
35bcb325 35 global $CFG;
0997e51a 36
423bd918 37 $text = '';
38 $format = 0;
39
0997e51a 40 if ($recordid){
423bd918 41 if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
42 $text = $content->content;
43 $format = $content->content1;
44 }
35bcb325 45 }
0997e51a 46
423bd918 47 $str = '<div title="'.$this->field->description.'">';
aab98aaf 48
f1ad19bc 49 if (can_use_richtext_editor()) {
50 // Show a rich text html editor.
0997e51a 51 $str .= $this->gen_textarea(true, $text);
eb073d70 52 $str .= helpbutton("richtext", get_string("helprichtext"), 'moodle', true, true, '', true);
0997e51a 53 $str .= '<input type="hidden" name="field_' . $this->field->id . '_content1' . '" value="' . FORMAT_HTML . '" />';
54
55 } else {
f1ad19bc 56 // Show a normal textarea. Also let the user specify the format to be used.
0997e51a 57 $str .= $this->gen_textarea(false, $text);
58
f1ad19bc 59 // Get the available text formats for this field.
60 $formatsForField = format_text_menu();
11378212 61 $str .= '<br />';
aab98aaf 62
63 $str .= choose_from_menu($formatsForField, 'field_' . $this->field->id .
0997e51a 64 '_content1', $format, 'choose', '', '', true);
65
66 $str .= helpbutton('textformat', get_string('helpformatting'), 'moodle', true, false, '', true);
11378212 67 }
bbe39b6c 68 $str .= '</div>';
35bcb325 69 return $str;
70 }
aab98aaf 71
72
0997e51a 73 function gen_textarea($usehtmleditor, $text='') {
aab98aaf 74 return print_textarea($usehtmleditor, $this->field->param3, $this->field->param2,
e357c206 75 '', '', 'field_'.$this->field->id, $text, '', true, 'field_' . $this->field->id);
f1ad19bc 76 }
aab98aaf 77
78
f1ad19bc 79 function print_after_form() {
80 if (can_use_richtext_editor()) {
e357c206 81 use_html_editor('field_' . $this->field->id, '', 'field_' . $this->field->id);
f1ad19bc 82 }
83 }
aab98aaf 84
85
0997e51a 86 function update_content($recordid, $value, $name='') {
87 $content = new object;
88 $content->fieldid = $this->field->id;
89 $content->recordid = $recordid;
0997e51a 90
91 $names = explode('_', $name);
92 if (!empty($names[2])) {
93 $content->$names[2] = clean_param($value, PARAM_NOTAGS); // content[1-4]
94 } else {
505d3123 95 $content->content = clean_param($value, PARAM_CLEAN);
11378212 96 }
0997e51a 97
1b0d9dca 98 if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
11378212 99 $content->id = $oldcontent->id;
0997e51a 100 return update_record('data_content', $content);
101 } else {
102 return insert_record('data_content', $content);
11378212 103 }
104 }
35bcb325 105}
106?>