* @copyright Deakin University 2007,2008 * @package queXS * @subpackage user * @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2 * */ /** * Configuration file */ include ("config.inc.php"); /** * Database file */ include ("db.inc.php"); /** * Authentication */ require ("auth-interviewer.php"); /** * XHTML functions */ include ("functions/functions.xhtml.php"); /** * Calendar functions */ include("functions/functions.calendar.php"); /** * Operator functions */ include("functions/functions.operator.php"); /** * Input functions */ include("functions/functions.input.php"); /** * LimeSurvey functions */ include("functions/functions.limesurvey.php"); /** * Display appropriate outcomes based on current call attempt status * * @param int $contacted 0 for not contacted, 1 for contacted (a person on the phone) * @param int $ca Call attempt id * @param int $case_id The Case id * */ function display_outcomes($contacted,$ca,$case_id) { global $db; $completed = limesurvey_is_completed($case_id); //see if the case is completed if ($completed) { $sql = "SELECT outcome_id,description,contacted FROM outcome WHERE outcome_id = 10"; } else if (limesurvey_is_quota_full($case_id)) { $sql = "SELECT outcome_id,description,contacted FROM outcome WHERE outcome_id = 32"; } else { //see if we have made an appointment on this call attempt $sql = "SELECT appointment_id FROM appointment WHERE completed_call_id IS NULL AND call_attempt_id = '$ca'"; $rs = $db->GetAll($sql); if (!empty($rs)) { //we have an appointment made ... only select appointment ID's $sql = "SELECT outcome_id,description,contacted FROM outcome WHERE outcome_id = '19'"; //outcome_type_id = '5' } else { if ($contacted === false) { print "
".T_("CONTACTED").""; print "".T_("NOT CONTACTED")."
"; if (isset ($_GET['contacted'])){ $contacted = bigintval($_GET['contacted']); $sql = "SELECT outcome_id,description,contacted FROM outcome WHERE contacted = '$contacted' AND outcome_id NOT IN(5,10,19,21,40,41,42,43,44,45)"; } } else { $contacted = bigintval($contacted); $sql = "SELECT outcome_id,description,contacted FROM outcome WHERE contacted = '$contacted' AND outcome_id NOT IN(5,10,19,21,40,41,42,43,44,45)"; } } } $rs = $db->GetAll($sql); print "
"; if (!empty($rs)) { $do = false; if (isset($_GET['defaultoutcome'])) $do = bigintval($_GET['defaultoutcome']); foreach($rs as $r) { if ($do == $r['outcome_id']) $selected = "checked='checked'"; else $selected = ""; if (isset($r['contacted']) && $r['contacted'] == 1) $highlight = "text-primary"; else $highlight = "text-default"; print "
  • "; } $_POST['confirm'] = true; } print "
    "; } //display the respondents phone numbers as a drop down list for this call global $db; $db->StartTrans(); $operator_id = get_operator_id(); if (isset($_POST['submit'])) { if (isset($_POST['contact_phone'])) { $contact_phone_id = bigintval($_POST['contact_phone']); $call_attempt_id = get_call_attempt($operator_id,false); $respondent_id = get_respondent_id($call_attempt_id); $call_id = get_call($operator_id,$respondent_id,$contact_phone_id,true); if ($call_id) { if (is_voip_enabled($operator_id)) { include("functions/functions.voip.php"); $v = new voip(); $v->connect(VOIP_SERVER); $v->dial(get_extension($operator_id),get_call_number($call_id)); } $btext = "onload='parent.closePopup();'"; $js = "js/window_interface2.js"; if (browser_ie()) $js = "js/window_ie6_interface2.js"; xhtml_head(T_("Call"),true,array("css/call.css"),array($js),$btext); } } else if (isset($_POST['outcome'])) { $outcome_id = bigintval($_POST['outcome']); end_call($operator_id,$outcome_id); 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"); $js = "js/window_interface2.js"; if (browser_ie()) $js = "js/window_ie6_interface2.js"; //If outcome is final, close the case $sql = "SELECT o.tryanother FROM `outcome` as o WHERE o.outcome_id = '$outcome_id'"; $rs = $db->GetRow($sql); if (!empty($rs) && $rs['tryanother'] == 0) { xhtml_head(T_("Call"),true,array("css/call.css"),array($js),"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. * FROM contact_phone AS c LEFT JOIN ( SELECT contact_phone.contact_phone_id FROM contact_phone LEFT JOIN `call` ON ( call.contact_phone_id = contact_phone.contact_phone_id ) LEFT JOIN outcome ON ( call.outcome_id = outcome.outcome_id ) WHERE contact_phone.case_id = '$case_id' AND outcome.tryagain =0 ) AS l ON l.contact_phone_id = c.contact_phone_id LEFT JOIN ( SELECT contact_phone_id FROM `call` WHERE call_attempt_id = '$call_attempt_id' AND outcome_id != 18 ) as ca on ca.contact_phone_id = c.contact_phone_id WHERE c.case_id = '$case_id' AND l.contact_phone_id IS NULL 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)) //no more numbers to call, end the case { xhtml_head(T_("Call"),true,array("css/call.css"),array($js),"onload='openParent(\"endcase=endcase\");'"); } else { xhtml_head(T_("Call"),true,array("css/call.css"),array($js),"onload='parent.closePopup();'"); } } } else { //if no outcome selected, just hang up the call 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"); $js = "js/window_interface2.js"; if (browser_ie()) $js = "js/window_ie6_interface2.js"; xhtml_head(T_("Call"),true,array("css/call.css"),array($js),"parent.closePopup();'"); } print "

    "; //for XHTML xhtml_foot(); $db->CompleteTrans(); exit(); } $call_attempt_id = get_call_attempt($operator_id,false); $case_id = get_case_id($operator_id); /** * Set the state manually if necessary (i.e if VOIP state is playing up) */ if (isset($_GET['newstate'])) { $ns = bigintval($_GET['newstate']); $sql = "UPDATE `call` SET state = '$ns' WHERE case_id = '$case_id' AND operator_id = '$operator_id' AND call_attempt_id = '$call_attempt_id' AND outcome_id = '0'"; $db->Execute($sql); } if (browser_ie()) $js = "js/window_ie6_interface2.js"; else $js = "js/window_interface2.js"; xhtml_head(T_("Set outcome"),true,array("include/bootstrap/css/bootstrap.min.css"/* ,"css/call.css" */),array($js,"include/jquery/jquery-1.4.2.min.js")); $state = is_on_call($operator_id); switch($state) { case false: //no call made case 0: //not called -- shouldn't come here as we should create requesting call immediately print "
    " . T_("Not on a call") . "
    "; //if we are on an appointment, we will just call the specified number for the appointment $appointment_id = is_on_appointment($call_attempt_id); if ($appointment_id) { if (isset($_GET['end'])) { //end the case if (!isset($_GET['end'])) print "
    " . T_("End work") . "
    "; print "

    " . T_("End case") . "

    "; print "

    " . T_("End work") . "

    "; } else { //determine whether to begin calling based on extension status $es = 1; if (is_voip_enabled($operator_id)) { if (get_extension_status($operator_id)) $es = 1; else $es = 0; } if ($es) { $sql = "SELECT c.* FROM contact_phone as c, appointment as a WHERE a.appointment_id = '$appointment_id' AND a.contact_phone_id = c.contact_phone_id"; $r = $db->GetRow($sql); print "
    " . T_("Press the call button to dial the number for this appointment:") . "
    "; print "
    "; print "

    " . T_("Number to call:") . " {$r['phone']} - {$r['description']}

    "; print "
    "; } else print "
    " . T_("Your VoIP extension is not enabled. Please close this window and enable VoIP by clicking once on the red button that says 'VoIP Off'") . "
    "; } } else { //determine whether we should make any more calls based on the last call outcome $sql = "SELECT o.tryanother, o.require_note FROM `call` as c, `outcome` as o WHERE c.call_attempt_id = '$call_attempt_id' AND c.outcome_id = o.outcome_id ORDER BY call_id DESC LIMIT 1"; $rs = $db->GetRow($sql); if (!isset($_GET['end']) && (empty($rs) || $rs['tryanother'] == 1)) //dial another number only when available and not ending { $rn = 0; if (!empty($rs) && $rs['require_note'] == 1) $rn = 1; //an exclusion left join $sql = "SELECT c. * FROM contact_phone AS c LEFT JOIN ( SELECT contact_phone.contact_phone_id FROM contact_phone LEFT JOIN `call` ON ( call.contact_phone_id = contact_phone.contact_phone_id ) LEFT JOIN outcome ON ( call.outcome_id = outcome.outcome_id ) WHERE contact_phone.case_id = '$case_id' AND outcome.tryagain =0 ) AS l ON l.contact_phone_id = c.contact_phone_id LEFT JOIN ( SELECT contact_phone_id FROM `call` WHERE call_attempt_id = '$call_attempt_id' AND outcome_id != 18 ) as ca on ca.contact_phone_id = c.contact_phone_id WHERE c.case_id = '$case_id' AND l.contact_phone_id IS NULL 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 //could be updated to take in to account the time delay and outcome $rs = $db->GetAll($sql); if (!empty($rs)) { //determine whether to begin calling based on extension status $es = 1; if (is_voip_enabled($operator_id)) { if (get_extension_status($operator_id)) $es = 1; else $es = 0; } if ($es) { print "
    " . T_("Select phone number to dial:") . "
    "; print "
    "; } else print "
    " . T_("Your VoIP extension is not enabled. Please close this window and enable VoIP by clicking once on the red button that says 'VoIP Off'") . "
    "; } else //no phone numbers left { //end the case print "
    " . T_("The last call completed this call attempt") . "
    "; if ($rn) // a note is required to be entered { print "




    "; //give focus on load print ''; //put these lower on the screen so they don't get "automatically" clicked print "

    " . T_("End case") . "

    "; print "

    " . T_("End work") . "

    "; } else { print "

    " . T_("End case") . "

    "; print "

    " . T_("End work") . "



    "; print ''; print "

    " . T_("End case") . "

    "; print "

    " . T_("End work") . "

    "; } else { if (!isset($_GET['end'])) print "
    " . T_("The last call completed this call attempt") . "
    "; print "

    " . T_("End case") . "

    "; print "

    " . T_("End work") . "

    "; } } } break; case 1: //requesting call case 2: //ringing case 3: //answered case 4: //requires coding // print "
    " . T_("Requires coding") . "
    "; print "
    "; display_outcomes(false,$call_attempt_id,$case_id); if (isset($_POST['confirm'])){ print "
    "; } break; case 5: //done -- shouldn't come here as should be coded + done default: print "
    " . T_("Error: Close window") . "
    "; break; } xhtml_foot(); $db->CompleteTrans(); ?>