Skip to content

Commit

Permalink
Fixed issue: Detection for duplicate field names was not working
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@9485 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Nov 16, 2010
1 parent b06e8af commit 58386b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
14 changes: 5 additions & 9 deletions admin/activate.php
Expand Up @@ -199,6 +199,8 @@
}
}
//CHECK THAT ALL THE CREATED FIELDS WILL BE UNIQUE
global $aDuplicateQIDs;
$aDuplicateQIDs=array();
$fieldmap=createFieldMap($surveyid, "full");
if (isset($fieldmap))
{
Expand All @@ -208,16 +210,10 @@
}
$fieldlist=array_reverse($fieldlist); //let's always change the later duplicate, not the earlier one
}
$checkKeysUniqueComparison = create_function('$value','if ($value > 1) return true;');
@$duplicates = array_keys (array_filter (array_count_values($fieldlist), $checkKeysUniqueComparison));
if (isset($duplicates))
foreach ($aDuplicateQIDs as $iQID=>$aDetails)
{
foreach ($duplicates as $dup)
{
$badquestion=arraySearchByKey($dup, $fieldmap, "fieldname", 1);
$fix = "[<a href='$scriptname?action=activate&amp;sid=$surveyid&amp;fixnumbering=".$badquestion['qid']."'>Click Here to Fix</a>]";
$failedcheck[]=array($badquestion['qid'], $badquestion['question'], ": Bad duplicate fieldname $fix", $badquestion['gid']);
}
$fix = "[<a href='{$scriptname}?action=activate&amp;sid={$surveyid}&amp;fixnumbering={$iQID}'>".$clang->gT("Click here to fix")."</a>]";
$failedcheck[]=array($iQID, Flattentext($aDetails['question']), ": ".$clang->gT("Duplicate fieldname:")." $fix", $aDetails['gid']);
}

//IF ANY OF THE CHECKS FAILED, PRESENT THIS SCREEN
Expand Down
17 changes: 15 additions & 2 deletions common.php
Expand Up @@ -2264,7 +2264,7 @@ function validate_templatedir($templatename)
*/
function createFieldMap($surveyid, $style='short', $force_refresh=false, $questionid=false, $sQuestionLanguage=null) {

global $dbprefix, $connect, $globalfieldmap, $clang;
global $dbprefix, $connect, $globalfieldmap, $clang, $aDuplicateQIDs;
$surveyid=sanitize_int($surveyid);
//checks to see if fieldmap has already been built for this page.
if (isset($globalfieldmap[$surveyid][$style][$clang->langcode]) && $force_refresh==false) {
Expand Down Expand Up @@ -2432,7 +2432,8 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
if ($qtypes[$arow['type']]['subquestions']==0 && $arow['type'] != "R")
{
$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}";
$fieldmap[$fieldname]=array("fieldname"=>$fieldname, 'type'=>"{$arow['type']}", 'sid'=>$surveyid, "gid"=>$arow['gid'], "qid"=>$arow['qid'], "aid"=>"");
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);
$fieldmap[$fieldname]=array('fieldname'=>$fieldname, 'type'=>$arow['type'], 'sid'=>$surveyid, "gid"=>$arow['gid'], "qid"=>$arow['qid'], "aid"=>"");
if ($style == "full")
{
$fieldmap[$fieldname]['title']=$arow['title'];
Expand All @@ -2457,6 +2458,8 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
if ($arow['other'] == "Y")
{
$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}other";
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);

$fieldmap[$fieldname]=array("fieldname"=>$fieldname,
'type'=>$arow['type'],
'sid'=>$surveyid,
Expand Down Expand Up @@ -2486,6 +2489,8 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
break;
case "O": //DROPDOWN LIST WITH COMMENT
$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}comment";
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);

