2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Import from DCARF SVN

This commit is contained in:
azammitdcarf
2008-10-15 04:49:50 +00:00
parent 74c9cb7408
commit ec24d5af18
45 changed files with 12429 additions and 0 deletions

262
admin/addshift.php Normal file
View File

@@ -0,0 +1,262 @@
<?
/**
* Add and modify shifts by questionnaire
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*/
/**
* Configuration file
*/
include ("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Operator functions
*/
include ("../functions/functions.operator.php");
/**
* Display functions
*/
include ("../functions/functions.display.php");
/**
* Input functions
*/
include("../functions/functions.input.php");
global $db;
/**
* Add shifts to the DB based on the shift_template table
*/
if (isset($_POST['year'])) $year = bigintval($_POST['year']); else $year = "YEAR(NOW())";
if (isset($_POST['woy'])) $woy = bigintval($_POST['woy']); else $woy = "WEEK(NOW(), 3)";
if (isset($_POST['qid'])) $questionnaire_id = bigintval($_POST['qid']); else $questionnaire_id = false;
if (isset($_GET['year'])) $year = bigintval($_GET['year']);
if (isset($_GET['woy'])) $woy = bigintval($_GET['woy']);
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
$y = $db->GetRow("SELECT $year as y");
$year = $y['y'];
$y = $db->GetRow("SELECT $woy as y");
$woy = $y['y'];
$operator_id = get_operator_id();
if (isset($_POST['submit']))
{
//process
//update or delete existing shifts
foreach($_POST as $key => $val)
{
if (substr($key,0,5) == "start")
{
$num = bigintval(substr($key,6));
if (isset($_POST["use_$num"]))
{
$sql = "UPDATE shift as s, operator as o
SET s.start = CONVERT_TZ(CONCAT(STR_TO_DATE(CONCAT($year, ' ',$woy,' ', {$_POST["dow_$num"]}),'%x %v %w'),' ','" . $_POST["start_$num"] . "'), o.Time_zone_name, 'UTC'),
s.end = CONVERT_TZ(CONCAT(STR_TO_DATE(CONCAT($year, ' ',$woy,' ', {$_POST["dow_$num"]}),'%x %v %w'),' ','" . $_POST["end_$num"] . "'), o.Time_zone_name, 'UTC')
WHERE o.operator_id = '$operator_id'
AND shift_id = '$num'";
$db->Execute($sql);
}
else
{
$sql = "DELETE FROM shift
WHERE shift_id = '$num'";
$db->Execute($sql);
}
}
}
//insert new shifts
foreach($_POST as $key => $val)
{
if (substr($key,0,7) == "NEW_use")
{
if ($val == "on")
{
$num = bigintval(substr($key,8));
$sql = "INSERT INTO shift (shift_id,questionnaire_id,start,end)
SELECT NULL,'$questionnaire_id', CONVERT_TZ(CONCAT(STR_TO_DATE(CONCAT($year, ' ',$woy,' ', {$_POST["NEW_dow_$num"]}),'%x %v %w'),' ','" . $_POST["NEW_start_$num"] . "'), Time_zone_name, 'UTC') , CONVERT_TZ(CONCAT(STR_TO_DATE(CONCAT($year, ' ',$woy,' ', {$_POST["NEW_dow_$num"]}),'%x %v %w'),' ','" . $_POST["NEW_end_$num"] . "'), Time_zone_name, 'UTC')
FROM operator
WHERE operator_id = '$operator_id'";
$db->Execute($sql);
}
}
}
}
xhtml_head(T_("Add shifts"),false,false,array("../js/window.js"));
?>
<style type="text/css">
.selected {
font-weight:bold;
font-size:larger;
}
</style>
</head>
<body>
<?
/**
* display years including current selected year
* display weeks of year including current selected week of year
* find if there are already shifts defined for this week of year / year and display them as selected, else show from template
* when submitted, add checked shifts, and delete unchecked shifts if they exist
*
* @todo Use javascript to add shifts if necessarry outside the template
*/
print "<h2>" . T_("Add shifts in your Time Zone") . "</h2>";
print "<h3>" . T_("Select a questionnaire from the list below") . "</h3>";
display_questionnaire_chooser($questionnaire_id);
if ($questionnaire_id != false)
{
print "<p>";
for ($i = $year - 1; $i < $year + 4; $i++)
{
if ($i == $year)
print "$i ";
else
print "<a href=\"?year=$i&amp;woy=$woy&amp;questionnaire_id=$questionnaire_id\">$i</a> ";
}
print "</p>";
print "<p>";
for ($i = 1; $i <= 53; $i++)
{
if ($i == $woy)
print "$i ";
else
print "<a href=\"?woy=$i&amp;year=$year&amp;questionnaire_id=$questionnaire_id\">$i</a> ";
}
print "</p>";
$sql = "SELECT shift_id, dt, dta,start,end
FROM (
(
SELECT shift_id, DATE_FORMAT( CONVERT_TZ( s.start, 'UTC', o.Time_zone_name ) , '%W %d %M %Y' ) AS dt,
DATE( CONVERT_TZ( s.start, 'UTC', o.Time_zone_name ) ) AS dta,
TIME( CONVERT_TZ( s.start, 'UTC', o.Time_zone_name ) ) AS start,
TIME( CONVERT_TZ( s.end, 'UTC', o.Time_zone_name ) ) AS end
FROM shift AS s, operator AS o
WHERE WEEK( CONVERT_TZ( s.start, 'UTC', o.Time_zone_name ) , 3 ) = '$woy'
AND YEAR( CONVERT_TZ( s.start, 'UTC', o.Time_zone_name ) ) = '$year'
AND o.operator_id = '$operator_id'
AND s.questionnaire_id = '$questionnaire_id'
)
UNION (
SELECT NULL AS shift_id,
DATE_FORMAT( STR_TO_DATE( CONCAT( '$year', ' ', '$woy', ' ', day_of_week -1 ) , '%x %v %w' ) , '%W %d %M %Y' ) AS dt,
STR_TO_DATE( CONCAT( '$year', ' ', '$woy', ' ', day_of_week -1 ) , '%x %v %w' ) AS dta,
start,end
FROM shift_template
)
) AS sb
GROUP BY dta,start,end";
$shifts = $db->GetAll($sql);
$sql = "SELECT DATE_FORMAT(STR_TO_DATE(CONCAT($year, ' ',$woy,' ',day_of_week - 1),'%x %v %w'), '%W %d %M %Y') as dt, day_of_week - 1 as dow
FROM shift_template
GROUP BY dow";
$daysofweek = $db->Execute($sql);
?>
<form method="post" action="">
<table>
<?
print "<tr><th>" . T_("Day") . "</th><th>" . T_("Start") . "</th><th>" . T_("End") . "</th><th>" . T_("Use shift?") . "</th></tr>";
$count = 1;
foreach($shifts as $shift)
{
$checked="";
$shift_id="";
$prefix="";
if (!empty($shift['shift_id']))
{
$checked="checked=\"checked\""; $shift_id = $shift['shift_id'];
}
else
{
$shift_id = $count;
$prefix = "NEW_";
}
print "<tr><td>" . $daysofweek->GetMenu($prefix . "dow_$shift_id",$shift['dt']) . "</td><td><input size=\"8\" name=\"" . $prefix ."start_$shift_id\" maxlength=\"8\" type=\"text\" value=\"{$shift['start']}\"/></td><td><input name=\"" . $prefix ."end_$shift_id\" type=\"text\" size=\"8\" maxlength=\"8\" value=\"{$shift['end']}\"/></td><td><input name=\"" . $prefix ."use_$shift_id\" type=\"checkbox\" $checked/></td></tr>";
$daysofweek->MoveFirst();
$count++;
}
?>
<!--<tr><td/><td/><td/><td>Select all</td></tr>-->
</table>
<!--<p><input type="submit" name="addshift" value="Add Shift"/></p>-->
<p><input type="submit" name="submit" value="Submit changes"/></p>
<p><input type="hidden" name="year" value="<? echo $year; ?>"/></p>
<p><input type="hidden" name="woy" value="<? echo $woy; ?>"/></p>
<p><input type="hidden" name="qid" value="<? echo $questionnaire_id; ?>"/></p>
</form>
<?
}
xhtml_foot();
?>

161
admin/assignsample.php Normal file
View File

@@ -0,0 +1,161 @@
<?
/**
* Assign sample(s) to a questionnaire
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*
*/
/**
* Configuration file
*/
include("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include("../functions/functions.xhtml.php");
/**
* Display functions
*/
include("../functions/functions.display.php");
/**
* Input functions
*/
include("../functions/functions.input.php");
global $db;
if (isset($_GET['questionnaire_id']) && isset($_GET['sample']) && isset($_GET['call_max']) && isset($_GET['call_attempt_max']))
{
//need to add sample to questionnaire
$questionnaire_id = bigintval($_GET['questionnaire_id']);
$sid = bigintval($_GET['sample']);
$cm = bigintval($_GET['call_max']);
$cam = bigintval($_GET['call_attempt_max']);
$am = bigintval($_GET['answering_machine_messages']);
$selecttype = 0;
if (isset($_GET['selecttype'])) $selecttype = 1;
$sql = "INSERT INTO questionnaire_sample(questionnaire_id,sample_import_id,call_max,call_attempt_max,random_select,answering_machine_messages)
VALUES('$questionnaire_id','$sid','$cm','$cam','$selecttype','$am')";
$db->Execute($sql);
}
if (isset($_GET['questionnaire_id']) && isset($_GET['rsid']))
{
//need to remove rsid from questionnaire
$questionnaire_id = bigintval($_GET['questionnaire_id']);
$sid = bigintval($_GET['rsid']);
$sql = "DELETE FROM questionnaire_sample
WHERE questionnaire_id = '$questionnaire_id'
AND sample_import_id = '$sid'";
$db->Execute($sql);
}
$questionnaire_id = false;
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
xhtml_head(T_("Assign Sample: Select sample to assign"),true,false,array("../js/window.js"));
print "<h1>" . T_("Select a questionnaire from the list below") . "</h1>";
display_questionnaire_chooser($questionnaire_id);
if ($questionnaire_id != false)
{
print "<h1>" . T_("Samples selected for this questionnaire") . "</h1>";
$sql = "SELECT q.sample_import_id as sample_import_id,si.description as description, q.call_max, q.call_attempt_max, q.random_select
FROM questionnaire_sample as q, sample_import as si
WHERE q.sample_import_id = si.sample_import_id
AND q.questionnaire_id = '$questionnaire_id'";
$qs = $db->GetAll($sql);
foreach($qs as $q)
{
if ($q['random_select'] == 0) $rs = T_("Sequentially selected");
else $rs = T_("Randomly selected");
print "<p><a href=\"?questionnaire_id=$questionnaire_id&amp;rsid={$q['sample_import_id']}\">{$q['sample_import_id']} - {$q['description']}: " . T_("Max calls:") . " {$q['call_max']} " . T_("Max call attempts:") . " {$q['call_attempt_max']} $rs (" . T_("Click to unassign") . ")</a></p>";
}
$sql = "SELECT si.sample_import_id,si.description
FROM sample_import as si
LEFT JOIN questionnaire_sample as q ON (q.questionnaire_id = '$questionnaire_id' AND q.sample_import_id = si.sample_import_id)
WHERE q.questionnaire_id is NULL";
$qs = $db->GetAll($sql);
if (!empty($qs))
{
print "<h1>" . T_("Add a sample to this questionnaire:") . "</h1>";
?>
<form action="" method="get">
<p><label for="sample"><? echo T_("Select sample:"); ?></label><select name="sample" id="sample">
<?
foreach($qs as $q)
{
print "<option value=\"{$q['sample_import_id']}\">{$q['description']}</option>";
}
?>
</select><br/>
<label for="call_max"><? echo T_("Max calls (0 for unlimited)"); ?></label><input type="text" name="call_max" id="call_max" value="0"/><br/>
<label for="call_attempt_max"><? echo T_("Max call attempts (0 for unlimited)"); ?></label><input type="text" name="call_attempt_max" id="call_attempt_max" value="0"/> <br/>
<label for="answering_machine_messages"><? echo T_("Number of answering machine messages to leave per case (0 for never)"); ?></label><input type="text" name="answering_machine_messages" id="answering_machine_messages" value="1"/> <br/>
<label for="selecttype"><? echo T_("Select from sample randomly? (otherwise sequentially)"); ?></label><input type="checkbox" id = "selecttype" name="selecttype" /> <br/>
<input type="hidden" name="questionnaire_id" value="<? print($questionnaire_id); ?>"/>
<input type="submit" name="add_sample" value="Add sample"/></p>
</form>
<?
}
}
xhtml_foot();
?>

80
admin/callhistory.php Normal file
View File

@@ -0,0 +1,80 @@
<?
/**
* Display a list of calls and outcomes for all calls
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Operator functions
*/
include("../functions/functions.operator.php");
xhtml_head(T_("Call History List"),true,array("../css/table.css"));
//List the case call history
$operator_id = get_operator_id();
if ($operator_id)
{
$sql = "SELECT DATE_FORMAT(CONVERT_TZ(c.start,'UTC',op.Time_zone_name),'".DATE_TIME_FORMAT."') as start,DATE_FORMAT(CONVERT_TZ(c.end,'UTC',op.Time_zone_name),'".TIME_FORMAT."') as end, o.description as des, (CONCAT(r.firstName,' ',r.lastName)) as firstName, opp.firstName as opname, CONCAT('<a href=\'supervisor.php?case_id=', c.case_id, '\'>', c.case_id, '</a>') as case_id
FROM `call` as c
JOIN (operator as op, respondent as r) on (op.operator_id = '$operator_id' and r.respondent_id = c.respondent_id)
LEFT JOIN (outcome as o) on (c.outcome_id = o.outcome_id)
LEFT JOIN (operator as opp) on (opp.operator_id = c.operator_id)
ORDER BY c.start DESC
LIMIT 500";
$rs = $db->GetAll($sql);
if (empty($rs))
print "<p>" . T_("No calls ever made") . "</p>";
else
xhtml_table($rs,array("start","end","case_id","opname","des","firstName"),array(T_("Date/Time call start"),T_("Time end"),T_("Case ID"),T_("Operator"),T_("Outcome"),T_("Respondent")));
}
else
print "<p>" . T_("No operator") . "</p>";
xhtml_foot();
?>

View File

@@ -0,0 +1,273 @@
<?
/**
* Assign clients to questionnaires in a checkbox matrix
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*/
/**
* Configuration file
*/
include ("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Return if an client has already been assigned to this questionnaire
*
* @param int $client Client id
* @param int $questionnaire_id Questionnaire id
* @return int 1 if assigned otherwise 0
*
*/
function vq($client_id,$questionnaire_id)
{
global $db;
$sql = "SELECT client_id,questionnaire_id
FROM client_questionnaire
WHERE client_id = '$client_id' and questionnaire_id = '$questionnaire_id'";
$vq = $db->Execute($sql);
return $vq->RecordCount();
}
/**
* Assign an client to a questionnaire
*
* @param int $client_id Client id
* @param int $questionnaire_id Questionnaire id
*
*/
function vqi($client_id,$questionnaire_id)
{
global $db;
$sql = "INSERT INTO
client_questionnaire (client_id,questionnaire_id)
VALUES('$client_id','$questionnaire_id')";
$db->Execute($sql);
}
/**
* Unassign an client from a questionnaire
*
* @param int $client_id Client id
* @param int $questionnaire_id Questionnaire id
*
*/
function vqd($client_id,$questionnaire_id)
{
global $db;
$sql = "DELETE FROM
client_questionnaire
WHERE client_id = '$client_id' and questionnaire_id = '$questionnaire_id'";
$db->Execute($sql);
}
if (isset($_POST['submit']))
{
$db->StartTrans();
$sql = "DELETE
FROM client_questionnaire
WHERE 1";
$db->Execute($sql);
foreach ($_POST as $g => $v)
{
$a = explode("_",$g);
if ($a[0] == "cb")
vqi($a[2],$a[1]);
}
$db->CompleteTrans();
}
$sql = "SELECT questionnaire_id,description
FROM questionnaire
ORDER by questionnaire_id ASC";
$questionnaires = $db->GetAll($sql);
$sql = "SELECT client_id,firstname as description
FROM client
ORDER by client_id ASC";
$clients = $db->GetAll($sql);
xhtml_head(T_("Assign clients to questionnaires"),false,array("../css/table.css"));
?>
<script type="text/javascript">
<?
print "questionnaire_id = new Array(";
$s = "";
foreach($questionnaires as $q)
{
$s .= "'{$q['questionnaire_id']}',";
}
$s = substr($s,0,strlen($s) - 1);
print "$s);\n";
print "client_id = new Array(";
$s = "";
foreach($clients as $q)
{
$s .= "'{$q['client_id']}',";
}
$s = substr($s,0,strlen($s) - 1);
print "$s);\n";
?>
var QidOn = 0;
var VidOn = 0;
function checkQid(q)
{
for (y in client_id)
{
v = client_id[y];
cb = document.getElementById('cb_' + q + "_" + v);
if (QidOn == 0)
cb.checked = 'checked';
else
cb.checked = '';
}
if (QidOn == 0)
QidOn = 1;
else
QidOn = 0;
}
function checkVid(v)
{
for (y in questionnaire_id)
{
q = questionnaire_id[y];
cb = document.getElementById('cb_' + q + "_" + v);
if (VidOn == 0)
cb.checked = 'checked';
else
cb.checked = '';
}
if (VidOn == 0)
VidOn = 1;
else
VidOn = 0;
}
</script>
</head>
<body>
<?
print "<form action=\"\" method=\"post\"><table>";
print "<tr><th></th>";
foreach($questionnaires as $q)
{
print "<th><a href=\"javascript:checkQid({$q['questionnaire_id']})\">{$q['description']}</a></th>";
}
print "</tr>";
$class = 0;
foreach($clients as $v)
{
print "<tr class='";
if ($class == 0) {$class = 1; print "even";} else {$class = 0; print "odd";}
print "'>";
print "<th><a href=\"javascript:checkVid({$v['client_id']})\">{$v['description']}</a></th>";
foreach($questionnaires as $q)
{
$checked = "";
if (vq($v['client_id'],$q['questionnaire_id'])) $checked="checked=\"checked\"";
print "<td><input type=\"checkbox\" name=\"cb_{$q['questionnaire_id']}_{$v['client_id']}\" id=\"cb_{$q['questionnaire_id']}_{$v['client_id']}\" $checked></input></td>";
}
print "</tr>";
}
print "</table><p><input type=\"submit\" name=\"submit\"/></p></form>";
xhtml_foot();
?>

101
admin/clients.php Normal file
View File

@@ -0,0 +1,101 @@
<?
/**
* Create a client and link to a webserver username for authentication
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*
* @todo Make timezone a drop down list
*
*/
/**
* Configuration file
*/
include ("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
global $db;
$a = false;
if (isset($_POST['client']))
{
$client = $db->qstr($_POST['client'],get_magic_quotes_gpc());
$firstname = $db->qstr($_POST['firstname'],get_magic_quotes_gpc());
$lastname = $db->qstr($_POST['lastname'],get_magic_quotes_gpc());
$time_zone_name = $db->qstr($_POST['Time_zone_name'],get_magic_quotes_gpc());
if (!empty($_POST['client']))
{
$sql = "INSERT INTO client
(`client_id` ,`username` ,`firstName` ,`lastName`, `Time_zone_name`)
VALUES (NULL , $client, $firstname , $lastname, $time_zone_name);";
if ($db->Execute($sql))
$a = T_("Added: $client");
else
$a = T_("Could not add") . " " . $client . ". " . T_("There may already be an client of this name");
}
}
xhtml_head(T_("Add a client"));
if ($a)
{
?>
<h3><? echo $a; ?></h3>
<?
}
?>
<h1><? echo T_("Add a client"); ?></h1>
<p><? echo T_("Adding a client here will allow them to access project information in the client subdirectory. You can assign a client to a particular project using the"); ?> <a href="clientquestionnaire.php"><? echo T_("Assign client to Questionnaire"); ?></a> <? echo T_("tool."); ?></p>
<p><? echo T_("Use this form to enter the username of a user based on your directory security system. For example, if you have secured the base directory of queXS using Apache file based security, enter the usernames of the users here."); ?></p>
<form enctype="multipart/form-data" action="" method="post">
<p><? echo T_("Enter the username of an client to add:"); ?> <input name="client" type="text"/></p>
<p><? echo T_("Enter the first name of an client to add:"); ?> <input name="firstname" type="text"/></p>
<p><? echo T_("Enter the surname of an client to add:"); ?> <input name="lastname" type="text"/></p>
<p><? echo T_("Enter the Time Zone of an client to add:"); ?> <input name="Time_zone_name" type="text" value="<? echo DEFAULT_TIME_ZONE; ?>"/></p>
<p><input type="submit" value="Add user" /></p>
</form>
<?
xhtml_foot();
?>

154
admin/dataoutput.php Normal file
View File

@@ -0,0 +1,154 @@
<?php
/**
* Output data as a fixed width ASCII file
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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");
if (isset($_GET['data']))
{
/**
* Limesurvey functions
*/
include("../functions/functions.limesurvey.php");
$questionnaire_id = false;
$sample_import_id = false;
if (isset($_GET['sample_import_id'])) $sample_import_id = bigintval($_GET['sample_import_id']);
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
limesurvey_export_fixed_width($questionnaire_id,$sample_import_id);
exit();
}
/**
* Configuration file
*/
include_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Display functions
*/
include("../functions/functions.display.php");
if (isset($_GET['sample_var']))
{
$questionnaire_id = bigintval($_GET['questionnaire_id']);
$sample_import_id = bigintval($_GET['sample_import_id']);
$sample_var = $db->quote($_GET['sample_var']);
$sql = "SELECT c.case_id, sv.val
FROM sample, `case` as c, sample_var as sv
WHERE c.questionnaire_id = '$questionnaire_id'
AND sample.import_id = '$sample_import_id'
AND c.sample_id = sample.sample_id
AND sv.sample_id = sample.sample_id
AND sv.var = $sample_var";
$list = $db->GetAll($sql);
$fn = "key_$questionnaire_id" . "_" . $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("caseid,$sample_var\n");
if (!empty($list))
{
foreach($list as $l)
{
echo $l['case_id'] . "," . $l['val'] . "\n";
}
}
exit;
}
xhtml_head(T_("Data output"),true,false,array("../js/window.js"));
print "<h3>Please select a questionnaire</h3>";
$questionnaire_id = false;
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
display_questionnaire_chooser($questionnaire_id);
if ($questionnaire_id)
{
print "<p><a href='?data&amp;questionnaire_id=$questionnaire_id'>Download all data for this questionnaire</a></p>";
$sample_import_id = false;
if (isset($_GET['sample_import_id'])) $sample_import_id = bigintval($_GET['sample_import_id']);
display_sample_chooser($questionnaire_id,$sample_import_id);
if ($sample_import_id)
{
print "<p><a href='?data&amp;questionnaire_id=$questionnaire_id&amp;sample_import_id=$sample_import_id'>Download data for this sample</a></p>";
//get sample vars
$sql = "SELECT sv.var as value, sv.var as description
FROM `sample_var` as sv
WHERE sv.sample_id = (SELECT sample_id FROM sample WHERE import_id = '$sample_import_id' LIMIT 1)";
//download a key file linking the caseid to the sample
print "<h3>Download key file: select sample var</h3>";
display_chooser($db->GetAll($sql),"sample_var","sample_var",true,"questionnaire_id=$questionnaire_id&amp;sample_import_id=$sample_import_id");
}
}
xhtml_foot();
?>

View File

@@ -0,0 +1,100 @@
<?php
/**
* Display appointments
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*/
/**
* Configuration file
*/
include_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Operator functions
*/
include ("../functions/functions.operator.php");
/**
* Input functions
*/
include ("../functions/functions.input.php");
if (isset($_GET['appointment_id']) && isset($_GET['case_id']))
{
$appointment_id = bigintval($_GET['appointment_id']);
$case_id = bigintval($_GET['case_id']);
$sql = "DELETE FROM appointment
WHERE appointment_id = '$appointment_id'";
$db->Execute($sql);
xhtml_head(T_("Now modify case outcome"));
print "<p>" . T_("The appointment has been deleted. Now you must modify the case outcome") . "</p>";
print "<p><a href='supervisor.php?case_id=$case_id'>" . T_("Modify case outcome") . "</a></p>";
}
else
{
$operator_id = get_operator_id();
xhtml_head(T_("Display Appointments"),true,array("../css/table.css"));
print "<h1>" . T_("Appointments") . "</h1><h2>" . T_("All appointments (with times displayed in your time zone)") . "</h2>";
$sql = "SELECT q.description, CONVERT_TZ(a.start,'UTC',o.Time_zone_name) as start, CONVERT_TZ(a.end,'UTC',o.Time_zone_name) as end, r.firstName, r.lastName, IFNULL(ou.description,'" . T_("Not yet called") . "') as outcome, oo.firstName as makerName, ooo.firstName as callerName, CONCAT('<a href=\'supervisor.php?case_id=', c.case_id, '\'>', c.case_id, '</a>') as case_id, CONCAT('<a href=\'?case_id=', c.case_id, '&amp;appointment_id=', a.appointment_id, '\'>". T_("Delete") . "</a>') as link
FROM appointment as a
JOIN (`case` as c, respondent as r, questionnaire as q, operator as o, operator as oo, call_attempt as cc) on (a.case_id = c.case_id and a.respondent_id = r.respondent_id and q.questionnaire_id = c.questionnaire_id and o.operator_id = '$operator_id' and a.call_attempt_id = cc.call_attempt_id and cc.operator_id = oo.operator_id)
LEFT JOIN (`call` as ca, outcome as ou, operator as ooo) ON (ca.call_id = a.completed_call_id and ou.outcome_id = ca.outcome_id and ca.operator_id = ooo.operator_id)
WHERE a.end >= CONVERT_TZ(NOW(),'System','UTC')
ORDER BY a.start ASC";
$rs = $db->GetAll($sql);
if (!empty($rs))
xhtml_table($rs,array("description","case_id","start","end","makerName","firstName","lastName","outcome","callerName","link"),array(T_("Questionnaire"),T_("Case ID"),T_("Start"),T_("End"),T_("Operator Name"),T_("Respondent Name"),T_("Surname"),T_("Current outcome"),T_("Operator who called"),T_("Delete")));
else
print "<p>" . T_("No appointments in the future") . "</p>";
}
xhtml_foot();
?>

131
admin/import.php Normal file
View File

@@ -0,0 +1,131 @@
<?
/**
* Import a sample from a Headered CSV file
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*/
/**
* Configuration file
*/
include ("../config.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Sample import functions
*/
include("../functions/functions.import.php");
session_start();
if (isset($_GET['import_form']))
{
//form has been submitted
xhtml_head(T_("Import: Validating and uploading"));
//verify each GET field is unique (except import_form)
$sfields = array();
foreach($_GET as $getv => $val)
//clean up?
$sfields[$getv] = $val;
$error = verify_fields($sfields);
$description = $_GET['description'];
if ($error == "")
{ //verified so upload
if (import_file($_SESSION['filename'],$description,$sfields))
{
print "<p>" . T_("Successfully imported file") . "</p>";
}
else
{
print "<p>" . T_("Error importing file. Please try again") . "</p>";
}
}
else
print "<p>" . T_("Error:") . " $error </p><p>" . T_("Please go back in your browser and fix the problem") . "</p>";
//verifiy that exactly one primary phone number is selected
//upload to database
xhtml_foot();
}
else if (isset($_POST['import_file']))
{
//file has been submitted
xhtml_head(T_("Import: Select columns to import"));
?>
<form action="" method="get">
<?
$tmpfname = tempnam("/tmp", "FOO");
move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname);
$_SESSION['filename'] = $tmpfname;
display_table(get_first_row($tmpfname));
?>
<p><input type="hidden" name="description" value="<? if (isset($_POST['description'])) print($_POST['description']); ?>"/></p>
<p><input type="submit" name="import_form"/></p>
</form>
<?
xhtml_foot();
}
else
{
//need to supply file to upload
xhtml_head(T_("Import: Select file to upload"));
?>
<form enctype="multipart/form-data" action="" method="post">
<p><input type="hidden" name="MAX_FILE_SIZE" value="1000000000" /></p>
<p><? echo T_("Choose the CSV sample file to upload:"); ?><input name="file" type="file" /></p>
<p><? echo T_("Description for file:"); ?><input name="description" type="text" /></p>
<p><input type="submit" name="import_file"/></p>
</form>
<?
xhtml_foot();
}
?>

88
admin/index.php Normal file
View File

@@ -0,0 +1,88 @@
<?php
/**
* Display an index of Admin tools
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*/
/**
* Language file
*/
include ("../lang.inc.php");
/**
* Config file
*/
include ("../config.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
xhtml_head(T_("Administrative Tools"),true,array("../css/table.css","../css/admin.css"),array("../js/link.js"));
print "<div id='menu'><h3>" . T_("Questionnaire creation and management") . "</h3>";
print "<div><a href=\"javascript:link('mainobj','new.php');\">" . T_("Create a new questionnaire") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','" . LIME_URL . "admin/admin.php');\">" . T_("Administer questionnaires with Limesurvey") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','import.php');\">" . T_("Import a sample file (in CSV form)") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','assignsample.php');\">" . T_("Assign samples to questionnaires") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','questionnaireprefill.php');\">" . T_("Set values in questionnaire to pre fill") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','operators.php');\">" . T_("Add operators to the system") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','operatorquestionnaire.php');\">" . T_("Assign operators to questionnaires") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','operatorskill.php');\">" . T_("Modify operator skills") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','addshift.php');\">" . T_("Shift management (add/remove)") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','dataoutput.php');\">" . T_("Data output") . "</a></div>";
print "<h3>" . T_("Questionnaire progress") . "</h3>";
print "<div><a href=\"javascript:link('mainobj','displayappointments.php');\">" . T_("Display all future appointments") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','outcomes.php');\">" . T_("Questionnaire outcomes") . "</a></div>";
print "<h3>" . T_("Performance") . "</h3>";
print "<div><a href=\"javascript:link('mainobj','operatorperformance.php');\">" . T_("Operator performance") . "</a></div>";
print "<h3>" . T_("Client management") . "</h3>";
print "<div><a href=\"javascript:link('mainobj','clients.php');\">" . T_("Add clients to the system") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','clientquestionnaire.php');\">" . T_("Assign clients to questionnaires") . "</a></div>";
print "<h3>" . T_("Supervisor functions") . "</h3>";
print "<div><a href=\"javascript:link('mainobj','supervisor.php');\">" . T_("Assign outcomes to cases") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','samplesearch.php');\">" . T_("Search the sample") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','callhistory.php');\">" . T_("Call history") . "</a></div>";
print "<div><a href=\"javascript:link('mainobj','shiftreport.php');\">" . T_("Shift reports") . "</a></div>";
print "</div>";
print "<div id='main'><object class='embeddedobject' id='mainobj' data='new.php' standby='Loading panel...' type='application/xhtml+xml'><p>Error, try with Firefox</p></object></div>";
xhtml_foot();
?>

