35bcb325 |
1 | <?php ///Class file for textarea field, extends base_field |
2 | /////////////////////////////////////////////////////////////////////////// |
3 | // // |
4 | // NOTICE OF COPYRIGHT // |
5 | // // |
6 | // Moodle - Modular Object-Oriented Dynamic Learning Environment // |
7 | // http://moodle.org // |
8 | // // |
9 | // Copyright (C) 2005 Martin Dougiamas http://dougiamas.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 | /////////////////////////////////////////////////////////////////////////// |
24 | |
25 | /// Please refer to lib.php for method comments |
26 | |
27 | class data_field_textarea extends data_field_base { |
28 | |
29 | var $type = 'textarea'; |
30 | var $id; |
31 | |
32 | |
33 | function data_field_textarea($fid=0){ |
34 | parent::data_field_base($fid); |
35 | } |
36 | |
37 | |
38 | /*********************************************** |
39 | * Saves the field into the database * |
40 | ***********************************************/ |
41 | function insert_field($dataid, $type='textarea', $name, $desc='', $autolink=0, $width='', $height='') { |
42 | $newfield = new object; |
43 | $newfield->dataid = $dataid; |
44 | $newfield->type = $type; |
45 | $newfield->name = $name; |
46 | $newfield->description = $desc; |
47 | $newfield->param1 = $autolink; |
48 | $newfield->param2 = $width; |
49 | $newfield->param3 = $height; |
50 | |
51 | if (!insert_record('data_fields', $newfield)) { |
52 | notify('Insertion of new field failed!'); |
53 | } |
54 | } |
55 | |
56 | |
57 | /*********************************************** |
58 | * Prints the form element in the add template * |
59 | ***********************************************/ |
60 | function display_add_field($id, $rid=0) { |
61 | global $CFG; |
62 | if (!$field = get_record('data_fields', 'id', $id)){ |
63 | notify('That is not a valid field id!'); |
64 | exit; |
65 | } |
66 | if ($rid) { |
67 | $content = get_record('data_content', 'fieldid', $id, 'recordid', $rid); |
68 | if (isset($content->content)) { |
69 | $content = $content->content; |
70 | } |
71 | } |
72 | else { |
73 | $content = ''; |
74 | } |
75 | $str = ''; |
76 | |
77 | if ($field->description) { |
78 | $str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'" /> '; |
79 | } |
80 | $str .= '<textarea name="field_' . $field->id . '" id="field_'.$field->id . '"'; |
81 | if (!empty($field->param2) && !empty($field->param3)) { |
82 | $str .= ' style="width:' . $field->param2. 'px; height:' . $field->param3 . 'px;"'; |
83 | } |
84 | $str .= '>' . $content . '</textarea>'; |
85 | return $str; |
86 | } |
87 | |
88 | |
89 | function display_edit_field($id, $mode=0) { |
90 | parent::display_edit_field($id, $mode); |
91 | } |
92 | |
93 | |
94 | function update($fieldobject) { |
95 | $fieldobject->param1 = trim($fieldobject->param1); |
96 | $fieldobject->param2 = trim($fieldobject->param2); |
97 | |
98 | if (!update_record('data_fields',$fieldobject)){ |
99 | notify ('upate failed'); |
100 | } |
101 | } |
102 | } |
103 | ?> |