~adamzammit/quexs/quexslinkcall

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php 
/**
 * Display status of case
 *
 *
 *	This file is part of queXS
 *	
 *	queXS is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 2 of the License, or
 *	(at your option) any later version.
 *	
 *	queXS is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with queXS; if not, write to the Free Software
 *	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *
 * @author Adam Zammit <adam.zammit@deakin.edu.au>
 * @copyright Deakin University 2007,2008
 * @package queXS
 * @subpackage user
 * @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
 * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
 * 
 */

/**
 * Configuration file
 */
include ("config.inc.php");

/**
 * Database file
 */
include ("db.inc.php");

/** 
 * Authentication
 */
require ("auth-interviewer.php");


/**
 * XHTML functions
 */
include ("functions/functions.xhtml.php");

/**
 * Operator functions
 */
include("functions/functions.operator.php");



$operator_id = get_operator_id();
$state = is_on_call($operator_id);

$js = array("js/popup.js");

if (browser_ie())
	$js[] = "js/window_ie6_interface2.js";
else
	$js[] = "js/window_interface2.js";

if (AUTO_LOGOUT_MINUTES !== false)
{
	$js[] = "include/jquery/jquery-1.4.2.min.js";
	$js[] = "js/childnap.js";
}

xhtml_head(T_("Status"),false,array("include/bootstrap/css/bootstrap.min.css","css/status_interface2.css"),$js);

