Skip to content

Commit

Permalink
Revert "Revert "Merge branch '2.1' of github.com:LimeSurvey/LimeSurve…
Browse files Browse the repository at this point in the history
…y into 2.1""

This reverts commit 241a44c.
  • Loading branch information
SamMousa committed Dec 13, 2012
1 parent df17cea commit be77e65
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 123 deletions.
4 changes: 2 additions & 2 deletions application/controllers/admin/checkintegrity.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ protected function _checkintegrity()
$aTokenSIDs[] = $iSurveyID;
$aFullOldTokenSIDs[$iSurveyID][] = $sTable;
}
$aOldTokenSIDs = array_unique($aOldTokenSIDs);
$aOldTokenSIDs = array_unique($aTokenSIDs);
$surveys = Survey::model()->findAll();
if (Survey::model()->hasErrors()) safeDie(Survey::model()->getError());
$aSIDs = array();
Expand All @@ -716,7 +716,7 @@ protected function _checkintegrity()
}
foreach ($aOldTokenSIDs as $iOldTokenSID)
{
if (!in_array($iOldTokenSID, $aTokenSIDs)) {
if (!in_array($iOldTokenSID, $aOldTokenSIDs)) {
foreach ($aFullOldTokenSIDs[$iOldTokenSID] as $sTableName)
{
$aDelete['orphantokentables'][] = $sTableName;
Expand Down
51 changes: 28 additions & 23 deletions application/controllers/admin/surveyadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,30 @@ public function __construct($controller, $id)
*/
public function index()
{
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/js/i18n/grid.locale-en.js");
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/js/jquery.jqGrid.min.js");
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jquery.coookie.js");
$this->getController()->_js_admin_includes(Yii::app()->getConfig('adminscripts') . "listsurvey.js");
$this->getController()->_css_admin_includes(Yii::app()->getConfig('publicstyleurl') . 'jquery.multiselect.css');
$this->getController()->_css_admin_includes(Yii::app()->getConfig('publicstyleurl') . 'jquery.multiselect.filter.css');
$this->getController()->_css_admin_includes(Yii::app()->getConfig('adminstyleurl') . "displayParticipants.css");
$this->getController()->_css_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/css/ui.jqgrid.css");
$this->getController()->_css_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/css/jquery.ui.datepicker.css");

Yii::app()->loadHelper('surveytranslator');

$aData['issuperadmin'] = false;
if (Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1)
if (count(getSurveyList(true)) == 0)
{
$aData['issuperadmin'] = true;
}
$this->_renderWrappedTemplate('super', 'firststeps');
} else {
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/js/i18n/grid.locale-en.js");
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/js/jquery.jqGrid.min.js");
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jquery.coookie.js");
$this->getController()->_js_admin_includes(Yii::app()->getConfig('adminscripts') . "listsurvey.js");
$this->getController()->_css_admin_includes(Yii::app()->getConfig('publicstyleurl') . 'jquery.multiselect.css');
$this->getController()->_css_admin_includes(Yii::app()->getConfig('publicstyleurl') . 'jquery.multiselect.filter.css');
$this->getController()->_css_admin_includes(Yii::app()->getConfig('adminstyleurl') . "displayParticipants.css");
$this->getController()->_css_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/css/ui.jqgrid.css");
$this->getController()->_css_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/css/jquery.ui.datepicker.css");

Yii::app()->loadHelper('surveytranslator');

$aData['issuperadmin'] = false;
if (Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1)
{
$aData['issuperadmin'] = true;
}

$this->_renderWrappedTemplate('survey', 'listSurveys_view', $aData);
$this->_renderWrappedTemplate('survey', 'listSurveys_view', $aData);
}
}

public function regenquestioncodes($iSurveyID, $sSubAction )
Expand Down Expand Up @@ -680,8 +685,9 @@ public function getSurveys_json()
//Set Responses
if ($rows['active'] == "Y")
{
$partial = Survey_dynamic::model($rows['sid'])->countByAttributes(array('submitdate' => null));
$all = Survey_dynamic::model($rows['sid'])->count();
$cntResult = Survey_dynamic::countAllAndPartial($rows['sid']);
$all = $cntResult['cntAll'];
$partial = $cntResult['cntPartial'];

$aSurveyEntry[] = $all - $partial;
$aSurveyEntry[] = $partial;
Expand All @@ -691,10 +697,9 @@ public function getSurveys_json()
$aSurveyEntry['viewurl'] = $this->getController()->createUrl("/admin/survey/sa/view/surveyid/" . $rows['sid']);
if (tableExists('tokens_' . $rows['sid'] ))
{
$tokens = Tokens_dynamic::model($rows['sid'])->count();
$tokenscompleted = Tokens_dynamic::model($rows['sid'])->count(array(
'condition' => "completed <> 'N'"
));
$cntResult = Tokens_dynamic::countAllAndCompleted($rows['sid']);
$tokens = $cntResult['cntAll'];
$tokenscompleted = $cntResult['cntCompleted'];

$aSurveyEntry[] = $tokens;
$aSurveyEntry[] = ($tokens == 0) ? 0 : round($tokenscompleted / $tokens * 100, 1);
Expand Down
19 changes: 15 additions & 4 deletions application/helpers/SurveyRuntimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ function run($surveyid,$args) {
$move = "movenext";
$_SESSION[$LEMsessid]['step']=1;
}
} else if($surveyid != LimeExpressionManager::getLEMsurveyId()) {
}
elseif($surveyid != LimeExpressionManager::getLEMsurveyId())
{
LimeExpressionManager::StartSurvey($surveyid, $surveyMode, $surveyOptions, false, $LEMdebugLevel);
LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false, false);
}
Expand Down Expand Up @@ -158,10 +160,13 @@ function run($surveyid,$args) {
{
$_SESSION[$LEMsessid]['prevstep']=-1; // this only happens on re-load
}

if (isset($_SESSION[$LEMsessid]['LEMtokenResume']))
{
LimeExpressionManager::StartSurvey($thissurvey['sid'], $surveyMode, $surveyOptions, false,$LEMdebugLevel);
if(isset($_SESSION[$LEMsessid]['maxstep']) && $_SESSION[$LEMsessid]['maxstep']>$_SESSION[$LEMsessid]['step'])
{
LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['maxstep'], false, false);
}
$moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'],false,false); // if late in the survey, will re-validate contents, which may be overkill
unset($_SESSION[$LEMsessid]['LEMtokenResume']);
}
Expand Down Expand Up @@ -273,8 +278,14 @@ function run($surveyid,$args) {
{
// must do this here to process the POSTed values
$moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false); // by jumping to current step, saves data so far

$cSave->showsaveform(); // generates a form and exits, awaiting input
if ($thissurvey['tokenanswerspersistence'] != 'Y' || !isset($surveyid) || !Survey::model()->hasTokens($surveyid))
{
$cSave->showsaveform(); // generates a form and exits, awaiting input
}
else
{
// TODO : update lastpage to $_SESSION[$LEMsessid]['step'] in Survey_dynamic
}
}

if ($thissurvey['active'] == "Y" && isset($_POST['saveprompt']))
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function isStandardTemplate($sTemplateName)
*/
function getSurveyList($returnarray=false, $returnwithouturl=false, $surveyid=false)
{
$cached = null;
static $cached = null;

$timeadjust = getGlobalSetting('timeadjust');
$clang = new Limesurvey_lang(Yii::app()->session['adminlang']);
Expand Down
166 changes: 84 additions & 82 deletions application/helpers/frontend_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,113 +11,115 @@
* See COPYRIGHT.php for copyright notices and details.
*/

function loadanswers()
{
global $surveyid;
global $thissurvey, $thisstep;
global $clienttoken;
$clang = Yii::app()->lang;

$scid=returnGlobal('scid');
if (isset($_POST['loadall']) && $_POST['loadall'] == "reload")
function loadanswers()
{
$query = "SELECT * FROM {{saved_control}} INNER JOIN {$thissurvey['tablename']}
ON {{saved_control}}.srid = {$thissurvey['tablename']}.id
WHERE {{saved_control}}.sid=$surveyid\n";
if (isset($scid)) //Would only come from email
global $surveyid;
global $thissurvey, $thisstep;
global $clienttoken;
$clang = Yii::app()->lang;

$scid=returnGlobal('scid');
if (isset($_POST['loadall']) && $_POST['loadall'] == "reload")
{
$query .= "AND {{saved_control}}.scid={$scid}\n";
}
$query .="AND {{saved_control}}.identifier = '".autoEscape($_SESSION['survey_'.$surveyid]['holdname'])."' ";
$query = "SELECT * FROM {{saved_control}} INNER JOIN {$thissurvey['tablename']}
ON {{saved_control}}.srid = {$thissurvey['tablename']}.id
WHERE {{saved_control}}.sid=$surveyid\n";
if (isset($scid)) //Would only come from email

{
$query .= "AND {{saved_control}}.scid={$scid}\n";
}
$query .="AND {{saved_control}}.identifier = '".autoEscape($_SESSION['survey_'.$surveyid]['holdname'])."' ";

if (in_array(Yii::app()->db->getDriverName(), array('mssql', 'sqlsrv')))
if (in_array(Yii::app()->db->getDriverName(), array('mssql', 'sqlsrv')))
{
$query .="AND CAST({{saved_control}}.access_code as varchar(32))= '".md5(autoUnescape($_SESSION['survey_'.$surveyid]['holdpass']))."'\n";
}
else
{
$query .="AND {{saved_control}}.access_code = '".md5(autoUnescape($_SESSION['survey_'.$surveyid]['holdpass']))."'\n";
}
}
elseif (isset($_SESSION['survey_'.$surveyid]['srid']))
{
$query .="AND CAST({{saved_control}}.access_code as varchar(32))= '".md5(autoUnescape($_SESSION['survey_'.$surveyid]['holdpass']))."'\n";
$query = "SELECT * FROM {$thissurvey['tablename']}
WHERE {$thissurvey['tablename']}.id=".$_SESSION['survey_'.$surveyid]['srid']."\n";
}
else
{
$query .="AND {{saved_control}}.access_code = '".md5(autoUnescape($_SESSION['survey_'.$surveyid]['holdpass']))."'\n";
return;
}
}
elseif (isset($_SESSION['survey_'.$surveyid]['srid']))
{
$query = "SELECT * FROM {$thissurvey['tablename']}
WHERE {$thissurvey['tablename']}.id=".$_SESSION['survey_'.$surveyid]['srid']."\n";
}
else
{
return;
}

$aRow = Yii::app()->db->createCommand($query)->queryRow();
if (!$aRow)
{
safeDie($clang->gT("There is no matching saved survey")."<br />\n");
return false;
}
else
{
//A match has been found. Let's load the values!
//If this is from an email, build surveysession first
$_SESSION['survey_'.$surveyid]['LEMtokenResume']=true;

// Get if survey is been answered
$submitdate=$aRow['submitdate'];
foreach ($aRow as $column => $value)
{
if ($column == "token")
{
$clienttoken=$value;
$token=$value;
}
elseif ($column == "saved_thisstep" && $thissurvey['alloweditaftercompletion'] != 'Y' )
{
$_SESSION['survey_'.$surveyid]['step']=$value;
$thisstep=$value-1;
}
elseif ($column =='lastpage' && isset($_GET['token']) && $thissurvey['alloweditaftercompletion'] != 'Y' )
{
if ($value<1) $value=1;
$_SESSION['survey_'.$surveyid]['step']=$value;
$thisstep=$value-1;
}
/*
Commented this part out because otherwise startlanguage would overwrite any other language during a running survey.
We will need a new field named 'endlanguage' to save the current language (for example for returning participants)
/the language the survey was completed in.
elseif ($column =='startlanguage')
{
$clang = SetSurveyLanguage( $surveyid, $value);
UpdateSessionGroupList($value); // to refresh the language strings in the group list session variable
UpdateFieldArray(); // to refresh question titles and question text
}*/
elseif ($column == "scid")
{
$_SESSION['survey_'.$surveyid]['scid']=$value;
}
elseif ($column == "srid")
{
$_SESSION['survey_'.$surveyid]['srid']=$value;
}
elseif ($column == "datestamp")
{
$_SESSION['survey_'.$surveyid]['datestamp']=$value;
}
if ($column == "startdate")
{
$_SESSION['survey_'.$surveyid]['startdate']=$value;
}
else
{
//Only make session variables for those in insertarray[]
if (in_array($column, $_SESSION['survey_'.$surveyid]['insertarray']))
{
$q = $_SESSION['survey_'.$surveyid]['fieldmap'][$column];
$_SESSION['survey_'.$surveyid][$column] = $q->loadAnswer($value);
} // if (in_array(
} // else
} // foreach
$clienttoken=$value;
$token=$value;
}
elseif ($column == "saved_thisstep" )
{
if($thissurvey['alloweditaftercompletion'] != 'Y' || !Survey::model()->hasTokens($surveyid) )
{
$_SESSION['survey_'.$surveyid]['step']=$value;
$thisstep=$value-1;
}
}
elseif ($column =='lastpage')
{
if(is_null($submitdate) || $submitdate=="N")
{
if ($value<1) $value=1;
$_SESSION['survey_'.$surveyid]['step']=$value;
$thisstep=$value-1;
}
elseif( $thissurvey['alloweditaftercompletion'] == 'Y' && Survey::model()->hasTokens($surveyid))
{
$_SESSION['survey_'.$surveyid]['maxstep']=$value;
}
}
elseif ($column == "scid")
{
$_SESSION['survey_'.$surveyid]['scid']=$value;
}
elseif ($column == "srid")
{
$_SESSION['survey_'.$surveyid]['srid']=$value;
}
elseif ($column == "datestamp")
{
$_SESSION['survey_'.$surveyid]['datestamp']=$value;
}
elseif ($column == "startdate")
{
$_SESSION['survey_'.$surveyid]['startdate']=$value;
}
else
{
//Only make session variables for those in insertarray[]
if (in_array($column, $_SESSION['survey_'.$surveyid]['insertarray']) && isset($_SESSION['survey_'.$surveyid]['fieldmap'][$column]))
{
$q = $_SESSION['survey_'.$surveyid]['fieldmap'][$column];
$_SESSION['survey_'.$surveyid][$column] = $q->loadAnswer($value);
} // if (in_array(
} // else
} // foreach
}
return true;
}
return true;
}

