~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
<?php 
/**
 * Display the main page including all panels and tabs
 *
 *
 *	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
 * 
 *
 */

/**
 * Language file
 */
include_once("lang.inc.php");

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


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

xhtml_head(T_("Standby"),false,array("include/bootstrap/css/bootstrap.min.css","include/bootstrap/css/bootstrap-theme.min.css","include/font-awesome/css/font-awesome.css","css/index_interface2.css"), array(), false, 300);

if (isset($_GET['auto']))
{
	include_once("functions/functions.operator.php");

	$operator_id = get_operator_id();
	$case_id = get_case_id($operator_id,false);
	end_case($operator_id);
	 //add case note  
      $sql = "INSERT INTO case_note (case_note_id,case_id,operator_id,note,`datetime`)
        VALUES (NULL,'$case_id','$operator_id','" . TQ_("Operator Automatically logged out after: ") . AUTO_LOGOUT_MINUTES . TQ_(" minutes") . "', CONVERT_TZ(NOW(),'System','UTC'))";
      $db->Execute($sql);

	print "<div class='error well' style='margin:2%; color:red;'><b>" . T_("You have been automatically logged out of work due to inactivity") . "</b></div>";
}


/* $sql = "SELECT sample_id FROM `sample` where import_id = 1";
$rs = $db->GetAll($sql);
for($i=0;$i<=count($rs)-1;$i++){ $ssseedss[] = $rs[$i]['sample_id'] ;}
$ssseedssd = implode(",",$ssseedss);
 print $ssseedssd; */
 
 
/**
 * check if cases available
 */

//if assigned to a questionnaire

$sql = "SELECT oq.questionnaire_id, q.description
	FROM operator_questionnaire as oq, questionnaire as q
	WHERE q.enabled = 1
	AND oq.operator_id = '$operator_id'
	AND q.questionnaire_id = oq.questionnaire_id";

$rs = $db->GetAll($sql);
$cases_count = array(); $new_samples = array();
if (empty($rs))
	
	print "<div class='error well' style='margin:2%; color:red; font-size:1.5em;'><b>" . T_("ERROR: No questionnaires assigned to you") . "</b></div>";
	
