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

new look for pages

This commit is contained in:
Alex
2015-03-23 12:03:33 +03:00
parent 979981adb6
commit 25b94fb428
10 changed files with 1554 additions and 1525 deletions

View File

@@ -73,7 +73,7 @@ $js_head = array(
);
$js_foot = array(
"../js/window.js",
"../js/custom.js"
//"../js/custom.js"
);
global $db;
@@ -113,29 +113,26 @@ else if (isset($_POST['availability_group']))
}
//view groups
$sql = "SELECT description,
$sql = "SELECT availability_group_id,description,
CONCAT('<a href=\'availability.php?availability_group=', availability_group_id, '\'>". TQ_("Modify") . "</a>') as link
FROM availability_group";
$rs = $db->GetAll($sql);
//print "<h3>" . T_("Time slots")."</h3>";
print "<div class='well'>" . T_("Time slots define periods of time during particular days of the week. These are used for the availability function and also the call attempt time slot function.") . "</div>";
if (empty($rs))
print "<div class='alert alert-danger'>" . T_("No time slots") . "</div>";
else{
print "<div class='panel-body col-sm-4'>";
// print "<h3>" . T_("Time slots")."</h3>";
xhtml_table($rs,array("description","link"),array(T_("Time slot"),T_("Modify")));
print "<div class='panel-body col-sm-6'>";
xhtml_table($rs,array("availability_group_id","description","link"),array(T_("ID"),T_("Time slot name"),T_("Modify")),"table table-hover");
print "</div>";
}
//add an availablity group <label for="availability_group"><?php echo T_("Time slot name"); : </label>
//add a time slot (ex- availablity group)
?>
<div class=" panel-body col-sm-4"><form method="post" action="?">
<h3><?php echo T_("Add time slot")," :";?></h3>
<h3><?php echo T_("Add new time slot")," :";?></h3>
<p><input type="text" class="textclass form-control" name="availability_group" id="availability_group" placeholder="<?php echo T_("Enter"),"&ensp;",T_("new"),"&ensp;",T_("Time slot name"); ?>"/></p>
<p><input class="submitclass btn btn-default" type="submit" name="submit" value="<?php echo T_("Add time slot"); ?>"/></p>
</form></div>

View File

