if ($field['SPSStype'] == 'DATETIME23.2') { $field['size'] = ''; } if ($field['SPSStype'] == 'F' && ($field['LStype'] == 'N' || $field['LStype'] == 'K')) { $field['size'] .= '.' . ($field['size'] - 1); } if (!$field['hide']) { echo "\n {$field['id']} {$field['SPSStype']}{$field['size']}"; } } echo ".\nCACHE.\n" . "EXECUTE.\n"; //Create the variable labels: echo "*Define Variable Properties.\n"; foreach ($fields as $field) { if (!$field['hide']) { echo "VARIABLE LABELS " . $field['id'] . " \"" . str_replace('"', '""', mb_substr(strip_tags_full($field['VariableLabel']), 0, $length_varlabel)) . "\".\n"; } } // Create our Value Labels! echo "*Define Value labels.\n"; foreach ($fields as $field) { if (isset($field['answers'])) { $answers = $field['answers']; //print out the value labels! echo "VALUE LABELS {$field['id']}\n"; $i = 0; foreach ($answers as $answer) { $i++; if ($field['SPSStype'] == "F" && my_is_numeric($answer['code'])) { $str = "{$answer['code']}"; } else {
//or safe_die ("Couldn't get token info<br />$tokenquery<br />".$connect->ErrorMsg()); while ($tokenrow = $tokenresult->FetchRow()) { $exportoutput .= "{$tokenrow['lastname']}, {$tokenrow['firstname']}"; if ($type == "pdf") { $pdf->intopdf($tokenrow['lastname'] . " , " . $tokenrow['firstname']); } } } else { $exportoutput .= $elang->gT("Tokens problem - token table missing"); if ($type == "pdf") { $pdf->intopdf($elang->gT("Tokens problem - token table missing")); } } } else { if ($type == "csv") { $exportoutput .= str_replace("\r\n", "\n", str_replace("\"", "\"\"", strip_tags_full($drow[$i]))); } else { if ($type == "pdf") { $pdf->intopdf(trim(strip_tags($drow[$i]))); } else { if ($type == "doc") { $exportoutput .= trim(strip_tags($drow[$i])); } else { $exportoutput .= str_replace("\r\n", " ", $drow[$i]); } } } } } if ($type == "csv") { $exportoutput .= "\"";
/** * Check it the gives field has a labelset and return it as an array if true * * @param $field array field from spss_fieldmap * @return array or false */ function spss_getvalues($field = array(), $qidattributes = null) { global $surveyid, $dbprefix, $connect, $clang, $language, $length_vallabel; if (!isset($field['LStype']) || empty($field['LStype'])) { return false; } $answers = array(); if (strpos("!LORFWZWH1", $field['LStype']) !== false) { if (substr($field['code'], -5) == 'other' || substr($field['code'], -7) == 'comment') { //We have a comment field, so free text } else { $query = "SELECT {$dbprefix}answers.code, {$dbprefix}answers.answer,\r\n\t\t\t{$dbprefix}questions.type FROM {$dbprefix}answers, {$dbprefix}questions WHERE"; if (isset($field['scale_id'])) { $query .= " {$dbprefix}answers.scale_id = " . (int) $field['scale_id'] . " AND"; } $query .= " {$dbprefix}answers.qid = '" . $field["qid"] . "' and {$dbprefix}questions.language='" . $language . "' and {$dbprefix}answers.language='" . $language . "'\r\n\t\t\t and {$dbprefix}questions.qid='" . $field['qid'] . "' ORDER BY sortorder ASC"; $result = db_execute_assoc($query) or safe_die("Couldn't lookup value labels<br />{$query}<br />" . $connect->ErrorMsg()); //Checked $num_results = $result->RecordCount(); if ($num_results > 0) { $displayvaluelabel = 0; # Build array that has to be returned for ($i = 0; $i < $num_results; $i++) { $row = $result->FetchRow(); $answers[] = array('code' => $row['code'], 'value' => mb_substr(strip_tags_full($row["answer"]), 0, $length_vallabel)); } } } } elseif ($field['LStype'] == ':') { $displayvaluelabel = 0; //Get the labels that could apply! if (is_null($qidattributes)) { $qidattributes = getQuestionAttributes($field["qid"], $field['LStype']); } if (trim($qidattributes['multiflexible_max']) != '') { $maxvalue = $qidattributes['multiflexible_max']; } else { $maxvalue = 10; } if (trim($qidattributes['multiflexible_min']) != '') { $minvalue = $qidattributes['multiflexible_min']; } else { $minvalue = 1; } if (trim($qidattributes['multiflexible_step']) != '') { $stepvalue = $qidattributes['multiflexible_step']; } else { $stepvalue = 1; } if ($qidattributes['multiflexible_checkbox'] != 0) { $minvalue = 0; $maxvalue = 1; $stepvalue = 1; } for ($i = $minvalue; $i <= $maxvalue; $i += $stepvalue) { $answers[] = array('code' => $i, 'value' => $i); } } elseif ($field['LStype'] == 'M' && substr($field['code'], -5) != 'other' && $field['size'] > 0) { $answers[] = array('code' => 1, 'value' => $clang->gT('Yes')); $answers[] = array('code' => 0, 'value' => $clang->gT('Not Selected')); } elseif ($field['LStype'] == "P" && substr($field['code'], -5) != 'other' && substr($field['code'], -7) != 'comment') { $answers[] = array('code' => 1, 'value' => $clang->gT('Yes')); $answers[] = array('code' => 0, 'value' => $clang->gT('Not Selected')); } elseif ($field['LStype'] == "G" && $field['size'] > 0) { $answers[] = array('code' => 1, 'value' => $clang->gT('Female')); $answers[] = array('code' => 2, 'value' => $clang->gT('Male')); } elseif ($field['LStype'] == "Y" && $field['size'] > 0) { $answers[] = array('code' => 1, 'value' => $clang->gT('Yes')); $answers[] = array('code' => 2, 'value' => $clang->gT('No')); } elseif ($field['LStype'] == "C" && $field['size'] > 0) { $answers[] = array('code' => 1, 'value' => $clang->gT('Yes')); $answers[] = array('code' => 2, 'value' => $clang->gT('No')); $answers[] = array('code' => 3, 'value' => $clang->gT('Uncertain')); } elseif ($field['LStype'] == "E" && $field['size'] > 0) { $answers[] = array('code' => 1, 'value' => $clang->gT('Increase')); $answers[] = array('code' => 2, 'value' => $clang->gT('Same')); $answers[] = array('code' => 3, 'value' => $clang->gT('Decrease')); } if (count($answers) > 0) { //check the max width of the answers $size = 0; $spsstype = $field['SPSStype']; foreach ($answers as $answer) { $len = mb_strlen($answer['code']); if ($len > $size) { $size = $len; } if ($spsstype == 'F' && (my_is_numeric($answer['code']) === false || $size > 16)) { $spsstype = 'A'; } } $answers['SPSStype'] = $spsstype; $answers['size'] = $size; return $answers; } else { return false; } }
switch ($field['SPSStype']) { case 'F': $type = "numeric"; break; case 'A': $type = "character"; break; case 'DATETIME23.2': case 'SDATE': $type = "character"; //@TODO set $type to format for date break; } if (!$field['hide']) { echo "data[, " . $i . "] <- " . "as.{$type}(data[, " . $i . "])\n"; echo 'attributes(data)$variable.labels[' . $i . '] <- "' . addslashes(htmlspecialchars_decode(mb_substr(strip_tags_full($field['VariableLabel']), 0, $length_varlabel))) . '"' . "\n"; // Create the value Labels! if (isset($field['answers'])) { $answers = $field['answers']; //print out the value labels! if ($field['LStype'] != ':') { echo 'data[, ' . $i . '] <- factor(data[, ' . $i . '], levels=c('; $str = ""; foreach ($answers as $answer) { if ($field['SPSStype'] == "F" && my_is_numeric($answer['code'])) { $str .= ",{$answer['code']}"; } else { $str .= ",\"{$answer['code']}\""; } } $str = mb_substr($str, 1);
case 'SDATE': $type="character"; //@TODO set $type to format for date break; } if (!$field['hide']) { echo "data[, " . $i . "] <- " ."as.$type(data[, " . $i . "])\n"; echo 'attributes(data)$variable.labels[' . $i . '] <- "' . addslashes( htmlspecialchars_decode( mb_substr( strip_tags_full( $field['VariableLabel']),0,$length_varlabel))) // <AdV> added htmlspecialchars_decode . '"' . "\n"; // Create the value Labels! if (isset($field['answers'])) { $answers = $field['answers']; //print out the value labels! // data$V14=factor(data$V14,levels=c(1,2,3),labels=c("Yes","No","Uncertain")) echo 'data[, ' . $i .'] <- factor(data[, ' . $i . '], levels=c('; $str=""; foreach ($answers as $answer) { if ($field['SPSStype']=="F" && my_is_numeric($answer['code'])) { $str .= ",{$answer['code']}"; } else { $str .= ",\"{$answer['code']}\"";