Skip to content

Commit

Permalink
Merge branch 'Yii' of https://github.com/LimeSurvey/LimeSurvey.git in…
Browse files Browse the repository at this point in the history
…to Yii
  • Loading branch information
mennodekker committed Aug 21, 2012
2 parents 5614cbb + b6555d9 commit a6afb27
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 48 deletions.
36 changes: 18 additions & 18 deletions application/controllers/Statistics_userController.php
Expand Up @@ -35,9 +35,9 @@ public function _remap($method, $params = array())
return call_user_func_array(array($this, "action"), $params);
}

function actionAction($iSurveyID,$language)
function actionAction($surveyid,$language)
{
$surveyid=(int)$surveyid;
$iSurveyID=(int)$surveyid;
//$postlang = returnglobal('lang');
Yii::import('application.libraries.admin.progressbar',true);
Yii::app()->loadHelper("admin/statistics");
Expand Down Expand Up @@ -65,31 +65,31 @@ function actionAction($iSurveyID,$language)
* not completed answers will be filtered.
*/

if(!isset($surveyid))
if(!isset($iSurveyID))
{
$surveyid=returnGlobal('sid');
$iSurveyID=returnGlobal('sid');
}
else
{
$surveyid = (int) $surveyid;
$iSurveyID = (int) $iSurveyID;
}
if (!$surveyid)
if (!$iSurveyID)
{
//This next line ensures that the $surveyid value is never anything but a number.
//This next line ensures that the $iSurveyID value is never anything but a number.
safeDie('You have to provide a valid survey ID.');
}


if ($surveyid)
if ($iSurveyID)
{
$actresult = Survey::model()->findAll('sid = :sid AND active = :active', array(':sid' => $surveyid, ':active' => 'Y')); //Checked
$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($surveyid);
$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
Expand Down Expand Up @@ -145,7 +145,7 @@ function actionAction($iSurveyID,$language)
if (isset($postlang) && $postlang != null )
$language = $postlang;
else
$language = Survey::model()->findByPk($surveyid)->language;
$language = Survey::model()->findByPk($iSurveyID)->language;



Expand All @@ -165,7 +165,7 @@ function actionAction($iSurveyID,$language)
}

//set survey language for translations
$clang = SetSurveyLanguage($surveyid, $language);
$clang = SetSurveyLanguage($iSurveyID, $language);


//Create header (fixes bug #3097)
Expand Down Expand Up @@ -202,7 +202,7 @@ function actionAction($iSurveyID,$language)
}

//execute query
$result = Yii::app()->db->createCommand($query)->bindParam(":lang", $language, PDO::PARAM_STR)->bindParam(":surveyid", $surveyid, PDO::PARAM_INT)->queryAll();
$result = Yii::app()->db->createCommand($query)->bindParam(":lang", $language, PDO::PARAM_STR)->bindParam(":surveyid", $iSurveyID, PDO::PARAM_INT)->queryAll();

//store all the data in $rows
$rows = $result;
Expand All @@ -227,13 +227,13 @@ function actionAction($iSurveyID,$language)
$totalrecords = 0;

//count number of answers
$query = "SELECT count(*) FROM {{survey_".intval($surveyid)."}}";
$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($surveyid)."}}.submitdate is not null";
$query .= " WHERE {{survey_".intval($iSurveyID)."}}.submitdate is not null";
}
$result = Yii::app()->db->createCommand($query)->queryAll();

Expand Down Expand Up @@ -268,7 +268,7 @@ function actionAction($iSurveyID,$language)
foreach ($filters as $flt)
{
//SGQ identifier
$myfield = "{$surveyid}X{$flt[1]}X{$flt[0]}";
$myfield = "{$iSurveyID}X{$flt[1]}X{$flt[0]}";

//let's switch through the question type for each question
switch ($flt[2])
Expand Down Expand Up @@ -392,7 +392,7 @@ function actionAction($iSurveyID,$language)
$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='.$surveyid); // add Button as Label 'btn1' and action '?restart=1'
$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;
Expand Down Expand Up @@ -440,7 +440,7 @@ function actionAction($iSurveyID,$language)

} // end foreach -> loop through all questions

$statisticsoutput .= generate_statistics($surveyid, $summary, $summary, $publicgraphs, 'html',null,$language,false);
$statisticsoutput .= generate_statistics($iSurveyID, $summary, $summary, $publicgraphs, 'html',null,$language,false);

} //end if -> show summary results

Expand Down
12 changes: 5 additions & 7 deletions application/controllers/admin/export.php
Expand Up @@ -624,11 +624,11 @@ public function exportr()

//$typeMap = $this->_getTypeMap();

$length_vallabel = '120'; // Set the max text length of Value Labels
// $length_vallabel = '120'; // Set the max text length of Value Labels
$iLength = '25500'; // Set the max text length of Text Data
$length_varlabel = '25500'; // Set the max text length of Variable Labels
$headerComment = '';
$tempFile = '';
// $tempFile = '';

