mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Merged from McMasterReports branch
This commit is contained in:
@@ -104,7 +104,6 @@ function display_shift_chooser($questionnaire_id, $shift_id = false)
|
||||
print "</select></div>";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a list of samples to choose from in a drop down list
|
||||
*
|
||||
@@ -133,6 +132,35 @@ function display_sample_chooser($questionnaire_id, $sample_import_id = false)
|
||||
print "</select></div>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a list of quota rows to choose from in a drop down list
|
||||
*
|
||||
* @param int $questionnaire_id The questionnaire id
|
||||
* @param int $sample_import_id The sample import id
|
||||
* @param int|bool $qsqri The sample import id or false if none selected
|
||||
*/
|
||||
function display_quota_chooser($questionnaire_id, $sample_import_id, $qsqri = false)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT q.questionnaire_sample_quota_row_id,q.description,CASE WHEN q.questionnaire_sample_quota_row_id = '$qsqri' THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
FROM questionnaire_sample_quota_row as q
|
||||
WHERE q.questionnaire_id = '$questionnaire_id'
|
||||
AND q.sample_import_id = '$sample_import_id'";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
print "<div><select id='questionnaire_sample_quota_row_id' name='questionnaire_sample_quota_row_id' onchange=\"LinkUp('questionnaire_sample_quota_row_id')\"><option value='?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id'></option>";
|
||||
if (!empty($rs))
|
||||
{
|
||||
foreach($rs as $r)
|
||||
{
|
||||
print "<option value='?sample_import_id=$sample_import_id&questionnaire_id=$questionnaire_id&questionnaire_sample_quota_row_id={$r['questionnaire_sample_quota_row_id']}' {$r['selected']}>{$r['questionnaire_sample_quota_row_id']}: {$r['description']}</option>";
|
||||
}
|
||||
}
|
||||
print "</select></div>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -42,6 +42,40 @@ include_once(dirname(__FILE__).'/../config.inc.php');
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../db.inc.php');
|
||||
|
||||
/**
|
||||
* Return the number of completions for a given
|
||||
* questionnaire, where the given sample var has
|
||||
* the given sample value
|
||||
*
|
||||
* @param int $lime_sid The limesurvey survey id
|
||||
* @param int $questionnaire_id The questionnaire ID
|
||||
* @param int $sample_import_id The sample import ID
|
||||
* @param string $val The value to compare
|
||||
* @param string $var The variable to compare
|
||||
* @return bool|int False if failed, otherwise the number of completions
|
||||
*
|
||||
*/
|
||||
function limesurvey_quota_replicate_completions($lime_sid,$questionnaire_id,$sample_import_id,$val,$var)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT count(*) as c
|
||||
FROM " . LIME_PREFIX . "survey_$lime_sid as s
|
||||
JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_id')
|
||||
JOIN `sample` as sam ON (c.sample_id = sam.sample_id AND sam.import_id = '$sample_import_id')
|
||||
JOIN `sample_var` as sv ON (sv.sample_id = sam.sample_id AND sv.var LIKE '$var' AND sv.val LIKE '$val')
|
||||
WHERE s.submitdate IS NOT NULL
|
||||
AND s.token = c.case_id";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
if (isset($rs) && !empty($rs))
|
||||
return $rs['c'];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the number of completions for a given
|
||||
@@ -77,6 +111,71 @@ function limesurvey_quota_completions($lime_sgqa,$lime_sid,$questionnaire_id,$sa
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information on limesurvey quota's
|
||||
* Based on GetQuotaInformation() from common.php in Limesurvey
|
||||
*
|
||||
* @param int $lime_quota_id The quota id to get information on
|
||||
* @param string $baselang The base language for getting information from questions
|
||||
* @return array An array containing the question information for comparison
|
||||
*/
|
||||
function get_limesurvey_quota_info($lime_quota_id,$baselang = DEFAULT_LOCALE)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$ret = array();
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM ".LIME_PREFIX."quota_members
|
||||
WHERE quota_id='$lime_quota_id'";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
foreach($rs as $quota_entry)
|
||||
{
|
||||
$lime_qid = $quota_entry['qid'];
|
||||
$surveyid = $quota_entry['sid'];
|
||||
|
||||
$sql = "SELECT type, title,gid
|
||||
FROM ".LIME_PREFIX."questions
|
||||
WHERE qid='$lime_qid'
|
||||
AND language='$baselang'";
|
||||
|
||||
$qtype = $db->GetRow($sql);
|
||||
|
||||
$fieldnames = "0";
|
||||
|
||||
if ($qtype['type'] == "I" || $qtype['type'] == "G" || $qtype['type'] == "Y")
|
||||
{
|
||||
$fieldnames= ($surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid']);
|
||||
$value = $quota_entry['code'];
|
||||
}
|
||||
|
||||
if($qtype['type'] == "L" || $qtype['type'] == "O" || $qtype['type'] =="!")
|
||||
{
|
||||
$fieldnames=( $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid']);
|
||||
$value = $quota_entry['code'];
|
||||
}
|
||||
|
||||
if($qtype['type'] == "M")
|
||||
{
|
||||
$fieldnames=( $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid'].$quota_entry['code']);
|
||||
$value = "Y";
|
||||
}
|
||||
|
||||
if($qtype['type'] == "A" || $qtype['type'] == "B")
|
||||
{
|
||||
$temp = explode('-',$quota_entry['code']);
|
||||
$fieldnames=( $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid'].$temp[0]);
|
||||
$value = $temp[1];
|
||||
}
|
||||
|
||||
|
||||
$ret[] = array('code' => $quota_entry['code'], 'value' => $value, 'qid' => $quota_entry['qid'], 'fieldname' => $fieldnames);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Taken from common.php in the LimeSurvey package
|
||||
@@ -133,33 +232,33 @@ function create_limesurvey_questionnaire($title)
|
||||
while (!empty($isresult) && $isresult->RecordCount() > 0);
|
||||
|
||||
$isquery = "INSERT INTO ". LIME_PREFIX ."surveys\n"
|
||||
. "(sid, owner_id, admin, active, useexpiry, expires, "
|
||||
. "adminemail, private, faxto, format, template, url, "
|
||||
. "language, datestamp, ipaddr, refurl, usecookie, notification, allowregister, attribute1, attribute2, "
|
||||
. "(sid, owner_id, admin, active, expires, "
|
||||
. "adminemail, private, faxto, format, template, "
|
||||
. "language, datestamp, ipaddr, refurl, usecookie, notification, allowregister, "
|
||||
. "allowsave, autoredirect, allowprev,datecreated,tokenanswerspersistence)\n"
|
||||
. "VALUES ($surveyid, 1,\n"
|
||||
. "'', 'N', \n"
|
||||
. "'N','1980-01-01', '', 'N',\n"
|
||||
. "'', 'S', 'quexs', '" . QUEXS_URL . "rs_project_end.php',\n"
|
||||
. "'en', 'Y', 'N', 'N',\n"
|
||||
. "NULL, '', 'N',\n"
|
||||
. "'', 'S', 'quexs',\n"
|
||||
. "'" . DEFAULT_LOCALE . "', 'Y', 'N', 'N',\n"
|
||||
. "'N', '0', 'Y',\n"
|
||||
. "'att1', 'att2', \n"
|
||||
. "'Y', 'Y', 'Y','".date("Y-m-d")."','Y')";
|
||||
$isresult = $db->Execute($isquery);
|
||||
$isresult = $db->Execute($isquery) or die ($isquery."<br/>".$db->ErrorMsg());
|
||||
|
||||
// insert base language into surveys_language_settings
|
||||
$isquery = "INSERT INTO ".db_table_name('surveys_languagesettings')
|
||||
. "(surveyls_survey_id, surveyls_language, surveyls_title, surveyls_description, surveyls_welcometext, surveyls_urldescription, "
|
||||
. "surveyls_email_invite_subj, surveyls_email_invite, surveyls_email_remind_subj, surveyls_email_remind, "
|
||||
. "surveyls_email_register_subj, surveyls_email_register, surveyls_email_confirm_subj, surveyls_email_confirm)\n"
|
||||
. "VALUES ($surveyid, 'en', $title, $title,\n"
|
||||
. "surveyls_email_register_subj, surveyls_email_register, surveyls_email_confirm_subj, surveyls_email_confirm,surveyls_url)\n"
|
||||
. "VALUES ($surveyid, '" . DEFAULT_LOCALE . "', $title, $title,\n"
|
||||
. "'',\n"
|
||||
. "'', '',\n"
|
||||
. "'', '',\n"
|
||||
. "'', '',\n"
|
||||
. "'', '',\n"
|
||||
. "'')";
|
||||
$isresult = $db->Execute($isquery);
|
||||
. "'', '" . QUEXS_URL . "rs_project_end.php')";
|
||||
$isresult = $db->Execute($isquery) or die ($isquery."<br/>".$db->ErrorMsg());
|
||||
|
||||
|
||||
// Insert into survey_rights
|
||||
$isrquery = "INSERT INTO ". LIME_PREFIX . "surveys_rights VALUES($surveyid,1,1,1,1,1,1,1)";
|
||||
@@ -249,6 +348,32 @@ function get_lime_sid($case_id)
|
||||
return $l['lime_sid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if LimeSurvey has marked a questionnaire as quota filled
|
||||
*
|
||||
* @param int $case_id The case id
|
||||
* @return bool True if complete, false if not or unknown
|
||||
*
|
||||
*/
|
||||
function limesurvey_is_quota_full($case_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$lime_sid = get_lime_sid($case_id);
|
||||
if ($lime_sid == false) return false;
|
||||
|
||||
$sql = "SELECT completed
|
||||
FROM " . LIME_PREFIX . "tokens_$lime_sid
|
||||
WHERE token = '$case_id'";
|
||||
|
||||
$r = $db->GetRow($sql);
|
||||
|
||||
if (!empty($r))
|
||||
if ($r['completed'] == 'Q') return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if LimeSurvey has marked a questionnaire as complete
|
||||
@@ -271,12 +396,9 @@ function limesurvey_is_completed($case_id)
|
||||
$r = $db->GetRow($sql);
|
||||
|
||||
if (!empty($r))
|
||||
if ($r['completed'] != 'N') return true;
|
||||
if ($r['completed'] != 'N' && $r['completed'] != 'Q') return true;
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -464,8 +464,8 @@ function get_case_id($operator_id, $create = false)
|
||||
|
||||
if ($lime_sid)
|
||||
{
|
||||
$sql = "INSERT INTO ".LIME_PREFIX."tokens_$lime_sid (tid,firstname,lastname,email,token,language,sent,completed,attribute_1,attribute_2,mpid)
|
||||
VALUES (NULL,'','','',$case_id,'en','N','N','','',NULL)";
|
||||
$sql = "INSERT INTO ".LIME_PREFIX."tokens_$lime_sid (tid,firstname,lastname,email,token,language,sent,completed,mpid)
|
||||
VALUES (NULL,'','','',$case_id,'en','N','N',NULL)";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
@@ -1035,6 +1035,98 @@ function update_quota($questionnaire_id)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* "Open" a row quota (allow to access)
|
||||
*
|
||||
* @param int $questionnaire_sample_quota_row_id The qsqri
|
||||
*/
|
||||
function open_row_quota($questionnaire_sample_quota_row_id,$delete = true)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
if ($delete)
|
||||
{
|
||||
$sql = "DELETE FROM questionnaire_sample_quota_row
|
||||
WHERE questionnaire_sample_quota_row_id = '$questionnaire_sample_quota_row_id'";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM questionnaire_sample_quota_row_exclude
|
||||
WHERE questionnaire_sample_quota_row_id = '$questionnaire_sample_quota_row_id'";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
/**
|
||||
* "Close" a row quota (set to completed)
|
||||
*
|
||||
*
|
||||
*/
|
||||
function close_row_quota($questionnaire_sample_quota_row_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
//only insert where we have to
|
||||
$sql = "SELECT count(*) as c
|
||||
FROM questionnaire_sample_quota_row_exclude
|
||||
WHERE questionnaire_sample_quota_row_id = '$questionnaire_sample_quota_row_id'";
|
||||
|
||||
$coun = $db->GetRow($sql);
|
||||
|
||||
if (isset($coun['c']) && $coun['c'] == 0)
|
||||
{
|
||||
//store list of sample records to exclude
|
||||
$sql = "INSERT INTO questionnaire_sample_quota_row_exclude (questionnaire_sample_quota_row_id,questionnaire_id,sample_id)
|
||||
SELECT $questionnaire_sample_quota_row_id,qs.questionnaire_id,s.sample_id
|
||||
FROM sample as s, sample_var as sv, questionnaire_sample_quota_row as qs
|
||||
WHERE s.import_id = qs.sample_import_id
|
||||
AND qs.questionnaire_sample_quota_row_id = $questionnaire_sample_quota_row_id
|
||||
AND s.sample_id = sv.sample_id
|
||||
AND sv.var = qs.exclude_var
|
||||
AND qs.exclude_val LIKE sv.val";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy row quotas from one sample to another
|
||||
* Set quota_reached to 0 by default
|
||||
*
|
||||
* @param int $questionnaire_id
|
||||
* @param int $sample_import_id
|
||||
* @param int $copy_sample_import_id The sample_import_id to copy to
|
||||
*/
|
||||
function copy_row_quota($questionnaire_id,$sample_import_id,$copy_sample_import_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
//Set quota_reached to 0 always
|
||||
|
||||
$sql = "INSERT INTO questionnaire_sample_quota_row (questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,exclude_var,exclude_val,quota_reached,description)
|
||||
SELECT questionnaire_id, $copy_sample_import_id, lime_sgqa,value,comparison,completions,exclude_var,exclude_val,0,description
|
||||
FROM questionnaire_sample_quota_row
|
||||
WHERE questionnaire_id = '$questionnaire_id'
|
||||
AND sample_import_id = '$sample_import_id'";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
update_quotas($questionnaire_id);
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the row quota table
|
||||
@@ -1051,7 +1143,8 @@ function update_row_quota($questionnaire_id)
|
||||
FROM questionnaire_sample_quota_row as qsq, questionnaire as q
|
||||
WHERE qsq.questionnaire_id = '$questionnaire_id'
|
||||
AND q.questionnaire_id = '$questionnaire_id'
|
||||
AND qsq.quota_reached != '1'";
|
||||
AND qsq.quota_reached != '1'
|
||||
AND qsq.lime_sgqa != -1";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
@@ -1074,28 +1167,7 @@ function update_row_quota($questionnaire_id)
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
|
||||
//only insert where we have to
|
||||
$sql = "SELECT count(*) as c
|
||||
FROM questionnaire_sample_quota_row_exclude
|
||||
WHERE questionnaire_sample_quota_row_id = '{$r['questionnaire_sample_quota_row_id']}'";
|
||||
|
||||
$coun = $db->GetRow($sql);
|
||||
|
||||
if (isset($coun['c']) && $coun['c'] == 0)
|
||||
{
|
||||
//store list of sample records to exclude
|
||||
$sql = "INSERT INTO questionnaire_sample_quota_row_exclude (questionnaire_sample_quota_row_id,questionnaire_id,sample_id)
|
||||
SELECT {$r['questionnaire_sample_quota_row_id']},'$questionnaire_id',s.sample_id
|
||||
FROM sample as s, sample_var as sv
|
||||
WHERE s.import_id = '{$r['sample_import_id']}'
|
||||
AND s.sample_id = sv.sample_id
|
||||
AND sv.var = '{$r['exclude_var']}'
|
||||
AND '{$r['exclude_val']}' LIKE sv.val";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
close_row_quota($r['questionnaire_sample_quota_row_id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ function get_CPH_by_shift($qid,$sid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,ca.time, c.completions/ca.time as CPH
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,SEC_TO_TIME(ca.time) as time, c.completions/(ca.time / 3600) as CPH
|
||||
FROM operator as o
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a, `case` as b, `shift` as s
|
||||
@@ -62,7 +62,7 @@ function get_CPH_by_shift($qid,$sid)
|
||||
AND s.`start` <= a.`start`
|
||||
AND s.`end` >= a.`start`
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , a.start, IFNULL(a.end,CONVERT_TZ(NOW(),'System','UTC')))) /3600 as time, a.operator_id
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , a.start, IFNULL(a.end,CONVERT_TZ(NOW(),'System','UTC')))) as time, a.operator_id
|
||||
FROM `call_attempt` as a, `case` as b, `shift` as s
|
||||
WHERE a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$qid'
|
||||
@@ -85,7 +85,7 @@ function get_CPH_by_questionnaire($qid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,ca.time, c.completions/ca.time as CPH
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,SEC_TO_TIME(ca.time) as time, c.completions/(ca.time / 3600) as CPH
|
||||
FROM operator as o
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a, `case` as b
|
||||
@@ -93,13 +93,216 @@ function get_CPH_by_questionnaire($qid)
|
||||
AND a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$qid'
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , a.start, IFNULL(a.end,CONVERT_TZ(NOW(),'System','UTC')))) /3600 as time, a.operator_id
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , a.start, IFNULL(a.end,CONVERT_TZ(NOW(),'System','UTC')))) as time, a.operator_id
|
||||
FROM `call_attempt` as a, `case` as b
|
||||
WHERE a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$qid'
|
||||
GROUP BY operator_id) as ca on (ca.operator_id = o.operator_id)
|
||||
ORDER BY cph DESC";
|
||||
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stats by interviewer by questionnaire by shift
|
||||
*
|
||||
* @param int $questionnaire_id The questionnaire
|
||||
* @param int $shift_id The shift id
|
||||
* @return arrayh An array containing operator_id,firstName,CPH,effectiveness,
|
||||
*/
|
||||
function get_stats_by_shift($questionnaire_id,$shift_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.operator_id, o.firstName, (calltime.totaltime / callattempttime.totaltime) AS effectiveness, c.completions,SEC_TO_TIME(callattempttime.totaltime) as time, c.completions/(callattempttime.totaltime / 3600) as CPH, SEC_TO_TIME(calltime.totaltime) as callt, SEC_TO_TIME(callattempttime.totaltime) as callatemptt, calls.calls as totalcalls, calls.calls/(callattempttime.totaltime / 3600) as CALLSPH, calltime.totaltime as calltotaltime, callattempttime.totaltime as callattempttotaltime
|
||||
|
||||
FROM operator AS o
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call` AS c, `case` as b, `shift` as s
|
||||
WHERE c.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
AND s.shift_id = '$shift_id'
|
||||
AND s.`start` <= c.`start`
|
||||
AND s.`end` >= c.`start`
|
||||
GROUP BY operator_id
|
||||
) AS calltime ON ( calltime.operator_id = o.operator_id )
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call_attempt` AS c, `case` as b, `shift` as s
|
||||
WHERE c.case_id = b.case_id
|
||||
AND s.shift_id = '$shift_id'
|
||||
AND s.`start` <= c.`start`
|
||||
AND s.`end` >= c.`start`
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY operator_id
|
||||
) AS callattempttime ON ( callattempttime.operator_id = o.operator_id )
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a, `case` as b, `shift` as s
|
||||
WHERE a.outcome_id = '10'
|
||||
AND s.shift_id = '$shift_id'
|
||||
AND s.`start` <= a.`start`
|
||||
AND s.`end` >= a.`start`
|
||||
AND a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT count(*) as calls,a.operator_id
|
||||
FROM `call` as a, `case` as b, `shift` as s
|
||||
WHERE a.case_id = b.case_id
|
||||
AND s.shift_id = '$shift_id'
|
||||
AND s.`start` <= a.`start`
|
||||
AND s.`end` >= a.`start`
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY a.operator_id) as calls on (calls.operator_id = o.operator_id)
|
||||
ORDER BY effectiveness DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert seconds to time in HH:MM:SS
|
||||
*
|
||||
* @param int Seconds
|
||||
* @return string Time in format HH:MM:SS
|
||||
*/
|
||||
function sec_to_time($seconds)
|
||||
{
|
||||
|
||||
if($seconds >= 3600){
|
||||
$h = floor($seconds/3600);
|
||||
$seconds = ($seconds%3600);
|
||||
}
|
||||
if($seconds >= 60){
|
||||
$m = floor($seconds/60);
|
||||
$seconds = ($seconds%60);
|
||||
}
|
||||
$s = floor($seconds);
|
||||
|
||||
return sprintf("%02d:%02d:%02d", $h, $m, $s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given the stats, add a total line
|
||||
*
|
||||
* @param array The result set from the database
|
||||
* @return array The result set plus a total row
|
||||
*/
|
||||
function get_stats_total($rs)
|
||||
{
|
||||
$completions = 0;
|
||||
$calls = 0;
|
||||
$totaltime = 0;
|
||||
$calltime = 0;
|
||||
|
||||
foreach($rs as $r)
|
||||
{
|
||||
$completions += $r['completions'];
|
||||
$calls += $r['totalcalls'];
|
||||
$totaltime += $r['callattempttotaltime'];
|
||||
$calltime += $r['calltotaltime'];
|
||||
}
|
||||
|
||||
if ($totaltime == 0)
|
||||
{
|
||||
$effectiveness = 0;
|
||||
$cph = 0;
|
||||
$callsph = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$effectiveness = round($calltime / $totaltime,4);
|
||||
$cph = round($completions/($totaltime/3600),4);
|
||||
$callsph = round($calls/($totaltime/3600),4);
|
||||
}
|
||||
|
||||
$rs[] = array("effectiveness" => $effectiveness, "completions" => $completions,"time" => sec_to_time($totaltime),"totalcalls" => $calls,"callt" => sec_to_time($calltime),"CPH" => $cph,"CALLSPH" => $callsph);
|
||||
|
||||
return $rs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get stats by interviewer
|
||||
*
|
||||
* @return arrayh An array containing operator_id,firstName,CPH,effectiveness,
|
||||
*/
|
||||
function get_stats()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.operator_id, o.firstName, (calltime.totaltime / callattempttime.totaltime) AS effectiveness, c.completions,SEC_TO_TIME(callattempttime.totaltime) as time, c.completions/(callattempttime.totaltime / 3600) as CPH, SEC_TO_TIME(calltime.totaltime) as callt, SEC_TO_TIME(callattempttime.totaltime) as callatemptt, calls.calls as totalcalls, calls.calls/(callattempttime.totaltime / 3600) as CALLSPH, calltime.totaltime as calltotaltime, callattempttime.totaltime as callattempttotaltime
|
||||
FROM operator AS o
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call` AS c
|
||||
GROUP BY operator_id
|
||||
) AS calltime ON ( calltime.operator_id = o.operator_id )
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call_attempt` AS c, `case` as b
|
||||
GROUP BY operator_id
|
||||
) AS callattempttime ON ( callattempttime.operator_id = o.operator_id )
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a
|
||||
WHERE a.outcome_id = '10'
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT count(*) as calls,a.operator_id
|
||||
FROM `call` as a
|
||||
GROUP BY a.operator_id) as calls on (calls.operator_id = o.operator_id)
|
||||
ORDER BY effectiveness DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get stats by interviewer by questionnaire
|
||||
*
|
||||
* @param int $questionnaire_id The questionnaire
|
||||
* @return arrayh An array containing operator_id,firstName,CPH,effectiveness,
|
||||
*/
|
||||
function get_stats_by_questionnaire($questionnaire_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.operator_id, o.firstName, (calltime.totaltime / callattempttime.totaltime) AS effectiveness, c.completions,SEC_TO_TIME(callattempttime.totaltime) as time, c.completions/(callattempttime.totaltime / 3600) as CPH, SEC_TO_TIME(calltime.totaltime) as callt, SEC_TO_TIME(callattempttime.totaltime) as callatemptt, calls.calls as totalcalls, calls.calls/(callattempttime.totaltime / 3600) as CALLSPH, calltime.totaltime as calltotaltime, callattempttime.totaltime as callattempttotaltime
|
||||
|
||||
FROM operator AS o
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call` AS c, `case` as b
|
||||
WHERE c.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY operator_id
|
||||
) AS calltime ON ( calltime.operator_id = o.operator_id )
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call_attempt` AS c, `case` as b
|
||||
WHERE c.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY operator_id
|
||||
) AS callattempttime ON ( callattempttime.operator_id = o.operator_id )
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a, `case` as b
|
||||
WHERE a.outcome_id = '10'
|
||||
AND a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT count(*) as calls,a.operator_id
|
||||
FROM `call` as a, `case` as b
|
||||
WHERE a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY a.operator_id) as calls on (calls.operator_id = o.operator_id)
|
||||
ORDER BY effectiveness DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
@@ -113,13 +316,13 @@ function get_CPH()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,ca.time, c.completions/ca.time as CPH
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,SEC_TO_TIME(ca.time) as time, c.completions/(ca.time / 3600) as CPH
|
||||
FROM operator as o
|
||||
JOIN ( SELECT count(*) as completions,operator_id
|
||||
FROM `call`
|
||||
WHERE outcome_id = '10'
|
||||
GROUP BY operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , start, IFNULL(end,CONVERT_TZ(NOW(),'System','UTC')))) /3600 as time, operator_id
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , start, IFNULL(end,CONVERT_TZ(NOW(),'System','UTC')))) as time, operator_id
|
||||
FROM `call_attempt`
|
||||
GROUP BY operator_id) as ca on (ca.operator_id = o.operator_id)
|
||||
ORDER BY cph DESC";
|
||||
|
||||
@@ -94,10 +94,12 @@ function xhtml_foot()
|
||||
* @param bool|array $head False if no header otherwise array of header titles
|
||||
* @param string $class Table CSS class
|
||||
* @param bool|array $highlight False if nothing to highlight else an array containing the field to highlight
|
||||
* @param bool|array $total False if nothing to total else an array containing the fields to total
|
||||
*
|
||||
*/
|
||||
function xhtml_table($content,$fields,$head = false,$class = "tclass",$highlight=false)
|
||||
function xhtml_table($content,$fields,$head = false,$class = "tclass",$highlight=false,$total=false)
|
||||
{
|
||||
$tot = array();
|
||||
print "<table class='$class'>";
|
||||
if ($head)
|
||||
{
|
||||
@@ -114,8 +116,23 @@ function xhtml_table($content,$fields,$head = false,$class = "tclass",$highlight
|
||||
print "<tr>";
|
||||
|
||||
foreach ($fields as $e)
|
||||
{
|
||||
print "<td>{$row[$e]}</td>";
|
||||
|
||||
if ($total && in_array($e,$total))
|
||||
$tot[$e] += $row[$e];
|
||||
}
|
||||
print "</tr>";
|
||||
}
|
||||
if ($total)
|
||||
{
|
||||
print "<tr>";
|
||||
foreach ($fields as $e)
|
||||
{
|
||||
print "<td>";
|
||||
if (in_array($e,$total))
|
||||
print $tot[$e];
|
||||
print "</td>";
|
||||
}
|
||||
print "</tr>";
|
||||
}
|
||||
print "</table>";
|
||||
|
||||
Reference in New Issue
Block a user