|
| 1 | +<?php |
| 2 | + |
| 3 | +class block_login_logout extends block_base { |
| 4 | + public function init() { |
| 5 | + $this->title = get_string('pluginname', 'block_login_logout'); |
| 6 | + } |
| 7 | + |
| 8 | + public function applicable_formats() { |
| 9 | + return array('all' => true); |
| 10 | + } |
| 11 | + |
| 12 | + public function specialization() { |
| 13 | + if (!isloggedin() or isguestuser()) { |
| 14 | + $this->title = get_string('login'); |
| 15 | + } else { |
| 16 | + $utz = timezone_offset_get(); //get_user_timezone_offset(); |
| 17 | + if ($utz == 99) { |
| 18 | + $ut = (date('G')*3600 + date('i')*60 + date('s'))/3600; |
| 19 | + } else { |
| 20 | + $ut = ((gmdate('G') + timezone_offset_get() /*get_user_timezone_offset()*/ )*3600 + gmdate('i')*60 + gmdate('s'))/3600; |
| 21 | + If ($ut <= 0) { $ut = 24 + $ut; } |
| 22 | + If ($ut > 24) { $ut = $ut - 24; } |
| 23 | + } |
| 24 | + if ($ut < 12) { |
| 25 | + $this->title = get_string('morning_greeting', 'block_login_logout'); |
| 26 | + } elseif (($ut >=12 ) and ($ut < 19 )) { |
| 27 | + $this->title = get_string('afternoon_greeting', 'block_login_logout'); |
| 28 | + } else { |
| 29 | + $this->title = get_string('night_greeting', 'block_login_logout'); |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + public function get_content () { |
| 35 | + global $USER, $CFG, $OUTPUT, $SESSION, $COURSE; |
| 36 | + $wwwroot = ''; |
| 37 | + $signup = ''; |
| 38 | + |
| 39 | + if ($this->content !== NULL) { |
| 40 | + return $this->content; |
| 41 | + } |
| 42 | + |
| 43 | + if (empty($CFG->loginhttps)) { |
| 44 | + $wwwroot = $CFG->wwwroot; |
| 45 | + } else { |
| 46 | + $wwwroot = str_replace("http://", "https://", $CFG->wwwroot); |
| 47 | + } |
| 48 | + |
| 49 | + if (!empty($CFG->registerauth)) { |
| 50 | + $authplugin = get_auth_plugin($CFG->registerauth); |
| 51 | + if ($authplugin->can_signup()) { |
| 52 | + $signup = $wwwroot . '/login/signup.php'; |
| 53 | + } |
| 54 | + } |
| 55 | + $forgot = $wwwroot . '/login/forgot_password.php'; |
| 56 | + |
| 57 | + $username = get_moodle_cookie(); |
| 58 | + |
| 59 | + $this->content->footer = ''; |
| 60 | + $this->content->text = ''; |
| 61 | + |
| 62 | + if (!isloggedin() or isguestuser()) { |
| 63 | + |
| 64 | + $this->content->text .= html_writer::start_tag('form', array('class'=>'loginform', 'id'=>'login', 'method'=>'post', 'action'=>get_login_url())); |
| 65 | + $this->content->text .= html_writer::start_tag('div', array('class'=>'c1 fld username')); |
| 66 | + $this->content->text .= html_writer::tag('label', get_string('username'), array('for'=>'login_username')); |
| 67 | + $this->content->text .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>'username', 'id'=>'login_username', 'value'=>s($username))); |
| 68 | + $this->content->text .= html_writer::end_tag('div'); |
| 69 | + $this->content->text .= html_writer::start_tag('div', array('class'=>'c1 fld password')); |
| 70 | + $this->content->text .= html_writer::tag('label', get_string('password'), array('for'=>'login_password')); |
| 71 | + |
| 72 | + if (!empty($CFG->loginpasswordautocomplete)) { |
| 73 | + $this->content->text .= html_writer::empty_tag('input', array('type'=>'password', 'name'=>'password', 'id'=>'login_password', 'value'=>'', 'autocomplete'=>'off')); |
| 74 | + } else { |
| 75 | + $this->content->text .= html_writer::empty_tag('input', array('type'=>'password', 'name'=>'password', 'id'=>'login_password', 'value'=>'')); |
| 76 | + } |
| 77 | + |
| 78 | + $this->content->text .= html_writer::end_tag('div'); |
| 79 | + |
| 80 | + if (isset($CFG->rememberusername) and $CFG->rememberusername == 2) { |
| 81 | + $this->content->text .= html_writer::start_tag('div', array('class'=>'c1 rememberusername')); |
| 82 | + if ($username) { |
| 83 | + $this->content->text .= html_writer::empty_tag('input', array('type'=>'checkbox', 'name'=>'rememberusername', 'id'=>'rememberusername', 'value'=>'1', 'checked'=>'checked')); |
| 84 | + } else { |
| 85 | + $this->content->text .= html_writer::empty_tag('input', array('type'=>'checkbox', 'name'=>'rememberusername', 'id'=>'rememberusername', 'value'=>'1')); |
| 86 | + } |
| 87 | + $label_rememberusername = ' '.get_string('rememberusername', 'admin'); |
| 88 | + $this->content->text .= html_writer::tag('label', $label_rememberusername, array('for'=>'rememberusername')); |
| 89 | + $this->content->text .= html_writer::end_tag('div'); |
| 90 | + } |
| 91 | + |
| 92 | + $this->content->text .= html_writer::start_tag('div', array('class'=>'c1 btn')); |
| 93 | + $this->content->text .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('login'))); |
| 94 | + $this->content->text .= html_writer::end_tag('div'); |
| 95 | + $this->content->text .= html_writer::end_tag('form'); |
| 96 | + |
| 97 | + if (!empty($signup)) { |
| 98 | + $this->content->footer .= html_writer::start_tag('div'); |
| 99 | + $this->content->footer .= html_writer::link(new moodle_url($signup), get_string('startsignup')); |
| 100 | + $this->content->footer .= html_writer::end_tag('div'); |
| 101 | + } |
| 102 | + if (!empty($forgot)) { |
| 103 | + $this->content->footer .= html_writer::start_tag('div'); |
| 104 | + $this->content->footer .= html_writer::link(new moodle_url($forgot), get_string('forgotaccount')); |
| 105 | + $this->content->footer .= html_writer::end_tag('div'); |
| 106 | + } |
| 107 | + |
| 108 | + } else { |
| 109 | + |
| 110 | + $this->content->text .= html_writer::start_tag('div', array('class'=>'logoutusername')); |
| 111 | + $this->content->text .= html_writer::link(new moodle_url('/user/profile.php', array('id'=>$USER->id)), fullname($USER)); |
| 112 | + $this->content->text .= html_writer::end_tag('div'); |
| 113 | + $this->content->text .= html_writer::tag('div', $OUTPUT->user_picture($USER, array('size'=>90, 'class'=>'profilepicture')), array('class'=>'logoutuserimg')); |
| 114 | + $this->content->text .= html_writer::start_tag('div', array('class'=>'logoutbtn')); |
| 115 | + $this->content->text .= html_writer::link(new moodle_url('/login/logout.php', array('sesskey'=>sesskey())), html_writer::tag('button', get_string('logout'), array('type'=>'button'))); |
| 116 | + $this->content->text .= html_writer::end_tag('div'); |
| 117 | + $this->content->text .= html_writer::start_tag('div', array('class'=>'logoutfooter')); |
| 118 | + $this->content->text .= html_writer::link(new moodle_url('/user/editadvanced.php', array('id'=>$USER->id)), get_string('updatemyprofile')); |
| 119 | + $this->content->text .= html_writer::end_tag('div'); |
| 120 | + if($USER->lastlogin){ |
| 121 | + $logout_footer = get_string('lastlogin').'<br>'.userdate($USER->lastlogin, get_string('strftimerecentfull')).'<br> ('.format_time(time() - $USER->lastlogin).')'; |
| 122 | + $this->content->text .= html_writer::tag('div', $logout_footer, array('class'=>'logoutfooter')); |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + return $this->content; |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | + |
0 commit comments