block_sloodle_menu.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * Defines the Sloodle menu block class.
  4. *
  5. * @package sloodle
  6. * @contributor Peter R. Bloomfield
  7. */
  8. /** Include the current Sloodle configuration, if possible. */
  9. @include_once($CFG->dirroot .'/mod/sloodle/sl_config.php');
  10. if (defined('SLOODLE_LIBROOT')) {
  11. /** Inlcude the current general Sloodle functionality. */
  12. require_once(SLOODLE_LIBROOT.'/general.php');
  13. /** Include the Sloodle course functionality. */
  14. require_once(SLOODLE_LIBROOT.'/course.php');
  15. }
  16. /** Include the old Sloodle configuration, in case the module is out-dated. */
  17. if (!defined('SLOODLE_VERSION')) {
  18. @include_once($CFG->dirroot .'/mod/sloodle/config.php');
  19. if (defined('SLOODLE_DIRROOT')) {
  20. /** Include the old general Sloodle functionality. */
  21. require_once(SLOODLE_DIRROOT.'/lib/sl_generallib.php');
  22. }
  23. }
  24. /** Define the Sloodle Menu Block version. */
  25. define('SLOODLE_MENU_VERSION', 2.0);
  26. /**
  27. * Defines the block class.
  28. * @package sloodle
  29. */
  30. class block_sloodle_menu extends block_base {
  31. /**
  32. * Perform block initialisation.
  33. * @return void
  34. */
  35. function init() {
  36. global $CFG;
  37. $this->title = get_string('blockname', 'block_sloodle_menu');
  38. $this->content_type = BLOCK_TYPE_TEXT;
  39. $this->version = 2010110311;
  40. }
  41. /**
  42. * Indicates whether or not this module has a global configuration page.
  43. * @return bool True if there is a global configuration page, or false otherwise.
  44. */
  45. function has_config() {
  46. return false;
  47. }
  48. /**
  49. * Indicates whether or not to hide the header of this block.
  50. * @return bool True to hide the header, or false to show it.
  51. */
  52. function hide_header() {
  53. return false;
  54. }
  55. /**
  56. * Defines *and* returns the content of this block.
  57. * @return object
  58. */
  59. function get_content() {
  60. global $CFG, $COURSE, $USER;
  61. // Construct the content
  62. $this->content = new stdClass;
  63. $this->content->text = '';
  64. $this->content->footer = '';
  65. // If no course has been specified, then we are using the site course
  66. if (!isset($COURSE)) {
  67. $COURSE = get_site();
  68. }
  69. // If the user is not logged in or if they are using guest access, then we can't show anything
  70. if (!isloggedin() || isguestuser()) {
  71. return $this->content;
  72. }
  73. // Get the context instance for this course
  74. $course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
  75. // This version of the menu isn't compatible with older version of the Sloodle module
  76. if (defined('SLOODLE_VERSION') && SLOODLE_VERSION < 0.4) {
  77. $this->content->text = get_string('oldmodule', 'block_sloodle_menu');
  78. return $this->content;
  79. }
  80. // Has the Sloodle activity module been installed?
  81. if (!(function_exists("sloodle_is_installed") && sloodle_is_installed())) {
  82. $this->content->text = get_string('sloodlenotinstalled', 'block_sloodle_menu');
  83. return $this->content;
  84. }
  85. // Get the Sloodle course data
  86. $sloodle_course = new SloodleCourse();
  87. if (!$sloodle_course->load((int)$COURSE->id)) {
  88. $this->content->text = get_string('failedloadcourse', 'block_sloodle_menu');
  89. return $this->content;
  90. }
  91. // Add the Sloodle and Sloodle Menu version info to the footer of the block
  92. $this->content->footer = '<span style="color:#565656;font-style:italic; font-size:10pt;">'.get_string('sloodlemenuversion', 'block_sloodle_menu').': '.(string)SLOODLE_MENU_VERSION.'</span>';
  93. $this->content->footer .= '<br/><span style="color:#888888;font-style:italic;font-size:8pt;">'.get_string('sloodleversion', 'block_sloodle_menu').': '.(string)SLOODLE_VERSION.'</span>';
  94. // Attempt to find a Sloodle user for the Moodle user
  95. $dbquery = " SELECT * FROM {$CFG->prefix}sloodle_users
  96. WHERE userid = ? AND NOT (avname = '' AND uuid = '')
  97. ";
  98. $dbresult = sloodle_get_records_sql_params($dbquery, array($USER->id));
  99. $sl_avatar_name = "";
  100. if (!is_array($dbresult) || count($dbresult) == 0) $userresult = FALSE;
  101. else if (count($dbresult) > 1) $userresult = "Multiple avatars associated with your Moodle account.";
  102. else {
  103. $userresult = TRUE;
  104. reset($dbresult);
  105. $cur = current($dbresult);
  106. $sl_avatar_name = $cur->avname;
  107. }
  108. if ($userresult === TRUE) {
  109. // Success
  110. // Make sure there was a name
  111. if (empty($sl_avatar_name)) $sl_avatar_name = '('.get_string('nameunknown', 'block_sloodle_menu').')';
  112. $this->content->text .= '<center><span style="font-size:10pt;font-style:italic;color:#777777;">'.get_string('youravatar', 'block_sloodle_menu').':</span><br/>';
  113. // Make the avatar name a link if the user management page exists
  114. $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=user&amp;id={$USER->id}&amp;course={$COURSE->id}\">$sl_avatar_name</a>";
  115. $this->content->text .= '<br/></center>';
  116. } else if (is_string($userresult)) {
  117. // An error occurred
  118. $this->content->text .= '<center><span style="font-size:10pt;font-style:italic;color:#777777;">'.get_string('youravatar', 'block_sloodle_menu').':</span><br/>ERROR ('.$userresult.')</center>';
  119. } else {
  120. // No avatar linked yet
  121. $this->content->text .= '<center><span style="font-style:italic;">('.get_string('noavatar', 'block_sloodle_menu').')</span></center>';
  122. }
  123. // Add links to common Sloodle stuff
  124. $this->content->text .= '<div style="padding:1px; margin-top:4px; margin-bottom:4px; border-top:solid 1px #cccccc; border-bottom:solid 1px #cccccc;">';
  125. // Add the Sloodle profile link
  126. $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/user.gif\" width=\"16\" height=\"16\"/> ";
  127. $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=user&amp;id={$USER->id}&amp;course={$COURSE->id}\">".get_string('mysloodleprofile', 'block_sloodle_menu')."</a><br/>";
  128. // Show a link to all Sloodle activities on this course
  129. //TODO: possibly show number of visible Sloodle activities?
  130. $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/boxes.gif\" width=\"16\" height=\"16\"/> ";
  131. $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/index.php?id={$COURSE->id}\">".get_string('sloodleactivities', 'block_sloodle_menu')."</a><br/>";
  132. // Do we have LoginZone data for this course?
  133. if ($sloodle_course->has_loginzone_data()) {
  134. // Show a link to the LoginZone for this course
  135. $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/loginzone.gif\" width=\"16\" height=\"16\"/> ";
  136. $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/classroom/loginzone.php?id={$COURSE->id}\">".get_string('courseloginzone', 'block_sloodle_menu')."</a><br/>";
  137. }
  138. //$this->content->text .= '<hr>';
  139. // Add a link for avatars list
  140. $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/user_mng.gif\" width=\"16\" height=\"16\"/> ";
  141. $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=users&amp;course={$COURSE->id}\">".get_string('avatars', 'block_sloodle_menu')."</a><br/>";
  142. // Add a link to Sloodle course settings, if the user can update the course
  143. if (has_capability('moodle/course:update', $course_context)) {
  144. $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/page.gif\" width=\"16\" height=\"16\"/> ";
  145. $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=course&amp;id={$COURSE->id}\">".get_string('editcourse', 'block_sloodle_menu')."</a><br>\n";
  146. }
  147. // Add a link to Sloodle logs, if the user can update the course
  148. //if (has_capability('moodle/course:update', $course_context)) {
  149. //$this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/notes.gif\" width=\"16\" height=\"16\"/> ";
  150. //$this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=logs&id={$COURSE->id}\">".get_string('logs:view', 'sloodle')."</a><br>\n";
  151. //}
  152. // Add a link to Sloodle Backpack
  153. $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/coin.png\" width=\"16\" height=\"16\"/> ";
  154. $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=backpack&id={$COURSE->id}\">".get_string('backpack:view', 'sloodle')."</a><br>\n";
  155. // Add a module configuration link if the user has authority to administer the module
  156. if (has_capability('moodle/site:config', $course_context)) {
  157. // The address of the configuration page depends on our version of Moodle
  158. if ($CFG->version < 2007101500) {
  159. // < 1.9
  160. $address = "/admin/module.php?module=sloodle";
  161. } else {
  162. // >= 1.9
  163. $address = "/admin/settings.php?section=modsettingsloodle";
  164. }
  165. $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/configure.gif\" width=\"16\" height=\"16\"/> ";
  166. $this->content->text .= "<a href=\"{$CFG->wwwroot}$address\">".get_string('sloodleconfig', 'block_sloodle_menu')."</a><br/>";
  167. }
  168. $this->content->text .= '</div>';
  169. return $this->content;
  170. }
  171. }
  172. ?>