/
Statistics_userController.php
297 lines (243 loc) · 10.1 KB
/
Statistics_userController.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
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
<?php
/*
* LimeSurvey
* Copyright (C) 2007-2011 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$
*/
/*
* Created 12-2008 by Maziminke (maziminke@web.de)
*
* This file handles the "Show results to users" option:
* Survey Settings -> Presentation & navigation -> "Public statistics?"
*
* The admin can set a question attribute "public_statistics" for each question
* to determine whether the results of a certain question should be shown to the user
* after he/she has submitted the survey.
*
* See http://docs.limesurvey.org/tiki-index.php?page=Question+attributes#public_statistics
*/
class Statistics_userController extends LSYii_Controller {
public function _remap($method, $params = array())
{
array_unshift($params, $method);
return call_user_func_array(array($this, "action"), $params);
}
function actionAction($surveyid,$language)
{
$iSurveyID=(int)$surveyid;
//$postlang = returnglobal('lang');
Yii::import('application.libraries.admin.progressbar',true);
Yii::app()->loadHelper("admin/statistics");
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('surveytranslator');
$data = array();
//XXX enable/disable this for testing
//$publicgraphs = 1;
//$showaggregateddata = 1;
/*
* List of important settings:
* - publicstatistics: General survey setting which determines if public statistics for this survey
* should be shown at all.
*
* - publicgraphs: General survey setting which determines if public statistics for this survey
* should include graphs or only show a tabular overview.
*
* - public_statistics: Question attribute which has to be applied to each question so that
* its statistics will be shown to the user. If not set no statistics for this question will be shown.
*
* - filterout_incomplete_answers: Setting taken from config-defaults.php which determines if
* not completed answers will be filtered.
*/
if(!isset($iSurveyID))
{
$iSurveyID=returnGlobal('sid');
}
else
{
$iSurveyID = (int) $iSurveyID;
}
if (!$iSurveyID)
{
//This next line ensures that the $iSurveyID value is never anything but a number.
safeDie('You have to provide a valid survey ID.');
}
if ($iSurveyID)
{
$actresult = Survey::model()->findAll('sid = :sid AND active = :active', array(':sid' => $iSurveyID, ':active' => 'Y')); //Checked
if (count($actresult) == 0)
{
safeDie('You have to provide a valid survey ID.');
}
else
{
$surveyinfo = getSurveyInfo($iSurveyID);
// CHANGE JSW_NZ - let's get the survey title for display
$thisSurveyTitle = $surveyinfo["name"];
// CHANGE JSW_NZ - let's get css from individual template.css - so define path
$thisSurveyCssPath = getTemplateURL($surveyinfo["template"]);
if ($surveyinfo['publicstatistics']!='Y')
{
safeDie('The public statistics for this survey are deactivated.');
}
//check if graphs should be shown for this survey
if ($surveyinfo['publicgraphs']=='Y')
{
$publicgraphs = 1;
}
else
{
$publicgraphs = 0;
}
}
}
//we collect all the output within this variable
$statisticsoutput ='';
//for creating graphs we need some more scripts which are included here
//True -> include
//False -> forget about charts
if (isset($publicgraphs) && $publicgraphs == 1)
{
require_once(APPPATH.'third_party/pchart/pchart/pChart.class');
require_once(APPPATH.'third_party/pchart/pchart/pData.class');
require_once(APPPATH.'third_party/pchart/pchart/pCache.class');
$MyCache = new pCache(Yii::app()->getConfig("tempdir").'/');
//$currentuser is created as prefix for pchart files
if (isset($_SERVER['REDIRECT_REMOTE_USER']))
{
$currentuser=$_SERVER['REDIRECT_REMOTE_USER'];
}
else if (session_id())
{
$currentuser=substr(session_id(), 0, 15);
}
else
{
$currentuser="standard";
}
}
// Set language for questions and labels to base language of this survey
if (isset($postlang) && $postlang != null )
$language = $postlang;
else
$language = Survey::model()->findByPk($iSurveyID)->language;
//set survey language for translations
$clang = SetSurveyLanguage($iSurveyID, $language);
//Create header (fixes bug #3097)
$surveylanguage= $language;
sendCacheHeaders();
$condition = false;
$header= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"".$surveylanguage."\" lang=\"".$surveylanguage."\"";
if (getLanguageRTL($surveylanguage))
{
$condition = true;
$header.=" dir=\"rtl\" ";
}
$sitename = Yii::app()->getConfig("sitename");
$data['surveylanguage'] = $surveylanguage;
$data['sitename'] = $sitename;
$data['condition'] = $condition;
$data['thisSurveyCssPath'] = $thisSurveyCssPath;
//number of records for this survey
$totalrecords = 0;
//count number of answers
$query = "SELECT count(*) FROM {{survey_".intval($iSurveyID)."}}";
//if incompleted answers should be filtert submitdate has to be not null
//this setting is taken from config-defaults.php
if (Yii::app()->getConfig("filterout_incomplete_answers") == true)
{
$query .= " WHERE {{survey_".intval($iSurveyID)."}}.submitdate is not null";
}
$result = Yii::app()->db->createCommand($query)->queryAll();
//$totalrecords = total number of answers
foreach($result as $row)
{
$totalrecords = reset($row);
}
//---------- CREATE SGQA OF ALL QUESTIONS WHICH USE "PUBLIC_STATISTICS" ----------
$summary = createCompleteSGQA($iSurveyID,$surveylanguage,true);
//---------- CREATE STATISTICS ----------
//some progress bar stuff
// Create progress bar which is shown while creating the results
$prb = new ProgressBar();
$prb->pedding = 2; // Bar Pedding
$prb->brd_color = "#404040 #dfdfdf #dfdfdf #404040"; // Bar Border Color
$prb->setFrame(); // set ProgressBar Frame
$prb->frame['left'] = 50; // Frame position from left
$prb->frame['top'] = 80; // Frame position from top
$prb->addLabel('text','txt1',$clang->gT("Please wait ...")); // add Text as Label 'txt1' and value 'Please wait'
$prb->addLabel('percent','pct1'); // add Percent as Label 'pct1'
$prb->addButton('btn1',$clang->gT('Go back'),'?action=statistics&sid='.$iSurveyID); // add Button as Label 'btn1' and action '?restart=1'
//progress bar starts with 35%
$process_status = 35;
$prb->show(); // show the ProgressBar
// 1: Get list of questions with answers chosen
//"Getting Questions and Answers ..." is shown above the bar
$prb->setLabelValue('txt1',$clang->gT('Getting questions and answers ...'));
$prb->moveStep(5);
// creates array of post variable names
for (reset($_POST); $key=key($_POST); next($_POST))
{
$postvars[]=$key;
}
$data['thisSurveyTitle'] = $thisSurveyTitle;
$data['totalrecords'] = $totalrecords;
$data['clang'] = $clang;
$data['summary'] = $summary;
//show some main data at the beginnung
// CHANGE JSW_NZ - let's allow html formatted questions to show
//push progress bar from 35 to 40
$process_status = 40;
//Show Summary results
if (isset($summary) && $summary)
{
//"Generating Summaries ..." is shown above the progress bar
$prb->setLabelValue('txt1',$clang->gT('Generating summaries ...'));
$prb->moveStep($process_status);
//let's run through the survey // Fixed bug 3053 with array_unique
$runthrough=array_unique($summary);
//loop through all selected questions
foreach ($runthrough as $rt)
{
//update progress bar
if ($process_status < 100) $process_status++;
$prb->moveStep($process_status);
} // end foreach -> loop through all questions
$helper = new statistics_helper();
$statisticsoutput .= $helper->generate_statistics($iSurveyID, $summary, $publicgraphs, 'html', null,$language,false);
} //end if -> show summary results
$data['statisticsoutput']=$statisticsoutput;
//done! set progress bar to 100%
if (isset($prb))
{
$prb->setLabelValue('txt1',$clang->gT('Completed'));
$prb->moveStep(100);
$prb->hide();
}
// Get the survey inforamtion
$thissurvey = getSurveyInfo($surveyid,$language);
//SET THE TEMPLATE DIRECTORY
if (!isset($thissurvey['templatedir']) || !$thissurvey['templatedir'])
{
$data['sTemplatePath'] = validateTemplateDir("default");
}
else
{
$data['sTemplatePath'] = validateTemplateDir($thissurvey['templatedir']);
}
header_includes('statistics_user.js');
$this->render('/statistics_user_view',$data);
//output footer
echo getFooter();
//Delete all Session Data
Yii::app()->session['finished'] = true;
}
}