Révision 31412baa
implement online_users graph
| plugins/moodle/moodle_users_online.php | ||
|---|---|---|
| 21 | 21 |
* @version 1.0 2014 |
| 22 | 22 |
* |
| 23 | 23 |
*/ |
| 24 |
$dbh = null; |
|
| 24 | 25 |
$db = getenv('db');
|
| 25 | 26 |
$type = getenv('type');
|
| 26 | 27 |
$host = getenv('host');
|
| 27 | 28 |
$user = getenv('user');
|
| 28 | 29 |
$pass = getenv('pass');
|
| 30 |
$table_prefix = getenv('table_prefix');
|
|
| 29 | 31 |
$port = getenv('port');
|
| 30 | 32 |
if (!$port) |
| 31 |
$port = 3306; |
|
| 33 |
$port = 3306; |
|
| 34 |
//$graph_period = getenv('graph_period');
|
|
| 35 |
$graph_period = time() - 5*60; |
|
| 36 |
|
|
| 37 |
|
|
| 38 |
if (count($argv) === 2 && $argv[1] === 'config') {
|
|
| 39 |
echo "graph_title Moodle Online Users\n"; |
|
| 40 |
echo "graph_args --base 1000 --lower-limit 0\n"; |
|
| 41 |
echo "graph_vlabel users\n"; |
|
| 42 |
echo "graph_category Moodle\n"; |
|
| 43 |
echo "graph_scale no\n"; |
|
| 44 |
echo "graph_info Displays the sum of online users in your Moodle site\n"; |
|
| 45 |
echo "users_online.label online users\n"; |
|
| 46 |
echo "users_online.min 0\n"; |
|
| 47 |
exit(0); |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
try {
|
|
| 51 |
$dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; |
|
| 52 |
$dbh = new PDO($dsn, $user, $pass); |
|
| 53 |
} catch (Exception $e) {
|
|
| 54 |
echo "Connection failed\n"; |
|
| 55 |
exit(1); |
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
//Online users |
|
| 59 |
$nbusers = 0; |
|
| 60 |
if (($stmt = $dbh->query("SELECT count(id) AS users FROM {$table_prefix}user WHERE lastaccess > $graph_period")) != false) {
|
|
| 61 |
$nbusers = $stmt->fetchColumn(); |
|
| 62 |
} |
|
| 63 |
echo "users_online.value $nbusers\n"; |
|
Formats disponibles : Unified diff