function makegraph($currentstep, $total)
{
Expand Down
6 changes: 3 additions & 3 deletions application/helpers/globalsettings_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ function injectglobalsettings()
//foreach ($dbvaluearray as $setting)
foreach ($settings as $setting)
{
if (Yii::app()->getConfig($setting->getAttribute('stg_name')) !== false)
{
//if (Yii::app()->getConfig($setting->getAttribute('stg_name')) !== false)
//{
//$$setting['stg_name']=$setting['stg_value'];
Yii::app()->setConfig($setting->getAttribute('stg_name'), $setting->getAttribute('stg_value'));
}
//}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions application/models/Answers.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ function getAnswers($qid)
->query();
}

/**
* @deprecated No longer used as questions have their answer(codes) encapsulated
*/
function getAnswerFromCode($qid, $code, $lang, $iScaleID=0)
{
return Yii::app()->db->cache(6)->createCommand()
Expand Down
13 changes: 13 additions & 0 deletions application/models/Survey_dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ public function addTokenCriteria($condition)
return $newCriteria;
}

public static function countAllAndPartial($sid)
{
$select = array(
'count(*) AS cntAll',
'sum(CASE
WHEN submitdate IS NULL THEN 1
ELSE 0
END) AS cntPartial',
);
$result = Yii::app()->db->createCommand()->select($select)->from('{{survey_' . $sid . '}}')->queryRow();
return $result;
}

/**
* Return true if actual survey is completed
*
Expand Down

0 comments on commit be77e65

Please sign in to comment.