$v->dial(get_extension($operator_id), get_call_number($call_id)); } } else { exit; } } else { //hang up the call first if (is_voip_enabled($operator_id)) { $v->hangup(get_extension($operator_id)); } //disable recording ---> Not actual for call_interface2 ?? $newtext = T_("Start REC"); if (isset($_POST['outcome'])) { //process with outcome $outcome_id = bigintval($_POST['outcome']); end_call($operator_id, $outcome_id); //If outcome is final, close the case $sql = "SELECT o.tryanother\r\n\t\t\t\tFROM `outcome` as o\r\n\t\t\t\tWHERE o.outcome_id = '{$outcome_id}'"; $rs = $db->GetRow($sql); if (!empty($rs) && $rs['tryanother'] == 0) { $btext = "onload='openParent(\"endcase=endcase\");'"; } else { $call_attempt_id = get_call_attempt($operator_id, false); $case_id = get_case_id($operator_id); //see if we have exhausted the available numbers $sql = "SELECT c. *\r\n\t\t\t\t\tFROM contact_phone AS c\r\n\t\t\t\t\tLEFT JOIN (\r\n\t\t\t\t\t\t\tSELECT contact_phone.contact_phone_id\r\n\t\t\t\t\t\t\tFROM contact_phone\r\n\t\t\t\t\t\t\tLEFT JOIN `call` ON ( call.contact_phone_id = contact_phone.contact_phone_id )\r\n\t\t\t\t\t\t\tLEFT JOIN outcome ON ( call.outcome_id = outcome.outcome_id )\r\n\t\t\t\t\t\t\tWHERE contact_phone.case_id = '{$case_id}'\r\n\t\t\t\t\t\t\tAND outcome.tryagain =0\r\n\t\t\t\t\t\t) AS l ON l.contact_phone_id = c.contact_phone_id\r\n\t\t\t\t\tLEFT JOIN (\r\n\t\t\t\t\t\t\tSELECT contact_phone_id\r\n\t\t\t\t\t\t\tFROM `call`\r\n\t\t\t\t\t\t\tWHERE call_attempt_id = '{$call_attempt_id}'\r\n\t\t\t\t\t\t\tAND outcome_id != 18\r\n\t\t\t\t\t\t) as ca on ca.contact_phone_id = c.contact_phone_id\r\n\t\t\t\t\tWHERE c.case_id = '{$case_id}'\r\n\t\t\t\t\tAND l.contact_phone_id IS NULL\r\n\t\t\t\t\tAND 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)) { $btext = "onload='openParent(\"endcase=endcase\");'"; }
if ($mail->Send()) { // Put call attempt id in to sent $sql = "UPDATE " . LIME_PREFIX . "tokens_{$lime_sid}\r\n\t\t\t\tSET sent='{$ca}' \r\n\t\t\t\tWHERE token='{$token}'"; $db->Execute($sql); //Add a note that sent $sql = "INSERT INTO `case_note` (case_id,operator_id,note,datetime)\r\n\t\t\t\tVALUES ({$case_id},{$operator_id},'" . TQ_("Self completion invitation sent via email to") . ": " . $_POST['email'] . "',CONVERT_TZ(NOW(),'System','UTC'))"; $db->Execute($sql); //set to start frm the first page if the format for the respondent is not question by question $sql = "SELECT q.lime_mode\r\n\t\t\t\tFROM questionnaire as q, `case` as c\r\n\t\t\t\tWHERE c.case_id = {$case_id}\r\n\t\t\t\tAND q.questionnaire_id = c.questionnaire_id"; $lmode = $db->GetOne($sql); if ($lmode != "question") { $sql = "UPDATE " . LIME_PREFIX . "survey_{$lime_sid}\r\n\t\t\t\t\tSET lastpage = 0\r\n\t\t\t\t\tWHERE token = '{$token}'"; $db->Execute($sql); } if (isset($_POST['submith'])) { end_call($operator_id, 41); //end with outcome sent if (is_voip_enabled($operator_id)) { include "functions/functions.voip.php"; $v = new voip(); $v->connect(VOIP_SERVER); $v->hangup(get_extension($operator_id)); } //disable recording $newtext = T_("Start REC"); if (isset($_GET['interface2'])) { if (browser_ie()) { $js = "js/window_ie6_interface2.js"; } else { $js = "js/window_interface2.js"; }
$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 { print T_("End call with outcome:") . " <a class='btn btn-primary' "; //check for alternate interface if (ALTERNATE_INTERFACE && !is_voip_enabled($operator_id)) { print "href=\"javascript:parent.location.href = 'index_interface2.php?outcome=10&endcase=endcase'\">"; } else { print "href=\"javascript:parent.poptastic('call.php?defaultoutcome=10');\">"; } print T_("Complete") . "</a>"; }
/** * 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; }