Skip to content

Commit

Permalink
New feature: Anded conditions for type M and P questions
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev@6723 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Thibault Le Meur committed Apr 26, 2009
1 parent 0cc25d3 commit 481a375
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 7 deletions.
25 changes: 25 additions & 0 deletions admin/conditionshandling.php
Expand Up @@ -851,6 +851,29 @@
}
unset($quicky);
} // End if type R
elseif($rows['type'] == "M" || $rows['type'] == "P")
{
$cquestions[]=array("$shortquestion [".$clang->gT("Group of checkboxes")."]", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid']);
$aquery="SELECT * "
."FROM {$dbprefix}answers "
."WHERE qid={$rows['qid']} "
."AND language='".GetBaseLanguageFromSurveyID($surveyid)."' "
."ORDER BY sortorder, "
."answer";
$aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to this question<br />$aquery<br />".$connect->ErrorMsg());

while ($arows=$aresult->FetchRow())
{
$theanswer = addcslashes($arows['answer'], "'");
$canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], $arows['code'], $theanswer);

$shortanswer = strip_tags($arows['answer']);
$shortanswer .= "[{$arows['code']}]";
$cquestions[]=array("$shortquestion ($shortanswer) [".$clang->gT("Single checkbox")."]", $rows['qid'], $rows['type'], "+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']);
$canswers[]=array("+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], 'Y', 'checked');
$canswers[]=array("+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], '', 'not checked');
}
}
else
{
$cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid']);
Expand Down Expand Up @@ -913,6 +936,7 @@
$canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", $clang->gT("No answer"));
}
break;

default:
$aquery="SELECT * "
."FROM {$dbprefix}answers "
Expand Down Expand Up @@ -1242,6 +1266,7 @@
."AND {$dbprefix}conditions.qid=$qid "
."AND {$dbprefix}conditions.scenario={$scenarionr['scenario']}\n"
."AND {$dbprefix}conditions.cfieldname NOT LIKE '{%' \n" // avoid catching SRCtokenAttr conditions
// ."AND {$dbprefix}conditions.cfieldname NOT LIKE '+%' \n" // avoid catching SRCtokenAttr conditions
."ORDER BY {$dbprefix}conditions.cfieldname";
$result = db_execute_assoc($query) or safe_die ("Couldn't get other conditions for question $qid<br />$query<br />".$connect->ErrorMsg());
$conditionscount=$result->RecordCount();
Expand Down
12 changes: 12 additions & 0 deletions classes/core/sanitize.php
Expand Up @@ -107,6 +107,18 @@ function sanitize_paranoid_string($string, $min='', $max='')
}
}

function sanitize_cquestions($string, $min='', $max='')
{
if (isset($string))
{
$string = preg_replace("/[^_.a-zA-Z0-9+]/", "", $string);
$len = strlen($string);
if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max)))
return FALSE;
return $string;
}
}

function sanitize_email($email) {
// Handles now emails separated with a semikolon
$emailarray=explode(';',$email);
Expand Down
44 changes: 37 additions & 7 deletions common.php
Expand Up @@ -2012,10 +2012,13 @@ function returnglobal($stringname)
return sanitize_languagecode($_REQUEST[$stringname]);
}
elseif ($stringname =="htmleditormode" ||
$stringname =="subaction" ||
$stringname =="cquestions")
$stringname =="subaction")
{
return sanitize_paranoid_string($_REQUEST[$stringname]);
}
elseif ( $stringname =="cquestions")
{
return sanitize_cquestions($_REQUEST[$stringname]);
}
return $_REQUEST[$stringname];
}
Expand Down Expand Up @@ -5871,25 +5874,40 @@ function checkquestionfordisplay($qid, $gid=null)
$conditionCanBeEvaluated=true;
//Iterate through each condition for this question and check if it is met.

