C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$RAQKNYH\admin\vvexport.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.

* $Id: vvexport.php 6606 2009-04-09 18:26:36Z c_schmitz $
*/

// Security Checked: POST, GET, SESSION, REQUEST, returnglobal, DB

//Exports all responses to a survey in special "Verified Voting" format.

include_once("login_check.php");

$sumquery5 "SELECT b.* FROM {$dbprefix}surveys AS a INNER JOIN {$dbprefix}surveys_rights AS b ON a.sid = b.sid WHERE a.sid=$surveyid AND b.uid = ".$_SESSION['loginID']; //Getting rights for this survey and user
$sumresult5 db_execute_assoc($sumquery5); //Checked
$sumrows5 $sumresult5->FetchRow();

if (
$sumrows5['export'] != "1")
{
    return;
}
if (!
$subaction == "export")
{
    if (
incompleteAnsFilterstate() === true)
    {
        
$selecthide="selected='selected'";
        
$selectshow="";
    }
    else
    {
        
$selecthide="";
        
$selectshow="selected='selected'";
    }

    
$vvoutput "<br /><form method='post' action='admin.php?action=vvexport&sid=$surveyid'>"
        
."<table align='center' class='outlinetable'>"
        
."<tr>"
        
." <th colspan='2'>".$clang->gT("Export a VV survey file")."</th>"
        
."</tr>"
        
."<tr>"
        
." <td align='right'>".$clang->gT("Export Survey").":</td>"
        
." <td><input type='text' size='10' value='$surveyid' name='sid' readonly='readonly' /></td>"
        
."</tr>"
        
."<tr>"
        
." <td align='right'>".$clang->gT("Filter incomplete answers")." </td>"
        
." <td><select name='filterinc'>\n"
        
."  <option value='filter' $selecthide>".$clang->gT("Enable")."</option>\n"
        
."  <option value='show' $selectshow>".$clang->gT("Disable")."</option>\n"
        
." </select></td>\n"
        
."</tr>"
        
."<tr>"
        
." <td align='right'>".$clang->gT("File Extension")." </td>\n"
        
." <td><input type='text' name='extension' size='3' value='csv'></td>\n"
        
."</tr>\n"
        
."<tr>"
        
." <td colspan='2' align='center'>"
        
."  <input type='submit' value='".$clang->gT("Export Responses")."' />&nbsp;"
        
."  <input type='hidden' name='subaction' value='export' />"
        
." </td>"
        
."</tr>"
        
."<tr><td colspan='2' align='center'>[<a href='$scriptname?action=browse&amp;sid=$surveyid'>".$clang->gT("Return to Survey Administration")."</a>]</td></tr>"
        
."</table>";
}
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($surveytabletrue));

    
//Create the human friendly first line
    
$firstline="";
    
$secondline="";
    foreach (
$fieldnames as $field)
    {
        
$fielddata=arraySearchByKey($field$fieldmap"fieldname"1);
        
//$vvoutput .= "<pre>";print_r($fielddata);$vvoutput .= "</pre>";
        
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:<br />$query<br />".$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!
            
if($field == "submitdate" && !$value) {$value "NULL";}
            
$sun[]=$value;
        }
        
$beach=implode($s$sun);
        
$vvoutput .= $beach;
        unset(
$sun);
        
$vvoutput .= "\n";
    }
    echo 
$vvoutput;
    exit;

    
//$vvoutput .= "<pre>$firstline</pre>";
    //$vvoutput .= "<pre>$secondline</pre>";
    //$vvoutput .= "<pre>"; print_r($fieldnames); $vvoutput .= "</pre>";
    //$vvoutput .= "<pre>"; print_r($fieldmap); $vvoutput .= "</pre>";

}

?>