📄 online.php
字号:
<?php
// +-------------------------------------------------------------+
// | DeskPRO v [2.0.1 Production]
// | Copyright (C) 2001 - 2004 Headstart Solutions Limited
// | Supplied by WTN-WDYL
// | Nullified by WTN-WDYL
// | Distribution via WebForum, ForumRU and associated file dumps
// +-------------------------------------------------------------+
// | DESKPRO IS NOT FREE SOFTWARE
// +-------------------------------------------------------------+
// | License ID : Full Enterprise License =) ...
// | License Owner : WTN-WDYL Team
// +-------------------------------------------------------------+
// | $RCSfile: online.php,v $
// | $Date: 2004/02/10 01:34:25 $
// | $Revision: 1.14 $
// +-------------------------------------------------------------+
// | File Details:
// | - Technician activity log and online/offline status viewer
// | (administration interface)
// +-------------------------------------------------------------+
error_reporting(E_ALL & ~E_NOTICE);
require_once('./global.php');
//Nullify WTN-WDYL Team
if ($_REQUEST['do'] == 'csv') {
$data = $db->query_return_array('SELECT * FROM tech_timelog_archive');
if (is_array($data)) {
header('Content-type: text/comma-separated-values');
print "id,techid,activity,stamp\n\n";
foreach ($data AS $val) {
print join(',', $val) . "\n";
}
}
exit;
}
$technames = $db->query_return_array_id("SELECT id, username FROM tech", 'username');
admin_header('Technician Activity', 'History');
if ($_REQUEST['do'] == 'archive') {
$data = $db->query_return_array("SELECT * FROM tech_timelog");
if (is_array($data)) {
$db->query('INSERT INTO tech_timelog_archive (id, techid, activity, stamp) VALUES ' . multi_array2sql($data));
foreach ($data AS $row) {
$ids[] = $row['id'];
}
$db->query('DELETE FROM tech_timelog WHERE id IN ' . array2sql($ids));
print '<P>Activity (' . count($data) . ' item(s)) archived.</P>';
} else {
print "<P>No activity to archive.</P>";
}
}
if ($_REQUEST['do'] == 'restore') {
$data = $db->query_return_array("SELECT * FROM tech_timelog_archive");
if (is_array($data)) {
$db->query('INSERT INTO tech_timelog (id, techid, activity, stamp) VALUES ' . multi_array2sql($data));
foreach ($data AS $row) {
$ids[] = $row['id'];
}
$db->query('DELETE FROM tech_timelog_archive WHERE id IN ' . array2sql($ids));
print '<P>Activity (' . count($data) . ' item(s)) restored.</P>';
} else {
print "<P>No activity to restore.</P>";
}
}
if ($_REQUEST['do'] == 'purge') {
$db->query('DELETE FROM tech_timelog_archive');
if ($rows = $db->affected_rows()) {
print "<P>Activity ($rows item(s)) purged.</P>";
} else {
print '<P>No activity to purge.</P>';
}
}
if (!$_REQUEST['range']) {
$_REQUEST['range'] = 'span';
}
if ($_REQUEST['range'] == 'span') {
if ((int)$_REQUEST['duration']) {
$duration = (int)$_REQUEST['duration'];
switch ($_REQUEST['units']) {
case 'seconds':
case 'minutes':
case 'hours':
case 'days':
case 'weeks':
case 'months':
case 'years':
$when = strtotime(date('r') . " -$duration $_REQUEST[units]");
$text = "Viewing events for the past $duration $_REQUEST[units]";
break;
default:
$_REQUEST['units'] = 'minutes';
$duration = 30;
$when = strtotime(date('r') . " -$duration days");
$text = "Viewing events for the past 30 minutes";
break;
}
} else {
$when = strtotime(date('r') . ' -30 minutes');
$duration = 30;
$_REQUEST['units'] = 'minutes';
}
$terms[] = "stamp >= $when";
$from = date('Y-m-d', strtotime(date('Y-m-d') . ' -1 week'));
$to = date('Y-m-d');
} else {
$from = "$_REQUEST[yfrom]-$_REQUEST[mfrom]-$_REQUEST[dfrom]";
$fromstamp = strtotime($from);
$to = "$_REQUEST[yto]-$_REQUEST[mto]-$_REQUEST[dto] 23:59:59";
$tostamp = strtotime($to);
$terms[] = "stamp >= $fromstamp AND stamp <= $tostamp";
}
$text = " <A HREF=\"#history\">Activity History</A> | <A HREF=\"#sessions\">View Currently Active Sessions</A><BR>Archive: <A HREF=\"online.php?do=archive\">Archive Current Activity</A> | <A HREF=\"online.php?do=csv\">Archive Download (CSV)</A> | <A HREF=\"online.php?do=restore\">Restore Archived Data (doesn't overwrite current data)</A> | <A HREF=\"online.php?do=purge\">Purge Archived Data</A><BR>" . $text;
if (is_array($_REQUEST['techid'])) {
if (!(count($_REQUEST['techid']) == 1 AND !$_REQUEST['techid'][0])) {
$terms[] = 'techid IN '.array2sql($_REQUEST['techid']);
$text .= " <I>(restricting to selected technicians, listed below)</I>";
}
}
$where = 'WHERE ' . join(' AND ', $terms);
// Tech activity log
$techs = array();
$techtime = array();
$datetime = array();
$db->query("SELECT tech.username AS username, techid, activity, stamp FROM tech_timelog, tech $where
AND tech.id = tech_timelog.techid ORDER BY stamp, tech.username");
if ($db->num_rows()) {
$logcols = array('<B>Technician</B>', '<B>Activity</B>', '<B>Date/Time</B>');
while ($result = $db->row_array()) {
if ($techs[$result['techid']]) {
if (($diff = $result['stamp'] - $techs[$result['techid']]) <= $settings['max_log_duration']) {
$techtime[$result['techid']][date('Y-m-d', $result['stamp'])] += $diff;
$techtime[$result['techid']]['total'] += $diff;
$datetime[date('Y-m-d', $result['stamp'])][$result['techid']] += $diff;
$total += $diff;
}
}
$techs[$result['techid']] = $result['stamp'];
$log[] = array("<A HREF=\"tech.php?do=edit&id=$result[techid]\">$result[username]</A>", $result['activity'], date('r', $result['stamp']));
}
} else {
$log[] = array('<CENTER><I>No activity for specified user(s).</I></CENTER>');
}
// Tech list
$db->query("SELECT username, id FROM tech ORDER BY username");
$users[0] = 'All';
while ($result = $db->row_array()) {
$users[$result[id]] = $result[username];
}
$form[] = array('<FORM METHOD="post" ACTION="online.php"><B>List Specific Technicians</B>',
form_select('techid', $users, '', $_REQUEST['techid'], 0, '', 5));
$form[] = array('<B>Show Events From the Last ...</B>',
form_radio_single('range', 'span', iff($_REQUEST['range'] == 'span', 1, 0)) . ' ' .
form_input('duration', $duration, 5) .
form_select('units', array('seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'), '', $_REQUEST['units'], 1));
$form[] = array('<B>... or between the dates<B>',
form_radio_single('range', 'range', iff($_REQUEST['range'] == 'range', 1, 0)) . ' ' .
form_date('from', NULL, NULL, NULL, NULL, $from) . ' and ' .
form_date('to', NULL, NULL, NULL, NULL, $to));
$form[] = array('<B>Show Individual Entries</B>',
form_radio_yn('detail', NULL, $_REQUEST['detail']));
$form[] = array('<B>Show Totals by Date</B>',
form_radio_yn('bydate', NULL, $_REQUEST['bydate']));
$form[] = array('<B>Show Totals by Technician</B>',
form_radio_yn('bytech', NULL, $_REQUEST['bytech']));
$form[] = array('', form_submit('Update'));
// Current sessions
$db->query("SELECT tech.username AS username, techid, lastactivity, location
FROM tech, tech_session
WHERE tech.id = tech_session.techid
ORDER BY username");
if ($db->num_rows()) {
$sessions[] = array('<B>Technician</B>', '<B>Last Activity</B>', '<B>Last Access Time/Date</B>');
while ($result = $db->row_array()) {
$sessions[] = array("<A HREF=\"tech.php?do=edit&id=$result[techid]\">$result[username]</A>", $result['location'], date('r', $result['lastactivity']));
}
} else {
$sessions[] = array('<CENTER><I>No active sessions.</I></CENTER>');
}
print $text."</P>";
print "<A NAME=\"sessions\"></A>";
table_header('Currently Active Sessions');
table_content('', $sessions);
table_footer();
print "<A NAME=\"options\"></A>";
table_header('History Options');
table_content('', $form);
table_footer();
if ($_REQUEST['bydate'] OR $_REQUEST['bytech']) {
print "<A NAME=\"stats\"></A>";
}
if ($_REQUEST['bydate']) {
$row = array();
foreach ($datetime AS $key => $day) {
$row[] = array('<B>' . date('D, M jS Y', strtotime($key)) . "</B>");
foreach ($day AS $tech => $data) {
$date = split('-', date('Y-m-d', $data));
$row[] = array($technames[$tech], "<A HREF=\"online.php?yfrom=$date[0]&mfrom=$date[1]&dfrom=$date[2]&yto=$date[0]&mto=$date[1]&dto=$date[2]&bydate=1&detail=1\">" . clean_time($data) . "</A>");
}
}
$row[] = '<CENTER><B>Total: ' . clean_time($total) . '</CENTER>';
table_header("Totals by Date");
table_content(NULL, $row);
table_footer();
}
if ($_REQUEST['bytech']) {
$row = array();
foreach ($techtime AS $key => $tech) {
$row[] = array("<B>{$technames[$key]}</B>");
foreach ($tech AS $date => $data) {
if ($date != 'total') {
$datetmp = split('-', date('Y-m-d', $data));
$row[] = array(date('D, M jS Y', strtotime($date)), "<A HREF=\"online.php?techid=$user[id]&yfrom=$datetmp[0]&mfrom=$datetmp[1]&dfrom=$datetmp[2]&yto=$datetmp[0]&mto=$datetmp[1]&dto=$datetmp[2]&bytech=1&detail=1\">" . clean_time($data) . "</A>");
}
}
}
$row[] = '<CENTER><B>Total: ' . clean_time($total) . '</CENTER>';
table_header("Totals by Technician");
table_content(NULL, $row);
table_footer();
}
if ($_REQUEST['detail']) {
print "<A NAME=\"history\"></A>";
table_header('Technician Activity Log');
table_content($logcols, $log);
table_footer();
print "<A HREF=\"#top\">View Active Sessions</A>";
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -