Ejemplo n.º 1
0
 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 {
                 $str = "\"{$answer['code']}\"";
             }
             if ($i < count($answers)) {
                 echo " {$str} \"{$answer['value']}\"\n";
             } else {
                 echo " {$str} \"{$answer['value']}\".\n";
             }
         }
     }
 }
 foreach ($fields as $field) {
     if ($field['scale'] !== '') {
         switch ($field['scale']) {
Ejemplo n.º 2
0
/**
 * 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;
    }
}