PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/course/report/log/index.php

https://bitbucket.org/ciceidev/cicei_moodle_conditional_activities
PHP | 144 lines | 119 code | 24 blank | 1 comment | 29 complexity | 8799cc910f8f74344674de173206e1c3 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. <?php // $Id$
  2. // Displays different views of the logs.
  3. require_once('../../../config.php');
  4. require_once('../../lib.php');
  5. require_once('lib.php');
  6. require_once($CFG->libdir.'/adminlib.php');
  7. $id = optional_param('id', 0, PARAM_INT);// Course ID
  8. $host_course = optional_param('host_course', '', PARAM_PATH);// Course ID
  9. if (empty($host_course)) {
  10. $hostid = $CFG->mnet_localhost_id;
  11. if (empty($id)) {
  12. $site = get_site();
  13. $id = $site->id;
  14. }
  15. } else {
  16. list($hostid, $id) = explode('/', $host_course);
  17. }
  18. $group = optional_param('group', 0, PARAM_INT); // Group to display
  19. $user = optional_param('user', 0, PARAM_INT); // User to display
  20. $date = optional_param('date', 0, PARAM_FILE); // Date to display - number or some string
  21. $modname = optional_param('modname', '', PARAM_CLEAN); // course_module->id
  22. $modid = optional_param('modid', 0, PARAM_FILE); // number or 'site_errors'
  23. $modaction = optional_param('modaction', '', PARAM_PATH); // an action as recorded in the logs
  24. $page = optional_param('page', '0', PARAM_INT); // which page to show
  25. $perpage = optional_param('perpage', '100', PARAM_INT); // how many per page
  26. $showcourses = optional_param('showcourses', 0, PARAM_INT); // whether to show courses if we're over our limit.
  27. $showusers = optional_param('showusers', 0, PARAM_INT); // whether to show users if we're over our limit.
  28. $chooselog = optional_param('chooselog', 0, PARAM_INT);
  29. $logformat = optional_param('logformat', 'showashtml', PARAM_ALPHA);
  30. if ($hostid == $CFG->mnet_localhost_id) {
  31. if (!$course = get_record('course', 'id', $id) ) {
  32. error('That\'s an invalid course id'.$id);
  33. }
  34. } else {
  35. $course_stub = array_pop(get_records_select('mnet_log', " hostid='$hostid' AND course='$id' ", '', '*', '', '1'));
  36. $course->id = $id;
  37. $course->shortname = $course_stub->coursename;
  38. $course->fullname = $course_stub->coursename;
  39. }
  40. require_login($course);
  41. $context = get_context_instance(CONTEXT_COURSE, $course->id);
  42. require_capability('coursereport/log:view', $context);
  43. add_to_log($course->id, "course", "report log", "report/log/index.php?id=$course->id", $course->id);
  44. $strlogs = get_string('logs');
  45. $stradministration = get_string('administration');
  46. $strreports = get_string('reports');
  47. session_write_close();
  48. $navlinks = array();
  49. if (!empty($chooselog)) {
  50. $userinfo = get_string('allparticipants');
  51. $dateinfo = get_string('alldays');
  52. if ($user) {
  53. if (!$u = get_record('user', 'id', $user) ) {
  54. error('That\'s an invalid user!');
  55. }
  56. $userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context));
  57. }
  58. if ($date) {
  59. $dateinfo = userdate($date, get_string('strftimedaydate'));
  60. }
  61. switch ($logformat) {
  62. case 'showashtml':
  63. if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) {
  64. admin_externalpage_setup('reportlog');
  65. admin_externalpage_print_header();
  66. } else {
  67. $navlinks[] = array('name' => $strreports, 'link' => "$CFG->wwwroot/course/report.php?id=$course->id", 'type' => 'misc');
  68. $navlinks[] = array('name' => $strlogs, 'link' => "index.php?id=$course->id", 'type' => 'misc');
  69. $navlinks[] = array('name' => "$userinfo, $dateinfo", 'link' => null, 'type' => 'misc');
  70. $navigation = build_navigation($navlinks);
  71. print_header($course->shortname .': '. $strlogs, $course->fullname, $navigation);
  72. }
  73. print_heading(format_string($course->fullname) . ": $userinfo, $dateinfo (".usertimezone().")");
  74. print_mnet_log_selector_form($hostid, $course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
  75. if($hostid == $CFG->mnet_localhost_id) {
  76. print_log($course, $user, $date, 'l.time DESC', $page, $perpage,
  77. "index.php?id=$course->id&amp;chooselog=1&amp;user=$user&amp;date=$date&amp;modid=$modid&amp;modaction=$modaction&amp;group=$group",
  78. $modname, $modid, $modaction, $group);
  79. } else {
  80. print_mnet_log($hostid, $id, $user, $date, 'l.time DESC', $page, $perpage, "", $modname, $modid, $modaction, $group);
  81. }
  82. break;
  83. case 'downloadascsv':
  84. if (!print_log_csv($course, $user, $date, 'l.time DESC', $modname,
  85. $modid, $modaction, $group)) {
  86. notify("No logs found!");
  87. print_footer($course);
  88. }
  89. exit;
  90. case 'downloadasods':
  91. if (!print_log_ods($course, $user, $date, 'l.time DESC', $modname,
  92. $modid, $modaction, $group)) {
  93. notify("No logs found!");
  94. print_footer($course);
  95. }
  96. exit;
  97. case 'downloadasexcel':
  98. if (!print_log_xls($course, $user, $date, 'l.time DESC', $modname,
  99. $modid, $modaction, $group)) {
  100. notify("No logs found!");
  101. print_footer($course);
  102. }
  103. exit;
  104. }
  105. } else {
  106. if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) {
  107. admin_externalpage_setup('reportlog');
  108. admin_externalpage_print_header();
  109. } else {
  110. $navlinks[] = array('name' => $strreports, 'link' => "$CFG->wwwroot/course/report.php?id=$course->id", 'type' => 'misc');
  111. $navlinks[] = array('name' => $strlogs, 'link' => null, 'type' => 'misc');
  112. $navigation = build_navigation($navlinks);
  113. print_header($course->shortname .': '. $strlogs, $course->fullname, $navigation, '');
  114. }
  115. print_heading(get_string('chooselogs') .':');
  116. print_log_selector_form($course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
  117. }
  118. print_footer($course);
  119. exit;
  120. ?>