diff --git a/functions/functions.limesurvey.php b/functions/functions.limesurvey.php index 66b54dc7..8e465228 100644 --- a/functions/functions.limesurvey.php +++ b/functions/functions.limesurvey.php @@ -313,20 +313,21 @@ function limesurvey_quota_replicate_completions($lime_sid,$questionnaire_id,$sam * @param string $lime_sgqa The limesurvey SGQA * @param int $lime_sid The limesurvey survey id * @param int $case_id The case id - * @param int $sample_import_id The sample import ID * @param string $value The value to compare * @param string $comparison The type of comparison + * @param int $sample_import_id The sample import ID + * * @return bool|int False if failed, otherwise 1 if matched, 0 if doesn't * */ -function limesurvey_quota_match($lime_sgqa,$lime_sid,$case_id,$value,$comparison) +function limesurvey_quota_match($lime_sgqa,$lime_sid,$case_id,$value,$comparison,$sample_import_id) { global $db; $sql = "SELECT count(*) as c FROM " . LIME_PREFIX . "survey_$lime_sid as s JOIN `case` as c ON (c.case_id = '$case_id') - JOIN `sample` as sam ON (c.sample_id = sam.sample_id) + JOIN `sample` as sam ON (c.sample_id = sam.sample_id and sam.import_id = $sample_import_id) WHERE s.token = c.token AND s.`$lime_sgqa` $comparison '$value'"; @@ -345,19 +346,20 @@ function limesurvey_quota_match($lime_sgqa,$lime_sid,$case_id,$value,$comparison * @param int $case_id The case id * @param string $val The sample value to compare * @param string $var The sample variable to compare + * @param int $sample_import_id The sample import id we are looking at * * @return bool|int False if failed, otherwise 1 if matched, 0 if doesn't * @author Adam Zammit * @since 2012-04-30 */ -function limesurvey_quota_replicate_match($lime_sid,$case_id,$val,$var) +function limesurvey_quota_replicate_match($lime_sid,$case_id,$val,$var,$import_id) { global $db; $sql = "SELECT count(*) as c FROM " . LIME_PREFIX . "survey_$lime_sid as s JOIN `case` as c ON (c.case_id = '$case_id') - JOIN `sample` as sam ON (c.sample_id = sam.sample_id) + JOIN `sample` as sam ON (c.sample_id = sam.sample_id and sam.import_id = $sample_import_id) JOIN `sample_var` as sv ON (sv.sample_id = sam.sample_id AND sv.var LIKE '$var' AND sv.val LIKE '$val') WHERE s.token = c.token"; diff --git a/functions/functions.operator.php b/functions/functions.operator.php index a7d3a48f..3bad8a61 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -1685,9 +1685,9 @@ function update_row_quota($questionnaire_id,$case_id = false) if ($case_id != false) { if ($r['lime_sgqa'] == -2) - $match = limesurvey_quota_replicate_match($r['lime_sid'],$case_id,$r['exclude_val'],$r['exclude_var']); + $match = limesurvey_quota_replicate_match($r['lime_sid'],$case_id,$r['exclude_val'],$r['exclude_var'],$r['sample_import_id']); else - $match = limesurvey_quota_match($r['lime_sgqa'],$r['lime_sid'],$case_id,$r['value'],$r['comparison']); + $match = limesurvey_quota_match($r['lime_sgqa'],$r['lime_sid'],$case_id,$r['value'],$r['comparison'],$r['sample_import_id']); if ($match == 1) {