* @copyright Deakin University 2007,2008 * @package queXS * @subpackage admin * @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 * */ /** * Input functions */ include("../functions/functions.input.php"); /** * Configuration file */ include_once(dirname(__FILE__).'/../config.inc.php'); /** * Database file */ include ("../db.inc.php"); /** * Authentication file */ require ("auth-admin.php"); /** * XHTML functions */ include ("../functions/functions.xhtml.php"); /** * Display functions */ include("../functions/functions.display.php"); if (isset($_GET['key']) || isset($_GET['sample'])) { $questionnaire_id = bigintval($_GET['questionnaire_id']); $sample_import_id = bigintval($_GET['sample_import_id']); $sql = "SELECT sivr.var as value, sivr.var_id as var_id FROM `sample_import_var_restrict` as sivr WHERE sivr.sample_import_id = $sample_import_id"; $svars = $db->GetAll($sql); $fn = "key_"; if (isset($_GET['sample'])) $fn = "sample_"; $fn .= T_("ALL") . "_Qid=" . $questionnaire_id . "_Sid=" . $sample_import_id .".csv"; header("Content-Type: text/csv"); header("Content-Disposition: attachment; filename=$fn"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); Header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: no-cache"); // HTTP/1.0 echo("token,".T_("Case ID").""); foreach($svars as $s) { echo("," . $s['value']); } if (isset($_GET['sample'])) { echo(",".T_("Current Outcome").",".T_("Number of call attempts").",".T_("Number of calls").",".T_("Case notes").",".T_("Total interview time over all calls (mins)").",".T_("Interview time for last call (mins)").",".T_("Last number dialled").",".T_("DATE/TIME Last number dialled").",".T_("Operator username for last call").",".T_("Shift report").", AAPOR"); } echo("\n"); $sql = "SELECT c.token,c.case_id "; if (isset($_GET['sample'])) $sql .= ", o.description, (SELECT COUNT(ca.call_attempt_id) FROM `call_attempt` as ca WHERE ca.case_id = c.case_id ) as callattempts, (SELECT COUNT(cl.call_id) FROM `call` as cl WHERE cl.case_id = c.case_id ) as calls, (SELECT GROUP_CONCAT(cn1.note SEPARATOR '|') FROM `case_note` as cn1 WHERE c.case_id = cn1.case_id GROUP BY cn1.case_id)as casenotes, (SELECT ROUND(SUM( TIMESTAMPDIFF(SECOND , cl2.start,IFNULL(cl2.end,CONVERT_TZ(NOW(),'System','UTC'))))/60,2) FROM `call_attempt` as cl2 WHERE cl2.case_id = c.case_id) as interviewtimec, (SELECT ROUND(TIMESTAMPDIFF(SECOND , cl3.start,IFNULL(cl3.end,CONVERT_TZ(NOW(),'System','UTC')))/60,2) FROM `call_attempt` as cl3 WHERE cl3.case_id = c.case_id ORDER BY cl3.call_attempt_id DESC LIMIT 1) as interviewtimel, (SELECT cp1.phone FROM `call` as cl4, `contact_phone` as cp1 WHERE cl4.call_id = c.last_call_id AND cp1.contact_phone_id = cl4.contact_phone_id ) as lastnumber, (SELECT cl55.start FROM `call` as cl55 WHERE cl55.call_id = c.last_call_id ) as lastcallstart, (SELECT op1.username FROM `call` as cl5, `operator` as op1 WHERE cl5.call_id = c.last_call_id AND op1.operator_id = cl5.operator_id) as operatoru, (SELECT GROUP_CONCAT(DISTINCT sr1.report SEPARATOR '|') FROM `call` as cl6, `shift` as sh1, `shift_report` as sr1 WHERE cl6.case_id = c.case_id AND sr1.shift_id = sh1.shift_id AND sh1.questionnaire_id = c.questionnaire_id AND cl6.start >= sh1.start AND cl6.end < sh1.end GROUP BY sr1.shift_id) as shiftr, o.aapor_id "; $i = 0; foreach ($svars as $s) { $sql .= ", sv$i.val as v$i"; $i++; } $sql .= " FROM sample "; //left join if getting whole sample file if (isset($_GET['sample'])) $sql .= "LEFT "; $sql .= "JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_id' AND c.sample_id = `sample`.sample_id) "; if (isset($_GET['sample'])) $sql .= " LEFT JOIN `outcome` as o ON (o.outcome_id = c.current_outcome_id)"; $i = 0; foreach ($svars as $s) { $sql .= " LEFT JOIN sample_var AS sv$i ON (sv$i.sample_id = `sample`.sample_id AND sv$i.var_id = '{$s['var_id']}') "; $i++; } $sql .= " WHERE `sample`.import_id = '$sample_import_id'"; $list = $db->GetAll($sql); if (!empty($list)) { foreach($list as $l) { echo $l['token'] . "," . $l['case_id']; $i = 0; foreach ($svars as $s) { echo "," . str_replace(","," ",$l["v$i"]); $i++; } if (isset($_GET['sample'])) { echo "," . str_replace(","," ",$l['description']) . "," .$l['callattempts']."," .$l['calls']."," .$l['casenotes'].",".$l['interviewtimec'].",".$l['interviewtimel'].",".$l['lastnumber'].",".$l['lastcallstart'].",".$l['operatoru'].",".$l['shiftr'].",". $l['aapor_id']; } echo "\n"; } } exit; } if (isset($_GET['sample_var'])){ $questionnaire_id = bigintval($_GET['questionnaire_id']); $sample_import_id = bigintval($_GET['sample_import_id']); $varid = intval($_GET['sample_var']); $sql = "SELECT c.token, c.case_id, sv.val, sivr.var FROM `case` as c, `sample_import_var_restrict` as sivr, `sample_var` as sv WHERE c.questionnaire_id = $questionnaire_id AND sivr.sample_import_id = $sample_import_id AND c.sample_id = sv.sample_id AND sivr.var_id = sv.var_id AND sivr.var_id = $varid"; $list = $db->GetAll($sql); $sample_var = $list[0]['var']; $fn = "key-" . $sample_var . "_Qid=$questionnaire_id" . "_Sid=" . $sample_import_id .".csv"; header("Content-Type: text/csv"); header("Content-Disposition: attachment; filename=$fn"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); Header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: no-cache"); // HTTP/1.0 echo("token,caseid,$sample_var\n"); if (!empty($list)) { foreach($list as $l) { echo $l['token'] . "," . $l['case_id'] . "," . $l['val'] . "\n"; } } exit; } xhtml_head(T_("Data output"),true,array("../include/bootstrap/css/bootstrap.min.css","../css/custom.css"),array("../js/window.js")); print "