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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
<?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: printanswers.php 6728 2009-04-27 13:07:23Z c_schmitz $ * */
//Security Checked: POST, GET, SESSION, REQUEST, returnglobal, DB require_once(dirname(__FILE__).'/classes/core/startup.php'); require_once(dirname(__FILE__).'/config-defaults.php'); require_once(dirname(__FILE__).'/common.php'); if(isset($usepdfexport) && $usepdfexport == 1) { require_once(dirname(__FILE__).$pdfexportdir."/extensiontcpdf.php"); }
//DEFAULT SETTINGS FOR TEMPLATES if (!$publicdir) {$publicdir=".";} $tpldir="$publicdir/templates";
@session_start(); if (isset($_SESSION['sid'])) {$surveyid=$_SESSION['sid'];} else die();
//Debut session time out if (!isset($_SESSION['finished']) || !isset($_SESSION['srid'])) // Argh ... a session time out! RUN! //display "sorry but your session has expired" { require_once($rootdir.'/classes/core/language.php'); $baselang = GetBaseLanguageFromSurveyID($surveyid); $clang = new limesurvey_lang($baselang); //A nice exit
sendcacheheaders(); doHeader();
echo templatereplace(file_get_contents("$tpldir/default/startpage.pstpl")); echo "\t\t<center><br />\n" ."\t\t\t<font color='RED'><strong>".$clang->gT("ERROR")."</strong></font><br />\n" ."\t\t\t".$clang->gT("We are sorry but your session has expired.")."<br />".$clang->gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection.")."<br />\n" ."\t\t\t".sprintf($clang->gT("Please contact %s ( %s ) for further assistance."),$siteadminname,$siteadminemail)."\n" ."\t\t</center><br />\n";
echo templatereplace(file_get_contents("$tpldir/default/endpage.pstpl")); doFooter(); exit; }; //Fin session time out
$id=$_SESSION['srid']; //I want to see the answers with this id $clang = $_SESSION['s_lang'];
//A little bit of debug to see in the noodles plate /*if ($debug==2) { echo "MonSurveyID $surveyid et ma langue ". $_SESSION['s_lang']. " et SRID = ". $_SESSION['srid'] ."<br />"; echo "session id".session_id()." \n"."<br />";
echo //"secanswer ". $_SESSION['secanswer'] "oldsid ". $_SESSION['oldsid']."<br />" ."step ". $_SESSION['step']."<br />" ."scid ". $_SESSION['scid'] ."srid ". $_SESSION['srid']."<br />" ."datestamp ". $_SESSION['datestamp']."<br />" ."insertarray ". $_SESSION['insertarray']."<br />" ."fieldarray ". $_SESSION['fieldarray']."<br />"; ."holdname". $_SESSION['holdname'];
print " limit ". $limit."<br />"; //afficher les 50 derniéres réponses par ex. (pas nécessaire) print " surveyid ".$surveyid."<br />"; //sid print " id ".$id."<br />"; //identifiant de la réponses print " order ". $order ."<br />"; //ordre de tri (pas nécessaire) print " this survey ". $thissurvey['tablename']; }; */
//Ensure script is not run directly, avoid path disclosure if (!isset($rootdir) || isset($_REQUEST['$rootdir'])) {die("browse - Cannot run this script directly");}
//Select public language file $query = "SELECT language FROM ".db_table_name("surveys")." WHERE sid=$surveyid"; $result = db_execute_assoc($query) or safe_die("Error selecting language: <br />".$query."<br />".$connect->ErrorMsg()); //Checked
// Set language for questions and labels to base language of this survey $language = GetBaseLanguageFromSurveyID($surveyid); $thissurvey = getSurveyInfo($surveyid); //SET THE TEMPLATE DIRECTORY if (!$thissurvey['templatedir']) {$thistpl=$tpldir."/default";} else {$thistpl=$tpldir."/{$thissurvey['templatedir']}";} if (!is_dir($thistpl)) {$thistpl=$tpldir."/default";}
if ($thissurvey['printanswers']=='N') die(); //Die quietly if print answers is not permitted
//CHECK IF SURVEY IS ACTIVATED AND EXISTS $actquery = "SELECT * FROM ".db_table_name('surveys')." as a inner join ".db_table_name('surveys_languagesettings')." as b on (b.surveyls_survey_id=a.sid and b.surveyls_language=a.language) WHERE a.sid=$surveyid";
$actresult = db_execute_assoc($actquery); //Checked $actcount = $actresult->RecordCount(); if ($actcount > 0) { while ($actrow = $actresult->FetchRow()) { $surveytable = db_table_name("survey_".$actrow['sid']); $surveyname = "{$actrow['surveyls_title']}"; } }
//OK. IF WE GOT THIS FAR, THEN THE SURVEY EXISTS AND IT IS ACTIVE, SO LETS GET TO WORK.
require_once($rootdir.'/classes/core/language.php'); // has been secured if (isset($_SESSION['s_lang'])) { $clang = SetSurveyLanguage( $surveyid, $_SESSION['s_lang']); } else { $baselang = GetBaseLanguageFromSurveyID($surveyid); $clang = SetSurveyLanguage( $surveyid, $baselang); } //SHOW HEADER $printoutput = ''; if(isset($usepdfexport) && $usepdfexport == 1) { $printoutput .= "<form action='printanswers.php?printableexport=pdf' method='post'>\n<center><input type='submit' value='".$clang->gT("PDF Export")."'id=\"exportbutton\"/><input type='hidden' name='printableexport' /></center></form>"; } if(isset($_POST['printableexport'])) { $pdf = new PDF($pdforientation); $pdf->SetFont($pdfdefaultfont,'',$pdffontsize); $pdf->AddPage(); $pdf->titleintopdf("Survey Name: ".$surveyname,"SurveyID: ".$surveyid); } $printoutput .= "\t<span class='printouttitle'><strong>".$clang->gT("Survey Name (ID)").":</strong> $surveyname ($surveyid)</span><br />\n";
//FIRST LETS GET THE NAMES OF THE QUESTIONS AND MATCH THEM TO THE FIELD NAMES FOR THE DATABASE $fnquery = "SELECT * FROM ".db_table_name("questions").", ".db_table_name("groups").", ".db_table_name("surveys")." WHERE ".db_table_name("questions").".gid=".db_table_name("groups").".gid AND ".db_table_name("groups").".sid=".db_table_name("surveys").".sid AND ".db_table_name("questions").".sid='$surveyid' AND ".db_table_name("questions").".language='{$language}' AND ".db_table_name("groups").".language='{$language}' ORDER BY ".db_table_name("groups").".group_order, ".db_table_name("questions").".title"; $fnresult = db_execute_assoc($fnquery); //Checked $fncount = 0;
$fnrows = array(); //Create an empty array in case fetch_array does not return any rows while ($fnrow = $fnresult->FetchRow()) {++$fncount; $fnrows[] = $fnrow; $private = $fnrow['private']; $datestamp=$fnrow['datestamp']; $ipaddr=$fnrow['ipaddr']; $refurl=$fnrow['refurl'];} // Get table output into array
// Perform a case insensitive natural sort on group name then question title of a multidimensional array usort($fnrows, 'CompareGroupThenTitle');
$fnames[] = array("id", "id", "id");
if ($private == "N") //add token to top ofl ist is survey is not private { $fnames[] = array("token", "token", $clang->gT("Token ID")); } //The "submitdate" field shouldn't show. If there is a datestamp being recorded, that's covered in "datestamp". //The submitdate field is an internal field and always filled out, but sometimes is not actually the date the //survey is submitted (in anonymous surveys, the datestamp is always unix epoch) //$fnames[] = array("submitdate", "submitdate", $clang->gT("Date Submitted")); if ($datestamp == "Y") //add datetime to list if survey is datestamped { $fnames[] = array("datestamp", "datestamp", $clang->gT("Date Stamp")); } if ($ipaddr == "Y") //add ipaddr to list if survey should save submitters IP address { $fnames[] = array("ipaddr", "ipaddr", $clang->gT("IP Address")); } if ($refurl == "Y") //add refer_URL to list if survey should save referring URL { $fnames[] = array("refurl", "refurl", $clang->gT("Referring URL")); } foreach ($fnrows as $fnrow) { $field = "{$fnrow['sid']}X{$fnrow['gid']}X{$fnrow['qid']}"; $ftitle = "Grp{$fnrow['gid']}Qst{$fnrow['title']}"; $fquestion = $fnrow['question']; if ($printanswershonorsconditions == 1 && checkquestionfordisplay($fnrow['qid'],null)) {
if ($fnrow['type'] == "Q" || $fnrow['type'] == "M" || $fnrow['type'] == "A" || $fnrow['type'] == "B" || $fnrow['type'] == "C" || $fnrow['type'] == "E" || $fnrow['type'] == "F" || $fnrow['type'] == "H" || $fnrow['type'] == "J" || $fnrow['type'] == "K" || $fnrow['type'] == "P" || $fnrow['type'] == "^") {
$fnrquery = "SELECT * FROM ".db_table_name("answers")." WHERE qid={$fnrow['qid']} AND language='{$language}' ORDER BY sortorder, answer"; $fnrresult = db_execute_assoc($fnrquery); //Checked while ($fnrrow = $fnrresult->FetchRow()) { $fnames[] = array("$field{$fnrrow['code']}", "$ftitle ({$fnrrow['code']})", "{$fnrow['question']} ({$fnrrow['answer']})"); if ($fnrow['type'] == "P") {$fnames[] = array("$field{$fnrrow['code']}"."comment", "$ftitle"."comment", "{$fnrow['question']} (comment)");} } if ($fnrow['other'] == "Y" and ($fnrow['type']=="!" or $fnrow['type']=="L" or $fnrow['type']=="M" or $fnrow['type']=="P")) { $fnames[] = array("$field"."other", "$ftitle"."other", "{$fnrow['question']}(other)"); if ($fnrow['type'] == "P" and $fnrow['other'] == "Y") { $fnames[] = array("$field"."othercomment", "$ftitle"."othercomment", "{$fnrow['question']}(other comment)"); } } } elseif ($fnrow['type'] == ":" || $fnrow['type'] == ";") //MultiFlexi Numbers or Text { $lset=array(); $fnrquery = "SELECT * FROM ".db_table_name('answers')." WHERE qid={$fnrow['qid']} AND language='{$language}' ORDER BY sortorder, answer"; $fnrresult = db_execute_assoc($fnrquery); $fnr2query = "SELECT * FROM ".db_table_name('labels')." WHERE lid={$fnrow['lid']} AND language = '{$language}' ORDER BY sortorder, title"; $fnr2result = db_execute_assoc($fnr2query); while( $fnr2row = $fnr2result->FetchRow()) { $lset[]=$fnr2row; } while ($fnrrow = $fnrresult->FetchRow()) { foreach($lset as $ls) { $fnames[] = array("$field{$fnrrow['code']}_{$ls['code']}", "$ftitle ({$fnrrow['code']})", "{$fnrow['question']} ({$fnrrow['answer']}: {$ls['title']})"); } } } elseif ($fnrow['type'] == "R") { $fnrquery = "SELECT * FROM ".db_table_name("answers")." WHERE qid={$fnrow['qid']} AND language='{$language}' ORDER BY sortorder, answer"; $fnrresult = $connect->Execute($fnrquery); //Checked $fnrcount = $fnrresult->RecordCount(); for ($i=1; $i<=$fnrcount; $i++) { $fnames[] = array("$field$i", "$ftitle ($i)", "{$fnrow['question']} ($i)"); } } elseif ($fnrow['type'] == "1") //Dual Scale { $qidattributes=getQuestionAttributes($fnrow['qid']); $field = "{$fnrow['sid']}X{$fnrow['gid']}X{$fnrow['qid']}"; $ftitle = "Grp{$fnrow['gid']}Qst{$fnrow['title']}"; $fquestion = $fnrow['question'];
$aquery="SELECT * " ."FROM {$dbprefix}answers " ."WHERE qid={$fnrow['qid']} " ."AND {$dbprefix}answers.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ."ORDER BY sortorder, " ."answer"; $aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to Array questions<br />$aquery<br />".$connect->ErrorMsg()); //Checked $header1=$clang->gT('First Scale'); $header2=$clang->gT('Second Scale'); if ($thisheader=arraySearchByKey("dualscale_headerA", $qidattributes, "attribute", 1)) { $header1=$thisheader['value']; } if ($thisheader=arraySearchByKey("dualscale_headerB", $qidattributes, "attribute", 1)) { $header2=$thisheader['value']; } while ($arows = $aresult->FetchRow()) { $fnames[] = array("{$fnrow['sid']}X{$fnrow['gid']}X{$fnrow['qid']}{$arows['code']}#0", "$ftitle ", "{$fnrow['question']} {$arows['answer']} - ".$header1); $fnames[] = array("{$fnrow['sid']}X{$fnrow['gid']}X{$fnrow['qid']}{$arows['code']}#1", "$ftitle ", "{$fnrow['question']} {$arows['answer']} - ".$header2); } //while }
elseif ($fnrow['type'] == "O") { $fnames[] = array("$field", "$ftitle", "{$fnrow['question']}"); $field2 = $field."comment"; $ftitle2 = $ftitle."[Comment]"; $longtitle = "{$fnrow['question']}<br />[Comment]"; $fnames[] = array("$field2", "$ftitle2", "$longtitle"); } else { $fnames[] = array("$field", "$ftitle", "{$fnrow['question']}"); if (($fnrow['type'] == "L" || $fnrow['type'] == "!") && $fnrow['other'] == "Y") { $fnames[] = array("$field"."other", "$ftitle"."other", "{$fnrow['question']}(other)"); } } } // End If checkquestionfordisplay
}
$nfncount = count($fnames)-1; //SHOW INDIVIDUAL RECORD $idquery = "SELECT * FROM $surveytable WHERE id=$id"; $idresult = db_execute_assoc($idquery) or safe_die ("Couldn't get entry<br />\n$idquery<br />\n".$connect->ErrorMsg()); //Checked while ($idrow = $idresult->FetchRow()) {$id=$idrow['id']; $rlangauge=$idrow['startlanguage'];} $next=$id+1; $last=$id-1; $printoutput .= "<table class='printouttable' >\n"; if(isset($_POST['printableexport'])) { $pdf->intopdf($clang->gT("Question").": ".$clang->gT("Your Answer")); } $printoutput .= "<tr><th>".$clang->gT("Question")."</th><th>".$clang->gT("Your Answer")."</th></tr>\n"; $idresult = db_execute_assoc($idquery) or safe_die ("Couldn't get entry<br />$idquery<br />".$connect->ErrorMsg()); //Checked while ($idrow = $idresult->FetchRow()) { $i=0; for ($i; $i<$nfncount+1; $i++) { $printoutput .= "\t<tr>\n" ."\t\t<td>{$fnames[$i][2]}</td>\n" ."\t\t<td>" .getextendedanswer($fnames[$i][0], $idrow[$fnames[$i][0]]) ."</td>\n" ."\t</tr>\n"; if(isset($_POST['printableexport'])) { $pdf->intopdf(strip_tags($fnames[$i][2]).": ".strip_tags(getextendedanswer($fnames[$i][0], $idrow[$fnames[$i][0]]))); $pdf->ln(2); } } } $printoutput .= "</table>\n"; if(isset($_POST['printableexport'])) { // IE6 Header-Cache fix // Wenn der IE 6 das pdf file nicht erkennt, liegts am IE6 Nutzer //(zu doof, der Browser kennt keine pdf's oder kein reader ist installiert) // oder daran das man multipleIE verwendet. // header('Cache-Control: no-cache, must-revalidate'); //Adjust maxage appropriately // header('Pragma: public'); // // // Wir werden eine PDF Datei ausgeben // // \n\n bewirkt eine korrektes erkennen des Content-type im IE // // header('Content-Disposition: attachment; filename="'.$clang->gT($surveyname).'-'.$surveyid.'.pdf"'); // header('Content-type: application/pdf'); // // header('Content-Transfer-Encoding: binary'); // //header('Content-Length: '. filesize($filename));
//session_cache_limiter('private'); header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); if (preg_match("/MSIE/i", $_SERVER["HTTP_USER_AGENT"])) { /* * $dateiname = $InternalReferenceNumber.'.pdf'; $pdf->Output($dateiname, 'F'); header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="'.basename($dateiname).'"'); readfile($dateiname); */ header("Content-type: application/pdf"); header("Content-Transfer-Encoding: binary"); header("Content-Disposition: Attachment; filename=\"". $clang->gT($surveyname)."-".$surveyid.".pdf\""); $pdf->Output("tmp/".$clang->gT($surveyname)."-".$surveyid.".pdf", "F"); header("Content-Length: ". filesize("tmp/".$clang->gT($surveyname)."-".$surveyid.".pdf")); readfile("tmp/".$clang->gT($surveyname)."-".$surveyid.".pdf"); unlink("tmp/".$clang->gT($surveyname)."-".$surveyid.".pdf"); //$pdf->write_out($clang->gT($surveyname)."-".$surveyid.".pdf"); } else { header("Content-Type: application/pdf"); //header("Content-Length: ". $size); $pdf->write_out($clang->gT($surveyname)."-".$surveyid.".pdf"); } }
//tadaaaaaaaaaaa : display the page with the answers of user if(!isset($_POST['printableexport'])) { sendcacheheaders(); doHeader(); echo templatereplace(file_get_contents("$thistpl/startpage.pstpl")); echo templatereplace(file_get_contents("$thistpl/printanswers.pstpl")); echo templatereplace(file_get_contents("$thistpl/endpage.pstpl")); echo "</body></html>"; } ?>
|