Skip to content

Commit

Permalink
Merge branch '2.05' of github.com:LimeSurvey/LimeSurvey into 2.05
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Jun 27, 2013
2 parents 0cfbd2d + c624345 commit fe47d0b
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 50 deletions.
26 changes: 15 additions & 11 deletions application/helpers/admin/export/SurveyDao.php
Expand Up @@ -84,10 +84,10 @@ public function loadSurveyById($id, $lang = null)
* If none are then all responses are loaded.
*
* @param Survey $survey
* @param int $iOffset
* @param int $iLimit
* @param int $iMinimum
* @param int $iMaximum
*/
public function loadSurveyResults(SurveyObj $survey, $iLimit, $iOffset, $iMaximum, $sFilter='' )
public function loadSurveyResults(SurveyObj $survey, $iMinimum, $iMaximum, $sFilter='' )
{

// Get info about the survey
Expand All @@ -112,14 +112,18 @@ public function loadSurveyResults(SurveyObj $survey, $iLimit, $iOffset, $iMaximu

if ($sFilter!='')
$oRecordSet->where($sFilter);

if ($iOffset+$iLimit>$iMaximum)
{
$iLimit=$iMaximum-$iOffset;

$iOffset = $iMinimum - 1;
$survey->responses=$oRecordSet->select($aSelectFields)->order('{{survey_' . $survey->id . '}}.id')->limit($iMaximum - $iOffset, $iOffset)->query();
}

/**
* Close the resultset
*/
public function close()
{
if ($survey->responses instanceof CDbDataReader) {
$survey->responses->close();
}

$survey->responses=$oRecordSet->select($aSelectFields)->order('{{survey_' . $survey->id . '}}.id')->limit($iLimit, $iOffset)->query()->readAll();

return count($survey->responses);
}
}
77 changes: 49 additions & 28 deletions application/helpers/admin/exportresults_helper.php
Expand Up @@ -79,41 +79,62 @@ function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOpti
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
}

