forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoll.inc.old
170 lines (154 loc) · 4.73 KB
/
poll.inc.old
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
$light_blue = "#d5f0ff";
// independent of any particular poll
function list_item2($x, $y) {
global $light_blue;
echo "
<tr>
<td width=50% bgcolor=$light_blue valign=top >$x</td>
<td colspan=8>$y</td>
</tr>
";
}
function boxes($options) {
$x = "<font size=-2>".tra("[check all that apply]")."</font><br>\n";
foreach ($options as $name => $text) {
$x .= "<input type=checkbox name=$name> $text<br>\n";
}
return $x;
}
function radio($radio_name, $options) {
$x = "";
foreach ($options as $name => $text) {
$x .= "<input type=radio name=$radio_name value=$name> $text<br>\n";
}
return $x;
}
function show_choice($choice, $outer_radio) {
$rname = $choice["rname"];
$text = $choice["text"];
$radio_name = $choice["radio_name"];
$x = "";
if ($rname) {
$x .= "<input onclick=\"$rname()\" type=radio name=$outer_radio value=$rname >";
}
$x .= $text;
if ($radio_name) {
$y = radio($radio_name, $choice["options"]);
} else {
$y = boxes($choice["options"]);
$other_name = $choice['other_name'];
$y .= tra("Other:")." <input size=30 name=$other_name>";
}
list_item2($x, $y);
}
function show_choices($choices, $outer_radio) {
foreach ($choices as $choice) {
show_choice($choice, $outer_radio);
}
}
function generate_functions($choices) {
echo "<script>\n";
echo "function disable_all() {\n";
foreach ($choices as $choice) {
$radio_name = $choice["radio_name"];
if ($radio_name) {
$options = $choice["options"];
$i = 0;
foreach ($options as $name => $text) {
echo "document.forms.blah.".$radio_name."[".$i."].disabled=true;\n";
$i++;
}
} else {
$options = $choice["options"];
foreach ($options as $name => $text) {
echo "document.forms.blah.$name.disabled=true;\n";
}
$other_name = $choice['other_name'];
echo "document.forms.blah.$other_name.disabled=true;\n";
}
}
echo "}\n";
foreach ($choices as $choice) {
$rname = $choice["rname"];
echo "function $rname() {\n";
echo "disable_all();\n";
$radio_name = $choice["radio_name"];
if ($radio_name) {
$options = $choice["options"];
$i = 0;
foreach ($options as $name => $text) {
echo "document.forms.blah.".$radio_name."[".$i."].disabled=false;\n";
$i++;
}
} else {
$options = $choice["options"];
foreach ($options as $name => $text) {
echo "document.forms.blah.$name.disabled=false;\n";
}
$other_name = $choice['other_name'];
echo "document.forms.blah.$other_name.disabled=false;\n";
}
echo "}\n";
}
echo "</script>\n";
}
function new_response($uid, $xml) {
$now = time();
return mysql_query("insert into response (uid, create_time, update_time, xml) values ('$uid', $now, $now, '$xml')");
}
function update_response($uid, $xml) {
$now = time();
return mysql_query("update response set update_time=$now, xml='$xml' where uid='$uid'");
}
function select_response($uid) {
$result = mysql_query("select * from response where uid='$uid'");
$response = mysql_fetch_object($result);
mysql_free_result($result);
return $response;
}
function parse_form_choice($x, $choice) {
$radio_name= $choice["radio_name"];
if ($radio_name) {
$x[$radio_name] = get_str($radio_name);
} else {
$options = $choice["options"];
foreach ($options as $name=>$text) {
$x[$name] = get_str($name);
}
$other_name = $choice['other_name'];
$x[$other_name] = get_str($other_name);
}
return $x;
}
function parse_form_choices($x, $choices) {
foreach ($choices as $choice) {
$x = parse_form_choice($x, $choice);
}
return $x;
}
function gen_xml_choice($x, $choice) {
$xml = "";
$radio_name= $choice["radio_name"];
if ($radio_name) {
$val = urlencode($x[$radio_name]);
$xml .= "<$radio_name>$val</$radio_name>\n";
} else {
$options = $choice["options"];
foreach ($options as $name=>$text) {
$val = urlencode($x[$name]);
$xml .= "<$name>$val</$name>\n";
}
$other_name = $choice['other_name'];
$text = urlencode($x[$other_name]);
$xml .= "<$other_name>$text</$other_name>\n";
}
return $xml;
}
function gen_xml_choices($x, $choices) {
foreach ($choices as $choice) {
$xml .= gen_xml_choice($x, $choice);
}
return $xml;
}
?>