2006-07-11 03:44:14 +00:00
|
|
|
<?php
|
|
|
|
|
2007-09-08 21:34:20 +00:00
|
|
|
$light_blue = "#d5f0ff";
|
|
|
|
|
2006-07-11 19:24:12 +00:00
|
|
|
// independent of any particular poll
|
|
|
|
|
2006-07-11 03:44:14 +00:00
|
|
|
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>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2006-07-17 16:38:53 +00:00
|
|
|
function boxes($options) {
|
2006-07-22 18:24:01 +00:00
|
|
|
$x = "<font size=-2>".tr(POLL_CHECK_ALL)."</font><br>\n";
|
2006-07-11 19:24:12 +00:00
|
|
|
foreach ($options as $name => $text) {
|
2006-07-17 16:38:53 +00:00
|
|
|
$x .= "<input type=checkbox name=$name> $text<br>\n";
|
2006-07-11 03:44:14 +00:00
|
|
|
}
|
2006-07-11 19:24:12 +00:00
|
|
|
return $x;
|
2006-07-11 03:44:14 +00:00
|
|
|
}
|
|
|
|
|
2006-07-17 16:38:53 +00:00
|
|
|
function radio($radio_name, $options) {
|
2006-07-11 19:24:12 +00:00
|
|
|
$x = "";
|
|
|
|
foreach ($options as $name => $text) {
|
2006-07-17 16:38:53 +00:00
|
|
|
$x .= "<input type=radio name=$radio_name value=$name> $text<br>\n";
|
2006-07-11 03:44:14 +00:00
|
|
|
}
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
2006-07-11 19:24:12 +00:00
|
|
|
function show_choice($choice, $outer_radio) {
|
|
|
|
$rname = $choice["rname"];
|
|
|
|
$text = $choice["text"];
|
|
|
|
$radio_name = $choice["radio_name"];
|
2006-07-11 03:44:14 +00:00
|
|
|
$x = "";
|
2006-07-11 19:24:12 +00:00
|
|
|
if ($rname) {
|
|
|
|
$x .= "<input onclick=\"$rname()\" type=radio name=$outer_radio value=$rname >";
|
2006-07-11 03:44:14 +00:00
|
|
|
}
|
2006-07-11 19:24:12 +00:00
|
|
|
$x .= $text;
|
|
|
|
if ($radio_name) {
|
2006-07-17 16:38:53 +00:00
|
|
|
$y = radio($radio_name, $choice["options"]);
|
2006-07-11 19:24:12 +00:00
|
|
|
} else {
|
2006-07-17 16:38:53 +00:00
|
|
|
$y = boxes($choice["options"]);
|
2006-07-11 19:24:12 +00:00
|
|
|
$other_name = $choice['other_name'];
|
2006-07-22 18:24:01 +00:00
|
|
|
$y .= tr(POLL_OTHER)." <input size=30 name=$other_name>";
|
2006-07-11 19:24:12 +00:00
|
|
|
}
|
|
|
|
list_item2($x, $y);
|
2006-07-11 03:44:14 +00:00
|
|
|
}
|
|
|
|
|
2006-07-11 19:24:12 +00:00
|
|
|
function show_choices($choices, $outer_radio) {
|
2006-07-11 03:44:14 +00:00
|
|
|
foreach ($choices as $choice) {
|
2006-07-11 19:24:12 +00:00
|
|
|
show_choice($choice, $outer_radio);
|
2006-07-11 03:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function generate_functions($choices) {
|
|
|
|
echo "<script>\n";
|
|
|
|
echo "function disable_all() {\n";
|
|
|
|
foreach ($choices as $choice) {
|
|
|
|
$radio_name = $choice["radio_name"];
|
|
|
|
if ($radio_name) {
|
2006-07-11 19:24:12 +00:00
|
|
|
$options = $choice["options"];
|
2006-07-11 03:44:14 +00:00
|
|
|
$i = 0;
|
2006-07-11 19:24:12 +00:00
|
|
|
foreach ($options as $name => $text) {
|
2006-07-11 03:44:14 +00:00
|
|
|
echo "document.forms.blah.".$radio_name."[".$i."].disabled=true;\n";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
} else {
|
2006-07-11 19:24:12 +00:00
|
|
|
$options = $choice["options"];
|
|
|
|
foreach ($options as $name => $text) {
|
2006-07-11 03:44:14 +00:00
|
|
|
echo "document.forms.blah.$name.disabled=true;\n";
|
|
|
|
}
|
2006-07-11 19:24:12 +00:00
|
|
|
$other_name = $choice['other_name'];
|
|
|
|
echo "document.forms.blah.$other_name.disabled=true;\n";
|
2006-07-11 03:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
2006-07-11 19:24:12 +00:00
|
|
|
$options = $choice["options"];
|
2006-07-11 03:44:14 +00:00
|
|
|
$i = 0;
|
2006-07-11 19:24:12 +00:00
|
|
|
foreach ($options as $name => $text) {
|
2006-07-11 03:44:14 +00:00
|
|
|
echo "document.forms.blah.".$radio_name."[".$i."].disabled=false;\n";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
} else {
|
2006-07-11 19:24:12 +00:00
|
|
|
$options = $choice["options"];
|
|
|
|
foreach ($options as $name => $text) {
|
2006-07-11 03:44:14 +00:00
|
|
|
echo "document.forms.blah.$name.disabled=false;\n";
|
|
|
|
}
|
2006-07-11 19:24:12 +00:00
|
|
|
$other_name = $choice['other_name'];
|
|
|
|
echo "document.forms.blah.$other_name.disabled=false;\n";
|
2006-07-11 03:44:14 +00:00
|
|
|
}
|
|
|
|
echo "}\n";
|
|
|
|
}
|
|
|
|
echo "</script>\n";
|
|
|
|
}
|
|
|
|
|
2006-07-11 19:24:12 +00:00
|
|
|
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) {
|
2006-07-12 23:18:57 +00:00
|
|
|
$val = urlencode($x[$radio_name]);
|
2006-07-11 19:24:12 +00:00
|
|
|
$xml .= "<$radio_name>$val</$radio_name>\n";
|
|
|
|
} else {
|
|
|
|
$options = $choice["options"];
|
|
|
|
foreach ($options as $name=>$text) {
|
2006-07-12 23:18:57 +00:00
|
|
|
$val = urlencode($x[$name]);
|
2006-07-11 19:24:12 +00:00
|
|
|
$xml .= "<$name>$val</$name>\n";
|
|
|
|
}
|
|
|
|
$other_name = $choice['other_name'];
|
2006-07-12 23:18:57 +00:00
|
|
|
$text = urlencode($x[$other_name]);
|
2006-07-11 19:24:12 +00:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2006-07-11 03:44:14 +00:00
|
|
|
?>
|