function letter($n) {
return chr($n+97);
}
function makeChecks($n, $arr, $a, $o=-1, $c=-1) {
?>
if ($c != -1) { ?>
}
}
function makeRadio($n, $arr, $a, $o=-1 , $c=-1) {
?>
if ($c != -1) { ?>
}
}
function printQuest($param, $answer, $other, $comment) {
$msg = $param["desc"];
$name = $param["items"];
$func = $param["func"];
$snum = $param["snum"];
$qnum = $param["qnum"];
$tag = $snum."_".$qnum;
$other = stripslashes($other);
$other = stripslashes($other);
$comment = stripslashes($comment);
$comment = stripslashes($comment);
global $$name;
?>
=$snum.".".$qnum.". ".$msg?> (help)
$func($name, $$name, $answer, $other, $comment);
?>
}
function printShortQuest($param, $answer, $other, $comment) {
$msg = $param["title"];
$name = $param["items"];
$func = $param["func"];
$snum = $param["snum"];
$qnum = $param["qnum"];
$tag = $snum."_".$qnum;
$other = stripslashes($other);
$other = stripslashes($other);
$comment = stripslashes($comment);
$comment = stripslashes($comment);
global $$name;
?>
=$snum.".".$qnum.". ".$msg?>
$func($name, $$name, $answer);
?>
}
function compareProjectName($elem1, $elem2) {
if ( strtolower($elem1["name"]) == strtolower($elem2["name"]) )
return 0;
if ( strtolower($elem1["name"]) < strtolower($elem2["name"]) )
return -1;
else
return +1;
}
function printProjectOptions($projects, $id) {
usort($projects, "compareProjectName");
foreach ( $projects as $p ) {
if ( $p["id"] == $id ) {
$sel = "SELECTED=SELECTED";
} else {
$sel = "";
}
?>
VALUE="=$p["id"]?>">= $p["name"] ?>
}
}
function printProjectBox($projects) {
?>
Registered Projects
foreach ( $projects as $p ) { ?>
=$p["name"]?>
} ?>
}
// exports ( forwards ) an associative array through HTML using
// "hiddens"
function export_array ( $array, $name ) {
for ($i = 0; $i < count($array) ; $i++ ) {
$content = each( $array ) ;
print "\t\t\t \n";
}
}
// Stuff used in results and view_survey
function printQuestLine($num, $desc, $multiple) {
?>
=$num?>: =$desc?>
= $multiple? "Multiple choices possible": "Single choice" ?>
}
function printOptLine($optnam, $optval, $optindex = -1) {
if ( $optindex != -1 ) {
$l = letter($optindex).". ";
} else {
$l = "";
}
?>
=$l ?> =$optnam?>
if ( $optval != -1 ) { ?>
=$optval?> (=avg($optval)?>%)
}
}
function avg($value) {
global $n_validproj;
return sprintf("%.1f", $value / $n_validproj * 100);
}
function printRadioResults($opts, $results) {
foreach ( $results as $result ) {
$optval = $result["count"];
$optnum = $result["answer"];
// this test is a bit wierd, but so are pgsql indexes. the fact
// is that the value for unanswered questions is 0, which means
// that a select will return counts even if the u
if ( $optnum == 0 ) {
$unanswered = $optval;
continue; // we don't want to print other right now
}
if ( $optnum == 1 ) {
$otherval = $optval;
continue; // we don't want to print other right now
}
// postgres answer index starts at 2 (1 is other), thus -2
printOptLine( $opts[$optnum-2], $optval, $optnum-2 );
}
if ( $otherval ) {
printOptLine( "Other", $otherval );
$otherval = 0;
}
if ( $unanswered ) {
printOptLine( "(Left unanswered)", $unanswered );
$unanswered = 0;
}
}
function printCheckResults($index, $opts) {
// there is one extra option, which is position 0, for "other" so we
// need to adjust the total loop and then the index to opts. Yes,
// this is ugly but I don't care enough to fix it. the position is
// used as a mask in getchecktotal, just so you know.
for ( $o = 0; $o < count($opts) + 1; $o++ ) {
$res = getCheckTotal($index, $o);
if ( $o == 0 ) {
$otherval = $res["count"];
continue; // we don't want to print other right now
}
if ( $res["count"] > 0 ) {
printOptLine( $opts[$o-1], $res["count"], $o-1 );
}
}
if ( $otherval > 0 ) {
printOptLine( "Other", $otherval, $o-1 );
$otherval = 0;
}
$unanswered = getCheckUnanswered($index);
if ( $unanswered["count"] > 0 ) {
printOptLine( "(Did not choose any)", $unanswered["count"] );
}
}
?>