@@ -1,272 +1,289 @@
<?php
/**
* Generate bulk appointments 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@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research (ACSPRI) 2012
* @package queXS
* @subpackage admin
* @link http://www.acspri.org.au/software queXS was writen for ACSPRI
* @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");
/**
* Database functions
*/
include ("../db.inc.php");
/**
* Operator functions
*/
include("../functions/functions.operator.php");
/**
* Validate that an uploaded CSV file contains a caseid, starttime and endtime column and generate
* an array containing the details for confirming on screen or updating the database
*
* @param string $tmpfname File name of uploaded CSV file
*
* @return bool|array False if invalid otherwise an array of arrays containing caseid,starttime,endtime and note
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @since 2012-11-02
*/
function validate_bulk_appointment($tmpfname)
{
$handle = fopen($tmpfname, "r");
$row = 1;
$cols = array("caseid" => -1,"starttime" => -1,"endtime" => -1);
$index = array();
$optcols = array("note" => -1);
$todo = array();
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 == 1) //validate
{
$colcount = 0;
$ic = 0;
foreach($data as $col)
{
if (array_key_exists(strtolower($col),$cols))
{
$cols[strtolower($col)] = $ic;
$colcount++;
}
if (array_key_exists(strtolower($col),$optcols))
{
$optcols[strtolower($col)] = $ic;
}
$ic++;
}
if ($colcount != 3)
{
return false;
}
}
else
{
$note = "";
if (isset($data[$optcols['note']]))
$note = $data[$optcols['note']];
$sd = getdate(strtotime($data[$cols['starttime']]));
$s = $sd['year'] . "-" . str_pad($sd['mon'],2,"0", STR_PAD_LEFT) . "-" . str_pad($sd['mday'],2,"0",STR_PAD_LEFT) . " " . str_pad($sd['hours'],2,"0",STR_PAD_LEFT) . ":" . str_pad($sd['minutes'],2,"0",STR_PAD_LEFT) . ":" . str_pad($sd['seconds'],2,"0",STR_PAD_LEFT);
$sd = getdate(strtotime($data[$cols['endtime']]));
$e = $sd['year'] . "-" . str_pad($sd['mon'],2,"0", STR_PAD_LEFT) . "-" . str_pad($sd['mday'],2,"0",STR_PAD_LEFT) . " " . str_pad($sd['hours'],2,"0",STR_PAD_LEFT) . ":" . str_pad($sd['minutes'],2,"0",STR_PAD_LEFT) . ":" . str_pad($sd['seconds'],2,"0",STR_PAD_LEFT);
$todor = array($data[$cols['caseid']],$s,$e,$note);
$todo[] = $todor;
}
$row++;
}
fclose($handle);
return $todo;
}
if (isset($_POST['tmpfname']))
{
xhtml_head("queXS",true,array("../css/table.css"));
$todo = validate_bulk_appointment($_POST['tmpfname']);
if (is_array($todo))
{
$res = array();
foreach($todo as $r)
{
$db->StartTrans();
//check the current case id exists and outcome is not final
$sql = "SELECT c.case_id
FROM `case` as c, `outcome` as o
WHERE c.current_outcome_id = o.outcome_id
AND o.outcome_type_id != 4
AND c.case_id = {$r[0]}
AND c.current_operator_id IS NULL";
$caseid = $db->GetOne($sql);
if (!empty($caseid))
{
//insert an appointment in respondent time
$sql = "SELECT respondent_id
FROM respondent
WHERE case_id = {$r[0]}";
$rid = $db->GetOne($sql);
$sql = "SELECT contact_phone_id
FROM contact_phone
WHERE case_id = {$r[0]}
ORDER BY priority ASC";
$cid = $db->GetOne($sql);
$oid = get_operator_id();
$sql = "INSERT INTO call_attempt (call_attempt_id,case_id,operator_id,respondent_id,start,end)
VALUES (NULL,{$r[0]},$oid,$rid,CONVERT_TZ(NOW(),'System','UTC'),CONVERT_TZ(NOW(),'System','UTC'))";
$db->Execute($sql);
$call_attempt_id = $db->Insert_ID();
$sql = "INSERT INTO appointment (case_id,contact_phone_id,`start`,`end`,respondent_id,call_attempt_id)
SELECT {$r[0]},$cid,CONVERT_TZ('{$r[1]}',Time_zone_name,'UTC'),CONVERT_TZ('{$r[2]}',Time_zone_name,'UTC'),$rid,$call_attempt_id
FROM respondent
WHERE respondent_id = $rid";
$db->Execute($sql);
$aid = $db->Insert_ID();
//change the outcome to unspecified appointment, other
$sql = "UPDATE `case`
SET current_outcome_id = 22
WHERE case_id = {$r[0]}";
$db->Execute($sql);
//add a note if not blank
if (!empty($r[3]))
{
$note = $db->qstr($r[3]);
$sql = "INSERT INTO case_note (case_id,operator_id,note,datetime)
VALUES ({$r[0]},$oid,$note,CONVERT_TZ(NOW(),'System','UTC'))";
$db->Execute($sql);
}
$cnote = T_("Added appointment") . " <a href='displayappointments?case_id={$r[0]}&amp;appointment_id=$aid'>$aid</a>";
}
else
{
$cnote = T_("No such case id, or case set to a final outcome, or case currently assigned to an operator");
}
$res[] = array("<a href='supervisor.php?case_id=" . $r[0] . "'>" . $r[0] . "</a>",$cnote);
$db->CompleteTrans();
}
xhtml_table($res,array(0,1),array(T_("Case id"),T_("Result")));
}
xhtml_foot();
}
else if (isset($_POST['import_file']))
{
//file has been submitted
xhtml_head("queXS",true,array("../css/table.css"));
?>
<form action="" method="post">
<?php
$tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO");
move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname);
$todo = validate_bulk_appointment($tmpfname);
if (is_array($todo))
{
print "<p>" . T_("Please check the case id's, appointment start and end times and notes are correct before accepting below") . "</p>";
$todoh = array(T_("Case id"), T_("Start time"), T_("End time"), T_("Note"));
xhtml_table($todo,array(0,1,2,3),$todoh);
?>
<form action="" method="post">
<p><input type="hidden" name="tmpfname" value="<?php echo $tmpfname; ?>" /></p>
<p><input type="submit" name="import_file" value="<?php echo T_("Accept and generate bulk appointments"); ?>"/></p>
</form>
<?php
}
else
print "<p>" . T_("The file does not contain at least caseid, starttime and endtime columns. Please try again.") ."</p>";
xhtml_foot();
}
else
{
//need to supply file to upload
xhtml_head(T_("Import: Select file to upload"),true,array("../css/table.css"));
?>
<h1><?php echo T_("Bulk appointment generator"); ?></h1>
<p><?php echo T_("Provide a headered CSV file containing at least 3 columns - caseid, starttime and endtime. Optionally you can include a note column to attach a note to the case in addition to setting an appointment. Only cases that have temporary (non final) outcomes will have appointments generated, and the outcome of the case will be updated to an appointment outcome."); ?><p>
<p><?php echo T_("Example CSV file:"); ?></p>
<div><table class="tclass">
<tr><th>caseid</th><th>starttime</th><th>endtime</th><th>note</th></tr>
<tr><td>1</td><td>2012-08-15 11:00:00</td><td>2012-08-15 13:00:00</td><td>Appointment automatically generated</td></tr>
<tr><td>2</td><td>2012-08-15 12:00:00</td><td>2012-08-15 14:00:00</td><td>Appointment automatically generated</td></tr>
<tr><td>3</td><td>2012-08-15 13:00:00</td><td>2012-08-15 15:00:00</td><td>Appointment automatically generated</td></tr>
</table></div>
<form enctype="multipart/form-data" action="" method="post">
<p><input type="hidden" name="MAX_FILE_SIZE" value="1000000000" /></p>
<p><?php echo T_("Choose the CSV file to upload:"); ?><input name="file" type="file" /></p>
<p><input type="submit" name="import_file" value="<?php echo T_("Load bulk appointment CSV"); ?>"/></p>
</form>
<?php
xhtml_foot();
}
?>
<?php
/**
* Generate bulk appointments 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@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research (ACSPRI) 2012
* @package queXS
* @subpackage admin
* @link http://www.acspri.org.au/software queXS was writen for ACSPRI
* @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");
/**
* Database functions
*/
include ("../db.inc.php");
/**
* Operator functions
*/
include("../functions/functions.operator.php");
/**
* Validate that an uploaded CSV file contains a caseid, starttime and endtime column and generate
* an array containing the details for confirming on screen or updating the database
*
* @param string $tmpfname File name of uploaded CSV file
*
* @return bool|array False if invalid otherwise an array of arrays containing caseid,starttime,endtime and note
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @since 2012-11-02
*/
function validate_bulk_appointment($tmpfname)
{
$handle = fopen($tmpfname, "r");
$row = 1;
$cols = array("caseid" => -1,"starttime" => -1,"endtime" => -1);
$index = array();
$optcols = array("note" => -1);
$todo = array();
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 == 1) //validate
{
$colcount = 0;
$ic = 0;
foreach($data as $col)
{
if (array_key_exists(strtolower($col),$cols))
{
$cols[strtolower($col)] = $ic;
$colcount++;
}
if (array_key_exists(strtolower($col),$optcols))
{
$optcols[strtolower($col)] = $ic;
}
$ic++;
}
if ($colcount != 3)
{
return false;
}
}
else
{
$note = "";
if (isset($data[$optcols['note']]))
$note = $data[$optcols['note']];
$sd = getdate(strtotime($data[$cols['starttime']]));
$s = $sd['year'] . "-" . str_pad($sd['mon'],2,"0", STR_PAD_LEFT) . "-" . str_pad($sd['mday'],2,"0",STR_PAD_LEFT) . " " . str_pad($sd['hours'],2,"0",STR_PAD_LEFT) . ":" . str_pad($sd['minutes'],2,"0",STR_PAD_LEFT) . ":" . str_pad($sd['seconds'],2,"0",STR_PAD_LEFT);
$sd = getdate(strtotime($data[$cols['endtime']]));
$e = $sd['year'] . "-" . str_pad($sd['mon'],2,"0", STR_PAD_LEFT) . "-" . str_pad($sd['mday'],2,"0",STR_PAD_LEFT) . " " . str_pad($sd['hours'],2,"0",STR_PAD_LEFT) . ":" . str_pad($sd['minutes'],2,"0",STR_PAD_LEFT) . ":" . str_pad($sd['seconds'],2,"0",STR_PAD_LEFT);
$todor = array($data[$cols['caseid']],$s,$e,$note);
$todo[] = $todor;
}
$row++;
}
fclose($handle);
return $todo;
}
if (isset($_POST['tmpfname']))
{
$subtitle = T_("Result");
xhtml_head(T_("Bulk appointment generator"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../css/custom.css"),false,false,false,false,$subtitle);
$todo = validate_bulk_appointment($_POST['tmpfname']);
if (is_array($todo))
{
$res = array();
foreach($todo as $r)
{
$db->StartTrans();
//check the current case id exists and outcome is not final
$sql = "SELECT c.case_id
FROM `case` as c, `outcome` as o
WHERE c.current_outcome_id = o.outcome_id
AND o.outcome_type_id != 4
AND c.case_id = {$r[0]}
AND c.current_operator_id IS NULL";
$caseid = $db->GetOne($sql);
if (!empty($caseid))
{
//insert an appointment in respondent time
$sql = "SELECT respondent_id
FROM respondent
WHERE case_id = {$r[0]}";
$rid = $db->GetOne($sql);
$sql = "SELECT contact_phone_id
FROM contact_phone
WHERE case_id = {$r[0]}
ORDER BY priority ASC";
$cid = $db->GetOne($sql);
$oid = get_operator_id();
$sql = "INSERT INTO call_attempt (call_attempt_id,case_id,operator_id,respondent_id,start,end)
VALUES (NULL,{$r[0]},$oid,$rid,CONVERT_TZ(NOW(),'System','UTC'),CONVERT_TZ(NOW(),'System','UTC'))";
$db->Execute($sql);
$call_attempt_id = $db->Insert_ID();
$sql = "INSERT INTO appointment (case_id,contact_phone_id,`start`,`end`,respondent_id,call_attempt_id)
SELECT {$r[0]},$cid,CONVERT_TZ('{$r[1]}',Time_zone_name,'UTC'),CONVERT_TZ('{$r[2]}',Time_zone_name,'UTC'),$rid,$call_attempt_id
FROM respondent
WHERE respondent_id = $rid";
$db->Execute($sql);
$aid = $db->Insert_ID();
//change the outcome to unspecified appointment, other
$sql = "UPDATE `case`
SET current_outcome_id = 22
WHERE case_id = {$r[0]}";
$db->Execute($sql);
//add a note if not blank
if (!empty($r[3]))
{
$note = $db->qstr($r[3]);
$sql = "INSERT INTO case_note (case_id,operator_id,note,datetime)
VALUES ({$r[0]},$oid,$note,CONVERT_TZ(NOW(),'System','UTC'))";
$db->Execute($sql);
}
$cnote = T_("Added appointment") . " <a href='displayappointments?case_id={$r[0]}&amp;appointment_id=$aid'>$aid</a>";
}
else
{
$cnote = T_("No such case id, or case set to a final outcome, or case currently assigned to an operator");
}
$res[] = array("<a href='supervisor.php?case_id=" . $r[0] . "'>" . $r[0] . "</a>",$cnote);
$db->CompleteTrans();
}
xhtml_table($res,array(0,1),array(T_("Case id"),T_("Result")));
}
xhtml_foot();
}
else if (isset($_POST['import_file']))
{
//file has been submitted
$subtitle = T_("Check data to submit");
xhtml_head(T_("Bulk appointment generator"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../css/custom.css"),false,false,false,false,$subtitle);
?>
<form action="" method="post" >
<?php
$tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO");
move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname);
$todo = validate_bulk_appointment($tmpfname);
if (is_array($todo) && !empty($todo)) {
print "<p class='well'>" . T_("Please check the case id's, appointment start and end times and notes are correct before accepting below") . "</p>";
$todoh = array(T_("Case id"), T_("Start time"), T_("End time"), T_("Note"));
xhtml_table($todo,array(0,1,2,3),$todoh);
?>
<form action="" method="post">
<input type="hidden" name="tmpfname" value="<?php echo $tmpfname; ?>" />
<input type="submit" name="import_file" value="<?php echo T_("Accept and generate bulk appointments"); ?>" class="btn btn-primary"/>
</form>
<?php
}
else
print "<p class='well text-danger'>" . T_("The file does not contain at least caseid, starttime and endtime columns. Please try again.") ."</p>";
print "</form>";
xhtml_foot();
}
else
{
//need to supply file to upload
$subtitle = T_("Import: Select file to upload");
xhtml_head(T_("Bulk appointment generator"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../include/font-awesome-4.3.0/css/font-awesome.css","../css/custom.css"),array("../js/jquery-2.1.3.min.js","../js/bootstrap-filestyle.min.js"),false,false,false,$subtitle );
$ua = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('/Firefox/i', $ua)) $csv= "text/csv"; else $csv= ".csv";
?>
<p class="well"><?php echo T_("Provide a headered CSV file containing at least 3 columns - caseid, starttime and endtime. </br> Optionally you can include a note column to attach a note to the case in addition to setting an appointment. </br>Only cases that have temporary (non final) outcomes will have appointments generated, and the outcome of the case will be updated to an appointment outcome."); ?><p>
<div class="panel-body">
<h5><u><?php echo T_("Example CSV file:"); ?></u></h5>
<table class="table-bordered table-condensed form-group">
<tr><th>caseid</th><th>starttime</th><th>endtime</th><th>note</th></tr>
<tr><td>1</td><td>2012-08-15 11:00:00</td><td>2012-08-15 13:00:00</td><td>Appointment automatically generated</td></tr>
<tr><td>2</td><td>2012-08-15 12:00:00</td><td>2012-08-15 14:00:00</td><td>Appointment automatically generated</td></tr>
<tr><td>3</td><td>2012-08-15 13:00:00</td><td>2012-08-15 15:00:00</td><td>Appointment automatically generated</td></tr>
</table>
</div>
<form enctype="multipart/form-data" action="" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000" />
<h4 class="pull-left" ><?php echo T_("Select bulk appointment CSV file to upload"); ?>:&ensp;</h4>
<div class="col-sm-4">
<input name="file" class="filestyle" type="file" required data-buttonBefore="true" data-iconName="fa fa-folder-open fa-lg text-primary " data-buttonText="<?php echo T_("Select file"); ?>" type="file" accept="<?php echo $csv; ?>"/>&emsp;
</div>
<button type="submit" class="btn btn-primary" name="import_file" value=""><i class='fa fa-upload fa-lg'></i>&emsp;<?php echo "" . T_("Upload file"); ?></button>
</form>
<?php
xhtml_foot();
}
?>

View File

@@ -1,74 +1,72 @@
<?php
/**
* Set information about this centre for diplay to operators
*
*
* 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@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2011
* @package queXS
* @subpackage admin
* @link http://www.acspri.org.au/ queXS was writen for ACSPRI
* @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");
/**
* CKEditor
*/
include("../include/ckeditor/ckeditor.php");
global $db;
$CKEditor = new CKEditor();
$CKEditor->basePath = "../include/ckeditor/";
if (isset($_POST['information']))
{
set_setting("information",$_POST['information']);
}
xhtml_head(T_("Set centre information"),true,false,array("../js/window.js"));
?>
<form action="" method="post"><p>
<label for="information"><?php echo T_("Set centre information: "); ?></label><?php echo $CKEditor->editor("information",get_setting("information")); ?>
<input type="submit" name="update" value="<?php echo T_("Update centre information"); ?>"/></p>
</form>
<?php
xhtml_foot();
?>
<?php
/**
* Set information about this centre for diplay to operators
*
*
* 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@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2011
* @package queXS
* @subpackage admin
* @link http://www.acspri.org.au/ queXS was writen for ACSPRI
* @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");
/**
* CKEditor
*/
include("../include/ckeditor/ckeditor.php");
global $db;
$CKEditor = new CKEditor();
$CKEditor->basePath = "../include/ckeditor/";
if (isset($_POST['information']))
{
set_setting("information",$_POST['information']);
}
xhtml_head(T_("Set centre information"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../css/custom.css"),array("../js/window.js"));
?>
<form action="" method="post" class="panel-body">
<!-- <label for="information"><?php //echo T_("Set centre information: "); ?></label> -->
<?php echo $CKEditor->editor("information",get_setting("information")); ?>
<br/><input class="btn btn-primary" type="submit" name="update" value="<?php echo T_("Update centre information"); ?>"/>
</form>
<?php
xhtml_foot();
?>

View File

@@ -1,236 +1,244 @@
<?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");
/**
* 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['key']) || isset($_GET['sample']))
{
$questionnaire_id = bigintval($_GET['questionnaire_id']);
$sample_import_id = bigintval($_GET['sample_import_id']);
$sql = "SELECT sv.var as value
FROM `sample_var` as sv
WHERE sv.sample_id = (SELECT sample_id FROM sample WHERE import_id = '$sample_import_id' LIMIT 1)";
$svars = $db->GetAll($sql);
$fn = "key_all_";
if (isset($_GET['sample'])) $fn = "sample_all_";
$fn .= $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("token,caseid");
foreach($svars as $s)
{
echo("," . $s['value']);
}
if (isset($_GET['sample']))
{
echo(",Outcome,AAPOR");
}
echo("\n");
$sql = "SELECT c.token,c.case_id ";
if (isset($_GET['sample'])) $sql .= ", o.description, o.aapor_id ";
$i = 0;
foreach ($svars as $s)
{
$sql .= ", sv$i.val as v$i";
$i++;
}
$sql .= " FROM sample ";
//left join if getting whole sample file
if (isset($_GET['sample'])) $sql .= "LEFT ";
$sql .= "JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_id' AND c.sample_id = sample.sample_id) ";
if (isset($_GET['sample'])) $sql .= " LEFT JOIN `outcome` as o ON (o.outcome_id = c.current_outcome_id) ";
$i = 0;
foreach ($svars as $s)
{
$sql .= " LEFT JOIN sample_var AS sv$i ON (sv$i.sample_id = sample.sample_id AND sv$i.var = '{$s['value']}') ";
$i++;
}
$sql .= " WHERE sample.import_id = '$sample_import_id'";
$list = $db->GetAll($sql);
if (!empty($list))
{
foreach($list as $l)
{
echo $l['token'] . "," . $l['case_id'];
$i = 0;
foreach ($svars as $s)
{
echo "," . str_replace(","," ",$l["v$i"]);
$i++;
}
if (isset($_GET['sample']))
{
echo "," . str_replace(","," ",$l['description']) . "," . $l['aapor_id'];
}
echo "\n";
}
}
exit;
}
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.token,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("token,caseid,$sample_var\n");
if (!empty($list))
{
foreach($list as $l)
{
echo $l['token'] . "," . $l['case_id'] . "," . $l['val'] . "\n";
}
}
exit;
}
xhtml_head(T_("Data output"),true,false,array("../js/window.js"));
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)
{
$sql = "SELECT lime_sid
FROM questionnaire
WHERE questionnaire_id = $questionnaire_id";
$ls = $db->GetRow($sql);
$lsid = $ls['lime_sid'];
print "<p><a href='" . LIME_URL . "admin/admin.php?action=exportresults&amp;sid=$lsid'>". T_("Download data for this questionnaire via Limesurvey") . "</a></p>";
print "<h3>" . T_("Please select a sample") . "</h3>";
$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='" .LIME_URL . "admin/admin.php?action=exportresults&amp;sid=$lsid&amp;quexsfilterinc=$questionnaire_id:$sample_import_id'>" . T_("Download data for this sample via Limesurvey") . "</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>" . T_("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");
//download complete key file
print "<p><a href='?key=key&amp;questionnaire_id=$questionnaire_id&amp;sample_import_id=$sample_import_id'>" . T_("Download complete key file") . "</a></p>";
//download complete sample file with outcomes
print "<p><a href='?sample=sample&amp;questionnaire_id=$questionnaire_id&amp;sample_import_id=$sample_import_id'>" . T_("Download complete sample file with current outcomes") . "</a></p>";
}
}
xhtml_foot();
?>
<?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");
/**
* 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['key']) || isset($_GET['sample']))
{
$questionnaire_id = bigintval($_GET['questionnaire_id']);
$sample_import_id = bigintval($_GET['sample_import_id']);
$sql = "SELECT sv.var as value
FROM `sample_var` as sv
WHERE sv.sample_id = (SELECT sample_id FROM sample WHERE import_id = '$sample_import_id' LIMIT 1)";
$svars = $db->GetAll($sql);
$fn = "key_all_";
if (isset($_GET['sample'])) $fn = "sample_all_";
$fn .= $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("token,".T_("Case ID")."");
foreach($svars as $s)
{
echo("," . $s['value']);
}
if (isset($_GET['sample']))
{
echo(",".T_("Current Outcome").",".T_("Number of call attempts").",".T_("Number of calls").",".T_("Case notes").",".T_("Total interview time over all calls (mins)").",".T_("Interview time for last call (mins)").",".T_("Last number dialled").",".T_("DATE/TIME Last number dialled").",".T_("Operator username for last call").",".T_("Shift report").", AAPOR");
}
echo("\n");
$sql = "SELECT c.token,c.case_id ";
if (isset($_GET['sample'])) $sql .= ", o.description,
(SELECT COUNT(ca.call_attempt_id) FROM `call_attempt` as ca WHERE ca.case_id = c.case_id ) as callattempts,
(SELECT COUNT(cl.call_id) FROM `call` as cl WHERE cl.case_id = c.case_id ) as calls,
(SELECT GROUP_CONCAT(cn1.note SEPARATOR '|') FROM `case_note` as cn1 WHERE c.case_id = cn1.case_id GROUP BY cn1.case_id)as casenotes,
(SELECT ROUND(SUM( TIMESTAMPDIFF(SECOND , cl2.start,IFNULL(cl2.end,CONVERT_TZ(NOW(),'System','UTC'))))/60,2) FROM `call_attempt` as cl2 WHERE cl2.case_id = c.case_id) as interviewtimec,
(SELECT ROUND(TIMESTAMPDIFF(SECOND , cl3.start,IFNULL(cl3.end,CONVERT_TZ(NOW(),'System','UTC')))/60,2) FROM `call_attempt` as cl3 WHERE cl3.case_id = c.case_id ORDER BY cl3.call_attempt_id DESC LIMIT 1) as interviewtimel,
(SELECT cp1.phone FROM `call` as cl4, `contact_phone` as cp1 WHERE cl4.call_id = c.last_call_id AND cp1.contact_phone_id = cl4.contact_phone_id ) as lastnumber,
(SELECT cl55.start FROM `call` as cl55 WHERE cl55.call_id = c.last_call_id ) as lastcallstart,
(SELECT op1.username FROM `call` as cl5, `operator` as op1 WHERE cl5.call_id = c.last_call_id AND op1.operator_id = cl5.operator_id) as operatoru,
(SELECT GROUP_CONCAT(DISTINCT sr1.report SEPARATOR '|') FROM `call` as cl6, `shift` as sh1, `shift_report` as sr1 WHERE cl6.case_id = c.case_id AND sr1.shift_id = sh1.shift_id AND sh1.questionnaire_id = c.questionnaire_id AND cl6.start >= sh1.start AND cl6.end < sh1.end GROUP BY sr1.shift_id) as shiftr,
o.aapor_id ";
$i = 0;
foreach ($svars as $s)
{
$sql .= ", sv$i.val as v$i";
$i++;
}
$sql .= " FROM sample ";
//left join if getting whole sample file
if (isset($_GET['sample'])) $sql .= "LEFT ";
$sql .= "JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_id' AND c.sample_id = sample.sample_id) ";
if (isset($_GET['sample'])) $sql .= " LEFT JOIN `outcome` as o ON (o.outcome_id = c.current_outcome_id)";
$i = 0;
foreach ($svars as $s)
{
$sql .= " LEFT JOIN sample_var AS sv$i ON (sv$i.sample_id = sample.sample_id AND sv$i.var = '{$s['value']}') ";
$i++;
}
$sql .= " WHERE sample.import_id = '$sample_import_id'";
$list = $db->GetAll($sql);
if (!empty($list))
{
foreach($list as $l)
{
echo $l['token'] . "," . $l['case_id'];
$i = 0;
foreach ($svars as $s)
{
echo "," . str_replace(","," ",$l["v$i"]);
$i++;
}
if (isset($_GET['sample']))
{
echo "," . str_replace(","," ",$l['description']) . "," .$l['callattempts']."," .$l['calls']."," .$l['casenotes'].",".$l['interviewtimec'].",".$l['interviewtimel'].",".$l['lastnumber'].",".$l['lastcallstart'].",".$l['operatoru'].",".$l['shiftr'].",". $l['aapor_id'];
}
echo "\n";
}
}
exit;
}
if (isset($_GET['sample_var']))
{
$questionnaire_id = bigintval($_GET['questionnaire_id']);
$sample_import_id = bigintval($_GET['sample_import_id']);
$sample_var = $db->quote($_GET['sample_var']);
$sql = "SELECT c.token,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("token,caseid,$sample_var\n");
if (!empty($list))
{
foreach($list as $l)
{
echo $l['token'] . "," . $l['case_id'] . "," . $l['val'] . "\n";
}
}
exit;
}
xhtml_head(T_("Data output"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../css/custom.css"),array("../js/window.js"));
print "<div class='form-group clearfix'><h3 class='col-sm-4 text-right'>" . T_("Please select a questionnaire") . ":&emsp;</h3>";
$questionnaire_id = false;
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
display_questionnaire_chooser($questionnaire_id,false,"form-inline pull-left", "form-control");
if ($questionnaire_id)
{
$sql = "SELECT lime_sid
FROM questionnaire
WHERE questionnaire_id = $questionnaire_id";
$ls = $db->GetRow($sql);
$lsid = $ls['lime_sid'];
print "&emsp;&emsp;<a href='" . LIME_URL . "admin/admin.php?action=exportresults&amp;sid=$lsid' class='btn btn-default fa btn-lime'>". T_("Download data for this questionnaire via Limesurvey") . "</a></div>";
print "<div class='form-group clearfix'><h3 class='col-sm-4 text-right'>" . T_("Please select a sample") . ":&emsp;</h3>";
$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,false,"form-inline pull-left", "form-control");
if ($sample_import_id)
{
print "&emsp;&emsp;<a href='" .LIME_URL . "admin/admin.php?action=exportresults&amp;sid=$lsid&amp;quexsfilterinc=$questionnaire_id:$sample_import_id' class='btn btn-default fa btn-lime'>" . T_("Download data for this sample via Limesurvey") . "</a></div>";
//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 "<div class='form-group clearfix'><h3 class='col-sm-4 text-right'>" . T_("Download key file: select sample var") . ":&emsp;</h3>";
display_chooser($db->GetAll($sql),"sample_var","sample_var",true,"questionnaire_id=$questionnaire_id&amp;sample_import_id=$sample_import_id",true,true,false,true,"form-inline pull-left");
// print "</div><div class='form-group col-sm-offset-4'>";
//download complete key file
print "&emsp;&emsp;<a href='?key=key&amp;questionnaire_id=$questionnaire_id&amp;sample_import_id=$sample_import_id' class='btn btn-default fa'>" . T_("Download complete key file") . "</a>";
//download complete sample file with outcomes
print "&emsp;&emsp;<a href='?sample=sample&amp;questionnaire_id=$questionnaire_id&amp;sample_import_id=$sample_import_id' class='btn btn-default fa'>" . T_("Download complete sample file with current outcomes") . "</a></div>";
}
}
xhtml_foot();
?>

View File

@@ -1,113 +1,110 @@
<?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,array("../css/table.css"),array("../js/window.js"));
//$rs = get_stats_total(get_stats());
//print "<h2>" . T_("Overall") . "</h2>";
//xhtml_table($rs,array("firstName","completions","totalcalls","time","callt","CPH","CALLSPH","effectiveness"),array(T_("Operator"),T_("Completions"),T_("Calls"),T_("Total time"),T_("Call time"),T_("Completions p/h"),T_("Calls p/h"),T_("Effectiveness")));
$questionnaire_id = false;
print "<h3>" . T_("Please select a questionnaire") . "</h3>";
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
display_questionnaire_chooser($questionnaire_id);
if ($questionnaire_id)
{
$rs = get_stats_total(get_stats_by_questionnaire($questionnaire_id));
print "<h2>" . T_("This project") . "</h2>";
xhtml_table($rs,array("firstName","completions","totalcalls","time","callt","CPH","CALLSPH","effectiveness"),array(T_("Operator"),T_("Completions"),T_("Calls"),T_("Total time"),T_("Call time"),T_("Completions p/h"),T_("Calls p/h"),T_("Effectiveness")));
$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 . "'),' " . TQ_("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);
print "<h3>" . T_("Please select a shift") . "</h3>";
display_chooser($rs,"shift_id","shift_id",true,"questionnaire_id=$questionnaire_id");
if ($shift_id)
{
$rs = get_stats_total(get_stats_by_shift($questionnaire_id,$shift_id));
print "<h2>" . T_("This shift") . "</h2>";
xhtml_table($rs,array("firstName","completions","totalcalls","time","callt","CPH","CALLSPH","effectiveness"),array(T_("Operator"),T_("Completions"),T_("Calls"),T_("Total time"),T_("Call time"),T_("Completions p/h"),T_("Calls p/h"),T_("Effectiveness")));
}
}
xhtml_foot();
?>
<?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,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../css/custom.css"),array("../js/window.js"));
//$rs = get_stats_total(get_stats());
//print "<h2>" . T_("Overall") . "</h2>";
//xhtml_table($rs,array("firstName","completions","totalcalls","time","callt","CPH","CALLSPH","effectiveness"),array(T_("Operator"),T_("Completions"),T_("Calls"),T_("Total time"),T_("Call time"),T_("Completions p/h"),T_("Calls p/h"),T_("Effectiveness")));
$questionnaire_id = false;
print "<h3 class='form-inline pull-left'>" . T_("Please select a questionnaire") . "&emsp;</h3>";
if (isset($_GET['questionnaire_id'])) $questionnaire_id = bigintval($_GET['questionnaire_id']);
display_questionnaire_chooser($questionnaire_id,false,"form-inline clearfix", "form-control");
if ($questionnaire_id)
{
$rs = get_stats_total(get_stats_by_questionnaire($questionnaire_id));
print "<h2>" . T_("This project") . "</h2>";
xhtml_table($rs,array("firstName","completions","totalcalls","time","callt","CPH","CALLSPH","effectiveness"),array(T_("Operator"),T_("Completions"),T_("Calls"),T_("Total time"),T_("Call time"),T_("Completions p/h"),T_("Calls p/h"),T_("Effectiveness")));
$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 . "'),' " . TQ_("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);
print "</br><h3 class='form-inline pull-left'>" . T_("Please select a shift") . "&emsp;</h3>";
display_chooser($rs,"shift_id","shift_id",true,"questionnaire_id=$questionnaire_id",true,true,false,true,"form-inline form-group");//,false,true,false,true,"pull-left"
if ($shift_id)
{
$rs = get_stats_total(get_stats_by_shift($questionnaire_id,$shift_id));
print "<h2>" . T_("This shift") . "</h2>";
xhtml_table($rs,array("firstName","completions","totalcalls","time","callt","CPH","CALLSPH","effectiveness"),array(T_("Operator"),T_("Completions"),T_("Calls"),T_("Total time"),T_("Call time"),T_("Completions p/h"),T_("Calls p/h"),T_("Effectiveness")));
}
}
xhtml_foot();
?>

View File

@@ -1,176 +1,176 @@
<?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, '\'>". TQ_("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();
?>
<?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("../include/bootstrap-3.3.2/css/bootstrap.min.css","../css/custom.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 ,false,"form-inline clearfix", "form-control");
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",true,true,false,true,"form-inline form-group");
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, '\'>". TQ_("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();
?>

View File

@@ -1,83 +1,91 @@
<?php
/**
* Set if supervisor chat should be enabled and required details
*
*
* 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@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2013
* @package queXS
* @subpackage admin
* @link http://www.acspri.org.au/ queXS was writen for ACSPRI
* @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");
if (isset($_POST['update']))
{
set_setting("bosh_service",$_POST['bosh']);
set_setting("supervisor_xmpp",$_POST['supervisor']);
$enable = false;
if (isset($_POST['enable']))
$enable = true;
set_setting("chat_enabled",$enable);
}
xhtml_head(T_("Supervisor chat"),true,false,array("../js/window.js"));
print "<p>" . T_("Allow interviewers to chat with the supervisor over XMPP (Jabber). Required is a BOSH enabled XMPP/Jabber server. The operators and the supervisor will need XMPP/Jabber accounts.") . "</p>";
$e = get_setting("chat_enabled");
$checked = "checked='checked'";
if (empty($e))
$checked = "";
?>
<form action="" method="post">
<p>
<div><label for="enable"><?php echo T_("Enable supervisor chat?"); ?>: </label><input id='enable' type='checkbox' name='enable' val='1' <?php echo $checked; ?>/></div>
<div><label for="bosh"><?php echo T_("Set BOSH URL"); ?>: </label><input id='bosh' type='text' name='bosh' value='<?php echo get_setting("bosh_service"); ?>'/></div>
<div><label for="supervisor"><?php echo T_("Supervisor XMPP/Jabber id"); ?>: </label><input id='supervisor' name='supervisor' type='text' value='<?php echo get_setting("supervisor_xmpp"); ?>'/></div>
<div><input type="submit" id="update" name="update" value="<?php echo T_("Update"); ?>"/></div>
</p>
</form>
<?php
xhtml_foot();
?>
<?php
/**
* Set if supervisor chat should be enabled and required details
*
*
* 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@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2013
* @package queXS
* @subpackage admin
* @link http://www.acspri.org.au/ queXS was writen for ACSPRI
* @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");
if (isset($_POST['update']))
{
set_setting("bosh_service",$_POST['bosh']);
set_setting("supervisor_xmpp",$_POST['supervisor']);
$enable = false;
if (isset($_POST['enable']))
$enable = true;
set_setting("chat_enabled",$enable);
}
xhtml_head(T_("Supervisor chat"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../include/bootstrap-toggle/css/bootstrap-toggle.min.css","../css/custom.css"),array("../js/jquery-2.1.3.min.js", "../include/bootstrap-3.3.2/js/bootstrap.min.js","../include/bootstrap-toggle/js/bootstrap-toggle.min.js","../js/window.js"));
print "<p class='well'>" . T_("Allow interviewers to chat with the supervisor over XMPP (Jabber). Required is a BOSH enabled XMPP/Jabber server. The operators and the supervisor will need XMPP/Jabber accounts.") . "</p>";
$e = get_setting("chat_enabled");
$checked = "checked='checked'";
if (empty($e))
$checked = "";
?>
<form action="" method="post" class="form-horizontal">
<div class="form-group form-inline">
<label class="control-label col-sm-3" for="enable"><?php echo T_("Enable supervisor chat?"); ?>: </label>
<input id='enable' type='checkbox' data-toggle="toggle" data-on="<?php echo T_("Yes"); ?>" data-off="<?php echo T_("No"); ?>" data-width="80" name='enable' val='1' <?php echo $checked; ?>/>
</div>
<div class="form-group form-inline">
<label class="control-label col-sm-3" for="bosh"><?php echo T_("Set BOSH URL"); ?>: </label>
<input id='bosh' type='text' name='bosh' class="form-control pull-left" required size="60" value='<?php echo get_setting("bosh_service"); ?>'/>
</div>
<div class="form-group form-inline">
<label class="control-label col-sm-3" for="supervisor"><?php echo T_("Supervisor XMPP/Jabber id"); ?>: </label>
<input id='supervisor' name='supervisor' type='text' class="form-control pull-left" required size="60" value='<?php echo get_setting("supervisor_xmpp"); ?>'/>
</div>
<input type="submit" id="update" name="update" class="btn btn-primary col-sm-offset-3 col-sm-3" value="<?php echo T_("Update"); ?>"/>
</form>
<?php
xhtml_foot();
?>

View File

@@ -1,111 +1,112 @@
<?php
/**
* Run the system wide case sorting process and monitor it's progress
*
*
* 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@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2011
* @package queXS
* @subpackage admin
* @link http://www.acspri.org.au/ queXS was writen for ACSPRI
* @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");
/**
* Process
*/
include ("../functions/functions.process.php");
/**
* XHTML functions
*/
include("../functions/functions.xhtml.php");
if (isset($_GET['watch']))
{
//start watching process
start_process(realpath(dirname(__FILE__) . "/systemsortprocess.php"),2);
}
$p = is_process_running(2);
if ($p)
{
if (isset($_GET['kill']))
{
if ($_GET['kill'] == "force")
end_process($p);
else
kill_process($p);
set_setting('systemsort',false);
}
xhtml_head(T_("Monitor system wide case sorting"),true,array("../css/table.css"),false,false,false,true);
print "<h1>" . T_("Running process:") . " $p</h1>";
if (is_process_killed($p))
{
print "<h3>" . T_("Kill signal sent: Please wait...") . "</h3>";
print "<p><a href='?kill=force'>" . T_("Process is already closed (eg. server was rebooted) - click here to confirm") . "</a></p>";
}
else
{
print "<p><a href='?kill=kill'>" . T_("Kill the running process") . "</a></p>";
}
$d = process_get_data($p);
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
}
else
{
xhtml_head(T_("Monitor system wide case sorting"),true,array("../css/table.css"));
print "<h2>" . T_("Monitor system wide case sorting") . "</h2>";
print "<p><a href='?watch=watch'>" . T_("Click here to enable and begin system wide case sorting") . "</a></p>";
print "<p>" . T_("System wide case sorting is periodically (via SYSTEM_SORT_MINUTES configuration directive) sorting cases on a system wide basis instead of finding the most appropriate case each time an operator requests a new case. This may increase performance where there are a large number of cases or complex quotas in place. If you are not experiencing any performance problems, it is not recommended to use this feature.") . "</p>";
print "<h2>" . T_("Outcome of last process run (if any)") . "</h2>";
$d = process_get_last_data(2);
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
}
xhtml_foot();
?>
<?php
/**
* Run the system wide case sorting process and monitor it's progress
*
*
* 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@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2011
* @package queXS
* @subpackage admin
* @link http://www.acspri.org.au/ queXS was writen for ACSPRI
* @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");
/**
* Process
*/
include ("../functions/functions.process.php");
/**
* XHTML functions
*/
include("../functions/functions.xhtml.php");
if (isset($_GET['watch']))
{
//start watching process
start_process(realpath(dirname(__FILE__) . "/systemsortprocess.php"),2);
}
$p = is_process_running(2);
if ($p)
{
if (isset($_GET['kill']))
{
if ($_GET['kill'] == "force")
end_process($p);
else
kill_process($p);
set_setting('systemsort',false);
}
xhtml_head(T_("Monitor system wide case sorting"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../css/custom.css"),false,false,false,true);
print "<h2>" . T_("Running process:") . " $p</h2>";
if (is_process_killed($p))
{
print "<h3>" . T_("Kill signal sent: Please wait...") . "</h3>";
print "<p><a href='?kill=force'>" . T_("Process is already closed (eg. server was rebooted) - click here to confirm") . "</a></p>";
}
else
{
print "<p><a href='?kill=kill'>" . T_("Kill the running process") . "</a></p>";
}
$d = process_get_data($p);
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
}
else
{
xhtml_head(T_("Monitor system wide case sorting"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../css/custom.css"));
//print "<h2>" . T_("Monitor system wide case sorting") . "</h2>";
print "<p><a href='?watch=watch'>" . T_("Click here to enable and begin system wide case sorting") . "</a></p>";
print "<div class='well pull-right col-sm-4'><p>" . T_("System wide case sorting is periodically (via SYSTEM_SORT_MINUTES configuration directive) sorting cases on a system wide basis instead of finding the most appropriate case each time an operator requests a new case. This may increase performance where there are a large number of cases or complex quotas in place. If you are not experiencing any performance problems, it is not recommended to use this feature.") . "</p></div>";
print "<h2>" . T_("Outcome of last process run (if any)") . "</h2>";
$d = process_get_last_data(2);
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
}
xhtml_foot();
?>

View File

@@ -1,344 +1,347 @@
<?php
/**
* Run the system wide case sorting process
*
*
* 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@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2011
* @package queXS
* @subpackage admin
* @link http://www.acspri.org.au/ queXS was written for ACSPRI
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
*
*/
/**
* Configuration file
*/
include (dirname(__FILE__) . "/../config.inc.php");
/**
* Database file
*/
include (dirname(__FILE__) . "/../db.inc.php");
/**
* Process
*/
include (dirname(__FILE__) . "/../functions/functions.process.php");
/**
* Operator functions (for quotas)
*/
include (dirname(__FILE__) . "/../functions/functions.operator.php");
/**
* Update the database with the new data from the running script
*
* @param string $buffer The data to append to the database
* @return string Return a blank string to empty the buffer
*/
function update_callback($buffer)
{
global $process_id;
process_append_data($process_id,$buffer);
return ""; //empty buffer
}
/**
* Disable system sort on shutdown
*
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @since 2011-01-31
*/
function disable_systemsort()
{
set_setting('systemsort',false);
}
//get the arguments from the command line (this process_id)
if ($argc != 2) exit();
$process_id = $argv[1];
//register an exit function which will tell the database we have ended
register_shutdown_function('end_process',$process_id);
register_shutdown_function('disable_systemsort');
//all output send to database instead of stdout
ob_start('update_callback',2);
$closecasescounter = 0;
print T_("Sorting cases process starting");
$closecasesinterval = (24 * 60) / SYSTEM_SORT_MINUTES; //check for closed cases once every day
$sleepinterval = 10; // in seconds so we can monitor if the process has been killed
while (!is_process_killed($process_id)) //check if process killed every $sleepinterval
{
//Make sure that the system knows we are system sorting
set_setting('systemsort',true);
if ($closecasescounter == 0 || $closecasescounter > $closecasesinterval)
{
$time_start = microtime(true);
print T_("Checking for cases open for more than 24 hours");
$closecasescounter = 0;
$db->StartTrans();
//find all call attempts without an end that started more than 24 hours ago
$sql = "SELECT case_id, call_attempt_id
FROM `call_attempt`
WHERE TIMESTAMPDIFF(HOUR, start, CONVERT_TZ(NOW(),'System','UTC')) > 24
AND end IS NULL";
$rs = $db->GetAll($sql);
foreach ($rs as $r)
{
//refer to supervisor if case still assigned
$sql = "UPDATE `case`
SET current_operator_id = NULL, current_outcome_id = 5
WHERE case_id = '{$r['case_id']}'
AND current_operator_id IS NOT NULL
AND current_call_id IS NULL";
$db->Execute($sql);
//add note
$sql = "INSERT INTO case_note (case_id,operator_id,note,`datetime`)
VALUES ('{$r['case_id']}',1,'" . TQ_("System automatically closed case as not closed for more than 24 hours") ."', CONVERT_TZ(NOW(),'System','UTC'))";
$db->Execute($sql);
//finish the call attempt
$sql = "UPDATE `call_attempt`
SET end = start
WHERE call_attempt_id = '{$r['call_attempt_id']}'";
$db->Execute($sql);
print T_("System automatically closed case as not closed for more than 24 hours") . " - " . T_("Case id") . ": {$r['case_id']}";
}
//find all calls without an end that started more than 24 hours ago
$sql = "SELECT case_id, call_id
FROM `call`
WHERE TIMESTAMPDIFF(HOUR, start, CONVERT_TZ(NOW(),'System','UTC')) > 24
AND end IS NULL";
$rs = $db->GetAll($sql);
foreach ($rs as $r)
{
//refer to supervisor if case still assigned
$sql = "UPDATE `case`
SET current_operator_id = NULL, current_outcome_id = 5, current_call_id = NULL
WHERE case_id = '{$r['case_id']}'
AND current_operator_id IS NOT NULL";
$db->Execute($sql);
//add note
$sql = "INSERT INTO case_note (case_id,operator_id,note,`datetime`)
VALUES ('{$r['case_id']}',1,'" . TQ_("System automatically closed case as not closed for more than 24 hours") ."', CONVERT_TZ(NOW(),'System','UTC'))";
$db->Execute($sql);
//finish the call
$sql = "UPDATE `call`
SET end = start, outcome_id = 5, state = 5
WHERE call_id = '{$r['call_id']}'";
$db->Execute($sql);
print T_("System automatically closed case as not closed for more than 24 hours") . " - " . T_("Case id") . ": {$r['case_id']}";
}
$result = $db->CompleteTrans();
$time_end = microtime(true);
$timer = $time_end - $time_start;
if ($result)
print T_("Completed case closing") . ". " . T_("This task took") . ": $timer " . T_("seconds");
else
print T_("Failed to complete case closing") . ". " . T_("This task took") . ": $timer " . T_("seconds");
}
$closecasescounter++;
//Sort cases on a questionnaire by questionnaire basis
$sql = "SELECT questionnaire_id, description
FROM questionnaire
WHERE enabled = 1";
$qs = $db->GetAll($sql);
foreach($qs as $q)
{
print T_("Sorting cases for ") . $q['description'];
$questionnaire_id = $q['questionnaire_id'];
$time_start = microtime(true);
$db->StartTrans();
//Set all cases as unavailable
$sql = "UPDATE `case`
SET sortorder = NULL
WHERE sortorder IS NOT NULL
AND questionnaire_id = '$questionnaire_id'";
$db->Execute($sql);
//update quotas
update_quotas($questionnaire_id);
//Sort current cases for this questionnaire
$sql = "SELECT c.case_id
FROM `case` as c
LEFT JOIN `call` as a on (a.call_id = c.last_call_id)
JOIN (sample as s, sample_import as si) on (s.sample_id = c.sample_id and si.sample_import_id = s.import_id)
JOIN (questionnaire_sample as qs, questionnaire as q, outcome as ou) on (c.questionnaire_id = q.questionnaire_id and qs.sample_import_id = s.import_id and ou.outcome_id = c.current_outcome_id and q.questionnaire_id = '$questionnaire_id' and qs.questionnaire_id = c.questionnaire_id)
LEFT JOIN shift as sh on (sh.questionnaire_id = q.questionnaire_id and (CONVERT_TZ(NOW(),'System','UTC') >= sh.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= sh.end))
LEFT JOIN appointment as ap on (ap.case_id = c.case_id AND ap.completed_call_id is NULL AND (ap.start > CONVERT_TZ(NOW(),'System','UTC')))
LEFT JOIN appointment as apn on (apn.case_id = c.case_id AND apn.completed_call_id is NULL AND (CONVERT_TZ(NOW(),'System','UTC') >= apn.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= apn.end))
LEFT JOIN call_restrict as cr on (cr.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= cr.start and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= cr.end)
LEFT JOIN questionnaire_sample_exclude_priority AS qsep ON (qsep.questionnaire_id = c.questionnaire_id AND qsep.sample_id = c.sample_id)
LEFT JOIN case_availability AS casa ON (casa.case_id = c.case_id)
LEFT JOIN availability AS ava ON (ava.availability_group_id = casa.availability_group_id)
LEFT JOIN questionnaire_timeslot AS qast ON (qast.questionnaire_id = c.questionnaire_id)
LEFT JOIN questionnaire_sample_timeslot AS qasts ON (qasts.questionnaire_id = c.questionnaire_id AND qasts.sample_import_id = si.sample_import_id)
WHERE c.current_operator_id IS NULL
AND c.questionnaire_id = '$questionnaire_id'
AND ((apn.appointment_id IS NOT NULL) OR casa.case_id IS NULL OR (ava.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(),'System',s.Time_zone_name)) AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= ava.start AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= ava.end ))
AND ((apn.appointment_id IS NOT NULL) OR qast.questionnaire_id IS NULL OR ((SELECT COUNT(*) FROM availability WHERE availability.availability_group_id = qast.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(),'System',s.Time_zone_name)) AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= availability.end)) >= 1 AND (SELECT COUNT(call_attempt_id) FROM `call_attempt`, availability WHERE call_attempt.case_id = c.case_id AND (availability.availability_group_id = qast.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(call_attempt.start,'UTC',s.Time_zone_name)) AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) <= availability.end))) = ( SELECT (SELECT COUNT(*) FROM availability, call_attempt WHERE call_attempt.case_id = c.case_id AND availability.availability_group_id = availability_group.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(call_attempt.start,'UTC',s.Time_zone_name)) AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) <= availability.end)) as cou FROM availability_group, questionnaire_timeslot WHERE questionnaire_timeslot.questionnaire_id = c.questionnaire_id AND availability_group.availability_group_id = questionnaire_timeslot.availability_group_id ORDER BY cou ASC LIMIT 1)))
AND ((apn.appointment_id IS NOT NULL) OR qasts.questionnaire_id IS NULL OR ((SELECT COUNT(*) FROM availability WHERE availability.availability_group_id = qasts.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(),'System',s.Time_zone_name)) AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= availability.end)) >= 1 AND (SELECT COUNT(call_attempt_id) FROM `call_attempt`, availability WHERE call_attempt.case_id = c.case_id AND (availability.availability_group_id = qasts.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(call_attempt.start,'UTC',s.Time_zone_name)) AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) <= availability.end))) = ( SELECT (SELECT COUNT(*) FROM availability, call_attempt WHERE call_attempt.case_id = c.case_id AND availability.availability_group_id = availability_group.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(call_attempt.start,'UTC',s.Time_zone_name)) AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) <= availability.end)) as cou FROM availability_group, questionnaire_sample_timeslot WHERE questionnaire_sample_timeslot.questionnaire_id = c.questionnaire_id AND questionnaire_sample_timeslot.sample_import_id = si.sample_import_id AND availability_group.availability_group_id = questionnaire_sample_timeslot.availability_group_id ORDER BY cou ASC LIMIT 1)))
AND (a.call_id is NULL or (a.end < CONVERT_TZ(DATE_SUB(NOW(), INTERVAL ou.default_delay_minutes MINUTE),'System','UTC')))
AND ap.case_id is NULL
AND ((qsep.questionnaire_id is NULL) or qsep.exclude = 0)
AND !(q.restrict_work_shifts = 1 AND sh.shift_id IS NULL)
AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL)
AND ((apn.appointment_id IS NOT NULL) or qs.call_attempt_max = 0 or ((SELECT count(*) FROM call_attempt WHERE case_id = c.case_id) < qs.call_attempt_max))
AND ((apn.appointment_id IS NOT NULL) or qs.call_max = 0 or ((SELECT count(*) FROM `call` WHERE case_id = c.case_id) < qs.call_max))
AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = c.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0
GROUP BY c.case_id
ORDER BY IF(ISNULL(apn.end),1,0),apn.end ASC, qsep.priority DESC, a.start ASC";
$rs = $db->GetAll($sql);
$i = 1;
foreach ($rs as $r)
{
$sql = "UPDATE `case`
SET sortorder = '$i'
WHERE case_id = '{$r['case_id']}'";
$db->Execute($sql);
$i++;
}
//First set all sample records as unavailable
$sql = "UPDATE `questionnaire_sample_exclude_priority`
SET sortorder = NULL
WHERE sortorder IS NOT NULL
AND questionnaire_id = '$questionnaire_id'";
$db->Execute($sql);
//Sort sample list where attached to this questionnaire
$sql = "SELECT s.sample_id as sample_id,qs.questionnaire_id as questionnaire_id
FROM sample as s
JOIN (questionnaire_sample as qs, questionnaire as q, sample_import as si) on (qs.sample_import_id = s.import_id and si.sample_import_id = s.import_id and q.questionnaire_id = qs.questionnaire_id AND q.questionnaire_id = '$questionnaire_id')
LEFT JOIN `case` as c on (c.sample_id = s.sample_id and c.questionnaire_id = qs.questionnaire_id)
LEFT JOIN call_restrict as cr on (cr.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= cr.start and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= cr.end)
LEFT JOIN shift as sh on (sh.questionnaire_id = q.questionnaire_id and (CONVERT_TZ(NOW(),'System','UTC') >= sh.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= sh.end))
LEFT JOIN questionnaire_sample_exclude_priority AS qsep ON (qsep.questionnaire_id = qs.questionnaire_id AND qsep.sample_id = s.sample_id)
WHERE c.case_id is NULL
AND ((qsep.questionnaire_id IS NULL) or qsep.exclude = 0)
AND !(q.restrict_work_shifts = 1 AND sh.shift_id IS NULL)
AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL)
AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = qs.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0
GROUP BY s.sample_id,qs.questionnaire_id
ORDER BY qsep.priority DESC, rand() * qs.random_select, s.sample_id";
$rs = $db->GetAll($sql);
$i = 1;
foreach ($rs as $r)
{
$sql = "INSERT INTO questionnaire_sample_exclude_priority (questionnaire_id,sample_id,exclude,priority,sortorder)
VALUES ('{$r['questionnaire_id']}', '{$r['sample_id']}', 0, 50,'$i')
ON DUPLICATE KEY UPDATE sortorder = '$i'";
$db->Execute($sql);
$i++;
}
$result = $db->CompleteTrans();
$time_end = microtime(true);
$timer = $time_end - $time_start;
if ($result)
print T_("Completed sort") . ". " . T_("This task took") . ": $timer " . T_("seconds");
else
print T_("Failed to complete sort") . ". " . T_("This task took") . ": $timer " . T_("seconds");
}
for ($i = 0; $i < (SYSTEM_SORT_MINUTES * 60); $i += $sleepinterval)
{
if (is_process_killed($process_id)){break;}
sleep($sleepinterval);
}
process_clear_log();
}
disable_systemsort();
ob_get_contents();
ob_end_clean();
?>
<?php
/**
* Run the system wide case sorting process
*
*
* 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@acspri.org.au>
* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2011
* @package queXS
* @subpackage admin
* @link http://www.acspri.org.au/ queXS was written for ACSPRI
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
*
*/
/**
* Configuration file
*/
include (dirname(__FILE__) . "/../config.inc.php");
/**
* Database file
*/
include (dirname(__FILE__) . "/../db.inc.php");
/**
* Process
*/
include (dirname(__FILE__) . "/../functions/functions.process.php");
/**
* Operator functions (for quotas)
*/
include (dirname(__FILE__) . "/../functions/functions.operator.php");
/**
* Update the database with the new data from the running script
*
* @param string $buffer The data to append to the database
* @return string Return a blank string to empty the buffer
*/
function update_callback($buffer)
{
global $process_id;
process_append_data($process_id,$buffer);
return ""; //empty buffer
}
/**
* Disable system sort on shutdown
*
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @since 2011-01-31
*/
function disable_systemsort()
{
set_setting('systemsort',false);
}
//get the arguments from the command line (this process_id)
if ($argc != 2) exit();
$process_id = $argv[1];
//register an exit function which will tell the database we have ended
register_shutdown_function('end_process',$process_id);
register_shutdown_function('disable_systemsort');
//all output send to database instead of stdout
ob_start('update_callback',2);
$closecasescounter = 0;
print T_("Sorting cases process starting");
$closecasesinterval = (24 * 60) / SYSTEM_SORT_MINUTES; //check for closed cases once every day
$sleepinterval = 10; // in seconds so we can monitor if the process has been killed
while (!is_process_killed($process_id)) //check if process killed every $sleepinterval
{
//Make sure that the system knows we are system sorting
set_setting('systemsort',true);
if ($closecasescounter == 0 || $closecasescounter > $closecasesinterval)
{
$time_start = microtime(true);
print T_("Checking for cases open for more than 24 hours");
$closecasescounter = 0;
$db->StartTrans();
//find all call attempts without an end that started more than 24 hours ago
$sql = "SELECT case_id, call_attempt_id
FROM `call_attempt`
WHERE TIMESTAMPDIFF(HOUR, start, CONVERT_TZ(NOW(),'System','UTC')) > 24
AND end IS NULL";
$rs = $db->GetAll($sql);
foreach ($rs as $r)
{
//refer to supervisor if case still assigned
$sql = "UPDATE `case`
SET current_operator_id = NULL, current_outcome_id = 5
WHERE case_id = '{$r['case_id']}'
AND current_operator_id IS NOT NULL
AND current_call_id IS NULL";
$db->Execute($sql);
//add note
$sql = "INSERT INTO case_note (case_id,operator_id,note,`datetime`)
VALUES ('{$r['case_id']}',1,'" . TQ_("System automatically closed case as not closed for more than 24 hours") ."', CONVERT_TZ(NOW(),'System','UTC'))";
$db->Execute($sql);
//finish the call attempt
$sql = "UPDATE `call_attempt`
SET end = start
WHERE call_attempt_id = '{$r['call_attempt_id']}'";
$db->Execute($sql);
print T_("System automatically closed case as not closed for more than 24 hours") . " - " . T_("Case id") . ": {$r['case_id']}";
}
//find all calls without an end that started more than 24 hours ago
$sql = "SELECT case_id, call_id
FROM `call`
WHERE TIMESTAMPDIFF(HOUR, start, CONVERT_TZ(NOW(),'System','UTC')) > 24
AND end IS NULL";
$rs = $db->GetAll($sql);
foreach ($rs as $r)
{
//refer to supervisor if case still assigned
$sql = "UPDATE `case`
SET current_operator_id = NULL, current_outcome_id = 5, current_call_id = NULL
WHERE case_id = '{$r['case_id']}'
AND current_operator_id IS NOT NULL";
$db->Execute($sql);
//add note
$sql = "INSERT INTO case_note (case_id,operator_id,note,`datetime`)
VALUES ('{$r['case_id']}',1,'" . TQ_("System automatically closed case as not closed for more than 24 hours") ."', CONVERT_TZ(NOW(),'System','UTC'))";
$db->Execute($sql);
//finish the call
$sql = "UPDATE `call`
SET end = start, outcome_id = 5, state = 5
WHERE call_id = '{$r['call_id']}'";
$db->Execute($sql);
print T_("System automatically closed case as not closed for more than 24 hours") . " - " . T_("Case id") . ": {$r['case_id']}";
}
$result = $db->CompleteTrans();
$time_end = microtime(true);
$timer = $time_end - $time_start;
if ($result)
print T_("Completed case closing") . ". " . T_("This task took") . ": $timer " . T_("seconds");
else
print T_("Failed to complete case closing") . ". " . T_("This task took") . ": $timer " . T_("seconds");
}
$closecasescounter++;
//Sort cases on a questionnaire by questionnaire basis
$sql = "SELECT questionnaire_id, description
FROM questionnaire
WHERE enabled = 1";
$qs = $db->GetAll($sql);
foreach($qs as $q)
{
print T_("Sorting cases for ") . $q['description'];
$questionnaire_id = $q['questionnaire_id'];
$time_start = microtime(true);
$db->StartTrans();
//Set all cases as unavailable
$sql = "UPDATE `case`
SET sortorder = NULL
WHERE sortorder IS NOT NULL
AND questionnaire_id = '$questionnaire_id'";
$db->Execute($sql);
//update quotas
update_quotas($questionnaire_id);
//Sort current cases for this questionnaire
$sql = "SELECT c.case_id
FROM `case` as c
LEFT JOIN `call` as a on (a.call_id = c.last_call_id)
JOIN (sample as s, sample_import as si) on (s.sample_id = c.sample_id and si.sample_import_id = s.import_id)
JOIN (questionnaire_sample as qs, questionnaire as q, outcome as ou) on (c.questionnaire_id = q.questionnaire_id and qs.sample_import_id = s.import_id and ou.outcome_id = c.current_outcome_id and q.questionnaire_id = '$questionnaire_id' and qs.questionnaire_id = c.questionnaire_id)
LEFT JOIN shift as sh on (sh.questionnaire_id = q.questionnaire_id and (CONVERT_TZ(NOW(),'System','UTC') >= sh.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= sh.end))
LEFT JOIN appointment as ap on (ap.case_id = c.case_id AND ap.completed_call_id is NULL AND (ap.start > CONVERT_TZ(NOW(),'System','UTC')))
LEFT JOIN appointment as apn on (apn.case_id = c.case_id AND apn.completed_call_id is NULL AND (CONVERT_TZ(NOW(),'System','UTC') >= apn.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= apn.end))
LEFT JOIN call_restrict as cr on (cr.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= cr.start and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= cr.end)
LEFT JOIN questionnaire_sample_exclude_priority AS qsep ON (qsep.questionnaire_id = c.questionnaire_id AND qsep.sample_id = c.sample_id)
LEFT JOIN case_availability AS casa ON (casa.case_id = c.case_id)
LEFT JOIN availability AS ava ON (ava.availability_group_id = casa.availability_group_id)
LEFT JOIN questionnaire_timeslot AS qast ON (qast.questionnaire_id = c.questionnaire_id)
LEFT JOIN questionnaire_sample_timeslot AS qasts ON (qasts.questionnaire_id = c.questionnaire_id AND qasts.sample_import_id = si.sample_import_id)
WHERE c.current_operator_id IS NULL
AND c.questionnaire_id = '$questionnaire_id'
AND ((apn.appointment_id IS NOT NULL) OR casa.case_id IS NULL OR (ava.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(),'System',s.Time_zone_name)) AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= ava.start AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= ava.end ))
AND ((apn.appointment_id IS NOT NULL) OR qast.questionnaire_id IS NULL OR ((SELECT COUNT(*) FROM availability WHERE availability.availability_group_id = qast.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(),'System',s.Time_zone_name)) AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= availability.end)) >= 1 AND (SELECT COUNT(call_attempt_id) FROM `call_attempt`, availability WHERE call_attempt.case_id = c.case_id AND (availability.availability_group_id = qast.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(call_attempt.start,'UTC',s.Time_zone_name)) AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) <= availability.end))) = ( SELECT (SELECT COUNT(*) FROM availability, call_attempt WHERE call_attempt.case_id = c.case_id AND availability.availability_group_id = availability_group.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(call_attempt.start,'UTC',s.Time_zone_name)) AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) <= availability.end)) as cou FROM availability_group, questionnaire_timeslot WHERE questionnaire_timeslot.questionnaire_id = c.questionnaire_id AND availability_group.availability_group_id = questionnaire_timeslot.availability_group_id ORDER BY cou ASC LIMIT 1)))
AND ((apn.appointment_id IS NOT NULL) OR qasts.questionnaire_id IS NULL OR ((SELECT COUNT(*) FROM availability WHERE availability.availability_group_id = qasts.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(),'System',s.Time_zone_name)) AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= availability.end)) >= 1 AND (SELECT COUNT(call_attempt_id) FROM `call_attempt`, availability WHERE call_attempt.case_id = c.case_id AND (availability.availability_group_id = qasts.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(call_attempt.start,'UTC',s.Time_zone_name)) AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) <= availability.end))) = ( SELECT (SELECT COUNT(*) FROM availability, call_attempt WHERE call_attempt.case_id = c.case_id AND availability.availability_group_id = availability_group.availability_group_id AND (availability.day_of_week = DAYOFWEEK(CONVERT_TZ(call_attempt.start,'UTC',s.Time_zone_name)) AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) >= availability.start AND TIME(CONVERT_TZ(call_attempt.start, 'UTC' , s.Time_zone_name)) <= availability.end)) as cou FROM availability_group, questionnaire_sample_timeslot WHERE questionnaire_sample_timeslot.questionnaire_id = c.questionnaire_id AND questionnaire_sample_timeslot.sample_import_id = si.sample_import_id AND availability_group.availability_group_id = questionnaire_sample_timeslot.availability_group_id ORDER BY cou ASC LIMIT 1)))
AND (a.call_id is NULL or (a.end < CONVERT_TZ(DATE_SUB(NOW(), INTERVAL ou.default_delay_minutes MINUTE),'System','UTC')))
AND ap.case_id is NULL
AND ((qsep.questionnaire_id is NULL) or qsep.exclude = 0)
AND !(q.restrict_work_shifts = 1 AND sh.shift_id IS NULL)
AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL)
AND ((apn.appointment_id IS NOT NULL) or qs.call_attempt_max = 0 or ((SELECT count(*) FROM call_attempt WHERE case_id = c.case_id) < qs.call_attempt_max))
AND ((apn.appointment_id IS NOT NULL) or qs.call_max = 0 or ((SELECT count(*) FROM `call` WHERE case_id = c.case_id) < qs.call_max))
AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = c.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0
GROUP BY c.case_id
ORDER BY IF(ISNULL(apn.end),1,0), apn.end ASC, qsep.priority DESC, a.start ASC";
$rs = $db->GetAll($sql);
$i = 1;
foreach ($rs as $r)
{
$sql = "UPDATE `case`
SET sortorder = '$i'
WHERE case_id = '{$r['case_id']}'";
$db->Execute($sql);
$i++;
}
//First set all sample records as unavailable
$sql = "UPDATE `questionnaire_sample_exclude_priority`
SET sortorder = NULL
WHERE sortorder IS NOT NULL
AND questionnaire_id = '$questionnaire_id'";
$db->Execute($sql);
//Sort sample list where attached to this questionnaire
$sql = "SELECT s.sample_id as sample_id,qs.questionnaire_id as questionnaire_id
FROM sample as s
JOIN (questionnaire_sample as qs, questionnaire as q, sample_import as si) on (qs.sample_import_id = s.import_id and si.sample_import_id = s.import_id and q.questionnaire_id = qs.questionnaire_id AND q.questionnaire_id = '$questionnaire_id')
LEFT JOIN `case` as c on (c.sample_id = s.sample_id and c.questionnaire_id = qs.questionnaire_id)
LEFT JOIN call_restrict as cr on (cr.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= cr.start and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= cr.end)
LEFT JOIN shift as sh on (sh.questionnaire_id = q.questionnaire_id and (CONVERT_TZ(NOW(),'System','UTC') >= sh.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= sh.end))
LEFT JOIN questionnaire_sample_exclude_priority AS qsep ON (qsep.questionnaire_id = qs.questionnaire_id AND qsep.sample_id = s.sample_id)
WHERE c.case_id is NULL
AND ((qsep.questionnaire_id IS NULL) or qsep.exclude = 0)
AND !(q.restrict_work_shifts = 1 AND sh.shift_id IS NULL)
AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL)
AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = qs.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0
GROUP BY s.sample_id,qs.questionnaire_id
ORDER BY qsep.priority DESC, rand() * qs.random_select, s.sample_id";
$rs = $db->GetAll($sql);
$i = 1;
foreach ($rs as $r)
{
$sql = "INSERT INTO questionnaire_sample_exclude_priority (questionnaire_id,sample_id,exclude,priority,sortorder)
VALUES ('{$r['questionnaire_id']}', '{$r['sample_id']}', 0, 50,'$i')
ON DUPLICATE KEY UPDATE sortorder = '$i'";
$db->Execute($sql);
$i++;
}
$result = $db->CompleteTrans();
$time_end = microtime(true);
$timer = $time_end - $time_start;
if ($result)
print T_("Completed sort") . ". " . T_("This task took") . ": $timer " . T_("seconds");
else
print T_("Failed to complete sort") . ". " . T_("This task took") . ": $timer " . T_("seconds");
}
for ($i = 0; $i < (SYSTEM_SORT_MINUTES * 60); $i += $sleepinterval)
{
if (is_process_killed($process_id)){break;}
sleep($sleepinterval);
}
process_clear_log();
}
disable_systemsort();
ob_get_contents();
ob_end_clean();
?>

