From f6a2f0d5d7940162be38d529f6ae85251e22c4ba Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Fri, 11 Sep 2015 11:08:00 +1000 Subject: [PATCH 1/4] Updated database structure --- CHANGELOG | 2 ++ database/quexs.sql | 1 + 2 files changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 9e138199..a0e4d362 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -52,6 +52,8 @@ WHERE 1; /* Remove redundant table */ DROP TABLE `sessions2`; +/* Add sort order feature to questionnaire sample table */ +ALTER TABLE `questionnaire_sample` ADD `sort_order` INT( 11 ) NOT NULL DEFAULT '0'; queXS 1.13.1 - Changes since 1.13.0 diff --git a/database/quexs.sql b/database/quexs.sql index b5995636..166480a5 100644 --- a/database/quexs.sql +++ b/database/quexs.sql @@ -1263,6 +1263,7 @@ CREATE TABLE `questionnaire_sample` ( `random_select` tinyint(1) NOT NULL DEFAULT '0', `answering_machine_messages` int(11) NOT NULL DEFAULT '1', `allow_new` tinyint(1) NOT NULL DEFAULT '1', + `sort_order` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`questionnaire_id`,`sample_import_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; From 338f50c6b6f25589eda246cca68c0b33ca389ba3 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Fri, 11 Sep 2015 12:04:24 +1000 Subject: [PATCH 2/4] Added sorting of samples to front end --- admin/assignsample.php | 108 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 8 deletions(-) diff --git a/admin/assignsample.php b/admin/assignsample.php index d4522b5a..eb6a5f6c 100644 --- a/admin/assignsample.php +++ b/admin/assignsample.php @@ -93,8 +93,14 @@ if (isset($_GET['questionnaire_id']) && isset($_GET['sample']) && isset($_GET[' $an = 0; if (isset($_GET['allownew'])) $an = 1; - $sql = "INSERT INTO questionnaire_sample(questionnaire_id,sample_import_id,call_max,call_attempt_max,random_select,answering_machine_messages,allow_new) - VALUES('$questionnaire_id','$sid','$cm','$cam','$selecttype','$am', '$an')"; + $sql = "SELECT MAX(sort_order) + 1 + FROM questionnaire_sample + WHERE questionnaire_id = '$questionnaire_id'"; + + $so = $db->GetOne($sql); + + $sql = "INSERT INTO questionnaire_sample(questionnaire_id,sample_import_id,call_max,call_attempt_max,random_select,answering_machine_messages,allow_new,sort_order) + VALUES('$questionnaire_id','$sid','$cm','$cam','$selecttype','$am', '$an', '$so')"; $db->Execute($sql); @@ -176,7 +182,6 @@ if (isset($_POST['edit'])) } - if (isset($_GET['questionnaire_id']) && isset($_GET['rsid'])) { $questionnaire_id = bigintval($_GET['questionnaire_id']); @@ -239,7 +244,67 @@ if (isset($_GET['questionnaire_id']) && isset($_GET['rsid'])) GetRow($sql); + + $ssid = $rs['sample_import_id']; + $sso = $rs['sort_order']; + + $sql = "UPDATE questionnaire_sample + SET sort_order = $sso + WHERE sample_import_id = $sid + AND questionnaire_id = $questionnaire_id"; + + $db->Execute($sql); + + $sql = "UPDATE questionnaire_sample + SET sort_order = ($sso + 1) + WHERE sample_import_id = $ssid + AND questionnaire_id = $questionnaire_id"; + + $db->Execute($sql); + } + else + { + //find next in sort order and do a swap + $sql = "SELECT sample_import_id,sort_order + FROM questionnaire_sample + WHERE questionnaire_id = $questionnaire_id + AND sort_order > (SELECT sort_order FROM questionnaire_sample WHERE questionnaire_id = $questionnaire_id AND sample_import_id = $sid) + ORDER BY sort_order ASC LIMIT 1"; + + $rs = $db->GetRow($sql); + + $ssid = $rs['sample_import_id']; + $sso = $rs['sort_order']; + + $sql = "UPDATE questionnaire_sample + SET sort_order = $sso + WHERE sample_import_id = $sid + AND questionnaire_id = $questionnaire_id"; + + $db->Execute($sql); + + $sql = "UPDATE questionnaire_sample + SET sort_order = ($sso - 1) + WHERE sample_import_id = $ssid + AND questionnaire_id = $questionnaire_id"; + + $db->Execute($sql); + + } + } else { //need to remove rsid from questionnaire @@ -266,7 +331,7 @@ if ($questionnaire_id != false) print "

". T_("Samples selected for this questionnaire") .":

"; - $sql = "SELECT si.description as description, + $sql = "SELECT q.sort_order as sort_order, si.description as description,si.sample_import_id, CASE WHEN q.call_max = 0 THEN '". TQ_("Unlimited") ."' ELSE q.call_max END as call_max, CASE WHEN q.call_attempt_max = 0 THEN '". TQ_("Unlimited") . "' ELSE q.call_attempt_max END AS call_attempt_max, CASE WHEN q.random_select = 0 THEN '". TQ_("Sequential") ."' ELSE '". TQ_("Random") . "' END as random_select, @@ -276,12 +341,39 @@ if ($questionnaire_id != false) CONCAT('') as unassign FROM questionnaire_sample as q, sample_import as si WHERE q.sample_import_id = si.sample_import_id - AND q.questionnaire_id = '$questionnaire_id'"; + AND q.questionnaire_id = '$questionnaire_id' + ORDER BY q.sort_order ASC"; $qs = $db->GetAll($sql); - if (!empty($qs)) - xhtml_table($qs,array("description","call_max","call_attempt_max","answering_machine_messages","random_select","allow_new","edit","unassign"),array(T_("Sample"), T_("Max calls"), T_("Max call attempts"), T_("Answering machine messages"), T_("Selection type"), T_("Allow new numbers to be drawn?"), T_("Edit"), T_("Unassign sample"))); + if (!empty($qs)) + { + $co = count($qs); + if ($co > 1) + { + for($i = 0; $i < $co; $i++) + { + $down = ""; + $up = ""; + if ($i == 0) //down only + { + $qs[$i]['sort_order'] = $down; + } + else if ($i == ($co - 1)) //up only + { + $qs[$i]['sort_order'] = $up; + } + else + { + $qs[$i]['sort_order'] = "$up $down"; + } + } + } + else + $qs[0]['sort_order'] = ""; + + xhtml_table($qs,array("sort_order","description","call_max","call_attempt_max","answering_machine_messages","random_select","allow_new","edit","unassign"),array(T_("Sort order"),T_("Sample"), T_("Max calls"), T_("Max call attempts"), T_("Answering machine messages"), T_("Selection type"), T_("Allow new numbers to be drawn?"), T_("Edit"), T_("Unassign sample"))); + } else print "

". T_("No samples selected for this questionnaire") ."

"; From 37cd24f63f2f60582c670c8cae11d0e5b0fd3bc0 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Fri, 11 Sep 2015 12:29:43 +1000 Subject: [PATCH 3/4] Added sort_order to queries --- admin/systemsortprocess.php | 4 ++-- functions/functions.operator.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/systemsortprocess.php b/admin/systemsortprocess.php index 9a3da1fe..6a805899 100644 --- a/admin/systemsortprocess.php +++ b/admin/systemsortprocess.php @@ -267,7 +267,7 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin 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 (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = c.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0 GROUP BY c.case_id - ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC , a.start ASC"; + ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC , a.start ASC, qs.sort_order ASC"; $rs = $db->GetAll($sql); @@ -308,7 +308,7 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL) AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = qs.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0 GROUP BY s.sample_id,qs.questionnaire_id - ORDER BY qsep.priority DESC, rand() * qs.random_select, s.sample_id"; + ORDER BY qsep.priority DESC, rand() * qs.random_select, qs.sort_order ASC"; $rs = $db->GetAll($sql); diff --git a/functions/functions.operator.php b/functions/functions.operator.php index e2e39c4c..40acf1de 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -708,7 +708,7 @@ function get_case_id($operator_id, $create = false) 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.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, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC , a.start ASC + ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC , a.start ASC, qs.sort_order ASC LIMIT 1"; //apn.appointment_id contains the id of an appointment if we are calling on an appointment @@ -762,7 +762,7 @@ function get_case_id($operator_id, $create = false) AND !(q.restrict_work_shifts = 1 AND sh.shift_id IS NULL) AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL) AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = qs.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0 - ORDER BY qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC, rand() * qs.random_select, s.sample_id + ORDER BY qsep.priority DESC, CONVERT_TZ(NOW(), 'System' , s.Time_zone_name) DESC, rand() * qs.random_select, qs.sort_order ASC LIMIT 1"; } From 759c2bcd5d3ad8f127abf916af3b3f891948e4c8 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 16 Sep 2015 00:41:39 +0300 Subject: [PATCH 4/4] added sort number and tooltips, unset $_GET request to avoid undefined indexes --- admin/assignsample.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/admin/assignsample.php b/admin/assignsample.php index eb6a5f6c..e43abbe3 100644 --- a/admin/assignsample.php +++ b/admin/assignsample.php @@ -302,6 +302,8 @@ if (isset($_GET['questionnaire_id']) && isset($_GET['rsid'])) AND questionnaire_id = $questionnaire_id"; $db->Execute($sql); + + unset($_GET['sort']); } } @@ -353,24 +355,24 @@ if ($questionnaire_id != false) { for($i = 0; $i < $co; $i++) { - $down = ""; - $up = ""; + $down = ""; + $up = ""; if ($i == 0) //down only { - $qs[$i]['sort_order'] = $down; + $qs[$i]['sort_order'] = "
" . $qs[$i]['sort_order'] . "  " . $down . "
"; } else if ($i == ($co - 1)) //up only { - $qs[$i]['sort_order'] = $up; + $qs[$i]['sort_order'] = " " . $qs[$i]['sort_order'] . " " . $up; } else { - $qs[$i]['sort_order'] = "$up $down"; + $qs[$i]['sort_order'] = "
" . $qs[$i]['sort_order'] . " " . $up . $down . "
"; } } } else - $qs[0]['sort_order'] = ""; + $qs[0]['sort_order'] = "  "; xhtml_table($qs,array("sort_order","description","call_max","call_attempt_max","answering_machine_messages","random_select","allow_new","edit","unassign"),array(T_("Sort order"),T_("Sample"), T_("Max calls"), T_("Max call attempts"), T_("Answering machine messages"), T_("Selection type"), T_("Allow new numbers to be drawn?"), T_("Edit"), T_("Unassign sample"))); }