-
Notifications
You must be signed in to change notification settings - Fork 0
/
elements-library.php
86 lines (69 loc) · 2.04 KB
/
elements-library.php
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
<?php
class ElementsLibrary {
public static function draw_label($caption) {
return "<div>$caption</div>";
}
public static function draw_input($tags) {
$html = '<input ';
foreach ($tags as $key => $value) {
if (isset($value)) {
$html .= $key . '="' . $value .'" ';
}
}
$html .= ' />';
return $html;
}
public static function draw_text($name, $value = null, $size = null, $tags = array()) {
$tags = array_merge(array(
'name' => $name,
'value' => $value,
'size' => $size,
'type' => 'text'), $tags);
return ElementsLibrary::draw_input($tags);
}
public static function echo_text($name, $value = null, $size = null, $tags = array()) {
return function() use ($name, $value, $size, $tags) {
echo ElementsLibrary::draw_text($name, $value, $size, $tags);
};
}
public static function draw_checkbox($name, $value = null, $tags = array()) {
$tags = array_merge(array(
'name' => $name,
'value' => $name,
'type' => 'checkbox'), $tags);
if ($value != '') {
$tags['checked'] = '';
}
return ElementsLibrary::draw_input($tags);
}
public static function echo_checkbox($name, $value = null, $tags = array()) {
return function() use ($name, $value, $tags) {
echo ElementsLibrary::draw_checkbox($name, $value, $tags);
};
}
public static function draw_select($name, $options, $value_selected = null, $tags = array()) {
$tags = array_merge(array(
'name' => $name), $tags);
$html = '<select ';
foreach ($tags as $key => $value) {
if (isset($value)) {
$html .= $key . '="' . $value .'" ';
}
}
$html .= '>';
foreach ($options as $value => $label) {
$html .= '<option value="' . $value . '" ';
if ($value_selected == $value) {
$html .= 'selected';
}
$html .= '>' . $label . '</option>';
}
$html .= '</select>';
return $html;
}
public static function echo_select($name, $options, $value = null, $tags = array()) {
return function() use ($name, $options, $value, $tags) {
echo ElementsLibrary::draw_select($name, $options, $value, $tags);
};
}
}