if (!preg_match("/^{/",$row['cfieldname']))
{ // this is a simple condition using a question as source
if (preg_match("/^\+(.*)$/",$row['cfieldname'],$cfieldnamematch))
{ // this condition uses a single checkbox as source
$conditionSourceType='question';
$query2= "SELECT type, gid FROM ".db_table_name('questions')."\n"
." WHERE qid={$row['cqid']} AND language='".$_SESSION['s_lang']."'";
$result2=db_execute_assoc($query2) or safe_die ("Coudn't get type from questions<br />$ccquery<br />".$connect->ErrorMsg()); //Checked
while($row2=$result2->FetchRow())
{
$cq_gid=$row2['gid'];
//Find out the "type" of the question this condition uses
$thistype=$row2['type'];
// set type to +M or +P in order to skip
$thistype='+'.$row2['type'];
}

$row['cfieldname']=$cfieldnamematch[1]; // remover the leading '+'
}
else
elseif (preg_match("/^{/",$row['cfieldname']))
{ // this condition uses a token attr as source
$conditionSourceType='tokenattr';
$thistype="";
$cq_gid=0;
}
else
{ // this is a simple condition using a question as source
$conditionSourceType='question';
$query2= "SELECT type, gid FROM ".db_table_name('questions')."\n"
." WHERE qid={$row['cqid']} AND language='".$_SESSION['s_lang']."'";
$result2=db_execute_assoc($query2) or safe_die ("Coudn't get type from questions<br />$ccquery<br />".$connect->ErrorMsg()); //Checked
while($row2=$result2->FetchRow())
{
$cq_gid=$row2['gid'];
//Find out the "type" of the question this condition uses
$thistype=$row2['type'];
}
}


if ( !is_null($gid) && $gid == $cq_gid && $conditionSourceType == 'question')
Expand All @@ -5904,6 +5922,18 @@ function checkquestionfordisplay($qid, $gid=null)
$cvalue="Y";
if (isset($_SESSION[$fieldname])) { $cfieldname=$_SESSION[$fieldname]; } else { $cfieldname=""; }
}
elseif ($thistype == "+M" || $thistype == "+P")
{
$fieldname=$row['cfieldname'];
$cvalue=$row['value'];
if (isset($_SESSION[$fieldname])) { $cfieldname=$_SESSION[$fieldname]; } else { $cfieldname=""; }
}


if ( !is_null($gid) && $gid == $cq_gid && $conditionSourceType == 'question')
{
//Don't do anything - this cq is in the current group
}
elseif (ereg('^@([0-9]+X[0-9]+X[^@]+)@',$row['value'],$targetconditionfieldname))
{
if (isset($_SESSION[$targetconditionfieldname[1]]) )
Expand Down
6 changes: 6 additions & 0 deletions index.php
Expand Up @@ -1022,6 +1022,12 @@ function checkconfield($value)
// while($rows = $result->FetchRow()) //Go through the condition on this field
foreach ($aAllCondrows as $rows)
{
if (preg_match("/^\+(.*)$/",$rows['cfieldname'],$cfieldnamematch))
{ // this condition uses a single checkbox as source
$rows['type'] = "+".$rows['type'];
$rows['cfieldname'] = $cfieldnamematch[1];
}

if($rows['type'] == "M" || $rows['type'] == "P")
{
$matchfield=$rows['cfieldname'].$rows['value'];
Expand Down
11 changes: 11 additions & 0 deletions qanda.php
Expand Up @@ -96,6 +96,12 @@ function retrieveConditionInfo($ia)
// while ($crow = $cresult->FetchRow())
foreach ($aAllConditions as $crow)
{
if (preg_match("/^\+(.*)$/",$crow['cfieldname'],$cfieldnamematch))
{ // this condition uses a single checkbox as source
$crow['type'] = "+".$crow['type'];
$crow['cfieldname'] = $cfieldnamematch[1];
}

$conditions[] = array ($crow['qid'],
$crow['cqid'],
$crow['cfieldname'],
Expand Down Expand Up @@ -165,6 +171,11 @@ function retrieveJSidname($cd,$currentgid=null)
{
$idname="java$cd[5]$cd[3]";
}
elseif ($cd[4] == "+M" ||
$cd[4] == "+P")
{
$idname="java$cd[2]";
}
elseif ($cd[4] == "D" ||
$cd[4] == "N" ||
$cd[4] == "S" ||
Expand Down

0 comments on commit 481a375

Please sign in to comment.