154
admin/new.php Normal file
View File

@@ -0,0 +1,154 @@
<?
/**
* Create a queXS questionnaire and link it to a LimeSurvey questionnaire
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*
* @todo Create from queXML
*
*/
/**
* Configuration file
*/
include ("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Input functions
*/
include("../functions/functions.input.php");
global $ldb;
global $db;
xhtml_head(T_("New: Create new questionnaire"));
if (isset($_POST['import_file']))
{
//file has been submitted
global $db;
$ras =0;
$rws = 0;
$testing = 0;
$rs = 0;
$lime_sid = 0;
if (isset($_POST['ras'])) $ras = 1;
if (isset($_POST['rws'])) $rws = 1;
if (isset($_POST['testing'])) $testing = 1;
if (isset($_POST['rs'])) $rs = 1;
$name = $db->qstr($_POST['description'],get_magic_quotes_gpc());
$rs_intro = $db->qstr($_POST['rs_intro'],get_magic_quotes_gpc());
$rs_project_intro = $db->qstr($_POST['rs_project_intro'],get_magic_quotes_gpc());
$rs_project_end = $db->qstr($_POST['rs_project_end'],get_magic_quotes_gpc());
$rs_callback = $db->qstr($_POST['rs_callback'],get_magic_quotes_gpc());
$rs_answeringmachine = $db->qstr($_POST['rs_answeringmachine'],get_magic_quotes_gpc());
if ($_POST['select'] == "new")
{
//create one from scratch
include("../functions/functions.limesurvey.php");
$lime_sid = create_limesurvey_questionnaire($name);
}else if ($_POST['select'] == "quexml")
{
//create from queXML
}else
{
//use existing lime instrument
$lime_sid = bigintval($_POST['select']);
}
$sql = "INSERT INTO questionnaire (questionnaire_id,description,lime_sid,restrict_appointments_shifts,restrict_work_shifts,respondent_selection,rs_intro,rs_project_intro,rs_project_end,rs_callback,rs_answeringmachine,testing)
VALUES (NULL,$name,'$lime_sid','$ras','$rws','$rs',$rs_intro,$rs_project_intro,$rs_project_end,$rs_callback,$rs_answeringmachine,'$testing')";
$rs = $db->Execute($sql);
if ($rs)
{
$qid = $db->Insert_ID();
print "<p>Successfully inserted $name as questionnaire $qid, linked to $lime_sid</p>";
}else
{
print "<p>Error: Failed to insert questionnaire</p>";
}
}
//create new questionnaire
?>
<form enctype="multipart/form-data" action="" method="post">
<p><input type="hidden" name="MAX_FILE_SIZE" value="1000000000" /></p>
<p><? echo T_("Name for questionnaire:"); ?> <input type="text" name="description"/></p>
<p><? echo T_("Select creation type:"); ?> <select name="select"><option value="quexml"><? echo T_("Create from queXML"); ?></option><option value="new"><? echo T_("Create new questionnaire in Limesurvey"); ?></option><?
$sql = "SELECT s.sid as sid, sl.surveyls_title AS title
FROM " . LIME_PREFIX . "surveys AS s
LEFT JOIN " . LIME_PREFIX . "surveys_languagesettings AS sl ON ( s.sid = sl.surveyls_survey_id
AND sl.surveyls_language = 'en' )
WHERE s.active = 'Y'";
$surveys = $ldb->GetAll($sql);
foreach($surveys as $s)
{
print "<option value=\"{$s['sid']}\">" . T_("Existing questionnaire:") . " {$s['title']}</option>";
}
?></select></p>
<p><? echo T_("Choose the queXML file (if required):"); ?> <input name="file" type="file" /></p>
<p><? echo T_("Restrict appointments to shifts?"); ?> <input name="ras" type="checkbox" checked="checked"/></p>
<p><? echo T_("Restrict work to shifts?"); ?> <input name="rws" type="checkbox" checked="checked"/></p>
<p><? echo T_("Questionnaire for testing only?"); ?> <input name="testing" type="checkbox"/></p>
<p><? echo T_("Use respondent selection text?"); ?> <input name="rs" type="checkbox" checked="checked"/></p>
<p><? echo T_("Respondent selection introduction:"); ?> <input type="text" name="rs_intro"/></p>
<p><? echo T_("Respondent selection project introduction:"); ?> <input type="text" name="rs_project_intro"/></p>
<p><? echo T_("Respondent selection project end:"); ?> <input type="text" name="rs_project_end"/></p>
<p><? echo T_("Respondent selection callback (already started questionnaire):"); ?> <input type="text" name="rs_callback"/></p>
<p><? echo T_("Message to leave on an answering machine:"); ?> <input type="text" name="rs_answeringmachine"/></p>
<p><input type="submit" name="import_file"/></p>
</form>
<?
xhtml_foot();
?>

View File

@@ -0,0 +1,113 @@
<?php
/**
* Display operator performance
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*/
/**
* Configuration file
*/
include_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Performance functions
*/
include("../functions/functions.performance.php");
/**
* Display functions
*/
include("../functions/functions.display.php");
/**
* Input functions
*/
include("../functions/functions.input.php");
/**
* Operator functions
*/
include("../functions/functions.operator.php");
xhtml_head(T_("Operator Performance"),true,false,array("../js/window.js"));
$rs = get_CPH();
print "<h2>" . T_("Overall") . "</h2>";
xhtml_table($rs,array("firstName","completions","time","CPH"),array(T_("Operator"),T_("Completions"),T_("Total time"),T_("Completions per hour")),"tclass");
xhtml_table(get_effectiveness(),array("firstName","effectiveness"),array(T_("Operator"),T_("Effectiveness (proportion of time on a call in a case)")),"tclass");
$questionnaire_id = false;
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
display_questionnaire_chooser($questionnaire_id);
if ($questionnaire_id)
{
$rs = get_CPH_by_questionnaire($questionnaire_id);
print "<h2>" . T_("This project") . "</h2>";
xhtml_table($rs,array("firstName","completions","time","CPH"),array(T_("Operator"),T_("Completions"),T_("Total time"),T_("Completions per hour")),"tclass");
xhtml_table(get_effectiveness_by_questionnaire($questionnaire_id),array("firstName","effectiveness"),array(T_("Operator"),T_("Effectiveness (proportion of time on a call in a case)")),"tclass");
$operator_id = get_operator_id();
$shift_id = false;
if (isset($_GET['shift_id'])) $shift_id = bigintval($_GET['shift_id']);
$sql = "SELECT s.shift_id as value,CONCAT(DATE_FORMAT(CONVERT_TZ(s.start,'UTC',o.Time_zone_name),'" . DATE_TIME_FORMAT . "'),' " . T_("till") . " ',DATE_FORMAT(CONVERT_TZ(s.end,'UTC',o.Time_zone_name),'" . TIME_FORMAT . "')) as description,CASE WHEN s.shift_id = '$shift_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM shift as s
LEFT JOIN (operator as o) on (o.operator_id = '$operator_id')
WHERE s.questionnaire_id = '$questionnaire_id'
ORDER BY s.start ASC";
$rs = $db->GetAll($sql);
display_chooser($rs,"shift_id","shift_id",true,"questionnaire_id=$questionnaire_id");
if ($shift_id)
{
$rs = get_CPH_by_shift($questionnaire_id,$shift_id);
print "<h2>" . T_("This shift") . "</h2>";
xhtml_table($rs,array("firstName","completions","time","CPH"),array(T_("Operator"),T_("Completions"),T_("Total time"),T_("Completions per hour")),"tclass");
}
}
xhtml_foot();
?>

View File

@@ -0,0 +1,273 @@
<?
/**
* Assign operators to questionnaires in a checkbox matrix
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*/
/**
* Configuration file
*/
include ("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Return if an operator has already been assigned to this questionnaire
*
* @param int $operator_id Operator id
* @param int $questionnaire_id Questionnaire id
* @return int 1 if assigned otherwise 0
*
*/
function vq($operator_id,$questionnaire_id)
{
global $db;
$sql = "SELECT operator_id,questionnaire_id
FROM operator_questionnaire
WHERE operator_id = '$operator_id' and questionnaire_id = '$questionnaire_id'";
$vq = $db->Execute($sql);
return $vq->RecordCount();
}
/**
* Assign an operator to a questionnaire
*
* @param int $operator_id Operator id
* @param int $questionnaire_id Questionnaire id
*
*/
function vqi($operator_id,$questionnaire_id)
{
global $db;
$sql = "INSERT INTO
operator_questionnaire (operator_id,questionnaire_id)
VALUES('$operator_id','$questionnaire_id')";
$db->Execute($sql);
}
/**
* Unassign an operator from a questionnaire
*
* @param int $operator_id Operator id
* @param int $questionnaire_id Questionnaire id
*
*/
function vqd($operator_id,$questionnaire_id)
{
global $db;
$sql = "DELETE FROM
operator_questionnaire
WHERE operator_id = '$operator_id' and questionnaire_id = '$questionnaire_id'";
$db->Execute($sql);
}
if (isset($_POST['submit']))
{
$db->StartTrans();
$sql = "DELETE
FROM operator_questionnaire
WHERE 1";
$db->Execute($sql);
foreach ($_POST as $g => $v)
{
$a = explode("_",$g);
if ($a[0] == "cb")
vqi($a[2],$a[1]);
}
$db->CompleteTrans();
}
$sql = "SELECT questionnaire_id,description
FROM questionnaire
ORDER by questionnaire_id ASC";
$questionnaires = $db->GetAll($sql);
$sql = "SELECT operator_id,firstname as description
FROM operator
ORDER by operator_id ASC";
$operators = $db->GetAll($sql);
xhtml_head(T_("Assign operators to questionnaires"),false,array("../css/table.css"));
?>
<script type="text/javascript">
<?
print "questionnaire_id = new Array(";
$s = "";
foreach($questionnaires as $q)
{
$s .= "'{$q['questionnaire_id']}',";
}
$s = substr($s,0,strlen($s) - 1);
print "$s);\n";
print "operator_id = new Array(";
$s = "";
foreach($operators as $q)
{
$s .= "'{$q['operator_id']}',";
}
$s = substr($s,0,strlen($s) - 1);
print "$s);\n";
?>
var QidOn = 0;
var VidOn = 0;
function checkQid(q)
{
for (y in operator_id)
{
v = operator_id[y];
cb = document.getElementById('cb_' + q + "_" + v);
if (QidOn == 0)
cb.checked = 'checked';
else
cb.checked = '';
}
if (QidOn == 0)
QidOn = 1;
else
QidOn = 0;
}
function checkVid(v)
{
for (y in questionnaire_id)
{
q = questionnaire_id[y];
cb = document.getElementById('cb_' + q + "_" + v);
if (VidOn == 0)
cb.checked = 'checked';
else
cb.checked = '';
}
if (VidOn == 0)
VidOn = 1;
else
VidOn = 0;
}
</script>
</head>
<body>
<?
print "<form action=\"\" method=\"post\"><table>";
print "<tr><th></th>";
foreach($questionnaires as $q)
{
print "<th><a href=\"javascript:checkQid({$q['questionnaire_id']})\">{$q['description']}</a></th>";
}
print "</tr>";
$class = 0;
foreach($operators as $v)
{
print "<tr class='";
if ($class == 0) {$class = 1; print "even";} else {$class = 0; print "odd";}
print "'>";
print "<th><a href=\"javascript:checkVid({$v['operator_id']})\">{$v['description']}</a></th>";
foreach($questionnaires as $q)
{
$checked = "";
if (vq($v['operator_id'],$q['questionnaire_id'])) $checked="checked=\"checked\"";
print "<td><input type=\"checkbox\" name=\"cb_{$q['questionnaire_id']}_{$v['operator_id']}\" id=\"cb_{$q['questionnaire_id']}_{$v['operator_id']}\" $checked></input></td>";
}
print "</tr>";
}
print "</table><p><input type=\"submit\" name=\"submit\"/></p></form>";
xhtml_foot();
?>

137
admin/operators.php Normal file
View File

@@ -0,0 +1,137 @@
<?
/**
* Create an operator and link to a webserver username for authentication
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*
* @todo Make timezone a drop down list
*
*/
/**
* Configuration file
*/
include ("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
global $db;
$a = false;
if (isset($_POST['operator']))
{
$operator = $db->qstr($_POST['operator'],get_magic_quotes_gpc());
$firstname = $db->qstr($_POST['firstname'],get_magic_quotes_gpc());
$lastname = $db->qstr($_POST['lastname'],get_magic_quotes_gpc());
$time_zone_name = $db->qstr($_POST['Time_zone_name'],get_magic_quotes_gpc());
$extension = $db->qstr($_POST['extension'],get_magic_quotes_gpc());
$supervisor = 0;
$temporary = 0;
$refusal = 0;
if (isset($_POST['supervisor']) && $_POST['supervisor'] == "on") $supervisor = 1;
if (isset($_POST['refusal']) && $_POST['refusal'] == "on") $refusal = 1;
if (isset($_POST['temporary']) && $_POST['temporary'] == "on") $temporary = 1;
if (!empty($_POST['operator']))
{
$sql = "INSERT INTO operator
(`operator_id` ,`username` ,`firstName` ,`lastName`, `extension`, `Time_zone_name`)
VALUES (NULL , $operator, $firstname , $lastname, $extension, $time_zone_name);";
if ($db->Execute($sql))
{
$a = "Added: $operator";
$oid = $db->Insert_ID();
if ($temporary)
{
$db->Execute(" INSERT INTO operator_skill (operator_id,outcome_type_id)
VALUES ('$oid','1')");
$db->Execute(" INSERT INTO operator_skill (operator_id,outcome_type_id)
VALUES ('$oid','5')"); //and appointment
}
if ($supervisor)
$db->Execute(" INSERT INTO operator_skill (operator_id,outcome_type_id)
VALUES ('$oid','2')");
if ($refusal)
$db->Execute(" INSERT INTO operator_skill (operator_id,outcome_type_id)
VALUES ('$oid','3')");
}else
{
$a = "Could not add $operator. There may already be an operator of this name";
}
}
}
xhtml_head(T_("Add an operator"));
if ($a)
{
?>
<h3><? echo $a; ?></h3>
<?
}
?>
<h1><? echo T_("Add an operator"); ?></h1>
<p><? echo T_("Adding an operator here will give the user the ability to call cases"); ?> <a href="operatorquestionnaire.php"><? echo T_("Assign Operator to Questionnaire"); ?></a> <? echo T_("tool"); ?>.</p>
<p><? echo T_("Use this form to enter the username of a user based on your directory security system. For example, if you have secured the base directory of queXS using Apache file based security, enter the usernames of the users here."); ?></p>
<form enctype="multipart/form-data" action="" method="post">
<p><? echo T_("Enter the username of an operator to add:"); ?> <input name="operator" type="text"/></p>
<p><? echo T_("Enter the first name of an operator to add:"); ?> <input name="firstname" type="text"/></p>
<p><? echo T_("Enter the surname of an operator to add:"); ?> <input name="lastname" type="text"/></p>
<p><? echo T_("Enter the Time Zone of an operator to add:"); ?> <input name="Time_zone_name" type="text" value="<? echo DEFAULT_TIME_ZONE; ?>"/></p>
<p><? echo T_("Enter the telephone extension number:"); ?> <input name="extension" type="text"/></p>
<p><? echo T_("Is the operator a normal interviewer?"); ?> <input name="temporary" type="checkbox" checked="checked"/></p>
<p><? echo T_("Is the operator a supervisor?"); ?> <input name="supervisor" type="checkbox"/></p>
<p><? echo T_("Is the operator a refusal converter?"); ?> <input name="refusal" type="checkbox"/></p>
<p><input type="submit" value="<? echo T_("Add user"); ?>" /></p>
</form>
<?
xhtml_foot();
?>

272
admin/operatorskill.php Normal file
View File

@@ -0,0 +1,272 @@
<?
/**
* Assign operators to skills in a checkbox matrix
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*/
/**
* Configuration file
*/
include ("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Determine if an operator has been assigned to a skill (outcome_type)
*
* @param int $operator_id Operator id
* @param int $outcome_type_id Outcome type id (skill)
* @return int 1 if assigned to that skill otherwise 0
*
*/
function vq($operator_id,$outcome_type_id)
{
global $db;
$sql = "SELECT operator_id,outcome_type_id
FROM operator_skill
WHERE operator_id = '$operator_id' and outcome_type_id = '$outcome_type_id'";
$vq = $db->Execute($sql);
return $vq->RecordCount();
}
/**
* Assign an operator to a skill (outcome_type)
*
* @param int $operator_id Operator id
* @param int $outcome_type_id Outcome type id (skill)
*
*/
function vqi($operator_id,$outcome_type_id)
{
global $db;
$sql = "INSERT INTO
operator_skill (operator_id,outcome_type_id)
VALUES('$operator_id','$outcome_type_id')";
$db->Execute($sql);
}
/**
* Delete a skill (outcome_type) from an operator
*
* @param int $operator_id Operator id
* @param int $outcome_type_id Outcome type id (skill)
*
*/
function vqd($operator_id,$outcome_type_id)
{
global $db;
$sql = "DELETE FROM
operator_skill
WHERE operator_id = '$operator_id' and outcome_type_id = '$outcome_type_id'";
$db->Execute($sql);
}
if (isset($_POST['submit']))
{
$db->StartTrans();
$sql = "DELETE
FROM operator_skill
WHERE 1";
$db->Execute($sql);
foreach ($_POST as $g => $v)
{
$a = explode("_",$g);
if ($a[0] == "cb")
vqi($a[2],$a[1]);
}
$db->CompleteTrans();
}
$sql = "SELECT outcome_type_id,description
FROM outcome_type
ORDER by outcome_type_id ASC";
$outcome_types = $db->GetAll($sql);
$sql = "SELECT operator_id,firstname as description
FROM operator
ORDER by operator_id ASC";
$operators = $db->GetAll($sql);
xhtml_head(T_("Assign operators to Skills"),false,array("../css/table.css"));
?>
<script type="text/javascript">
<?
print "outcome_type_id = new Array(";
$s = "";
foreach($outcome_types as $q)
{
$s .= "'{$q['outcome_type_id']}',";
}
$s = substr($s,0,strlen($s) - 1);
print "$s);\n";
print "operator_id = new Array(";
$s = "";
foreach($operators as $q)
{
$s .= "'{$q['operator_id']}',";
}
$s = substr($s,0,strlen($s) - 1);
print "$s);\n";
?>
var QidOn = 0;
var VidOn = 0;
function checkQid(q)
{
for (y in operator_id)
{
v = operator_id[y];
cb = document.getElementById('cb_' + q + "_" + v);
if (QidOn == 0)
cb.checked = 'checked';
else
cb.checked = '';
}
if (QidOn == 0)
QidOn = 1;
else
QidOn = 0;
}
function checkVid(v)
{
for (y in outcome_type_id)
{
q = outcome_type_id[y];
cb = document.getElementById('cb_' + q + "_" + v);
if (VidOn == 0)
cb.checked = 'checked';
else
cb.checked = '';
}
if (VidOn == 0)
VidOn = 1;
else
VidOn = 0;
}
</script>
</head>
<body>
<?
print "<form action=\"\" method=\"post\"><table>";
print "<tr><th></th>";
foreach($outcome_types as $q)
{
print "<th><a href=\"javascript:checkQid({$q['outcome_type_id']})\">{$q['description']}</a></th>";
}
print "</tr>";
$ct = 1;
foreach($operators as $v)
{
print "<tr class='";
if ($ct == 1) {$ct = 0; print "even";} else {$ct = 1; print "odd";}
print "'>";
print "<th><a href=\"javascript:checkVid({$v['operator_id']})\">{$v['description']}</a></th>";
foreach($outcome_types as $q)
{
$checked = "";
if (vq($v['operator_id'],$q['outcome_type_id'])) $checked="checked=\"checked\"";
print "<td><input type=\"checkbox\" name=\"cb_{$q['outcome_type_id']}_{$v['operator_id']}\" id=\"cb_{$q['outcome_type_id']}_{$v['operator_id']}\" $checked></input></td>";
}
print "</tr>";
}
print "</table><p><input type=\"submit\" name=\"submit\"/></p></form>";
xhtml_foot();
?>

172
admin/outcomes.php Normal file
View File

@@ -0,0 +1,172 @@
<?php
/**
* Display outcomes by questionnaire
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*/
/**
* Configuration file
*/
include_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* AAPOR calculation functions
*/
include ("../functions/functions.aapor.php");
/**
* Display functions
*/
include ("../functions/functions.display.php");
/**
* Performance functions
*/
include ("../functions/functions.performance.php");
/**
* Operator functions
*/
include ("../functions/functions.operator.php");
/**
* Input functions
*/
include("../functions/functions.input.php");
$operator_id = get_operator_id();
$questionnaire_id = false;
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
xhtml_head(T_("Questionnaire Outcomes"),true,array("../css/table.css"),array("../js/window.js"));
print "<h3>" . T_("Select a questionnaire from the list below") . "</h3>";
display_questionnaire_chooser($questionnaire_id);
if ($questionnaire_id != false)
{
print "<h1>" . T_("Outcomes") . "</h1>";
print "<p>" . T_("Sample status") . "</p>";
$sql = "SELECT CASE WHEN (c.sample_id is not null) = 1 THEN '" . T_("Drawn from sample") . "' ELSE '" . T_("Remain in sample") . "' END as drawn,
count(*) as count
FROM sample as s
JOIN questionnaire_sample as qs ON (qs.questionnaire_id = '$questionnaire_id' and qs.sample_import_id = s.import_id)
LEFT JOIN `case` as c ON (c.questionnaire_id = qs.questionnaire_id and c.sample_id = s.sample_id)
GROUP BY (c.sample_id is not null)";
xhtml_table($db->GetAll($sql),array("drawn","count"),array(T_("Status"),T_("Number")));
$atime = get_average_time_questionnaire(10,$questionnaire_id);
$mins = intval($atime / 60);
$secs = $atime % 60;
print "<p>" . T_("Average time on a completed questionnaire") . ": $mins " . T_("Min") . " $secs " . T_("Secs") . "</p>";
$sql = "SELECT o.calc, count( c.case_id )
FROM `case` AS c, `outcome` AS o
WHERE c.questionnaire_id = '$questionnaire_id'
AND c.current_outcome_id = o.outcome_id
GROUP BY o.calc";
$a = $db->GetAssoc($sql);
$a = aapor_clean($a);
print "<table><tr><th>" . T_("Outcome") . "</th><th>" . T_("Rate") . "</th></tr>";
print "<tr><td>" . T_("Response Rate 1") . "</td><td>" . round(aapor_rr1($a),2) . "</td></tr>";
print "<tr><td>" . T_("Refusal Rate 1") . "</td><td>" . round(aapor_ref1($a),2) . "</td></tr>";
print "<tr><td>" . T_("Cooperation Rate 1") . "</td><td>" . round(aapor_coop1($a),2) . "</td></tr>";
print "<tr><td>" . T_("Contact Rate 1") . "</td><td>" . round(aapor_con1($a),2) . "</td></tr>";
print "</table>";
$sql = "SELECT o.description as des, o.outcome_id, count( c.case_id ) as count
FROM `case` AS c, `outcome` AS o
WHERE c.questionnaire_id = '$questionnaire_id'
AND c.current_outcome_id = o.outcome_id
GROUP BY o.outcome_id";
$rs = $db->GetAll($sql);
if (!empty($rs))
xhtml_table($rs,array("des","count"),array(T_("Outcome"),T_("Count")),"tclass",array("des" => "Complete"));
else
print "<p>" . T_("No outcomes recorded for this questionnaire") . "</p>";
//display a list of shifts with completions and a link to either add a report or view reports
print "<h2>" . T_("Shifts") . "</h2>";
$sql = "SELECT s.shift_id, CONCAT(DATE_FORMAT(CONVERT_TZ(s.start,'UTC',o.Time_zone_name),'" . DATE_TIME_FORMAT ."'), ' - ', DATE_FORMAT(CONVERT_TZ(s.end,'UTC',o.Time_zone_name),'" . DATE_TIME_FORMAT ."')) as description,
CASE WHEN sr.shift_id IS NULL THEN CONCAT('<a href=\'shiftreport.php?questionnaire_id=$questionnaire_id&amp;shift_id=', s.shift_id, '&amp;createnewreport=yes\'>" . T_("No shift reports: Add report") . "</a>') ELSE CONCAT('<a href=\'shiftreport.php?questionnaire_id=$questionnaire_id&amp;shift_id=', s.shift_id, '\'>" . T_("View shift reports") . "</a>') END AS link, c.completions as completions, CONCAT('<a href=\'operatorperformance.php?questionnaire_id=$questionnaire_id&amp;shift_id=', s.shift_id, '\'>" . T_("View operator performance") . "</a>') as operform
FROM `shift` as s
JOIN operator as o on (o.operator_id = '$operator_id')
LEFT JOIN shift_report as sr on (sr.shift_id = s.shift_id)
LEFT JOIN ( SELECT count(*) as completions,sh.shift_id
FROM `call` as a, `case` as b, shift as sh
WHERE a.outcome_id = '10'
AND a.case_id = b.case_id
AND b.questionnaire_id = '$questionnaire_id'
AND sh.start <= a.start
AND sh.end >= a.start
GROUP BY sh.shift_id) as c on (s.shift_id = c.shift_id)
WHERE s.questionnaire_id = '$questionnaire_id'
GROUP BY shift_id
ORDER BY s.start ASC";
$r = $db->GetAll($sql);
if (empty($r))
print "<p>" . T_("No shifts defined for this questionnaire") . "</p>";
else
xhtml_table($r,array("description","completions","link","operform"),array(T_("Shift"),T_("Completions"),T_("Shift report"),T_("Operator performance")),"tclass");
}
xhtml_foot();
?>

View File

@@ -0,0 +1,172 @@
<?
/**
* Select and set questions to pre fill in the questionnaire
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*
*/
/**
* Configuration file
*/
include("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include("../functions/functions.xhtml.php");
/**
* Display functions
*/
include("../functions/functions.display.php");
/**
* Input functions
*/
include("../functions/functions.input.php");
global $db;
if (isset($_GET['questionnaire_id']) && isset($_GET['sgqa']) && isset($_GET['value']))
{
//need to add prefill to questionnaire
$questionnaire_id = bigintval($_GET['questionnaire_id']);
$value = $db->quote($_GET['value']);
$sgqa = $db->quote($_GET['sgqa']);
$sql = "INSERT INTO questionnaire_prefill(questionnaire_id,lime_sgqa,value)
VALUES('$questionnaire_id',$sgqa,$value)";
$db->Execute($sql);
}
if (isset($_GET['questionnaire_id']) && isset($_GET['questionnaire_prefill_id']))
{
//need to remove prefill from questionnaire
$questionnaire_id = bigintval($_GET['questionnaire_id']);
$questionnaire_prefill_id = bigintval($_GET['questionnaire_prefill_id']);
$sql = "DELETE FROM questionnaire_prefill
WHERE questionnaire_prefill_id = '$questionnaire_prefill_id'";
$db->Execute($sql);
}
$questionnaire_id = false;
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
xhtml_head(T_("Pre fill questionnaire: Set values for questionnaire to prefill"),true,false,array("../js/window.js"));
print "<h1>" . T_("Select a questionnaire from the list below") . "</h1>";
$sql = "SELECT questionnaire_id as value,description, CASE WHEN questionnaire_id = '$questionnaire_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM questionnaire";
display_chooser($db->GetAll($sql),"questionnaire","questionnaire_id");
if ($questionnaire_id != false)
{
print "<h1>" . T_("Current pre fills (click to delete)") . "</h1>";
$sql = "SELECT questionnaire_prefill_id,lime_sgqa,value
FROM questionnaire_prefill
WHERE questionnaire_id = '$questionnaire_id'";
$r = $db->GetAll($sql);
if (empty($r))
{
print "<p>" . T_("Currently no pre fills") . "</p>";
}
else
{
foreach($r as $v)
{
print "<div><a href='?questionnaire_id=$questionnaire_id&amp;questionnaire_prefill_id={$v['questionnaire_prefill_id']}'>{$v['lime_sgqa']}: {$v['value']}</a></div>";
}
}
print "<h1>" . T_("Select a question to pre fill") . "</h1>";
$sql = "SELECT lime_sid
FROM questionnaire
WHERE questionnaire_id = '$questionnaire_id'";
$r = $db->GetRow($sql);
$lime_sid = $r['lime_sid'];
$sgqa = false;
if (isset($_GET['sgqa'])) $sgqa = $_GET['sgqa'];
$sql = "SELECT CONCAT( q.sid, 'X', q.gid, 'X', q.qid, IFNULL( a.code, '' ) ) AS value, CONCAT(q.question, ': ', IFNULL(a.answer,'')) as description, CASE WHEN CONCAT( q.sid, 'X', q.gid, 'X', q.qid, IFNULL( a.code, '' ) ) = '$sgqa' THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM `" . LIME_PREFIX . "questions` AS q
LEFT JOIN `" . LIME_PREFIX . "answers` AS a ON ( a.qid = q.qid )
WHERE q.sid = '$lime_sid'";
display_chooser($ldb->GetAll($sql),"sgqa","sgqa",true,"questionnaire_id=$questionnaire_id");
if ($sgqa != false)
{
print "<h1>" . T_("Enter a value to pre fill this question with:") . "</h1>";
print "<p>";
print T_("Possible uses:");
print "</p><ul>";
print "<li>" . T_("{Respondent:firstName} First name of the respondent") . "</li>";
print "<li>" . T_("{Respondent:lastName} Last name of the respondent") . "</li>";
print "<li>" . T_("{Sample:var} A record from the sample where the column name is 'var'") . "</li>";
print "</ul>";
?>
<form action="" method="get">
<p>
<label for="value"><? echo T_("The value to pre fill"); ?> </label><input type="text" name="value" id="value"/> <br/>
<input type="hidden" name="questionnaire_id" value="<? print($questionnaire_id); ?>"/>
<input type="hidden" name="sgqa" value="<? print($sgqa); ?>"/>
<input type="submit" name="add_prefill" value="Add pre fill"/></p>
</form>
<?
}
}
xhtml_foot();
?>

165
admin/samplesearch.php Normal file
View File

@@ -0,0 +1,165 @@
<?
/**
* Select and search within a sample to see what case(s) is/are assigned to a sample record
* and if so to look at them, otherwise give the option to remove a sample record
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*
*/
/**
* Configuration file
*/
include("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include("../functions/functions.xhtml.php");
/**
* Input functions
*/
include("../functions/functions.input.php");
global $db;
if (isset($_GET['sample_id']))
{
//need to remove this sample record from the sample
$sample_id = bigintval($_GET['sample_id']);
$db->StartTrans();
$sql = "DELETE FROM sample_var
WHERE sample_id = '$sample_id'";
$db->Execute($sql);
$sql = "DELETE FROM sample
WHERE sample_id = '$sample_id'";
$db->Execute($sql);
$db->CompleteTrans();
}
$sample_import_id = false;
if (isset($_GET['sample_import_id'])) $sample_import_id = bigintval($_GET['sample_import_id']);
xhtml_head(T_("Search sample"),true,array("../css/table.css"),array("../js/window.js"));
print "<h1>" . T_("Select a sample from the list below") . "</h1>";
$sql = "SELECT sample_import_id as value,description, CASE WHEN sample_import_id = '$sample_import_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM sample_import";
$r = $db->GetAll($sql);
if(!empty($r))
display_chooser($r,"sample_import_id","sample_import_id");
if ($sample_import_id != false)
{
if (isset($_GET['search']))
{
$search = $db->qstr($_GET['search']);
$sql = "SELECT sv.sample_id, CASE WHEN c.case_id IS NULL THEN CONCAT('<a href=\'?sample_import_id=$sample_import_id&amp;sample_id=', sv.sample_id , '\'>" . T_("No cases yet assigned: Delete this sample record") . "</a>') ELSE CONCAT('<a href=\'supervisor.php?case_id=', c.case_id , '\'>" . T_("Assigned to questionnaire: ") . "', q.description, '</a>') END as link
FROM sample_var AS sv
JOIN (sample as s) ON (s.import_id = '$sample_import_id' and sv.sample_id = s.sample_id)
LEFT JOIN (`case` AS c, questionnaire AS q) ON ( c.sample_id = sv.sample_id AND q.questionnaire_id = c.questionnaire_id )
WHERE sv.val LIKE $search";
$r = $db->GetAll($sql);
if (empty($r))
print "<p>" . T_("No records in this sample match this search criteria") . "</p>";
else
{
//add sample information to results
$sql = "SELECT var
FROM sample_var
WHERE sample_id = {$r[0]['sample_id']}";
$rs = $db->GetAll($sql);
$fnames = array("sample_id");
$fdesc = array(T_("Sample id"));
foreach($rs as $rsw)
{
$fnames[] = $rsw['var'];
$fdesc[] = $rsw['var'];
}
$fnames[] = "link";
$fdesc[] = T_("Link");
foreach($r as &$rw)
{
$sql = "SELECT var,val
FROM sample_var
WHERE sample_id = {$rw['sample_id']}";
$rs = $db->GetAll($sql);
foreach($rs as $rsw)
$rw[$rsw['var']] = $rsw['val'];
}
xhtml_table($r,$fnames,$fdesc);
}
}
print "<h1>" . T_("Search within this sample") . "</h1>";
print "<p>" . T_("Use the % character as a wildcard") ."</p>";
?>
<form action="" method="get">
<p>
<label for="search"><? echo T_("Search for:"); ?></label><input type="text" name="search" id="search"/><br/>
<input type="hidden" name="sample_import_id" value="<? print($sample_import_id); ?>"/>
<input type="submit" name="searchsub" value="<? echo T_("Start search"); ?>"/>
</p>
</form>
<?
}
xhtml_foot();
?>

177
admin/shiftreport.php Normal file
View File

@@ -0,0 +1,177 @@
<?php
/**
* List and edit reports on shifts
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*/
/**
* Configuration file
*/
include_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Display functions
*/
include("../functions/functions.display.php");
/**
* Operator functions
*/
include("../functions/functions.operator.php");
/**
* Input functions
*/
include("../functions/functions.input.php");
xhtml_head(T_("Shift reports"),true,array("../css/table.css"),array("../js/window.js"));
$operator_id = get_operator_id();
print "<h3>" . T_("Please select a questionnaire") . "</h3>";
$questionnaire_id = false;
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
display_questionnaire_chooser($questionnaire_id);
if ($questionnaire_id)
{
print "<h3>" . T_("Please select a shift") . "</h3>";
$shift_id = false;
if (isset($_GET['shift_id'])) $shift_id = bigintval($_GET['shift_id']);
//get shifts for this questionnaire in operator time
$sql = "SELECT s.shift_id as value, CONCAT(DATE_FORMAT(CONVERT_TZ(s.start,'UTC',o.Time_zone_name),'" . DATE_TIME_FORMAT ."'), ' - ', DATE_FORMAT(CONVERT_TZ(s.end,'UTC',o.Time_zone_name),'" . TIME_FORMAT ."')) as description,
CASE WHEN s.shift_id = '$shift_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM `shift` as s, operator as o
WHERE s.questionnaire_id = '$questionnaire_id'
AND o.operator_id = '$operator_id'
ORDER BY s.start ASC";
$r = $db->GetAll($sql);
if (!empty($r))
display_chooser($r,"shift","shift_id",true,"questionnaire_id=$questionnaire_id");
if ($shift_id)
{
print "<h3>" . T_("Reports for this shift") . "</h3>";
//list current reports with a link to edit
$sql = "SELECT s.report,o.firstName,DATE_FORMAT(CONVERT_TZ(s.datetime,'UTC',o.Time_zone_name),'" . DATE_TIME_FORMAT ."') as d,
CONCAT('<a href=\'?questionnaire_id=$questionnaire_id&amp;shift_id=$shift_id&amp;shift_report_id=', s.shift_report_id, '\'>". T_("Edit") . "</a>') as link
FROM shift_report as s, operator as o
WHERE s.operator_id = o.operator_id
AND s.shift_id = '$shift_id'";
$r = $db->GetAll($sql);
if (!empty($r))
xhtml_table($r,array("firstName", "d", "report","link"),array(T_("Operator"),T_("Date"),T_("Report"),T_("Edit")),"tclass");
//link to create a new report
print "<p><a href='?questionnaire_id=$questionnaire_id&amp;shift_id=$shift_id&amp;createnewreport=yes'>" . T_("Create new report for this shift") . "</a></p>";
if (isset($_GET['createnewreport']))
{
//create a new report
print "<h3>" . T_("Enter report for this shift") . "</h3>";
print "<form action='?' method='get'><p><textarea name='report' id='report' rows='15' cols='80'></textarea></p>";
print "<p><input type='hidden' name='questionnaire_id' id='questionnaire_id' value='$questionnaire_id'/>";
print "<input type='hidden' name='shift_id' id='shift_id' value='$shift_id'/>";
print "<input type='submit' name='submit' id='submit' value='" . T_("Add report") . "'/>";
print "</p></form>";
}
else if (isset($_GET['report']))
{
//add report to database
$report = $db->qstr($_GET['report']);
$sql = "INSERT INTO shift_report (shift_id,operator_id,datetime,report,shift_report_id)
VALUES ('$shift_id','$operator_id',CONVERT_TZ(NOW(),'System','UTC'),$report,NULL)";
$db->Execute($sql);
}
else if (isset($_GET['shift_report_id']))
{
$shift_report_id = bigintval($_GET['shift_report_id']);
if (isset($_GET['ereport']))
{
//edit report
$report = $db->qstr($_GET['ereport']);
$sql = "UPDATE shift_report
SET operator_id = '$operator_id', datetime = CONVERT_TZ(NOW(),'System','UTC'), report = $report
WHERE shift_report_id = '$shift_report_id'";
$db->Execute($sql);
}
$sql = "SELECT report
FROM shift_report
WHERE shift_report_id = '$shift_report_id'";
$r = $db->GetRow($sql);
if (empty($r))
{
print "<h3>" . T_("This report does not exist in the database") . "</h3>";
}
else
{
//edit report
print "<h3>" . T_("Edit report for this shift") . "</h3>";
print "<form action='?' method='get'><p><textarea name='ereport' id='ereport' rows='15' cols='80'>{$r['report']}</textarea></p>";
print "<p><input type='hidden' name='questionnaire_id' id='questionnaire_id' value='$questionnaire_id'/>";
print "<input type='hidden' name='shift_id' id='shift_id' value='$shift_id'/>";
print "<input type='hidden' name='shift_report_id' id='shift_report_id' value='$shift_report_id'/>";
print "<input type='submit' name='submit' id='submit' value='" . T_("Modify report") . "'/>";
print "</p></form>";
}
}
}
}
xhtml_foot();
?>

234
admin/supervisor.php Normal file
View File

@@ -0,0 +1,234 @@
<?
/**
* View cases referred to the supervisor and add notes/assign outcomes
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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
*
*
*/
/**
* Configuration file
*/
include("../config.inc.php");
/**
* Database file
*/
include ("../db.inc.php");
/**
* XHTML functions
*/
include("../functions/functions.xhtml.php");
/**
* Display functions
*/
include("../functions/functions.display.php");
/**
* Operator functions
*/
include("../functions/functions.operator.php");
/**
* Input functions
*/
include("../functions/functions.input.php");
global $db;
$operator_id = get_operator_id();
$case_id = false;
if (isset($_GET['case_id'])) $case_id = bigintval($_GET['case_id']);
xhtml_head(T_("Supervisor functions"),true,array("../css/table.css"),array("../js/window.js"));
print "<h1>" . T_("Enter a case id or select a case from the list below:") . "</h1>";
$sql = "SELECT c.case_id as value, c.case_id as description, CASE WHEN c.case_id = '$case_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM `case` as c, `outcome` as o
WHERE c.current_outcome_id = o.outcome_id
AND o.outcome_type_id = 2";
$rs = $db->GetAll($sql);
if (!empty($rs))
{
print "<div><label for=\"case\">". T_("Select case from list of cases referred to the supervisor:") . " </label>";
display_chooser($rs,"case","case_id");
print "</div>";
}
?>
<form action="" method="get">
<p>
<label for="case_id"><? echo T_("Case id:"); ?> </label><input type="text" name="case_id" id="case_id" value="<? echo $case_id; ?>"/>
<input type="submit" name="case_form" value="<? echo T_("Select case"); ?>"/></p>
</form>
<?
if (isset($_GET['call_id']))
{
$call_id = bigintval($_GET['call_id']);
if (isset($_GET['set_outcome_id']))
{
$outcome_id = bigintval($_GET['set_outcome_id']);
$sql = "UPDATE `call`
SET outcome_id = '$outcome_id'
WHERE call_id = '$call_id'";
$db->Execute($sql);
}
else
{
print "<h3>" . T_("Set an outcome for this call") . "</h3>";
?>
<form method="get" action="?">
<?
$sql = "SELECT o.outcome_id as value,description, CASE WHEN o.outcome_id = c.outcome_id THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM outcome as o, `call` as c
WHERE c.call_id = '$call_id'";
display_chooser($db->GetAll($sql), "set_outcome_id", "set_outcome_id",true,false,false);
?>
<p><input type="hidden" name="call_id" value="<? echo $call_id;?>"/><input type="hidden" name="case_id" value="<? echo $case_id;?>"/><input class="submitclass" type="submit" name="submit" value="<? echo T_("Set outcome"); ?>"/></p>
</form>
<?
}
}
if ($case_id != false)
{
if (isset($_GET['note']))
{
$note = $db->qstr($_GET['note']);
$sql = "INSERT INTO `case_note` (case_note_id,case_id,operator_id,note,datetime)
VALUES (NULL,'$case_id','$operator_id',$note,CONVERT_TZ(NOW(),'System','UTC'))";
$db->Execute($sql);
}
if (isset($_GET['outcome_id']))
{
$outcome_id = bigintval($_GET['outcome_id']);
$sql = "UPDATE `case`
SET current_outcome_id = $outcome_id
WHERE case_id = '$case_id'";
$db->Execute($sql);
}
$sql = "SELECT o.description,o.outcome_id, q.description as qd, si.description as sd
FROM `case` as c, `outcome` as o, questionnaire as q, sample as s, sample_import as si
WHERE c.case_id = '$case_id'
AND q.questionnaire_id = c.questionnaire_id
AND s.sample_id = c.sample_id
AND si.sample_import_id = s.import_id
AND c.current_outcome_id = o.outcome_id";
$rs = $db->GetRow($sql);
if (!empty($rs))
{
print "<h1>" . T_("Project") . ": {$rs['qd']}</h1>";
print "<h1>" . T_("Sample") . ": {$rs['sd']}</h1>";
print "<h2>". T_("Current outcome:") ." {$rs['description']}</h2>";
$current_outcome_id = $rs['outcome_id'];
//view calls and outcomes
$sql = "SELECT DATE_FORMAT(CONVERT_TZ(c.start,'UTC',r.Time_zone_name),'".DATE_TIME_FORMAT."') as start,CONVERT_TZ(c.end,'UTC',r.Time_zone_name) as end, op.firstName, op.lastName, o.description as des, CONCAT('<a href=\'?case_id=$case_id&amp;call_id=', c.call_id, '\'>". T_("Edit") . "</a>') as link, cp.phone as phone
FROM `call` as c
JOIN (operator as op, outcome as o, respondent as r, contact_phone as cp) on (c.operator_id = op.operator_id and c.outcome_id = o.outcome_id and r.respondent_id = c.respondent_id and cp.contact_phone_id = c.contact_phone_id)
WHERE c.case_id = '$case_id'
ORDER BY c.start DESC";
$rs = $db->GetAll($sql);
print "<h3>" . T_("Call list")."</h3>";
if (empty($rs))
print "<p>" . T_("No calls made") . "</p>";
else
xhtml_table($rs,array("start","des","phone","link","firstName"),array(T_("Date/Time"),T_("Outcome"),T_("Phone number"),T_("Change outcome"),T_("Operator")));
//view notes
$sql = "SELECT DATE_FORMAT(CONVERT_TZ(c.datetime,'UTC',op.Time_zone_name),'".DATE_TIME_FORMAT."') as time, op.firstName, op.lastName, c.note as note
FROM `case_note` as c
JOIN (operator as op) on (c.operator_id = op.operator_id)
WHERE c.case_id = '$case_id'
ORDER BY c.datetime DESC";
$rs = $db->GetAll($sql);
print "<h3>" . T_("Case notes")."</h3>";
if (empty($rs))
print "<p>" . T_("No notes") . "</p>";
else
xhtml_table($rs,array("time","firstName","note"),array(T_("Date/Time"),T_("Operator"),T_("Note")));
//add a note
?>
<form method="get" action="?">
<p>
<input type="hidden" name="case_id" value="<? echo $case_id;?>"/><input type="text" class="textclass" name="note" id="note"/><input class="submitclass" type="submit" name="submit" value="<? echo T_("Add note"); ?>"/>
</p>
</form>
<?
//set an outcome
print "<h3>" . T_("Set a case outcome") . "</h3>";
?>
<form method="get" action="?">
<?
$sql = "SELECT outcome_id as value,description, CASE WHEN outcome_id = '$current_outcome_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM outcome";
display_chooser($db->GetAll($sql), "outcome_id", "outcome_id",true,false,false);
?>
<p><input type="hidden" name="case_id" value="<? echo $case_id;?>"/><input class="submitclass" type="submit" name="submit" value="<? echo T_("Set outcome"); ?>"/></p>
</form>
<?
}
else
{
print "<h2>" . T_("Case does not exist") . "</h2>";
}
}
xhtml_foot();
?>

13
client/css/table.css Normal file
View File

@@ -0,0 +1,13 @@
tr.odd {
background-color: #eeeeee;
}
.tclass th {
text-align:left;
border: 1px solid #aaa;
}
.tclass td {
border: 1px solid #aaa;
}
.highlight {
background-color: #cccccc;
}

127
client/index.php Normal file
View File

@@ -0,0 +1,127 @@
<?php
/**
* Display outcomes for each questionnaire assigned to this client
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage client
* @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_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include_once(dirname(__FILE__).'/../db.inc.php');
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* AAPOR calculation functions
*/
include ("../functions/functions.aapor.php");
/**
* Client functions
*/
include ("../functions/functions.client.php");
$client_id = get_client_id();
xhtml_head(T_("Questionnaire Outcomes"),true,array("css/table.css"));
if ($client_id)
{
$sql = "SELECT q.questionnaire_id,q.description
FROM questionnaire as q, client_questionnaire as cq
WHERE cq.questionnaire_id = q.questionnaire_id
AND cq.client_id = '$client_id'";
$qs = $db->GetAll($sql);
if (empty($qs))
print "<p>" . T_("There are no questionnaires assigned to you") . "</p>";
else
{
foreach($qs as $q)
{
print "<h2>{$q['description']}</h2>";
$questionnaire_id = $q['questionnaire_id'];
$sql = "SELECT o.calc, count( c.case_id )
FROM `case` AS c, `outcome` AS o
WHERE c.questionnaire_id = '$questionnaire_id'
AND c.current_outcome_id = o.outcome_id
GROUP BY o.calc";
$a = $db->GetAssoc($sql);
$a = aapor_clean($a);
print "<table><tr><th>" . T_("Outcome") . "</th><th>" . T_("Rate") . "</th></tr>";
print "<tr><td>" . T_("Response Rate 1") . "</td><td>" . round(aapor_rr1($a),2) . "</td></tr>";
print "<tr><td>" . T_("Refusal Rate 1") . "</td><td>" . round(aapor_ref1($a),2) . "</td></tr>";
print "<tr><td>" . T_("Cooperation Rate 1") . "</td><td>" . round(aapor_coop1($a),2) . "</td></tr>";
print "<tr><td>" . T_("Contact Rate 1") . "</td><td>" . round(aapor_con1($a),2) . "</td></tr>";
print "</table>";
$sql = "SELECT o.description as des, o.outcome_id, count( c.case_id ) as count
FROM `case` AS c, `outcome` AS o
WHERE c.questionnaire_id = '$questionnaire_id'
AND c.current_outcome_id = o.outcome_id
GROUP BY o.outcome_id";
$rs = $db->GetAll($sql);
if (!empty($rs))
xhtml_table($rs,array("des","count"),array(T_("Outcome"),T_("Count")),"tclass",array("des" => "Complete"));
else
print "<p>" . T_("No outcomes recorded for this questionnaire") . "</p>";
}
}
}
else
print "<p>" . T_("You are not a valid client") . "</p>";
xhtml_foot();
?>

24
css/admin.css Normal file
View File

@@ -0,0 +1,24 @@
#menu {
position : fixed;
width : 20%;
height : 100%;
top : 0;
right : 0;
bottom : auto;
left : 0;
/*border-bottom: 1px solid #aaa;*/
}
#main {
position : fixed;
top : 0;
left : 20%;
bottom : auto;
width : 80%;
height : 100%;
}
.embeddedobject {
width:100%;
height:100%;
position:absolute;
}

29
css/call.css Normal file
View File

@@ -0,0 +1,29 @@
.label {
width:80%;
}
.radio {
float:right;
}
.status {
text-align:center;
}
.tclass th {
text-align:left;
border: 1px solid #aaa;
}
.tclass td {
border: 1px solid #aaa;
}
.labelclass{
width:20%;
}
.textclass {
width:70%;
height:80%;
}
.submitclass{
width:20%;
}
.addresp{
font-style:italic;
}

8
css/casenote.css Normal file
View File

@@ -0,0 +1,8 @@
.textclass {
width:70%;
height:80%;
}
.submitclass{
width:20%;
}

4
css/display.css Normal file
View File

@@ -0,0 +1,4 @@
h1 {font-family: Arial, sans-serif; font-size: 400%; text-align: center;}
h2 {font-family: Arial, sans-serif; font-size: 1100%; text-align: center;}
h3 {font-family: Arial, sans-serif; font-size: 150%; text-align: center;}
p {font-family: Arial, sans-serif; font-size: 100%;}

82
css/index.css Normal file
View File

@@ -0,0 +1,82 @@
.box {
margin: 8px;
}
.online {
background: #00FF00;
}
.offline {
background: #FF0000;
}
a {
padding: 3px 0.5em;
margin-left: 3px;
border: 1px solid #778;
background: #DDE;
text-decoration: none;
color: black;
}
a:active {
border: 4px inset;
}
#respondent {
position : fixed;
width : 20%;
height : 30%;
top : 0;
right : 0;
bottom : auto;
left : 0;
}
#header {
position : fixed;
width : 20%;
height : 30%;
top : 0;
right : 0;
bottom : auto;
left : 0;
/*border-bottom: 1px solid #aaa;*/
}
#calllist {
position : fixed;
width : 60%;
height : 30%;
top : 0;
right : 0;
bottom : auto;
}
#qstatus {
position : fixed;
width : 10%;
height : 30%;
top : 0;
right : 0;
left: 30%;
bottom : auto;
/*border: 1px solid #aaa;*/
}
#casefunctions {
position : fixed;
width : 10%;
height : 30%;
top : 0;
right : 0;
left: 20%;
bottom : auto;
}
#content {
position : fixed;
top : 30%;
left : 0;
bottom : auto;
width : 100%;
height : 70%;
}
.embeddedobject {
width:100%;
height:100%;
position:absolute;
}

16
css/respondent.css Normal file
View File

@@ -0,0 +1,16 @@
#details {
display: none;
}
.labelclass{
width:20%;
}
.textclass {
width:70%;
height:80%;
}
.submitclass{
width:20%;
}
.addresp{
font-style:italic;
}

6
css/rs.css Normal file
View File

@@ -0,0 +1,6 @@
body {background-color: #eeeeee;}
p.rstext {
font-weight: bold;
font-size: 16pt;
font-family: Arial, sans-serif;
}

22
css/status.css Normal file
View File

@@ -0,0 +1,22 @@
.statusbutton {
padding: 1px 1px;
margin: 1px;
border: 1px solid #778;
text-decoration: none;
color: black;
text-align: center;
float: left;
}
.online {
background: #00FF00;
}
.offline {
background: #FF0000;
}
.tobecoded {
background: orange;
}
.text {
float: left;
}

105
css/tabber.css Normal file
View File

@@ -0,0 +1,105 @@
/* $Id: example.css,v 1.5 2006/03/27 02:44:36 pat Exp $ */
/*--------------------------------------------------
REQUIRED to hide the non-active tab content.
But do not hide them in the print stylesheet!
--------------------------------------------------*/
.tabberlive .tabbertabhide {
display:none;
}
/*--------------------------------------------------
.tabber = before the tabber interface is set up
.tabberlive = after the tabber interface is set up
--------------------------------------------------*/
.tabber {
}
.tabberlive {
/*margin-top:1em;*/
}
/*--------------------------------------------------
ul.tabbernav = the tab navigation list
li.tabberactive = the active tab
--------------------------------------------------*/
ul.tabbernav
{
margin:0;
padding: 3px 0;
border-bottom: 1px solid #778;
font: bold 12px Verdana, sans-serif;
}
ul.tabbernav li
{
list-style: none;
margin: 0;
display: inline;
}
ul.tabbernav li a
{
padding: 3px 0.5em;
margin-left: 3px;
border: 1px solid #778;
border-bottom: none;
background: #DDE;
text-decoration: none;
}
ul.tabbernav li a:link { color: #448; }
ul.tabbernav li a:visited { color: #667; }
ul.tabbernav li a:hover
{
color: #000;
background: #AAE;
border-color: #227;
}
ul.tabbernav li.tabberactive a
{
background-color: #fff;
border-bottom: 1px solid #fff;
}
ul.tabbernav li.tabberactive a:hover
{
color: #000;
background: white;
border-bottom: 1px solid white;
}
/*--------------------------------------------------
.tabbertab = the tab content
Add style only after the tabber interface is set up (.tabberlive)
--------------------------------------------------*/
.tabberlive .tabbertab {
position:absolute;
border:1px solid #aaa;
border-top:0;
top: 1.25em;
left: 0;
right: 0;
bottom: 0;
overflow:auto;
}
/* If desired, hide the heading since a heading is provided by the tab */
.tabberlive .tabbertab h2 {
display:none;
}
.tabberlive .tabbertab h3 {
display:none;
}
/* Example of using an ID to set different styles for the tabs on the page*/
.tabberlive#tab1 {
}
.tabberlive#tab2 {
}
.tabberlive#tab2 .tabbertab {
height:100%;
overflow:auto;
}

13
css/table.css Normal file
View File

@@ -0,0 +1,13 @@
tr.odd {
background-color: #eeeeee;
}
.tclass th {
text-align:left;
border: 1px solid #aaa;
}
.tclass td {
border: 1px solid #aaa;
}
.highlight {
background-color: #cccccc;
}

4106
database/quexs.sql Normal file

File diff suppressed because it is too large Load Diff

149
display/index.php Normal file
View File

@@ -0,0 +1,149 @@
<?
/**
* Display a "full screen" view of outcomes for display on a large
* communal screen - will change views periodically
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @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');
/**
* XHTML functions
*/
include ("../functions/functions.xhtml.php");
/**
* Display functions
*/
include ("../functions/functions.performance.php");
/**
* Input functions
*/
include("../functions/functions.input.php");
$shift_id = 0;
$questionnaire_id = 0;
$display_type = 0;
if (isset($_GET['shift_id'])) $shift_id = bigintval($_GET['shift_id']);
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
if (isset($_GET['display_type'])) $display_type= bigintval($_GET['display_type']);
if ($display_type >= 6)
{
$sql = "SELECT shift_id,questionnaire_id
FROM shift
WHERE start <= CONVERT_TZ(NOW(),'System','UTC')
AND end >= CONVERT_TZ(NOW(),'System','UTC')
AND shift_id > '$shift_id'
ORDER BY shift_id ASC
LIMIT 1";
$s = $db->GetRow($sql);
$display_type = 0;
$shift_id = 0;
$questionnaire_id = 0;
if (!empty($s))
{
$shift_id = $s['shift_id'];
$questionnaire_id = $s['questionnaire_id'];
}
}
if ($shift_id == 0)
{
$sql = "SELECT shift_id,questionnaire_id
FROM shift
WHERE start <= CONVERT_TZ(NOW(),'System','UTC')
AND end >= CONVERT_TZ(NOW(),'System','UTC')
ORDER BY shift_id ASC
LIMIT 1";
$s = $db->GetRow($sql);
$display_type = 0;
if (!empty($s))
{
$shift_id = $s['shift_id'];
$questionnaire_id = $s['questionnaire_id'];
}
}
$dt1 = $display_type + 1;
xhtml_head(T_("Display"),true,array("../css/display.css"),false,false,"6;url=?shift_id=$shift_id&amp;questionnaire_id=$questionnaire_id&amp;display_type=$dt1");
if ($shift_id == 0 || $questionnaire_id == 0)
display_none();
else
{
$sql = "SELECT description
FROM questionnaire
WHERE questionnaire_id = '$questionnaire_id'";
$n = $db->GetRow($sql);
print "<h1>{$n['description']}</h1>\n";
switch($display_type)
{
case 0:
display_total_completions($questionnaire_id);
break;
case 1:
display_completions_this_shift($questionnaire_id,$shift_id);
break;
case 2:
display_completions_same_time_last_shift($questionnaire_id,$shift_id);
break;
case 3:
display_completions_last_shift($questionnaire_id,$shift_id);
break;
case 4:
display_top_cph_this_shift($questionnaire_id,$shift_id);
break;
case 5:
display_top_cph($questionnaire_id);
break;
}
}
xhtml_foot();
?>

View File

@@ -0,0 +1,291 @@
<?
/**
* Functions to calculate AAPOR outcomes based on Standard Definitions here:
*
* The American Association for Public Opinion Research. 2004. Standard Definitions: Final Dispositions of Case Codes and Outcome Rates for Surveys. 3rd edition. Lenexa, Kansas: AAPOR.
*
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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
*
*/
/**
* Return a cleaned array containing all required elements
* for AAPOR calculations
*
* @param array $a Array containing some of I,P,R,NC,O,UH,UO keys
* @return array Array containing all I,P,R,NC,O,UH,UO keys
*/
function aapor_clean($a)
{
if (!isset($a['I']) || empty($a['I'])) $a['I'] = 0;
if (!isset($a['P']) || empty($a['P'])) $a['P'] = 0;
if (!isset($a['R']) || empty($a['R'])) $a['R'] = 0;
if (!isset($a['NC']) || empty($a['NC'])) $a['NC'] = 0;
if (!isset($a['O']) || empty($a['O'])) $a['O'] = 0;
if (!isset($a['UH']) || empty($a['UH'])) $a['UH'] = 0;
if (!isset($a['UO']) || empty($a['UO'])) $a['UO'] = 0;
if (!isset($a[' ']) || empty($a[' '])) $a[' '] = 0;
return $a;
}
/**
* Calculate AAPOR's RR1
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Response rate as a decimal
*
*/
function aapor_rr1($a)
{
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($a['UH'] + $a['UO']));
if ($d == 0) return 0;
return $a['I'] / $d;
}
/**
* Calculate AAPOR's RR2
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Response rate as a decimal
*
*/
function aapor_rr2($a)
{
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($a['UH'] + $a['UO']));
if ($d == 0) return 0;
return ($a['I'] + $a['P']) / $d;
}
/**
* Calculate AAPOR's RR3
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @param float $e Estimated proportion of cases of unknown eligibility that are eligible
* @return float Response rate as a decimal
*
*/
function aapor_rr3($a,$e)
{
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($e*($a['UH'] + $a['UO'])));
if ($d == 0) return 0;
return ($a['I']) / $d;
}
/**
* Calculate AAPOR's RR4
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @param float $e Estimated proportion of cases of unknown eligibility that are eligible
* @return float Response rate as a decimal
*
*/
function aapor_rr4($a,$e)
{
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($e*($a['UH'] + $a['UO'])));
if ($d == 0) return 0;
return ($a['I'] + $a['P']) / $d;
}
/**
* Calculate AAPOR's RR5
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Response rate as a decimal
*
*/
function aapor_rr5($a)
{
return aapor_rr3($a,0);
}
/**
* Calculate AAPOR's RR6
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Response rate as a decimal
*
*/
function aapor_rr6($a)
{
return aapor_rr4($a,0);
}
/**
* Calculate AAPOR's COOP1
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Cooperation rate as a decimal
*
*/
function aapor_coop1($a)
{
$d = (($a['I'] + $a['P']) + $a['R'] + $a['O']);
if ($d == 0) return 0;
return $a['I'] / $d;
}
/**
* Calculate AAPOR's COOP2
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Cooperation rate as a decimal
*
*/
function aapor_coop2($a)
{
$d = (($a['I'] + $a['P']) + $a['R'] + $a['O']);
if ($d == 0) return 0;
return ($a['I'] + $a['P']) / $d;
}
/**
* Calculate AAPOR's COOP3
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Cooperation rate as a decimal
*
*/
function aapor_coop3($a)
{
$d = (($a['I'] + $a['P']) + $a['R']);
if ($d == 0) return 0;
return $a['I'] / $d;
}
/**
* Calculate AAPOR's COOP4
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Cooperation rate as a decimal
*
*/
function aapor_coop4($a)
{
$d = (($a['I'] + $a['P']) + $a['R']);
if ($d == 0) return 0;
return ($a['I'] + $a['P']) / $d;
}
/**
* Calculate AAPOR's REF1
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Refusal rate as a decimal
*
*/
function aapor_ref1($a)
{
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($a['UH'] + $a['UO']));
if ($d == 0) return 0;
return $a['R'] / $d;
}
/**
* Calculate AAPOR's REF2
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @param float $e Estimated proportion of cases of unknown eligibility that are eligible
* @return float Refusal rate as a decimal
*
*/
function aapor_ref2($a,$e)
{
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($e*($a['UH'] + $a['UO'])));
if ($d == 0) return 0;
return ($a['R']) / $d;
}
/**
* Calculate AAPOR's REF3
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Refusal rate as a decimal
*
*/
function aapor_ref3($a)
{
return aapor_ref2($a,0);
}
/**
* Calculate AAPOR's CON1
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Contact rate as a decimal
*
*/
function aapor_con1($a)
{
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($a['UH'] + $a['UO']));
if ($d == 0) return 0;
return (($a['I'] + $a['P']) + $a['R'] +$a['O']) / $d;
}
/**
* Calculate AAPOR's CON2
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @param float $e Estimated proportion of cases of unknown eligibility that are eligible
* @return float Contact rate as a decimal
*
*/
function aapor_con2($a,$e)
{
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($e*($a['UH'] + $a['UO'])));
if ($d == 0) return 0;
return (($a['I'] + $a['P']) + $a['R'] +$a['O']) / $d;
}
/**
* Calculate AAPOR's CON3
*
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
* @return float Contact rate as a decimal
*
*/
function aapor_con3($a)
{
return aapor_con2($a,0);
}
?>