switch ( $sExportPlugin ) {
case "doc":
$writer = new DocWriter();
break;
case "xls":
$writer = new ExcelWriter();
break;
case "pdf":
$writer = new PdfWriter();
break;
case "html":
$writer = new HtmlWriter();
break;
case "csv":
default:
$writer = new CsvWriter();
break;

$exports = array(
'doc' => '',
'xls' => '',
'pdf' => '',
'html' => '',
'csv' => ''
);
$event = new PluginEvent('listExportPlugins');
$oPluginManager = App()->getPluginManager();
$oPluginManager->dispatchEvent($event);

$exports = $event->get('exportplugins', array());

if (array_key_exists($sExportPlugin, $exports) && !empty($exports[$sExportPlugin])) {
// This must be a plugin, now use plugin to load the right class
$event = new PluginEvent('newExport');
$event->set('type', $sExportPlugin);
$oPluginManager->dispatchEvent($event, $exports[$sExportPlugin]);
$writer = $event->get('writer');
} else {
// fallback for core exports before ported to a plugin
switch ( $sExportPlugin ) {
case "doc":
$writer = new DocWriter();
break;
case "xls":
$writer = new ExcelWriter();
break;
case "pdf":
$writer = new PdfWriter();
break;
case "html":
$writer = new HtmlWriter();
break;
case "csv":
default:
$writer = new CsvWriter();
break;
}
}

if (!($writer instanceof IWriter)) {
throw new Exception(sprintf('Writer for %s should implement IWriter', $sExportPlugin));
}

$surveyDao = new SurveyDao();
$survey = $surveyDao->loadSurveyById($iSurveyId, $sLanguageCode);
$writer->init($survey, $sLanguageCode, $oOptions);

$iBatchSize=100; $iCurrentRecord=$oOptions->responseMinRecord-1;
$bMoreRecords=true; $first=true;
while ($bMoreRecords)
{
$iExported= $surveyDao->loadSurveyResults($survey, $iBatchSize, $iCurrentRecord, $oOptions->responseMaxRecord, $sFilter);
$iCurrentRecord+=$iExported;
$writer->write($survey, $sLanguageCode, $oOptions,$first);
$first=false;
$bMoreRecords= ($iExported == $iBatchSize);
}
$surveyDao->loadSurveyResults($survey, $oOptions->responseMinRecord, $oOptions->responseMaxRecord, $sFilter);

$writer->write($survey, $sLanguageCode, $oOptions,true);
$result = $writer->close();
$surveyDao->close();

if ($oOptions->output=='file')
{
return $writer->filename;
Expand Down
5 changes: 2 additions & 3 deletions application/helpers/export_helper.php
Expand Up @@ -1705,14 +1705,13 @@ function tokensExport($iSurveyID)
$bquery .= " ORDER BY tid";
Yii::app()->loadHelper('database');

$bresult = Yii::app()->db->createCommand($bquery)->query()->readAll(); //dbExecuteAssoc($bquery) is faster but deprecated!
$bresult = Yii::app()->db->createCommand($bquery)->query(); //dbExecuteAssoc($bquery) is faster but deprecated!
//HEADERS should be after the above query else timeout errors in case there are lots of tokens!
header("Content-Disposition: attachment; filename=tokens_".$iSurveyID.".csv");
header("Content-type: text/comma-separated-values; charset=UTF-8");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: cache");

$bfieldcount=count($bresult);
// Export UTF8 WITH BOM
$tokenoutput = chr(hexdec('EF')).chr(hexdec('BB')).chr(hexdec('BF'));
$tokenoutput .= "tid,firstname,lastname,email,emailstatus,token,language,validfrom,validuntil,invited,reminded,remindercount,completed,usesleft";
Expand All @@ -1731,7 +1730,7 @@ function tokensExport($iSurveyID)
// Export token line by line and fill $aExportedTokens with token exported
Yii::import('application.libraries.Date_Time_Converter', true);
$aExportedTokens = array();
foreach($bresult as $brow)
while ($brow = $bresult->read())
{
if (trim($brow['validfrom']!=''))
{
Expand Down
42 changes: 42 additions & 0 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -221,6 +221,7 @@ function __construct()
'strrev' => array('strrev', 'strrev', $this->gT('Reverse a string'), 'string strrev(string)', 'http://www.php.net/manual/en/function.strrev.php', 1),
'strstr' => array('strstr', 'strstr', $this->gT('Find first occurrence of a string'), 'string strstr(haystack, needle)', 'http://www.php.net/manual/en/function.strstr.php', 2),
'strtolower' => array('strtolower', 'LEMstrtolower', $this->gT('Make a string lowercase'), 'string strtolower(string)', 'http://www.php.net/manual/en/function.strtolower.php', 1),
'strtotime' => array('strtotime', 'strtotime', $this->gT('Convert a date/time string to unix timestamp'), 'int strtotime(string)', 'http://www.php.net/manual/de/function.strtotime.php', 1),
'strtoupper' => array('strtoupper', 'LEMstrtoupper', $this->gT('Make a string uppercase'), 'string strtoupper(string)', 'http://www.php.net/manual/en/function.strtoupper.php', 1),
'substr' => array('substr', 'substr', $this->gT('Return part of a string'), 'string substr(string, start [, length])', 'http://www.php.net/manual/en/function.substr.php', 2,3),
'sum' => array('array_sum', 'LEMsum', $this->gT('Calculate the sum of values in an array'), 'number sum(arg1, arg2, ... argN)', '', -2),
Expand Down Expand Up @@ -2835,6 +2836,47 @@ static function UnitTestEvaluator()
FGHI~strstr('ABCDEFGHI','FG')
hi there!~strtolower(c)
HI THERE!~strtoupper(c)
3600~strtotime("27 Mar 1976 8:20")-strtotime("1976/03/27 7:20")
10~(strtotime("13 Apr 2013")-strtotime("2013-04-03"))/60/60/24
1985-11-05 00:00:00~date("Y-m-d H:i:s",strtotime("05 Nov 1985"))
HOURS PASSED SINCE 1970~round(strtotime("now")/60/60)
~""
1985-11-05 00:00:00~date("Y-m-d H:i:s",strtotime("11/5/85"))
2010-08-09 00:00:00~date("Y-m-d H:i:s",strtotime("8/9/10"))
2010-08-09 00:00:00~date("Y-m-d H:i:s",strtotime("8/9/2010"))
2010-08-09 00:00:00~date("Y-m-d H:i:s",strtotime("2010/8/9"))
~""
1985-11-05 00:00:00~date("Y-m-d H:i:s",strtotime("85-11-5"))
2010-08-09 00:00:00~date("Y-m-d H:i:s",strtotime("10-8-9"))
2010-08-09 00:00:00~date("Y-m-d H:i:s",strtotime("9-8-2010"))
2010-08-09 00:00:00~date("Y-m-d H:i:s",strtotime("2010-8-9"))
~""
1985-11-05 00:53:20~date("Y-m-d H:i:s",strtotime("85-11-5 0:53:20"))
2010-08-09 00:53:20~date("Y-m-d H:i:s",strtotime("10-8-9 0:53:20"))
2010-08-09 11:12:13~date("Y-m-d H:i:s",strtotime("9-8-2010 11:12:13"))
2010-08-09 11:12:13~date("Y-m-d H:i:s",strtotime("2010-8-9 11:12:13"))
~""
Today 11:11:59~date("Y-m-d H:i:s",strtotime("11.11.59"))
Today 9:08:10~date("Y-m-d H:i:s",strtotime("9.8.10"))
2010-08-09 00:00:00~date("Y-m-d H:i:s",strtotime("9.8.2010"))
~""
1985-11-05 00:53:20~date("Y-m-d H:i:s",strtotime("5.11.85 0:53:20"))
2010-08-09 11:12:13~date("Y-m-d H:i:s",strtotime("9.8.2010 11:12:13"))
~""
1970-01-01 00:00:00~date("Y-m-d H:i:s",strtotime("70-01-01"))
1999-01-01 00:00:00~date("Y-m-d H:i:s",strtotime("99-01-01"))
2001-01-01 00:00:00~date("Y-m-d H:i:s",strtotime("01-01-01"))
1902-01-01 00:00:00~date("Y-m-d H:i:s",strtotime("1902-01-01"))
~""
today 2:15:00~date("Y-m-d H:i:s",strtotime("2:15:00"))
Some dates that are not (correctly) parsed:~"Some dates that are not (correctly) parsed:"
1969-01-19 00:00:00~date("Y-m-d H:i:s",strtotime("69-01-19"))
1985-11-05 00:00:00~date("Y-m-d H:i:s",strtotime("85/11/5"))
1985-11-05 00:00:00~date("Y-m-d H:i:s",strtotime("5-11-85"))
2010-08-09 00:00:00~date("Y-m-d H:i:s",strtotime("2010.8.9"))
1985-11-05 00:00:00~date("Y-m-d H:i:s",strtotime("85.11.5"))
1985-11-05 00:53:20~date("Y-m-d H:i:s",strtotime("85.11.5 0:53:20"))
2010-08-09 11:12:13~date("Y-m-d H:i:s",strtotime("9.8.10 11:12:13"))
678~substr('1234567890',5,3)
15~sum(1,2,3,4,5)
15~sum(one,two,three,four,five)
Expand Down
5 changes: 5 additions & 0 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -3295,6 +3295,11 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
}
break;
}
// Hidden question are never on same page (except for equation)
if($hidden && $type!="*"){
$jsVarName_on = '';
}

if (!is_null($rowdivid) || $type == 'L' || $type == 'N' || $type == '!' || !is_null($preg)
|| $type == 'S' || $type == 'T' || $type == 'U' || $type == '|') {
if (!isset($q2subqInfo[$questionNum])) {
Expand Down
11 changes: 3 additions & 8 deletions application/helpers/qanda_helper.php
Expand Up @@ -5156,15 +5156,10 @@ function do_array_multitext($ia)
$addcheckcond = <<< EOD
<script type="text/javascript">
<!--
$(document).ready(function()
{
$('#question{$ia[0]} :input:visible:enabled').each(function(index){
$(this).bind('keyup',function(e) {
checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
return true;
})
$('#question{$ia[0]} .question').delegate('input[type=text]:visible:enabled','blur keyup',function(event){
checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
return true;
})
})
// -->
</script>
EOD;
Expand Down

0 comments on commit fe47d0b

Please sign in to comment.