$fieldmap[$fieldname]=array("fieldname"=>$fieldname,
'type'=>$arow['type'],
'sid'=>$surveyid,
Expand Down Expand Up @@ -2525,6 +2530,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
foreach($answerset as $answer)
{
$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['title']}_{$answer['title']}";
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);
$fieldmap[$fieldname]=array("fieldname"=>$fieldname,
'type'=>$arow['type'],
'sid'=>$surveyid,
Expand Down Expand Up @@ -2553,6 +2559,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
foreach ($abrows as $abrow)
{
$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['title']}#0";
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);
$fieldmap[$fieldname]=array("fieldname"=>$fieldname, 'type'=>$arow['type'], 'sid'=>$surveyid, "gid"=>$arow['gid'], "qid"=>$arow['qid'], "aid"=>$abrow['title'], "scale_id"=>0);
if ($style == "full")
{
Expand All @@ -2567,6 +2574,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
}

$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['title']}#1";
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);
$fieldmap[$fieldname]=array("fieldname"=>$fieldname, 'type'=>$arow['type'], 'sid'=>$surveyid, "gid"=>$arow['gid'], "qid"=>$arow['qid'], "aid"=>$abrow['title'], "scale_id"=>1);
if ($style == "full")
{
Expand All @@ -2589,6 +2597,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
for ($i=1; $i<=$slots; $i++)
{
$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}$i";
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);
$fieldmap[$fieldname]=array("fieldname"=>$fieldname, 'type'=>$arow['type'], 'sid'=>$surveyid, "gid"=>$arow['gid'], "qid"=>$arow['qid'], "aid"=>$i);
if ($style == "full")
{
Expand All @@ -2609,6 +2618,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
foreach ($abrows as $abrow)
{
$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['title']}";
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);
$fieldmap[$fieldname]=array("fieldname"=>$fieldname, 'type'=>$arow['type'], 'sid'=>$surveyid, "gid"=>$arow['gid'], "qid"=>$arow['qid'], "aid"=>$abrow['title']);
if ($style == "full")
{
Expand All @@ -2631,6 +2641,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
if ($arow['type'] == "P")
{
$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}{$abrow['title']}comment";
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);
$fieldmap[$fieldname]=array("fieldname"=>$fieldname, 'type'=>$arow['type'], 'sid'=>$surveyid, "gid"=>$arow['gid'], "qid"=>$arow['qid'], "aid"=>$abrow['title']."comment");
if ($style == "full")
{
Expand All @@ -2647,6 +2658,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
if ($arow['other']=="Y" && ($arow['type']=="M" || $arow['type']=="P"))
{
$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}other";
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);
$fieldmap[$fieldname]=array("fieldname"=>$fieldname, 'type'=>$arow['type'], 'sid'=>$surveyid, "gid"=>$arow['gid'], "qid"=>$arow['qid'], "aid"=>"other");
if ($style == "full")
{
Expand All @@ -2661,6 +2673,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
if ($arow['type']=="P")
{
$fieldname="{$arow['sid']}X{$arow['gid']}X{$arow['qid']}othercomment";
if (isset($fieldmap[$fieldname])) $aDuplicateQIDs[$arow['qid']]=array('fieldname'=>$fieldname,'question'=>$arow['question'],'gid'=>$arow['gid']);
$fieldmap[$fieldname]=array("fieldname"=>$fieldname, 'type'=>$arow['type'], 'sid'=>$surveyid, "gid"=>$arow['gid'], "qid"=>$arow['qid'], "aid"=>"othercomment");
if ($style == "full")
{
Expand Down
2 changes: 1 addition & 1 deletion save.php
Expand Up @@ -434,7 +434,7 @@ function createinsertquery()
else
{
// Empty the 'Other' field if a value other than '-oth-' was set for the main field (prevent invalid other values being saved - for example if Javascript fails to hide the 'Other' input field)
if ($fieldexists['type']=='!' && $fieldmap[$value]['aid']=='other' && $_POST[substr($value,0,strlen($value)-5)]!='-oth-')
if ($fieldexists['type']=='!' && $fieldmap[$value]['aid']=='other' && isset($_POST[substr($value,0,strlen($value)-5)]) && $_POST[substr($value,0,strlen($value)-5)]!='-oth-')
{
$_SESSION[$value]='';
}
Expand Down

0 comments on commit 58386b1

Please sign in to comment.