mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Here it is
REWORKED sample strorage and sample variables organizatoin to have edit/delete/change options Please, be very carefull with update
This commit is contained in:
@@ -59,16 +59,16 @@ if (isset($_GET['key']) || isset($_GET['sample']))
|
||||
$questionnaire_id = bigintval($_GET['questionnaire_id']);
|
||||
$sample_import_id = bigintval($_GET['sample_import_id']);
|
||||
|
||||
$sql = "SELECT sv.var as value
|
||||
FROM `sample_var` as sv
|
||||
WHERE sv.sample_id = (SELECT sample_id FROM sample WHERE import_id = '$sample_import_id' LIMIT 1)";
|
||||
$sql = "SELECT sivr.var as value, sivr.var_id as var_id
|
||||
FROM `sample_import_var_restrict` as sivr
|
||||
WHERE sivr.sample_import_id = $sample_import_id";
|
||||
|
||||
$svars = $db->GetAll($sql);
|
||||
|
||||
$fn = "key_all_";
|
||||
if (isset($_GET['sample'])) $fn = "sample_all_";
|
||||
$fn = "key_";
|
||||
if (isset($_GET['sample'])) $fn = "sample_";
|
||||
|
||||
$fn .= $questionnaire_id . "_" . $sample_import_id .".csv";
|
||||
$fn .= T_("ALL") . "_Qid=" . $questionnaire_id . "_Sid=" . $sample_import_id .".csv";
|
||||
|
||||
header("Content-Type: text/csv");
|
||||
header("Content-Disposition: attachment; filename=$fn");
|
||||
@@ -116,18 +116,18 @@ if (isset($_GET['key']) || isset($_GET['sample']))
|
||||
//left join if getting whole sample file
|
||||
if (isset($_GET['sample'])) $sql .= "LEFT ";
|
||||
|
||||
$sql .= "JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_id' AND c.sample_id = sample.sample_id) ";
|
||||
$sql .= "JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_id' AND c.sample_id = `sample`.sample_id) ";
|
||||
|
||||
if (isset($_GET['sample'])) $sql .= " LEFT JOIN `outcome` as o ON (o.outcome_id = c.current_outcome_id)";
|
||||
|
||||
$i = 0;
|
||||
foreach ($svars as $s)
|
||||
{
|
||||
$sql .= " LEFT JOIN sample_var AS sv$i ON (sv$i.sample_id = sample.sample_id AND sv$i.var = '{$s['value']}') ";
|
||||
$sql .= " LEFT JOIN sample_var AS sv$i ON (sv$i.sample_id = `sample`.sample_id AND sv$i.var_id = '{$s['var_id']}') ";
|
||||
$i++;
|
||||
}
|
||||
|
||||
$sql .= " WHERE sample.import_id = '$sample_import_id'";
|
||||
$sql .= " WHERE `sample`.import_id = '$sample_import_id'";
|
||||
|
||||
$list = $db->GetAll($sql);
|
||||
|
||||
@@ -152,23 +152,23 @@ if (isset($_GET['key']) || isset($_GET['sample']))
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_GET['sample_var']))
|
||||
{
|
||||
if (isset($_GET['sample_var'])){
|
||||
$questionnaire_id = bigintval($_GET['questionnaire_id']);
|
||||
$sample_import_id = bigintval($_GET['sample_import_id']);
|
||||
$sample_var = $db->quote($_GET['sample_var']);
|
||||
$varid = intval($_GET['sample_var']);
|
||||
|
||||
$sql = "SELECT c.token,c.case_id, sv.val
|
||||
FROM sample, `case` as c, sample_var as sv
|
||||
WHERE c.questionnaire_id = '$questionnaire_id'
|
||||
AND sample.import_id = '$sample_import_id'
|
||||
AND c.sample_id = sample.sample_id
|
||||
AND sv.sample_id = sample.sample_id
|
||||
AND sv.var = $sample_var";
|
||||
$sql = "SELECT c.token, c.case_id, sv.val, sivr.var
|
||||
FROM `case` as c, `sample_import_var_restrict` as sivr, `sample_var` as sv
|
||||
WHERE c.questionnaire_id = $questionnaire_id
|
||||
AND sivr.sample_import_id = $sample_import_id
|
||||
AND c.sample_id = sv.sample_id
|
||||
AND sivr.var_id = sv.var_id
|
||||
AND sivr.var_id = $varid";
|
||||
|
||||
$list = $db->GetAll($sql);
|
||||
$sample_var = $list[0]['var'];
|
||||
|
||||
$fn = "key_$questionnaire_id" . "_" . $sample_import_id .".csv";
|
||||
$fn = "key-" . $sample_var . "_Qid=$questionnaire_id" . "_Sid=" . $sample_import_id .".csv";
|
||||
|
||||
header("Content-Type: text/csv");
|
||||
header("Content-Disposition: attachment; filename=$fn");
|
||||
@@ -219,14 +219,15 @@ if ($questionnaire_id)
|
||||
print "  <a href='" .LIME_URL . "admin/admin.php?action=exportresults&sid=$lsid&quexsfilterinc=$questionnaire_id:$sample_import_id' class='btn btn-default fa btn-lime'>" . T_("Download data for this sample via Limesurvey") . "</a></div>";
|
||||
|
||||
//get sample vars
|
||||
$sql = "SELECT sv.var as value, sv.var as description
|
||||
FROM `sample_var` as sv
|
||||
WHERE sv.sample_id = (SELECT sample_id FROM sample WHERE import_id = '$sample_import_id' LIMIT 1)";
|
||||
$sql = "SELECT sivr.var_id as value, sivr.var as description
|
||||
FROM `sample_import_var_restrict` as sivr
|
||||
WHERE sivr.sample_import_id = $sample_import_id";
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
//download a key file linking the caseid to the sample
|
||||
print "<div class='form-group clearfix'><h3 class='col-sm-4 text-right'>" . T_("Download key file: select sample var") . ": </h3>";
|
||||
|
||||
display_chooser($db->GetAll($sql),"sample_var","sample_var",true,"questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id",true,true,false,true,"form-inline pull-left");
|
||||
display_chooser($rs,"sample_var","sample_var",true,"questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id",true,true,false,true,"form-inline pull-left");
|
||||
|
||||
// print "</div><div class='form-group col-sm-offset-4'>";
|
||||
|
||||
|
||||
@@ -127,11 +127,17 @@ if ( (isset($_GET['appointment_id']) && isset($_GET['case_id'])) ||(($_GET['new'
|
||||
|
||||
xhtml_head($title,true,$css,$js_head,false,false,false,$subtitle);
|
||||
$lang = DEFAULT_LOCALE;
|
||||
$sql = "SELECT CONVERT_TZ(NOW(),'SYSTEM',r.Time_zone_name) as startdate, CONVERT_TZ(s.end,'UTC',r.Time_zone_name) as enddate FROM `shift` as s, `case` as c, `respondent` as r WHERE s.questionnaire_id = c.questionnaire_id AND c.case_id = $case_id AND r.case_id = c.case_id ORDER BY s.end DESC LIMIT 1";
|
||||
$rs = $db->GetRow($sql); $startdate = $rs['startdate'];$enddate = $rs['enddate'];
|
||||
|
||||
print "<script type='text/javascript'>
|
||||
$(document).ready(function() { var startDateTextBox = $('#start'); var endDateTextBox = $('#end');
|
||||
/* var std = '$startdate'.split(/[- :]/);
|
||||
var etd = '$enddate'.split(/[- :]/); */
|
||||
$.timepicker.datetimeRange(
|
||||
startDateTextBox,endDateTextBox,{
|
||||
minInterval: (1000*60*15), // 15min
|
||||
numberOfMonths: 2,
|
||||
dateFormat: 'yy-mm-dd',
|
||||
timeFormat: 'HH:mm:ss',
|
||||
showSecond: false,
|
||||
@@ -141,13 +147,13 @@ if ( (isset($_GET['appointment_id']) && isset($_GET['case_id'])) ||(($_GET['new'
|
||||
stepMinute: 5,
|
||||
hourGrid: 2,
|
||||
minuteGrid: 10,
|
||||
start: {minDateTime: new Date()}, // start picker options
|
||||
end: { } // end picker options
|
||||
minDate: '$startdate',
|
||||
maxDate: '$enddate',
|
||||
});});</script>";
|
||||
|
||||
if ($_GET['new'] =='new'){
|
||||
$start = date("Y-m-d H:m:s");
|
||||
$end = date("Y-m-d H:m:s", mktime(0,0,0,date("m"),date("d")+7,date("Y")));
|
||||
$start = $startdate;
|
||||
$end = $enddate;
|
||||
$rtz = $_GET['rtz'];
|
||||
}
|
||||
if (isset($_GET['appointment_id'])) {
|
||||
@@ -189,7 +195,7 @@ if ( (isset($_GET['appointment_id']) && isset($_GET['case_id'])) ||(($_GET['new'
|
||||
print "<label class='text-right col-sm-2 control-label'>" . T_("Respondent TimeZone") . ":</label>
|
||||
<h4 class='col-sm-2 text-danger text-uppercase fa-lg'>" . $rtz . "</h4>
|
||||
<label class=''>" . T_("Respondent Time") . ": <b class='fa fa-2x '>" . date("H:i:s") . "</b></label>";
|
||||
|
||||
|
||||
print "<br/><br/><label class='pull-left text-right control-label col-sm-2' for='start'>" . T_("Start time") . "</label>
|
||||
<div class='pull-left'><input class='form-control' type='text' value='$start' id='start' name='start'/></div>";
|
||||
print "<br/><br/><label class='pull-left text-right control-label col-sm-2' for='end'>" . T_("End time") . "</label>
|
||||
@@ -214,7 +220,7 @@ if ( (isset($_GET['appointment_id']) && isset($_GET['case_id'])) ||(($_GET['new'
|
||||
|
||||
if ($_GET['new'] == 'new') { print "<input type='hidden' value='create' id='new' name='new'/><input type='hidden' value='$case_id' id='case_id' name='case_id'/>";}
|
||||
|
||||
print "<div class='clearfix form-group'></div><br/><br/>
|
||||
print "<div class='clearfix'></div><br/><br/>
|
||||
<div class='col-sm-2'><a href='' onclick='history.back();return false;' class='btn btn-default pull-left'><i class='fa fa-ban fa-lg'></i> " . T_("Cancel edit") . "</a></div>";
|
||||
|
||||
print "<div class='col-sm-2'><button type='submit' class='btn btn-primary btn-block'><i class='fa fa-floppy-o fa-lg'></i> " . T_("Save changes") . "</button></div>";
|
||||
|
||||
@@ -171,12 +171,10 @@ if ($questionnaire_id != false)
|
||||
print "<li>" . T_("{Sample:var} A record from the sample where the column name is 'var'") . "</li>";
|
||||
print "</ul></div>";
|
||||
|
||||
$sql = "SELECT sv.var as description, CONCAT('{Sample:', sv.var, '}') as value
|
||||
FROM `sample` AS s, sample_var AS sv, questionnaire_sample as qs
|
||||
$sql = "SELECT sivr.var as description, CONCAT('{Sample:', sivr.var, '}') as value
|
||||
FROM `sample_import_var_restrict` as sivr, questionnaire_sample as qs
|
||||
WHERE qs.questionnaire_id = '$questionnaire_id'
|
||||
AND s.import_id = qs.sample_import_id
|
||||
AND s.sample_id = sv.sample_id
|
||||
GROUP BY sv.var";
|
||||
AND sivr.sample_import_id = qs.sample_import_id";
|
||||
?>
|
||||
<form action="" method="get" class="form-inline form-group">
|
||||
<label for="value"><?php echo T_("The value to pre fill"); ?>: </label><input type="text" name="value" id="value" size="50" class="form-control"/>
|
||||
|
||||
@@ -186,14 +186,15 @@ if ($questionnaire_id != false)
|
||||
$sgqa = false;
|
||||
if (isset($_GET['sgqa'])) $sgqa = $_GET['sgqa'];
|
||||
|
||||
$sql = "SELECT CONCAT( lq.sid, 'X', lq.gid, 'X', CASE WHEN lq.parent_qid = 0 THEN lq.qid ELSE CONCAT(lq.parent_qid, lq.title) END) as value, CASE WHEN lq.parent_qid = 0 THEN lq.question ELSE CONCAT(lq2.question, ': ', lq.question) END as description, CASE WHEN CONCAT( lq.sid, 'X', lq.gid, 'X', CASE WHEN lq.parent_qid = 0 THEN lq.qid ELSE CONCAT(lq.parent_qid, lq.title) END) = '$sgqa' THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
$sql = "SELECT CONCAT( lq.sid, 'X', lq.gid, 'X', CASE WHEN lq.parent_qid = 0 THEN lq.qid ELSE CONCAT(lq.parent_qid, lq.title) END) as value,
|
||||
CASE WHEN lq.parent_qid = 0 THEN lq.question ELSE CONCAT(lq2.question, ': ', lq.question) END as description,
|
||||
CASE WHEN CONCAT( lq.sid, 'X', lq.gid, 'X', CASE WHEN lq.parent_qid = 0 THEN lq.qid ELSE CONCAT(lq.parent_qid, lq.title) END) = '$sgqa' THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
FROM `" . LIME_PREFIX . "questions` AS lq
|
||||
LEFT JOIN `" . LIME_PREFIX . "questions` AS lq2 ON ( lq2.qid = lq.parent_qid )
|
||||
JOIN `" . LIME_PREFIX . "groups` as g ON (g.gid = lq.gid)
|
||||
WHERE lq.sid = '$lime_sid'
|
||||
ORDER BY lq.parent_qid ASC, lq.question_order ASC";//, lq.parent_qid ASC lq.qid ASC,
|
||||
|
||||
|
||||
ORDER BY CASE WHEN lq2.question_order IS NULL THEN lq.question_order ELSE lq2.question_order + (lq.question_order / 1000) END ASC";
|
||||
|
||||
display_chooser($db->GetAll($sql),"sgqa","sgqa",true,"questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id",true,true,false,true,"form-group");
|
||||
|
||||
print "<div class='clearfix'></div>";
|
||||
|
||||
@@ -143,44 +143,10 @@ if ($questionnaire_id)
|
||||
|
||||
//Rows to display: Strata Status Quota Sample Sample Used Sample Remaining Completes % Complete
|
||||
|
||||
// Firstly, for the entire sample
|
||||
|
||||
//We need to calc Sample size, Sample drawn, Sample remain, Completions, %complete
|
||||
$sql = "SELECT (c.sample_id is not null) as type, count(*) as count
|
||||
FROM sample as s
|
||||
JOIN questionnaire_sample as qs ON (qs.questionnaire_id = '$questionnaire_id' and qs.sample_import_id = s.import_id)
|
||||
LEFT JOIN `case` as c ON (c.questionnaire_id = qs.questionnaire_id and c.sample_id = s.sample_id)
|
||||
WHERE s.import_id = '$sample_import_id'
|
||||
GROUP BY (c.sample_id is not null)";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
//type == 1 is drawn from sample, type == 0 is remains in sample
|
||||
$drawn = 0;
|
||||
$remain = 0;
|
||||
|
||||
foreach ($rs as $r)
|
||||
{
|
||||
if ($r['type'] == 1) $drawn = $r['count'];
|
||||
if ($r['type'] == 0) $remain = $r['count'];
|
||||
}
|
||||
|
||||
$sql = "SELECT count(*) as count
|
||||
FROM `case` as c, sample as s
|
||||
WHERE c.current_outcome_id = 10
|
||||
AND s.import_id = '$sample_import_id'
|
||||
AND s.sample_id = c.sample_id
|
||||
AND c.questionnaire_id = '$questionnaire_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
$completions = $rs['count'];
|
||||
|
||||
$report[] = array("strata" => T_("Total sample"), "quota" => $drawn + $remain, "sample" => $drawn + $remain, "sampleused" => $drawn, "sampleremain" => $remain, "completions" => $completions, "perc" => ROUND(($completions / ($drawn + $remain)) * 100,2));
|
||||
|
||||
//a. (Standard quota) Monitor outcomes of questions in completed questionnaires, and exclude selected sample records when completion limit is reached
|
||||
//b. (Replicate quota) Exclude selected sample records (where lime_sgqa == -1)
|
||||
$sql = "SELECT questionnaire_sample_quota_row_id,lime_sgqa,value,completions,quota_reached,lime_sid,comparison,exclude_var,exclude_val,qsq.description,current_completions, priority, autoprioritise
|
||||
$sql = "SELECT questionnaire_sample_quota_row_id,lime_sgqa,value,completions,quota_reached,lime_sid,comparison,exclude_var_id,exclude_var,exclude_val,qsq.description,current_completions, priority, autoprioritise
|
||||
FROM questionnaire_sample_quota_row as qsq, questionnaire as q
|
||||
WHERE qsq.questionnaire_id = '$questionnaire_id'
|
||||
AND qsq.sample_import_id = '$sample_import_id'
|
||||
@@ -207,12 +173,14 @@ if ($questionnaire_id)
|
||||
{
|
||||
$perc = ($v['completions'] <= 0 ? 0 : ROUND(($completions / ($v['completions'])) * 100,2));
|
||||
}
|
||||
|
||||
|
||||
if($v['exclude_var_id'] > 0) $excl = "sv.var_id = '{$v['exclude_var_id']}'"; else $excl = "sv.var LIKE '{$v['exclude_var']}'";
|
||||
|
||||
//We need to calc Sample size, Sample drawn, Sample remain
|
||||
$sql = "SELECT (c.sample_id is not null) as type, count(*) as count
|
||||
FROM sample as s
|
||||
JOIN questionnaire_sample as qs ON (qs.questionnaire_id = '$questionnaire_id' and qs.sample_import_id = s.import_id)
|
||||
JOIN sample_var as sv ON (sv.sample_id = s.sample_id AND sv.var LIKE '{$v['exclude_var']}' AND sv.val LIKE '{$v['exclude_val']}')
|
||||
JOIN sample_var as sv ON (sv.sample_id = s.sample_id AND sv.val LIKE '{$v['exclude_val']}' AND $excl )
|
||||
LEFT JOIN `case` as c ON (c.questionnaire_id = qs.questionnaire_id and c.sample_id = s.sample_id)
|
||||
WHERE s.import_id = '$sample_import_id'
|
||||
GROUP BY (c.sample_id is not null)";
|
||||
@@ -243,7 +211,7 @@ if ($questionnaire_id)
|
||||
$status = T_("open");
|
||||
}
|
||||
|
||||
$report[] = array("strata" => "<a href='quotarow.php?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id'>" . $v['description'] . "</a>", "status" => $status, "quota" => $v['completions'], "sample" => $drawn + $remain, "sampleused" => $drawn, "sampleremain" => $remain, "completions" => $completions, "perc" => $perc, "priority" => "<input type='text' size='3' value='$priority' id='p$qsqr' name='p$qsqr' />", "autoprioritise" => "<input type='checkbox' id='a$qsqr' name='a$qsqr' $checked />");
|
||||
$report[] = array("strata" => "<a href='quotarow.php?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id'>" . $v['description'] . "</a>", "status" => $status, "quota" => $v['completions'], "sample" => $drawn + $remain, "sampleused" => $drawn, "sampleremain" => $remain, "completions" => $completions, "perc" => $perc, "priority" => "<input type='number' maxlength='3' min='0' max='100' size='3' style='width:6em;' value='$priority' id='p$qsqr' name='p$qsqr' class='form-control'/>", "autoprioritise" => "<input type='checkbox' id='a$qsqr' name='a$qsqr' $checked />");
|
||||
}
|
||||
|
||||
//c. (Questionnaire quota) Monitor outcomes of questions in completed questionnaires, and abort interview when completion limit is reached
|
||||
@@ -281,10 +249,46 @@ if ($questionnaire_id)
|
||||
$report[] = array("strata" => "<a href='" . LIME_URL . "/admin/admin.php?action=quotas&sid={$r['sid']}"a_id={$r['id']}&subaction=quota_editquota'>" . $r['name'] . "</a>", "quota" => $r['qlimit'], "completions" => $completions, "perc" => $perc);
|
||||
}
|
||||
|
||||
|
||||
// At the end - > the entire sample
|
||||
|
||||
//We need to calc Sample size, Sample drawn, Sample remain, Completions, %complete
|
||||
$sql = "SELECT (c.sample_id is not null) as type, count(*) as count
|
||||
FROM sample as s
|
||||
JOIN questionnaire_sample as qs ON (qs.questionnaire_id = '$questionnaire_id' and qs.sample_import_id = s.import_id)
|
||||
LEFT JOIN `case` as c ON (c.questionnaire_id = qs.questionnaire_id and c.sample_id = s.sample_id)
|
||||
WHERE s.import_id = '$sample_import_id'
|
||||
GROUP BY (c.sample_id is not null)";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
//type == 1 is drawn from sample, type == 0 is remains in sample
|
||||
$drawn = 0;
|
||||
$remain = 0;
|
||||
|
||||
foreach ($rs as $r)
|
||||
{
|
||||
if ($r['type'] == 1) $drawn = $r['count'];
|
||||
if ($r['type'] == 0) $remain = $r['count'];
|
||||
}
|
||||
|
||||
$sql = "SELECT count(*) as count
|
||||
FROM `case` as c, sample as s
|
||||
WHERE c.current_outcome_id = 10
|
||||
AND s.import_id = '$sample_import_id'
|
||||
AND s.sample_id = c.sample_id
|
||||
AND c.questionnaire_id = '$questionnaire_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
$completions = $rs['count'];
|
||||
|
||||
$report[] = array("strata" => T_("Total sample"), "quota" => $drawn + $remain, "sample" => $drawn + $remain, "sampleused" => $drawn, "sampleremain" => $remain, "completions" => $completions, "perc" => ROUND(($completions / ($drawn + $remain)) * 100,2));
|
||||
|
||||
print "<form action='' method='post'>";
|
||||
xhtml_table($report,array("strata","status","quota","sample","sampleused","sampleremain","completions","perc","priority","autoprioritise"),array(T_("Strata"),T_("Status"),T_("Quota"),T_("Sample"),T_("Sample Used"),T_("Sample Remaining"),T_("Completions"),T_("% Complete"),T_("Set priority"),T_("Auto prioritise")),"tclass",false,false);
|
||||
|
||||
if ($report[0]("strata") != T_("Total sample"))
|
||||
if (count($report) > 1)
|
||||
print "<input type='hidden' name='questionnaire_id' id='questionnaire_id' value='$questionnaire_id'/></br>
|
||||
<input type='submit' id='submit' name='submit' class='btn btn-primary fa'value='" . TQ_("Update priorities") . "'/>";
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ include("../functions/functions.operator.php");
|
||||
|
||||
global $db;
|
||||
|
||||
if (isset($_GET['questionnaire_id']) && isset($_GET['sgqa']) && isset($_GET['value']) && isset($_GET['completions']) && isset($_GET['sample_import_id']) && isset($_GET['comparison']) && isset($_GET['exclude_var']) && isset($_GET['exclude_val']))
|
||||
if (isset($_GET['questionnaire_id']) && isset($_GET['sgqa']) && isset($_GET['value']) && isset($_GET['completions']) && isset($_GET['sample_import_id']) && isset($_GET['comparison']) && isset($_GET['exclude_var_id']) && isset($_GET['exclude_var']) && isset($_GET['exclude_val']))
|
||||
{
|
||||
//need to add quota
|
||||
$value = -1;
|
||||
@@ -97,12 +97,13 @@ if (isset($_GET['questionnaire_id']) && isset($_GET['sgqa']) && isset($_GET['va
|
||||
}
|
||||
$completions = $db->quote($_GET['completions']);
|
||||
}
|
||||
$exclude_var_id = $db->quote($_GET['exclude_var_id']);
|
||||
$exclude_val = $db->quote($_GET['exclude_val']);
|
||||
$exclude_var = $db->quote($_GET['exclude_var']);
|
||||
$description = $db->quote($_GET['description']);
|
||||
|
||||
$sql = "INSERT INTO questionnaire_sample_quota_row(questionnaire_id, sample_import_id, lime_sgqa,value,completions,comparison,exclude_var,exclude_val,description, priority, autoprioritise)
|
||||
VALUES ($questionnaire_id, $sample_import_id, $sgqa, $value, $completions, $comparison, $exclude_var, $exclude_val, $description, $priority, $autoprioritise)";
|
||||
$sql = "INSERT INTO questionnaire_sample_quota_row(questionnaire_id, sample_import_id, lime_sgqa,value,completions,comparison,exclude_var_id,exclude_var,exclude_val,description, priority, autoprioritise)
|
||||
VALUES ($questionnaire_id, $sample_import_id, $sgqa, $value, $completions, $comparison, $exclude_var_id, $exclude_var, $exclude_val, $description, $priority, $autoprioritise)";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
@@ -168,7 +169,7 @@ if ($questionnaire_id != false)
|
||||
|
||||
print "<h2>" . T_("Current row quotas ") . ":</h2>"; //(click to delete)
|
||||
|
||||
$sql = "SELECT questionnaire_sample_quota_row_id,lime_sgqa,value,completions,quota_reached,lime_sid,comparison,exclude_var,exclude_val,current_completions
|
||||
$sql = "SELECT questionnaire_sample_quota_row_id, lime_sgqa, value, completions, quota_reached, lime_sid, comparison, exclude_var, exclude_val, current_completions
|
||||
FROM questionnaire_sample_quota_row as qsq, questionnaire as q
|
||||
WHERE qsq.questionnaire_id = '$questionnaire_id'
|
||||
AND qsq.sample_import_id = '$sample_import_id'
|
||||
@@ -246,7 +247,7 @@ if ($questionnaire_id != false)
|
||||
LEFT JOIN `" . LIME_PREFIX . "questions` AS lq2 ON ( lq2.qid = lq.parent_qid )
|
||||
JOIN `" . LIME_PREFIX . "groups` as g ON (g.gid = lq.gid)
|
||||
WHERE lq.sid = '$lime_sid'
|
||||
ORDER BY lq.parent_qid ASC, lq.question_order ASC";
|
||||
ORDER BY CASE WHEN lq2.question_order IS NULL THEN lq.question_order ELSE lq2.question_order + (lq.question_order / 1000) END ASC";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
@@ -264,23 +265,26 @@ if ($questionnaire_id != false)
|
||||
|
||||
if ($sgqa != false)
|
||||
{
|
||||
$sample_var = false;
|
||||
if (isset($_GET['sample_var']))
|
||||
$sample_var = $_GET['sample_var'];
|
||||
$sample_var_id = false;
|
||||
if (isset($_GET['sample_var_id']))
|
||||
$sample_var_id = $_GET['sample_var_id'];
|
||||
|
||||
print "<h3 class='form-inline pull-left'>" . T_("Select the sample variable to exclude") . ": </h3>";
|
||||
|
||||
$sql = "SELECT sv.var as value, sv.var as description, CASE WHEN sv.var LIKE '$sample_var' THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
FROM sample_var AS sv, sample AS s
|
||||
WHERE s.import_id = $sample_import_id
|
||||
AND s.sample_id = sv.sample_id
|
||||
GROUP BY sv.var";
|
||||
$sql = "SELECT sivr.var_id as value, sivr.var as description,
|
||||
CASE WHEN sivr.var_id = '$sample_var_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
FROM `sample_import_var_restrict` as sivr
|
||||
WHERE sivr.sample_import_id = '$sample_import_id'";
|
||||
|
||||
$rsv = $db->GetAll($sql);
|
||||
|
||||
$sample_var = $rsv[0]['description'];
|
||||
|
||||
display_chooser($db->GetAll($sql),"sample_var","sample_var",true,"questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id&sgqa=$sgqa",true,true,false,true,"pull-left");
|
||||
display_chooser($rsv,"sample_var_id","sample_var_id",true,"questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id&sgqa=$sgqa",true,true,false,true,"pull-left");
|
||||
|
||||
print "<div class='clearfix form-group'></div>";
|
||||
|
||||
if ($sample_var != false)
|
||||
if ($sample_var_id != false)
|
||||
{
|
||||
|
||||
print "<div class='col-sm-6 panel-body'><h3>" . T_("Enter the details for creating the row quota:") . "</h3>";
|
||||
@@ -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)
|
||||
?>
|
||||
</p>
|
||||
<input type="hidden" name="exclude_var" value="<?php print($sample_var); ?>"/>
|
||||
<input type="hidden" name="exclude_var_id" value="<?php print($sample_var_id); ?>"/>
|
||||
<input type="hidden" name="questionnaire_id" value="<?php print($questionnaire_id); ?>"/>
|
||||
<input type="hidden" name="sample_import_id" value="<?php print($sample_import_id); ?>"/>
|
||||
<input type="hidden" name="sgqa" value="<?php print($sgqa); ?>"/>
|
||||
|
||||
@@ -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 "<p class='well text-danger'>" . T_("No calls for this questionnaire") . "</p>";
|
||||
}
|
||||
|
||||
xhtml_foot();
|
||||
xhtml_foot("../js/custom.js");
|
||||
|
||||
?>
|
||||
|
||||
@@ -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). "</br>"; //ïîñìîòðèì ÷åãî îòðàâëÿåòñÿ
|
||||
|
||||
if (isset($_POST['del']) && isset($_POST['type']) ) {
|
||||
$a = array(); $b = array(); $cert = array(); $a = $_POST['type'];
|
||||
|
||||
//echo "<p> type before unset->>"; foreach($_POST['type'] as $key => $val) { echo ' | ', $key,' => ',$val,' | '; }; print "</p>";
|
||||
|
||||
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 "<div class='alert alert-danger'>", T_("Attention!! It's not recommended to delete string '$key'.</br> Please BE Careful and check again strings to delete."), "</div>";
|
||||
}
|
||||
/* else { echo "<div class='alert alert-info'>", T_("You can delete string '$key'. "), "</div>"; } */
|
||||
}
|
||||
//echo "<p>del ->>"; foreach($_POST['del'] as $key => $val) { echo ' | ', $key,' => ',$val,' | '; }; print "</p>";
|
||||
}
|
||||
|
||||
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, "</br>" ;
|
||||
|
||||
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 "<div class='alert alert-warning col-sm-6'>", T_(" String $p DELETED"), "</div>";
|
||||
|
||||
$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 "<div class='alert alert-warning col-sm-6'>", T_(" Sample_Var data for variable $p DELETED from this sample"), "</div>";
|
||||
}
|
||||
unset($_POST['del']);
|
||||
|
||||
$db->CompleteTrans();
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "<div class='alert alert-danger'>", T_("Smth wrong with selected field types. </br>Please check again var types selection and/or fields that you supposed to delete."), "</div>";
|
||||
//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 "<div class='alert alert-danger'>", T_("Sample $sample_import_id is still assigned to questionnaire. </br>Please unassign sample prior to delete."), "</div>";
|
||||
}
|
||||
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 "<div class='alert alert-warning'>", T_("Sample $sample_import_id was deleted."), "</div>"; }
|
||||
else {echo "<div class='alert alert-warning'>ERROR ".mysql_errno()." ".mysql_error()."\n</div>";}
|
||||
}
|
||||
|
||||
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 "<a href='?' class='btn btn-default' ><i class='fa fa-chevron-left fa-lg' style='color:blue;'></i> " . T_("Go back") . "</a>";
|
||||
$sample_import_id = intval($_GET['rename']);
|
||||
echo "<div class='col-sm-2'><a href='?' class='btn btn-default' ><i class='fa fa-chevron-left fa-lg' style='color:blue;'></i> " . T_("Go back") . "</a></div>";
|
||||
|
||||
$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('<input type=\"text\" onInput=\"$(this).attr(\'name\',\'var[',sir.var_id,']\');\" value=\"' ,sir.var, '\" required class=\"form-control\" style=\"min-width: 300px;\" $dis />') as var,
|
||||
CONCAT ('<select name=\"type[',sir.var_id,']\" class=\"form-control\" $dis >
|
||||
<option value=\"' ,svt.type, '\" $selected>' ,svt.description, '</option>";
|
||||
$selected = "selected=\"selected\"";
|
||||
foreach($rd as $r)
|
||||
{
|
||||
$sql .= "<option value=\"{$r['type']}\">" . T_($r['description']) . "</option>";
|
||||
}
|
||||
$sql .= "</select>') as type, sv.val,
|
||||
CONCAT('<input type=\'checkbox\' ', CASE WHEN (sir.restrict IS NULL || sir.restrict = 0) THEN 'checked=\"checked\"' ELSE '' END ,' name=\"see[]\" value=\'',sir.var_id,'\' data-toggle=\"toggle\" data-size=\"small\" data-style=\"center-block\" data-on=" . TQ_("Yes") . " data-off=" . TQ_("No") . " data-width=\"70\"/>') as see,
|
||||
CONCAT('<input type=\'checkbox\' name=\"del[',sir.var_id,']\" value=\'',sir.var_id,'\' $dis data-toggle=\"toggle\" data-size=\"small\" data-style=\"center-block\" data-on=" . TQ_("Yes") . " data-off=" . TQ_("No") . " data-width=\"70\" data-onstyle=\'danger \'/>') 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 "<h3>" . T_("Sample current description") . ": <span class='text-primary'>" . $rs . "</span></h3>";
|
||||
print "<div class='col-sm-8'><h3>" . T_("Sample") . ": " . $sd['description'] . " <small>ID <b> $sample_import_id</b> </small></h3></div>";
|
||||
print "<div class='col-sm-2'><a href='samplesearch.php?sample_import_id=$sample_import_id' class='btn btn-default' ><i class='fa fa-search fa-lg fa-fw text-primary'></i> " . T_("Search this sample") . "</a></div>";
|
||||
print "<div class='clearfix'></div>";
|
||||
|
||||
if($sd['enabled'] == 0){
|
||||
|
||||
?>
|
||||
<form action="?" method="post" class="form-group " >
|
||||
<div class="form-group">
|
||||
<h4 class="col-sm-3 control-label text-right" for="description"><?php echo T_("Enter")," ", T_("new")," ", T_("Description"), ":" ; ?></h4>
|
||||
<div class="col-sm-4"><input type='text' name='description' class="form-control" value="<?php echo $rs;?>"/></div>
|
||||
<h4 class="col-sm-3 control-label text-right" for="description"><?php echo T_("Enter")," ", T_("new")," ", T_("Description"),":" ; ?></h4>
|
||||
<div class="col-sm-4"><input type='text' name='description' class="form-control" value="<?php echo $sd['description'];?>" <?php echo $dis ;?>/></div>
|
||||
</div>
|
||||
<div><input type='hidden' name='sample_import_id' value='<?php echo $sample_import_id;?>'/></div>
|
||||
<div><button type="submit" name="submitr" class="btn btn-default"><i class="fa fa-edit fa-lg fa-fw text-primary"></i> <?php echo T_("Rename");?></button></div>
|
||||
<div><button type="submit" name="ren" class="btn btn-default"><i class="fa fa-edit fa-lg fa-fw text-primary"></i> <?php echo T_("Rename");?></button></div>
|
||||
</form>
|
||||
<?php
|
||||
xhtml_foot();
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($_GET['view']))
|
||||
{
|
||||
$subtitle=T_("Operator viewing permissions");
|
||||
xhtml_head(T_("Sample management"),true,$css,$js_head,false,false,false,$subtitle);
|
||||
|
||||
echo "<a href='?' class='btn btn-default' ><i class='fa fa-chevron-left fa-lg' style='color:blue;'></i> " . T_("Go back") . "</a>";
|
||||
|
||||
$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('<input type=\'checkbox\' ', CASE WHEN (sir.restrict IS NULL || sir.restrict = 0) THEN 'checked=\"checked\"' ELSE '' END ,' name=\'',sv.var,'\' value=\'11\' data-toggle=\"toggle\" data-size=\"small\" data-style=\"center-block\" data-on=" . TQ_("Yes") . " data-off=" . TQ_("No") . " data-width=\"70\"/>') 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 "<h3>" . T_("Operator viewing permissions") . " ". T_("for") . " " . T_("sample") . ": " . $rs[0]['description'] . "</h3>";
|
||||
if (!$rs) print "<div class='alert alert-info col-sm-6' role='alert'><h4>" . T_("There's no data in this sample. ") . "</h4></div>";
|
||||
else {
|
||||
print "<div class='alert alert-info' role='alert'><p>" . T_("Select which fields from this sample should be able to be viewed by operators") . "</p></div>
|
||||
<form action='?' method='post' class='form-group form-horisontal'>";
|
||||
xhtml_table($rs,array("var","val","box"),array(T_("Field"),T_("Example data"),T_("Allow operator to see?")));
|
||||
?>
|
||||
<div><input type='hidden' name='sample_import_id' value='<?php echo $sample_import_id;?>'/></div></br>
|
||||
<div class="col-md-offset-4"><button type="submit" name="submitvp" class="btn btn-default"> <i class="fa fa-eye fa-lg fa-fw text-primary"></i> <?php echo T_("Save changes");?></button></div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
}
|
||||
xhtml_foot();
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($_GET['edit']))
|
||||
{
|
||||
$subtitle=T_("Delete sample variables") ;
|
||||
xhtml_head(T_("Sample management"),true,$css,$js_head,false,false,false,$subtitle);
|
||||
|
||||
echo "<a href='?' class='btn btn-default' ><i class='fa fa-chevron-left fa-lg' style='color:blue;'></i> " . T_("Go back") . "</a>";
|
||||
|
||||
$sample_import_id = intval($_GET['edit']);
|
||||
|
||||
$sql = "SELECT si.description, sv.val, sv.var,
|
||||
CONCAT('<input type=\'checkbox\' name=\'',sv.var,'\' value=\'',sv.var,'\' data-toggle=\"toggle\" data-size=\"small\" data-style=\"center-block\" data-on=" . TQ_("Yes") . " data-off=" . TQ_("No") . " data-width=\"70\" data-onstyle=\'danger\'/>') 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 "<h3>" . T_("Sample") . ": " . $rs[0]['description'] . "</h3>";
|
||||
|
||||
if ($rs){
|
||||
print "<div class='alert alert-danger' role='alert'><p>" . T_("Select which fields from this sample to deidentify. Deidentified fields will be permanently deleted from the sample.") . "</p></div>";
|
||||
|
||||
?>
|
||||
<form action="?" method="post">
|
||||
<form action="?" method="post" class="col-sm-9 form-group">
|
||||
<?php
|
||||
xhtml_table($rs,array("var","val","box"),array(T_("Field"),T_("Example data"),T_("Delete")));
|
||||
xhtml_table($rs,array("var_id","var","see","type","val","del"),array(T_("ID"),T_("Sample variable (Column)"),T_("Visible?"),T_("Var type"),T_("Example data"),T_("Delete ?")));
|
||||
?>
|
||||
<div><input type='hidden' name='sample_import_id' value='<?php echo $sample_import_id;?>'/></div>
|
||||
</br>
|
||||
<div class="col-md-offset-3"><button type="submit" name="submit" class="btn btn-danger"> <i class="fa fa-trash-o fa-lg fa-fw "></i> <?php echo T_("Delete selected fields");?></button></div>
|
||||
<div class="col-sm-6"><button type="submit" name="ed" class="btn btn-primary pull-right"> <i class="fa fa-floppy-o fa-lg fa-fw "></i> <?php echo T_("Save changes");
|
||||
/* if($sd['enabled'] == 0){ ?>
|
||||
</button></div>
|
||||
<div class="col-sm-6 "><button type="submit" name="del__" class="btn btn-danger pull-right"> <i class="fa fa-trash-o fa-lg fa-fw "></i> <?php echo T_("Delete var fields");
|
||||
} */?>
|
||||
</button></div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
<?php
|
||||
|
||||
print "<div class='well text-danger col-sm-3'><p>" . T_("Select which fields from this sample to deidentify. </p> Deidentified fields will be permanently deleted from the sample.") . "</p></div>";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<div class='alert alert-info col-sm-6' role='alert'><h4>" . T_("There's no data in this sample. Probably was deidentified earlier.") . "</h4></div>";
|
||||
print "<div class='alert alert-info' role='alert'><h4>" . T_("There's no data in this sample. Probably was deidentified earlier.") . "</h4></div>";
|
||||
|
||||
/*check `Time_zone_name` and `phone` values for deidentified records*/
|
||||
$sql = "SELECT `sample`.sample_id FROM `sample`
|
||||
LEFT JOIN `sample_var` ON (`sample`.sample_id = `sample_var`.sample_id)
|
||||
WHERE `sample_var`.sample_id IS NULL
|
||||
AND `sample`.import_id = $sample_import_id
|
||||
AND (`sample`.Time_zone_name !='' || `sample`.phone !='')";
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
if (!empty($rs)) {
|
||||
$num = count($rs);
|
||||
print "<div class='well text-danger '><p>" . T_("There're still $num records for `Time_zone_name` and `phone` values for deidentified records") . "</p>";
|
||||
|
||||
print "<form method='POST'><button type='submit' name='dtzph' class='btn btn-danger '> <i class='fa fa-trash-o fa-lg fa-fw '></i> " . T_("Clean it") . "?</button></form></div>";
|
||||
}
|
||||
|
||||
}
|
||||
xhtml_foot();
|
||||
|
||||
unset ($rs);
|
||||
|
||||
/*check if there's sample_var data not matching sample_import_var_restrict.var_id */
|
||||
$sql = "SELECT `sv`.var_id, `sv`.var, `sv`.type FROM `sample_var` as sv
|
||||
LEFT JOIN `sample_import_var_restrict` as sivr ON (`sivr`.var_id = `sv`.var_id)
|
||||
WHERE `sivr`.var_id IS NULL
|
||||
AND `sv`.sample_id IN (SELECT sample_id FROM `sample` WHERE import_id = $sample_import_id)
|
||||
GROUP BY `sv`.var_id";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
if (!empty($rs)) {
|
||||
$count = count($rs);
|
||||
//print_r($rs);
|
||||
print "<div class='well text-danger col-sm-3'><p>" . T_("Fix this sample ") . "</p>";
|
||||
print "<p>" . $count . " var id's not match</p>";
|
||||
|
||||
/* print "<div class=' '><form method='POST'>
|
||||
<button type='submit' name='restore___' class='btn btn-default pull-left'> <i class='fa fa-reload-o fa-lg fa-fw '></i> " . T_("Restore vars") . "</button>
|
||||
<button type='submit' name='delvarf___' class='btn btn-danger pull-right'> <i class='fa fa-trash-o fa-lg fa-fw '></i> " . T_("Delete vars") . "</button>
|
||||
|
||||
</form></div>"; */
|
||||
print "</div>";
|
||||
|
||||
/* if (isset($_POST['restore___'])){
|
||||
$sql = "INSERT INTO sample_import_var_restrict
|
||||
(`sample_import_id`,`var_id`,`var`,`type`,`restrict`)
|
||||
VALUES ($sample_import_id,' ',' ',' ',1)";
|
||||
|
||||
$db->Execute($sql);
|
||||
unset($_POST['restore___']);
|
||||
}
|
||||
if (isset($_POST['delvarf___'])){
|
||||
$sql = "";
|
||||
|
||||
$db->Execute($sql);
|
||||
unset($_POST['delvarf___']);
|
||||
} */
|
||||
|
||||
unset($rs);
|
||||
}
|
||||
|
||||
if (isset($_POST['dtzph'])){
|
||||
|
||||
/*delete `Time_zone_name` and `phone` values for deidentified records*/
|
||||
$db->StartTrans();
|
||||
|
||||
$sql = "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
|
||||
AND `sample`.import_id = $sample_import_id";
|
||||
$db->Execute($sql);
|
||||
|
||||
unset($_POST['dtzph']);
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
xhtml_foot($js_foot);
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -281,17 +472,22 @@ $sql = "SELECT
|
||||
END
|
||||
as enabledisable,
|
||||
CASE WHEN enabled = 1 THEN
|
||||
CONCAT('<a href=\'?edit=',sample_import_id,'\' class=\'btn btn-default disabled\'><i class=\'fa fa-minus-circle fa-lg fa-fw\' style=\'color:grey;\'></i></a>')
|
||||
CONCAT('<a href=\'?edit=',sample_import_id,'\' class=\'btn btn-default btn-block\' data-toggle=\'tooltip\' title=\'" . TQ_("Edit") ." " . TQ_("Viewing permissions") . "\'><i class=\'fa fa-eye fa-lg fa-fw \'></i></a>')
|
||||
ELSE
|
||||
CONCAT('<a href=\'?edit=',sample_import_id,'\' class=\'btn btn-default \' data-toggle=\'tooltip\' title=\'" . TQ_("Deidentify") . "\'><i class=\'fa fa-minus-circle fa-lg fa-fw text-danger \'></i></a>')
|
||||
CONCAT('<a href=\'?edit=',sample_import_id,'\' class=\'btn btn-default \' data-toggle=\'tooltip\' title=\'" . TQ_("Edit sample parameters") . "\'><i class=\'fa fa-eye fa-lg fa-fw text-primary\'></i> + <i class=\'fa fa-edit fa-lg fa-fw text-primary\'></i> + <i class=\'fa fa-minus-circle fa-lg fa-fw text-danger \'></i></a>')
|
||||
END as did,
|
||||
CONCAT('<a href=\'?view=',sample_import_id,'\' class=\'btn btn-default\' data-toggle=\'tooltip\' title=\'" . TQ_("Viewing permissions") . "\'><i class=\'fa fa-eye fa-lg fa-fw text-primary\'></i></a>') as vp,
|
||||
CONCAT('<a href=\'?rename=',sample_import_id,'\' class=\'btn btn-default\' data-toggle=\'tooltip\' title=\'" . TQ_("Rename") . "\'><i class=\'fa fa-edit fa-lg fa-fw text-primary\'></i></a>') as rname,
|
||||
CASE WHEN enabled = 1 THEN
|
||||
CONCAT('<a href=\'\' class=\'btn btn-default disabled\'><i class=\'fa fa-trash fa-lg fa-fw\' style=\'color:grey;\'></i></a>')
|
||||
ELSE
|
||||
CONCAT('<a href=\'\' class=\'btn btn-default \' data-toggle=\'confirmation\' data-href=\'?delete_sample=',sample_import_id,'\' data-title=\'" . TQ_("ARE YOU SHURE?") . "\' data-btnOkLabel=\'" . TQ_("Yes") . "\' data-btnCancelLabel=\'" . TQ_("Cancel") . "\' ><i class=\'fa fa-trash fa-lg fa-fw text-danger \' data-toggle=\'tooltip\' title=\'" . TQ_("DELETE SAMPLE") . "\'></i></a>')
|
||||
END as delsample,
|
||||
CONCAT('<a href=\'samplesearch.php?sample_import_id=',sample_import_id,'\' class=\'btn btn-default\' data-toggle=\'tooltip\' title=\'" . TQ_("Search the sample") . "',sample_import_id,'\'><i class=\'fa fa-search fa-lg fa-fw text-primary\'></i></a>') as ssearch,
|
||||
CONCAT('<a href=\'callhistory.php?sample_import_id=',sample_import_id,'\' class=\'btn btn-default\' data-toggle=\'tooltip\' title=\'" . TQ_("Call history"). " \n" . TQ_("sample"). " ',sample_import_id,'\'><i class=\'fa fa-phone fa-lg text-primary\'></i></a>') as calls,
|
||||
CONCAT('<h4>',description,' </h4>') as description
|
||||
FROM sample_import";
|
||||
$rs = $db->GetAll($sql);
|
||||
CONCAT('<h4>',description,' </h4>') as description,
|
||||
CONCAT('<h4 class=\'fa fa-lg text-primary pull-right\'>',(SELECT COUNT( DISTINCT`sample_var`.sample_id) FROM `sample_var`, `sample` WHERE `sample`.sample_id = `sample_var`.sample_id AND `sample`.import_id = sample_import_id ),' </h4>') as cnt
|
||||
FROM sample_import ORDER BY sample_import_id DESC";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
$subtitle=T_("Sample list");
|
||||
xhtml_head(T_("Sample management"),true,$css,$js_head,false,false,false,$subtitle);
|
||||
@@ -299,12 +495,12 @@ echo "<div class='form-group'>
|
||||
<a href='' onclick='history.back();return false;' class='btn btn-default'><i class='fa fa-chevron-left fa-lg text-primary'></i> " . T_("Go back") . "</a>
|
||||
<a href='import.php' class='btn btn-default col-sm-offset-4' ><i class='fa fa-upload fa-lg'></i> " . T_("Import a sample file") . "</a>
|
||||
</div>";
|
||||
$columns = array("id","description","status","enabledisable","calls","did","vp","rname", "ssearch");
|
||||
$columns = array("id","description","cnt","status","enabledisable","calls","did","ssearch","delsample"); //"vp","rname",
|
||||
//$titles = array(T_("ID"),T_("Sample"), T_("Call History"),T_("Enable/Disable"), T_("Status"), T_("Deidentify"), T_("View"), T_("Rename"), T_("Search"));
|
||||
xhtml_table($rs,$columns, false, "table-hover table-condensed ");
|
||||
|
||||
xhtml_foot($js_foot);
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$('[data-toggle="confirmation"]').confirmation()
|
||||
$('[data-toggle="confirmation"]').confirmation();
|
||||
</script>
|
||||
@@ -156,25 +156,25 @@ if ($sample_import_id != false)
|
||||
$fnames[] = "link";
|
||||
$fdesc[] = T_("Case ID");
|
||||
|
||||
$sql = "SELECT var
|
||||
FROM sample_var
|
||||
WHERE sample_id = {$r[0]['sample_id']}
|
||||
$sql = "SELECT var,var_id
|
||||
FROM sample_import_var_restrict
|
||||
WHERE sample_import_id = $sample_import_id
|
||||
ORDER by var ASC";
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
foreach($rs as $rsw)
|
||||
{
|
||||
$fnames[] = $rsw['var'];
|
||||
$fnames[] = $rsw['var_id'];
|
||||
$fdesc[] = $rsw['var'];
|
||||
}
|
||||
foreach($r as &$rw)
|
||||
{
|
||||
$sql = "SELECT var,val
|
||||
$sql = "SELECT var_id,val
|
||||
FROM sample_var
|
||||
WHERE sample_id = {$rw['sample_id']}";
|
||||
$rs = $db->GetAll($sql);
|
||||
foreach($rs as $rsw){
|
||||
$rw[$rsw['var']] = $rsw['val'];
|
||||
$rw[$rsw['var_id']] = $rsw['val'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ if ($case_id != false)
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
$sql = "SELECT o.description,o.outcome_id, q.description as qd, si.description as sd
|
||||
$sql = "SELECT o.description,o.outcome_id, q.description as qd, si.description as sd, s.import_id as sid
|
||||
FROM `case` as c, `outcome` as o, questionnaire as q, sample as s, sample_import as si
|
||||
WHERE c.case_id = '$case_id'
|
||||
AND q.questionnaire_id = c.questionnaire_id
|
||||
@@ -299,11 +299,12 @@ if ($case_id != false)
|
||||
<h2 class=''>". T_("Current outcome:") ."<span class='text-info'> " . T_($rs['description']) . "</span></h2>";
|
||||
|
||||
$current_outcome_id = $rs['outcome_id'];
|
||||
$sid = $rs['sid'];
|
||||
|
||||
// view sample details
|
||||
print "<div class='panel-body'><h4 class=''><i class='fa fa-book'></i> " . T_("Sample details")."</h4>";
|
||||
|
||||
$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'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
15
email.php
15
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);
|
||||
|
||||
@@ -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)
|
||||
<td><input type=\"text\" value=\"$val\" name=\"n_$row\" class=\"form-control\" /></td>
|
||||
<td>";
|
||||
print "<select name=\"t_$row\" class=\"form-control\">";
|
||||
print "<option value=\"\" $selected></option>";
|
||||
//print "<option value=\"\" $selected></option>";
|
||||
$selected = "selected=\"selected\"";
|
||||
foreach($rs as $r)
|
||||
{
|
||||
print "<option value=\"{$r['type']}\" >" . T_($r['description']) . "</option>";
|
||||
print "<option value=\"{$r['type']}\" $selected>" . T_($r['description']) . "</option>";
|
||||
$selected = "";
|
||||
}
|
||||
print "</select></td>";
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 <adam.zammit@acspri.org.au>
|
||||
* @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);
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -267,13 +267,13 @@ $quexsfilterstate = questionnaireSampleFilterstate();
|
||||
."<option value='shiftr' id='shiftr' />".T_("Shift report")."</option>\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);
|
||||
}
|
||||
?>
|
||||
?>
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
51
referral.php
51
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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
76
sample var update and fix.txt
Normal file
76
sample var update and fix.txt
Normal file
@@ -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*
|
||||
Reference in New Issue
Block a user