logs.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. // This file is part of the Sloodle project (www.sloodle.org)
  3. /**
  4. * Defines a class to render a view of SLOODLE course information.
  5. * Class is inherited from the base view class.
  6. *
  7. * @package sloodle
  8. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  9. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  10. *
  11. * @contributor Peter R. Bloomfield
  12. *
  13. */
  14. /** The base view class */
  15. require_once(SLOODLE_DIRROOT.'/view/base/base_view.php');
  16. /** SLOODLE logs data structure */
  17. require_once(SLOODLE_LIBROOT.'/course.php');
  18. /**
  19. * Class for rendering a view of SLOODLE course information.
  20. * @package sloodle
  21. */
  22. class sloodle_view_logs extends sloodle_base_view
  23. {
  24. /**
  25. * The VLE course object, retrieved directly from database.
  26. * @var object
  27. * @access private
  28. */
  29. var $course = 0;
  30. /**
  31. * SLOODLE course object, retrieved directly from database.
  32. * @var object
  33. * @access private
  34. */
  35. var $sloodle_course = null;
  36. /**
  37. * Constructor.
  38. */
  39. function sloodle_view_logs()
  40. {
  41. }
  42. /**
  43. * Check the request parameters to see which course was specified.
  44. */
  45. function process_request()
  46. {
  47. $id = required_param('id', PARAM_INT);
  48. if (!$this->course = sloodle_get_record('course', 'id', $id)) error('Could not find course.');
  49. $this->sloodle_course = new SloodleCourse();
  50. if (!$this->sloodle_course->load($this->course)) error(get_string('failedcourseload', 'sloodle'));
  51. }
  52. /**
  53. * Check that the user is logged-in and has permission to alter course settings.
  54. */
  55. function check_permission()
  56. {
  57. // Ensure the user logs in
  58. require_login($this->course->id);
  59. if (isguestuser()) error(get_string('noguestaccess', 'sloodle'));
  60. add_to_log($this->course->id, 'course', 'view sloodle data', '', "{$this->course->id}");
  61. // Ensure the user is allowed to update information on this course
  62. $this->course_context = get_context_instance(CONTEXT_COURSE, $this->course->id);
  63. require_capability('moodle/course:update', $this->course_context);
  64. }
  65. /**
  66. * Print the course settings page header.
  67. */
  68. function sloodle_print_header()
  69. {
  70. global $CFG;
  71. $navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/view_logs.php?id={$this->course->id}\">".get_string('logs:view', 'sloodle')."</a>";
  72. sloodle_print_header_simple(get_string('logs:view','sloodle'), "&nbsp;", $navigation, "", "", true, '', navmenu($this->course));
  73. }
  74. /**
  75. * Render the view of the module or feature.
  76. * This MUST be overridden to provide functionality.
  77. */
  78. function render()
  79. {
  80. global $CFG;
  81. global $sloodle;
  82. // Display info about Sloodle course configuration
  83. echo "<h1 style=\"text-align:center;\">".get_string('logs:sloodlelogs','sloodle')."</h1>\n";
  84. // sloodle_print_box(get_string('logs:info','sloodle'), 'generalbox boxaligncenter boxwidthnormal');
  85. $sloodletable = new stdClass();
  86. $sloodletable->head = array(
  87. '<h4><div style="color:red;text-align:left;">'.get_string('avatarname', 'sloodle').'</h4>',
  88. '<h4><div style="color:red;text-align:left;">'.get_string('user').'</h4>',
  89. '<h4><div style="color:green;text-align:left;">'.get_string('action').'</h4>',
  90. '<h4><div style="color:green;text-align:left;">'.get_string('logs:slurl', 'sloodle').'</h4>',
  91. '<h4><div style="color:black;text-align:center;">'.get_string('logs:time', 'sloodle').'</h4>');
  92. //set alignment of table cells
  93. $sloodletable->align = array('left','left','left','left','left');
  94. $sloodletable->width="95%";
  95. //set size of table cells
  96. $sloodletable->size = array('15%','10%', '50%','5%','20%');
  97. $logData = sloodle_get_records('sloodle_logs','course',$this->sloodle_course->get_course_id(), 'timemodified DESC');
  98. if ($logData && count($logData)>0){
  99. foreach ($logData as $ld){
  100. $trowData= Array();
  101. $link_url=' <a href="'.$CFG->wwwroot.'/user/view.php?id='.$ld->userid."&amp;course=";
  102. $link_url.=$this->sloodle_course->get_course_id().'">'.$ld->avname."</a>";
  103. $trowData[]=$link_url;
  104. $userData = sloodle_get_record('user','id',$ld->userid);
  105. $username= $userData->firstname.' '.$userData->lastname;
  106. $trowData[]=$username;
  107. $trowData[]=$ld->action;
  108. $trowData[]='<a href="'.$ld->slurl.'">'.get_string('logs:slurl', 'sloodle').'</a>';
  109. $trowData[]=date("F j, Y, g:i a",$ld->timemodified);
  110. $sloodletable->data[] = $trowData;
  111. }//for
  112. }
  113. else
  114. {
  115. $trowData[]=get_string('logs:nologs', 'sloodle');
  116. $sloodletable->data[] = $trowData;
  117. }
  118. sloodle_print_table($sloodletable);
  119. }
  120. /**
  121. * Print the footer for this course.
  122. */
  123. function sloodle_print_footer()
  124. {
  125. global $CFG;
  126. echo "<p style=\"text-align:center; margin-top:32px; font-size:90%;\"><a href=\"{$CFG->wwwroot}/course/view.php?id={$this->course->id}\">&lt;&lt;&lt; ".get_string('backtocoursepage','sloodle')."</a></h2>";
  127. sloodle_print_footer($this->course);
  128. }
  129. }
  130. ?>