FetchRow(); if ($sumrows5['export'] != "1") { return; } if (!$subaction == "export") { if (incompleteAnsFilterstate() === true) { $selecthide="selected='selected'"; $selectshow=""; } else { $selecthide=""; $selectshow="selected='selected'"; } $vvoutput = "
" ."" ."" ."" ."" ."" ."" ."" ."" ."\n" ."" ."" ."" ."" ."
".$clang->gT("Export a VV survey file")."
".$clang->gT("Export Survey").":
".$clang->gT("Filter incomplete answers")."
" ." " ."" ."
[".$clang->gT("Return to Survey Administration")."]
"; } elseif (isset($surveyid) && $surveyid) { //Export is happening header("Content-Disposition: attachment; filename=vvexport_$surveyid.csv"); header("Content-type: text/comma-separated-values; charset=UTF-8"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: cache"); $s="\t"; $fieldmap=createFieldMap($surveyid, "full"); $surveytable = "{$dbprefix}survey_$surveyid"; GetBaseLanguageFromSurveyID($surveyid); $fieldnames = array_values($connect->MetaColumnNames($surveytable, true)); //Create the human friendly first line $firstline=""; $secondline=""; foreach ($fieldnames as $field) { $fielddata=arraySearchByKey($field, $fieldmap, "fieldname", 1); //$vvoutput .= "
";print_r($fielddata);$vvoutput .= "
"; if (count($fielddata) < 1) {$firstline.=$field;} else //{$firstline.=str_replace("\n", " ", str_replace("\t", " ", strip_tags($fielddata['question'])));} {$firstline.=preg_replace('/\s+/',' ',strip_tags($fielddata['question']));} $firstline .= $s; $secondline .= $field.$s; } $vvoutput = $firstline."\n"; $vvoutput .= $secondline."\n"; $query = "SELECT * FROM $surveytable"; if (incompleteAnsFilterstate() === true) { $query .= " WHERE submitdate is not null "; } $result = db_execute_assoc($query) or safe_die("Error:
$query
".$connect->ErrorMsg()); //Checked while ($row=$result->FetchRow()) { foreach ($fieldnames as $field) { $value=trim($row[$field]); // sunscreen for the value. necessary for the beach. // careful about the order of these arrays: // lbrace has to be substituted *first* $value=str_replace(array("{", "\n", "\r", "\t"), array("{lbrace}", "{newline}", "{cr}", "{tab}"), $value); // one last tweak: excel likes to quote values when it // exports as tab-delimited (esp if value contains a comma, // oddly enough). So we're going to encode a leading quote, // if it occurs, so that we can tell the difference between // strings that "really are" quoted, and those that excel quotes // for us. $value=preg_replace('/^"/','{quote}',$value); // yay! that nasty soab won't hurt us now! $sun[]=$value; } $beach=implode($s, $sun); $vvoutput .= $beach; unset($sun); $vvoutput .= "\n"; } echo $vvoutput; exit; //$vvoutput .= "
$firstline
"; //$vvoutput .= "
$secondline
"; //$vvoutput .= "
"; print_r($fieldnames); $vvoutput .= "
"; //$vvoutput .= "
"; print_r($fieldmap); $vvoutput .= "
"; } ?>