else
{
	print "<div class='col-sm-4'>";
	print "<div class=' well' style='padding:2%;'><p>" . T_("Assigned questionnaires:") . "";
			
	/* if (isset($_GET['auto'])) {
		echo "</p></br>";
		xhtml_table($rs,array("questionnaire_id","description"),array(T_("ID"),T_("Description")));
	}
	else  */
	echo "&emsp;<b style='color:green;'>" . count($rs) . "</b></p>";
	print "</div>";
	
	for ($i = 0; $i <= count($rs)-1;$i++){ 	$oq[] = $rs[$i]['questionnaire_id']; }
	$oqid = implode(",",$oq);

	//no sample
	$sql = "SELECT q.questionnaire_id, q.description, si.description as sdescription, si.sample_import_id
	FROM questionnaire as q, sample_import as si LEFT JOIN questionnaire_sample_quota AS qsq ON (qsq.sample_import_id = si.sample_import_id), questionnaire_sample as qs
	WHERE q.questionnaire_id IN ($oqid)
	AND si.enabled = 1
	AND (qsq.quota_reached = 0 OR qsq.quota_reached IS NULL)
	AND qs.questionnaire_id = q.questionnaire_id
	AND si.sample_import_id = qs.sample_import_id
	GROUP BY si.sample_import_id";

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

	if (empty($rs))
		print "<div class='error well' style='margin:2%; color:red; font-size:1.5em;'><b>" . T_("ERROR: No samples assigned to the questionnaires") . "</b></div>";
	else {
		print "<div class=' well' style='padding:2%;'>" . T_("Assigned samples:") . "&emsp;<b style='color:green;'>" . count($rs) . "</b></div>";
		//xhtml_table($rs,array("questionnaire_id","description","sdescription"),array(T_("ID"),T_("Description"),T_("Sample")));
	
	for ($i = 0; $i <= count($rs)-1;$i++){ 	$si[] = $rs[$i]['sample_import_id']; }
	$siid = implode(",",$si);
	
	//shift restrictions and no shift
	$sql = "SELECT q.description, CONVERT_TZ(sh.start, 'UTC', @@session.time_zone) as st, CONVERT_TZ(sh.end, 'UTC',@@session.time_zone) as en
			FROM questionnaire AS q
			LEFT JOIN shift AS sh ON (sh.questionnaire_id = q.questionnaire_id AND (CONVERT_TZ( NOW( ) ,@@session.time_zone, 'UTC' ) >= sh.start ) AND (CONVERT_TZ( NOW( ) ,@@session.time_zone, 'UTC' ) <= sh.end ))
			WHERE q.questionnaire_id IN ($oqid)
			AND !(q.restrict_work_shifts = 1 AND sh.shift_id IS NULL)";

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

	if (empty($rs))
		print "<div class='error well' style='margin:2%; color:red; font-size:1.5em;'><b>" . T_("ERROR: No shifts at this time") . "</b></div>";

	else{
			print "<div class=' well' style='padding:2%;'>" . T_("Current shifts available:") . "&emsp;<b style='color:green;'>" . T_("Yes") . "</b></div>";
			//xhtml_table($rs,array("description","st","en"),array(T_("Questionnaire"),T_("Shift start"),T_("Shift end")));
		
			//assigned to operator
	
			// call restrictions and outside times, operator skill and filter outcomes 10,25,28,42,43,40
			$sql = "SELECT COUNT( DISTINCT sv.sample_id) as count_samples
			FROM `sample` as s
			JOIN `sample_var` as sv on( s.sample_id = sv.sample_id )
			JOIN sample_import as si on (s.import_id = si.sample_import_id)
			LEFT JOIN (`case` as c,  `outcome` as ou ) on (s.sample_id = c.sample_id and ou.outcome_id = c.current_outcome_id)
			LEFT JOIN call_restrict as cr on ( cr.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= cr.start 	and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= cr.end)
			WHERE c.questionnaire_id IN ($oqid)
            AND s.import_id IN ($siid)
			AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL)
			AND ou.outcome_type_id IN( SELECT outcome_type_id FROM operator_skill WHERE operator_id = '$operator_id')
			AND ou.outcome_id NOT IN (10,25,28,42,43,44,45,40)";
			$cases_count = $db->GetRow($sql);

			if ($cases_count['count_samples'] == 0){
			print "<div class='error well' style='padding:2%;'>" . T_("Cases currently available to call") . ": <b style='color:red;'> " . $cases_count['count_samples'] . "</b></div>";
			}
			else {
			print "<div class='well' style='padding:2%;'>" . T_("Cases currently available to call") . ": <b style='color:green;'> " . $cases_count['count_samples'] . "</b></div>";
			}
		
			//new samples available 
			$sql = "SELECT COUNT( DISTINCT sv.sample_id) as count_samples
				FROM `sample` as s
				JOIN `sample_var` as sv on( s.sample_id = sv.sample_id )
				JOIN sample_import as si on (s.import_id = si.sample_import_id)
				LEFT JOIN `case` as c on (s.sample_id = c.sample_id )
				LEFT JOIN call_restrict as cr on ( cr.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= cr.start 	and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= cr.end)
				WHERE s.import_id IN ($siid)
				AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL)
				AND c.sample_id IS NULL";
			$new_samples = $db->GetRow($sql);
			
			if ($new_samples['count_samples'] == 0){
			print "<div class='error well' style='margin:2%; font-size:1.5em;'>" . T_("New samples available to call") . ": <b style='color:red;'> " . $new_samples['count_samples'] . "</b></div>";
				}
			else {
				print "<div class='well' style='padding:2%;'>" . T_("New samples available to call") . ": <b style='color:green;'> " . $new_samples['count_samples'] . "</b></div>";
			}
		
		}
	}
	
	print "</div>";
}

?>
			<div class="col-sm-3 col-sm-offset-1" style="top: 150px;">
				
<?php if ((isset($cases_count['count_samples']) && $cases_count['count_samples'] > 0) or (isset($new_samples['count_samples']) && $new_samples['count_samples'] > 0)){  ?>
				<a href="index_interface2.php" class="btn btn-default btn-lg btn-block" style="border-radius:25px; color:blue"><?php  echo T_("Get a new case"); ?>  <i class="fa fa-lg fa-play fa-fw"></i></a>
				</br>
<?php } ?>
				<a href="endwork.php" class="btn btn-default btn-lg btn-block" style="border-radius:25px; color:red;"><?php  echo T_("End work"); ?>  <i class="fa fa-lg fa-ban fa-fw "></i></a>

			</div>
<?php 
			
xhtml_foot();

?>