$rs = $db->GetRow($sql); if (!empty($rs) && $rs['tryanother'] == 1) { //we can try another number... $case_id = get_case_id($operator_id, false); $call_attempt_id = get_call_attempt($operator_id, false); //check if there is another number to try... $sql = "SELECT c. *\r\n FROM contact_phone AS c\r\n LEFT JOIN (\r\n SELECT contact_phone.contact_phone_id\r\n FROM contact_phone\r\n LEFT JOIN `call` ON ( call.contact_phone_id = contact_phone.contact_phone_id )\r\n LEFT JOIN outcome ON ( call.outcome_id = outcome.outcome_id )\r\n WHERE contact_phone.case_id = '{$case_id}'\r\n AND outcome.tryagain =0\r\n ) AS l ON l.contact_phone_id = c.contact_phone_id\r\n LEFT JOIN\r\n (\r\n SELECT contact_phone_id\r\n FROM `call`\r\n WHERE call_attempt_id = '{$call_attempt_id}'\r\n AND outcome_id != 18\r\n ) as ca on ca.contact_phone_id = c.contact_phone_id\r\n WHERE c.case_id = '{$case_id}'\r\n AND l.contact_phone_id IS NULL\r\n AND ca.contact_phone_id IS NULL"; //only select numbers that should be tried again and have not been tried in this attempt which are not the accidental hang up outcome $rs = $db->GetAll($sql); if (!empty($rs)) { $endthecase = false; } } } if ($endthecase) { end_call_attempt($operator_id); end_case($operator_id); $db->CompleteTrans(); //need to complete here otherwise getting the case later will fail require "waitnextcase_interface2.php"; exit; } } $js = array("js/popup.js", "js/tabber.js", "include/jquery/jquery.min.js", "include/jquery-ui/jquery-ui.min.js"); $body = true; $script = ""; if (AUTO_LOGOUT_MINUTES !== false) { $js[] = "include/nap-1.0.0/js/jquery.nap-1.0.0.js"; $script = "<script type='text/javascript'>\r\n\t\t \$(document).nap(\r\n\t\t\tfunction() { \r\n\t\t\t\tlocation.replace('" . QUEXS_URL . "?endwork=endwork&auto=auto');\r\n\t\t\t},\r\n\t\t\tfunction() { \r\n\t\t\t\t//do nothing if woken up as shouldn't get here\r\n\t\t\t},\r\n\t\t\t" . AUTO_LOGOUT_MINUTES * 60 . "\r\n\t\t);</script></head><body>"; $body = false; }
/** * End the current case * * @param int $operator_id The operator to end the case for * * @see get_case() */ function end_case($operator_id) { global $db; $db->StartTrans(); $case_id = get_case_id($operator_id, false); $questionnaire_id = get_questionnaire_id($operator_id); $return = false; if ($case_id) { //End all calls (with not attempted or worked if there is a call); end_call($operator_id, 1); //Make sure to end call attempts end_call_attempt($operator_id); //determine current final outcome code //Look over all calls, for each phone number that is to be tried again //Calculate outcome based on //If no phone number is to be tried again, use the outcome from the last call //If one phone number is to be tried again, use: "Differences in Response Rates using Most recent versus Final dispositions in Telephone Surveys" by Christopher McCarty // //Look for any calls where none should be tried again (this should be a final outcome) $sql = "SELECT c.call_id, c.outcome_id\r\n\t\t\tFROM `call` as c, `outcome` as o\r\n\t\t\tWHERE c.case_id = '{$case_id}'\r\n\t\t\tAND c.outcome_id = o.outcome_id\r\n\t\t\tAND o.tryanother = 0\r\n\t\t\tAND (o.outcome_type_id = 4)\r\n\t\t\tORDER BY c.call_id DESC\r\n\t\t\tLIMIT 1"; $a = $db->GetRow($sql); if (empty($a)) { $sql = "SELECT c.*\r\n\t\t\t\tFROM contact_phone AS c\r\n\t\t\t\tLEFT JOIN (\r\n\t\t\t\t\tSELECT contact_phone.contact_phone_id\r\n\t\t\t\t\tFROM contact_phone\r\n\t\t\t\t\tLEFT JOIN `call` ON ( call.contact_phone_id = contact_phone.contact_phone_id )\r\n\t\t\t\t\tLEFT JOIN outcome ON ( call.outcome_id = outcome.outcome_id )\r\n\t\t\t\t\tWHERE contact_phone.case_id = '{$case_id}'\r\n\t\t\t\t\tAND outcome.tryagain =0\r\n\t\t\t\t\t) AS l ON l.contact_phone_id = c.contact_phone_id\r\n\t\t\t\tWHERE c.case_id = '{$case_id}'\r\n\t\t\t\tAND l.contact_phone_id IS NULL"; $r = $db->GetAll($sql); //$r contains one row for each phone number that is to be tried again if (!empty($r)) { $count = count($r); } else { $count = 0; } $outcome = 1; //default outcome is 1 - not attempted //last call $sql = "SELECT call_id,outcome_id\r\n\t\t\t\tFROM `call`\r\n\t\t\t\tWHERE case_id = '{$case_id}'\r\n\t\t\t\tORDER BY call_id DESC\r\n\t\t\t\tLIMIT 1"; $l = $db->GetRow($sql); $lastcall = 0; if (!empty($l)) { $lastcall = $l['call_id']; } if ($count == 0) { //last call $sql = "SELECT c.outcome_id as outcome_id\r\n\t\t\t\t\tFROM `call` as c\r\n\t\t\t\t\tJOIN outcome AS o ON ( c.outcome_id = o.outcome_id)\r\n\t\t\t\t\tWHERE c.case_id = '{$case_id}'\r\n\t\t\t\t\tAND o.outcome_id != 18\r\n\t\t\t\t\tORDER BY c.call_id DESC\r\n\t\t\t\t\tLIMIT 1"; $t = $db->GetRow($sql); if (!empty($t)) { $outcome = $t['outcome_id']; } } else { if ($count >= 1) { $sql = "SELECT call_attempt_max,call_max\r\n FROM questionnaire_sample as qs, `case` as c, sample as s\r\n WHERE c.case_id = '{$case_id}'\r\n AND c.sample_id = s.sample_id\r\n AND qs.sample_import_id = s.import_id\r\n AND qs.questionnaire_id = c.questionnaire_id"; $cm = $db->GetRow($sql); $sql = "SELECT COUNT(*) as c\r\n FROM call_attempt\r\n WHERE case_id = '{$case_id}'"; $callattempts = $db->GetOne($sql); $sql = "SELECT COUNT(*) as c\r\n FROM `call`\r\n WHERE case_id = '{$case_id}'"; $calls = $db->GetOne($sql); $eligsql = "SELECT count(*)\r\n FROM `call` as c, `outcome` as o\r\n WHERE c.outcome_id = o.outcome_id\r\n AND o.eligible = 1\r\n AND c.case_id = '{$case_id}'"; if ($cm['call_attempt_max'] > 0 && $callattempts >= $cm['call_attempt_max']) { //if ever eligible, code as eligible if ($db->GetOne($eligsql) > 0) { $outcome = 44; } else { $outcome = 42; } } else { if ($cm['call_max'] > 0 && $calls >= $cm['call_max']) { //if ever eligible, code as eligible if ($db->GetOne($eligsql) > 0) { $outcome = 45; } else { $outcome = 43; } } else { //$r[0]['contact_phone_id']; //code as eligible if ever eligible, or if referred to the supervisor, code as that if last call $sql = "SELECT c.outcome_id as outcome_id\r\n \t\t\t\t\tFROM `call` as c\r\n \t\t\t\t\tJOIN outcome AS o ON ( c.outcome_id = o.outcome_id AND (o.eligible = 1 OR o.outcome_type_id = 2 OR o.outcome_type_id = 1) )\r\n \t\t\t\t\tWHERE c.case_id = '{$case_id}'\r\n \t\t\t\t\tORDER BY c.call_id DESC"; $t = $db->GetRow($sql); if (!empty($t)) { $outcome = $t['outcome_id']; } } } } } } else { //the last call is the call with the final otucome $outcome = $a['outcome_id']; $lastcall = $a['call_id']; //if the outcome is complete, then update the quota's for this questionnaire (if any) if ($outcome == 10) { update_quotas($questionnaire_id, $case_id); } } $sql = "UPDATE `case`\r\n\t\t\tSET current_operator_id = NULL, current_call_id = NULL, sortorder = NULL, current_outcome_id = '{$outcome}', last_call_id = '{$lastcall}'\r\n\t\t\tWHERE case_id = '{$case_id}'"; $o = $db->Execute($sql); $return = true; } else { $return = false; } //if ($db->HasFailedTrans()) { print "FAILED in end_case"; exit; } if ($db->CompleteTrans()) { return $return; } return false; }