* @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 * @param string|int $require_operator_id False if for any operator otherwise restrict this appointment to a particular operator * @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,$require_operator_id = false) { global $db; $start = "$y-$m-$d $start"; $end= "$y-$m-$d $end"; if ($require_operator_id == false) $require_operator_id = "NULL"; $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'),$require_operator_id,$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)); $p = "am"; if ($h == 12) { $p = "pm"; } else if ($h == 0) { $h = 12; $p = "am"; } else if ($h > 12) { $h = $h - 12; $p = "pm"; } //Use the TIME_FORMAT string as defined in mysql http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format $from = array("%H","%h","%I","%i","%S","%s","%p"); $to = array(substr($time,0,2),$h,$h,$m,$m,$s,$s,$p); return str_replace($from,$to,TIME_FORMAT); } /** * 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 * @param bool $first Select the first respondent available if none specifically selected? */ function display_respondent_list($case_id,$respondent_id = false,$first = false) { global $db; $sql = "SELECT respondent_id,firstName,lastName FROM respondent WHERE case_id = '$case_id'"; $rs = $db->GetAll($sql); if (count($rs) >1 ){ print "
" . T_("Select a respondent") . ":
". $rs->GetMenu('Time_zone_name',$rzone,false,false,0,'class="form-control"'). "
"; } /** * 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 $questionnaire_id The questionnaire id * @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($questionnaire_id,$respondent_id, $day, $month, $year, $time = false, $timeend = false) { global $db; $restricted = is_shift_restricted($questionnaire_id); if ($restricted) { /** * 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( s.end, s.start)) / 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"; } else $sql = "SELECT 0 as sh, 0 as sm, !(DATE(CONVERT_TZ(NOW(),'System',r.Time_zone_name)) = DATE(CONVERT_TZ('$year-$month-$day 08:00:00','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, 288 as intervals, '00:00:00' as start, '23:59:59' as end FROM respondent as r WHERE r.respondent_id = '$respondent_id'"; $rs = $db->GetAll($sql); foreach($rs as $r) { print "" . T_("Shift from:") . " ".$r['start']." " . T_(" till ")." ".$r['end']."
"; } print "| " . T_("Mon") . " | " . T_("Tue") . " | " . T_("Wed") . " | " . T_("Thu") . " | " . T_("Fri") . " | " . T_("Sat") . " | " . T_("Sun") . " |
| ".$Day->thisDay()." | \n" ); } else if ( $Day->isEmpty() ) { echo ( "\n" ); } else { //if it is in the past -> unavailable if ($Day->getTimeStamp() < $ttoday->getTimeStamp()) { echo ( " | ".$Day->thisDay()." | \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 (!empty($rs) && $rs->RecordCount() == 0) { echo ( "".$Day->thisDay()." | \n" ); } else { echo ( "".$Day->thisDay()." | \n" ); } } else echo ( "".$Day->thisDay()." | \n" ); } // isLast() to find end of week if ( $Day->isLast() ) echo ( "|
| << | " . date('l j F Y',mktime(0,0,0,$month,$day,$year)) . "";?> | >> | ||||