Removed closing PHP tags in more files
[timetracker.git] / WEB-INF / lib / form / TextArea.class.php
1 <?php
2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
10 // |
11 // | There are only two ways to violate the license:
12 // |
13 // | 1. To redistribute this code in source form, with the copyright
14 // |    notice or license removed or altered. (Distributing in compiled
15 // |    forms without embedded copyright notices is permitted).
16 // |
17 // | 2. To redistribute modified versions of this code in *any* form
18 // |    that bears insufficient indications that the modifications are
19 // |    not the work of the original author(s).
20 // |
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
23 // |
24 // +----------------------------------------------------------------------+
25 // | Contributors:
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
28
29 import('form.FormElement');
30         
31 class TextArea extends FormElement {
32     var $mValue;
33     var $mPassword      = false;
34     var $mColumns       = "";
35     var $mRows          = "";
36     var $cClassName             = "TextArea";
37
38         function TextArea($name,$value="")
39         {
40                 $this->mName                    = $name;
41                 $this->mValue                   = $value;
42         }
43         
44         function setColumns($value)     { $this->mColumns = $value;     }
45         function getColumns()   { return $this->mColumns; }
46
47         function setRows($value)        { $this->mRows = $value;        }
48         function getRows()      { return $this->mRows; }
49         
50         function toStringControl()      {
51                 if (!$this->isRenderable()) return "";
52             
53             if ($this->mId=="") $this->mId = $this->mName;
54             
55             $js_maxlen = "";
56             
57                 $html = "\n\t<textarea";
58                 $html .= " name=\"$this->mName\" id=\"$this->mId\"";
59                 
60                 if ($this->mColumns!="")
61                   $html .= " cols=\"$this->mColumns\"";
62                   
63                 if ($this->mRows!="")
64                    $html .= " rows=\"$this->mRows\"";
65                    
66                 if ($this->mMaxLength!="") {
67                         if ($this->mOnKeyPress) $this->mOnKeyPress .= ";";
68                         $this->mOnKeyPress .= "return validateMaxLenght_".$this->mName."(this, event);";
69                         $js_maxlen = $this->getExtraScript();
70                         $html .= " maxlength=\"$this->mMaxLength\"";
71                 }
72
73                 if ($this->mStyle!="")
74                    $html .= " style=\"$this->mStyle\"";
75
76                 if ($this->mOnKeyPress) {
77                         $html .= " onkeypress=\"$this->mOnKeyPress\"";
78                 }
79                         
80                 $html .= ">".htmlspecialchars($this->getValue())."</textarea>";
81                 if ($js_maxlen) $html = $js_maxlen."\n".$html;
82                 
83                 return $html;
84         }
85         
86         function getExtraScript() {
87                 $s = "<script>\n";
88                 $s .= "var isNS4 = (navigator.appName==\"Netscape\")?1:0;\n";
89                 $s .= "function validateMaxLenght_".$this->mName."(element, event) {\n";
90                 $s .= "\tmaxlength=".$this->mMaxLength.";\n";
91                 $s .= "\tvar iKey = (!isNS4?event.keyCode:event.which);\n";
92                 //$s .= "alert(iKey);";
93                 $s .= "\tvar re = new RegExp(\"".'\r\n'."\",\"g\");\n";
94                 $s .= "\tvar x = element.value.replace(re,\"\").length;\n";
95                 $s .= "\tif ((x>=maxlength) && ((iKey > 31 && iKey < 1200) || (iKey > 95 && iKey < 106)) && (iKey != 13)) {\n";
96                 $s .= "\t\treturn false;\n";
97                 $s .= "\t} else {\n";
98                 $s .= "\t\treturn true;\n";
99                 $s .= "\t}\n}\n";
100                 $s .= "</script>\n";
101                 return $s;
102         }
103 }