gT("Export VV file")). "
" ."
".$clang->gT("Export a VV survey file")."
" ."\n" ."

 " ."" ."

" ."

* ".$clang->gT("For easy opening in MS Excel, change the extension to 'tab' or 'txt'")."
\n"; } elseif (isset($surveyid) && $surveyid) { //Export is happening $extension=sanitize_paranoid_string(returnglobal('extension')); header("Content-Disposition: attachment; filename=vvexport_$surveyid.".$extension); 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"; $qfs = questionnaireSampleFilterstate(); if ($qfs != false) { //Limit responses by questionnaire and/or sample $query .= " JOIN `case` AS c ON ({$dbprefix}survey_$surveyid.token = c.token AND c.questionnaire_id = '{$qfs[0]}') "; if ($qfs[1] != 0) //if a sample is selected $query .= " JOIN `sample` AS s ON (s.sample_id = c.sample_id AND s.import_id = '{$qfs[1]}') "; } if (incompleteAnsFilterstate() == "inc") { $query .= " WHERE submitdate IS NULL "; } elseif (incompleteAnsFilterstate() == "filter") { $query .= " WHERE submitdate >= ".$connect->DBDate('1980-01-01'). " "; } $result = db_execute_assoc($query) or safe_die("Error:
$query
".$connect->ErrorMsg()); //Checked while ($row=$result->FetchRow()) { foreach ($fieldnames as $field) { if (is_null($row[$field])) { $value='{question_not_shown}'; } else { $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! if($field == "submitdate" && !$value) {$value = "NULL";} $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 .= "
"; } ?>