diff --git a/admin/quotarow.php b/admin/quotarow.php index 0b6393c0..1d16dfc6 100755 --- a/admin/quotarow.php +++ b/admin/quotarow.php @@ -103,7 +103,7 @@ if (isset($_POST['submitexport'])) $q2 = $db->GetAll($sql); - $sql = "SELECT exclude_var as samplerecord,comparison,exclude_val as value + $sql = "SELECT exclude_var_id, exclude_var as samplerecord,comparison,exclude_val as value FROM qsqr_sample WHERE questionnaire_sample_quota_row_id = $tmp"; @@ -248,12 +248,15 @@ if (isset($_GET['qsqri']) & isset($_GET['edit'])) if (isset($_POST['adds'])) { - $comparison = $db->qstr($_POST['comparisons']); - $exvar = $db->qstr(substr($_POST['sample_var'],12,strpos($_POST['sample_var'],'&')-12)); + $exvar_id = $db->qstr(substr($_POST['sample_var_id'],15,strpos($_POST['sample_var_id'],'&')-15)); + $exvar = $db->qstr($_POST['sample_var']); $exval = $db->qstr($_POST['exclude_val']); + $comparison = $db->qstr($_POST['comparisons']); + $description = $db->qstr($_POST['description']); + //add ssample - $sql = "INSERT INTO qsqr_sample (questionnaire_sample_quota_row_id,exclude_var,exclude_val,comparison) - VALUES ($qsqri,$exvar,$exval,$comparison)"; + $sql = "INSERT INTO qsqr_sample (questionnaire_sample_quota_row_id,exclude_var_id,exclude_var,exclude_val,comparison,description) + VALUES ($qsqri,$exvar_id,$exvar,$exval,$comparison,$description)"; $db->Execute($sql); @@ -263,12 +266,13 @@ if (isset($_GET['qsqri']) & isset($_GET['edit'])) if (isset($_POST['addq'])) { - $comparison = $db->qstr($_POST['comparison']); - $value = $db->qstr($_POST['value']); $sgqa = $db->qstr(substr($_POST['sgqa'],6,strpos($_POST['sgqa'],'&')-6)); + $value = $db->qstr($_POST['value']); + $comparison = $db->qstr($_POST['comparison']); + $description = $db->qstr($_POST['description']); //add ssample - $sql = "INSERT INTO qsqr_question (questionnaire_sample_quota_row_id,lime_sgqa,value,comparison) - VALUES ($qsqri,$sgqa,$value,$comparison)"; + $sql = "INSERT INTO qsqr_question (questionnaire_sample_quota_row_id,lime_sgqa,value,comparison,description) + VALUES ($qsqri,$sgqa,$value,$comparison,$description)"; $db->Execute($sql); @@ -280,7 +284,7 @@ if (isset($_GET['qsqri']) & isset($_GET['edit'])) $questionnaire_id = false; if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']); -xhtml_head(T_("Quota row management"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../include/bootstrap-toggle/css/bootstrap-toggle.min.css","../css/custom.css"),array("../js/jquery-2.1.3.min.js","../include/bootstrap-toggle/js/bootstrap-toggle.min.js","../js/window.js")); +xhtml_head(T_("Quota row management"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../include/bootstrap-toggle/css/bootstrap-toggle.min.css","../include/font-awesome-4.3.0/css/font-awesome.css","../include/iCheck/skins/square/blue.css","../css/custom.css"),array("../js/jquery-2.1.3.min.js","../include/bootstrap-toggle/js/bootstrap-toggle.min.js","../include/iCheck/icheck.min.js","../js/window.js")); print "

" . T_("Questionnaire") . ": 

"; $sql = "SELECT questionnaire_id as value,description, CASE WHEN questionnaire_id = '$questionnaire_id' THEN 'selected=\'selected\'' ELSE '' END AS selected @@ -293,8 +297,6 @@ if ($questionnaire_id != false) { $sample_import_id = false; if (isset($_GET['sample_import_id'])) $sample_import_id = bigintval($_GET['sample_import_id']); - - print "

" . T_("Select a sample from the list below") . "

"; $sql = "SELECT s.sample_import_id as value,s.description, CASE WHEN s.sample_import_id = '$sample_import_id' THEN 'selected=\'selected\'' ELSE '' END AS selected FROM sample_import as s, questionnaire_sample as q @@ -323,10 +325,10 @@ if ($questionnaire_id != false) if (count($data) > 2) { //one quota record per row - $completions = intval($data[1]); + $description = $db->quote($data[0]); + $completions = intval($data[1]); $autoprioritise = 0; if ($data[2] != 0) $autoprioritise = 1; - $description = $db->quote($data[0]); $sql = "INSERT INTO questionnaire_sample_quota_row(questionnaire_id, sample_import_id, completions, description, priority, autoprioritise) VALUES ($questionnaire_id, $sample_import_id, $completions, $description, 50, $autoprioritise)"; @@ -355,12 +357,13 @@ if ($questionnaire_id != false) else { //is a sample variable - $comparison = $db->qstr($data[($i*3) + 1]); - $value = $db->qstr($data[($i*3) + 2]); - $var = $db->qstr($data[$i*3]); + $var_id = $db->qstr($data[$i*3]); + $var = $db->qstr($data[($i*3) + 1]); + $comparison = $db->qstr($data[($i*3) + 2]); + $value = $db->qstr($data[($i*3) + 3]); - $sql = "INSERT INTO qsqr_sample (questionnaire_sample_quota_row_id,exclude_var,exclude_val,comparison) - VALUES ($qq,$var,$value,$comparison)"; + $sql = "INSERT INTO qsqr_sample (questionnaire_sample_quota_row_id,exclude_var_id,exclude_var,exclude_val,comparison) + VALUES ($qq,$var_id,$var,$value,$comparison)"; $db->Execute($sql); } @@ -375,23 +378,22 @@ if ($questionnaire_id != false) } } - - if ($qsqri != false) { + print "

 " . T_("Go back") . "

"; print "

" . T_("Quota") . ": $qsqrid

"; - print "

" . T_("Go back") . "

"; - + ?> -
" method="post"> -

-
-
- />
-
+

+ " method="post" class="form-inline table"> +

+

+

+

data-toggle="toggle" data-on="" data-off="" data-offstyle="warning"/>

- "/>

+

+
" . TQ_("Delete") . "') as qdelete FROM qsqr_question WHERE questionnaire_sample_quota_row_id = $qsqri"; - - + $rs = $db->GetAll($sql); - + + print "
"; + print "

" . T_("Restrictions based on answered questions") . "

"; + print "
"; + if (empty($rs)) { - print "

" . T_("All completed responses that match the sample criteria below will be counted towards the quota") . "

"; + print "

" . T_("Currently NO Restrictions based on answered questions") . "

" . T_("All completed responses that match the sample criteria below will be counted towards the quota") . "

"; } else { - print "

" . T_("Only completed responses that have answered the following will be counted") . "

"; - xhtml_table($rs,array('lime_sgqa','comparison','value','qdelete'),array(T_("Question"),T_("Comparison"),T_("Value"),T_("Delete"))); + print "

" . T_("Only completed responses that have answered the following will be counted") . "

"; + xhtml_table($rs,array('description','lime_sgqa','comparison','value','qdelete'),array(T_("Description"),T_("SGQ code"),T_("Comparison"),T_("Value"),T_("Delete"))); + print "
"; } //add questionnaire references if any (refer to sample only or count completions based on responses to questions) @@ -426,101 +432,138 @@ if ($questionnaire_id != false) $ssgqa = $db->qstr($_GET['sgqa']); //select question - $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 $ssgqa LIKE CONCAT( lq.sid, 'X', lq.gid, 'X', CASE WHEN lq.parent_qid = 0 THEN lq.qid ELSE CONCAT(lq.parent_qid, lq.title) END) 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, CONCAT( lq.sid, 'X', lq.gid, 'X', CASE WHEN lq.parent_qid = 0 THEN lq.qid ELSE CONCAT(lq.parent_qid, lq.title) END, ' -> ' , CASE WHEN lq.parent_qid = 0 THEN lq.question ELSE CONCAT(lq2.question, ' : ', lq.question) END) as description, CASE WHEN $ssgqa LIKE CONCAT( lq.sid, 'X', lq.gid, 'X', CASE WHEN lq.parent_qid = 0 THEN lq.qid ELSE CONCAT(lq.parent_qid, lq.title) END) 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 g.group_order 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); + $rsgqa = $db->GetAll($sql); - if (!empty($rs)) + if (!empty($rsgqa)) { - print "
"; - print "

" . T_("Add restriction based on answered questions") . "

"; - print ""; - display_chooser($rs,"sgqa","sgqa",false,"edit=edit&qsqri=$qsqri",true,false); + print "
"; + print "

" . T_("Add restriction based on answered questions") . "

"; + print ""; + display_chooser($rsgqa,"sgqa","sgqa",true,"edit=edit&qsqri=$qsqri"); + + if (isset($_GET['sgqa'])){ ?> -

-
- "/> - +
+

+

+ +

+

+

+

" . T_("Code values for this question") . ": 

"; + + $rs = ""; + if (isset($_GET['sgqa'])) + { + $sgqa = $_GET['sgqa']; + $qid = explode("X", $sgqa); + $qid = $qid[2]; + + $sql = "SELECT CONCAT(' ', l.code , '')as code, l.answer as title + FROM `" . LIME_PREFIX . "answers` as l + WHERE l.qid = '$qid'"; + $rsc = $db->GetAll($sql); + } + if (!isset($rsc) || empty($rsc)) + print "

" . T_("No labels defined for this question") ."

"; + else + xhtml_table($rsc,array('code','title'),array(T_("Code value"), T_("Description"))); + } + else { print ""; } + print "
"; } - + print "
"; + //list sample records to exclude - $sql = "SELECT qsqr_sample_id,exclude_var,exclude_val,comparison,description, - CONCAT('" . TQ_("Delete") . "') as sdelete + $sql = "SELECT qsqr_sample_id,exclude_var_id,exclude_var,exclude_val,comparison,description, + CONCAT(' " . TQ_("Delete") . "') as sdelete FROM qsqr_sample WHERE questionnaire_sample_quota_row_id = $qsqri"; $rs = $db->GetAll($sql); - + + print "
"; + print "

" . T_("Restrictions based on sample records") . "

"; + print "
"; if (empty($rs)) { - print "

" . T_("All sample records will be excluded") . "

"; + print "

" . T_("Currently NO Restrictions based on sample records") . "

" . T_("This sample will be limited to number of competions set in quota") . "

" . T_("Caling cases for this sample will be stopped when the quota is reached") . "

"; } else { - print "

" . T_("Completed responses that have the following sample details will be counted towards the quota and excluded when the quota is reached") . "

"; - xhtml_table($rs,array('exclude_var','comparison','exclude_val','sdelete'),array(T_("Sample record"),T_("Comparison"),T_("Value"),T_("Delete"))); + print "

" . T_("Completed responses that have the following sample details will be counted towards the quota and excluded when the quota is reached") . "

"; + xhtml_table($rs,array('description','exclude_var_id','exclude_var','comparison','exclude_val','sdelete'),array(T_("Description"),T_("Sample var ID"),T_("Sample variable"),T_("Comparison"),T_("Value"),T_("Delete"))); + print "
"; } - - $ssample_var = "''"; - if (isset($_GET['sample_var'])) - $ssample_var = $db->qstr($_GET['sample_var']); + $ssample_var_id = "''"; + if (isset($_GET['sample_var_id'])) $ssample_var_id = $db->qstr($_GET['sample_var_id']); //add sample references (records from sample to exclude when quota reached) - $sql = "SELECT sv.var as value, sv.var as description, CASE WHEN sv.var LIKE $ssample_var THEN 'selected=\'selected\'' ELSE '' END AS selected - FROM sample_var AS sv, sample AS s - WHERE s.import_id = $sample_import_id + $sql = "SELECT sivr.var_id as value, sivr.var as description, + CASE WHEN sivr.var_id = $ssample_var_id THEN 'selected=\'selected\'' ELSE '' END AS selected + FROM `sample_import_var_restrict` as sivr, `sample_var` AS sv, `sample` AS s + WHERE sivr.sample_import_id = $sample_import_id AND s.sample_id = sv.sample_id - GROUP BY sv.var"; + AND sivr.var_id = sv.var_id + GROUP BY sivr.var_id"; - $rs = $db->GetAll($sql); + $rsvi = $db->GetAll($sql); - if (!empty($rs)) + if (!empty($rsvi)) { - if ($ssample_var == "''") - $ssample_var = "'" . $rs[0]['value']. "'"; + if ($ssample_var_id == "''") + $ssample_var_id = $rsvi[0]['value']; - print "

" . T_("Add restriction based on sample records") . "

"; - print "
"; - print ""; - display_chooser($rs,"sample_var","sample_var",false,"edit=edit&qsqri=$qsqri",true,false); - ?> -

- - GetAll($sql),"exclude_val","exclude_val",false,false,false,false); - flush(); - ?> -
"/> -
+ print "

" . T_("Add restriction based on sample records") . "

"; + print "
"; + print "

: "; + display_chooser($rsvi,"sample_var_id","sample_var_id",true,"edit=edit&qsqri=$qsqri",true,false); + + if (isset($_GET['sample_var_id'])){ + ?> + +  :   + + GetAll($sql); + $sample_var = $val[0]['var']; + display_chooser($val,"exclude_val","exclude_val",false,false,false,false); + flush(); + ?> +  

+

+ + "/> ";} + print "
"; } + print "
"; } else { - - - print "

" . T_("Current row quotas (click to edit)") . "

"; - - - $sql = "SELECT questionnaire_sample_quota_row_id,qsq.description, + $sql = "SELECT questionnaire_sample_quota_row_id,qsq.description, CONCAT('', qsq.description, '') as qedit, - CONCAT('') as qselect, + CONCAT('
') as qselect, qsq.completions,qsq.quota_reached,qsq.current_completions, CASE WHEN qsq.autoprioritise = 1 THEN '" . TQ_("Yes") . "' ELSE '" . TQ_("No") . "' END AS ap, qsq.priority, CASE WHEN qsq.quota_reached = 1 THEN '" . TQ_("closed") . "' ELSE '" . TQ_("open") . "' END AS status @@ -528,48 +571,58 @@ if ($questionnaire_id != false) WHERE qsq.questionnaire_id = '$questionnaire_id' AND qsq.sample_import_id = '$sample_import_id' AND q.questionnaire_id = '$questionnaire_id'"; - $r = $db->GetAll($sql); - print "
"; if (empty($r)) { - print "

" . T_("Currently no row quotas") . "

"; + print "

" . T_("Currently no row quotas") . "

"; } else { - xhtml_table($r,array('qedit','completions','current_completions','status','priority','ap','qselect'),array(T_("Description"),T_("Quota"),T_("Completions"),T_("Status"),T_("Priority"),T_("Auto prioritise"),T_("Select"))); - print ""; - print ""; - - //select sample - + print ""; + print "

" . T_("Current row quotas (click to edit)") . "

"; + xhtml_table($r,array('qedit','completions','current_completions','status','priority','ap','qselect'),array(T_("Description"),T_("Quota"),T_("Completions"),T_("Status"),T_("Priority"),T_("Auto prioritise"),T_("Select"))); + print "

"; + print "

"; + print "
"; + print "
"; } - print ""; - print "

" . T_("Add row quota") . "

"; - ?> -
" method="post"> -

-
-
-
-
- "/>

-
- " . T_("Import row quota") . ""; + print "

" . T_("Add row quota") . "

"; ?> -
" method="post"> -

-

-

"/>

-
+
" method="post" class="form-inline table"> +

+

+

+

" data-off="" data-offstyle="warning"/>

+

"/>

+
+
+

" . T_("Import row quota") . "

"; +$ua = $_SERVER['HTTP_USER_AGENT']; +if (preg_match('/Firefox/i', $ua)) $csv= "text/csv"; else $csv= ".csv"; + ?> +
" method="post"> + +

+

..." accept=""/>

+ +
+ + + \ No newline at end of file