- if ($sgqa != -1) { ?>
+ if ($sgqa != -1) { if ($sgqa != -2) { ?>
+ } else { ?>
+
+
+ } ?>
} else { ?>
diff --git a/functions/functions.limesurvey.php b/functions/functions.limesurvey.php
index ee308370..54a2b76f 100644
--- a/functions/functions.limesurvey.php
+++ b/functions/functions.limesurvey.php
@@ -106,6 +106,38 @@ function limesurvey_quota_match($lime_sgqa,$lime_sid,$case_id,$value,$comparison
return false;
}
+/**
+ * Return whether the given case matches the replicate sample only quota
+ *
+ * @param int $lime_sid The Limesurvey survey id
+ * @param int $case_id The case id
+ * @param string $val The sample value to compare
+ * @param string $var The sample variable to compare
+ *
+ * @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)
+{
+ 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_var` as sv ON (sv.sample_id = sam.sample_id AND sv.var LIKE '$var' AND sv.val LIKE '$val')
+ WHERE s.token = c.case_id";
+
+ $rs = $db->GetRow($sql);
+
+ if (isset($rs) && !empty($rs))
+ return $rs['c'];
+
+ return false;
+
+}
+
/**
* Return the number of completions for a given
* questionnaire, where the given question has
diff --git a/functions/functions.operator.php b/functions/functions.operator.php
index d53312b7..8f7c10de 100644
--- a/functions/functions.operator.php
+++ b/functions/functions.operator.php
@@ -1509,7 +1509,10 @@ function update_row_quota($questionnaire_id,$case_id = false)
//the quota criteria, and if so, increment the quota completions counter
if ($case_id != false)
{
- $match = limesurvey_quota_match($r['lime_sgqa'],$r['lime_sid'],$case_id,$r['value'],$r['comparison']);
+ if ($r['lime_sgqa'] == -2)
+ $match = limesurvey_quota_replicate_match($r['lime_sid'],$case_id,$r['exclude_val'],$r['exclude_var']);
+ else
+ $match = limesurvey_quota_match($r['lime_sgqa'],$r['lime_sid'],$case_id,$r['value'],$r['comparison']);
if ($match == 1)
{
@@ -1527,7 +1530,10 @@ function update_row_quota($questionnaire_id,$case_id = false)
}
else
{
- $completions = limesurvey_quota_completions($r['lime_sgqa'],$r['lime_sid'],$r['questionnaire_id'],$r['sample_import_id'],$r['value'],$r['comparison']);
+ if ($r['lime_sgqa'] == -2)
+ $completions = limesurvey_quota_replicate_completions($r['lime_sid'],$r['questionnaire_id'],$r['sample_import_id'],$r['exclude_val'],$r['exclude_var']);
+ else
+ $completions = limesurvey_quota_completions($r['lime_sgqa'],$r['lime_sid'],$r['questionnaire_id'],$r['sample_import_id'],$r['value'],$r['comparison']);
$updatequota = true;
}