View File

@@ -0,0 +1,534 @@
<?
/**
* Functions relating to appointment times and calendars
*
*
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include_once(dirname(__FILE__).'/../db.inc.php');
/**
* Add a phone number to a case (via the contact_phone table)
*
* @param int $case_id Case id
* @param int $phone Phone number
* @return bool Result false if failed to add else true
*/
function add_contact_phone($case_id,$phone)
{
global $db;
$sql = "INSERT INTO contact_phone
(contact_phone_id,case_id,priority,phone)
SELECT NULL,$case_id,MAX(priority)+1,'$phone'
FROM contact_phone
WHERE case_id = $case_id";
return $db->Execute($sql);
}
/**
* Add an appointment to a case (via the appointment table)
*
* @param int $respondent_id The respondent
* @param int $case_id The case
* @param int $contact_phone_id The contact phone number to call on
* @param int $call_attempt_id the current call attempt
* @param int $d the day of the month
* @param int $m the month of the year
* @param int $y the year (4 digit)
* @param string $start The time in the format HH:MM:SS
* @param string $end The time in the format HH:MM:SS
* @return bool Result false if failed to add else true
*/
function make_appointment($respondent_id,$case_id,$contact_phone_id,$call_attempt_id,$d,$m,$y,$start,$end)
{
global $db;
$start = "$y-$m-$d $start";
$end= "$y-$m-$d $end";
$sql = "INSERT INTO `appointment`
(appointment_id,case_id,contact_phone_id,call_attempt_id,start,end,require_operator_id,respondent_id,completed_call_id)
SELECT NULL,'$case_id','$contact_phone_id','$call_attempt_id',CONVERT_TZ('$start',r.Time_zone_name,'UTC'),CONVERT_TZ('$end',r.Time_zone_name,'UTC'),NULL,$respondent_id,NULL
FROM respondent as r
WHERE r.respondent_id = '$respondent_id'";
return $db->Execute($sql);
}
/**
* Take a 24 hour time in the format: hh:mm:ss and make it more human
*
* @param string $time The time in the format HH:MM:SS
* @return string Human readable time
*/
function convert_time($time)
{
$h = intval(substr($time,0,2));
$m = substr($time,3,2);
$s = intval(substr($time,5,2));
if ($h > 12)
return $h - 12 . ":$m"."pm";
else
return $h . ":$m"."am";
}
/**
* Return whether or not a questionnaire is restricted to work in shifts
*
* @param int $questionnaire_id Questionnaire ID
* @return bool True if shift restricted else false
*/
function is_shift_restricted($questionnaire_id)
{
global $db;
$sql = "SELECT restrict_appointments_shifts as r
FROM questionnaire
WHERE questionnaire_id = '$questionnaire_id'";
$rs = $db->GetRow($sql);
if ($rs['r'] == 1) return true;
return false;
}
/**
* Get an arary containing all contact phone numbers for a case
*
* @param int $case_id The case ID
* @return array|bool An array of contact phone numbers else false if none
*/
function return_contact_phone_list($case_id)
{
global $db;
$sql = "SELECT contact_phone_id,phone,description
FROM contact_phone
WHERE case_id = '$case_id'";
$rs = $db->GetAll($sql);
return $rs;
}
/**
* Print a list of respodnents for a case
* with an HTML GET request with the respondent_id
*
* @param int $case_id The case ID
* @param bool|int $respondent_id The respondent already selected or false if none selected
*/
function display_respondent_list($case_id,$respondent_id = false)
{
global $db;
$sql = "SELECT respondent_id,firstName,lastName
FROM respondent
WHERE case_id = '$case_id'";
$rs = $db->GetAll($sql);
print "<div><select id='respondent_id' name='respondent_id' onchange=\"LinkUp('respondent_id')\"><option>" . T_("None") . "</option>";
if (!empty($rs))
{
foreach($rs as $r)
{
$rid = $r['respondent_id'];
$selected = "";
if ($rid == $respondent_id) $selected="selected='selected'";
print "<option value='?respondent_id=$rid' $selected>{$r['firstName']} {$r['lastName']}</option>";
}
}
print "<option value='?respondent_id=0' class='addresp'>" . T_("Add respondent") . "</option></select></div>";
}
/**
* Print an XHTML form for adding or modifying respondent details
*
* @param bool|int $respondent_id The respondent already selected or false if none selected
* @param bool|int $case_id The case to add a respondent to or false if none selected
*/
function display_respondent_form($respondent_id = false,$case_id = false)
{
global $db;
/**
* Use the default time zone if none other to work with
*/
$rzone = DEFAULT_TIME_ZONE;
$fn = "";
$ln = "";
if ($respondent_id)
{
$sql = "SELECT Time_zone_name,firstName,lastName
FROM respondent
WHERE respondent_id = '$respondent_id'";
$rs = $db->GetRow($sql);
$rzone = $rs['Time_zone_name'];
$fn = $rs['firstName'];
$ln = $rs['lastName'];
}
else if ($case_id)
{
$sql = "SELECT Time_zone_name
FROM respondent
WHERE case_id = '$case_id'";
$rs = $db->GetRow($sql);
}
$sql = "SELECT Time_zone_name
FROM timezone_template";
$rs = $db->Execute($sql);
print "<div><label for='firstName'>" . T_("First name:") . " </label><input type=\"text\" id='firstName' name=\"firstName\" value=\"$fn\"/></div>
<div><label for='lastName'>" . T_("Last name:") . " </label><input type=\"text\" id='lastName' name=\"lastName\" value=\"$ln\"/></div>";
/**
* Display the current respondent zone in a drop down box with other zones from timezone_template
*/
print "<div><label>" . T_("Time Zone:") . " ".$rs->GetMenu('Time_zone_name',$rzone,false)."</label></div>";
}
/**
* Print shift details in XHTML based on the given day
* Display start time, and if start time selected display end time also
* Used generally for making an appointment
*
* @see make_appointment()
*
* @param int $respondent_id The respondent id
* @param int $day the day of the month
* @param int $month the month of the year
* @param int $year the year (4 digit)
* @param string $time The time in the format HH:MM:SS
* @param string $timeend The time in the format HH:MM:SS
*
* @todo Handle questionnaires without shift restrictions
*/
function display_time($respondent_id, $day, $month, $year, $time = false, $timeend = false)
{
global $db;
/**
* Select shift start and end times for this day
*/
$sql = " SELECT s.shift_id, HOUR(TIME(CONVERT_TZ(s.start,'UTC',r.Time_zone_name))) as sh, MINUTE(TIME(CONVERT_TZ(s.start,'UTC',r.Time_zone_name))) as sm, !(DATE(CONVERT_TZ(NOW(),'System',r.Time_zone_name)) = DATE(CONVERT_TZ(s.start,'UTC',r.Time_zone_name))) as today, HOUR(TIME(CONVERT_TZ(NOW(),'System',r.Time_zone_name))) as eh, MINUTE(TIME(CONVERT_TZ(NOW(),'System',r.Time_zone_name))) as em, (TIME_TO_SEC( TIMEDIFF( TIME( CONVERT_TZ( s.end, 'UTC', r.Time_zone_name ) ) , TIME( CONVERT_TZ( s.start, 'UTC', r.Time_zone_name ) ) ) ) /300) as intervals, TIME(CONVERT_TZ(s.start,'UTC',r.Time_zone_name)) as start, TIME(CONVERT_TZ(s.end,'UTC',r.Time_zone_name)) as end
FROM shift as s, respondent as r, `case` as c
WHERE r.respondent_id = '$respondent_id'
AND r.case_id = c.case_id
AND s.questionnaire_id = c.questionnaire_id
AND DAY(CONVERT_TZ(s.start,'UTC', r.Time_zone_name)) = '$day'
AND MONTH(CONVERT_TZ(s.start,'UTC', r.Time_zone_name)) = '$month'
AND YEAR(CONVERT_TZ(s.start,'UTC', r.Time_zone_name)) = '$year'
ORDER BY s.start ASC";
$rs = $db->GetAll($sql);
print "<div class=\"shifts\">";
foreach($rs as $r)
{
print "<p>" . T_("Shift from:") . " ".convert_time($r['start'])." till ".convert_time($r['end'])."</p>";
}
print "</div>";
print "<p>";
print "<select name=\"start\" id=\"start\" onchange=\"LinkUp('start')\"><option value=\"?y=$year&amp;m=$month&amp;d=$day&amp;respondent_id=$respondent_id\">" . T_("Start Time") . "</option>";
foreach ($rs as $r)
{
$sh = $r['sh'];
$sm = $r['sm'];
$intervals = $r['intervals'];
//eh and em should be the current respondent time
$eh = $r['eh'];
$em = $r['em'];
//today = 0 if the shift is today otherwise 1
$today = $r['today'];
/**
* Display only times in the future and within the shift in 5 minute intervals
*
*/
for ($i = 0; $i <= $intervals; $i++)
{
$t = str_pad($sh,2,"0",STR_PAD_LEFT).":".str_pad($sm,2,"0",STR_PAD_LEFT).":00";
if ($today || ($sh > $eh || ($sh == $eh && $sm > $em)))
{
$selected = "";
if ($t == $time) $selected = "selected=\"selected\"";
print "<option value=\"?y=$year&amp;m=$month&amp;d=$day&amp;respondent_id=$respondent_id&amp;start=$t\" $selected>".convert_time($t)."</option>";
}
$sm += 5;
if ($sm >= 60)
{
$sh++;
if ($sh >= 24) $sh -= 24;
$sm -= 60;
}
}
}
print "</select>";
if ($time)
{
$eh = substr($time,0,2);
$em = substr($time,3,2);
print "<select name=\"end\" id=\"end\" onchange=\"LinkUp('end')\"><option value=\"?y=$year&amp;m=$month&amp;d=$day&amp;respondent_id=$respondent_id&amp;start=$time\">" . T_("End Time") . "</option>";
foreach ($rs as $r)
{
$sh = $r['sh'];
$sm = $r['sm'];
$intervals = $r['intervals'];
/**
* Display only times after the start time and within the shift in 5 minute intervals
*
*/
for ($i = 0; $i <= $intervals; $i++)
{
$t = str_pad($sh,2,"0",STR_PAD_LEFT).":".str_pad($sm,2,"0",STR_PAD_LEFT).":00";
if ($sh > $eh || ($sh == $eh && $sm > $em))
{
$selected = "";
if ($t == $timeend) $selected = "selected=\"selected\"";
print "<option value=\"?y=$year&amp;m=$month&amp;d=$day&amp;respondent_id=$respondent_id&amp;start=$time&amp;end=$t\" $selected>".convert_time($t)."</option>";
}
$sm += 5;
if ($sm >= 60)
{
$sh++;
if ($sh >= 24) $sh -= 24;
$sm -= 60;
}
}
}
print "</select>";
}
print "<input type=\"hidden\" name=\"respondent_id\" value=\"$respondent_id\"/>";
print "<input type=\"hidden\" name=\"y\" value=\"$year\"/>";
print "<input type=\"hidden\" name=\"m\" value=\"$month\"/>";
print "<input type=\"hidden\" name=\"d\" value=\"$day\"/>";
print "</p>";
}
/**
* Print a tabular calendar for selecting dates for appointments
* Based on code from the PEAR package
*
* @link http://pear.php.net/package/Calendar PEAR Calendar
* @link http://pearcalendar.sourceforge.net/examples/3.php Example this code based on
*
* @see make_appointment()
* @see display_time()
*
* @param int $respondent_id The respondent id
* @param int $questionnaire_id The questionnaire id
* @param bool|int $day the day of the month if selected else false
* @param bool|int $month the month of the year if selected else false
* @param bool|int $year the year (4 digit) if selected else false
*
*/
function display_calendar($respondent_id, $questionnaire_id, $year = false, $month = false, $day = false)
{
global $db;
/**
* PEAR Caldendar Weekday functions
*/
include_once('Calendar/Month/Weekdays.php');
/**
* PEAR Caldendar Day functions
*/
include_once('Calendar/Day.php');
/**
* See if questionnaire has shift restrictions
*/
$restricted = is_shift_restricted($questionnaire_id);
$rtime = strtotime(get_respondent_time($respondent_id));
$y = date('Y',$rtime);
$m = date('m',$rtime);
$d = date('d',$rtime);
if (!$year) $year = $y;
if (!$month) $month = $m;
if (!$day) $day = $d;
$ttoday = new Calendar_Day($y,$m,$d);
$Month = new Calendar_Month_Weekdays($year,$month);
// Construct strings for next/previous links
$PMonth = $Month->prevMonth('object'); // Get previous month as object
$prev = '?y='.$PMonth->thisYear().'&amp;m='.$PMonth->thisMonth().'&amp;d='.$PMonth->thisDay().'&amp;respondent_id='.$respondent_id;
$NMonth = $Month->nextMonth('object');
$next = '?y='.$NMonth->thisYear().'&amp;m='.$NMonth->thisMonth().'&amp;d='.$NMonth->thisDay().'&amp;respondent_id='.$respondent_id;
// Build the days in the month
$Month->build();
?>
<table class="calendar">
<caption>
<?php echo ( date('F Y',$Month->getTimeStamp())); ?>
</caption>
<tr>
<th>M</th>
<th>T</th>
<th>W</th>
<th>T</th>
<th>F</th>
<th>S</th>
<th>S</th>
</tr>
<?php
while ( $Day = $Month->fetch() ) {
// Build a link string for each day
$link = '?y='.$Day->thisYear().
'&amp;m='.$Day->thisMonth().
'&amp;d='.$Day->thisDay().
'&amp;respondent_id='.$respondent_id;
$today = "";
if ($year == $Day->thisYear() && $month == $Day->thisMonth() && $day == $Day->thisDay()) $today = "today";
// isFirst() to find start of week
if ( $Day->isFirst() )
echo ( "<tr>\n" );
if ( $Day->isSelected() ) {
echo ( "<td class=\"selected $today\">".$Day->thisDay()."</td>\n" );
} else if ( $Day->isEmpty() ) {
echo ( "<td>&nbsp;</td>\n" );
} else {
//if it is in the past -> unavailable
if ($Day->getTimeStamp() < $ttoday->getTimeStamp())
{
echo ( "<td class=\"notavailable\">".$Day->thisDay()."</td>\n" );
}
//if there are shift restrictions, restrict
else if ($restricted)
{
$rs = $db->Execute(" SELECT s.shift_id
FROM shift as s
LEFT JOIN respondent as r on (r.respondent_id = '$respondent_id')
WHERE s.questionnaire_id = '$questionnaire_id'
AND DAY(CONVERT_TZ(s.start,'UTC',r.Time_zone_name)) = '{$Day->thisDay()}'
AND MONTH(CONVERT_TZ(s.start,'UTC',r.Time_zone_name)) = '{$Day->thisMonth()}'
AND YEAR(CONVERT_TZ(s.start,'UTC',r.Time_zone_name)) = '{$Day->thisYear()}'");
if ($rs->RecordCount() == 0)
{
echo ( "<td class=\"notavailable $today\">".$Day->thisDay()."</td>\n" );
}
else
{
echo ( "<td class=\"$today\"><a href=\"".$link."\">".$Day->thisDay()."</a></td>\n" );
}
}
else
echo ( "<td class=\"$today\"><a href=\"".$link."\">".$Day->thisDay()."</a></td>\n" );
}
// isLast() to find end of week
if ( $Day->isLast() )
echo ( "</tr>\n" );
}
?>
<tr>
<td>
<a href="<?php echo ($prev);?>" class="prevMonth">&lt;&lt; </a>
</td>
<td colspan="5">&nbsp;</td>
<td>
<a href="<?php echo ($next);?>" class="nextMonth"> &gt;&gt;</a>
</td>
</tr>
</table>
<?
}
?>

View File

@@ -0,0 +1,89 @@
<?
/**
* Client functions
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include_once(dirname(__FILE__).'/../db.inc.php');
/**
* Return the current client id based on PHP_AUTH_USER
*
* @return bool|int False if none otherwise the client id
*
*/
function get_client_id()
{
global $db;
$sql = "SELECT client_id
FROM client
WHERE username = '{$_SERVER['PHP_AUTH_USER']}'";
$o = $db->GetRow($sql);
if (empty($o)) return false;
return $o['client_id'];
}
/**
* Return a list of questionnaires assigned to this client
*
* @param int $client_id Client id
* @return bool|array False if nothing assigned otherwise an array of questionnaire assigned
*
*/
function get_client_questionnaire($client_id)
{
global $db;
$sql = "SELECT questionnaire_id
FROM client_questionnaire
WHERE client_id = '$client_id'";
$o = $db->GetAll($sql);
if (empty($o)) return false;
return $o;
}

View File

@@ -0,0 +1,138 @@
<?
/**
* Functions relating to displaying for XHTML
*
*
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include_once(dirname(__FILE__).'/../db.inc.php');
/**
* Display a list of questionnaires to choose from in a drop down list
*
* @param int|bool $questionnaire_id The questionnaire id or false if none selecetd
*
*/
function display_questionnaire_chooser($questionnaire_id = false)
{
global $db;
$sql = "SELECT questionnaire_id,description,CASE WHEN questionnaire_id = '$questionnaire_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM questionnaire";
$rs = $db->GetAll($sql);
print "<div><select id='questionnaire' name='questionnaire' onchange=\"LinkUp('questionnaire')\"><option value='?'></option>";
if (!empty($rs))
{
foreach($rs as $r)
{
print "<option value='?questionnaire_id={$r['questionnaire_id']}' {$r['selected']}>{$r['description']}</option>";
}
}
print "</select></div>";
}
/**
* Display a list of shifts to choose from in a drop down list
*
* @param int $questionnaire_id The questionnaire id
* @param int|bool $shift_id The shift id or false if none selected
*/
function display_shift_chooser($questionnaire_id, $shift_id = false)
{
global $db;
$sql = "SELECT s.shift_id,DATE_FORMAT(s.start,'" . DATE_TIME_FORMAT . "') as start,DATE_FORMAT(s.end,'" . TIME_FORMAT . "') as end,CASE WHEN s.shift_id = '$shift_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM shift as s
WHERE s.questionnaire_id = '$questionnaire_id'
ORDER BY s.start ASC";
$rs = $db->GetAll($sql);
print "<div><select id='shift' name='shift' onchange=\"LinkUp('shift')\"><option value='?questionnaire_id=$questionnaire_id'></option>";
if (!empty($rs))
{
foreach($rs as $r)
{
print "<option value='?shift_id={$r['shift_id']}&amp;questionnaire_id=$questionnaire_id' {$r['selected']}>{$r['start']} till {$r['end']}</option>";
}
}
print "</select></div>";
}
/**
* Display a list of samples to choose from in a drop down list
*
* @param int $questionnaire_id The questionnaire id
* @param int|bool $sample_import_id The sample import id or false if none selected
*/
function display_sample_chooser($questionnaire_id, $sample_import_id = false)
{
global $db;
$sql = "SELECT s.sample_import_id,si.description,CASE WHEN s.sample_import_id = '$sample_import_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
FROM questionnaire_sample as s, sample_import as si
WHERE s.questionnaire_id = '$questionnaire_id'
AND s.sample_import_id = si.sample_import_id";
$rs = $db->GetAll($sql);
print "<div><select id='sample' name='sample' onchange=\"LinkUp('sample')\"><option value='?questionnaire_id=$questionnaire_id'></option>";
if (!empty($rs))
{
foreach($rs as $r)
{
print "<option value='?sample_import_id={$r['sample_import_id']}&amp;questionnaire_id=$questionnaire_id' {$r['selected']}>{$r['sample_import_id']}: {$r['description']}</option>";
}
}
print "</select></div>";
}
?>

View File

@@ -0,0 +1,334 @@
<?
/**
* Functions relating to importing a sample file (from CSV)
*
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include_once(dirname(__FILE__).'/../db.inc.php');
/**
* Return only numbers from a string
*
* @param string $str String containing any character
* @return int A number
*
*/
function only_numbers($str)
{
return ereg_replace('[^0-9]*','',$str);
}
/**
* Verify fields in a CSV file
* confirm that there are no duplicate names
* confirm that there is one and only one primary number selected
*
* @param array $fields an array of field information i_ if selected, n_ name, t_ type code
* @return string An empty string if valid, otherwise invalid with error message
*
*/
function verify_fields($fields)
{
//i_ is if selected
//n_ is name of field
//t_ is type of field
$selected = array();
foreach($fields as $key => $val)
{
if (strncmp($key, "i_", 2) == 0)
{
$selected[] = substr($key,2);
}
}
$names = array();
//check for duplicate names
foreach($selected as $val)
{
if (array_key_exists($fields["n_$val"], $names))
{
return T_("Duplicate name");
}
else
{
//set name to type
$names[$fields["n_$val"]] = $fields["t_$val"];
}
}
//check that there is one and one only primary phone selected
$count = 0;
foreach($names as $val)
{
if ($val == 3) $count++;
}
if ($count == 1)
{
return "";
}
else
{
return T_("You must select one and one only Primary Phone number");
}
}
/**
* Display an XHTML table of the CSV data header
*
* @param array $data Header data from a CSV file
*
* @see get_first_row()
*
*/
function display_table($data)
{
print "<table>";
print "<tr><th></th><th>" . T_("Import?") . "</th><th>" . T_("Name") . "</th><th>" . T_("Type") . "</th></tr>";
$row = 1;
global $db;
$sql = "SELECT description,type
FROM sample_var_type";
$rs = $db->Execute($sql);
foreach ($data as $key => $value)
{
$val = str_replace(" ", "_", $value);
$checked = "checked";
if (empty($val)) $val = "samp_$row";
print "<tr><td>$value</td><td><input type=\"checkbox\" name=\"i_$row\" checked=\"$checked\"/></td><td><input type=\"text\" value=\"$val\" name=\"n_$row\"/></td><td>" . $rs->GetMenu("t_$row","1",false) . "</td></tr>";
$row++;
$rs->MoveFirst();
}
print "</table>";
}
/**
* Return the first row of a CSV file as an array
*
* @param string $file File name to open
*
*/
function get_first_row($file)
{
$handle = fopen($file, "r");
$data = fgetcsv($handle);
fclose($handle);
return $data;
}
/**
* Import a CSV file to the sample database
*
* @param string $file File name to open
* @param string $description A description of the sample
* @param array $fields Which fields to import and what type they are assigned to
*
* @see verify_fields()
* @see display_table()
*
*/
function import_file($file, $description, $fields, $firstrow = 2)
{
$row = 1;
$handle = fopen($file, "r");
//import into database
global $db;
$db->StartTrans();
$sql = "INSERT INTO sample_import
(sample_import_id, description)
VALUES (NULL, '$description')";
//print("$sql<br/>");
//if ($db->HasFailedTrans()) { print "FAILED"; exit(); }
$rs = $db->Execute($sql);
$id = $db->Insert_ID();
$selected_type = array();
$selected_name = array();
foreach($fields as $key => $val)
{
if (strncmp($key, "i_", 2) == 0)
{
$selected_type[substr($key,2)] = $fields["t_" . substr($key,2)];
$selected_name[substr($key,2)] = $fields["n_" . substr($key,2)];
}
}
/**
* create an ordered index of columns that contain data for obtaining the timezone
* type of 5,4,3,2 preferred
*/
arsort($selected_type);
$imported = 0;
while (($data = fgetcsv($handle)) !== FALSE)
{
//data contains an array of elements in the csv
//selected contains an indexed array of elements to import with the type attached
if ($row >= $firstrow) //don't import the header row
{
//determine if there is a phone number - if not - do not import
$numberavail = 0;
foreach($selected_type as $key => $val)
{
if ($val == 2 || $val == 3)
{
$dkey = only_numbers($data[$key - 1]);
if (!empty($dkey))
$numberavail = 1;
}
}
if ($numberavail == 1)
{
//insert into sample field
//first find the timezone
$tzone = DEFAULT_TIME_ZONE; //set this to default
/**
* Determine time zone from all possible sources in sample_var_type table
*
*/
foreach($selected_type as $key => $val)
{
$sql = "SELECT `table`
FROM sample_var_type
WHERE type = '$val'";
$tname = $db->GetRow($sql);
if (!empty($tname))
{
$tname = $tname['table'];
if (!empty($tname))
{
$value = $db->Quote($data[$key - 1]);
$sql = "SELECT Time_zone_name as tz
FROM `$tname`
WHERE val = SUBSTR($value, 1, CHAR_LENGTH( val ) )";
$tz = $db->GetRow($sql);
//print("$sql<br/>");
//if ($db->HasFailedTrans()) { print "FAILED"; exit(); }
if (!empty($tz))
{
$tzone = $tz['tz'];
break;
}
}
}
}
/**
* insert using primary phone number (3)
*/
$ppid = array_search('3', $selected_type);
$dppid = only_numbers($data[$ppid - 1]);
$sql = "INSERT INTO sample (sample_id,import_id,Time_zone_name,phone)
VALUES (NULL,'$id','$tzone','$dppid')";
$db->Execute($sql);
$sid = $db->Insert_Id();
/**
* insert into sample_var field
*/
foreach($selected_name as $key => $val)
{
$dkey = $db->Quote($data[$key - 1]);
$sql = "INSERT INTO sample_var (sample_id,var,val,type)
VALUES ('$sid','$val',{$dkey},'{$selected_type[$key]}')";
$db->Execute($sql);
}
$imported++;
}
}
$row++;
}
fclose($handle);
//cleanup
unlink($file);
return $db->CompleteTrans();
}
?>

View File

@@ -0,0 +1,52 @@
<?
/**
* Input conversion functions
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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_once(dirname(__FILE__).'/../config.inc.php');
/**
* Return only numbers given a string
*
* @param string $val The value to convert to numbers only
* @return int 0 if empty or no numbers otherwise the number portion of the string
*
*/
function bigintval($val)
{
$r = ereg_replace('[^0-9]*','',$val);
if (empty($r))
return 0;
else
return $r;
}

View File

@@ -0,0 +1,576 @@
<?
/**
* Functions relating to integration with {@link http://www.limesurvey.org/ LimeSurvey}
*
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include_once(dirname(__FILE__).'/../db.inc.php');
/**
* Taken from common.php in the LimeSurvey package
* Add a prefix to a database name
*
* @param string $name Database name
* @link http://www.limesurvey.org/ LimeSurvey
*/
function db_table_name($name)
{
return "`".LIME_PREFIX.$name."`";
}
/**
* Taken from common.php in the LimeSurvey package
* Get a random survey ID
*
* @link http://www.limesurvey.org/ LimeSurvey
*/
function getRandomID()
{ // Create a random survey ID - based on code from Ken Lyle
// Random sid/ question ID generator...
$totalChar = 5; // number of chars in the sid
$salt = "123456789"; // This is the char. that is possible to use
srand((double)microtime()*1000000); // start the random generator
$sid=""; // set the inital variable
for ($i=0;$i<$totalChar;$i++) // loop and create sid
$sid = $sid . substr ($salt, rand() % strlen($salt), 1);
return $sid;
}
/**
* Taken from admin/database.php in the LimeSurvey package
* With modifications
*
* @param string $title Questionnaire name
* @link http://www.limesurvey.org/ LimeSurvey
*/
function create_limesurvey_questionnaire($title)
{
global $ldb;
// Get random ids until one is found that is not used
do
{
$surveyid = getRandomID();
$isquery = "SELECT sid FROM ".db_table_name('surveys')." WHERE sid=$surveyid";
$isresult = $ldb->Execute($isquery);
}
while ($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, "
. "allowsave, autoredirect, allowprev,datecreated,tokenanswerspersistence)\n"
. "VALUES ($surveyid, 1,\n"
. "'', 'N', \n"
. "'N','1980-01-01', '', 'N',\n"
. "'', 'G', 'quexs', '" . QUEXS_URL . "rs_project_end.php',\n"
. "'en', 'Y', 'N', 'N',\n"
. "'N', '0', 'Y',\n"
. "'att1', 'att2', \n"
. "'Y', 'Y', 'Y','".date("Y-m-d")."','Y')";
$isresult = $ldb->Execute($isquery);
// 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"
. "'',\n"
. "'', '',\n"
. "'', '',\n"
. "'', '',\n"
. "'', '',\n"
. "'')";
$isresult = $ldb->Execute($isquery);
// Insert into survey_rights
$isrquery = "INSERT INTO ". LIME_PREFIX . "surveys_rights VALUES($surveyid,1,1,1,1,1,1,1)";
$isrresult = $ldb->Execute($isrquery) or die ($isrquery."<br />".$ldb->ErrorMsg());
return $surveyid;
}
/**
* Return the lime_sid given the case_id
*
* @param int $case_id The case id
* @return bool|int False if no lime_sid otherwise the lime_sid
*
*/
function get_lime_sid($case_id)
{
global $db;
$sql = "SELECT q.lime_sid
FROM questionnaire as q, `case` as c
WHERE c.case_id = '$case_id'
AND q.questionnaire_id = c.questionnaire_id";
$l = $db->GetRow($sql);
if (empty($l)) return false;
return $l['lime_sid'];
}
/**
* Check if LimeSurvey has marked a questionnaire as complete
*
* @param int $case_id The case id
* @return bool True if complete, false if not or unknown
*
*/
function limesurvey_is_completed($case_id)
{
global $ldb;
$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 = $ldb->GetRow($sql);
if (!empty($r))
if ($r['completed'] != 'N') return true;
return false;
}
/**
* Return the number of questions in the given questionnaire
*
* @param int $lime_sid The limesurvey sid
* @return bool|int False if no data, otherwise the number of questions
*
*/
function limesurvey_get_numberofquestions($lime_sid)
{
global $ldb;
$sql = "SELECT count(qid) as c
FROM " . LIME_PREFIX . "questions
WHERE sid = '$lime_sid'";
$r = $ldb->GetRow($sql);
if (!empty($r))
return $r['c'];
return false;
}
/**
* Return the percent complete a questionnaire is, or false if not started
*
* @param int $case_id The case id
* @return bool|float False if no data, otherwise the percentage of questions answered
*
*/
function limesurvey_percent_complete($case_id)
{
global $ldb;
$lime_sid = get_lime_sid($case_id);
if ($lime_sid == false) return false;
$sql = "SELECT saved_thisstep
FROM ". LIME_PREFIX ."saved_control
WHERE sid = '$lime_sid'
AND identifier = '$case_id'";
$r = $ldb->GetRow($sql);
if (!empty($r))
{
$step = $r['saved_thisstep'];
$questions = limesurvey_get_numberofquestions($lime_sid);
return ($step / $questions) * 100.0;
}
return false;
}
function limesurvey_get_width($qid,$default)
{
global $ldb;
$sql = "SELECT value FROM ".LIME_PREFIX."question_attributes WHERE qid = '$qid' and attribute = 'maximum_chars'";
$r = $ldb->GetRow($sql);
if (!empty($r))
$default = $r['value'];
return $default;
}
function limesurvey_fixed_width($lid)
{
global $ldb;
$sql = "SELECT MAX(LENGTH(code)) as c FROM ".LIME_PREFIX."labels WHERE lid = $lid";
$r = $ldb->GetRow($sql);
$val = 1;
if (!empty($r))
$val = $r['c'];
return $val;
}
function limesurvey_create_multi(&$varwidth,&$vartype,$qid,$varname,$length,$type)
{
global $ldb;
$sql = "SELECT *
FROM ".LIME_PREFIX."answers
WHERE qid = $qid
ORDER BY sortorder ASC";
$r = $ldb->GetAll($sql);
foreach($r as $Row)
{
$v = $varname . $Row['code'];
$varwidth[$v] = $length;
$vartype[$v] = $type;
}
return;
}
/**
* Return a string with only ASCII characters in it
*
* This function was sourced from the php website, help on str_replace
* No author was listed at the time of access
*
* @param string $stringIn The string
* @return string A string containing only ASCII characters
*/
function all_ascii( $stringIn ){
$final = '';
$search = array(chr(145),chr(146),chr(147),chr(148),chr(150),chr(151),chr(13),chr(10));
$replace = array("'","'",'"','"','-','-',' ',' ');
$hold = str_replace($search[0],$replace[0],$stringIn);
$hold = str_replace($search[1],$replace[1],$hold);
$hold = str_replace($search[2],$replace[2],$hold);
$hold = str_replace($search[3],$replace[3],$hold);
$hold = str_replace($search[4],$replace[4],$hold);
$hold = str_replace($search[5],$replace[5],$hold);
$hold = str_replace($search[6],$replace[6],$hold);
$hold = str_replace($search[7],$replace[7],$hold);
if(!function_exists('str_split')){
function str_split($string,$split_length=1){
$count = strlen($string);
if($split_length < 1){
return false;
} elseif($split_length > $count){
return array($string);
} else {
$num = (int)ceil($count/$split_length);
$ret = array();
for($i=0;$i<$num;$i++){
$ret[] = substr($string,$i*$split_length,$split_length);
}
return $ret;
}
}
}
$holdarr = str_split($hold);
foreach ($holdarr as $val) {
if (ord($val) < 128) $final .= $val;
}
return $final;
}
/**
* Produce a fixed width string containing the data from a questionnaire
*
* @param int $questionnaire_id The quesitonnaire id
* @param int|false $sample_import_id The sample importid or false for all data
* @return string Fixed width data from the limesurvey database
*
*/
function limesurvey_export_fixed_width($questionnaire_id,$sample_import_id = false)
{
global $ldb;
global $db;
//array of varname and width
$varwidth = array();
$vartype = array();
$sql = "SELECT lime_sid
FROM questionnaire
WHERE questionnaire_id = '$questionnaire_id'";
$r = $db->GetRow($sql);
if (!empty($r))
$surveyid = $r['lime_sid'];
else
return;
//foreach question
$sql = "SELECT *
FROM ".LIME_PREFIX."questions
WHERE sid=$surveyid
AND type NOT LIKE 'X'
ORDER BY gid,question_order ASC";
$r = $ldb->GetAll($sql);
foreach ($r as $RowQ)
{
$type = $RowQ['type'];
$qid = $RowQ['qid'];
$lid = $RowQ['lid'];
$gid = $RowQ['gid'];
$varName = $surveyid . "X" . $gid . "X" . $qid;
switch ($type)
{
case "X": //BOILERPLATE QUESTION - none should appear
break;
case "5": //5 POINT CHOICE radio-buttons
$varwidth[$varName]=1;
$vartype[$varName] = 1;
break;
case "D": //DATE
$varwidth[$varName]=8;
$vartype[$varName] = 1;
break;
case "Z": //LIST Flexible drop-down/radio-button list
$varwidth[$varName]=limesurvey_fixed_width($lid);
$vartype[$varName] = 1;
break;
case "L": //LIST drop-down/radio-button list
$varwidth[$varName]=limesurvey_fixed_width($lid);
$vartype[$varName] = 1;
break;
case "W": //List - dropdown
$varwidth[$varName]=limesurvey_fixed_width($lid);
$vartype[$varName] = 1;
break;
case "!": //List - dropdown
$varwidth[$varName]=limesurvey_fixed_width($lid);
$vartype[$varName] = 1;
break;
case "O": //LIST WITH COMMENT drop-down/radio-button list + textarea
//Not yet implemented
break;
case "R": //RANKING STYLE
//Not yet implemented
break;
case "M": //MULTIPLE OPTIONS checkbox
limesurvey_create_multi($varwidth,$vartype,$qid,$varName,1,3);
break;
case "P": //MULTIPLE OPTIONS WITH COMMENTS checkbox + text
//Not yet implemented
break;
case "Q": //MULTIPLE SHORT TEXT
limesurvey_create_multi($varwidth,$vartype,$qid,$varName,limesurvey_get_width($qid,24),2);
break;
case "K": //MULTIPLE NUMERICAL
limesurvey_create_multi($varwidth,$vartype,$qid,$varName,limesurvey_get_width($qid,10),1);
break;
case "N": //NUMERICAL QUESTION TYPE
$varwidth[$varName]= limesurvey_get_width($qid,10);
$vartype[$varName] = 1;
break;
case "S": //SHORT FREE TEXT
$varwidth[$varName]= limesurvey_get_width($qid,240);
$vartype[$varName] = 2;
break;
case "T": //LONG FREE TEXT
$varwidth[$varName]= limesurvey_get_width($qid,1024);
$vartype[$varName] = 2;
break;
case "U": //HUGE FREE TEXT
$varwidth[$varName]= limesurvey_get_width($qid,2048);
$vartype[$varName] = 2;
break;
case "Y": //YES/NO radio-buttons
$varwidth[$varName]=1;
$vartype[$varName] = 1;
break;
case "G": //GENDER drop-down list
$varwidth[$varName]=1;
$vartype[$varName] = 1;
break;
case "A": //ARRAY (5 POINT CHOICE) radio-buttons
$varwidth[$varName]=1;
$vartype[$varName] = 1;
break;
case "B": //ARRAY (10 POINT CHOICE) radio-buttons
$varwidth[$varName]=2;
$vartype[$varName] = 1;
break;
case "C": //ARRAY (YES/UNCERTAIN/NO) radio-buttons
$varwidth[$varName]=1;
$vartype[$varName] = 1;
break;
case "E": //ARRAY (Increase/Same/Decrease) radio-buttons
$varwidth[$varName]=1;
$vartype[$varName] = 1;
break;
case "F": //ARRAY (Flexible) - Row Format
limesurvey_create_multi($varwidth,$vartype,$qid,$varName,limesurvey_fixed_width($lid),1);
break;
case "H": //ARRAY (Flexible) - Column Format
limesurvey_create_multi($varwidth,$vartype,$qid,$varName,limesurvey_fixed_width($lid),1);
break;
case "^": //SLIDER CONTROL
//Not yet implemented
break;
} //End Switch
}
$fn = "survey_$surveyid.dat";
header("Content-Type: application/download");
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
$sql3 = "SELECT c.case_id as case_id
FROM `case` as c
WHERE c.questionnaire_id = '$questionnaire_id'";
$r = $db->GetAll($sql3);
if (!empty($r))
{
$sql = "SELECT *
FROM ".LIME_PREFIX."survey_$surveyid
WHERE submitdate IS NOT NULL";
if ($sample_import_id == false)
{
$sql .= " AND (";
foreach($r as $row)
{
$token = $row['case_id'];
$sql .= " token = '$token'";
if (next($r)) $sql .= " or ";
}
$sql .= ")";
}
else
{
$sql2 = "SELECT c.case_id as case_id
FROM `case` as c, `sample` as s
WHERE c.questionnaire_id = '$questionnaire_id'
AND c.sample_id = s.sample_id
AND s.import_id = '$sample_import_id'";
$r = $db->GetAll($sql2);
if (!empty($r))
{
$sql .= " AND (";
foreach($r as $row)
{
$token = $row['case_id'];
$sql .= " token = '$token'";
if (next($r)) $sql .= " or ";
}
$sql .= ")";
}
}
$r = $ldb->GetAll($sql);
foreach($r as $Row)
{
foreach ($varwidth as $var => $width)
{
if ($vartype[$var] == 1)
echo str_pad(substr(all_ascii($Row[$var]),0,$width), $width, " ", STR_PAD_LEFT);
else if ($vartype[$var] == 2)
echo str_pad(substr(all_ascii($Row[$var]),0,$width), $width, " ", STR_PAD_RIGHT);
else if ($vartype[$var] == 3)
if (empty($Row[$var])) echo " "; else echo "1";
}
echo str_pad(substr($Row['token'],0,9), 9, " ", STR_PAD_LEFT);
echo str_pad(substr($Row['datestamp'],0,16), 16, " ", STR_PAD_LEFT);
echo "\n";
}
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,445 @@
<?
/**
* Functions that display data about the project
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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_once(dirname(__FILE__).'/../config.inc.php');
/**
* Database file
*/
include_once(dirname(__FILE__).'/../db.inc.php');
/**
* Get completions per hour by shift with interviewer id and first name
*
* @param int $qid The questionnaire ID
* @param int $sid The shift ID
* @return array An array containing operator_id,firstName,CPH
*/
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
FROM operator as o
JOIN ( SELECT count(*) as completions,a.operator_id
FROM `call` as a, `case` as b, `shift` as s
WHERE a.outcome_id = '10'
AND a.case_id = b.case_id
AND b.questionnaire_id = '$qid'
AND s.shift_id = '$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
FROM `call_attempt` as a, `case` as b, `shift` as s
WHERE a.case_id = b.case_id
AND b.questionnaire_id = '$qid'
AND s.shift_id = '$sid'
AND s.`start` <= a.`start`
AND s.`end` >= a.`start`
GROUP BY operator_id) as ca on (ca.operator_id = o.operator_id)
ORDER BY cph DESC";
return $db->GetAll($sql);
}
/**
* Get completions per hour by questionnaire with interviewer id and first name
*
* @param int $qid The questionnaire ID
* @return array An array containing operator_id,firstName,CPH
*/
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
FROM operator as o
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 = '$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
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 completions per hour overall with interviewer id and first name
*
* @param int $qid The questionnaire ID
* @return array An array containing operator_id,firstName,CPH
*/
function get_CPH()
{
global $db;
$sql = "SELECT o.firstName,o.operator_id,c.completions,ca.time, c.completions/ca.time 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
FROM `call_attempt`
GROUP BY operator_id) as ca on (ca.operator_id = o.operator_id)
ORDER BY cph DESC";
return $db->GetAll($sql);
}
/**
* Get effectiveness by questionnaire with interviewer id and first name
*
* @param int $qid The questionnaire ID
* @return array An array containing operator_id,firstName,effectiveness
*/
function get_effectiveness_by_questionnaire($questionnaire_id)
{
global $db;
$sql = "SELECT o.operator_id, o.firstName, (calltime.totaltime / callattempttime.totaltime) AS effectiveness
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 )
ORDER BY effectiveness DESC";
return $db->GetAll($sql);
}
/**
* Get effectiveness overall with interviewer id and first name
*
* @return array An array containing operator_id,firstName,effectiveness
*/
function get_effectiveness()
{
global $db;
$sql = "SELECT o.operator_id, o.firstName, (calltime.totaltime / callattempttime.totaltime) AS effectiveness
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
GROUP BY operator_id
) AS callattempttime ON ( callattempttime.operator_id = o.operator_id )
ORDER BY effectiveness DESC";
return $db->GetAll($sql);
}
/**
* Get the average time on a call with an outcome
* in seconds by questionnaire
*
* @param int $outcome_id The outcome id
* @param int $questionnaire_id The questionnaire id
* @return int Seconds average of calls with this outcome
*/
function get_average_time_questionnaire($outcome_id,$questionnaire_id)
{
global $db;
$sql = "SELECT AVG(TIMESTAMPDIFF(SECOND,c.start,c.end)) as average
FROM `call` as c, `case` as q
WHERE c.outcome_id = '$outcome_id'
AND q.case_id = c.case_id
AND q.questionnaire_id = '$questionnaire_id'";
$rs = $db->GetRow($sql);
if (!empty($rs))
return $rs['average'];
else
return 0;
}
/**
* Get the average time on a call with an outcome
* in seconds
*
* @param int $outcome_id The outcome id
* @return int Seconds average of calls with this outcome
*/
function get_average_time($outcome_id)
{
global $db;
$sql = "SELECT AVG(TIMESTAMPDIFF(SECOND,c.start,c.end)) as average
FROM `call` as c
WHERE c.outcome_id = '$outcome_id'";
$rs = $db->GetRow($sql);
if (!empty($rs))
return $rs['average'];
else
return 0;
}
/**
* If not on a shift, display a message
*/
function display_none()
{
print "<h1>" . T_("No shift") . "</h1>";
}
/**
* Display the total number of completions for this project
*
* @param int $qid The questionnaire id
*
*/
function display_total_completions($qid)
{
global $db;
$sql = "SELECT count(case_id) as c
FROM `case`
WHERE current_outcome_id = 10
AND questionnaire_id = '$qid'";
$rs = $db->GetRow($sql);
$c = 0;
if (!empty($rs)) $c = $rs['c'];
print "<h3>" . T_("Total completions") . "</h3><h2>$c</h2>";
}
/**
* Display the total number of completions for this shift
*
* @param int $qid The questionnaire id
* @param int $sid The shift id
*
*/
function display_completions_this_shift($qid,$sid)
{
global $db;
$sql = "SELECT count(ca.call_id) as c
FROM `call` as ca, `case` as cs, `shift` as s
WHERE ca.outcome_id = 10
AND ca.case_id = cs.case_id
AND cs.questionnaire_id = '$qid'
AND s.questionnaire_id = '$qid'
AND s.shift_id = '$sid'
AND ca.start >= s.start
AND ca.start <= s.end";
$rs = $db->GetRow($sql);
$c = 0;
if (!empty($rs)) $c = $rs['c'];
print "<h3>" . T_("Completions this shift") . "</h3><h2>$c</h2>";
}
/**
* Display the total number of completions for the last shift
*
* @param int $qid The questionnaire id
* @param int $sid The current shift id
*
*/
function display_completions_last_shift($qid,$sid)
{
global $db;
$sql = "SELECT shift_id
FROM shift
WHERE questionnaire_id = '$qid'
AND shift_id < '$sid'
ORDER BY shift_id DESC
LIMIT 1";
$ps = $db->GetRow($sql);
if (empty($ps))
print "<h3>" . T_("No previous shift") . "</h3>";
else
{
$psid = $ps['shift_id'];
$sql = "SELECT count(ca.call_id) as c
FROM `call` as ca, `case` as cs, `shift` as s
WHERE ca.outcome_id = 10
AND ca.case_id = cs.case_id
AND cs.questionnaire_id = '$qid'
AND s.questionnaire_id = '$qid'
AND s.shift_id = '$psid'
AND ca.start >= s.start
AND ca.start <= s.end";
$rs = $db->GetRow($sql);
$c = 0;
if (!empty($rs)) $c = $rs['c'];
print "<h3>" . T_("Completions on the previous shift") . "</h3><h2>$c</h2>";
}
}
/**
* Display the total number of completions for the last shift
* at the same number of seconds in to the last shift
*
* @param int $qid The questionnaire id
* @param int $sid The current shift id
*
*/
function display_completions_same_time_last_shift($qid,$sid)
{
global $db;
$sql = "SELECT shift_id
FROM shift
WHERE questionnaire_id = '$qid'
AND shift_id < '$sid'
ORDER BY shift_id DESC
LIMIT 1";
$ps = $db->GetRow($sql);
if (empty($ps))
print "<h3>" . T_("No previous shift") . "</h3>";
else
{
$psid = $ps['shift_id'];
$sql = "SELECT count(ca.call_id) as c
FROM `call` as ca, `case` as cs, `shift` as s
JOIN `shift` as s2 on (s2.shift_id = '$sid')
WHERE ca.outcome_id = 10
AND ca.case_id = cs.case_id
AND cs.questionnaire_id = '$qid'
AND s.questionnaire_id = '$qid'
AND s.shift_id = '$psid'
AND ca.start >= s.start
AND ca.start <= DATE_SUB(s.end, INTERVAL TIMESTAMPDIFF(SECOND , CONVERT_TZ(NOW(),'System','UTC'), s2.end) SECOND)";
$rs = $db->GetRow($sql);
$c = 0;
if (!empty($rs)) $c = $rs['c'];
print "<h3>" . T_("Completions this time on the previous shift") . "</h3><h2>$c</h2>";
}
}
/**
* Display the interviewer with the top CPH for this shift
*
* @param int $qid The questionnaire id
* @param int $sid The current shift id
*
*/
function display_top_cph_this_shift($qid,$sid)
{
global $db;
$rs = get_CPH_by_shift($qid,$sid);
if (empty($rs))
print "<h3>" . T_("No calls made for this shift") . "</h3>";
else
print "<h3>" . T_("Top CPH for this shift") . "</h3><h2>{$rs[0]['firstName']} - ". round($rs[0]['CPH'],2) ."</h2>";
}
/**
* Display the interviewer with the top CPH overall
*
* @param int $qid The questionnaire id
*
*/
function display_top_cph($qid)
{
global $db;
$rs = get_CPH_by_questionnaire($qid);
if (empty($rs))
print "<h3>" . T_("No calls made for this project") . "</h3>";
else
print "<h3>" . T_("Top CPH") . "</h3><h2>{$rs[0]['firstName']} - ". round($rs[0]['CPH'],2) ."</h2>";
}
?>