$ca = get_call_attempt($operator_id,false);
if ($ca)
{
	$respondent_id  = get_respondent_id($ca);
	$case_id = get_case_id($operator_id);
	$fname = get_respondent_variable("firstName",$respondent_id);
	$lname = get_respondent_variable("lastName",$respondent_id);
	print "<h4>" . T_("Name") . ": $fname $lname</h4>";

	$appointment = is_on_appointment($ca);

	$call_id = get_call($operator_id);

	$sql = "SELECT o.tryanother, o.require_note
		FROM `call` as c, `outcome` as o
		WHERE c.call_attempt_id = '$ca'
		AND c.outcome_id = o.outcome_id
		ORDER BY call_id DESC
		LIMIT 1";
	
	$rst = $db->GetRow($sql);
	
	if ((empty($rst) || $rst['tryanother'] == 1)) //dial another number only when available and not ending
	{

		if (isset($_POST['contactphone']))
		{
			$pcontact_phone_id = intval($_POST['contactphone']);

			//If an outcome already assigned, end the current call and start the enxt one to pcontact_phone_id
			//Otherwise bring up the assign outcome window
			if (!$call_id) //outcome assigned
			{
				$call_id = get_call($operator_id,$respondent_id,$pcontact_phone_id,true);
				echo "<script type='text/javascript'>openParentObject(\"main-content\",\"" . get_respondentselection_url($operator_id,false) . "\");</script>";
			}
			else
			{
				//bring up assign outcome window
				print "<script type='text/javascript'>parent.poptastic('call_interface2.php');</script>";
			}
		}
		
		if (!$call_id)
		{
			$sql = "SELECT c. *
                                FROM contact_phone AS c
                                LEFT JOIN (
                                                SELECT contact_phone.contact_phone_id
                                                FROM contact_phone
                                                LEFT JOIN `call` ON ( call.contact_phone_id = contact_phone.contact_phone_id )
                                                LEFT JOIN outcome ON ( call.outcome_id = outcome.outcome_id )
                                                WHERE contact_phone.case_id = '$case_id'
                                                AND outcome.tryagain =0
                                          ) AS l ON l.contact_phone_id = c.contact_phone_id
                                LEFT JOIN
                                (
                                 SELECT contact_phone_id
                                 FROM `call`
                                 WHERE call_attempt_id = '$ca'
                                 AND outcome_id != 18
                                ) as ca on ca.contact_phone_id = c.contact_phone_id
                                WHERE c.case_id = '$case_id'
                                AND l.contact_phone_id IS NULL
                                AND ca.contact_phone_id IS NULL
				order by c.priority ASC";
			
			$numsa = $db->GetRow($sql);

			if (!empty($numsa))
			{
				if ($appointment)
				{
					//create a call on the appointment number
					$sql = "SELECT cp.*
						FROM contact_phone as cp, appointment as a
						WHERE cp.case_id = '$case_id'
						AND a.appointment_id = '$appointment'
						AND a.contact_phone_id = cp.contact_phone_id";
		
					$rs = $db->GetRow($sql);
					$contact_phone_id = $rs['contact_phone_id'];				
				}
				else
				{
					$contact_phone_id = $numsa['contact_phone_id'];
				}
			
				$call_id = get_call($operator_id,$respondent_id,$contact_phone_id,true);
			}
		}
		
		if ($appointment)
		{	
			$sql = "SELECT DATE_FORMAT(CONVERT_TZ(a.start,'System', o.Time_zone_name),'%Y-%b-%d %H:%i') as time
				FROM appointment as a, operator as o
				WHERE o.operator_id = '$operator_id'
				AND a.appointment_id = '$appointment'";

			$rs = $db->GetRow($sql);

			$apdate = $rs['time'];

			if (missed_appointment($ca)) 	print "<div class='alert alert-warning'>" . T_("MISSED") .  ": " . $apdate .  "</div>";
			else 							print "<div class='alert alert-info'>" . T_("Appointment") . ": " . $apdate .  "</div>";
		}

		if ($call_id)
		{
			$sql = "SELECT c.*, CASE WHEN c.contact_phone_id = ccc.contact_phone_id THEN 'checked=\"checked\"' ELSE '' END as checked
				FROM contact_phone as c
				LEFT JOIN `call` as ccc ON (ccc.call_id = '$call_id')
				LEFT JOIN (
					SELECT contact_phone.contact_phone_id
					FROM contact_phone
					LEFT JOIN `call` ON ( call.contact_phone_id = contact_phone.contact_phone_id )
					LEFT JOIN outcome ON ( call.outcome_id = outcome.outcome_id )
					WHERE contact_phone.case_id = '$case_id'
					AND outcome.tryagain =0
				) AS l ON l.contact_phone_id = c.contact_phone_id
				LEFT JOIN
					(
					SELECT contact_phone_id
					FROM `call`
					WHERE call_attempt_id = '$ca'
					AND outcome_id != 18
					AND outcome_id != 0
					) as ca on ca.contact_phone_id = c.contact_phone_id
				WHERE c.case_id = '$case_id'
				AND l.contact_phone_id IS NULL
				AND ca.contact_phone_id IS NULL";
	
	
			$rs = $db->GetAll($sql);
	

			//Display all available numbers for this case as a list of radio buttons
			//By default, the selected radio button should have a "call" started for it
		 	//When then next one clicked, it should bring up call screen if no outcome otherwise start new call
			//print "<div>";print "</div>";
			foreach($rs as $r)
			{
				print "<form method='post' action='?'>
						<p>
						<input onclick='this.form.submit();' type='radio' name='contactphone' value='{$r['contact_phone_id']}' id='contactphone{$r['contact_phone_id']}' {$r['checked']}/>&ensp;
						<label for='contactphone{$r['contact_phone_id']}'>{$r['phone']}";
						if ($r['checked']) print "&emsp;<a href='callto:{$r['phone']}' class='btn btn-primary btn-xs'><i class='fa fa-phone fa-fw'></i>&ensp;" . T_('Dial') . "</a>";
						if (!empty($r['description'])) print " - " . $r['description'];
						print "</label>
						</p>
					  </form>";
			}
			
		}
		else
			print "<div class='text'>" . T_("No more numbers to call") . "</div>";
	}
	else
		print "<div class='text'>" . T_("No more numbers to call") . "</div>";
}
else
	print "<div class='text'>" . T_("No case") . "</div>";

xhtml_foot();

?>