/** * Get start interviewer URL * * @return string The URL to start the interview */ function get_start_interview_url() { $db = newADOConnection(DB_TYPE); $db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $db->SetFetchMode(ADODB_FETCH_ASSOC); $operator_id = get_operator_id(); $url = QUEXS_URL . "nocaseavailable.php"; $case_id = get_case_id($operator_id); if ($case_id) { $sql = "SELECT token\r\n\t\t\tFROM `case`\r\n\t\t\tWHERE case_id = {$case_id}"; $token = $db->GetOne($sql); $sid = get_limesurvey_id($operator_id); $url = LIME_URL . "index.php?interviewer=interviewer&loadall=reload&sid={$sid}&token={$token}&lang=" . DEFAULT_LOCALE; $questionnaire_id = get_questionnaire_id($operator_id); //get prefills $sql = "SELECT lime_sgqa,value\r\n FROM questionnaire_prefill\r\n WHERE questionnaire_id = '{$questionnaire_id}'"; $pf = $db->GetAll($sql); if (!empty($pf)) { foreach ($pf as $p) { $url .= "&" . $p['lime_sgqa'] . "=" . quexs_template_replace($p['value']); } } } return $url; }
/** * XHTML functions */ include "functions/functions.xhtml.php"; /** * Operator functions */ include "functions/functions.operator.php"; $operator_id = get_operator_id(); $js = array("js/popup.js", "include/jquery/jquery-1.4.2.min.js", "include/jquery-ui/jquery-ui.min.js"); if (AUTO_LOGOUT_MINUTES !== false) { $js[] = "js/childnap.js"; } xhtml_head(T_("Respondent Selection") . " - " . T_("Project end"), true, array("include/bootstrap/css/bootstrap.min.css", "css/rs.css"), $js); $case_id = get_case_id($operator_id); $questionnaire_id = get_questionnaire_id($operator_id); //display introduction text $sql = "SELECT rs_project_end\r\n\tFROM questionnaire\r\n\tWHERE questionnaire_id = '{$questionnaire_id}'"; $r = $db->GetRow($sql); if (!empty($r['rs_project_end'])) { print "<p class='rstext well'>" . template_replace($r['rs_project_end'], $operator_id, $case_id) . "</p>"; } print "<p class='well'>"; if (!is_voip_enabled($operator_id) && AUTO_COMPLETE_OUTCOME) { end_call($operator_id, 10); print T_("Call automatically ended with outcome:") . " <b>" . T_("Complete") . "</b>"; //check for alternate interface if (ALTERNATE_INTERFACE && !is_voip_enabled($operator_id)) { print " <a href=\"javascript:parent.location.href = 'index_interface2.php?endcase=endcase'\" class='btn btn-primary'>" . T_("End case") . "</a>"; } } else {
/** * 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; }