loadHelper("surveytranslator");
}
/**
* Constructor
*/
public function run($surveyid = 0, $subaction = null)
{
$surveyid = sanitize_int($surveyid);
//TODO: Convert question types to views
$clang = $this->getController()->lang;
$imageurl = Yii::app()->getConfig("imageurl");
$aData = array('clang' => $clang, 'imageurl' => $imageurl);
$aData['sql']='';
/*
* We need this later:
* 1 - Array Dual Scale
* 5 - 5 Point Choice
* A - Array (5 Point Choice)
* B - Array (10 Point Choice)
* C - Array (Yes/No/Uncertain)
* D - Date
* E - Array (Increase, Same, Decrease)
* F - Array (Flexible Labels)
* G - Gender
* H - Array (Flexible Labels) by Column
* I - Language Switch
* K - Multiple Numerical Input
* L - List (Radio)
* M - Multiple choice
* N - Numerical Input
* O - List With Comment
* P - Multiple choice with comments
* Q - Multiple Short Text
* R - Ranking
* S - Short Free Text
* T - Long Free Text
* U - Huge Free Text
* X - Boilerplate Question
* Y - Yes/No
* ! - List (Dropdown)
* : - Array (Flexible Labels) multiple drop down
* ; - Array (Flexible Labels) multiple texts
* | - File Upload
Debugging help:
echo '';
*/
//split up results to extend statistics -> NOT WORKING YET! DO NOT ENABLE THIS!
$showcombinedresults = 0;
/*
* this variable is used in the function shortencode() which cuts off a question/answer title
* after $maxchars and shows the rest as tooltip
*/
$maxchars = 50;
//we collect all the output within this variable
$statisticsoutput ='';
//output for chosing questions to cross query
$cr_statisticsoutput = '';
// This gets all the 'to be shown questions' from the POST and puts these into an array
$summary=returnGlobal('summary');
$statlang=returnGlobal('statlang');
//if $summary isn't an array we create one
if (isset($summary) && !is_array($summary)) {
$summary = explode("+", $summary);
}
//no survey ID? -> come and get one
if (!isset($surveyid)) {$surveyid=returnGlobal('sid');}
//still no survey ID -> error
$aData['surveyid'] = $surveyid;
// Set language for questions and answers to base language of this survey
$language = Survey::model()->findByPk($surveyid)->language;
$aData['language'] = $language;
//Call the javascript file
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . 'statistics.js');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . 'json-js/json2.min.js');
$aData['display']['menu_bars']['browse'] = $clang->gT("Quick statistics");
//Select public language file
$row = Survey::model()->find('sid = :sid', array(':sid' => $surveyid));
/*
* check if there is a datestamp available for this survey
* yes -> $datestamp="Y"
* no -> $datestamp="N"
*/
$datestamp = $row->datestamp;
// 1: Get list of questions from survey
/*
* We want to have the following data
* a) "questions" -> all table namens, e.g.
* qid
* sid
* gid
* type
* title
* question
* preg
* help
* other
* mandatory
* lid
* lid1
* question_order
* language
*
* b) "groups" -> group_name + group_order *
*/
//store all the data in $rows
$rows = Question::model()->getQuestionList($surveyid, $language);
//SORT IN NATURAL ORDER!
usort($rows, 'groupOrderThenQuestionOrder');
//put the question information into the filter array
$filters = array();
foreach ($rows as $row)
{
//store some column names in $filters array
$filters[]=array($row['qid'],
$row['gid'],
$row['type'],
$row['title'],
$row['group_name'],
flattenText($row['question']));
}
$aData['filters'] = $filters;
//var_dump($filters);
// SHOW ID FIELD
$grapherror = false;
$error = '';
if (!function_exists("gd_info")) {
$grapherror = true;
$error.='
'.$clang->gT('You do not have the GD Library installed. Showing charts requires the GD library to function properly.');
$error.='
'.$clang->gT('visit http://us2.php.net/manual/en/ref.image.php for more information').'
';
}
elseif (!function_exists("imageftbbox")) {
$grapherror = true;
$error.='
'.$clang->gT('You do not have the Freetype Library installed. Showing charts requires the Freetype library to function properly.');
$error.='
'.$clang->gT('visit http://us2.php.net/manual/en/ref.image.php for more information').'
';
}
if ($grapherror)
{
unset($_POST['usegraph']);
}
//pre-selection of filter forms
if (incompleteAnsFilterState() == "complete")
{
$selecthide="selected='selected'";
$selectshow="";
$selectinc="";
}
elseif (incompleteAnsFilterState() == "incomplete")
{
$selecthide="";
$selectshow="";
$selectinc="selected='selected'";
}
else
{
$selecthide="";
$selectshow="selected='selected'";
$selectinc="";
}
$aData['selecthide'] = $selecthide;
$aData['selectshow'] = $selectshow;
$aData['selectinc'] = $selectinc;
$aData['error'] = $error;
$survlangs = Survey::model()->findByPk($surveyid)->additionalLanguages;
$survlangs[] = Survey::model()->findByPk($surveyid)->language;
$aData['survlangs'] = $survlangs;
$aData['datestamp'] = $datestamp;
//if the survey contains timestamps you can filter by timestamp, too
//Output selector
//second row below options -> filter settings headline
$filterchoice_state=returnGlobal('filterchoice_state');
$aData['filterchoice_state'] = $filterchoice_state;
/*
* let's go through the filter array which contains
* ['qid'],
['gid'],
['type'],
['title'],
['group_name'],
['question'],
['lid'],
['lid1']);
*/
$currentgroup='';
$counter = 0;
foreach ($filters as $key1 => $flt)
{
//is there a previous question type set?
/*
* remember: $flt is structured like this
* ['qid'],
['gid'],
['type'],
['title'],
['group_name'],
['question'],
['lid'],
['lid1']);
*/
//SGQ identifier
//full question title
/*
* Check question type: This question types will be used (all others are separated in the if clause)
* 5 - 5 Point Choice
G - Gender
I - Language Switch
L - List (Radio)
M - Multiple choice
N - Numerical Input
| - File Upload
O - List With Comment
P - Multiple choice with comments
Y - Yes/No
! - List (Dropdown) )
*/
/////////////////////////////////////////////////////////////////////////////////////////////////
//This section presents the filter list, in various different ways depending on the question type
/////////////////////////////////////////////////////////////////////////////////////////////////
//let's switch through the question type for each question
switch ($flt[2])
{
case "K": // Multiple Numerical
//get answers
$result = Question::model()->getQuestionsForStatistics('title as code, question as answer', "parent_qid=$flt[0] AND language = '{$language}'", 'question_order');
$aData['result'][$key1]['key1'] = $result;
break;
case "Q": // Multiple Short Text
//get subqestions
$result = Question::model()->getQuestionsForStatistics('title as code, question as answer', "parent_qid=$flt[0] AND language = '{$language}'", 'question_order');
$aData['result'][$key1] = $result;
break;
//----------------------- ARRAYS --------------------------
case "A": // ARRAY OF 5 POINT CHOICE QUESTIONS
//get answers
$result = Question::model()->getQuestionsForStatistics('title, question', "parent_qid=$flt[0] AND language = '{$language}'", 'question_order');
$aData['result'][$key1] = $result;
break;
//just like above only a different loop
case "B": // ARRAY OF 10 POINT CHOICE QUESTIONS
$result = Question::model()->getQuestionsForStatistics('title, question', "parent_qid=$flt[0] AND language = '{$language}'", 'question_order');
$aData['result'][$key1] = $result;
break;
case "C": // ARRAY OF YES\No\$clang->gT("Uncertain") QUESTIONS
//get answers
$result = Question::model()->getQuestionsForStatistics('title, question', "parent_qid=$flt[0] AND language = '{$language}'", 'question_order');
$aData['result'][$key1] = $result;
break;
//similiar to the above one
case "E": // ARRAY OF Increase/Same/Decrease QUESTIONS
$result = Question::model()->getQuestionsForStatistics('title, question', "parent_qid=$flt[0] AND language = '{$language}'", 'question_order');
$aData['result'][$key1] = $result;
break;
case ";": //ARRAY (Multi Flex) (Text)
$result = Question::model()->getQuestionsForStatistics('title, question', "parent_qid=$flt[0] AND language = '{$language}' AND scale_id = 0", 'question_order');
$aData['result'][$key1] = $result;
foreach($result as $key => $row)
{
$fresult = Question::model()->getQuestionsForStatistics('title, question', "parent_qid=$flt[0] AND language = '{$language}' AND scale_id = 1", 'question_order');
$aData['fresults'][$key1][$key] = $fresult;
}
break;
case ":": //ARRAY (Multi Flex) (Numbers)
$result = Question::model()->getQuestionsForStatistics('title, question', "parent_qid=$flt[0] AND language = '{$language}' AND scale_id = 0", 'question_order');
$aData['result'][$key1] = $result;
foreach($result as $row)
{
$fresult = Question::model()->getQuestionsForStatistics('*', "parent_qid=$flt[0] AND language = '{$language}' AND scale_id = 1", 'question_order, title');
$aData['fresults'][$key1] = $fresult;
}
break;
/*
* For question type "F" and "H" you can use labels.
* The only difference is that the labels are applied to column heading
* or rows respectively
*/
case "F": // FlEXIBLE ARRAY
case "H": // ARRAY (By Column)
//Get answers. We always use the answer code because the label might be too long elsewise
$result = Question::model()->getQuestionsForStatistics('title, question', "parent_qid=$flt[0] AND language = '{$language}'", 'question_order');
$aData['result'][$key1] = $result;
//check all the answers
foreach($result as $row)
{
$fresult = Answer::model()->getQuestionsForStatistics('*', "qid=$flt[0] AND language = '{$language}'", 'sortorder, code');
$aData['fresults'][$key1] = $fresult;
}
//$statisticsoutput .= "\t\t\t\t