block_myprofile.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Block displaying information about current logged-in user.
  18. *
  19. * This block can be used as anti cheating measure, you
  20. * can easily check the logged-in user matches the person
  21. * operating the computer.
  22. *
  23. * @package block_myprofile
  24. * @copyright 2010 Remote-Learner.net
  25. * @author Olav Jordan <olav.jordan@remote-learner.ca>
  26. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27. */
  28. defined('MOODLE_INTERNAL') || die();
  29. /**
  30. * Displays the current user's profile information.
  31. *
  32. * @copyright 2010 Remote-Learner.net
  33. * @author Olav Jordan <olav.jordan@remote-learner.ca>
  34. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35. */
  36. class block_myprofile extends block_base {
  37. /**
  38. * block initializations
  39. */
  40. public function init() {
  41. $this->title = get_string('pluginname', 'block_myprofile');
  42. }
  43. /**
  44. * block contents
  45. *
  46. * @return object
  47. */
  48. public function get_content() {
  49. global $CFG, $USER, $DB, $OUTPUT, $PAGE;
  50. if ($this->content !== NULL) {
  51. return $this->content;
  52. }
  53. if (!isloggedin() or isguestuser()) {
  54. return ''; // Never useful unless you are logged in as real users
  55. }
  56. $this->content = new stdClass;
  57. $this->content->text = '';
  58. $this->content->footer = '';
  59. $course = $this->page->course;
  60. if (!isset($this->config->display_picture) || $this->config->display_picture == 1) {
  61. $this->content->text .= '<div class="myprofileitem picture">';
  62. $this->content->text .= $OUTPUT->user_picture($USER, array('courseid'=>$course->id, 'size'=>'100', 'class'=>'profilepicture')); // The new class makes CSS easier
  63. $this->content->text .= '</div>';
  64. }
  65. $this->content->text .= '<div class="myprofileitem fullname">'.fullname($USER).'</div>';
  66. if(!isset($this->config->display_country) || $this->config->display_country == 1) {
  67. $countries = get_string_manager()->get_list_of_countries();
  68. if (isset($countries[$USER->country])) {
  69. $this->content->text .= '<div class="myprofileitem country">';
  70. $this->content->text .= get_string('country') . ': ' . $countries[$USER->country];
  71. $this->content->text .= '</div>';
  72. }
  73. }
  74. if(!isset($this->config->display_city) || $this->config->display_city == 1) {
  75. $this->content->text .= '<div class="myprofileitem city">';
  76. $this->content->text .= get_string('city') . ': ' . format_string($USER->city);
  77. $this->content->text .= '</div>';
  78. }
  79. if(!isset($this->config->display_email) || $this->config->display_email == 1) {
  80. $this->content->text .= '<div class="myprofileitem email">';
  81. $this->content->text .= obfuscate_mailto($USER->email, '');
  82. $this->content->text .= '</div>';
  83. }
  84. if(!empty($this->config->display_icq) && !empty($USER->icq)) {
  85. $this->content->text .= '<div class="myprofileitem icq">';
  86. $this->content->text .= 'ICQ: ' . s($USER->icq);
  87. $this->content->text .= '</div>';
  88. }
  89. if(!empty($this->config->display_skype) && !empty($USER->skype)) {
  90. $this->content->text .= '<div class="myprofileitem skype">';
  91. $this->content->text .= 'Skype: ' . s($USER->skype);
  92. $this->content->text .= '</div>';
  93. }
  94. if(!empty($this->config->display_yahoo) && !empty($USER->yahoo)) {
  95. $this->content->text .= '<div class="myprofileitem yahoo">';
  96. $this->content->text .= 'Yahoo: ' . s($USER->yahoo);
  97. $this->content->text .= '</div>';
  98. }
  99. if(!empty($this->config->display_aim) && !empty($USER->aim)) {
  100. $this->content->text .= '<div class="myprofileitem aim">';
  101. $this->content->text .= 'AIM: ' . s($USER->aim);
  102. $this->content->text .= '</div>';
  103. }
  104. if(!empty($this->config->display_msn) && !empty($USER->msn)) {
  105. $this->content->text .= '<div class="myprofileitem msn">';
  106. $this->content->text .= 'MSN: ' . s($USER->msn);
  107. $this->content->text .= '</div>';
  108. }
  109. if(!empty($this->config->display_phone1) && !empty($USER->phone1)) {
  110. $this->content->text .= '<div class="myprofileitem phone1">';
  111. $this->content->text .= get_string('phone1').': ' . s($USER->phone1);
  112. $this->content->text .= '</div>';
  113. }
  114. if(!empty($this->config->display_phone2) && !empty($USER->phone2)) {
  115. $this->content->text .= '<div class="myprofileitem phone2">';
  116. $this->content->text .= get_string('phone2').': ' . s($USER->phone2);
  117. $this->content->text .= '</div>';
  118. }
  119. if(!empty($this->config->display_institution) && !empty($USER->institution)) {
  120. $this->content->text .= '<div class="myprofileitem institution">';
  121. $this->content->text .= format_string($USER->institution);
  122. $this->content->text .= '</div>';
  123. }
  124. if(!empty($this->config->display_address) && !empty($USER->address)) {
  125. $this->content->text .= '<div class="myprofileitem address">';
  126. $this->content->text .= format_string($USER->address);
  127. $this->content->text .= '</div>';
  128. }
  129. if(!empty($this->config->display_firstaccess) && !empty($USER->firstaccess)) {
  130. $this->content->text .= '<div class="myprofileitem firstaccess">';
  131. $this->content->text .= get_string('firstaccess').': ' . userdate($USER->firstaccess);
  132. $this->content->text .= '</div>';
  133. }
  134. if(!empty($this->config->display_lastaccess) && !empty($USER->lastaccess)) {
  135. $this->content->text .= '<div class="myprofileitem lastaccess">';
  136. $this->content->text .= get_string('lastaccess').': ' . userdate($USER->lastaccess);
  137. $this->content->text .= '</div>';
  138. }
  139. if(!empty($this->config->display_currentlogin) && !empty($USER->currentlogin)) {
  140. $this->content->text .= '<div class="myprofileitem currentlogin">';
  141. $this->content->text .= get_string('login').': ' . userdate($USER->currentlogin);
  142. $this->content->text .= '</div>';
  143. }
  144. if(!empty($this->config->display_lastip) && !empty($USER->lastip)) {
  145. $this->content->text .= '<div class="myprofileitem lastip">';
  146. $this->content->text .= 'IP: ' . $USER->lastip;
  147. $this->content->text .= '</div>';
  148. }
  149. return $this->content;
  150. }
  151. /**
  152. * allow the block to have a configuration page
  153. *
  154. * @return boolean
  155. */
  156. public function has_config() {
  157. return false;
  158. }
  159. /**
  160. * allow more than one instance of the block on a page
  161. *
  162. * @return boolean
  163. */
  164. public function instance_allow_multiple() {
  165. //allow more than one instance on a page
  166. return false;
  167. }
  168. /**
  169. * allow instances to have their own configuration
  170. *
  171. * @return boolean
  172. */
  173. function instance_allow_config() {
  174. //allow instances to have their own configuration
  175. return false;
  176. }
  177. /**
  178. * instance specialisations (must have instance allow config true)
  179. *
  180. */
  181. public function specialization() {
  182. }
  183. /**
  184. * locations where block can be displayed
  185. *
  186. * @return array
  187. */
  188. public function applicable_formats() {
  189. return array('all'=>true);
  190. }
  191. /**
  192. * post install configurations
  193. *
  194. */
  195. public function after_install() {
  196. }
  197. /**
  198. * post delete configurations
  199. *
  200. */
  201. public function before_delete() {
  202. }
  203. }