Refactoring - removed not used default parameters from constructors.
[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 $mColumns       = "";
33     var $mRows          = "";
34     var $mOnKeyPress    = "";
35
36   function __construct($name)
37   {
38     $this->class = 'TextArea';
39     $this->name = $name;
40   }
41
42         function setColumns($value)     { $this->mColumns = $value;     }
43         function getColumns()   { return $this->mColumns; }
44
45         function setRows($value)        { $this->mRows = $value;        }
46         function getRows()      { return $this->mRows; }
47         
48         function getHtml() {
49     
50             if ($this->id=="") $this->id = $this->mName;
51             
52             $js_maxlen = "";
53             
54                 $html = "\n\t<textarea";
55                 $html .= " name=\"$this->name\" id=\"$this->id\"";
56                 
57                 if ($this->mColumns!="")
58                   $html .= " cols=\"$this->mColumns\"";
59                   
60                 if ($this->mRows!="")
61                    $html .= " rows=\"$this->mRows\"";
62                    
63                 if ($this->max_length!="") {
64                         if ($this->mOnKeyPress) $this->mOnKeyPress .= ";";
65                         $this->mOnKeyPress .= "return validateMaxLenght_".$this->name."(this, event);";
66                         $js_maxlen = $this->getExtraScript();
67                         $html .= " maxlength=\"$this->max_length\"";
68                 }
69
70                 if ($this->style!="")
71                    $html .= " style=\"$this->style\"";
72
73                 if ($this->mOnKeyPress) {
74                         $html .= " onkeypress=\"$this->mOnKeyPress\"";
75                 }
76                         
77                 $html .= ">".htmlspecialchars($this->getValue())."</textarea>";
78                 if ($js_maxlen) $html = $js_maxlen."\n".$html;
79                 
80                 return $html;
81         }
82         
83         function getExtraScript() {
84                 $s = "<script>\n";
85                 $s .= "var isNS4 = (navigator.appName==\"Netscape\")?1:0;\n";
86                 $s .= "function validateMaxLenght_".$this->name."(element, event) {\n";
87                 $s .= "\tmaxlength=".$this->max_length.";\n";
88                 $s .= "\tvar iKey = (!isNS4?event.keyCode:event.which);\n";
89                 //$s .= "alert(iKey);";
90                 $s .= "\tvar re = new RegExp(\"".'\r\n'."\",\"g\");\n";
91                 $s .= "\tvar x = element.value.replace(re,\"\").length;\n";
92                 $s .= "\tif ((x>=maxlength) && ((iKey > 31 && iKey < 1200) || (iKey > 95 && iKey < 106)) && (iKey != 13)) {\n";
93                 $s .= "\t\treturn false;\n";
94                 $s .= "\t} else {\n";
95                 $s .= "\t\treturn true;\n";
96                 $s .= "\t}\n}\n";
97                 $s .= "</script>\n";
98                 return $s;
99         }
100 }