mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Import from DCARF SVN
This commit is contained in:
291
functions/functions.aapor.php
Normal file
291
functions/functions.aapor.php
Normal file
@@ -0,0 +1,291 @@
|
||||
<?
|
||||
/**
|
||||
* Functions to calculate AAPOR outcomes based on Standard Definitions here:
|
||||
*
|
||||
* The American Association for Public Opinion Research. 2004. Standard Definitions: Final Dispositions of Case Codes and Outcome Rates for Surveys. 3rd edition. Lenexa, Kansas: AAPOR.
|
||||
*
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return a cleaned array containing all required elements
|
||||
* for AAPOR calculations
|
||||
*
|
||||
* @param array $a Array containing some of I,P,R,NC,O,UH,UO keys
|
||||
* @return array Array containing all I,P,R,NC,O,UH,UO keys
|
||||
*/
|
||||
function aapor_clean($a)
|
||||
{
|
||||
if (!isset($a['I']) || empty($a['I'])) $a['I'] = 0;
|
||||
if (!isset($a['P']) || empty($a['P'])) $a['P'] = 0;
|
||||
if (!isset($a['R']) || empty($a['R'])) $a['R'] = 0;
|
||||
if (!isset($a['NC']) || empty($a['NC'])) $a['NC'] = 0;
|
||||
if (!isset($a['O']) || empty($a['O'])) $a['O'] = 0;
|
||||
if (!isset($a['UH']) || empty($a['UH'])) $a['UH'] = 0;
|
||||
if (!isset($a['UO']) || empty($a['UO'])) $a['UO'] = 0;
|
||||
if (!isset($a[' ']) || empty($a[' '])) $a[' '] = 0;
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's RR1
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Response rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_rr1($a)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($a['UH'] + $a['UO']));
|
||||
if ($d == 0) return 0;
|
||||
return $a['I'] / $d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's RR2
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Response rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_rr2($a)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($a['UH'] + $a['UO']));
|
||||
if ($d == 0) return 0;
|
||||
return ($a['I'] + $a['P']) / $d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's RR3
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @param float $e Estimated proportion of cases of unknown eligibility that are eligible
|
||||
* @return float Response rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_rr3($a,$e)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($e*($a['UH'] + $a['UO'])));
|
||||
if ($d == 0) return 0;
|
||||
return ($a['I']) / $d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's RR4
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @param float $e Estimated proportion of cases of unknown eligibility that are eligible
|
||||
* @return float Response rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_rr4($a,$e)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($e*($a['UH'] + $a['UO'])));
|
||||
if ($d == 0) return 0;
|
||||
return ($a['I'] + $a['P']) / $d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's RR5
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Response rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_rr5($a)
|
||||
{
|
||||
return aapor_rr3($a,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's RR6
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Response rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_rr6($a)
|
||||
{
|
||||
return aapor_rr4($a,0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's COOP1
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Cooperation rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_coop1($a)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + $a['R'] + $a['O']);
|
||||
if ($d == 0) return 0;
|
||||
return $a['I'] / $d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's COOP2
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Cooperation rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_coop2($a)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + $a['R'] + $a['O']);
|
||||
if ($d == 0) return 0;
|
||||
return ($a['I'] + $a['P']) / $d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's COOP3
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Cooperation rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_coop3($a)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + $a['R']);
|
||||
if ($d == 0) return 0;
|
||||
return $a['I'] / $d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's COOP4
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Cooperation rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_coop4($a)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + $a['R']);
|
||||
if ($d == 0) return 0;
|
||||
return ($a['I'] + $a['P']) / $d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's REF1
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Refusal rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_ref1($a)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($a['UH'] + $a['UO']));
|
||||
if ($d == 0) return 0;
|
||||
return $a['R'] / $d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's REF2
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @param float $e Estimated proportion of cases of unknown eligibility that are eligible
|
||||
* @return float Refusal rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_ref2($a,$e)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($e*($a['UH'] + $a['UO'])));
|
||||
if ($d == 0) return 0;
|
||||
return ($a['R']) / $d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's REF3
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Refusal rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_ref3($a)
|
||||
{
|
||||
return aapor_ref2($a,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's CON1
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Contact rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_con1($a)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($a['UH'] + $a['UO']));
|
||||
if ($d == 0) return 0;
|
||||
return (($a['I'] + $a['P']) + $a['R'] +$a['O']) / $d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's CON2
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @param float $e Estimated proportion of cases of unknown eligibility that are eligible
|
||||
* @return float Contact rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_con2($a,$e)
|
||||
{
|
||||
$d = (($a['I'] + $a['P']) + ($a['R'] + $a['NC'] + $a['O']) + ($e*($a['UH'] + $a['UO'])));
|
||||
if ($d == 0) return 0;
|
||||
return (($a['I'] + $a['P']) + $a['R'] +$a['O']) / $d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate AAPOR's CON3
|
||||
*
|
||||
* @param array $a Array containing I,P,R,NC,O,UH,UO keys
|
||||
* @return float Contact rate as a decimal
|
||||
*
|
||||
*/
|
||||
function aapor_con3($a)
|
||||
{
|
||||
return aapor_con2($a,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
534
functions/functions.calendar.php
Normal file
534
functions/functions.calendar.php
Normal file
@@ -0,0 +1,534 @@
|
||||
<?
|
||||
/**
|
||||
* Functions relating to appointment times and calendars
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Configuration file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../config.inc.php');
|
||||
|
||||
/**
|
||||
* Database file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../db.inc.php');
|
||||
|
||||
|
||||
/**
|
||||
* Add a phone number to a case (via the contact_phone table)
|
||||
*
|
||||
* @param int $case_id Case id
|
||||
* @param int $phone Phone number
|
||||
* @return bool Result false if failed to add else true
|
||||
*/
|
||||
function add_contact_phone($case_id,$phone)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "INSERT INTO contact_phone
|
||||
(contact_phone_id,case_id,priority,phone)
|
||||
SELECT NULL,$case_id,MAX(priority)+1,'$phone'
|
||||
FROM contact_phone
|
||||
WHERE case_id = $case_id";
|
||||
|
||||
return $db->Execute($sql);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an appointment to a case (via the appointment table)
|
||||
*
|
||||
* @param int $respondent_id The respondent
|
||||
* @param int $case_id The case
|
||||
* @param int $contact_phone_id The contact phone number to call on
|
||||
* @param int $call_attempt_id the current call attempt
|
||||
* @param int $d the day of the month
|
||||
* @param int $m the month of the year
|
||||
* @param int $y the year (4 digit)
|
||||
* @param string $start The time in the format HH:MM:SS
|
||||
* @param string $end The time in the format HH:MM:SS
|
||||
* @return bool Result false if failed to add else true
|
||||
*/
|
||||
function make_appointment($respondent_id,$case_id,$contact_phone_id,$call_attempt_id,$d,$m,$y,$start,$end)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$start = "$y-$m-$d $start";
|
||||
$end= "$y-$m-$d $end";
|
||||
|
||||
$sql = "INSERT INTO `appointment`
|
||||
(appointment_id,case_id,contact_phone_id,call_attempt_id,start,end,require_operator_id,respondent_id,completed_call_id)
|
||||
SELECT NULL,'$case_id','$contact_phone_id','$call_attempt_id',CONVERT_TZ('$start',r.Time_zone_name,'UTC'),CONVERT_TZ('$end',r.Time_zone_name,'UTC'),NULL,$respondent_id,NULL
|
||||
FROM respondent as r
|
||||
WHERE r.respondent_id = '$respondent_id'";
|
||||
|
||||
return $db->Execute($sql);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Take a 24 hour time in the format: hh:mm:ss and make it more human
|
||||
*
|
||||
* @param string $time The time in the format HH:MM:SS
|
||||
* @return string Human readable time
|
||||
*/
|
||||
function convert_time($time)
|
||||
{
|
||||
$h = intval(substr($time,0,2));
|
||||
$m = substr($time,3,2);
|
||||
$s = intval(substr($time,5,2));
|
||||
|
||||
if ($h > 12)
|
||||
return $h - 12 . ":$m"."pm";
|
||||
else
|
||||
return $h . ":$m"."am";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether or not a questionnaire is restricted to work in shifts
|
||||
*
|
||||
* @param int $questionnaire_id Questionnaire ID
|
||||
* @return bool True if shift restricted else false
|
||||
*/
|
||||
function is_shift_restricted($questionnaire_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT restrict_appointments_shifts as r
|
||||
FROM questionnaire
|
||||
WHERE questionnaire_id = '$questionnaire_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
if ($rs['r'] == 1) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an arary containing all contact phone numbers for a case
|
||||
*
|
||||
* @param int $case_id The case ID
|
||||
* @return array|bool An array of contact phone numbers else false if none
|
||||
*/
|
||||
function return_contact_phone_list($case_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT contact_phone_id,phone,description
|
||||
FROM contact_phone
|
||||
WHERE case_id = '$case_id'";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
return $rs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print a list of respodnents for a case
|
||||
* with an HTML GET request with the respondent_id
|
||||
*
|
||||
* @param int $case_id The case ID
|
||||
* @param bool|int $respondent_id The respondent already selected or false if none selected
|
||||
*/
|
||||
function display_respondent_list($case_id,$respondent_id = false)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT respondent_id,firstName,lastName
|
||||
FROM respondent
|
||||
WHERE case_id = '$case_id'";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
print "<div><select id='respondent_id' name='respondent_id' onchange=\"LinkUp('respondent_id')\"><option>" . T_("None") . "</option>";
|
||||
if (!empty($rs))
|
||||
{
|
||||
foreach($rs as $r)
|
||||
{
|
||||
$rid = $r['respondent_id'];
|
||||
$selected = "";
|
||||
if ($rid == $respondent_id) $selected="selected='selected'";
|
||||
print "<option value='?respondent_id=$rid' $selected>{$r['firstName']} {$r['lastName']}</option>";
|
||||
}
|
||||
}
|
||||
print "<option value='?respondent_id=0' class='addresp'>" . T_("Add respondent") . "</option></select></div>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Print an XHTML form for adding or modifying respondent details
|
||||
*
|
||||
* @param bool|int $respondent_id The respondent already selected or false if none selected
|
||||
* @param bool|int $case_id The case to add a respondent to or false if none selected
|
||||
*/
|
||||
function display_respondent_form($respondent_id = false,$case_id = false)
|
||||
{
|
||||
global $db;
|
||||
|
||||
/**
|
||||
* Use the default time zone if none other to work with
|
||||
*/
|
||||
$rzone = DEFAULT_TIME_ZONE;
|
||||
$fn = "";
|
||||
$ln = "";
|
||||
|
||||
if ($respondent_id)
|
||||
{
|
||||
$sql = "SELECT Time_zone_name,firstName,lastName
|
||||
FROM respondent
|
||||
WHERE respondent_id = '$respondent_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
$rzone = $rs['Time_zone_name'];
|
||||
$fn = $rs['firstName'];
|
||||
$ln = $rs['lastName'];
|
||||
}
|
||||
else if ($case_id)
|
||||
{
|
||||
$sql = "SELECT Time_zone_name
|
||||
FROM respondent
|
||||
WHERE case_id = '$case_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT Time_zone_name
|
||||
FROM timezone_template";
|
||||
|
||||
$rs = $db->Execute($sql);
|
||||
|
||||
print "<div><label for='firstName'>" . T_("First name:") . " </label><input type=\"text\" id='firstName' name=\"firstName\" value=\"$fn\"/></div>
|
||||
<div><label for='lastName'>" . T_("Last name:") . " </label><input type=\"text\" id='lastName' name=\"lastName\" value=\"$ln\"/></div>";
|
||||
|
||||
/**
|
||||
* Display the current respondent zone in a drop down box with other zones from timezone_template
|
||||
*/
|
||||
print "<div><label>" . T_("Time Zone:") . " ".$rs->GetMenu('Time_zone_name',$rzone,false)."</label></div>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print shift details in XHTML based on the given day
|
||||
* Display start time, and if start time selected display end time also
|
||||
* Used generally for making an appointment
|
||||
*
|
||||
* @see make_appointment()
|
||||
*
|
||||
* @param int $respondent_id The respondent id
|
||||
* @param int $day the day of the month
|
||||
* @param int $month the month of the year
|
||||
* @param int $year the year (4 digit)
|
||||
* @param string $time The time in the format HH:MM:SS
|
||||
* @param string $timeend The time in the format HH:MM:SS
|
||||
*
|
||||
* @todo Handle questionnaires without shift restrictions
|
||||
*/
|
||||
function display_time($respondent_id, $day, $month, $year, $time = false, $timeend = false)
|
||||
{
|
||||
global $db;
|
||||
|
||||
/**
|
||||
* Select shift start and end times for this day
|
||||
*/
|
||||
$sql = " SELECT s.shift_id, HOUR(TIME(CONVERT_TZ(s.start,'UTC',r.Time_zone_name))) as sh, MINUTE(TIME(CONVERT_TZ(s.start,'UTC',r.Time_zone_name))) as sm, !(DATE(CONVERT_TZ(NOW(),'System',r.Time_zone_name)) = DATE(CONVERT_TZ(s.start,'UTC',r.Time_zone_name))) as today, HOUR(TIME(CONVERT_TZ(NOW(),'System',r.Time_zone_name))) as eh, MINUTE(TIME(CONVERT_TZ(NOW(),'System',r.Time_zone_name))) as em, (TIME_TO_SEC( TIMEDIFF( TIME( CONVERT_TZ( s.end, 'UTC', r.Time_zone_name ) ) , TIME( CONVERT_TZ( s.start, 'UTC', r.Time_zone_name ) ) ) ) /300) as intervals, TIME(CONVERT_TZ(s.start,'UTC',r.Time_zone_name)) as start, TIME(CONVERT_TZ(s.end,'UTC',r.Time_zone_name)) as end
|
||||
FROM shift as s, respondent as r, `case` as c
|
||||
WHERE r.respondent_id = '$respondent_id'
|
||||
AND r.case_id = c.case_id
|
||||
AND s.questionnaire_id = c.questionnaire_id
|
||||
AND DAY(CONVERT_TZ(s.start,'UTC', r.Time_zone_name)) = '$day'
|
||||
AND MONTH(CONVERT_TZ(s.start,'UTC', r.Time_zone_name)) = '$month'
|
||||
AND YEAR(CONVERT_TZ(s.start,'UTC', r.Time_zone_name)) = '$year'
|
||||
ORDER BY s.start ASC";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
print "<div class=\"shifts\">";
|
||||
foreach($rs as $r)
|
||||
{
|
||||
print "<p>" . T_("Shift from:") . " ".convert_time($r['start'])." till ".convert_time($r['end'])."</p>";
|
||||
}
|
||||
print "</div>";
|
||||
|
||||
|
||||
|
||||
print "<p>";
|
||||
print "<select name=\"start\" id=\"start\" onchange=\"LinkUp('start')\"><option value=\"?y=$year&m=$month&d=$day&respondent_id=$respondent_id\">" . T_("Start Time") . "</option>";
|
||||
foreach ($rs as $r)
|
||||
{
|
||||
$sh = $r['sh'];
|
||||
$sm = $r['sm'];
|
||||
$intervals = $r['intervals'];
|
||||
|
||||
//eh and em should be the current respondent time
|
||||
$eh = $r['eh'];
|
||||
$em = $r['em'];
|
||||
|
||||
//today = 0 if the shift is today otherwise 1
|
||||
$today = $r['today'];
|
||||
|
||||
/**
|
||||
* Display only times in the future and within the shift in 5 minute intervals
|
||||
*
|
||||
*/
|
||||
for ($i = 0; $i <= $intervals; $i++)
|
||||
{
|
||||
$t = str_pad($sh,2,"0",STR_PAD_LEFT).":".str_pad($sm,2,"0",STR_PAD_LEFT).":00";
|
||||
|
||||
if ($today || ($sh > $eh || ($sh == $eh && $sm > $em)))
|
||||
{
|
||||
$selected = "";
|
||||
if ($t == $time) $selected = "selected=\"selected\"";
|
||||
|
||||
print "<option value=\"?y=$year&m=$month&d=$day&respondent_id=$respondent_id&start=$t\" $selected>".convert_time($t)."</option>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sm += 5;
|
||||
if ($sm >= 60)
|
||||
{
|
||||
$sh++;
|
||||
if ($sh >= 24) $sh -= 24;
|
||||
$sm -= 60;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
print "</select>";
|
||||
|
||||
if ($time)
|
||||
{
|
||||
$eh = substr($time,0,2);
|
||||
$em = substr($time,3,2);
|
||||
|
||||
print "<select name=\"end\" id=\"end\" onchange=\"LinkUp('end')\"><option value=\"?y=$year&m=$month&d=$day&respondent_id=$respondent_id&start=$time\">" . T_("End Time") . "</option>";
|
||||
foreach ($rs as $r)
|
||||
{
|
||||
$sh = $r['sh'];
|
||||
$sm = $r['sm'];
|
||||
$intervals = $r['intervals'];
|
||||
|
||||
|
||||
/**
|
||||
* Display only times after the start time and within the shift in 5 minute intervals
|
||||
*
|
||||
*/
|
||||
for ($i = 0; $i <= $intervals; $i++)
|
||||
{
|
||||
$t = str_pad($sh,2,"0",STR_PAD_LEFT).":".str_pad($sm,2,"0",STR_PAD_LEFT).":00";
|
||||
|
||||
if ($sh > $eh || ($sh == $eh && $sm > $em))
|
||||
{
|
||||
$selected = "";
|
||||
if ($t == $timeend) $selected = "selected=\"selected\"";
|
||||
|
||||
print "<option value=\"?y=$year&m=$month&d=$day&respondent_id=$respondent_id&start=$time&end=$t\" $selected>".convert_time($t)."</option>";
|
||||
}
|
||||
|
||||
$sm += 5;
|
||||
if ($sm >= 60)
|
||||
{
|
||||
$sh++;
|
||||
if ($sh >= 24) $sh -= 24;
|
||||
$sm -= 60;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
print "</select>";
|
||||
}
|
||||
|
||||
print "<input type=\"hidden\" name=\"respondent_id\" value=\"$respondent_id\"/>";
|
||||
print "<input type=\"hidden\" name=\"y\" value=\"$year\"/>";
|
||||
print "<input type=\"hidden\" name=\"m\" value=\"$month\"/>";
|
||||
print "<input type=\"hidden\" name=\"d\" value=\"$day\"/>";
|
||||
print "</p>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a tabular calendar for selecting dates for appointments
|
||||
* Based on code from the PEAR package
|
||||
*
|
||||
* @link http://pear.php.net/package/Calendar PEAR Calendar
|
||||
* @link http://pearcalendar.sourceforge.net/examples/3.php Example this code based on
|
||||
*
|
||||
* @see make_appointment()
|
||||
* @see display_time()
|
||||
*
|
||||
* @param int $respondent_id The respondent id
|
||||
* @param int $questionnaire_id The questionnaire id
|
||||
* @param bool|int $day the day of the month if selected else false
|
||||
* @param bool|int $month the month of the year if selected else false
|
||||
* @param bool|int $year the year (4 digit) if selected else false
|
||||
*
|
||||
*/
|
||||
function display_calendar($respondent_id, $questionnaire_id, $year = false, $month = false, $day = false)
|
||||
{
|
||||
global $db;
|
||||
|
||||
/**
|
||||
* PEAR Caldendar Weekday functions
|
||||
*/
|
||||
include_once('Calendar/Month/Weekdays.php');
|
||||
|
||||
/**
|
||||
* PEAR Caldendar Day functions
|
||||
*/
|
||||
include_once('Calendar/Day.php');
|
||||
|
||||
/**
|
||||
* See if questionnaire has shift restrictions
|
||||
*/
|
||||
$restricted = is_shift_restricted($questionnaire_id);
|
||||
|
||||
$rtime = strtotime(get_respondent_time($respondent_id));
|
||||
|
||||
$y = date('Y',$rtime);
|
||||
$m = date('m',$rtime);
|
||||
$d = date('d',$rtime);
|
||||
|
||||
if (!$year) $year = $y;
|
||||
if (!$month) $month = $m;
|
||||
if (!$day) $day = $d;
|
||||
|
||||
$ttoday = new Calendar_Day($y,$m,$d);
|
||||
|
||||
$Month = new Calendar_Month_Weekdays($year,$month);
|
||||
|
||||
// Construct strings for next/previous links
|
||||
$PMonth = $Month->prevMonth('object'); // Get previous month as object
|
||||
$prev = '?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay().'&respondent_id='.$respondent_id;
|
||||
$NMonth = $Month->nextMonth('object');
|
||||
$next = '?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay().'&respondent_id='.$respondent_id;
|
||||
|
||||
// Build the days in the month
|
||||
$Month->build();
|
||||
?>
|
||||
<table class="calendar">
|
||||
<caption>
|
||||
<?php echo ( date('F Y',$Month->getTimeStamp())); ?>
|
||||
</caption>
|
||||
<tr>
|
||||
<th>M</th>
|
||||
<th>T</th>
|
||||
<th>W</th>
|
||||
<th>T</th>
|
||||
<th>F</th>
|
||||
<th>S</th>
|
||||
<th>S</th>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
|
||||
while ( $Day = $Month->fetch() ) {
|
||||
|
||||
// Build a link string for each day
|
||||
$link = '?y='.$Day->thisYear().
|
||||
'&m='.$Day->thisMonth().
|
||||
'&d='.$Day->thisDay().
|
||||
'&respondent_id='.$respondent_id;
|
||||
|
||||
$today = "";
|
||||
if ($year == $Day->thisYear() && $month == $Day->thisMonth() && $day == $Day->thisDay()) $today = "today";
|
||||
|
||||
|
||||
// isFirst() to find start of week
|
||||
if ( $Day->isFirst() )
|
||||
echo ( "<tr>\n" );
|
||||
|
||||
if ( $Day->isSelected() ) {
|
||||
echo ( "<td class=\"selected $today\">".$Day->thisDay()."</td>\n" );
|
||||
} else if ( $Day->isEmpty() ) {
|
||||
echo ( "<td> </td>\n" );
|
||||
} else {
|
||||
//if it is in the past -> unavailable
|
||||
if ($Day->getTimeStamp() < $ttoday->getTimeStamp())
|
||||
{
|
||||
echo ( "<td class=\"notavailable\">".$Day->thisDay()."</td>\n" );
|
||||
}
|
||||
//if there are shift restrictions, restrict
|
||||
else if ($restricted)
|
||||
{
|
||||
$rs = $db->Execute(" SELECT s.shift_id
|
||||
FROM shift as s
|
||||
LEFT JOIN respondent as r on (r.respondent_id = '$respondent_id')
|
||||
WHERE s.questionnaire_id = '$questionnaire_id'
|
||||
AND DAY(CONVERT_TZ(s.start,'UTC',r.Time_zone_name)) = '{$Day->thisDay()}'
|
||||
AND MONTH(CONVERT_TZ(s.start,'UTC',r.Time_zone_name)) = '{$Day->thisMonth()}'
|
||||
AND YEAR(CONVERT_TZ(s.start,'UTC',r.Time_zone_name)) = '{$Day->thisYear()}'");
|
||||
|
||||
if ($rs->RecordCount() == 0)
|
||||
{
|
||||
echo ( "<td class=\"notavailable $today\">".$Day->thisDay()."</td>\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo ( "<td class=\"$today\"><a href=\"".$link."\">".$Day->thisDay()."</a></td>\n" );
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
echo ( "<td class=\"$today\"><a href=\"".$link."\">".$Day->thisDay()."</a></td>\n" );
|
||||
}
|
||||
|
||||
// isLast() to find end of week
|
||||
if ( $Day->isLast() )
|
||||
echo ( "</tr>\n" );
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<?php echo ($prev);?>" class="prevMonth"><< </a>
|
||||
</td>
|
||||
<td colspan="5"> </td>
|
||||
<td>
|
||||
<a href="<?php echo ($next);?>" class="nextMonth"> >></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
89
functions/functions.client.php
Normal file
89
functions/functions.client.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?
|
||||
/**
|
||||
* Client functions
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configuration file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../config.inc.php');
|
||||
|
||||
/**
|
||||
* Database file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../db.inc.php');
|
||||
|
||||
/**
|
||||
* Return the current client id based on PHP_AUTH_USER
|
||||
*
|
||||
* @return bool|int False if none otherwise the client id
|
||||
*
|
||||
*/
|
||||
function get_client_id()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT client_id
|
||||
FROM client
|
||||
WHERE username = '{$_SERVER['PHP_AUTH_USER']}'";
|
||||
|
||||
$o = $db->GetRow($sql);
|
||||
|
||||
if (empty($o)) return false;
|
||||
|
||||
return $o['client_id'];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of questionnaires assigned to this client
|
||||
*
|
||||
* @param int $client_id Client id
|
||||
* @return bool|array False if nothing assigned otherwise an array of questionnaire assigned
|
||||
*
|
||||
*/
|
||||
function get_client_questionnaire($client_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT questionnaire_id
|
||||
FROM client_questionnaire
|
||||
WHERE client_id = '$client_id'";
|
||||
|
||||
$o = $db->GetAll($sql);
|
||||
|
||||
if (empty($o)) return false;
|
||||
|
||||
return $o;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
138
functions/functions.display.php
Normal file
138
functions/functions.display.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?
|
||||
/**
|
||||
* Functions relating to displaying for XHTML
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Configuration file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../config.inc.php');
|
||||
|
||||
/**
|
||||
* Database file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../db.inc.php');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Display a list of questionnaires to choose from in a drop down list
|
||||
*
|
||||
* @param int|bool $questionnaire_id The questionnaire id or false if none selecetd
|
||||
*
|
||||
*/
|
||||
function display_questionnaire_chooser($questionnaire_id = false)
|
||||
{
|
||||
global $db;
|
||||
|
||||
|
||||
$sql = "SELECT questionnaire_id,description,CASE WHEN questionnaire_id = '$questionnaire_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
FROM questionnaire";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
print "<div><select id='questionnaire' name='questionnaire' onchange=\"LinkUp('questionnaire')\"><option value='?'></option>";
|
||||
if (!empty($rs))
|
||||
{
|
||||
foreach($rs as $r)
|
||||
{
|
||||
print "<option value='?questionnaire_id={$r['questionnaire_id']}' {$r['selected']}>{$r['description']}</option>";
|
||||
}
|
||||
}
|
||||
print "</select></div>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a list of shifts to choose from in a drop down list
|
||||
*
|
||||
* @param int $questionnaire_id The questionnaire id
|
||||
* @param int|bool $shift_id The shift id or false if none selected
|
||||
*/
|
||||
function display_shift_chooser($questionnaire_id, $shift_id = false)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT s.shift_id,DATE_FORMAT(s.start,'" . DATE_TIME_FORMAT . "') as start,DATE_FORMAT(s.end,'" . TIME_FORMAT . "') as end,CASE WHEN s.shift_id = '$shift_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
FROM shift as s
|
||||
WHERE s.questionnaire_id = '$questionnaire_id'
|
||||
ORDER BY s.start ASC";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
print "<div><select id='shift' name='shift' onchange=\"LinkUp('shift')\"><option value='?questionnaire_id=$questionnaire_id'></option>";
|
||||
if (!empty($rs))
|
||||
{
|
||||
foreach($rs as $r)
|
||||
{
|
||||
print "<option value='?shift_id={$r['shift_id']}&questionnaire_id=$questionnaire_id' {$r['selected']}>{$r['start']} till {$r['end']}</option>";
|
||||
}
|
||||
}
|
||||
print "</select></div>";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a list of samples to choose from in a drop down list
|
||||
*
|
||||
* @param int $questionnaire_id The questionnaire id
|
||||
* @param int|bool $sample_import_id The sample import id or false if none selected
|
||||
*/
|
||||
function display_sample_chooser($questionnaire_id, $sample_import_id = false)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT s.sample_import_id,si.description,CASE WHEN s.sample_import_id = '$sample_import_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
FROM questionnaire_sample as s, sample_import as si
|
||||
WHERE s.questionnaire_id = '$questionnaire_id'
|
||||
AND s.sample_import_id = si.sample_import_id";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
print "<div><select id='sample' name='sample' onchange=\"LinkUp('sample')\"><option value='?questionnaire_id=$questionnaire_id'></option>";
|
||||
if (!empty($rs))
|
||||
{
|
||||
foreach($rs as $r)
|
||||
{
|
||||
print "<option value='?sample_import_id={$r['sample_import_id']}&questionnaire_id=$questionnaire_id' {$r['selected']}>{$r['sample_import_id']}: {$r['description']}</option>";
|
||||
}
|
||||
}
|
||||
print "</select></div>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
334
functions/functions.import.php
Normal file
334
functions/functions.import.php
Normal file
@@ -0,0 +1,334 @@
|
||||
<?
|
||||
/**
|
||||
* Functions relating to importing a sample file (from CSV)
|
||||
*
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Configuration file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../config.inc.php');
|
||||
|
||||
/**
|
||||
* Database file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../db.inc.php');
|
||||
|
||||
/**
|
||||
* Return only numbers from a string
|
||||
*
|
||||
* @param string $str String containing any character
|
||||
* @return int A number
|
||||
*
|
||||
*/
|
||||
function only_numbers($str)
|
||||
{
|
||||
return ereg_replace('[^0-9]*','',$str);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verify fields in a CSV file
|
||||
* confirm that there are no duplicate names
|
||||
* confirm that there is one and only one primary number selected
|
||||
*
|
||||
* @param array $fields an array of field information i_ if selected, n_ name, t_ type code
|
||||
* @return string An empty string if valid, otherwise invalid with error message
|
||||
*
|
||||
*/
|
||||
function verify_fields($fields)
|
||||
{
|
||||
//i_ is if selected
|
||||
//n_ is name of field
|
||||
//t_ is type of field
|
||||
|
||||
$selected = array();
|
||||
|
||||
foreach($fields as $key => $val)
|
||||
{
|
||||
if (strncmp($key, "i_", 2) == 0)
|
||||
{
|
||||
$selected[] = substr($key,2);
|
||||
}
|
||||
}
|
||||
|
||||
$names = array();
|
||||
|
||||
//check for duplicate names
|
||||
foreach($selected as $val)
|
||||
{
|
||||
if (array_key_exists($fields["n_$val"], $names))
|
||||
{
|
||||
return T_("Duplicate name");
|
||||
}
|
||||
else
|
||||
{
|
||||
//set name to type
|
||||
$names[$fields["n_$val"]] = $fields["t_$val"];
|
||||
}
|
||||
}
|
||||
|
||||
//check that there is one and one only primary phone selected
|
||||
$count = 0;
|
||||
foreach($names as $val)
|
||||
{
|
||||
if ($val == 3) $count++;
|
||||
}
|
||||
|
||||
if ($count == 1)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return T_("You must select one and one only Primary Phone number");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an XHTML table of the CSV data header
|
||||
*
|
||||
* @param array $data Header data from a CSV file
|
||||
*
|
||||
* @see get_first_row()
|
||||
*
|
||||
*/
|
||||
function display_table($data)
|
||||
{
|
||||
print "<table>";
|
||||
print "<tr><th></th><th>" . T_("Import?") . "</th><th>" . T_("Name") . "</th><th>" . T_("Type") . "</th></tr>";
|
||||
$row = 1;
|
||||
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT description,type
|
||||
FROM sample_var_type";
|
||||
|
||||
$rs = $db->Execute($sql);
|
||||
|
||||
foreach ($data as $key => $value)
|
||||
{
|
||||
$val = str_replace(" ", "_", $value);
|
||||
$checked = "checked";
|
||||
if (empty($val)) $val = "samp_$row";
|
||||
|
||||
print "<tr><td>$value</td><td><input type=\"checkbox\" name=\"i_$row\" checked=\"$checked\"/></td><td><input type=\"text\" value=\"$val\" name=\"n_$row\"/></td><td>" . $rs->GetMenu("t_$row","1",false) . "</td></tr>";
|
||||
$row++;
|
||||
|
||||
$rs->MoveFirst();
|
||||
}
|
||||
print "</table>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the first row of a CSV file as an array
|
||||
*
|
||||
* @param string $file File name to open
|
||||
*
|
||||
*/
|
||||
function get_first_row($file)
|
||||
{
|
||||
$handle = fopen($file, "r");
|
||||
$data = fgetcsv($handle);
|
||||
fclose($handle);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Import a CSV file to the sample database
|
||||
*
|
||||
* @param string $file File name to open
|
||||
* @param string $description A description of the sample
|
||||
* @param array $fields Which fields to import and what type they are assigned to
|
||||
*
|
||||
* @see verify_fields()
|
||||
* @see display_table()
|
||||
*
|
||||
*/
|
||||
function import_file($file, $description, $fields, $firstrow = 2)
|
||||
{
|
||||
|
||||
$row = 1;
|
||||
$handle = fopen($file, "r");
|
||||
|
||||
//import into database
|
||||
|
||||
global $db;
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
$sql = "INSERT INTO sample_import
|
||||
(sample_import_id, description)
|
||||
VALUES (NULL, '$description')";
|
||||
|
||||
//print("$sql<br/>");
|
||||
//if ($db->HasFailedTrans()) { print "FAILED"; exit(); }
|
||||
|
||||
$rs = $db->Execute($sql);
|
||||
$id = $db->Insert_ID();
|
||||
|
||||
$selected_type = array();
|
||||
$selected_name = array();
|
||||
|
||||
foreach($fields as $key => $val)
|
||||
{
|
||||
if (strncmp($key, "i_", 2) == 0)
|
||||
{
|
||||
$selected_type[substr($key,2)] = $fields["t_" . substr($key,2)];
|
||||
$selected_name[substr($key,2)] = $fields["n_" . substr($key,2)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create an ordered index of columns that contain data for obtaining the timezone
|
||||
* type of 5,4,3,2 preferred
|
||||
*/
|
||||
|
||||
arsort($selected_type);
|
||||
|
||||
$imported = 0;
|
||||
|
||||
while (($data = fgetcsv($handle)) !== FALSE)
|
||||
{
|
||||
//data contains an array of elements in the csv
|
||||
//selected contains an indexed array of elements to import with the type attached
|
||||
|
||||
if ($row >= $firstrow) //don't import the header row
|
||||
{
|
||||
//determine if there is a phone number - if not - do not import
|
||||
$numberavail = 0;
|
||||
foreach($selected_type as $key => $val)
|
||||
{
|
||||
if ($val == 2 || $val == 3)
|
||||
{
|
||||
$dkey = only_numbers($data[$key - 1]);
|
||||
if (!empty($dkey))
|
||||
$numberavail = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($numberavail == 1)
|
||||
{
|
||||
//insert into sample field
|
||||
|
||||
//first find the timezone
|
||||
|
||||
$tzone = DEFAULT_TIME_ZONE; //set this to default
|
||||
|
||||
/**
|
||||
* Determine time zone from all possible sources in sample_var_type table
|
||||
*
|
||||
*/
|
||||
foreach($selected_type as $key => $val)
|
||||
{
|
||||
$sql = "SELECT `table`
|
||||
FROM sample_var_type
|
||||
WHERE type = '$val'";
|
||||
|
||||
$tname = $db->GetRow($sql);
|
||||
|
||||
if (!empty($tname))
|
||||
{
|
||||
$tname = $tname['table'];
|
||||
if (!empty($tname))
|
||||
{
|
||||
|
||||
$value = $db->Quote($data[$key - 1]);
|
||||
|
||||
$sql = "SELECT Time_zone_name as tz
|
||||
FROM `$tname`
|
||||
WHERE val = SUBSTR($value, 1, CHAR_LENGTH( val ) )";
|
||||
|
||||
$tz = $db->GetRow($sql);
|
||||
|
||||
//print("$sql<br/>");
|
||||
//if ($db->HasFailedTrans()) { print "FAILED"; exit(); }
|
||||
|
||||
if (!empty($tz))
|
||||
{
|
||||
$tzone = $tz['tz'];
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* insert using primary phone number (3)
|
||||
*/
|
||||
$ppid = array_search('3', $selected_type);
|
||||
|
||||
$dppid = only_numbers($data[$ppid - 1]);
|
||||
|
||||
$sql = "INSERT INTO sample (sample_id,import_id,Time_zone_name,phone)
|
||||
VALUES (NULL,'$id','$tzone','$dppid')";
|
||||
|
||||
$db->Execute($sql);
|
||||
$sid = $db->Insert_Id();
|
||||
|
||||
|
||||
/**
|
||||
* insert into sample_var field
|
||||
*/
|
||||
foreach($selected_name as $key => $val)
|
||||
{
|
||||
$dkey = $db->Quote($data[$key - 1]);
|
||||
|
||||
$sql = "INSERT INTO sample_var (sample_id,var,val,type)
|
||||
VALUES ('$sid','$val',{$dkey},'{$selected_type[$key]}')";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
}
|
||||
|
||||
$imported++;
|
||||
}
|
||||
}
|
||||
|
||||
$row++;
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
//cleanup
|
||||
unlink($file);
|
||||
|
||||
return $db->CompleteTrans();
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
52
functions/functions.input.php
Normal file
52
functions/functions.input.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?
|
||||
/**
|
||||
* Input conversion functions
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configuration file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../config.inc.php');
|
||||
|
||||
/**
|
||||
* Return only numbers given a string
|
||||
*
|
||||
* @param string $val The value to convert to numbers only
|
||||
* @return int 0 if empty or no numbers otherwise the number portion of the string
|
||||
*
|
||||
*/
|
||||
function bigintval($val)
|
||||
{
|
||||
$r = ereg_replace('[^0-9]*','',$val);
|
||||
if (empty($r))
|
||||
return 0;
|
||||
else
|
||||
return $r;
|
||||
}
|
||||
576
functions/functions.limesurvey.php
Normal file
576
functions/functions.limesurvey.php
Normal file
@@ -0,0 +1,576 @@
|
||||
<?
|
||||
|
||||
/**
|
||||
* Functions relating to integration with {@link http://www.limesurvey.org/ LimeSurvey}
|
||||
*
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Configuration file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../config.inc.php');
|
||||
|
||||
/**
|
||||
* Database file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../db.inc.php');
|
||||
|
||||
|
||||
/**
|
||||
* Taken from common.php in the LimeSurvey package
|
||||
* Add a prefix to a database name
|
||||
*
|
||||
* @param string $name Database name
|
||||
* @link http://www.limesurvey.org/ LimeSurvey
|
||||
*/
|
||||
function db_table_name($name)
|
||||
{
|
||||
return "`".LIME_PREFIX.$name."`";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Taken from common.php in the LimeSurvey package
|
||||
* Get a random survey ID
|
||||
*
|
||||
* @link http://www.limesurvey.org/ LimeSurvey
|
||||
*/
|
||||
function getRandomID()
|
||||
{ // Create a random survey ID - based on code from Ken Lyle
|
||||
// Random sid/ question ID generator...
|
||||
$totalChar = 5; // number of chars in the sid
|
||||
$salt = "123456789"; // This is the char. that is possible to use
|
||||
srand((double)microtime()*1000000); // start the random generator
|
||||
$sid=""; // set the inital variable
|
||||
for ($i=0;$i<$totalChar;$i++) // loop and create sid
|
||||
$sid = $sid . substr ($salt, rand() % strlen($salt), 1);
|
||||
return $sid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Taken from admin/database.php in the LimeSurvey package
|
||||
* With modifications
|
||||
*
|
||||
* @param string $title Questionnaire name
|
||||
* @link http://www.limesurvey.org/ LimeSurvey
|
||||
*/
|
||||
function create_limesurvey_questionnaire($title)
|
||||
{
|
||||
global $ldb;
|
||||
|
||||
// Get random ids until one is found that is not used
|
||||
do
|
||||
{
|
||||
$surveyid = getRandomID();
|
||||
$isquery = "SELECT sid FROM ".db_table_name('surveys')." WHERE sid=$surveyid";
|
||||
$isresult = $ldb->Execute($isquery);
|
||||
}
|
||||
while ($isresult->RecordCount()>0);
|
||||
|
||||
$isquery = "INSERT INTO ". LIME_PREFIX ."surveys\n"
|
||||
. "(sid, owner_id, admin, active, useexpiry, expires, "
|
||||
. "adminemail, private, faxto, format, template, url, "
|
||||
. "language, datestamp, ipaddr, refurl, usecookie, notification, allowregister, attribute1, attribute2, "
|
||||
. "allowsave, autoredirect, allowprev,datecreated,tokenanswerspersistence)\n"
|
||||
. "VALUES ($surveyid, 1,\n"
|
||||
. "'', 'N', \n"
|
||||
. "'N','1980-01-01', '', 'N',\n"
|
||||
. "'', 'G', 'quexs', '" . QUEXS_URL . "rs_project_end.php',\n"
|
||||
. "'en', 'Y', 'N', 'N',\n"
|
||||
. "'N', '0', 'Y',\n"
|
||||
. "'att1', 'att2', \n"
|
||||
. "'Y', 'Y', 'Y','".date("Y-m-d")."','Y')";
|
||||
$isresult = $ldb->Execute($isquery);
|
||||
|
||||
// insert base language into surveys_language_settings
|
||||
$isquery = "INSERT INTO ".db_table_name('surveys_languagesettings')
|
||||
. "(surveyls_survey_id, surveyls_language, surveyls_title, surveyls_description, surveyls_welcometext, surveyls_urldescription, "
|
||||
. "surveyls_email_invite_subj, surveyls_email_invite, surveyls_email_remind_subj, surveyls_email_remind, "
|
||||
. "surveyls_email_register_subj, surveyls_email_register, surveyls_email_confirm_subj, surveyls_email_confirm)\n"
|
||||
. "VALUES ($surveyid, 'en', $title, $title,\n"
|
||||
. "'',\n"
|
||||
. "'', '',\n"
|
||||
. "'', '',\n"
|
||||
. "'', '',\n"
|
||||
. "'', '',\n"
|
||||
. "'')";
|
||||
$isresult = $ldb->Execute($isquery);
|
||||
|
||||
// Insert into survey_rights
|
||||
$isrquery = "INSERT INTO ". LIME_PREFIX . "surveys_rights VALUES($surveyid,1,1,1,1,1,1,1)";
|
||||
$isrresult = $ldb->Execute($isrquery) or die ($isrquery."<br />".$ldb->ErrorMsg());
|
||||
|
||||
return $surveyid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the lime_sid given the case_id
|
||||
*
|
||||
* @param int $case_id The case id
|
||||
* @return bool|int False if no lime_sid otherwise the lime_sid
|
||||
*
|
||||
*/
|
||||
function get_lime_sid($case_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT q.lime_sid
|
||||
FROM questionnaire as q, `case` as c
|
||||
WHERE c.case_id = '$case_id'
|
||||
AND q.questionnaire_id = c.questionnaire_id";
|
||||
|
||||
$l = $db->GetRow($sql);
|
||||
|
||||
if (empty($l)) return false;
|
||||
|
||||
return $l['lime_sid'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if LimeSurvey has marked a questionnaire as complete
|
||||
*
|
||||
* @param int $case_id The case id
|
||||
* @return bool True if complete, false if not or unknown
|
||||
*
|
||||
*/
|
||||
function limesurvey_is_completed($case_id)
|
||||
{
|
||||
global $ldb;
|
||||
|
||||
$lime_sid = get_lime_sid($case_id);
|
||||
if ($lime_sid == false) return false;
|
||||
|
||||
$sql = "SELECT completed
|
||||
FROM " . LIME_PREFIX . "tokens_$lime_sid
|
||||
WHERE token = '$case_id'";
|
||||
|
||||
$r = $ldb->GetRow($sql);
|
||||
|
||||
if (!empty($r))
|
||||
if ($r['completed'] != 'N') return true;
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the number of questions in the given questionnaire
|
||||
*
|
||||
* @param int $lime_sid The limesurvey sid
|
||||
* @return bool|int False if no data, otherwise the number of questions
|
||||
*
|
||||
*/
|
||||
function limesurvey_get_numberofquestions($lime_sid)
|
||||
{
|
||||
global $ldb;
|
||||
|
||||
$sql = "SELECT count(qid) as c
|
||||
FROM " . LIME_PREFIX . "questions
|
||||
WHERE sid = '$lime_sid'";
|
||||
|
||||
$r = $ldb->GetRow($sql);
|
||||
|
||||
if (!empty($r))
|
||||
return $r['c'];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the percent complete a questionnaire is, or false if not started
|
||||
*
|
||||
* @param int $case_id The case id
|
||||
* @return bool|float False if no data, otherwise the percentage of questions answered
|
||||
*
|
||||
*/
|
||||
function limesurvey_percent_complete($case_id)
|
||||
{
|
||||
global $ldb;
|
||||
|
||||
$lime_sid = get_lime_sid($case_id);
|
||||
if ($lime_sid == false) return false;
|
||||
|
||||
$sql = "SELECT saved_thisstep
|
||||
FROM ". LIME_PREFIX ."saved_control
|
||||
WHERE sid = '$lime_sid'
|
||||
AND identifier = '$case_id'";
|
||||
|
||||
$r = $ldb->GetRow($sql);
|
||||
|
||||
if (!empty($r))
|
||||
{
|
||||
$step = $r['saved_thisstep'];
|
||||
$questions = limesurvey_get_numberofquestions($lime_sid);
|
||||
return ($step / $questions) * 100.0;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function limesurvey_get_width($qid,$default)
|
||||
{
|
||||
global $ldb;
|
||||
|
||||
$sql = "SELECT value FROM ".LIME_PREFIX."question_attributes WHERE qid = '$qid' and attribute = 'maximum_chars'";
|
||||
$r = $ldb->GetRow($sql);
|
||||
|
||||
if (!empty($r))
|
||||
$default = $r['value'];
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function limesurvey_fixed_width($lid)
|
||||
{
|
||||
global $ldb;
|
||||
|
||||
$sql = "SELECT MAX(LENGTH(code)) as c FROM ".LIME_PREFIX."labels WHERE lid = $lid";
|
||||
$r = $ldb->GetRow($sql);
|
||||
|
||||
$val = 1;
|
||||
|
||||
if (!empty($r))
|
||||
$val = $r['c'];
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
function limesurvey_create_multi(&$varwidth,&$vartype,$qid,$varname,$length,$type)
|
||||
{
|
||||
global $ldb;
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM ".LIME_PREFIX."answers
|
||||
WHERE qid = $qid
|
||||
ORDER BY sortorder ASC";
|
||||
|
||||
$r = $ldb->GetAll($sql);
|
||||
|
||||
foreach($r as $Row)
|
||||
{
|
||||
$v = $varname . $Row['code'];
|
||||
$varwidth[$v] = $length;
|
||||
$vartype[$v] = $type;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string with only ASCII characters in it
|
||||
*
|
||||
* This function was sourced from the php website, help on str_replace
|
||||
* No author was listed at the time of access
|
||||
*
|
||||
* @param string $stringIn The string
|
||||
* @return string A string containing only ASCII characters
|
||||
*/
|
||||
function all_ascii( $stringIn ){
|
||||
$final = '';
|
||||
$search = array(chr(145),chr(146),chr(147),chr(148),chr(150),chr(151),chr(13),chr(10));
|
||||
$replace = array("'","'",'"','"','-','-',' ',' ');
|
||||
|
||||
$hold = str_replace($search[0],$replace[0],$stringIn);
|
||||
$hold = str_replace($search[1],$replace[1],$hold);
|
||||
$hold = str_replace($search[2],$replace[2],$hold);
|
||||
$hold = str_replace($search[3],$replace[3],$hold);
|
||||
$hold = str_replace($search[4],$replace[4],$hold);
|
||||
$hold = str_replace($search[5],$replace[5],$hold);
|
||||
$hold = str_replace($search[6],$replace[6],$hold);
|
||||
$hold = str_replace($search[7],$replace[7],$hold);
|
||||
|
||||
if(!function_exists('str_split')){
|
||||
function str_split($string,$split_length=1){
|
||||
$count = strlen($string);
|
||||
if($split_length < 1){
|
||||
return false;
|
||||
} elseif($split_length > $count){
|
||||
return array($string);
|
||||
} else {
|
||||
$num = (int)ceil($count/$split_length);
|
||||
$ret = array();
|
||||
for($i=0;$i<$num;$i++){
|
||||
$ret[] = substr($string,$i*$split_length,$split_length);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$holdarr = str_split($hold);
|
||||
foreach ($holdarr as $val) {
|
||||
if (ord($val) < 128) $final .= $val;
|
||||
}
|
||||
return $final;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Produce a fixed width string containing the data from a questionnaire
|
||||
*
|
||||
* @param int $questionnaire_id The quesitonnaire id
|
||||
* @param int|false $sample_import_id The sample importid or false for all data
|
||||
* @return string Fixed width data from the limesurvey database
|
||||
*
|
||||
*/
|
||||
function limesurvey_export_fixed_width($questionnaire_id,$sample_import_id = false)
|
||||
{
|
||||
global $ldb;
|
||||
global $db;
|
||||
|
||||
//array of varname and width
|
||||
$varwidth = array();
|
||||
$vartype = array();
|
||||
|
||||
$sql = "SELECT lime_sid
|
||||
FROM questionnaire
|
||||
WHERE questionnaire_id = '$questionnaire_id'";
|
||||
|
||||
$r = $db->GetRow($sql);
|
||||
|
||||
if (!empty($r))
|
||||
$surveyid = $r['lime_sid'];
|
||||
else
|
||||
return;
|
||||
|
||||
//foreach question
|
||||
$sql = "SELECT *
|
||||
FROM ".LIME_PREFIX."questions
|
||||
WHERE sid=$surveyid
|
||||
AND type NOT LIKE 'X'
|
||||
ORDER BY gid,question_order ASC";
|
||||
|
||||
$r = $ldb->GetAll($sql);
|
||||
foreach ($r as $RowQ)
|
||||
{
|
||||
$type = $RowQ['type'];
|
||||
$qid = $RowQ['qid'];
|
||||
$lid = $RowQ['lid'];
|
||||
$gid = $RowQ['gid'];
|
||||
|
||||
$varName = $surveyid . "X" . $gid . "X" . $qid;
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case "X": //BOILERPLATE QUESTION - none should appear
|
||||
|
||||
break;
|
||||
case "5": //5 POINT CHOICE radio-buttons
|
||||
$varwidth[$varName]=1;
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "D": //DATE
|
||||
$varwidth[$varName]=8;
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "Z": //LIST Flexible drop-down/radio-button list
|
||||
$varwidth[$varName]=limesurvey_fixed_width($lid);
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "L": //LIST drop-down/radio-button list
|
||||
$varwidth[$varName]=limesurvey_fixed_width($lid);
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "W": //List - dropdown
|
||||
$varwidth[$varName]=limesurvey_fixed_width($lid);
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "!": //List - dropdown
|
||||
$varwidth[$varName]=limesurvey_fixed_width($lid);
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "O": //LIST WITH COMMENT drop-down/radio-button list + textarea
|
||||
//Not yet implemented
|
||||
break;
|
||||
case "R": //RANKING STYLE
|
||||
//Not yet implemented
|
||||
break;
|
||||
case "M": //MULTIPLE OPTIONS checkbox
|
||||
limesurvey_create_multi($varwidth,$vartype,$qid,$varName,1,3);
|
||||
break;
|
||||
case "P": //MULTIPLE OPTIONS WITH COMMENTS checkbox + text
|
||||
//Not yet implemented
|
||||
break;
|
||||
case "Q": //MULTIPLE SHORT TEXT
|
||||
limesurvey_create_multi($varwidth,$vartype,$qid,$varName,limesurvey_get_width($qid,24),2);
|
||||
break;
|
||||
case "K": //MULTIPLE NUMERICAL
|
||||
limesurvey_create_multi($varwidth,$vartype,$qid,$varName,limesurvey_get_width($qid,10),1);
|
||||
break;
|
||||
case "N": //NUMERICAL QUESTION TYPE
|
||||
$varwidth[$varName]= limesurvey_get_width($qid,10);
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "S": //SHORT FREE TEXT
|
||||
$varwidth[$varName]= limesurvey_get_width($qid,240);
|
||||
$vartype[$varName] = 2;
|
||||
break;
|
||||
case "T": //LONG FREE TEXT
|
||||
$varwidth[$varName]= limesurvey_get_width($qid,1024);
|
||||
$vartype[$varName] = 2;
|
||||
break;
|
||||
case "U": //HUGE FREE TEXT
|
||||
$varwidth[$varName]= limesurvey_get_width($qid,2048);
|
||||
$vartype[$varName] = 2;
|
||||
break;
|
||||
case "Y": //YES/NO radio-buttons
|
||||
$varwidth[$varName]=1;
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "G": //GENDER drop-down list
|
||||
$varwidth[$varName]=1;
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "A": //ARRAY (5 POINT CHOICE) radio-buttons
|
||||
$varwidth[$varName]=1;
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "B": //ARRAY (10 POINT CHOICE) radio-buttons
|
||||
$varwidth[$varName]=2;
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "C": //ARRAY (YES/UNCERTAIN/NO) radio-buttons
|
||||
$varwidth[$varName]=1;
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "E": //ARRAY (Increase/Same/Decrease) radio-buttons
|
||||
$varwidth[$varName]=1;
|
||||
$vartype[$varName] = 1;
|
||||
break;
|
||||
case "F": //ARRAY (Flexible) - Row Format
|
||||
limesurvey_create_multi($varwidth,$vartype,$qid,$varName,limesurvey_fixed_width($lid),1);
|
||||
break;
|
||||
case "H": //ARRAY (Flexible) - Column Format
|
||||
limesurvey_create_multi($varwidth,$vartype,$qid,$varName,limesurvey_fixed_width($lid),1);
|
||||
break;
|
||||
case "^": //SLIDER CONTROL
|
||||
//Not yet implemented
|
||||
break;
|
||||
} //End Switch
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$fn = "survey_$surveyid.dat";
|
||||
|
||||
header("Content-Type: application/download");
|
||||
header("Content-Disposition: attachment; filename=$fn");
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
|
||||
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
||||
Header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
||||
header("Pragma: no-cache"); // HTTP/1.0
|
||||
|
||||
$sql3 = "SELECT c.case_id as case_id
|
||||
FROM `case` as c
|
||||
WHERE c.questionnaire_id = '$questionnaire_id'";
|
||||
|
||||
$r = $db->GetAll($sql3);
|
||||
|
||||
if (!empty($r))
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM ".LIME_PREFIX."survey_$surveyid
|
||||
WHERE submitdate IS NOT NULL";
|
||||
|
||||
|
||||
if ($sample_import_id == false)
|
||||
{
|
||||
$sql .= " AND (";
|
||||
foreach($r as $row)
|
||||
{
|
||||
$token = $row['case_id'];
|
||||
$sql .= " token = '$token'";
|
||||
if (next($r)) $sql .= " or ";
|
||||
}
|
||||
$sql .= ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql2 = "SELECT c.case_id as case_id
|
||||
FROM `case` as c, `sample` as s
|
||||
WHERE c.questionnaire_id = '$questionnaire_id'
|
||||
AND c.sample_id = s.sample_id
|
||||
AND s.import_id = '$sample_import_id'";
|
||||
|
||||
$r = $db->GetAll($sql2);
|
||||
|
||||
if (!empty($r))
|
||||
{
|
||||
$sql .= " AND (";
|
||||
foreach($r as $row)
|
||||
{
|
||||
$token = $row['case_id'];
|
||||
$sql .= " token = '$token'";
|
||||
if (next($r)) $sql .= " or ";
|
||||
}
|
||||
$sql .= ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$r = $ldb->GetAll($sql);
|
||||
|
||||
foreach($r as $Row)
|
||||
{
|
||||
foreach ($varwidth as $var => $width)
|
||||
{
|
||||
if ($vartype[$var] == 1)
|
||||
echo str_pad(substr(all_ascii($Row[$var]),0,$width), $width, " ", STR_PAD_LEFT);
|
||||
else if ($vartype[$var] == 2)
|
||||
echo str_pad(substr(all_ascii($Row[$var]),0,$width), $width, " ", STR_PAD_RIGHT);
|
||||
else if ($vartype[$var] == 3)
|
||||
if (empty($Row[$var])) echo " "; else echo "1";
|
||||
}
|
||||
echo str_pad(substr($Row['token'],0,9), 9, " ", STR_PAD_LEFT);
|
||||
echo str_pad(substr($Row['datestamp'],0,16), 16, " ", STR_PAD_LEFT);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
1347
functions/functions.operator.php
Normal file
1347
functions/functions.operator.php
Normal file
File diff suppressed because it is too large
Load Diff
445
functions/functions.performance.php
Normal file
445
functions/functions.performance.php
Normal file
@@ -0,0 +1,445 @@
|
||||
<?
|
||||
/**
|
||||
* Functions that display data about the project
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configuration file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../config.inc.php');
|
||||
|
||||
/**
|
||||
* Database file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../db.inc.php');
|
||||
|
||||
|
||||
/**
|
||||
* Get completions per hour by shift with interviewer id and first name
|
||||
*
|
||||
* @param int $qid The questionnaire ID
|
||||
* @param int $sid The shift ID
|
||||
* @return array An array containing operator_id,firstName,CPH
|
||||
*/
|
||||
function get_CPH_by_shift($qid,$sid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,ca.time, c.completions/ca.time as CPH
|
||||
FROM operator as o
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a, `case` as b, `shift` as s
|
||||
WHERE a.outcome_id = '10'
|
||||
AND a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$qid'
|
||||
AND s.shift_id = '$sid'
|
||||
AND s.`start` <= a.`start`
|
||||
AND s.`end` >= a.`start`
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , a.start, IFNULL(a.end,CONVERT_TZ(NOW(),'System','UTC')))) /3600 as time, a.operator_id
|
||||
FROM `call_attempt` as a, `case` as b, `shift` as s
|
||||
WHERE a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$qid'
|
||||
AND s.shift_id = '$sid'
|
||||
AND s.`start` <= a.`start`
|
||||
AND s.`end` >= a.`start`
|
||||
GROUP BY operator_id) as ca on (ca.operator_id = o.operator_id)
|
||||
ORDER BY cph DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get completions per hour by questionnaire with interviewer id and first name
|
||||
*
|
||||
* @param int $qid The questionnaire ID
|
||||
* @return array An array containing operator_id,firstName,CPH
|
||||
*/
|
||||
function get_CPH_by_questionnaire($qid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,ca.time, c.completions/ca.time as CPH
|
||||
FROM operator as o
|
||||
JOIN ( SELECT count(*) as completions,a.operator_id
|
||||
FROM `call` as a, `case` as b
|
||||
WHERE a.outcome_id = '10'
|
||||
AND a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$qid'
|
||||
GROUP BY a.operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , a.start, IFNULL(a.end,CONVERT_TZ(NOW(),'System','UTC')))) /3600 as time, a.operator_id
|
||||
FROM `call_attempt` as a, `case` as b
|
||||
WHERE a.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$qid'
|
||||
GROUP BY operator_id) as ca on (ca.operator_id = o.operator_id)
|
||||
ORDER BY cph DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get completions per hour overall with interviewer id and first name
|
||||
*
|
||||
* @param int $qid The questionnaire ID
|
||||
* @return array An array containing operator_id,firstName,CPH
|
||||
*/
|
||||
function get_CPH()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.firstName,o.operator_id,c.completions,ca.time, c.completions/ca.time as CPH
|
||||
FROM operator as o
|
||||
JOIN ( SELECT count(*) as completions,operator_id
|
||||
FROM `call`
|
||||
WHERE outcome_id = '10'
|
||||
GROUP BY operator_id) as c on (c.operator_id = o.operator_id)
|
||||
JOIN ( SELECT SUM( TIMESTAMPDIFF(SECOND , start, IFNULL(end,CONVERT_TZ(NOW(),'System','UTC')))) /3600 as time, operator_id
|
||||
FROM `call_attempt`
|
||||
GROUP BY operator_id) as ca on (ca.operator_id = o.operator_id)
|
||||
ORDER BY cph DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get effectiveness by questionnaire with interviewer id and first name
|
||||
*
|
||||
* @param int $qid The questionnaire ID
|
||||
* @return array An array containing operator_id,firstName,effectiveness
|
||||
*/
|
||||
function get_effectiveness_by_questionnaire($questionnaire_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.operator_id, o.firstName, (calltime.totaltime / callattempttime.totaltime) AS effectiveness
|
||||
FROM operator AS o
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call` AS c, `case` as b
|
||||
WHERE c.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY operator_id
|
||||
) AS calltime ON ( calltime.operator_id = o.operator_id )
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call_attempt` AS c, `case` as b
|
||||
WHERE c.case_id = b.case_id
|
||||
AND b.questionnaire_id = '$questionnaire_id'
|
||||
GROUP BY operator_id
|
||||
) AS callattempttime ON ( callattempttime.operator_id = o.operator_id )
|
||||
ORDER BY effectiveness DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get effectiveness overall with interviewer id and first name
|
||||
*
|
||||
* @return array An array containing operator_id,firstName,effectiveness
|
||||
*/
|
||||
function get_effectiveness()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.operator_id, o.firstName, (calltime.totaltime / callattempttime.totaltime) AS effectiveness
|
||||
FROM operator AS o
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call` AS c
|
||||
GROUP BY operator_id
|
||||
) AS calltime ON ( calltime.operator_id = o.operator_id )
|
||||
JOIN (
|
||||
SELECT SUM( TIMESTAMPDIFF(
|
||||
SECOND , c.start, IFNULL( c.end, CONVERT_TZ( NOW( ) , 'System', 'UTC' ) ) ) ) AS totaltime, operator_id
|
||||
FROM `call_attempt` AS c
|
||||
GROUP BY operator_id
|
||||
) AS callattempttime ON ( callattempttime.operator_id = o.operator_id )
|
||||
ORDER BY effectiveness DESC";
|
||||
|
||||
return $db->GetAll($sql);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the average time on a call with an outcome
|
||||
* in seconds by questionnaire
|
||||
*
|
||||
* @param int $outcome_id The outcome id
|
||||
* @param int $questionnaire_id The questionnaire id
|
||||
* @return int Seconds average of calls with this outcome
|
||||
*/
|
||||
function get_average_time_questionnaire($outcome_id,$questionnaire_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT AVG(TIMESTAMPDIFF(SECOND,c.start,c.end)) as average
|
||||
FROM `call` as c, `case` as q
|
||||
WHERE c.outcome_id = '$outcome_id'
|
||||
AND q.case_id = c.case_id
|
||||
AND q.questionnaire_id = '$questionnaire_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
if (!empty($rs))
|
||||
return $rs['average'];
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the average time on a call with an outcome
|
||||
* in seconds
|
||||
*
|
||||
* @param int $outcome_id The outcome id
|
||||
* @return int Seconds average of calls with this outcome
|
||||
*/
|
||||
function get_average_time($outcome_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT AVG(TIMESTAMPDIFF(SECOND,c.start,c.end)) as average
|
||||
FROM `call` as c
|
||||
WHERE c.outcome_id = '$outcome_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
if (!empty($rs))
|
||||
return $rs['average'];
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* If not on a shift, display a message
|
||||
*/
|
||||
function display_none()
|
||||
{
|
||||
print "<h1>" . T_("No shift") . "</h1>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the total number of completions for this project
|
||||
*
|
||||
* @param int $qid The questionnaire id
|
||||
*
|
||||
*/
|
||||
function display_total_completions($qid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT count(case_id) as c
|
||||
FROM `case`
|
||||
WHERE current_outcome_id = 10
|
||||
AND questionnaire_id = '$qid'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
$c = 0;
|
||||
if (!empty($rs)) $c = $rs['c'];
|
||||
|
||||
print "<h3>" . T_("Total completions") . "</h3><h2>$c</h2>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the total number of completions for this shift
|
||||
*
|
||||
* @param int $qid The questionnaire id
|
||||
* @param int $sid The shift id
|
||||
*
|
||||
*/
|
||||
function display_completions_this_shift($qid,$sid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT count(ca.call_id) as c
|
||||
FROM `call` as ca, `case` as cs, `shift` as s
|
||||
WHERE ca.outcome_id = 10
|
||||
AND ca.case_id = cs.case_id
|
||||
AND cs.questionnaire_id = '$qid'
|
||||
AND s.questionnaire_id = '$qid'
|
||||
AND s.shift_id = '$sid'
|
||||
AND ca.start >= s.start
|
||||
AND ca.start <= s.end";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
$c = 0;
|
||||
if (!empty($rs)) $c = $rs['c'];
|
||||
|
||||
print "<h3>" . T_("Completions this shift") . "</h3><h2>$c</h2>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the total number of completions for the last shift
|
||||
*
|
||||
* @param int $qid The questionnaire id
|
||||
* @param int $sid The current shift id
|
||||
*
|
||||
*/
|
||||
function display_completions_last_shift($qid,$sid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT shift_id
|
||||
FROM shift
|
||||
WHERE questionnaire_id = '$qid'
|
||||
AND shift_id < '$sid'
|
||||
ORDER BY shift_id DESC
|
||||
LIMIT 1";
|
||||
|
||||
$ps = $db->GetRow($sql);
|
||||
if (empty($ps))
|
||||
print "<h3>" . T_("No previous shift") . "</h3>";
|
||||
else
|
||||
{
|
||||
$psid = $ps['shift_id'];
|
||||
|
||||
$sql = "SELECT count(ca.call_id) as c
|
||||
FROM `call` as ca, `case` as cs, `shift` as s
|
||||
WHERE ca.outcome_id = 10
|
||||
AND ca.case_id = cs.case_id
|
||||
AND cs.questionnaire_id = '$qid'
|
||||
AND s.questionnaire_id = '$qid'
|
||||
AND s.shift_id = '$psid'
|
||||
AND ca.start >= s.start
|
||||
AND ca.start <= s.end";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
$c = 0;
|
||||
if (!empty($rs)) $c = $rs['c'];
|
||||
|
||||
print "<h3>" . T_("Completions on the previous shift") . "</h3><h2>$c</h2>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display the total number of completions for the last shift
|
||||
* at the same number of seconds in to the last shift
|
||||
*
|
||||
* @param int $qid The questionnaire id
|
||||
* @param int $sid The current shift id
|
||||
*
|
||||
*/
|
||||
function display_completions_same_time_last_shift($qid,$sid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT shift_id
|
||||
FROM shift
|
||||
WHERE questionnaire_id = '$qid'
|
||||
AND shift_id < '$sid'
|
||||
ORDER BY shift_id DESC
|
||||
LIMIT 1";
|
||||
|
||||
$ps = $db->GetRow($sql);
|
||||
if (empty($ps))
|
||||
print "<h3>" . T_("No previous shift") . "</h3>";
|
||||
else
|
||||
{
|
||||
$psid = $ps['shift_id'];
|
||||
|
||||
$sql = "SELECT count(ca.call_id) as c
|
||||
FROM `call` as ca, `case` as cs, `shift` as s
|
||||
JOIN `shift` as s2 on (s2.shift_id = '$sid')
|
||||
WHERE ca.outcome_id = 10
|
||||
AND ca.case_id = cs.case_id
|
||||
AND cs.questionnaire_id = '$qid'
|
||||
AND s.questionnaire_id = '$qid'
|
||||
AND s.shift_id = '$psid'
|
||||
AND ca.start >= s.start
|
||||
AND ca.start <= DATE_SUB(s.end, INTERVAL TIMESTAMPDIFF(SECOND , CONVERT_TZ(NOW(),'System','UTC'), s2.end) SECOND)";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
$c = 0;
|
||||
if (!empty($rs)) $c = $rs['c'];
|
||||
|
||||
print "<h3>" . T_("Completions this time on the previous shift") . "</h3><h2>$c</h2>";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the interviewer with the top CPH for this shift
|
||||
*
|
||||
* @param int $qid The questionnaire id
|
||||
* @param int $sid The current shift id
|
||||
*
|
||||
*/
|
||||
function display_top_cph_this_shift($qid,$sid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$rs = get_CPH_by_shift($qid,$sid);
|
||||
|
||||
if (empty($rs))
|
||||
print "<h3>" . T_("No calls made for this shift") . "</h3>";
|
||||
else
|
||||
print "<h3>" . T_("Top CPH for this shift") . "</h3><h2>{$rs[0]['firstName']} - ". round($rs[0]['CPH'],2) ."</h2>";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the interviewer with the top CPH overall
|
||||
*
|
||||
* @param int $qid The questionnaire id
|
||||
*
|
||||
*/
|
||||
function display_top_cph($qid)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$rs = get_CPH_by_questionnaire($qid);
|
||||
|
||||
if (empty($rs))
|
||||
print "<h3>" . T_("No calls made for this project") . "</h3>";
|
||||
else
|
||||
print "<h3>" . T_("Top CPH") . "</h3><h2>{$rs[0]['firstName']} - ". round($rs[0]['CPH'],2) ."</h2>";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
38
functions/functions.template.php
Normal file
38
functions/functions.template.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?
|
||||
/**
|
||||
* Template of functions
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configuration file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../config.inc.php');
|
||||
|
||||
|
||||
?>
|
||||
492
functions/functions.voip.php
Normal file
492
functions/functions.voip.php
Normal file
@@ -0,0 +1,492 @@
|
||||
<?
|
||||
/**
|
||||
* Functions to interact with Asterisk
|
||||
* Some examples taken from {@link http://www.voip-info.org/wiki/index.php?page=Asterisk+manager+Example%3A+PHP voip-info.org}
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Configuration file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../config.inc.php');
|
||||
|
||||
/**
|
||||
* Class to interact with Asterisk
|
||||
*
|
||||
* @package queXS
|
||||
*/
|
||||
class voip {
|
||||
/**
|
||||
* Socket connection to Asterisk server
|
||||
*/
|
||||
var $socket;
|
||||
|
||||
/**
|
||||
* Close the socket gracefully on destruct
|
||||
*/
|
||||
function __destruct() {
|
||||
//close the socket
|
||||
fclose($this->socket);
|
||||
$this->socket = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a list of active extensions and their corresponding
|
||||
* channels as an associative array
|
||||
*
|
||||
* @return array Key is extension, value is Asterisk channel
|
||||
*
|
||||
*/
|
||||
function getChannels()
|
||||
{
|
||||
$ret = $this->query("Action: Status\r\n\r\n","StatusComplete");
|
||||
|
||||
$c = spliti("\r\n\r\n",$ret);
|
||||
$chans = array();
|
||||
foreach ($c as $s)
|
||||
{
|
||||
if(eregi("Event: Status.*Channel: SIP/([0-9a-zA-Z-]+).*Link: ([/0-9a-zA-Z-]+)",$s,$regs))
|
||||
{
|
||||
//print T_("Channel: SIP/") . $regs[1] . " Link " . $regs[2] . "\n";
|
||||
$chan = substr($regs[1],0,4);
|
||||
$chans[$chan] = array("SIP/" . $regs[1],$regs[2]);
|
||||
}
|
||||
else if(eregi("Event: Status.*Channel: SIP/([0-9a-zA-Z-]+).*",$s,$regs))
|
||||
{
|
||||
//print T_("Channel: ") . $regs[1] . "\n";
|
||||
$chan = substr($regs[1],0,4);
|
||||
$chans[$chan] = array("SIP/".$regs[1],false);
|
||||
}
|
||||
}
|
||||
return $chans;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the channel (if active) given the extension
|
||||
* Return false if no channel found
|
||||
*
|
||||
* @param string $ext Extension as in Asterisk
|
||||
* @return string|bool The Asterisk channel or false if no channel exists
|
||||
*
|
||||
*/
|
||||
function getChannel($ext,$link = false)
|
||||
{
|
||||
$v = $this->getChannels();
|
||||
if (isset($v[$ext]))
|
||||
{
|
||||
if ($link)
|
||||
return $v[$ext][1];
|
||||
else
|
||||
return $v[$ext][0];
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add another party to an active call (eg add in the supervisor)
|
||||
*
|
||||
* @param int $ext The extension of the current call
|
||||
* @param int $number The phone number to add to the call
|
||||
* @todo CHECK IF THE MEETING ROOM IS EMPTY before adding use meetme list
|
||||
*
|
||||
*/
|
||||
function addParty($ext,$number)
|
||||
{
|
||||
if($ext)
|
||||
{
|
||||
$channel = $this->getChannel($ext);
|
||||
$link = $this->getChannel($ext,true);
|
||||
|
||||
|
||||
//check if the meeting room is empty
|
||||
|
||||
//if so:
|
||||
// 1. call the supervisor to the room
|
||||
$q = "Action: Originate\r\nChannel: Local/$number@from-internal\r\nPriority: 1\r\nContext: default\r\nApplication: MeetMe\r\nData: " . MEET_ME_ROOM . "|d\r\n\r\n";
|
||||
$r = $this->query($q,"Meetme");
|
||||
|
||||
|
||||
// 2. transfer the current call to the room
|
||||
$r = $this->query("Action: Redirect\r\nChannel: $channel\r\nExtraChannel: $link\r\nExten: " . MEET_ME_ROOM . "\r\nPriority: 1\r\nContext: from-internal-xfer\r\n\r\n","Response");
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Dial call from the call database
|
||||
*
|
||||
* @param string $ext The extension to originate the call from
|
||||
* @param string $number The number to dial
|
||||
*
|
||||
*/
|
||||
function dial($ext,$number)
|
||||
{
|
||||
$r = $this->query("Action: Originate\r\nChannel: SIP/$ext\r\nExten: $number\r\nPriority: 1\r\nCallerid: $ext\r\n\r\n","Response");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hang up the current call by the extension
|
||||
*
|
||||
* @param int $ext The extension to hang up for
|
||||
*
|
||||
*/
|
||||
function hangup($ext)
|
||||
{
|
||||
if($ext)
|
||||
{
|
||||
$channel = $this->getChannel($ext);
|
||||
$r = $this->query("Action: Hangup\r\nChannel: $channel\r\n\r\n","Response");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin recording the call to a file
|
||||
*
|
||||
* @param string $ext The Asterisk extension
|
||||
* @param bool|string $filename False for an auto generated file name else specify file name
|
||||
* @todo Handle multiple recordings
|
||||
*
|
||||
*/
|
||||
function beginRecord($ext,$filename = false)
|
||||
{
|
||||
|
||||
if($ext)
|
||||
{
|
||||
$channel = $this->getChannel($ext);
|
||||
$r = $this->query("Action: Monitor\r\nChannel: $channel\r\nFile: $filename\r\nFormat: gsm\r\nMix: 1\r\n\r\n","Response");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* End the recording on this extension
|
||||
*
|
||||
* @param string $ext The Asterisk extension
|
||||
* @todo Handle multiple recordings
|
||||
* @see beginRecord()
|
||||
*
|
||||
*/
|
||||
function endRecord($ext)
|
||||
{
|
||||
|
||||
if($ext)
|
||||
{
|
||||
$channel = $this->getChannel($ext);
|
||||
$r = $this->query("Action: StopMonitor\r\nChannel: $channel\r\n\r\n","Response");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the status of an extension
|
||||
*
|
||||
* @param int $ext The extension
|
||||
* @return bool|int false if not available, 1 for available, 2 for available and on a call
|
||||
*
|
||||
*/
|
||||
function getExtensionStatus($ext)
|
||||
{
|
||||
if($ext)
|
||||
{
|
||||
$ret = $this->query("Action: ExtensionState\r\nContext: default\r\nExten: $ext\r\nActionID: 1\r\n\r\n","Status:");
|
||||
if(eregi("Status: ([0-9]+)",$ret,$regs))
|
||||
{
|
||||
if (isset($regs[1]))
|
||||
{
|
||||
// 0 appears to be online, 1 online and on a call
|
||||
if ($regs[1] == 0)
|
||||
return 1;
|
||||
else if ($regs[1] == 1 || $regs[1] == 8)
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether we are connected to the Asterisk server or not
|
||||
*
|
||||
* @return True if connected else false
|
||||
*
|
||||
*/
|
||||
function isConnected()
|
||||
{
|
||||
if ($this->socket)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the Asterisk server
|
||||
*
|
||||
* @param string $ip The IP Address
|
||||
* @param string $user Username for Asterisk manager
|
||||
* @param string $pass Password for Asterisk manager
|
||||
* @param bool $events If events should be enabled or not (default false)
|
||||
*
|
||||
* @return bool True if connected successfully, else false
|
||||
*/
|
||||
function connect($ip,$user="admin",$pass="amp111",$events = false)
|
||||
{
|
||||
$this->socket = fsockopen($ip,"5038",$errno,$errstr,1);
|
||||
if (!$this->socket)
|
||||
{
|
||||
print "$errno: $errstr";
|
||||
exit();
|
||||
return false;
|
||||
}
|
||||
|
||||
stream_set_timeout($this->socket, 1);
|
||||
|
||||
$q = "Action: Login\r\nUsername: $user\r\nSecret: $pass\r\nEvents: ";
|
||||
|
||||
if ($events)
|
||||
$q .= "on";
|
||||
else
|
||||
$q .= "off";
|
||||
|
||||
$q .= "\r\n\r\n";
|
||||
|
||||
$r = $this->query($q,"accepted");
|
||||
|
||||
if (strpos($r,"Response: Success"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose($this->socket);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the Asterisk server and wait for a response or timeout
|
||||
*
|
||||
* @param string $query The string to send to the Asterisk manager, see {@link http://www.voip-info.org/wiki/view/Asterisk+manager+API API} for details
|
||||
* @param string $waitfor A string within the return string to wait for before returning
|
||||
* @return string The response string from Asterisk
|
||||
*
|
||||
*/
|
||||
function query($query,$waitfor=false)
|
||||
{
|
||||
$wrets = "";
|
||||
|
||||
if ($this->socket === false)
|
||||
return false;
|
||||
|
||||
fputs($this->socket, $query);
|
||||
|
||||
$c = 1;
|
||||
do
|
||||
{
|
||||
$line = fgets($this->socket, 4096);
|
||||
$wrets .= $line;
|
||||
$info = stream_get_meta_data($this->socket);
|
||||
} while ($line != "\n" && !$info['timed_out'] && (strpos($line,$waitfor) === false));
|
||||
|
||||
return $wrets;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Class used to watch Asterisk events and effect changes to queXS database
|
||||
*
|
||||
* @package queXS
|
||||
* @todo automatically code a call if we know it is busy
|
||||
*/
|
||||
class voipWatch extends voip {
|
||||
|
||||
|
||||
var $keepWatching = true;
|
||||
|
||||
/**
|
||||
* Watch for Asterisk events and make changes to the queXS databse if
|
||||
* appropriate
|
||||
*
|
||||
*
|
||||
*/
|
||||
function watch()
|
||||
{
|
||||
/**
|
||||
* Database file
|
||||
*/
|
||||
include_once(dirname(__FILE__).'/../db.inc.php');
|
||||
|
||||
$line = "";
|
||||
|
||||
if ($this->socket === false)
|
||||
return false;
|
||||
|
||||
/**
|
||||
* Array key: Asterisk unique ID, value: queXS call id
|
||||
*/
|
||||
$e = array();
|
||||
|
||||
/**
|
||||
* Array key: Asterisk unique ID, value: Asterisk sequence number
|
||||
*/
|
||||
$f = array();
|
||||
|
||||
do
|
||||
{
|
||||
//keep reconnecting to the db so it doesn't time out
|
||||
$db = newADOConnection(DB_TYPE);
|
||||
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||
|
||||
$in = fgets($this->socket, 4096);
|
||||
|
||||
//print "IN: $in\n";
|
||||
|
||||
/**
|
||||
* When we have reached the end of a message, process it
|
||||
*
|
||||
*/
|
||||
if ($in == "\r\n")
|
||||
{
|
||||
//print "PROCESS: ";
|
||||
/**
|
||||
* New channel, assign Asterisk unique id to queXF call id
|
||||
*/
|
||||
if(eregi("Event: Newchannel.*Channel: SIP/([0-9]+).*Uniqueid: ([0-9]+)\.([0-9]+)",$line,$regs))
|
||||
{
|
||||
print T_("Extension: ") . $regs[1] . T_(" UniqueID ") . $regs[2] . T_(" Sequence ") . $regs[3] . "\n";
|
||||
$sql = "SELECT l.call_id
|
||||
FROM operator AS o
|
||||
JOIN (`case` AS c, `call_attempt` AS ca, `call` AS l) ON
|
||||
( c.current_operator_id = o.operator_id
|
||||
AND c.case_id = ca.case_id
|
||||
AND ca.operator_id = o.operator_id
|
||||
AND ca.end IS NULL
|
||||
AND l.call_attempt_id = ca.call_attempt_id
|
||||
AND l.outcome_id =0 )
|
||||
WHERE o.extension = '{$regs[1]}'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
if (!empty($rs))
|
||||
{
|
||||
$e[$regs[2]] = $rs['call_id']; //set call id
|
||||
$f[$regs[2]] = $regs[3]; //set sequence
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The call is ringing
|
||||
*/
|
||||
else if (eregi("Event: Dial.*SrcUniqueid: ([0-9]+)",$line,$regs))
|
||||
{
|
||||
print T_("Ringing") . T_(" UniqueID ") . $regs[1] . "\n";
|
||||
if (isset($e[$regs[1]])) //if we know the call of this unique id
|
||||
{
|
||||
$call_id = $e[$regs[1]];
|
||||
$sql = "UPDATE `call`
|
||||
SET state = 2
|
||||
WHERE call_id = '$call_id'";
|
||||
$db->Execute($sql);
|
||||
//print $sql;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The call has been answered
|
||||
*/
|
||||
else if (eregi("Event: Link.*Uniqueid1: ([0-9]+)",$line,$regs))
|
||||
{
|
||||
print T_("Answered") . T_(" UniqueID ") . $regs[1] . "\n";
|
||||
if (isset($e[$regs[1]])) //if we know the call of this unique id
|
||||
{
|
||||
$call_id = $e[$regs[1]];
|
||||
$sql = "UPDATE `call`
|
||||
SET state = 3
|
||||
WHERE call_id = '$call_id'";
|
||||
$db->Execute($sql);
|
||||
// print $sql;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The call has been hung up
|
||||
*/
|
||||
else if (eregi("Event: Hangup.*Uniqueid: ([0-9]+)\.([0-9]+)",$line,$regs))
|
||||
{
|
||||
print T_("Hangup") . T_(" UniqueID ") . $regs[1] . "\n";
|
||||
// print_r($e);
|
||||
if (isset($e[$regs[1]]) && $f[$regs[1]] == $regs[2]) //if we know the call and it is the same line hangingup
|
||||
{
|
||||
$call_id = $e[$regs[1]];
|
||||
$sql = "UPDATE `call`
|
||||
SET state = 4
|
||||
WHERE call_id = '$call_id'
|
||||
AND outcome_id = '0'";
|
||||
$db->Execute($sql); //don't update if already coded outcome
|
||||
|
||||
// print $sql;
|
||||
|
||||
//unset the variables
|
||||
unset($e[$regs[1]]);
|
||||
unset($f[$regs[1]]);
|
||||
}
|
||||
}
|
||||
|
||||
//print $line . "\n\n";
|
||||
$line = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* Append the lines to the message if we are not yet at the end of one
|
||||
*/
|
||||
$line .= $in;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@flush();
|
||||
|
||||
} while ($this->keepWatching);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
170
functions/functions.xhtml.php
Normal file
170
functions/functions.xhtml.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?
|
||||
/**
|
||||
* Functions related to XHTML code generation
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Display a valid XHTML Strict header
|
||||
*
|
||||
* @param string $title HTML title
|
||||
* @param bool $body True if to display the end of the head/body
|
||||
* @param bool|array $css False for no CSS otherwise array of CSS include files
|
||||
* @param bool|array $javascript False for no Javascript otherwise array of Javascript include files
|
||||
* @param string $bodytext Space in the body element: good for onload='top.close()' to close validly
|
||||
* @param bool|int $refresh False or 0 for no refresh otherwise the number of seconds to refresh
|
||||
*
|
||||
* @see xhtml_foot()
|
||||
*/
|
||||
function xhtml_head($title="",$body=true,$css=false,$javascript=false,$bodytext=false,$refresh=false)
|
||||
{
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
||||
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head><title><? if (empty($title)) print "queXS"; else print "queXS: $title"; ?></title>
|
||||
<?
|
||||
if ($css)
|
||||
foreach ($css as $c) print "<link rel='stylesheet' href='$c' type='text/css'></link>";
|
||||
if ($javascript)
|
||||
foreach ($javascript as $j) print "<script type='text/javascript' src='$j'></script>";
|
||||
if ($refresh)
|
||||
print " <!--Set to refresh every $refresh seconds-->
|
||||
<meta http-equiv='Cache-Control' content='no-cache'/>
|
||||
<meta http-equiv='refresh' content='$refresh'/>";
|
||||
if (!$body) return;
|
||||
?>
|
||||
</head>
|
||||
<?
|
||||
if ($bodytext) print "<body $bodytext>"; else print "<body>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a valid XHTML Strict footer
|
||||
*
|
||||
* @see xhtml_head()
|
||||
*/
|
||||
|
||||
function xhtml_foot()
|
||||
{
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a valid XHTML Strict table
|
||||
*
|
||||
* @param array $content Content from database usually an array of arrays
|
||||
* @param array $fields The names of fields to display
|
||||
* @param bool|array $head False if no header otherwise array of header titles
|
||||
* @param string $class Table CSS class
|
||||
* @param bool|array $highlight False if nothing to highlight else an array containing the field to highlight
|
||||
*
|
||||
*/
|
||||
function xhtml_table($content,$fields,$head = false,$class = "tclass",$highlight=false)
|
||||
{
|
||||
print "<table class='$class'>";
|
||||
if ($head)
|
||||
{
|
||||
print "<tr>";
|
||||
foreach ($head as $e)
|
||||
print"<th>$e</th>";
|
||||
print "</tr>";
|
||||
}
|
||||
foreach($content as $row)
|
||||
{
|
||||
if ($highlight && isset($row[key($highlight)]) && $row[key($highlight)] == current($highlight))
|
||||
print "<tr class='highlight'>";
|
||||
else
|
||||
print "<tr>";
|
||||
|
||||
foreach ($fields as $e)
|
||||
print "<td>{$row[$e]}</td>";
|
||||
|
||||
print "</tr>";
|
||||
}
|
||||
print "</table>";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a drop down list based on a given array
|
||||
*
|
||||
* Example SQL:
|
||||
* SELECT questionnaire_id as value,description, CASE WHEN questionnaire_id = '$questionnaire_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
* FROM questionnaire
|
||||
*
|
||||
*
|
||||
* @param array $elements An array of arrays containing a value and a description and if selected (3 elements)
|
||||
* @param string $selectid The ID of the element
|
||||
* @param string $var The var name of the return string
|
||||
* @param bool $useblank Add a blank element to the start of the list
|
||||
* @param string|bool $pass Anything to pass along in the return string (remember to separate with &)
|
||||
* @param bool $js Whether to use JS or not
|
||||
*
|
||||
*/
|
||||
function display_chooser($elements, $selectid, $var, $useblank = true, $pass = false, $js = true)
|
||||
{
|
||||
print "<div><select id='$selectid' name='$selectid' ";
|
||||
if ($js) print "onchange=\"LinkUp('$selectid')\"";
|
||||
print ">";
|
||||
if ($useblank)
|
||||
{
|
||||
print "<option value='";
|
||||
if ($js) print "?";
|
||||
if ($pass != false)
|
||||
print $pass;
|
||||
print "'></option>";
|
||||
}
|
||||
foreach($elements as $e)
|
||||
{
|
||||
if ($js)
|
||||
{
|
||||
print "<option value='?$var={$e['value']}";
|
||||
if ($pass != false)
|
||||
print "&$pass";
|
||||
print "' ";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<option value='{$e['value']}' ";
|
||||
}
|
||||
if (isset($e['selected'])) print $e['selected'];
|
||||
print ">".$e['description']."</option>";
|
||||
}
|
||||
print "</select></div>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user