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.
 
  11 // | There are only two ways to violate the license:
 
  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).
 
  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).
 
  21 // | This license applies to this document only, not any other software
 
  22 // | that it may be combined with.
 
  24 // +----------------------------------------------------------------------+
 
  26 // | https://www.anuko.com/time_tracker/credits.htm
 
  27 // +----------------------------------------------------------------------+
 
  29 import('form.FormElement');
 
  31 class TextArea extends FormElement {
 
  34     var $mOnKeyPress    = "";
 
  36   function __construct($name, $value = '')
 
  38     $this->class = 'TextArea';
 
  40     $this->value = $value;
 
  43         function setColumns($value)     { $this->mColumns = $value;     }
 
  44         function getColumns()   { return $this->mColumns; }
 
  46         function setRows($value)        { $this->mRows = $value;        }
 
  47         function getRows()      { return $this->mRows; }
 
  51             if ($this->id=="") $this->id = $this->mName;
 
  55                 $html = "\n\t<textarea";
 
  56                 $html .= " name=\"$this->name\" id=\"$this->id\"";
 
  58                 if ($this->mColumns!="")
 
  59                   $html .= " cols=\"$this->mColumns\"";
 
  62                    $html .= " rows=\"$this->mRows\"";
 
  64                 if ($this->max_length!="") {
 
  65                         if ($this->mOnKeyPress) $this->mOnKeyPress .= ";";
 
  66                         $this->mOnKeyPress .= "return validateMaxLenght_".$this->name."(this, event);";
 
  67                         $js_maxlen = $this->getExtraScript();
 
  68                         $html .= " maxlength=\"$this->max_length\"";
 
  72                    $html .= " style=\"$this->style\"";
 
  74                 if ($this->mOnKeyPress) {
 
  75                         $html .= " onkeypress=\"$this->mOnKeyPress\"";
 
  78                 $html .= ">".htmlspecialchars($this->getValue())."</textarea>";
 
  79                 if ($js_maxlen) $html = $js_maxlen."\n".$html;
 
  84         function getExtraScript() {
 
  86                 $s .= "var isNS4 = (navigator.appName==\"Netscape\")?1:0;\n";
 
  87                 $s .= "function validateMaxLenght_".$this->name."(element, event) {\n";
 
  88                 $s .= "\tmaxlength=".$this->max_length.";\n";
 
  89                 $s .= "\tvar iKey = (!isNS4?event.keyCode:event.which);\n";
 
  90                 //$s .= "alert(iKey);";
 
  91                 $s .= "\tvar re = new RegExp(\"".'\r\n'."\",\"g\");\n";
 
  92                 $s .= "\tvar x = element.value.replace(re,\"\").length;\n";
 
  93                 $s .= "\tif ((x>=maxlength) && ((iKey > 31 && iKey < 1200) || (iKey > 95 && iKey < 106)) && (iKey != 13)) {\n";
 
  94                 $s .= "\t\treturn false;\n";
 
  96                 $s .= "\t\treturn true;\n";