View File

@@ -0,0 +1,38 @@
<?
/**
* Template of functions
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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_once(dirname(__FILE__).'/../config.inc.php');
?>

View File

@@ -0,0 +1,492 @@
<?
/**
* Functions to interact with Asterisk
* Some examples taken from {@link http://www.voip-info.org/wiki/index.php?page=Asterisk+manager+Example%3A+PHP voip-info.org}
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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_once(dirname(__FILE__).'/../config.inc.php');
/**
* Class to interact with Asterisk
*
* @package queXS
*/
class voip {
/**
* Socket connection to Asterisk server
*/
var $socket;
/**
* Close the socket gracefully on destruct
*/
function __destruct() {
//close the socket
fclose($this->socket);
$this->socket = false;
}
/**
* Return a list of active extensions and their corresponding
* channels as an associative array
*
* @return array Key is extension, value is Asterisk channel
*
*/
function getChannels()
{
$ret = $this->query("Action: Status\r\n\r\n","StatusComplete");
$c = spliti("\r\n\r\n",$ret);
$chans = array();
foreach ($c as $s)
{
if(eregi("Event: Status.*Channel: SIP/([0-9a-zA-Z-]+).*Link: ([/0-9a-zA-Z-]+)",$s,$regs))
{
//print T_("Channel: SIP/") . $regs[1] . " Link " . $regs[2] . "\n";
$chan = substr($regs[1],0,4);
$chans[$chan] = array("SIP/" . $regs[1],$regs[2]);
}
else if(eregi("Event: Status.*Channel: SIP/([0-9a-zA-Z-]+).*",$s,$regs))
{
//print T_("Channel: ") . $regs[1] . "\n";
$chan = substr($regs[1],0,4);
$chans[$chan] = array("SIP/".$regs[1],false);
}
}
return $chans;
}
/**
* Return the channel (if active) given the extension
* Return false if no channel found
*
* @param string $ext Extension as in Asterisk
* @return string|bool The Asterisk channel or false if no channel exists
*
*/
function getChannel($ext,$link = false)
{
$v = $this->getChannels();
if (isset($v[$ext]))
{
if ($link)
return $v[$ext][1];
else
return $v[$ext][0];
}
else
return false;
}
/**
* Add another party to an active call (eg add in the supervisor)
*
* @param int $ext The extension of the current call
* @param int $number The phone number to add to the call
* @todo CHECK IF THE MEETING ROOM IS EMPTY before adding use meetme list
*
*/
function addParty($ext,$number)
{
if($ext)
{
$channel = $this->getChannel($ext);
$link = $this->getChannel($ext,true);
//check if the meeting room is empty
//if so:
// 1. call the supervisor to the room
$q = "Action: Originate\r\nChannel: Local/$number@from-internal\r\nPriority: 1\r\nContext: default\r\nApplication: MeetMe\r\nData: " . MEET_ME_ROOM . "|d\r\n\r\n";
$r = $this->query($q,"Meetme");
// 2. transfer the current call to the room
$r = $this->query("Action: Redirect\r\nChannel: $channel\r\nExtraChannel: $link\r\nExten: " . MEET_ME_ROOM . "\r\nPriority: 1\r\nContext: from-internal-xfer\r\n\r\n","Response");
}
}
/**
* Dial call from the call database
*
* @param string $ext The extension to originate the call from
* @param string $number The number to dial
*
*/
function dial($ext,$number)
{
$r = $this->query("Action: Originate\r\nChannel: SIP/$ext\r\nExten: $number\r\nPriority: 1\r\nCallerid: $ext\r\n\r\n","Response");
}
/**
* Hang up the current call by the extension
*
* @param int $ext The extension to hang up for
*
*/
function hangup($ext)
{
if($ext)
{
$channel = $this->getChannel($ext);
$r = $this->query("Action: Hangup\r\nChannel: $channel\r\n\r\n","Response");
}
}
/**
* Begin recording the call to a file
*
* @param string $ext The Asterisk extension
* @param bool|string $filename False for an auto generated file name else specify file name
* @todo Handle multiple recordings
*
*/
function beginRecord($ext,$filename = false)
{
if($ext)
{
$channel = $this->getChannel($ext);
$r = $this->query("Action: Monitor\r\nChannel: $channel\r\nFile: $filename\r\nFormat: gsm\r\nMix: 1\r\n\r\n","Response");
}
}
/**
* End the recording on this extension
*
* @param string $ext The Asterisk extension
* @todo Handle multiple recordings
* @see beginRecord()
*
*/
function endRecord($ext)
{
if($ext)
{
$channel = $this->getChannel($ext);
$r = $this->query("Action: StopMonitor\r\nChannel: $channel\r\n\r\n","Response");
}
}
/**
* Return the status of an extension
*
* @param int $ext The extension
* @return bool|int false if not available, 1 for available, 2 for available and on a call
*
*/
function getExtensionStatus($ext)
{
if($ext)
{
$ret = $this->query("Action: ExtensionState\r\nContext: default\r\nExten: $ext\r\nActionID: 1\r\n\r\n","Status:");
if(eregi("Status: ([0-9]+)",$ret,$regs))
{
if (isset($regs[1]))
{
// 0 appears to be online, 1 online and on a call
if ($regs[1] == 0)
return 1;
else if ($regs[1] == 1 || $regs[1] == 8)
return 2;
}
}
}
return false;
}
/**
* Return whether we are connected to the Asterisk server or not
*
* @return True if connected else false
*
*/
function isConnected()
{
if ($this->socket)
return true;
else
return false;
}
/**
* Connect to the Asterisk server
*
* @param string $ip The IP Address
* @param string $user Username for Asterisk manager
* @param string $pass Password for Asterisk manager
* @param bool $events If events should be enabled or not (default false)
*
* @return bool True if connected successfully, else false
*/
function connect($ip,$user="admin",$pass="amp111",$events = false)
{
$this->socket = fsockopen($ip,"5038",$errno,$errstr,1);
if (!$this->socket)
{
print "$errno: $errstr";
exit();
return false;
}
stream_set_timeout($this->socket, 1);
$q = "Action: Login\r\nUsername: $user\r\nSecret: $pass\r\nEvents: ";
if ($events)
$q .= "on";
else
$q .= "off";
$q .= "\r\n\r\n";
$r = $this->query($q,"accepted");
if (strpos($r,"Response: Success"))
{
return true;
}
else
{
fclose($this->socket);
return false;
}
}
/**
* Query the Asterisk server and wait for a response or timeout
*
* @param string $query The string to send to the Asterisk manager, see {@link http://www.voip-info.org/wiki/view/Asterisk+manager+API API} for details
* @param string $waitfor A string within the return string to wait for before returning
* @return string The response string from Asterisk
*
*/
function query($query,$waitfor=false)
{
$wrets = "";
if ($this->socket === false)
return false;
fputs($this->socket, $query);
$c = 1;
do
{
$line = fgets($this->socket, 4096);
$wrets .= $line;
$info = stream_get_meta_data($this->socket);
} while ($line != "\n" && !$info['timed_out'] && (strpos($line,$waitfor) === false));
return $wrets;
}
}
/**
* Class used to watch Asterisk events and effect changes to queXS database
*
* @package queXS
* @todo automatically code a call if we know it is busy
*/
class voipWatch extends voip {
var $keepWatching = true;
/**
* Watch for Asterisk events and make changes to the queXS databse if
* appropriate
*
*
*/
function watch()
{
/**
* Database file
*/
include_once(dirname(__FILE__).'/../db.inc.php');
$line = "";
if ($this->socket === false)
return false;
/**
* Array key: Asterisk unique ID, value: queXS call id
*/
$e = array();
/**
* Array key: Asterisk unique ID, value: Asterisk sequence number
*/
$f = array();
do
{
//keep reconnecting to the db so it doesn't time out
$db = newADOConnection(DB_TYPE);
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$in = fgets($this->socket, 4096);
//print "IN: $in\n";
/**
* When we have reached the end of a message, process it
*
*/
if ($in == "\r\n")
{
//print "PROCESS: ";
/**
* New channel, assign Asterisk unique id to queXF call id
*/
if(eregi("Event: Newchannel.*Channel: SIP/([0-9]+).*Uniqueid: ([0-9]+)\.([0-9]+)",$line,$regs))
{
print T_("Extension: ") . $regs[1] . T_(" UniqueID ") . $regs[2] . T_(" Sequence ") . $regs[3] . "\n";
$sql = "SELECT l.call_id
FROM operator AS o
JOIN (`case` AS c, `call_attempt` AS ca, `call` AS l) ON
( c.current_operator_id = o.operator_id
AND c.case_id = ca.case_id
AND ca.operator_id = o.operator_id
AND ca.end IS NULL
AND l.call_attempt_id = ca.call_attempt_id
AND l.outcome_id =0 )
WHERE o.extension = '{$regs[1]}'";
$rs = $db->GetRow($sql);
if (!empty($rs))
{
$e[$regs[2]] = $rs['call_id']; //set call id
$f[$regs[2]] = $regs[3]; //set sequence
}
}
/**
* The call is ringing
*/
else if (eregi("Event: Dial.*SrcUniqueid: ([0-9]+)",$line,$regs))
{
print T_("Ringing") . T_(" UniqueID ") . $regs[1] . "\n";
if (isset($e[$regs[1]])) //if we know the call of this unique id
{
$call_id = $e[$regs[1]];
$sql = "UPDATE `call`
SET state = 2
WHERE call_id = '$call_id'";
$db->Execute($sql);
//print $sql;
}
}
/**
* The call has been answered
*/
else if (eregi("Event: Link.*Uniqueid1: ([0-9]+)",$line,$regs))
{
print T_("Answered") . T_(" UniqueID ") . $regs[1] . "\n";
if (isset($e[$regs[1]])) //if we know the call of this unique id
{
$call_id = $e[$regs[1]];
$sql = "UPDATE `call`
SET state = 3
WHERE call_id = '$call_id'";
$db->Execute($sql);
// print $sql;
}
}
/**
* The call has been hung up
*/
else if (eregi("Event: Hangup.*Uniqueid: ([0-9]+)\.([0-9]+)",$line,$regs))
{
print T_("Hangup") . T_(" UniqueID ") . $regs[1] . "\n";
// print_r($e);
if (isset($e[$regs[1]]) && $f[$regs[1]] == $regs[2]) //if we know the call and it is the same line hangingup
{
$call_id = $e[$regs[1]];
$sql = "UPDATE `call`
SET state = 4
WHERE call_id = '$call_id'
AND outcome_id = '0'";
$db->Execute($sql); //don't update if already coded outcome
// print $sql;
//unset the variables
unset($e[$regs[1]]);
unset($f[$regs[1]]);
}
}
//print $line . "\n\n";
$line = "";
}
else
{
/**
* Append the lines to the message if we are not yet at the end of one
*/
$line .= $in;
}
@flush();
} while ($this->keepWatching);
}
}
?>

