コード例 #1
0
ファイル: export.php プロジェクト: ddrmoscow/queXC
 */
include "../config.inc.php";
/**
 * XHTML functions
 */
include "../functions/functions.xhtml.php";
/**
 * DB functions
 */
include "../db.inc.php";
/**
 * Export functions
 */
include "../functions/functions.export.php";
if (isset($_GET['data'])) {
    export_fixed_width(intval($_GET['data']));
    exit;
}
if (isset($_GET['ddi'])) {
    export_ddi(intval($_GET['ddi']));
    exit;
}
if (isset($_GET['csv'])) {
    export_csv(intval($_GET['csv']));
    exit;
}
if (isset($_GET['csvl'])) {
    export_csv(intval($_GET['csvl']), true, true);
    exit;
}
if (isset($_GET['pspp'])) {
コード例 #2
0
ファイル: functions.export.php プロジェクト: ddrmoscow/queXC
/**
 * Export the data in PSPP form (may also work with SPSS)
 *
 * @param int data_id The data id to export
 * @param bool include_data Whether or not to include the data
 *
 */
function export_pspp($data_id, $include_data = true)
{
    global $db;
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: text");
    header("Content-Disposition: attachment; filename=data_{$data_id}.sps");
    if ($include_data) {
        echo "DATA LIST FIXED /";
    } else {
        echo "DATA LIST FILE=\"data_{$data_id}.txt\" /";
    }
    //export variables in the format: varname start-end (type)
    //Make sure not to include variables with no name as there is no way to identify them
    $sql = "SELECT c.*\r\n\t\tFROM `column` as c\r\n\t\tWHERE data_id = '{$data_id}'\r\n\t\tAND c.name IS NOT NULL\r\n\t\tAND c.name != ''\r\n\t\tORDER BY c.in_input DESC , c.startpos ASC , c.sortorder ASC, c.column_id ASC";
    $cols = $db->GetAll($sql);
    $startpos = 1;
    $width = 0;
    foreach ($cols as $key => $col) {
        $varname = $col['name'];
        if ($col['type'] == 0) {
            $vartype = ' ';
        } else {
            $vartype = '(A) ';
        }
        if (!empty($col['startpos']) && $col['startpos'] > 0) {
            $startpos = $col['startpos'];
        } else {
            $startpos = $startpos + $width;
        }
        $width = $col['width'];
        $endpos = $startpos + $width - 1;
        if ($width != 0) {
            echo "{$varname} {$startpos}-{$endpos} {$vartype}";
        } else {
            unset($cols[$key]);
        }
    }
    echo " .\nVARIABLE LABELS ";
    $first = true;
    foreach ($cols as $col) {
        $vardescription = pspp_escape($col['description']);
        $varname = $col['name'];
        if ($first) {
            $first = false;
        } else {
            echo "/";
        }
        echo "{$varname} '{$vardescription}' ";
    }
    echo " .\nVALUE LABELS";
    //If there are categories, insert them here
    foreach ($cols as $col) {
        if (!empty($col['code_level_id'])) {
            $varname = $col['name'];
            $code_level_id = $col['code_level_id'];
            $sql = "SELECT value,label\r\n\t\t\t\tFROM code\r\n\t\t\t\tWHERE code_level_id = '{$code_level_id}'\r\n\t\t\t\tORDER BY code_id ASC";
            $codes = $db->GetAll($sql);
            if (!empty($codes)) {
                echo " /{$varname} ";
                if ($col['type'] == 0) {
                    $surround = "";
                } else {
                    $surround = "'";
                }
                foreach ($codes as $code) {
                    echo $surround . $code['value'] . "{$surround} '" . pspp_escape($code['label'], 60) . "' ";
                }
            }
        }
    }
    echo " .\n";
    if ($include_data) {
        echo "BEGIN DATA.\n";
        export_fixed_width($data_id, false);
        echo "END DATA.\n";
    }
}