Subversion Repositories Applications.papyrus

Rev

Rev 320 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
320 jpm 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
4
// | PHP version 4.0                                                      |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group             |
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 2.0 of the PHP license,       |
9
// | that is bundled with this package in the file LICENSE, and is        |
10
// | available at through the world-wide-web at                           |
11
// | http://www.php.net/license/2_02.txt.                                 |
12
// | If you did not receive a copy of the PHP license and are unable to   |
13
// | obtain it through the world-wide-web, please send a note to          |
14
// | license@php.net so we can mail you a copy immediately.               |
15
// +----------------------------------------------------------------------+
16
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com>                        |
17
// |          Bertrand Mansion <bmansion@mamasam.com>                     |
18
// +----------------------------------------------------------------------+
19
//
443 ddelon 20
// $Id: textarea.php,v 1.2 2005-09-20 17:01:22 ddelon Exp $
320 jpm 21
 
22
require_once("HTML/QuickForm/element.php");
23
 
24
/**
25
 * HTML class for a textarea type field
26
 *
27
 * @author       Adam Daniel <adaniel1@eesus.jnj.com>
28
 * @author       Bertrand Mansion <bmansion@mamasam.com>
29
 * @version      1.0
30
 * @since        PHP4.04pl1
31
 * @access       public
32
 */
33
class HTML_QuickForm_textarea extends HTML_QuickForm_element
34
{
35
    // {{{ properties
36
 
37
    /**
38
     * Field value
39
     * @var       string
40
     * @since     1.0
41
     * @access    private
42
     */
43
    var $_value = null;
44
 
45
    // }}}
46
    // {{{ constructor
47
 
48
    /**
49
     * Class constructor
50
     *
51
     * @param     string    Input field name attribute
52
     * @param     mixed     Label(s) for a field
53
     * @param     mixed     Either a typical HTML attribute string or an associative array
54
     * @since     1.0
55
     * @access    public
56
     * @return    void
57
     */
58
    function HTML_QuickForm_textarea($elementName=null, $elementLabel=null, $attributes=null)
59
    {
60
        HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
61
        $this->_persistantFreeze = true;
62
        $this->_type = 'textarea';
63
    } //end constructor
64
 
65
    // }}}
66
    // {{{ setName()
67
 
68
    /**
69
     * Sets the input field name
70
     *
71
     * @param     string    $name   Input field name attribute
72
     * @since     1.0
73
     * @access    public
74
     * @return    void
75
     */
76
    function setName($name)
77
    {
78
        $this->updateAttributes(array('name'=>$name));
79
    } //end func setName
80
 
81
    // }}}
82
    // {{{ getName()
83
 
84
    /**
85
     * Returns the element name
86
     *
87
     * @since     1.0
88
     * @access    public
89
     * @return    string
90
     */
91
    function getName()
92
    {
93
        return $this->getAttribute('name');
94
    } //end func getName
95
 
96
    // }}}
97
    // {{{ setValue()
98
 
99
    /**
100
     * Sets value for textarea element
101
     *
102
     * @param     string    $value  Value for textarea element
103
     * @since     1.0
104
     * @access    public
105
     * @return    void
106
     */
107
    function setValue($value)
108
    {
109
        $this->_value = $value;
110
    } //end func setValue
111
 
112
    // }}}
113
    // {{{ getValue()
114
 
115
    /**
116
     * Returns the value of the form element
117
     *
118
     * @since     1.0
119
     * @access    public
120
     * @return    string
121
     */
122
    function getValue()
123
    {
124
        return $this->_value;
125
    } // end func getValue
126
 
127
    // }}}
128
    // {{{ setWrap()
129
 
130
    /**
131
     * Sets wrap type for textarea element
132
     *
133
     * @param     string    $wrap  Wrap type
134
     * @since     1.0
135
     * @access    public
136
     * @return    void
137
     */
138
    function setWrap($wrap)
139
    {
140
        $this->updateAttributes(array('wrap' => $wrap));
141
    } //end func setWrap
142
 
143
    // }}}
144
    // {{{ setRows()
145
 
146
    /**
147
     * Sets height in rows for textarea element
148
     *
149
     * @param     string    $rows  Height expressed in rows
150
     * @since     1.0
151
     * @access    public
152
     * @return    void
153
     */
154
    function setRows($rows)
155
    {
156
        $this->updateAttributes(array('rows' => $rows));
157
    } //end func setRows
158
 
159
    // }}}
160
    // {{{ setCols()
161
 
162
    /**
163
     * Sets width in cols for textarea element
164
     *
165
     * @param     string    $cols  Width expressed in cols
166
     * @since     1.0
167
     * @access    public
168
     * @return    void
169
     */
170
    function setCols($cols)
171
    {
172
        $this->updateAttributes(array('cols' => $cols));
173
    } //end func setCols
174
 
175
    // }}}
176
    // {{{ toHtml()
177
 
178
    /**
179
     * Returns the textarea element in HTML
180
     *
181
     * @since     1.0
182
     * @access    public
183
     * @return    string
184
     */
185
    function toHtml()
186
    {
187
        if ($this->_flagFrozen) {
188
            return $this->getFrozenHtml();
189
        } else {
190
            return $this->_getTabs() .
191
                   '<textarea' . $this->_getAttrString($this->_attributes) . '>' .
192
                   // because we wrap the form later we don't want the text indented
193
                   preg_replace("/(\r\n|\n|\r)/", '&#010;', htmlspecialchars($this->_value)) .
194
                   '</textarea>';
195
        }
196
    } //end func toHtml
197
 
198
    // }}}
199
    // {{{ getFrozenHtml()
200
 
201
    /**
202
     * Returns the value of field without HTML tags (in this case, value is changed to a mask)
203
     *
204
     * @since     1.0
205
     * @access    public
206
     * @return    string
207
     */
208
    function getFrozenHtml()
209
    {
210
        $value = htmlspecialchars($this->getValue());
211
        if ($this->getAttribute('wrap') == 'off') {
212
            $html = $this->_getTabs() . '<pre>' . $value."</pre>\n";
213
        } else {
214
            $html = nl2br($value)."\n";
215
        }
216
        return $html . $this->_getPersistantData();
217
    } //end func getFrozenHtml
218
 
219
    // }}}
220
 
221
} //end class HTML_QuickForm_textarea
222
?>