-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
130 lines (114 loc) · 5.08 KB
/
index.php
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
<?php
include "conf/config.php";
require_once 'Cache/Lite.php';
$id=mktime(date("H"), floor(date("i")/10), 0, date("n"), date("j"), date("Y"));
if (isset($_GET['id'])){ $id=time();}
$opts = array(
'cacheDir' => '/tmp/cache/',
'automaticSerialization' => true,
'lifeTime' => 600 );
$globcount = microtime(true);
function dbconnect(){
include('conf/config.php');
$link = mysqli_connect($config['MYSQL']['HOST'], $config['MYSQL']['USER'], $config['MYSQL']['PWD']) or die("Could not connect : " . mysqli_error($link));
mysqli_select_db($link, $config['MYSQL']['DBNAME']) or die("Could not select database");
$GLOBALS['link']=$link;
}
function dbas(){
include "conf/config.php";
$linkas = mysqli_connect($config['MYSQLas']['HOST'], $config['MYSQLas']['USER'], $config['MYSQLas']['PWD'], $config['MYSQLas']['DBNAME']) or die("Could not connect : " . mysqli_error($linkas). "<br> mysql connect error: ".mysqli_connect_error($linkas));
mysqli_select_db($linkas, $config['MYSQLas']['DBNAME']) or die("Could not select database");
$GLOBALS['linkas']=$linkas;
}
function get_user_info($userid) {
$query="SELECT `firstname`,`lastname`,`username` FROM `swstaff` where `staffid` = '".$userid."';";
dbconnect();
global $link;
$starttime = microtime(true);
$result = mysqli_query($link, $query, MYSQLI_USE_RESULT) or die("Query failed (info)[$link] : " . mysqli_error($link));
$endtime = microtime(true); $duration = $endtime - $starttime;
$row=mysqli_fetch_row($result);
return "".$row['0']." ".$row['1']." (".$row['2'].")<!-- ".$userid." ($duration ms) -->";
}
function get_user_id_with_max_chatobj($enabledID) {
$query='SELECT
`staffid`
FROM (
SELECT
COUNT(`chatobjectid`) ccobj,
staffid
FROM
`swchatobjects`
WHERE
`chatstatus` = 3
AND
`staffpostactivity` > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))
AND
`staffid` IN (' . $enabledID . ')
GROUP BY
staffid
) t
HAVING MAX(t.ccobj)';
dbconnect();
global $link;
$result = mysqli_query($link, $query, MYSQLI_USE_RESULT) or die("Query failed (chat) : " . mysqli_error($link));
$row=mysqli_fetch_row($result);
return $row['0'];
}
function get_user_chat($userid) {
$query="select count(`chatobjectid`) from `swchatobjects` where `chatstatus` = '3' and `staffpostactivity` > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY)) and `staffid` = '".$userid."';";
dbconnect();
global $link;
$starttime = microtime(true);
$result = mysqli_query($link, $query, MYSQLI_USE_RESULT) or die("Query failed (chat) : " . mysqli_error($link));
$endtime = microtime(true); $duration = $endtime - $starttime;
$row=mysqli_fetch_row($result);
return $row['0']."<!-- $duration -->";
}
function get_user_ticket($userid) {
$query="select count(*) from `swticketauditlogs` where `dateline` > unix_timestamp(curdate()) and `creatorid` = '".$userid."' and `actionmsg` = \"Ticket status changed from: Open to: In Progress\";";
dbconnect();
global $link;
$starttime = microtime(true);
$result = mysqli_query($link,$query, MYSQLI_USE_RESULT) or die("Query failed (ticket): " . mysqli_error($link));
$endtime = microtime(true); $duration = $endtime - $starttime;
$row=mysqli_fetch_row($result);
return $row['0']."<!-- $duration -->";
}
function get_user_phone($userid) {
include "conf/config.php";
$query="SELECT count(*) FROM `cdr` WHERE `calldate` > curdate() and `disposition` = 'ANSWERED' and `dstchannel` like 'SIP/".$sip[$userid]."%'";
dbas();
global $linkas;
$starttime = microtime(true);
$result = mysqli_query($linkas, $query, MYSQLI_USE_RESULT) or die("Query failed (chat) : " . mysqli_error($linkas)."|||".mysqli_connect_error($linkas));
$endtime = microtime(true); $duration = $endtime - $starttime;
$row = mysqli_fetch_row($result);
return $row[0]."<!-- $duration -->";
}
$Cache_Lite = new Cache_Lite($opts);
if ($design = $Cache_Lite->get($id)) {
echo($design);
}
else {
$design="<table border=\"2\" cellpadding=\"2\" width=\"100%\">";
$design.="<tr> <td width=\"20%\" >user</td> <td>chat</td> <td>ticket</td> <td>phone</td> </tr>";
$max_chatobj_user_id = get_user_id_with_max_chatobj($config['enabledID']);
foreach (explode(",", $config['enabledID']) as $user) {
$chat=get_user_chat($user);
$ticket=get_user_ticket($user);
$phone=get_user_phone($user);
$design.="<tr><td>".get_user_info($user)."</td>";
if ($chat==0) {$design.="<td bgcolor=\"#FFD9D9\">".$chat."</td>";} elseif ((int)$user == (int)$max_chatobj_user_id) { $design.="<td bgcolor=\"#FFDEAD\">".$chat."</td>"; } else { $design.="<td>".$chat."</td>";}
if ($ticket==0) {$design.="<td bgcolor=\"#FFD9D9\">".$ticket."</td>";}else {$design.="<td>".$ticket."</td>";}
if ($phone==0) {$design.="<td bgcolor=\"#FFD9D9\">".$phone."</td>";}else {$design.="<td>".$phone."</td>";}
$design.=" </tr>\r\n";
}
$design.="</table>";
$endglobcount = microtime(true); $globduration = $endglobcount - $globcount;
$design.= "generated $globduration<br>last update: ".date("Y-m-d H:i:s",$id);
echo $design;
$Cache_Lite->save($design);
}
$previd=$id-600;
$Cache_Lite->remove($previd);