MDL-51427 user: correctly use strings for phone1 and phone2
[moodle.git] / blocks / myprofile / block_myprofile.php
CommitLineData
03d9401e 1<?php
03d9401e
MD
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/**
0ab727fb
PS
18 * Block displaying information about current logged-in user.
19 *
20 * This block can be used as anti cheating measure, you
21 * can easily check the logged-in user matches the person
22 * operating the computer.
03d9401e 23 *
f25a6839 24 * @package block_myprofile
03d9401e
MD
25 * @copyright 2010 Remote-Learner.net
26 * @author Olav Jordan <olav.jordan@remote-learner.ca>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 */
29
0ab727fb
PS
30defined('MOODLE_INTERNAL') || die();
31
03d9401e 32/**
0ab727fb 33 * Displays the current user's profile information.
03d9401e
MD
34 *
35 * @copyright 2010 Remote-Learner.net
36 * @author Olav Jordan <olav.jordan@remote-learner.ca>
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 */
39class block_myprofile extends block_base {
40 /**
41 * block initializations
42 */
43 public function init() {
44 $this->title = get_string('pluginname', 'block_myprofile');
03d9401e
MD
45 }
46
47 /**
48 * block contents
49 *
50 * @return object
51 */
52 public function get_content() {
53 global $CFG, $USER, $DB, $OUTPUT, $PAGE;
54
55 if ($this->content !== NULL) {
56 return $this->content;
57 }
58
0ab727fb
PS
59 if (!isloggedin() or isguestuser()) {
60 return ''; // Never useful unless you are logged in as real users
03d9401e
MD
61 }
62
63 $this->content = new stdClass;
64 $this->content->text = '';
65 $this->content->footer = '';
66
67 $course = $this->page->course;
03d9401e
MD
68
69 if (!isset($this->config->display_picture) || $this->config->display_picture == 1) {
70 $this->content->text .= '<div class="myprofileitem picture">';
0ab727fb 71 $this->content->text .= $OUTPUT->user_picture($USER, array('courseid'=>$course->id, 'size'=>'100', 'class'=>'profilepicture')); // The new class makes CSS easier
03d9401e
MD
72 $this->content->text .= '</div>';
73 }
74
0ab727fb 75 $this->content->text .= '<div class="myprofileitem fullname">'.fullname($USER).'</div>';
03d9401e
MD
76
77 if(!isset($this->config->display_country) || $this->config->display_country == 1) {
78 $countries = get_string_manager()->get_list_of_countries();
0ab727fb 79 if (isset($countries[$USER->country])) {
db9a1414 80 $this->content->text .= '<div class="myprofileitem country">';
0ab727fb 81 $this->content->text .= get_string('country') . ': ' . $countries[$USER->country];
db9a1414
DM
82 $this->content->text .= '</div>';
83 }
03d9401e
MD
84 }
85
86 if(!isset($this->config->display_city) || $this->config->display_city == 1) {
87 $this->content->text .= '<div class="myprofileitem city">';
0ab727fb 88 $this->content->text .= get_string('city') . ': ' . format_string($USER->city);
03d9401e
MD
89 $this->content->text .= '</div>';
90 }
91
92 if(!isset($this->config->display_email) || $this->config->display_email == 1) {
93 $this->content->text .= '<div class="myprofileitem email">';
0ab727fb 94 $this->content->text .= obfuscate_mailto($USER->email, '');
03d9401e
MD
95 $this->content->text .= '</div>';
96 }
97
0ab727fb 98 if(!empty($this->config->display_icq) && !empty($USER->icq)) {
03d9401e 99 $this->content->text .= '<div class="myprofileitem icq">';
0ab727fb 100 $this->content->text .= 'ICQ: ' . s($USER->icq);
03d9401e
MD
101 $this->content->text .= '</div>';
102 }
103
0ab727fb 104 if(!empty($this->config->display_skype) && !empty($USER->skype)) {
03d9401e 105 $this->content->text .= '<div class="myprofileitem skype">';
0ab727fb 106 $this->content->text .= 'Skype: ' . s($USER->skype);
03d9401e
MD
107 $this->content->text .= '</div>';
108 }
109
0ab727fb 110 if(!empty($this->config->display_yahoo) && !empty($USER->yahoo)) {
03d9401e 111 $this->content->text .= '<div class="myprofileitem yahoo">';
0ab727fb 112 $this->content->text .= 'Yahoo: ' . s($USER->yahoo);
03d9401e
MD
113 $this->content->text .= '</div>';
114 }
115
0ab727fb 116 if(!empty($this->config->display_aim) && !empty($USER->aim)) {
03d9401e 117 $this->content->text .= '<div class="myprofileitem aim">';
0ab727fb 118 $this->content->text .= 'AIM: ' . s($USER->aim);
03d9401e
MD
119 $this->content->text .= '</div>';
120 }
121
0ab727fb 122 if(!empty($this->config->display_msn) && !empty($USER->msn)) {
03d9401e 123 $this->content->text .= '<div class="myprofileitem msn">';
0ab727fb 124 $this->content->text .= 'MSN: ' . s($USER->msn);
03d9401e
MD
125 $this->content->text .= '</div>';
126 }
127
0ab727fb 128 if(!empty($this->config->display_phone1) && !empty($USER->phone1)) {
03d9401e 129 $this->content->text .= '<div class="myprofileitem phone1">';
70fb46c8 130 $this->content->text .= get_string('phone1').': ' . s($USER->phone1);
03d9401e
MD
131 $this->content->text .= '</div>';
132 }
133
0ab727fb 134 if(!empty($this->config->display_phone2) && !empty($USER->phone2)) {
03d9401e 135 $this->content->text .= '<div class="myprofileitem phone2">';
70fb46c8 136 $this->content->text .= get_string('phone2').': ' . s($USER->phone2);
03d9401e
MD
137 $this->content->text .= '</div>';
138 }
139
0ab727fb 140 if(!empty($this->config->display_institution) && !empty($USER->institution)) {
03d9401e 141 $this->content->text .= '<div class="myprofileitem institution">';
0ab727fb 142 $this->content->text .= format_string($USER->institution);
03d9401e
MD
143 $this->content->text .= '</div>';
144 }
145
0ab727fb 146 if(!empty($this->config->display_address) && !empty($USER->address)) {
03d9401e 147 $this->content->text .= '<div class="myprofileitem address">';
0ab727fb 148 $this->content->text .= format_string($USER->address);
03d9401e
MD
149 $this->content->text .= '</div>';
150 }
151
0ab727fb 152 if(!empty($this->config->display_firstaccess) && !empty($USER->firstaccess)) {
03d9401e 153 $this->content->text .= '<div class="myprofileitem firstaccess">';
0ab727fb 154 $this->content->text .= get_string('firstaccess').': ' . userdate($USER->firstaccess);
03d9401e
MD
155 $this->content->text .= '</div>';
156 }
157
0ab727fb 158 if(!empty($this->config->display_lastaccess) && !empty($USER->lastaccess)) {
03d9401e 159 $this->content->text .= '<div class="myprofileitem lastaccess">';
0ab727fb 160 $this->content->text .= get_string('lastaccess').': ' . userdate($USER->lastaccess);
03d9401e
MD
161 $this->content->text .= '</div>';
162 }
163
0ab727fb 164 if(!empty($this->config->display_currentlogin) && !empty($USER->currentlogin)) {
03d9401e 165 $this->content->text .= '<div class="myprofileitem currentlogin">';
0ab727fb 166 $this->content->text .= get_string('login').': ' . userdate($USER->currentlogin);
03d9401e
MD
167 $this->content->text .= '</div>';
168 }
169
0ab727fb 170 if(!empty($this->config->display_lastip) && !empty($USER->lastip)) {
03d9401e 171 $this->content->text .= '<div class="myprofileitem lastip">';
0ab727fb 172 $this->content->text .= 'IP: ' . $USER->lastip;
03d9401e
MD
173 $this->content->text .= '</div>';
174 }
175
03d9401e
MD
176 return $this->content;
177 }
178
179 /**
180 * allow the block to have a configuration page
181 *
182 * @return boolean
183 */
184 public function has_config() {
185 return false;
186 }
187
188 /**
189 * allow more than one instance of the block on a page
190 *
191 * @return boolean
192 */
193 public function instance_allow_multiple() {
194 //allow more than one instance on a page
195 return false;
196 }
197
198 /**
199 * allow instances to have their own configuration
200 *
201 * @return boolean
202 */
203 function instance_allow_config() {
204 //allow instances to have their own configuration
205 return false;
206 }
207
208 /**
209 * instance specialisations (must have instance allow config true)
210 *
211 */
212 public function specialization() {
213 }
214
03d9401e
MD
215 /**
216 * locations where block can be displayed
217 *
218 * @return array
219 */
220 public function applicable_formats() {
221 return array('all'=>true);
222 }
223
224 /**
225 * post install configurations
226 *
227 */
228 public function after_install() {
229 }
230
231 /**
232 * post delete configurations
233 *
234 */
235 public function before_delete() {
236 }
237
238}