Skip to content

Commit

Permalink
Merge branch 'master' into 192_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
TMSWhite committed Jun 6, 2012
2 parents 8828604 + 68952b7 commit d2fcd32
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 22 deletions.
2 changes: 1 addition & 1 deletion admin/import_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ function XMLImportSurvey($sFullFilepath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
//echo $clang->gT("This is VALID LimeSurvey survey structure XML file.");
//return $results;
}
$dbversion = (int) $xml->DBVersion;
$dbversion = (float) $xml->DBVersion;
$aQIDReplacements=array();
$aQuotaReplacements=array();
$results['defaultvalues']=0;
Expand Down
2 changes: 1 addition & 1 deletion admin/importgroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ function XMLImportGroup($sFullFilepath, $newsid)

$xml = @simplexml_load_file($sFullFilepath);
if ($xml==false || $xml->LimeSurveyDocType!='Group') safe_die('This is not a valid LimeSurvey group structure XML file.');
$dbversion = (int) $xml->DBVersion;
$dbversion = (float) $xml->DBVersion;
$aQIDReplacements=array();
$results['defaultvalues']=0;
$results['answers']=0;
Expand Down
2 changes: 1 addition & 1 deletion admin/importlabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function XMLImportLabelsets($sFullFilepath, $options)

$xml = simplexml_load_file($sFullFilepath);
if ($xml->LimeSurveyDocType!='Label set') safe_die('This is not a valid LimeSurvey label set structure XML file.');
$dbversion = (int) $xml->DBVersion;
$dbversion = (float) $xml->DBVersion;
$csarray=buildLabelSetCheckSumArray();
$aLSIDReplacements=array();
$results['labelsets']=0;
Expand Down
2 changes: 1 addition & 1 deletion admin/importquestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ function XMLImportQuestion($sFullFilepath, $newsid, $newgid)

$xml = simplexml_load_file($sFullFilepath);
if ($xml->LimeSurveyDocType!='Question') safe_die('This is not a valid LimeSurvey question structure XML file.');
$dbversion = (int) $xml->DBVersion;
$dbversion = (float) $xml->DBVersion;
$aQIDReplacements=array();
$aSQIDReplacements=array(0=>0);
$results['defaultvalues']=0;
Expand Down
6 changes: 3 additions & 3 deletions admin/install/cmd_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@
$usrow = $usresult->FetchRow();