View File

@@ -1,107 +1,107 @@
<?php
/**
* Run the VoIP monitoring process and monitor it via the database
*
*
* 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");
/**
* Process
*/
include ("../functions/functions.process.php");
/**
* XHTML functions
*/
include("../functions/functions.xhtml.php");
if (isset($_GET['watch']))
{
//start watching process
start_process(realpath(dirname(__FILE__) . "/process.php"));
}
$p = is_process_running();
if ($p)
{
if (isset($_GET['kill']))
{
if ($_GET['kill'] == "force")
end_process($p);
else
kill_process($p);
}
xhtml_head(T_("Monitor VoIP Process"),true,array("../css/table.css"),false,false,false,true);
print "<h1>" . T_("Running process:") . " $p</h1>";
if (is_process_killed($p))
{
print "<h3>" . T_("Kill signal sent: Please wait... (Note: Process will be stalled until there is activity on the VoIP Server)") . "</h3>";
print "<p><a href='?kill=force'>" . T_("Process is already closed (eg. server was rebooted) - click here to confirm") . "</a></p>";
}
else
{
print "<p><a href='?kill=kill'>" . T_("Kill the running process") . "</a> ". T_("(requires activity on the VoIP Server to take effect)") . "</p>";
}
$d = process_get_data($p);
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
}
else
{
xhtml_head(T_("Monitor VoIP Process"),true,array("../css/table.css"));
print "<h2>" . T_("Monitor VoIP Process") . "</h2>";
print "<p><a href='?watch=watch'>" . T_("Click here to begin monitoring the VoIP Process") . "</a></p>";
print "<h2>" . T_("Outcome of last process run (if any)") . "</h2>";
$d = process_get_last_data();
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
}
xhtml_foot();
?>
<?php
/**
* Run the VoIP monitoring process and monitor it via the database
*
*
* 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");
/**
* Process
*/
include ("../functions/functions.process.php");
/**
* XHTML functions
*/
include("../functions/functions.xhtml.php");
if (isset($_GET['watch']))
{
//start watching process
start_process(realpath(dirname(__FILE__) . "/process.php"));
}
$p = is_process_running();
if ($p)
{
if (isset($_GET['kill']))
{
if ($_GET['kill'] == "force")
end_process($p);
else
kill_process($p);
}
xhtml_head(T_("Monitor VoIP Process"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../css/custom.css"),false,false,false,true);
print "<h2>" . T_("Running process:") . " $p</h2>";
if (is_process_killed($p))
{
print "<h3>" . T_("Kill signal sent: Please wait... </br>(Note: Process will be stalled until there is activity on the VoIP Server)") . "</h3>";
print "<p>" . T_("Process is already closed (eg. server was rebooted)") . "<a href='?kill=force'>" . T_("click here to confirm") . "</a></p>";
}
else
{
print "<p><a class='btn btn-default' href='?kill=kill'>" . T_("Kill the running process") . "</a> ". T_("(requires activity on the VoIP Server to take effect)") . "</p>";
}
$d = process_get_data($p);
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
}
else
{
xhtml_head(T_("Monitor VoIP Process"),true,array("../include/bootstrap-3.3.2/css/bootstrap.min.css","../css/custom.css"));
//print "<h2>" . T_("Monitor VoIP Process") . "</h2>";
print "<p><a class='btn btn-warning' href='?watch=watch'>" . T_("Click here to begin monitoring the VoIP Process") . "</a></p>";
print "<h3>" . T_("Outcome of last process run (if any)") . "</h3>";
$d = process_get_last_data();
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
}
xhtml_foot();
?>