" . T_("Enter the details for creating the row quota:") . " ";
@@ -331,7 +335,7 @@ if ($questionnaire_id != false)
FROM sample_var AS sv, sample AS s
WHERE s.import_id = $sample_import_id
AND s.sample_id = sv.sample_id
- AND sv.var = '$sample_var'
+ AND sv.var_id = '$sample_var_id'
GROUP BY sv.val";
display_chooser($db->GetAll($sql),"exclude_val","exclude_val",false,false,false,false);
@@ -339,6 +343,7 @@ if ($questionnaire_id != false)
?>
+
diff --git a/admin/samplecallattempts.php b/admin/samplecallattempts.php
index a103d2c2..2928e425 100644
--- a/admin/samplecallattempts.php
+++ b/admin/samplecallattempts.php
@@ -79,7 +79,7 @@ function sample_call_attempt_report($questionnaire_id = false, $sample_id = fals
$qs = "";
if ($qsqri !== false)
$qs = "JOIN questionnaire_sample_quota_row as q ON (q.questionnaire_sample_quota_row_id = '$qsqri')
- JOIN sample_var ON (sample_var.sample_id = c.sample_id AND sample_var.var LIKE q.exclude_var AND sample_var.val LIKE q.exclude_val)";
+ JOIN sample_var ON (sample_var.sample_id = c.sample_id AND sample_var.var_id = q.exclude_var_id AND sample_var.val LIKE q.exclude_val)";
$sql = "SELECT ca1 AS callattempts, COUNT( ca1 ) AS sample
FROM ( SELECT count( ca.call_attempt_id ) AS ca1
@@ -211,6 +211,6 @@ if ($questionnaire_id || $questionnaire_id == -1)
print "
" . T_("No calls for this questionnaire") . "
";
}
-xhtml_foot();
+xhtml_foot("../js/custom.js");
?>
diff --git a/admin/samplelist.php b/admin/samplelist.php
index 96166ef2..95e23250 100644
--- a/admin/samplelist.php
+++ b/admin/samplelist.php
@@ -61,189 +61,380 @@ $js_foot = array(
"../js/custom.js"
);
-if (isset($_POST['submitr']))
+if (isset($_POST['ren']))
{
$sample_import_id = intval($_POST['sample_import_id']);
+ unset($_POST['ren']);
+ unset($_POST['sample_import_id']);
+
$sql = "UPDATE sample_import
SET description = " . $db->qstr($_POST['description']) . "
WHERE sample_import_id = $sample_import_id";
$db->Execute($sql);
- $_GET['rename'] = $sample_import_id;
+ $_GET['edit'] = $sample_import_id;
}
-if (isset($_POST['submit']))
+
+if (isset($_POST['ed']))
{
$sample_import_id = intval($_POST['sample_import_id']);
- unset($_POST['submit']);
+ unset($_POST['ed']);
unset($_POST['sample_import_id']);
- foreach($_POST as $p)
- {
- $sql = "DELETE FROM sample_var
- WHERE var LIKE " . $db->qstr($p) . "
- AND sample_id IN
- (SELECT sample_id
- FROM sample
- WHERE import_id = $sample_import_id)";
- $db->Execute($sql);
+// print_r($_POST). ""; //посмотрим чего отравляется
+ if (isset($_POST['del']) && isset($_POST['type']) ) {
+ $a = array(); $b = array(); $cert = array(); $a = $_POST['type'];
+
+ //echo "
type before unset->>"; foreach($_POST['type'] as $key => $val) { echo ' | ', $key,' => ',$val,' | '; }; print "
";
+
+ foreach($_POST['del'] as $p) {
+ unset ($_POST['type'][$p]);
+ $deleted[] = $p;
+ }
+ $b = $_POST['type']; $cert = array_diff_assoc($a, $b);
+
+ foreach($cert as $key => $val ) {
+
+ if ($val == 3 || $val==4 || $val == 5 || $val == 6 || $val == 7){
+ echo "
", T_("Attention!! It's not recommended to delete string '$key'. Please BE Careful and check again strings to delete."), "
";
+ }
+ /* else { echo "
", T_("You can delete string '$key'. "), "
"; } */
+ }
+ //echo "
del ->>"; foreach($_POST['del'] as $key => $val) { echo ' | ', $key,' => ',$val,' | '; }; print "
";
}
+
+ if (isset($_POST['type'])){
+
+ //check that we have correct var types and quantity
+ $prph = 0; $pcd = 0; $st = 0; $fn = 0; $eml =0;
+ foreach($_POST['type'] as $key => $val) {
+ if ($val == 3) $prph++;
+ else if ($val == 5) $pcd++;
+ else if ($val == 4) $st++;
+ else if ($val == 6) $fn++;
+ else if ($val == 7) $ln++;
+ else if ($val == 8) $eml++;
+ }
+ /* if($prph == 1) {$ch1 = true;}
+
+
+
+
+
+
+
+
+
+
+ if ($ch1 && $ch2 && $ch3 && $ch4) */$typecheck = true; //echo $ch1,$ch2,$ch3,$ch4, "typecheck=",$typecheck, "" ;
+
+ if ($typecheck){
+
+ foreach($_POST['type'] as $p => $val)
+ {
+ $sql = "UPDATE sample_import_var_restrict
+ SET `type` = $val
+ WHERE `var_id` = $p";
+ $db->Execute($sql);
+ }
+
+ if (isset($_POST['del'])) {
+ $db->StartTrans();
+
+ foreach($_POST["del"] as $p) {
+ $sql = "DELETE FROM `sample_import_var_restrict`
+ WHERE var_id = $p";
+ $db->Execute($sql);
+ echo "
", T_(" String $p DELETED"), "
";
+
+ $sql = "DELETE FROM `sample_var`
+ WHERE var_id = $p
+ AND sample_id IN (SELECT sample_id FROM `sample` WHERE import_id = $sample_import_id)";
+ $db->Execute($sql);
+ echo "
", T_(" Sample_Var data for variable $p DELETED from this sample"), "
";
+ }
+ unset($_POST['del']);
+
+ $db->CompleteTrans();
+
+ }
+ }
+ else {
+ echo "
", T_("Smth wrong with selected field types. Please check again var types selection and/or fields that you supposed to delete."), "
";
+ //exit ();
+ }
+ }
+
+ if (isset($_POST['var'])){
+
+ foreach($_POST['var'] as $p => $val)
+ {// echo '| ',$p,' => ',$val,'+ ';
+ $v = str_replace(" ", "_", $val);
+
+ $sql = "UPDATE sample_import_var_restrict
+ SET `var` = '$v'
+ WHERE sample_import_id = $sample_import_id
+ AND `var_id` = $p";
+ $db->Execute($sql);
+ }
+
+ unset($_POST['var']);
+ }
+
+ if (isset($_POST['see'])){
+
+ $sql = "UPDATE sample_import_var_restrict
+ SET `restrict` = 1
+ WHERE sample_import_id = $sample_import_id";
+ $db->Execute($sql);
+
+ foreach($_POST['see'] as $p => $val)
+ {// echo $p,' => ',$val,' + ';
+ $sql = "UPDATE sample_import_var_restrict
+ SET `restrict` = 0
+ WHERE sample_import_id = $sample_import_id
+ AND `var_id` = $val";
+ $db->Execute($sql);
+ }
+ unset($_POST['see']);
+ }
+
+ unset($_POST['type']);
$_GET['edit'] = $sample_import_id;
+
}
-if (isset($_POST['submitvp']))
-{
- $sample_import_id = intval($_POST['sample_import_id']);
+if (isset($_GET['delete_sample'])){
- unset($_POST['submitvp']);
- unset($_POST['sample_import_id']);
- $db->StartTrans();
-
- $sql = "UPDATE sample_import_var_restrict
- SET `restrict` = 1
- WHERE sample_import_id = $sample_import_id";
- $db->Execute($sql);
+ $sample_import_id = $_GET['delete_sample'];
- foreach($_POST as $p => $val)
- {
- $sql = "UPDATE sample_import_var_restrict
- SET `restrict` = 0
- WHERE sample_import_id = $sample_import_id
- AND `var` LIKE " . $db->qstr($p);
+ // -->check questionnaire_sample - unassign sample if assigned
+ $sql = "SELECT questionnaire_id FROM `questionnaire_sample` WHERE sample_import_id = $sample_import_id";
+ $rs = $db->GetAll($sql);
+ if (count($rs) != 0){
+ echo "
", T_("Sample $sample_import_id is still assigned to questionnaire. Please unassign sample prior to delete."), "
";
+ }
+ else{
+ //get the string list of sample_id's
+ $sql = "SELECT sample_id FROM `sample` where import_id = $sample_import_id";
+ $rs = $db->GetAll($sql);
+ for($i=0;$i<=count($rs)-1;$i++){ $samimdel[] = $rs[$i]['sample_id'] ;}
+ $samimdel_s = implode(",",$samimdel);
+
+ $db->StartTrans();
+
+ //del from questionnaire_sample_exclude_priority
+ $sql = "DELETE FROM `questionnaire_sample_exclude_priority` WHERE sample_id IN ($samimdel_s)";
+ $db->Execute($sql);
+
+ //del from questionnaire_sample_quota
+ $sql = "DELETE FROM `questionnaire_sample_quota` WHERE sample_import_id = $sample_import_id";
+ $db->Execute($sql);
+
+ //del from questionnaire_sample_quota_row
+ $sql = "DELETE FROM `questionnaire_sample_quota_row` WHERE sample_import_id = $sample_import_id";
+ $db->Execute($sql);
+
+ //del from questionnaire_sample_quota_row_exclude
+ $sql = "DELETE FROM `questionnaire_sample_quota_row_exclude` WHERE sample_id IN ($samimdel_s)";
$db->Execute($sql);
- }
- $db->CompleteTrans();
-
- $_GET['view'] = $sample_import_id;
+ //del from questionnaire_sample_timeslot
+ $sql = "DELETE FROM `questionnaire_sample_timeslot` WHERE sample_import_id = $sample_import_id";
+ $db->Execute($sql);
+
+ //delete from sample_var
+ $sql = "DELETE FROM `sample_var` WHERE sample_id IN ($samimdel_s)";
+ $db->Execute($sql);
+
+ //del from sample_import_var_restrict
+ $sql = "DELETE FROM `sample_import_var_restrict` WHERE sample_import_id = $sample_import_id";
+ $db->Execute($sql);
+
+ //del from sample
+ $sql = "DELETE FROM `sample` WHERE import_id = $sample_import_id";
+ $db->Execute($sql);
+
+ //del from sample_import
+ $sql = "DELETE FROM `sample_import` WHERE sample_import_id = $sample_import_id";
+ $db->Execute($sql);
+
+ $db->CompleteTrans();
+
+ if (mysql_errno() == 0){echo "
", T_("Sample $sample_import_id was deleted."), "
"; }
+ else {echo "
ERROR ".mysql_errno()." ".mysql_error()."\n
";}
+ }
+
+ unset($_GET['delete_sample']);
+ $samimdel_s = '';
}
-if (isset($_GET['rename']))
+
+if (isset($_GET['edit']) )
{
- $subtitle=T_("Rename sample");
+ $subtitle=T_("Rename, Set viewing permissions & Manage sample variables") ;
xhtml_head(T_("Sample management"),true,$css,$js_head,false,false,false,$subtitle);
- echo "
" . T_("Go back") . "";
- $sample_import_id = intval($_GET['rename']);
+ echo "
";
+
+ $sample_import_id = intval($_GET['edit']);
+
+ $sql = "SELECT * FROM sample_import WHERE sample_import_id = $sample_import_id";
+ $sd = $db->GetRow($sql);
+
+ if($sd['enabled'] == 1) $dis = disabled; // -> disable edit and delete if sample is enabled
- $sql = "SELECT description
- FROM sample_import
- WHERE sample_import_id = $sample_import_id";
- $rs = $db->GetOne($sql);
+ $sql = "SELECT type, description
+ FROM sample_var_type";
+ $rd = $db->GetAll($sql);
+
+ $sql = "SELECT sir.var_id,
+ CONCAT('
') as var,
+ CONCAT ('
+ ' ,svt.description, ' ";
+ $selected = "selected=\"selected\"";
+ foreach($rd as $r)
+ {
+ $sql .= "" . T_($r['description']) . " ";
+ }
+ $sql .= " ') as type, sv.val,
+ CONCAT('
') as see,
+ CONCAT('
') as del,
+ sir.restrict IS NULL as existss
+ FROM sample_import as si, sample_var as sv, sample as s, sample_import_var_restrict as sir, sample_var_type as svt
+ WHERE si.sample_import_id = $sample_import_id
+ AND sir.sample_import_id = si.sample_import_id
+ AND sir.var_id = sv.var_id
+ AND sv.sample_id = s.sample_id
+ AND s.import_id = si.sample_import_id
+ AND svt.type = sir.type
+ GROUP BY sir.var_id";
+ $rs = $db->GetAll($sql);
- print "
" . T_("Sample current description") . ": " . $rs . " ";
+ print "
" . T_("Sample") . ": " . $sd['description'] . " ID $sample_import_id ";
+ print "
";
+ print "
";
+
+ if($sd['enabled'] == 0){
+
?>
" . T_("Go back") . "";
-
- $sample_import_id = intval($_GET['view']);
-
- $sql = "SELECT sample_id
- FROM `sample`
- WHERE import_id = $sample_import_id";
-
- $sample_id = $db->GetOne($sql);
-
- $sql = "SELECT si.description, sv.val, sv.var,
- CONCAT('
') as box,
- sir.restrict IS NULL as existss
- FROM sample_import as si
- JOIN `sample` as s ON (s.import_id = si.sample_import_id AND s.sample_id = $sample_id)
- JOIN sample_var as sv ON (sv.sample_id = s.sample_id)
- LEFT JOIN sample_import_var_restrict as sir ON (sir.sample_import_id = si.sample_import_id AND sir.var = sv.var)
- WHERE si.sample_import_id = $sample_import_id";
-
- $rs = $db->GetAll($sql);
-
- //if not in restrict table, then insert
- foreach($rs as $r)
- {
- if ($r['existss'] == 1)
- {
- $sql = "INSERT INTO sample_import_var_restrict (sample_import_id,var,`restrict`)
- VALUES ($sample_import_id,'{$r['var']}',0)";
- $db->Execute($sql);
- }
}
-
- print "
" . T_("Operator viewing permissions") . " ". T_("for") . " " . T_("sample") . ": " . $rs[0]['description'] . " ";
- if (!$rs) print "
" . T_("There's no data in this sample. ") . " ";
- else {
- print "
" . T_("Select which fields from this sample should be able to be viewed by operators") . "
-
-
-
" . T_("Go back") . "";
-
- $sample_import_id = intval($_GET['edit']);
-
- $sql = "SELECT si.description, sv.val, sv.var,
- CONCAT('
') as box
- FROM sample_import as si, sample_var as sv, sample as s
- WHERE si.sample_import_id = $sample_import_id
- AND sv.sample_id = s.sample_id
- AND s.import_id = si.sample_import_id
- GROUP BY sv.var";
- $rs = $db->GetAll($sql);
-
- print "
" . T_("Sample") . ": " . $rs[0]['description'] . " ";
-
if ($rs){
- print "
" . T_("Select which fields from this sample to deidentify. Deidentified fields will be permanently deleted from the sample.") . "
";
+
?>
-
-
" . T_("Select which fields from this sample to deidentify.
Deidentified fields will be permanently deleted from the sample.") . "
";
}
else
{
- print " " . T_("Sample details")."";
- $sql = "SELECT sv.sample_id, c.case_id , s.Time_zone_name,
+ $sql = "SELECT sv.sample_id, c.case_id , s.Time_zone_name,
TIME_FORMAT(CONVERT_TZ(NOW(),@@session.time_zone,s.Time_zone_name),'". TIME_FORMAT ."') as time
FROM sample_var AS sv
LEFT JOIN (`case` AS c , sample as s) ON ( c.sample_id = sv.sample_id AND s.sample_id = c.sample_id ) WHERE c.case_id = '$case_id'
@@ -312,26 +313,28 @@ if ($case_id != false)
if ($r){
$fnames = array("sample_id", "Time_zone_name", "time");
$fdesc = array(T_("Sample id"),T_("Timezone"),T_("Time NOW"));
-
- $sql = "SELECT var
- FROM sample_var
- WHERE sample_id = {$r[0]['sample_id']} AND type IN (2,3,6,7)
+ $varr= array();
+ $sql = "SELECT var,var_id
+ FROM sample_import_var_restrict
+ WHERE sample_import_id = $sid AND type IN (2,3,6,7)
ORDER by var DESC";
$rs = $db->GetAll($sql);
foreach($rs as $rsw)
{
- $fnames[] = $rsw['var'];
+ $fnames[] = $rsw['var_id'];
$fdesc[] = $rsw['var'];
+ $varr[] = $rsw['var_id']; //array for valid var_id's
}
+ $varr= implode(",",$varr);
foreach($r as &$rw)
{
- $sql = "SELECT var,val
+ $sql = "SELECT var_id,val
FROM sample_var
- WHERE sample_id = {$rw['sample_id']} AND type IN (2,3,6,7)";
+ WHERE sample_id = {$rw['sample_id']} AND var_id IN ($varr)";
$rs = $db->GetAll($sql);
foreach($rs as $rsw){
- $rw[$rsw['var']] = $rsw['val'];
+ $rw[$rsw['var_id']] = $rsw['val'];
}
}
diff --git a/contactdetails.php b/contactdetails.php
index 186af2ce..5d5f5d02 100644
--- a/contactdetails.php
+++ b/contactdetails.php
@@ -148,12 +148,12 @@ else
//display sample details
// use sample_import_var_restrict to limit
- $sql = "SELECT s.var,s.val
- FROM sample_var as s
- JOIN `case` as c on (c.case_id = '$case_id' and c.sample_id = s.sample_id)
- JOIN `sample` as sa ON (sa.sample_id = c.sample_id)
- LEFT JOIN sample_import_var_restrict as sv ON (sv.var LIKE s.var AND sa.import_id = sv.sample_import_id)
- WHERE (sv.restrict IS NULL OR sv.restrict = 0)";
+ $sql = "SELECT sivr.var,sv.val
+ FROM `sample_var` as sv, `sample_import_var_restrict` as sivr, `case` as c
+ WHERE c.case_id = '$case_id'
+ AND sv.sample_id = c.sample_id
+ AND sivr.var_id = sv.var_id
+ AND (sivr.restrict IS NULL OR sivr.restrict = 0)";
$rs = $db->GetAll($sql);
diff --git a/email.php b/email.php
index 3c5076ab..a5e9f823 100644
--- a/email.php
+++ b/email.php
@@ -97,10 +97,11 @@ if (isset($_POST['firstname']))
$fieldsarray["{SID}"]=$fieldsarray["{SURVEYID}"]=$lime_sid;
//$fieldsarray["{SURVEYNAME}"]=$thissurvey["surveyls_title"];
- $sql = "SELECT s.var,s.val
- FROM `sample_var` as s, `case` as c
+ $sql = "SELECT sivr.var,sv.val
+ FROM `sample_var` as sv, `sample_import_var_restrict` as sivr, `case` as c
WHERE c.case_id = $case_id
- AND s.sample_id = c.sample_id";
+ AND sv.sample_id = c.sample_id
+ AND sivr.var_id = sv.var_id";
$attributes = $db->GetAssoc($sql);
@@ -317,11 +318,11 @@ $sc = $db->GetOne($sql);
if ($sc == 1)
{
- $sql = "SELECT sv1.val as firstname, sv2.val as lastname, sv3.val as email
+ $sql = "SELECT
+(SELECT sv.val from sample_var as sv, `sample_import_var_restrict` as sivr WHERE sivr.var_id = sv.var_id AND sv.sample_id = c.sample_id AND sivr.type =6) as firstname,
+(SELECT sv.val from sample_var as sv, `sample_import_var_restrict` as sivr WHERE sivr.var_id = sv.var_id AND sv.sample_id = c.sample_id AND sivr.type =7) as lastname,
+(SELECT sv.val from sample_var as sv, `sample_import_var_restrict` as sivr WHERE sivr.var_id = sv.var_id AND sv.sample_id = c.sample_id AND sivr.type =8) as email
FROM `case` as c
- LEFT JOIN sample_var as sv1 on (sv1.sample_id = c.sample_id AND sv1.type = 6)
- LEFT JOIN sample_var as sv2 on (sv2.sample_id = c.sample_id AND sv2.type = 7)
- LEFT JOIN sample_var as sv3 on (sv3.sample_id = c.sample_id AND sv3.type = 8)
WHERE c.case_id = $case_id";
$rs = $db->GetRow($sql);
diff --git a/functions/functions.import.php b/functions/functions.import.php
index 13295f0d..0b567a7c 100644
--- a/functions/functions.import.php
+++ b/functions/functions.import.php
@@ -130,7 +130,7 @@ function display_table($data)
global $db;
$sql = "SELECT description,type
- FROM sample_var_type";
+ FROM sample_var_type ORDER BY type ASC";
$rs = $db->GetAll($sql);
@@ -145,11 +145,11 @@ function display_table($data)
";
print "";
- print " ";
+ //print " ";
$selected = "selected=\"selected\"";
foreach($rs as $r)
{
- print "" . T_($r['description']) . " ";
+ print "" . T_($r['description']) . " ";
$selected = "";
}
print " ";
@@ -212,6 +212,7 @@ function import_file($file, $description, $fields, $firstrow = 2)
$selected_type = array();
$selected_name = array();
+ $sirv_id = array();
foreach($fields as $key => $val)
{
@@ -229,10 +230,12 @@ function import_file($file, $description, $fields, $firstrow = 2)
}
$sql = "INSERT INTO sample_import_var_restrict
- (`sample_import_id`,`var`,`restrict`)
- VALUES ($id,'" . $fields["n_" . substr($key,2)] . "',$restrict)";
+ (`sample_import_id`,`var`,`type`,`restrict`)
+ VALUES ($id,'" . $fields["n_" . substr($key,2)] . "','" . $fields["t_" . substr($key,2)] . "',$restrict)";
- $db->Execute($sql);
+ $db->Execute($sql);
+
+ $sirv_id[substr($key,2)] = $db->Insert_ID(); //
}
}
@@ -312,8 +315,8 @@ function import_file($file, $description, $fields, $firstrow = 2)
{
$dkey = $db->Quote($data[$key - 1]);
- $sql = "INSERT INTO sample_var (sample_id,var,val,type)
- VALUES ('$sid','$val',{$dkey},'{$selected_type[$key]}')";
+ $sql = "INSERT INTO sample_var (sample_id,var_id,var,val,type)
+ VALUES ('$sid','{$sirv_id[$key]}','$val',{$dkey},'{$selected_type[$key]}')";
$db->Execute($sql);
diff --git a/functions/functions.limesurvey.php b/functions/functions.limesurvey.php
index 6327c4bb..fee499c5 100644
--- a/functions/functions.limesurvey.php
+++ b/functions/functions.limesurvey.php
@@ -283,11 +283,11 @@ function validate_email($email){
* @param int $questionnaire_id The questionnaire ID
* @param int $sample_import_id The sample import ID
* @param string $val The value to compare
- * @param string $var The variable to compare
+ * --- changed @param string $var the variable to compare
+ * to @param string $var_id - ID for variable to compare
* @return bool|int False if failed, otherwise the number of completions
- *
*/
-function limesurvey_quota_replicate_completions($lime_sid,$questionnaire_id,$sample_import_id,$val,$var)
+function limesurvey_quota_replicate_completions($lime_sid,$questionnaire_id,$sample_import_id,$val,$var_id)
{
global $db;
@@ -305,7 +305,7 @@ function limesurvey_quota_replicate_completions($lime_sid,$questionnaire_id,$sam
FROM " . LIME_PREFIX . "survey_$lime_sid as s
JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_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')
+ JOIN `sample_var` as sv ON (sv.sample_id = sam.sample_id AND sv.var_id = '$var_id' AND sv.val LIKE '$val')
WHERE s.submitdate IS NOT NULL
AND s.token = c.token";
@@ -355,14 +355,15 @@ function limesurvey_quota_match($lime_sgqa,$lime_sid,$case_id,$value,$comparison
* @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
+ * --- changed @param string $var the variable to compare
+ * to @param string $var_id - ID for 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,$sample_import_id)
+function limesurvey_quota_replicate_match($lime_sid,$case_id,$val,$var_id,$sample_import_id)
{
global $db;
@@ -370,7 +371,7 @@ function limesurvey_quota_replicate_match($lime_sid,$case_id,$val,$var,$sample_i
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 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')
+ JOIN `sample_var` as sv ON (sv.sample_id = sam.sample_id AND sv.var_id = '$var_id' AND sv.val LIKE '$val')
WHERE s.token = c.token";
$rs = $db->GetRow($sql);
diff --git a/functions/functions.operator.php b/functions/functions.operator.php
index 77b361e6..9fd59380 100644
--- a/functions/functions.operator.php
+++ b/functions/functions.operator.php
@@ -184,8 +184,9 @@ function get_sample_variable($variable,$case_id)
$sql = "SELECT s.val as r
FROM sample_var as s
- JOIN `case` as c on (c.case_id = '$case_id' and s.sample_id = c.sample_id)
- WHERE s.var = '$variable'";
+ JOIN `case` as c on (c.case_id = '$case_id' and s.sample_id = c.sample_id), `sample_import_var_restrict` as sivr
+ WHERE sivr.var = '$variable'
+ AND s.var_id = sivr.var_id";
$rs = $db->GetRow($sql);
@@ -238,7 +239,6 @@ function get_respondent_variable($variable,$respondent_id)
$rs = $db->GetRow($sql);
-
if (empty($rs)) return "";
return $rs['r'];
@@ -380,14 +380,15 @@ function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing =
//$db->Execute("SET @row := 0");
- $sql = "SELECT val as phone
- FROM sample_var
- WHERE sample_id = '$sample_id'
- AND val > 0
- AND val is NOT NULL
- AND val != \"\"
- AND (`type` = 2 or `type` = 3)
- ORDER BY `type` DESC";
+ $sql = "SELECT sv.val as phone
+ FROM sample_var as sv, sample_import_var_restrict as sivr
+ WHERE sv.sample_id = '$sample_id'
+ AND sv.var_id = sivr.var_id
+ AND sv.val > 0
+ AND sv.val is NOT NULL
+ AND sv.val != \"\"
+ AND sivr.`type` IN (2,3)
+ ORDER BY sivr.`type` DESC";
$r5 = $db->GetAll($sql);
@@ -418,8 +419,8 @@ function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing =
$sql = "INSERT INTO respondent (case_id,firstName,lastName,Time_zone_name)
SELECT $case_id as case_id, IFNULL(s1.val,'') as firstName, IFNULL(s2.val,'') as lastName, s3.Time_zone_name as Time_zone_name
FROM sample as s3
- LEFT JOIN sample_var as s2 on (s2.sample_id = '$sample_id' and s2.type = 7)
- LEFT JOIN sample_var as s1 on (s1.sample_id = '$sample_id' and s1.type = 6)
+ LEFT JOIN (sample_var as s2 , sample_import_var_restrict as sivr2) on (s2.sample_id = '$sample_id' and s2.var_id = sivr2.var_id and sivr2.type = 7)
+ LEFT JOIN (sample_var as s1 , sample_import_var_restrict as sivr1) on (s1.sample_id = '$sample_id' and s1.var_id = sivr1.var_id and sivr1.type = 6)
WHERE s3.sample_id = '$sample_id'";
$db->Execute($sql);
@@ -637,8 +638,8 @@ function get_case_id($operator_id, $create = false)
AND ((qsep.questionnaire_id is NULL) or qsep.exclude = 0)
AND !(q.restrict_work_shifts = 1 AND sh.shift_id IS NULL AND os.outcome_type_id != 2)
AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL AND os.outcome_type_id != 2)
- AND ((apn.appointment_id IS NOT NULL) or qs.call_attempt_max = 0 or ((SELECT count(*) FROM call_attempt WHERE case_id = c.case_id) < qs.call_attempt_max))
- AND ((apn.appointment_id IS NOT NULL) or qs.call_max = 0 or ((SELECT count(*) FROM `call` WHERE case_id = c.case_id) < qs.call_max))
+ AND ((apn.appointment_id IS NOT NULL) or qs.call_attempt_max = 0 or ((SELECT count(*) FROM call_attempt WHERE call_attempt.case_id = c.case_id) < qs.call_attempt_max))
+ AND ((apn.appointment_id IS NOT NULL) or qs.call_max = 0 or ((SELECT count(*) FROM `call` WHERE `call`.case_id = c.case_id) < qs.call_max))
AND (apn.require_operator_id IS NULL OR apn.require_operator_id = '$operator_id')
AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = c.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0
ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, qsep.priority DESC, a.start ASC
@@ -1515,7 +1516,7 @@ function close_row_quota($questionnaire_sample_quota_row_id,$update = true)
WHERE s.import_id = qs.sample_import_id
AND qs.questionnaire_sample_quota_row_id = $questionnaire_sample_quota_row_id
AND s.sample_id = sv.sample_id
- AND sv.var = qs.exclude_var
+ AND sv.var_id = qs.exclude_var_id
AND qs.exclude_val LIKE sv.val";
$db->Execute($sql);
@@ -1549,8 +1550,8 @@ function copy_row_quota($questionnaire_id,$sample_import_id,$copy_sample_import_
//Set quota_reached to 0 always
- $sql = "INSERT INTO questionnaire_sample_quota_row (questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,exclude_var,exclude_val,quota_reached,description)
- SELECT questionnaire_id, $copy_sample_import_id, lime_sgqa,value,comparison,completions,exclude_var,exclude_val,0,description
+ $sql = "INSERT INTO questionnaire_sample_quota_row (questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,exclude_var_id,exclude_var,exclude_val,quota_reached,description)
+ SELECT questionnaire_id, $copy_sample_import_id, lime_sgqa,value,comparison,completions,exclude_var_id,exclude_var,exclude_val,0,description
FROM questionnaire_sample_quota_row
WHERE questionnaire_id = '$questionnaire_id'
AND sample_import_id = '$sample_import_id'";
@@ -1578,8 +1579,8 @@ function copy_row_quota_with_blocking($questionnaire_id,$sample_import_id,$copy_
//Set quota_reached to 0 always
- $sql = "INSERT INTO questionnaire_sample_quota_row (questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,exclude_var,exclude_val,quota_reached,description)
- SELECT questionnaire_id, $copy_sample_import_id, lime_sgqa,value,comparison,completions,exclude_var,exclude_val,quota_reached,description
+ $sql = "INSERT INTO questionnaire_sample_quota_row (questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,exclude_var_id,exclude_var,exclude_val,quota_reached,description)
+ SELECT questionnaire_id, $copy_sample_import_id, lime_sgqa,value,comparison,completions, exclude_var_id,exclude_var,exclude_val, quota_reached,description
FROM questionnaire_sample_quota_row
WHERE questionnaire_id = '$questionnaire_id'
AND sample_import_id = '$sample_import_id'";
@@ -1609,7 +1610,7 @@ function copy_row_quota_with_adjusting($questionnaire_id,$sample_import_id,$copy
$db->StartTrans();
// Select quotas from the old sample rows and calculate
- $sql = "SELECT questionnaire_sample_quota_row_id,q.questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,quota_reached,q.lime_sid,qsq.exclude_var,qsq.exclude_val
+ $sql = "SELECT questionnaire_sample_quota_row_id,q.questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,quota_reached,q.lime_sid,qsq.exclude_var_id,qsq.exclude_var,qsq.exclude_val
FROM questionnaire_sample_quota_row as qsq, questionnaire as q
WHERE qsq.questionnaire_id = '$questionnaire_id'
AND q.questionnaire_id = '$questionnaire_id'
@@ -1664,7 +1665,7 @@ function update_row_quota($questionnaire_id,$case_id = false)
$db->StartTrans();
- $sql = "SELECT questionnaire_sample_quota_row_id,q.questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,quota_reached,q.lime_sid,qsq.exclude_var,qsq.exclude_val,qsq.current_completions,qsq.priority,qsq.autoprioritise
+ $sql = "SELECT questionnaire_sample_quota_row_id,q.questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,quota_reached,q.lime_sid, qsq.exclude_var_id,qsq.exclude_var,qsq.exclude_val,qsq.current_completions,qsq.priority,qsq.autoprioritise
FROM questionnaire_sample_quota_row as qsq, questionnaire as q
WHERE qsq.questionnaire_id = '$questionnaire_id'
AND q.questionnaire_id = '$questionnaire_id'
@@ -1688,7 +1689,7 @@ 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'],$r['sample_import_id']);
+ $match = limesurvey_quota_replicate_match($r['lime_sid'],$case_id,$r['exclude_val'],$r['exclude_var_id'],$r['sample_import_id']);
else
$match = limesurvey_quota_match($r['lime_sgqa'],$r['lime_sid'],$case_id,$r['value'],$r['comparison'],$r['sample_import_id']);
@@ -1709,7 +1710,7 @@ function update_row_quota($questionnaire_id,$case_id = false)
else
{
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']);
+ $completions = limesurvey_quota_replicate_completions($r['lime_sid'],$r['questionnaire_id'],$r['sample_import_id'],$r['exclude_val'],$r['exclude_var_id']);
else
$completions = limesurvey_quota_completions($r['lime_sgqa'],$r['lime_sid'],$r['questionnaire_id'],$r['sample_import_id'],$r['value'],$r['comparison']);
$updatequota = true;
@@ -1832,7 +1833,7 @@ function update_quota_priorities($questionnaire_id)
WHERE s.import_id = qs.sample_import_id
AND qs.questionnaire_sample_quota_row_id = '$qsqri'
AND s.sample_id = sv.sample_id
- AND sv.var = qs.exclude_var
+ AND sv.var_id = qs.exclude_var_id
AND qs.exclude_val LIKE sv.val
AND qsep.questionnaire_id = qs.questionnaire_id
AND qsep.sample_id = s.sample_id";
diff --git a/include/limesurvey/admin/exportresults.php b/include/limesurvey/admin/exportresults.php
index ef0ebcb5..aff094f5 100644
--- a/include/limesurvey/admin/exportresults.php
+++ b/include/limesurvey/admin/exportresults.php
@@ -267,13 +267,13 @@ $quexsfilterstate = questionnaireSampleFilterstate();
." ".T_("Shift report")."\n";
- $sql = "SELECT sv.var,sv.val
- FROM `questionnaire` as q, questionnaire_sample as qs, sample as s, sample_var as sv
- WHERE q.lime_sid = $surveyid
+ $sql = "SELECT sivr.var,sv.val
+ FROM `questionnaire` as q, questionnaire_sample as qs, sample_var as sv, `sample_import_var_restrict` as sivr
+ WHERE q.lime_sid = $surveyid
AND qs.questionnaire_id = q.questionnaire_id
- AND s.import_id = qs.sample_import_id
- AND sv.sample_id = s.sample_id
- GROUP BY qs.sample_import_id,sv.var";
+ AND sivr.sample_import_id = qs.sample_import_id
+ AND sv.var_id = sivr.var_id
+ GROUP BY qs.sample_import_id,sivr.var";
$queXSrs = $connect->GetAssoc($sql);
@@ -305,13 +305,13 @@ if ($tokenTableExists)
{
$aTokenFieldNames=GetTokenFieldsAndNames($surveyid,false,true);
- $sql = "SELECT sv.var,sv.val
- FROM `questionnaire` as q, questionnaire_sample as qs, sample as s, sample_var as sv
- WHERE q.lime_sid = $surveyid
+ $sql = "SELECT sivr.var,sv.val
+ FROM `questionnaire` as q, questionnaire_sample as qs, sample_var as sv, `sample_import_var_restrict` as sivr
+ WHERE q.lime_sid = $surveyid
AND qs.questionnaire_id = q.questionnaire_id
- AND s.import_id = qs.sample_import_id
- AND sv.sample_id = s.sample_id
- GROUP BY qs.sample_import_id,sv.var";
+ AND sivr.sample_import_id = qs.sample_import_id
+ AND sv.var_id = sivr.var_id
+ GROUP BY qs.sample_import_id,sivr.var";
$attributeFields = $connect->GetAssoc($sql);
@@ -554,10 +554,11 @@ if ($tokenTableExists && $thissurvey['anonymized']=='N' && isset($_POST['attribu
if (in_array("SAMPLE:$attr_name",$_POST['attribute_select']))
{
$dquery .= ", ( SELECT sv.val
- FROM sample_var as sv, `case` as c3
+ FROM sample_var as sv, `case` as c3,`sample_import_var_restrict` as sivr
WHERE c3.token = {$dbprefix}survey_$surveyid.token
AND c3.sample_id = sv.sample_id
- AND sv.var LIKE '$attr_name') as attribute_$i ";
+ AND sivr.var_id = sv.var_id
+ AND sivr.var LIKE '$attr_name') as attribute_$i ";
$attributeFieldAndNames["attribute_$i"] = $attr_name;
@@ -1362,4 +1363,4 @@ function strip_tags_full($string) {
$string=str_replace('-oth-','',$string);
return FlattenText($string,true,'UTF-8',false);
}
-?>
+?>
\ No newline at end of file
diff --git a/include/limesurvey/classes/expressions/LimeExpressionManager.php b/include/limesurvey/classes/expressions/LimeExpressionManager.php
index 5d0709d5..4e55d0a0 100644
--- a/include/limesurvey/classes/expressions/LimeExpressionManager.php
+++ b/include/limesurvey/classes/expressions/LimeExpressionManager.php
@@ -3422,17 +3422,19 @@
if ($use_call)
{
- $sql = "SELECT sv.var,sv.val
- FROM sample_var as sv, `case` as c, `call` as cl
+ $sql = "SELECT sivr.var,sv.val
+ FROM sample_var as sv, `case` as c, `call` as cl, `sample_import_var_restrict` as sivr
WHERE c.sample_id = sv.sample_id
AND c.case_id = cl.case_id
+ AND sv.var_id = sivr.var_id
AND cl.call_id = '{$_SESSION['token']}'";
}
else
{
- $sql = "SELECT sv.var,sv.val
- FROM sample_var as sv, `case` as c
+ $sql = "SELECT sivr.var,sv.val
+ FROM sample_var as sv, `case` as c, `sample_import_var_restrict` as sivr
WHERE c.sample_id = sv.sample_id
+ AND sv.var_id = sivr.var_id
AND c.token = '{$_SESSION['token']}'";
}
@@ -3504,10 +3506,6 @@
'jsName'=>'',
'readWrite'=>'N',
);
-
-
-
-
}
else
@@ -3535,13 +3533,13 @@
//Add all sample variables for this questionnaire
global $connect;
- $sql = "SELECT sv.var,sv.val
- FROM `questionnaire` as q, questionnaire_sample as qs, sample as s, sample_var as sv
- WHERE q.lime_sid = $surveyid
- AND qs.questionnaire_id = q.questionnaire_id
- AND s.import_id = qs.sample_import_id
- AND sv.sample_id = s.sample_id
- GROUP BY qs.sample_import_id,sv.var";
+ $sql = "SELECT sivr.var,sv.val
+ FROM `questionnaire` as q, questionnaire_sample as qs, sample_var as sv, `sample_import_var_restrict` as sivr
+ WHERE q.lime_sid = $surveyid
+ AND qs.questionnaire_id = q.questionnaire_id
+ AND sivr.sample_import_id = qs.sample_import_id
+ AND sv.var_id = sivr.var_id
+ GROUP BY qs.sample_import_id,sivr.var";
$queXSrs = $connect->GetAssoc($sql);
diff --git a/include/limesurvey/quexs.php b/include/limesurvey/quexs.php
index 440a4b6a..ca7ef8b9 100644
--- a/include/limesurvey/quexs.php
+++ b/include/limesurvey/quexs.php
@@ -419,10 +419,11 @@ function quexs_update_sample($lime_sid,$id,$postedfieldnames)
$sgqa = $r['sid'] . 'X' . $r['gid'] . 'X' . $r['qid'] . $r['title'];
$var = $r['answer'];
- $sql = "UPDATE sample_var as sv, ".LIME_PREFIX."survey_$lime_sid as ld
+ $sql = "UPDATE sample_var as sv, ".LIME_PREFIX."survey_$lime_sid as ld, `sample_import_var_restrict` as sivr
SET sv.val = ld.$sgqa
- WHERE sv.var LIKE '$var'
+ WHERE sivr.var LIKE '$var'
AND sv.sample_id = '$sample_id'
+ AND sivr.var_id = sv.var_id
AND ld.id = '$id'";
$db->Execute($sql);
@@ -477,8 +478,9 @@ function get_sample_variable($variable,$case_id)
$sql = "SELECT s.val as r
FROM sample_var as s
- JOIN `case` as c on (c.case_id = '$case_id' and s.sample_id = c.sample_id)
- WHERE s.var = '$variable'";
+ JOIN `case` as c on (c.case_id = '$case_id' and s.sample_id = c.sample_id), `sample_import_var_restrict` as sivr
+ WHERE sivr.var = '$variable'
+ AND s.var_id = sivr.var_id";
$rs = $db->GetRow($sql);
diff --git a/referral.php b/referral.php
index 7f08adfe..97964d6b 100644
--- a/referral.php
+++ b/referral.php
@@ -69,11 +69,12 @@ if (isset($_POST['submit']))
{
$case_id = get_case_id($operator_id);
- $sql = "SELECT s.var
- FROM sample_var as s, `case` as c
- WHERE c.case_id = '$case_id'
- AND s.sample_id = c.sample_id
- AND s.type = 3";
+ $sql = "SELECT sivr.var
+ FROM `sample_import_var_restrict` as sivr, `sample_var` as s, `case` as c
+ WHERE c.case_id = '$case_id'
+ AND s.var_id = sivr.var_id
+ AND s.sample_id = c.sample_id
+ AND sivr.type = 3";
$pphone = $db->GetOne($sql);
@@ -94,10 +95,11 @@ if (isset($_POST['submit']))
$import_id = $db->GetOne($sql);
//get all sample records
- $sql = "SELECT s.var,s.val, s.type
- FROM sample_var as s, `case` as c
+ $sql = "SELECT sivr.var,s.val, sivr.type
+ FROM `sample_import_var_restrict` as sivr, `sample_var` as s, `case` as c
WHERE c.case_id = '$case_id'
- AND s.sample_id = c.sample_id";
+ AND s.sample_id = c.sample_id
+ AND s.var_id = sivr.var_id";
$rs = $db->GetAll($sql);
@@ -124,14 +126,28 @@ if (isset($_POST['submit']))
//insert sample var records
foreach($rs as $r)
{
- $sql = "INSERT INTO `sample_var` (`sample_id`,`var`,`val`,`type`)
- VALUES ('$sample_id','{$r['var']}'," . $db->qstr($_POST['v_' . $r['var']]) . ",'{$r['type']}')";
+
+ $sql = "INSERT INTO `sample_import_var_restrict` (`var`,`type`)
+ VALUES ('{$r['var']}','{$r['type']}')";
$db->Execute($sql);
+
+ $varid = $db->Insert_ID();
+
+ $sql = "INSERT INTO `sample_var` (`sample_id`,`var_id`,`val`)
+ VALUES ('$sample_id','$varid'," . $db->qstr($_POST['v_' . $r['var']]) . ")";
+ $db->Execute($sql);
+
}
//Add CASEREFERREDFROM record
- $sql = "INSERT INTO `sample_var` (`sample_id`,`var`,`val`,`type`)
- VALUES ('$sample_id','CASEREFERREDFROM','$case_id','1')";
+ $sql = "INSERT INTO `sample_import_var_restrict` (`var`,`type`)
+ VALUES ('CASEREFERREDFROM','1')";
+ $db->Execute($sql);
+
+ $varid = $db->Insert_ID();
+
+ $sql = "INSERT INTO `sample_var` (`sample_id`,`var_id`,`val`)
+ VALUES ('$sample_id','$varid','$case_id')";
$db->Execute($sql);
@@ -212,11 +228,12 @@ if ($sc == 1)
//Create a list of sample records matching this current case
- $sql = "SELECT sv.var,t.description,sv.type
- FROM sample_var as sv, `case` as c, sample_var_type as t
- WHERE sv.sample_id = c.sample_id
- AND c.case_id = '$case_id'
- AND sv.type = t.type";
+ $sql = "SELECT sivr.var,t.description,sivr.type
+ FROM `sample_import_var_restrict` as sivr,`sample_var` as sv, `case` as c, `sample_var_type` as t
+ WHERE c.case_id = '$case_id'
+ AND sv.sample_id = c.sample_id
+ AND sv.var_id = sivr.var_id
+ AND sivr.type = t.type";
$rs = $db->GetAll($sql);
diff --git a/respondent.php b/respondent.php
index 70287003..35fadc5b 100644
--- a/respondent.php
+++ b/respondent.php
@@ -154,13 +154,12 @@ else
//display sample details
//limit to those allowed by admin
- $sql = "SELECT s.var,s.val
- FROM sample_var as s
- JOIN `case` as c on (c.case_id = '$case_id' and c.sample_id = s.sample_id)
- JOIN `sample` as sa ON (sa.sample_id = c.sample_id)
- LEFT JOIN sample_import_var_restrict as sv ON (sv.var LIKE s.var AND sa.import_id = sv.sample_import_id)
- WHERE (sv.restrict IS NULL OR sv.restrict = 0)";
-
+ $sql = "SELECT sivr.var,sv.val
+ FROM `sample_var` as sv, `sample_import_var_restrict` as sivr, `case` as c
+ WHERE c.case_id = '$case_id'
+ AND sv.sample_id = c.sample_id
+ AND sivr.var_id = sv.var_id
+ AND (sivr.restrict IS NULL OR sivr.restrict = 0)";
$rs = $db->GetAll($sql);
diff --git a/sample var update and fix.txt b/sample var update and fix.txt
new file mode 100644
index 00000000..8ad83fe8
--- /dev/null
+++ b/sample var update and fix.txt
@@ -0,0 +1,76 @@
+
+!!! PRIOR TO ANY FURTHER CHANGES -> MAKE a backup copy of 'quexs' database ! and working QUEXS folder on server !!!
+ - in case smth will go wrong you may loose your data!!!
+
+ next steps should be done manually (used phpMyAdmin for sql management) , sql querries are for original 'quexs' sql DB structure
+
+
+-->> 1st create new table columns:
+
+/* insert var_id + type into sample_import_var_restrict table, fill var_id with continuous numbers (unique)*/
+ALTER TABLE `sample_import_var_restrict` ADD `var_id` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT AFTER `sample_import_id`;
+ ALTER TABLE `sample_import_var_restrict` ADD `type` SMALLINT( 10 ) UNSIGNED NOT NULL AFTER `var`;
+ ALTER TABLE `sample_import_var_restrict` DROP PRIMARY KEY, ADD PRIMARY KEY(`var_id`)
+
+
+/* insert var_id into sample_var table */
+ALTER TABLE `sample_var` ADD `var_id` BIGINT( 20 ) UNSIGNED NOT NULL AFTER `sample_id`
+
+
+-->> 2nd fill created columns with corresponding data
+
+/* update sample_var table */
+
+UPDATE `sample_var` as sv ,`sample`as s, `sample_import_var_restrict` as sivr SET sv.`var_id`=sivr.`var_id` WHERE sv.`var` LIKE sivr.`var` AND sv.`sample_id`=s.`sample_id` AND s.`import_id`=sivr.`sample_import_id`
+
+
+/* update type @ sample_import_var_restrict table, insert corresponding values from sample_var */
+UPDATE `sample_import_var_restrict` ,
+`sample_var` SET `sample_import_var_restrict`.`type` = `sample_var`.`type` WHERE `sample_import_var_restrict`.`var_id` = `sample_var`.`var_id`
+
+
+--> 3d some cleanup
+
+/*--> check if there're unmatched strings for previously "de-identified" samples*/
+SELECT * FROM `sample` LEFT JOIN `sample_var` ON (`sample`.sample_id = `sample_var`.sample_id) WHERE `sample_var`.sample_id IS NULL
+
+/* --> delete `Time_zone_name` and `phone` data from `sample` table for previously "de-identified" samples from `sample_var` table*/
+UPDATE `sample` LEFT JOIN `sample_var` ON (`sample`.sample_id = `sample_var`.sample_id) SET `Time_zone_name`= '',`phone`= '' WHERE `sample_var`.sample_id IS NULL
+
+
+/* delete records for deidentified sample strings*/
+DELETE FROM `sample_import_var_restrict` WHERE `type` =0
+
+--> !!! VERY Important !!! check that collations and character sets are the same for all tables in DB (f.i. utf8_unicode_ci )
+
+ probably need some php and sql querry here...
+
+
+--> !!!!QUOTA Row SHOULD BE FINISHED AND CLEARED FOR ALL SAMPLES AND QUESTtionnaires!!!!
+--> (could influence quota calculation and behaviour because now switched to sample.var_id instead of sample.var )
+
+/* add column for var_id*/
+ALTER TABLE `questionnaire_sample_quota_row` ADD `exclude_var_id` BIGINT( 20 ) NOT NULL AFTER `completions`
+
+/*fill `exclude_var_id` with relevant data for `exclude_var_id` = `var_id`*/
+UPDATE `questionnaire_sample_quota_row` as qsqr, `sample_import_var_restrict` as sivr SET qsqr.exclude_var_id = sivr.var_id WHERE qsqr.sample_import_id = sivr.sample_import_id and qsqr.exclude_var = sivr.var
+
+
+--> 4th update *.php files in 'quexs' folder according to the branch revisions
+
+--> Finish list
+
+CHECK program is working OK :
+ ADMIN - > samplesearch, samplelist, dataoutput, superviser, quotas , lime(export data)
+ operator panel -> displaying respondent data as required
+
+
+
+update file admin/functions.import.php - > remove sample_var.`var`, sample_var.`type` from importing data
+
+delete columns `var` and `type` from `sample_var` table
+
+
+THE END
+
+*enjoy sample freedom*
\ No newline at end of file