File: of_select.inc

package info (click to toggle)
phplib 2%3A7.2d-3.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,612 kB
  • ctags: 198
  • sloc: php: 6,095; pascal: 186; perl: 95; makefile: 78; sh: 6
file content (112 lines) | stat: -rw-r--r-- 2,794 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/* OOHForms: select
 *
 * Copyright (c) 1998 by Jay Bloodworth
 *
 * $Id: of_select.inc,v 1.1.1.1 2000/04/17 16:40:15 kk Exp $
 */

class of_select extends of_element {

  var $options;
  var $size;
  var $valid_e;

  // Constructor
  function of_select($a) {
    $this->setup_element($a);
    if ($a["type"]=="select multiple") $this->multiple=1;
  }
  
  function self_get($val,$which, &$count) {
    $str = "";
    
    if ($this->multiple) {
      $n = $this->name . "[]";
      $t = "select multiple";
    } else {
      $n = $this->name;
      $t = "select";
    }
    $str .= "<$t name='$n'";
    if ($this->size) 
      $str .= " size='$this->size'";
    if ($this->extrahtml) 
      $str .= " $this->extrahtml";
    $str .= ">";

    reset($this->options);
    while (list($k,$o) = each($this->options)) {
      $str .= "<option";
      if (is_array($o)) 
        $str .= " value='" .  $o["value"] . "'";
      if (!$this->multiple && ($this->value==$o["value"] || $this->value==$o))
        $str .= " selected";
      elseif ($this->multiple && is_array($this->value)) {
        reset($this->value);
        while (list($tk,$v) = each($this->value)) {
          if ($v==$o["value"] || $v==$o) { 
            $str .= " selected"; break; 
          }
        }
      }
      $str .= ">" . (is_array($o) ? $o["label"] : $o) . "\n";
    }
    $str .= "</select>";
    
    $count = 1;
    return $str;
  }

  function self_get_frozen($val,$which, &$count) {
    $str = "";
    
    $x = 0;
    $n = $this->name . ($this->multiple ? "[]" : "");
    $v_array = (is_array($this->value) ? $this->value : array($this->value));
    $str .= "<table border=1>\n";
    reset($v_array);
    while (list($tk,$tv) = each($v_array)) {
      reset($this->options);
      while (list($k,$v) = each($this->options)) {
        if ((is_array($v) && 
           (($tmp=$v["value"])==$tv || $v["label"]==$tv))
         || ($tmp=$v)==$tv) {
          $x++;
          $str .= "<input type='hidden' name='$n' value='$tmp'>\n";
          $str .= "<tr><td>" . (is_array($v) ? $v["label"] : $v) . "</td></tr>\n";
        }
      }
    }
    $str .= "</table>\n";
    
    $count = $x;
    return $str;
  }

  function self_get_js($ndx_array) {
    $str = "";
    
    if (!$this->multiple && $this->valid_e) {
      $str .= "if (f.$this->name.selectedIndex == 0) {\n";
      $str .= "  alert(\"$this->valid_e\");\n";
      $str .= "  f.$this->name.focus();\n";
      $str .= "  return(false);\n";
      $str .= "}\n";
    }
    
    return $str;
  }

  function self_validate($val) {
    if (!$this->multiple && $this->valid_e) {
      reset($this->options);
      $o = current($this->options);
      if ($val==$o["value"] || $val==$o) return $this->valid_e;
    }
    return false;
  }

} // end SELECT

?>