if ( ! isset($iSurveyID) ) { $iSurveyID = returnGlobal('sid'); }
$filterstate = incompleteAnsFilterState();
Expand Down Expand Up @@ -679,7 +679,7 @@ public function exportr()
header("Pragma: public");

$na = ""; //change to empty string instead of two double quotes to fix warnings on NA
SPSSExportData($iSurveyID, $iLength);
SPSSExportData($iSurveyID, $iLength, $na='', $q='"', $header=TRUE);

exit;
}
Expand All @@ -692,11 +692,9 @@ public function exportr()
header("Pragma: public");

echo $headerComment;
echo "data <- read.table(\"survey_" . $iSurveyID
."_R_data_file.csv\", sep=\",\", quote = \"'\", "
."na.strings=c(\"\",\"\\\"\\\"\"), "
."stringsAsFactors=FALSE)\n\n";

echo ('data <- read.csv("survey_' . $iSurveyID .'_R_data_file.csv", na.strings=c(",", "\"\""), stringsAsFactors=FALSE)');
echo ("\n\n");

// Build array that has to be returned
$fields = SPSSFieldMap($iSurveyID,"V");
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/surveyadmin.php
Expand Up @@ -667,7 +667,7 @@ public function getSurveys_json()


$aSurveyEntry['viewurl'] = $this->getController()->createUrl("/admin/survey/view/surveyid/" . $rows['sid']);
if (Yii::app()->db->schema->getTable("{{tokens_" . $rows['sid'] . "}}"))
if (tableExists('tokens_' . $rows['sid'] ))
{
$tokens = Tokens_dynamic::model($rows['sid'])->count();
$tokenscompleted = Tokens_dynamic::model($rows['sid'])->count(array(
Expand Down
1 change: 0 additions & 1 deletion application/controllers/survey/index.php
Expand Up @@ -247,7 +247,6 @@ function action()
$link = "<li><a href=\"#\" id='inactivesurvey' onclick = 'sendreq(".$rows['sid'].");' ";
//$link = "<li><a href=\"#\" id='inactivesurvey' onclick = 'convertGETtoPOST(".$this->getController()->createUrl('survey/send/')."?sid={$rows['sid']}&amp;)sendreq(".$rows['sid'].",".$rows['startdate'].",".$rows['expires'].");' ";
$link .= " $langtag class='surveytitle'>".$rows['surveyls_title']."</a>\n";
//if ($rows['publicstatistics'] == 'Y') $link .= "<a href='".$this->getController()->createUrl("/statistics_user/action/surveyid/".$rows['sid'])."'>(".$clang->gT('View statistics').")</a>";
$link .= "</li><div id='regform'></div>\n";
$list[]=$link;
}
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -475,7 +475,7 @@ function run($surveyid,$args) {
// Link to Public statistics **********
if ($thissurvey['publicstatistics'] == 'Y')
{
$url = Yii::app()->getController()->createUrl("statistics_user/sid/{$surveyid}/lang/".$_SESSION[$LEMsessid]['s_lang']);
$url = Yii::app()->getController()->createUrl("statistics_user/action/surveyid/{$surveyid}/language/".$_SESSION[$LEMsessid]['s_lang']);
$completed .= "<br /><br />"
. "<a class='publicstatisticslink' href='$url' target='_blank'>"
. $clang->gT("View the statistics for this survey.")
Expand Down
48 changes: 32 additions & 16 deletions application/helpers/export_helper.php
Expand Up @@ -54,8 +54,10 @@ function isNumericExtended($value) {
* @param mixed $iSurveyID The survey ID
* @param mixed $iLength Maximum text lenght data, usually 255 for SPSS <v16 and 16384 for SPSS 16 and later
* @param mixed $na Value for N/A data
* @param sep Quote separator. Use '\'' for SPSS, '"' for R
* @param logical $header If TRUE, adds SQGA code as column headings (used by export to R)
*/
function SPSSExportData ($iSurveyID, $iLength, $na = '') {
function SPSSExportData ($iSurveyID, $iLength, $na = '', $q='\'', $header=FALSE) {

// Build array that has to be returned
$fields = SPSSFieldMap($iSurveyID);
Expand All @@ -68,6 +70,19 @@ function SPSSExportData ($iSurveyID, $iLength, $na = '') {

//This shouldn't occur, but just to be safe:
if (count($fields)<>$num_fields) safeDie("Database inconsistency error");

// Add column headers (used by R export)
if($header==TRUE)
{
$i = 1;
foreach ($fields as $field) {
echo $q.strtoupper($field['sql_name']).$q;
if ($i<$num_fields && !$field['hide']) echo ',';
$i++;
}
echo("\n");
}


foreach ($result as $row) {
$row = array_change_key_case($row,CASE_UPPER);
Expand All @@ -84,7 +99,7 @@ function SPSSExportData ($iSurveyID, $iLength, $na = '') {
list( $year, $month, $day, $hour, $minute, $second ) = preg_split( '([^0-9])', $row[$fieldno] );
if ($year != '' && (int)$year >= 1970)
{
echo "'".date('d-m-Y H:i:s', mktime( $hour, $minute, $second, $month, $day, $year ) )."'";
echo $q.date('d-m-Y H:i:s', mktime( $hour, $minute, $second, $month, $day, $year ) ).$q;
} else
{
echo ($na);
Expand All @@ -97,66 +112,67 @@ function SPSSExportData ($iSurveyID, $iLength, $na = '') {
{
if ($row[$fieldno] == 'Y') // Yes/No Question Type
{
echo( "'1'");
echo( $q. 1 .$q);
} else if ($row[$fieldno] == 'N'){
echo( "'2'");
echo( $q. 2 .$q);
} else {
echo($na);
}
} else if ($field['LStype'] == 'G') //Gender
{
if ($row[$fieldno] == 'F')
{
echo( "'1'");
echo( $q. 1 .$q);
} else if ($row[$fieldno] == 'M'){
echo( "'2'");
echo( $q. 2 .$q);
} else {
echo($na);
}
} else if ($field['LStype'] == 'C') //Yes/No/Uncertain
{
if ($row[$fieldno] == 'Y')
{
echo( "'1'");
echo( $q. 1 .$q);
} else if ($row[$fieldno] == 'N'){
echo( "'2'");
echo( $q. 2 .$q);
} else if ($row[$fieldno] == 'U'){
echo( "'3'");
echo( $q. 3 .$q);
} else {
echo($na);
}
} else if ($field['LStype'] == 'E') //Increase / Same / Decrease
{
if ($row[$fieldno] == 'I')
{
echo( "'1'");
echo( $q. 1 .$q);
} else if ($row[$fieldno] == 'S'){
echo( "'2'");
echo( $q. 2 .$q);
} else if ($row[$fieldno] == 'D'){
echo( "'3'");
echo( $q. 3 .$q);
} else {
echo($na);
}
} elseif (($field['LStype'] == 'P' || $field['LStype'] == 'M') && (substr($field['code'],-7) != 'comment' && substr($field['code'],-5) != 'other'))
{
if ($row[$fieldno] == 'Y')
{
echo("'1'");
echo($q. 1 .$q);
} else
{
echo("'0'");
echo($q. 0 .$q);
}
} elseif (!$field['hide']) {
$strTmp=mb_substr(stripTagsFull($row[$fieldno]), 0, $iLength);
if (trim($strTmp) != ''){
$strTemp=str_replace(array("'","\n","\r"),array("''",' ',' '),trim($strTmp));
if($q=='\'') $strTemp=str_replace(array("'","\n","\r"),array("''",' ',' '),trim($strTmp));
if($q=='"') $strTemp=str_replace(array('"',"\n","\r"),array('""',' ',' '),trim($strTmp));
/*
* Temp quick fix for replacing decimal dots with comma's
if (isNumericExtended($strTemp)) {
$strTemp = str_replace('.',',',$strTemp);
}
*/
echo "'$strTemp'";
echo $q. $strTemp .$q ;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/expressions/em_core_helper.php
Expand Up @@ -1833,7 +1833,7 @@ public function sProcessStringContainingExpressions($src, $questionNum=0, $numRe
for($i=1;$i<=$numRecursionLevels;++$i)
{
// TODO - Since want to use <span> for dynamic substitution, what if there are recursive substititons?
$result = $this->sProcessStringContainingExpressionsHelper(htmlspecialchars_decode($result,ENT_QUOTES),$questionNum, $staticReplacement);
$result = $this->sProcessStringContainingExpressionsHelper($result ,$questionNum, $staticReplacement);
if ($i == $whichPrettyPrintIteration)
{
$prettyPrint = $this->prettyPrintSource;
Expand Down
5 changes: 2 additions & 3 deletions application/models/Tokens_dynamic.php
Expand Up @@ -82,13 +82,12 @@ public function rules()
array('usesleft','numerical', 'integerOnly'=>true,'allowEmpty'=>true),
array('mpid','numerical', 'integerOnly'=>true,'allowEmpty'=>true),
array('blacklisted', 'in','range'=>array('Y','N'), 'allowEmpty'=>true),
array('sent', 'in','range'=>array('Y','N'), 'allowEmpty'=>true),
array('completed', 'in','range'=>array('Y','N'), 'allowEmpty'=>true),
array('validfrom','date', 'format'=>array('yyyy-MM-dd', 'yyyy-MM-dd HH:mm', 'yyyy-MM-dd HH:mm:ss',), 'allowEmpty'=>true),
array('validuntil','date', 'format'=>array('yyyy-MM-dd', 'yyyy-MM-dd HH:mm', 'yyyy-MM-dd HH:mm:ss',), 'allowEmpty'=>true),
);
}



/**
* Returns summary information of this token table
*
Expand Down

0 comments on commit a6afb27

Please sign in to comment.