View File

@@ -0,0 +1,170 @@
<?
/**
* Functions related to XHTML code generation
*
*
* This file is part of queXS
*
* queXS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* queXS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with queXS; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* @author Adam Zammit <adam.zammit@deakin.edu.au>
* @copyright Deakin University 2007,2008
* @package queXS
* @subpackage functions
* @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
*
*/
/**
* Display a valid XHTML Strict header
*
* @param string $title HTML title
* @param bool $body True if to display the end of the head/body
* @param bool|array $css False for no CSS otherwise array of CSS include files
* @param bool|array $javascript False for no Javascript otherwise array of Javascript include files
* @param string $bodytext Space in the body element: good for onload='top.close()' to close validly
* @param bool|int $refresh False or 0 for no refresh otherwise the number of seconds to refresh
*
* @see xhtml_foot()
*/
function xhtml_head($title="",$body=true,$css=false,$javascript=false,$bodytext=false,$refresh=false)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title><? if (empty($title)) print "queXS"; else print "queXS: $title"; ?></title>
<?
if ($css)
foreach ($css as $c) print "<link rel='stylesheet' href='$c' type='text/css'></link>";
if ($javascript)
foreach ($javascript as $j) print "<script type='text/javascript' src='$j'></script>";
if ($refresh)
print " <!--Set to refresh every $refresh seconds-->
<meta http-equiv='Cache-Control' content='no-cache'/>
<meta http-equiv='refresh' content='$refresh'/>";
if (!$body) return;
?>
</head>
<?
if ($bodytext) print "<body $bodytext>"; else print "<body>";
}
/**
* Display a valid XHTML Strict footer
*
* @see xhtml_head()
*/
function xhtml_foot()
{
?>
</body>
</html>
<?
}
/**
* Display a valid XHTML Strict table
*
* @param array $content Content from database usually an array of arrays
* @param array $fields The names of fields to display
* @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
*
*/
function xhtml_table($content,$fields,$head = false,$class = "tclass",$highlight=false)
{
print "<table class='$class'>";
if ($head)
{
print "<tr>";
foreach ($head as $e)
print"<th>$e</th>";
print "</tr>";
}
foreach($content as $row)
{
if ($highlight && isset($row[key($highlight)]) && $row[key($highlight)] == current($highlight))
print "<tr class='highlight'>";
else
print "<tr>";
foreach ($fields as $e)
print "<td>{$row[$e]}</td>";
print "</tr>";
}
print "</table>";
}
/**
* Display a drop down list based on a given array
*
* Example SQL:
* SELECT questionnaire_id as value,description, CASE WHEN questionnaire_id = '$questionnaire_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
* FROM questionnaire
*
*
* @param array $elements An array of arrays containing a value and a description and if selected (3 elements)
* @param string $selectid The ID of the element
* @param string $var The var name of the return string
* @param bool $useblank Add a blank element to the start of the list
* @param string|bool $pass Anything to pass along in the return string (remember to separate with &amp;)
* @param bool $js Whether to use JS or not
*
*/
function display_chooser($elements, $selectid, $var, $useblank = true, $pass = false, $js = true)
{
print "<div><select id='$selectid' name='$selectid' ";
if ($js) print "onchange=\"LinkUp('$selectid')\"";
print ">";
if ($useblank)
{
print "<option value='";
if ($js) print "?";
if ($pass != false)
print $pass;
print "'></option>";
}
foreach($elements as $e)
{
if ($js)
{
print "<option value='?$var={$e['value']}";
if ($pass != false)
print "&amp;$pass";
print "' ";
}
else
{
print "<option value='{$e['value']}' ";
}
if (isset($e['selected'])) print $e['selected'];
print ">".$e['description']."</option>";
}
print "</select></div>";
}
?>