//if user doesn't run the latest DB version, show a message and run update
if (intval($usrow['stg_value'])<$dbversionnumber)
if (floatval($usrow['stg_value'])<$dbversionnumber)
{
print("Upgrading db to $dbversionnumber\n");
db_upgrade_all(intval($usrow['stg_value']));
db_upgrade(intval($usrow['stg_value']));
db_upgrade_all(floatval($usrow['stg_value']));
db_upgrade(floatval($usrow['stg_value']));
}
//latest DB version is already in use
else
Expand Down
6 changes: 3 additions & 3 deletions admin/update/updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ function CheckForDBUpgrades()
{
global $connect, $databasetype, $dbprefix, $dbversionnumber, $clang;
$currentDBVersion=GetGlobalSetting('DBVersion');
if (intval($dbversionnumber)>intval($currentDBVersion))
if (floatval($dbversionnumber)>intval($currentDBVersion))
{
if(isset($_GET['continue']) && $_GET['continue']==1)
{
Expand All @@ -635,8 +635,8 @@ function CheckForDBUpgrades()
include ('upgrade-'.$upgradedbtype.'.php');
include ('upgrade-all.php');
$tables = $connect->MetaTables();
db_upgrade_all(intval($currentDBVersion));
db_upgrade(intval($currentDBVersion));
db_upgrade_all(floatval($currentDBVersion));
db_upgrade(floatval($currentDBVersion));
echo "<br />".sprintf($clang->gT("Database has been successfully upgraded to version %s"),$dbversionnumber);
}
else {
Expand Down
6 changes: 5 additions & 1 deletion admin/update/upgrade-mssql.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ function db_upgrade($oldversion) {
if ($oldversion < 154)
{
modify_database("","ALTER TABLE [prefix_groups] ADD [grelevance] text DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
LimeExpressionManager::UpgradeConditionsToRelevance();
modify_database("","update [prefix_settings_global] set [stg_value]='154' where stg_name='DBVersion'"); echo $modifyoutput; flush();@ob_flush();
}
if ($oldversion < 155)
Expand All @@ -589,6 +588,11 @@ function db_upgrade($oldversion) {
modify_database("","EXEC sp_rename 'prefix_surveys.showXquestions','showxquestions'"); echo $modifyoutput; flush();@ob_flush();
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='155' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}
if ($oldversion < 155.5)
{
LimeExpressionManager::UpgradeConditionsToRelevance();
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='155.5' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}

echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
return true;
Expand Down
6 changes: 5 additions & 1 deletion admin/update/upgrade-mssqlnative.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ function db_upgrade($oldversion) {
if ($oldversion < 154)
{
modify_database("","ALTER TABLE [prefix_groups] ADD [grelevance] varchar(max) DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
LimeExpressionManager::UpgradeConditionsToRelevance();
modify_database("","update [prefix_settings_global] set [stg_value]='154' where stg_name='DBVersion'"); echo $modifyoutput; flush();@ob_flush();
}
if ($oldversion < 155)
Expand All @@ -590,6 +589,11 @@ function db_upgrade($oldversion) {
modify_database("","EXEC sp_rename 'prefix_surveys.showXquestions','showxquestions'"); echo $modifyoutput; flush();@ob_flush();
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='155' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}
if ($oldversion < 155.5)
{
LimeExpressionManager::UpgradeConditionsToRelevance();
modify_database("", "UPDATE [prefix_settings_global] SET [stg_value]='155.5' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}

echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
return true;
Expand Down
6 changes: 5 additions & 1 deletion admin/update/upgrade-mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,6 @@ function db_upgrade($oldversion) {
if ($oldversion < 154)
{
modify_database("","ALTER TABLE `prefix_groups` ADD `grelevance` text DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
LimeExpressionManager::UpgradeConditionsToRelevance();
modify_database("","update `prefix_settings_global` set `stg_value`='154' where stg_name='DBVersion'"); echo $modifyoutput; flush();@ob_flush();
}
if ($oldversion < 155)
Expand All @@ -698,6 +697,11 @@ function db_upgrade($oldversion) {

modify_database("", "UPDATE `prefix_settings_global` SET stg_value='155' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}
if ($oldversion < 155.5)
{
LimeExpressionManager::UpgradeConditionsToRelevance();
modify_database("", "UPDATE `prefix_settings_global` SET stg_value='155.5' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();ob_flush();
}
fixLanguageConsistencyAllSurveys();
echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
return true;
Expand Down
6 changes: 5 additions & 1 deletion admin/update/upgrade-postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ function db_upgrade($oldversion) {
if ($oldversion < 154)
{
modify_database("","ALTER TABLE prefix_groups ADD grelevance text DEFAULT NULL;"); echo $modifyoutput; flush();@ob_flush();
LimeExpressionManager::UpgradeConditionsToRelevance();
modify_database("", "UPDATE prefix_settings_global SET stg_value='154' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();@ob_flush();
}
if ($oldversion < 155)
Expand All @@ -417,6 +416,11 @@ function db_upgrade($oldversion) {
modify_database("",'ALTER TABLE prefix_surveys RENAME COLUMN "showXquestions" TO "showxquestions";');
modify_database("","UPDATE prefix_settings_global SET stg_value='155' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();@ob_flush();
}
if ($oldversion < 155.5)
{
LimeExpressionManager::UpgradeConditionsToRelevance();
modify_database("","UPDATE prefix_settings_global SET stg_value='155.5' WHERE stg_name='DBVersion'"); echo $modifyoutput; flush();@ob_flush();
}

fixLanguageConsistencyAllSurveys();
echo '<br /><br />'.sprintf($clang->gT('Database update finished (%s)'),date('Y-m-d H:i:s')).'<br />';
Expand Down
55 changes: 50 additions & 5 deletions classes/expressions/LimeExpressionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ class LimeExpressionManager {
* 'type' => 'M' // the one-letter question type
* 'fieldname' => '26626X34X702sq1' // the fieldname (used as JavaScript variable name, and also as database column name
* 'rootVarName' => 'afDS' // the root variable name
* 'preg' => '/[A-Z]+/' // regular expression validation equation, if any
* 'subqs' => array() of sub-questions, where each contains:
* 'rowdivid' => '26626X34X702sq1' // the javascript id identifying the question row (so array_filter can hide rows)
* 'varName' => 'afSrcFilter_sq1' // the full variable name for the sub-question
Expand Down Expand Up @@ -1003,6 +1004,15 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$input_boxes='';
}

if (isset($qattr['value_range_allows_missing']) && $qattr['value_range_allows_missing'] == '1')
{
$value_range_allows_missing = true;
}
else
{
$value_range_allows_missing = false;
}

// array_filter
// If want to filter question Q2 on Q1, where each have subquestions SQ1-SQ3, this is equivalent to relevance equations of:
// relevance for Q2_SQ1 is Q1_SQ1!=''
Expand Down Expand Up @@ -1192,12 +1202,18 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$mainEqn = 'round(' . $mainEqn . ', ' . $precision . ')';
}

$noanswer_option = '';
if ($value_range_allows_missing)
{
$noanswer_option = ' || count(' . implode(', ', $sq_names) . ') == 0';
}

$validationEqn[$questionNum][] = array(
'qtype' => $type,
'type' => 'equals_num_value',
'class' => 'sum_range',
// Different script for mandatory or non-mandatory question
'eqn' => ($qinfo['mandatory']=='Y')?'(' . $mainEqn . ' == (' . $equals_num_value . '))':'(' . $mainEqn . ' == (' . $equals_num_value . ') || count(' . implode(', ', $sq_names) . ') == 0)',
'eqn' => ($qinfo['mandatory']=='Y')?'(' . $mainEqn . ' == (' . $equals_num_value . '))':'(' . $mainEqn . ' == (' . $equals_num_value . ')' . $noanswer_option . ')',
'qid' => $questionNum,
'sumEqn' => $sumEqn,
'sumRemainingEqn' => $sumRemainingEqn,
Expand Down Expand Up @@ -1706,11 +1722,17 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$sumEqn = 'round(' . $sumEqn . ', ' . $precision . ')';
}

$noanswer_option = '';
if ($value_range_allows_missing)
{
$noanswer_option = ' || count(' . implode(', ', $sq_names) . ') == 0';
}

$validationEqn[$questionNum][] = array(
'qtype' => $type,
'type' => 'min_num_value',
'class' => 'sum_range',
'eqn' => '(sum(' . implode(', ', $sq_names) . ') >= (' . $min_num_value . ') || count(' . implode(', ', $sq_names) . ') == 0)',
'eqn' => '(sum(' . implode(', ', $sq_names) . ') >= (' . $min_num_value . ')' . $noanswer_option . ')',
'qid' => $questionNum,
'sumEqn' => $sumEqn,
);
Expand Down Expand Up @@ -1762,11 +1784,18 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
{
$sumEqn = 'round(' . $sumEqn . ', ' . $precision . ')';
}

$noanswer_option = '';
if ($value_range_allows_missing)
{
$noanswer_option = ' || count(' . implode(', ', $sq_names) . ') == 0';
}

$validationEqn[$questionNum][] = array(
'qtype' => $type,
'type' => 'max_num_value',
'class' => 'sum_range',
'eqn' => '(sum(' . implode(', ', $sq_names) . ') <= (' . $max_num_value . ') || count(' . implode(', ', $sq_names) . ') == 0)',
'eqn' => '(sum(' . implode(', ', $sq_names) . ') <= (' . $max_num_value . ')' . $noanswer_option . ')',
'qid' => $questionNum,
'sumEqn' => $sumEqn,
);
Expand Down Expand Up @@ -7660,10 +7689,20 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
// SHOW QUESTION ATTRIBUTES THAT ARE PROCESSED BY EM
//////
$attrTable = '';
if (isset($LEM->qattr[$qid]) && count($LEM->qattr[$qid]) > 0) {

$attrs = (isset($LEM->qattr[$qid]) ? $LEM->qattr[$qid] : array());
if (isset($LEM->q2subqInfo[$qid]['preg']))
{
$attrs['regex_validation'] = $LEM->q2subqInfo[$qid]['preg'];
}
if (isset($LEM->questionSeq2relevance[$qseq]['other']))
{
$attrs['other'] = $LEM->questionSeq2relevance[$qseq]['other'];
}
if (count($attrs) > 0) {
$attrTable = "<hr/><table border='1'><tr><th>" . $LEM->gT("Question Attribute") . "</th><th>" . $LEM->gT("Value"). "</th></tr>\n";
$count=0;
foreach ($LEM->qattr[$qid] as $key=>$value) {
foreach ($attrs as $key=>$value) {
if (is_null($value) || trim($value) == '') {
continue;
}
Expand Down Expand Up @@ -7703,6 +7742,12 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
break;
case 'other_replace_text':
case 'show_totals':
case 'regex_validation':
break;
case 'other':
if ($value == 'N') {
$value = NULL; // so can skip this one
}
break;
}
if (is_null($value)) {
Expand Down
2 changes: 1 addition & 1 deletion common.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
If (!$dbexistsbutempty && $sourcefrom=='admin')
{
$usrow = getGlobalSetting('DBVersion');
if (intval($usrow)<$dbversionnumber)
if (floatval($usrow)<$dbversionnumber)
{
$action='';
require_once($rootdir.'/classes/core/language.php');
Expand Down
14 changes: 14 additions & 0 deletions common_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4121,6 +4121,20 @@ function questionAttributes($returnByName=false)
"help"=>$clang->gT("Place questions into a specified randomization group, all questions included in the specified group will appear in a random order"),
"caption"=>$clang->gT("Randomization group name"));

// This is added to support historical behavior. Early versions of 1.92 used a value of "No", so if there was a min_sum_value or equals_sum_value, the question was not valid
// unless those criteria were met. In later releases of 1.92, the default was changed so that missing values were allowed even if those attributes were set
// This attribute lets authors control whether missing values should be allowed in those cases without needing to set min_answers
// Existing surveys will use the old behavior, but if the author edits the question, the default will be the new behavior.
$qattributes["value_range_allows_missing"]=array(
"types"=>"K",
'category'=>$clang->gT('Input'),
'sortorder'=>100,
"inputtype"=>"singleselect",
'options'=>array(0=>$clang->gT('No'),
1=>$clang->gT('Yes')),
'default'=>1,
"help"=>$clang->gT("Is no answer (missing) allowed when either 'Equals sum value' or 'Minimum sum value' are set?"),
"caption"=>$clang->gT("Value range allows missing"));

//This builds a more useful array (don't modify)
if ($returnByName==false)
Expand Down
2 changes: 1 addition & 1 deletion qanda.php
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,7 @@ function do_multiplechoice($ia)
{
$dispVal = str_replace('.',$sSeperator,$dispVal);
}
$answer .= ' value="'.htmlspecialchars($dispVal,ENT_QUOTES).'"';
$answer .= htmlspecialchars($dispVal,ENT_QUOTES);
}

$answer .= "\" />\n{$wrapper['item-end']}";
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$versionnumber = "1.92+";
$dbversionnumber = 155;
$dbversionnumber = 155.5;
$buildnumber = '';

?>

0 comments on commit d2fcd32

Please sign in to comment.