= '$start' AND registered_at <= '$end' AND session_id = '$sessionId' "; $result = Database::query($sql); $result = Database::fetch_array($result); $row['course'] = $courseListInString; $row['count'] = $result['count']; $list[] = $row; } } if (!empty($operation)) { $fileName = !empty($action) ? get_lang('PortalUserSessionStats').'_'.api_get_local_time() : 'report'; switch ($exportFormat) { case 'xls': Export::arrayToXls($list, $fileName); break; case 'xls_html': //TODO add date if exists $browser = new Browser(); if ($browser->getPlatform() == Browser::PLATFORM_WINDOWS) { Export::export_table_xls_html($list, $fileName, 'ISO-8859-15'); } else { Export::export_table_xls_html($list, $fileName); } break; case 'csv': default: Export::arrayToCsv($list, $fileName); break; } } echo json_encode($list); break; case 'recent_logins': // Give a JSON array to the stats page main/admin/statistics/index.php // for global recent logins header('Content-type: application/json'); $list = []; $all = Statistics::getRecentLoginStats(false, $sessionDuration); foreach ($all as $tick => $tock) { $list['labels'][] = $tick; } $list['datasets'][0]['label'] = get_lang('Logins'); $list['datasets'][0]['backgroundColor'] = "rgba(151,187,205,0.2)"; $list['datasets'][0]['borderColor'] = "rgba(151,187,205,1)"; $list['datasets'][0]['pointBackgroundColor'] = "rgba(151,187,205,1)"; $list['datasets'][0]['pointBorderColor'] = "#fff"; $list['datasets'][0]['pointHoverBackgroundColor'] = "#fff"; $list['datasets'][0]['pointHoverBorderColor'] = "rgba(151,187,205,1)"; foreach ($all as $tick => $tock) { $list['datasets'][0]['data'][] = $tock; } $list['datasets'][1]['label'] = get_lang('DistinctUsersLogins'); $list['datasets'][1]['backgroundColor'] = "rgba(0,204,0,0.2)"; $list['datasets'][1]['borderColor'] = "rgba(0,204,0,1)"; $list['datasets'][1]['pointBackgroundColor'] = "rgba(0,204,0,1)"; $list['datasets'][1]['pointBorderColor'] = "#fff"; $list['datasets'][1]['pointHoverBackgroundColor'] = "#fff"; $list['datasets'][1]['pointHoverBorderColor'] = "rgba(0,204,0,1)"; $distinct = Statistics::getRecentLoginStats(true, $sessionDuration); foreach ($distinct as $tick => $tock) { $list['datasets'][1]['data'][] = $tock; } echo json_encode($list); break; case 'tools_usage': // Give a JSON array to the stats page main/admin/statistics/index.php // for global tools usage (number of clicks) header('Content-type: application/json'); $list = []; $all = Statistics::getToolsStats(); foreach ($all as $tick => $tock) { $list['labels'][] = $tick; } // Get the common colors from the palette used for pchart $paletteFile = api_get_path(SYS_CODE_PATH).'palettes/pchart/default.color'; $palette = file($paletteFile); // Because the pchart palette has transparency as integer values // (0..100) and chartjs uses percentage (0.0..1.0), we need to divide // the last value by 100, which is a bit overboard for just one chart foreach ($palette as $index => $color) { $components = preg_split('/,/', trim($color)); $components[3] = round($components[3] / 100, 1); $palette[$index] = join(',', $components); } $list['datasets'][0]['label'] = get_lang('Tools'); $list['datasets'][0]['borderColor'] = "rgba(255,255,255,1)"; $i = 0; foreach ($all as $tick => $tock) { $j = $i%count($palette); $list['datasets'][0]['data'][] = $tock; $list['datasets'][0]['backgroundColor'][] = 'rgba('.$palette[$j].')'; $i++; } echo json_encode($list); break; }