$x |
$y |
";
}
function boxes($options, $disabled) {
$x = "[check all that apply]
\n";
foreach ($options as $name => $text) {
$x .= " $text
\n";
}
return $x;
}
function radio($radio_name, $options, $disabled) {
$x = "";
foreach ($options as $name => $text) {
$x .= " $text
\n";
}
return $x;
}
function show_choice($choice, $outer_radio) {
$rname = $choice["rname"];
$text = $choice["text"];
$radio_name = $choice["radio_name"];
$x = "";
if ($rname) {
$disabled = "disabled";
$x .= "";
}
$x .= $text;
if ($radio_name) {
$y = radio($radio_name, $choice["options"], $disabled);
} else {
$y = boxes($choice["options"], $disabled);
$other_name = $choice['other_name'];
$y .= "Other: ";
}
list_item2($x, $y);
}
function show_choices($choices, $outer_radio) {
foreach ($choices as $choice) {
show_choice($choice, $outer_radio);
}
}
function generate_functions($choices) {
echo "\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 get_str($name) {
if (isset($_GET[$name])) {
$x = $_GET[$name];
$x = trim($x);
return mysql_real_escape_string($x);
}
return null;
}
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 = $x[$radio_name];
$xml .= "<$radio_name>$val$radio_name>\n";
} else {
$options = $choice["options"];
foreach ($options as $name=>$text) {
$val = $x[$name];
$xml .= "<$name>$val$name>\n";
}
$other_name = $choice['other_name'];
$text = $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;
}
?>