Posted By


fearghalmurphy on 04/23/09

Tagged


Statistics


Viewed 276 times
Favorited by 0 user(s)

Moodle Livestats


/ Published in: PHP
Save to your folder(s)

Block - install as normal


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. //*code from http://moodle.org/blocks/HOWTO.html-->
  4.  
  5. class block_livestats extends block_list {
  6. // The init() method does not need to change at all
  7.  
  8. function init() {
  9. $this->title = "Live Statistik";
  10. // $this->title = "Live Stats";
  11. $this->version = 2006150300;
  12. }
  13.  
  14. function preferred_width() {
  15. // The preferred value is in pixels
  16. return 120;
  17. }
  18.  
  19. function get_content() {
  20. if ($this->content !== NULL) {
  21. return $this->content;}
  22.  
  23.  
  24. $date=time() - 3600;
  25. //echo $date.'<br>';
  26.  
  27. global $CFG;
  28.  
  29. $datum = date("d.m.Y",time());
  30. //echo $datum.'<br>';
  31.  
  32. $timestamp = mktime(0,0,0,substr($datum,3,2),substr($datum,0,2),substr($datum,6,4));
  33. //echo $timestamp.'<br>';
  34.  
  35.  
  36. $query='SELECT COUNT( * ) FROM `mdl_log` WHERE `time` > '.$timestamp.' AND `action` = "login"';
  37. $res = mysql_query($query);
  38. list($count) = mysql_fetch_row($res);
  39.  
  40.  
  41. $this->content->items = array();
  42. $this->content->icons = array();
  43. $this->content->footer = "<p>".date("jS F Y") ."</p>";
  44.  
  45. $Users = count_records('user','deleted',0,'confirmed',1);
  46. $Courses = count_records('course','visible',1);
  47.  
  48.  
  49. $this->content->items[] =
  50.  
  51. '<br><table border="0" align="center">
  52. <tr>
  53. <td width="133"> <div align="left">Gesamtzahl Benutzer: </div></td>
  54. <td width="42"><div align="left">' .$Users. '</div></td>
  55. </tr>
  56. <tr>
  57. <td width="133"> <div align="left">Gesamtzahl Kurse: </div></td>
  58. <td><div align="left">'.$Courses.'</div></td>
  59. </tr>
  60. <tr>
  61. <td width="133"> <div align="left">Logins heute: </div></td>
  62. <td><div align="left">'.$count.'</div></td>
  63. </tr>
  64. </table>';
  65.  
  66.  
  67. return $this->content;
  68. }
  69. }
  70.  
  71. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.