function channel_client_disconnected_log($participant) { $db = sr_pdo(); $p_log = new ParticipantLog(); $p_log->type = 2; $p_log->room_id = $participant->room_id; $p_log->participant_name = $participant->name; $p_log->user_id = $participant->user_id; $p_log->is_registered_user = $participant->is_registered_user; $p_log->ip_address = $participant->ip_address; $p_log->time = $p_log->getCurrentTime(); try { $p_log->add($db); } catch (PDOException $e) { // failed to write the log echo $e; } }
/** * Write a log that the participant joined the room. */ function room_join_log($participant) { $db = sr_pdo(); $p_log = new ParticipantLog(); $p_log->type = 1; $p_log->room_id = $participant->room_id; $p_log->participant_name = $participant->name; $p_log->user_id = $participant->user_id; $p_log->is_registered_user = $participant->is_registered_user; $p_log->ip_address = $participant->ip_address; $p_log->time = $p_log->getCurrentTime(); try { $p_log->add($db); } catch (PDOException $e) { // failed to write the log } }
function admin_dashboard() { global $sr_channel_server_uri; global $sr_root; global $sr_channel_local_installation; // Show Dashboard Page if ($_SERVER['REQUEST_METHOD'] != 'POST') { if (!sr_is_signed_in()) { sr_redirect('/d/main/signin/'); } if (!sr_is_admin()) { sr_redirect('/d/'); } $db = sr_pdo(); $room_log_data = array(); for ($i = 0; $i > -8; $i--) { $date = date('Y-m', strtotime($i . ' month')); $a_month_data = array(); $a_month_data['period'] = $date; for ($j = 0; $j < 3; $j++) { $filter = 'is_open=' . $j . ' AND'; if ($j == 2) { $filter = ''; } $stmt = $db->prepare("SELECT COUNT(*) FROM room_log\n WHERE {$filter} DATE_FORMAT(start_time, '%Y-%m') BETWEEN '{$date}' AND '{$date}'"); $stmt->execute(); $result = $stmt->fetch(); switch ($j) { case 0: $a_month_data['private'] = $result['COUNT(*)']; break; case 1: $a_month_data['public'] = $result['COUNT(*)']; break; case 2: $a_month_data['total'] = $result['COUNT(*)']; break; } } array_push($room_log_data, $a_month_data); } $participant_log_data = array(); for ($i = 0; $i > -8; $i--) { $date = date('Y-m', strtotime($i . ' month')); $a_month_data = array(); $a_month_data['period'] = $date; for ($j = 0; $j < 3; $j++) { $filter = 'is_registered_user='******' AND '; if ($j == 2) { $filter = ''; } $filter .= 'type=2 AND'; $stmt = $db->prepare("SELECT COUNT(*) FROM participant_log\n WHERE {$filter} DATE_FORMAT(time, '%Y-%m') BETWEEN '{$date}' AND '{$date}'"); $stmt->execute(); $result = $stmt->fetch(); switch ($j) { case 0: $a_month_data['non-member'] = $result['COUNT(*)']; break; case 1: $a_month_data['member'] = $result['COUNT(*)']; break; case 2: $a_month_data['total'] = $result['COUNT(*)']; break; } } array_push($participant_log_data, $a_month_data); } $room_num_data = array('total' => RoomLog::getRecordNum(array()), 'current' => Room::getRecordNum(array())); $filter = array(); $filter['type'] = 2; $participant_num_data = array('total' => ParticipantLog::getRecordNum($filter), 'current' => Participant::getRecordNum(array())); $context = array('room_log_data' => $room_log_data, 'room_num_data' => $room_num_data, 'participant_log_data' => $participant_log_data, 'participant_num_data' => $participant_num_data, 'channel_server_uri' => $sr_channel_server_uri, 'channel_server_control_api' => $sr_root . '/d/admin/channel', 'show_channel_server_controls' => $sr_channel_local_installation); sr_response('views/admin/dashboard.php', $context); // Handling Ajax Request (Pagination) } else { try { $db = sr_pdo(); $log_data = array(); if ($_POST['selected_btn'] == 'prev') { $base_date = date('Y-m', strtotime('6 month', strtotime($_POST['viewed_date_first']))); } else { $base_date = date('Y-m', strtotime('8 month', strtotime($_POST['viewed_date_first']))); } for ($i = 0; $i > -8; $i--) { $date = date('Y-m', strtotime($i . ' month', strtotime($base_date))); $a_month_data = array(); $a_month_data['period'] = $date; for ($j = 0; $j < 3; $j++) { if ($_POST['graph'] == 'room') { $filter = 'is_open=' . $j . ' AND'; if ($j == 0) { $filter = ''; } $stmt = $db->prepare("SELECT COUNT(*) FROM room_log\n WHERE {$filter} DATE_FORMAT(start_time, '%Y-%m') BETWEEN '{$date}' AND '{$date}'"); $stmt->execute(); $result = $stmt->fetch(); switch ($j) { case 0: $a_month_data['total'] = $result['COUNT(*)']; break; case 1: $a_month_data['public'] = $result['COUNT(*)']; break; case 2: $a_month_data['private'] = $result['COUNT(*)']; break; } } else { $filter = 'is_registered_user='******' AND '; if ($j == 2) { $filter = ''; } $filter .= 'type=2 AND'; $stmt = $db->prepare("SELECT COUNT(*) FROM participant_log\n WHERE {$filter} DATE_FORMAT(time, '%Y-%m') BETWEEN '{$date}' AND '{$date}'"); $stmt->execute(); $result = $stmt->fetch(); switch ($j) { case 0: $a_month_data['non-member'] = $result['COUNT(*)']; break; case 1: $a_month_data['member'] = $result['COUNT(*)']; break; case 2: $a_month_data['total'] = $result['COUNT(*)']; break; } } } array_push($log_data, $a_month_data); } if ($_POST['graph'] == 'room') { $num_data = array('total' => RoomLog::getRecordNum(array()), 'current' => Room::getRecordNum(array())); } else { $filter = array(); $filter['type'] = 2; $num_data = array('total' => ParticipantLog::getRecordNum($filter), 'current' => Participant::getRecordNum(array())); } $result = array('log_data' => $log_data, 'num_data' => $num_data); echo json_encode($result); } catch (PDOException $e) { } } }