summaryrefslogtreecommitdiff
path: root/utils/forms.php
blob: 4383d0a0d85c350a6162c902f027b7c214856dec (plain)
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
113
114
115
116
117
118
119
<?php

function beginform($action)
{
  global $m, $s;
?>
<form method="post" action="?page=admin&amp;m=<?php echo $m; ?>&amp;s=<?php echo $s; ?>&amp;a=<?php echo $action; ?>">
<?php
}

function endform()
{
?>
</form>
<?php
}

function button($label)
{
?>
  <div class="input">
    <div class="label"></div>
    <div class="widget"><button type="submit"><?php echo $label; ?></button></div>
  </div>
<?php
}

function lineedit($label, $name, $value = "")
{
?>
  <div class="input">
    <div class="label"><?php echo $label; ?></div>
    <div class="widget"><input name="<?php echo "vars[".$name."]"; ?>" value="<?php echo $value; ?>"/></div>
  </div>
<?php
}

function hidden($values)
{
  foreach($values as $key => $value) {
?>
  <input type="hidden" name="<?php echo "vars[".$key."]"; ?>" value="<?php echo $value; ?>"/>
<?php
  }
}

function textedit($label, $name, $value = "")
{
?>
  <div class="input">
    <div class="label"><?php echo $label; ?></div>
    <div class="widget"><textarea name="<?php echo "vars[".$name."]"; ?>"><?php echo $value; ?></textarea></div>
  </div>
<?php
}

function datetimeedit($label, $name, $timestamp = 0)
{
  if($timestamp == 0) $timestamp = time();

  $second = date('s',$timestamp);
  $minute = date('i',$timestamp);
  $hour = date('G',$timestamp); 
  $day = date('d',$timestamp);
  $month = date('m',$timestamp);
  $year = date('Y',$timestamp); 
?>
  <div class="input">
		<div class="label"><?php echo $label; ?></div>
    <div class="widget">
       <input style="width: 40px;" name="<?php echo "vars[".$name."_year]"; ?>" value="<?php echo $year; ?>"/>
						/
       <input style="width: 20px;" name="<?php echo "vars[".$name."_month]"; ?>" value="<?php echo $month; ?>"/>
						/
       <input style="width: 20px;" name="<?php echo "vars[".$name."_day]"; ?>" value="<?php echo $day; ?>"/>
						-
       <input style="width: 20px;" name="<?php echo "vars[".$name."_hour]"; ?>" value="<?php echo $hour; ?>"/>
						:
       <input style="width: 20px;" name="<?php echo "vars[".$name."_minute]"; ?>" value="<?php echo $minute; ?>"/>
						:
       <input style="width: 20px;" name="<?php echo "vars[".$name."_second]"; ?>" value="<?php echo $second; ?>"/>
    </div>
  </div>
<?php
}
function totimestamp($t, $name)
{
  $timestring = sprintf("%d", $t[$name."_year"])  ."/".
    sprintf("%d", $t[$name."_month"]) ."/".
    sprintf("%d", $t[$name."_day"])   ." ".
    sprintf("%d", $t[$name."_hour"])  .":".
    sprintf("%02d", $t[$name."_minute"]).":".
    sprintf("%02d", $t[$name."_second"]);

  echo $timestring;
  
  return strtotime($timestring);
}

function combobox($label, $name, $value, $values)
{
?>
  <div class="input">
    <div class="label"><?php echo $label; ?></div>
    <div class="widget">
      <select name="<?php echo "vars[".$name."]"; ?>">
<?php
						
  foreach($values as $k => $v) {
    if($v != $value) echo "        <option value=\"$v\">$k</option>\n";
    else echo "        <option value=\"$v\" selected>$k</option>\n";
  }
?>
      </select>
    </div>
  </div>
<?php
}
?>