MDL-17773 new get_login_url() function - fixes missing httpslogin tweaks
authorskodak <skodak>
Fri, 2 Jan 2009 22:56:48 +0000 (22:56 +0000)
committerskodak <skodak>
Fri, 2 Jan 2009 22:56:48 +0000 (22:56 +0000)
36 files changed:
admin/settings/users.php
backup/backup.php
backup/backup_check.html
backup/backup_execute.html
backup/backup_form.html
backup/restore.php
backup/restore_check.html
backup/restore_execute.html
backup/restore_form.html
backup/restore_precheck.html
blocks/login/block_login.php
blocks/tags/block_tags.php
course/enrol.php
enrol/manual/enrol.html
lib/moodlelib.php
lib/sessionlib.php
lib/weblib.php
login/change_password.php
login/forgot_password.php
login/signup.php
message/edit.php
mod/chat/view.php
mod/choice/view.php
mod/forum/markposts.php
mod/forum/post.php
mod/forum/subscribe.php
mod/quiz/view.php
my/index.php
search/add.php
search/delete.php
search/indexer.php
search/indexersplash.php
search/tests/index.php
search/update.php
user/edit.php
user/view.php

index c4ddfd1..84690cd 100644 (file)
@@ -22,7 +22,7 @@ if ($hassiteconfig
     $temp->add(new admin_setting_configselect('guestloginbutton', get_string('guestloginbutton', 'auth'),
                                               get_string('showguestlogin', 'auth'), '1', array('0'=>get_string('hide'), '1'=>get_string('show'))));
     $temp->add(new admin_setting_configtext('alternateloginurl', get_string('alternateloginurl', 'auth'),
-                                            get_string('alternatelogin', 'auth', htmlspecialchars($CFG->wwwroot.'/login/index.php')), ''));
+                                            get_string('alternatelogin', 'auth', htmlspecialchars(get_login_url())), ''));
     $temp->add(new admin_setting_configtext('forgottenpasswordurl', get_string('forgottenpasswordurl', 'auth'),
                                             get_string('forgottenpassword', 'auth'), ''));
     $temp->add(new admin_setting_configtextarea('auth_instructions', get_string('instructions', 'auth'),
index 861b122..630bd51 100644 (file)
     $cancel = optional_param( 'cancel' );
     $launch = optional_param( 'launch' );
 
+    $loginurl = get_login_url();
 
     if (!empty($id)) {
         require_login($id);
         if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $id))) {
-            print_error('cannotuseadminadminorteacher', 'error', "$CFG->wwwroot/login/index.php");
+            print_error('cannotuseadminadminorteacher', 'error', $loginurl);
         }
     } else {
         require_login();
         if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
-            print_error('cannotuseadmin', 'error', "$CFG->wwwroot/login/index.php");
+            print_error('cannotuseadmin', 'error', $loginurl);
         }
     }
 
     if (!empty($to)) {
         if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
-            print_error('cannotuseadminadminorteacher', 'error', "$CFG->wwwroot/login/index.php");
+            print_error('cannotuseadminadminorteacher', 'error', $loginurl);
         }
     }
 
index 09b6fd4..94d92b6 100644 (file)
@@ -4,19 +4,21 @@
     //Check login
     require_login();
 
+    $loginurl = get_login_url();
+
     if (!empty($course->id)) {
         if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
             if (empty($to)) {
-                print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                print_error("cannotuseadminadminorteacher", '', $loginurl);
             } else {
                 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
-                    print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                    print_error("cannotuseadminadminorteacher", '', $loginurl);
                 }
             }
         }
     } else {
         if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
-            print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php");
+            print_error("cannotuseadmin", '', $loginurl);
         }
     }
 
index 7c4bfc8..1ca0344 100644 (file)
@@ -4,19 +4,21 @@
     //Check login   
     require_login();
 
+    $loginurl = get_login_url();
+
     if (!empty($course->id)) {
         if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
             if (empty($to)) {
-                print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                print_error("cannotuseadminadminorteacher", '', $loginurl);
             } else {
                 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
-                    print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                    print_error("cannotuseadminadminorteacher", '', $loginurl);
                 }
             }
         }
     } else {
         if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
-            print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php");
+            print_error("cannotuseadmin", '', $loginurl);
         }
     }
 
index b94e15f..06653c3 100644 (file)
@@ -5,19 +5,21 @@
     //Check login
     require_login();
 
+    $loginurl = get_login_url();
+
     if (!empty($course->id)) {
         if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
             if (empty($to)) {
-                print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                print_error("cannotuseadminadminorteacher", '', $loginurl);
             } else {
                 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
-                    print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                    print_error("cannotuseadminadminorteacher", '', $loginurl);
                 }
             }
         }
     } else {
         if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
-            print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php");
+            print_error("cannotuseadmin", '', $loginurl);
         }
     }
 
index f79fd96..ff4299c 100644 (file)
         $to = $SESSION->restore->course_id;
     }
 
+    $loginurl = get_login_url();
+
     if (!empty($id)) {
         require_login($id);
         if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
             if (empty($to)) {
-                print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                print_error("cannotuseadminadminorteacher", '', $loginurl);
             } else {
                 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
                     && !has_capability('moodle/site:import',  get_context_instance(CONTEXT_COURSE, $to))) {
-                    print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                    print_error("cannotuseadminadminorteacher", '', $loginurl);
                 }
             }
         }
     } else {
         if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
-            print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php");
+            print_error("cannotuseadmin", '', $loginurl);
         }
     }
 
index ac35bed..871febb 100644 (file)
     //Check login
     require_login();
 
+    $loginurl = get_login_url();
+
     //Check admin
     if (!empty($id)) {
         if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
-            print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+            print_error("cannotuseadminadminorteacher", '', $loginurl);
         }
     } else {
         if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
-            print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php");
+            print_error("cannotuseadmin", '', $loginurl);
         }
     }
 
index 1216fe3..4c10580 100644 (file)
     //Check login
     require_login();
 
+    $loginurl = get_login_url();
+
     //Check admin
     if (!empty($id)) {
         if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
             if (empty($to)) {
-                print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                print_error("cannotuseadminadminorteacher", '', $loginurl);
             } else {
                 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to)) 
                     && !has_capability('moodle/site:import',  get_context_instance(CONTEXT_COURSE, $to))) {
-                    print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                    print_error("cannotuseadminadminorteacher", '', $loginurl);
                 }
             }
         }
     } else {
         if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
-            print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php");
+            print_error("cannotuseadmin", '', $loginurl);
         }
     }
 
index 704e37f..d501cb2 100644 (file)
     //Check login
     require_login();
 
+    $loginurl = get_login_url();
+
     //Check admin
     if (!empty($id)) {
         if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
-            print_error('cannotuseadminadminorteacher', '', '$CFG->wwwroot/login/index.php');
+            print_error('cannotuseadminadminorteacher', '', $loginurl);
         }
     } else {
         if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
-            print_error('cannotuseadmin', '', '$CFG->wwwroot/login/index.php');
+            print_error('cannotuseadmin', '', $loginurl);
         }
     }
 
index e14d2fb..e6cecba 100644 (file)
 
     //Check login   
     require_login();
+
+    $loginurl = get_login_url();
+
     //Check admin
     if (!empty($id)) {
         if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
             if (empty($to)) {
-                print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                print_error("cannotuseadminadminorteacher", '', $loginurl);
             } else {
                 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
                     && !has_capability('moodle/site:import',  get_context_instance(CONTEXT_COURSE, $to))) {
-                    print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php");
+                    print_error("cannotuseadminadminorteacher", '', $loginurl);
                 }
             }
         }
     } else {
         if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
-            print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php");   
+            print_error("cannotuseadmin", '', $loginurl);
         }
     }
 
index 8d924e8..4befcac 100644 (file)
@@ -43,7 +43,7 @@ class block_login extends block_base {
 
         if (!isloggedin() or isguestuser()) {   // Show the block
 
-            $this->content->text .= "\n".'<form class="loginform" id="login" method="post" action="'.$wwwroot.'/login/index.php">';
+            $this->content->text .= "\n".'<form class="loginform" id="login" method="post" action="'.get_login_url().'">';
 
             $this->content->text .= '<div class="c1 fld username"><label for="login_username">'.get_string('username').'</label>';
             $this->content->text .= '<input type="text" name="username" id="login_username" value="'.s($username).'" /></div>';
index fecd634..67da56c 100644 (file)
@@ -309,7 +309,7 @@ EOT;
             } else {
                 //if not logged in
                 $this->content->footer = '<hr />'.get_string('please', $tagslang).'
-                    <a href="'.$CFG->wwwroot.'/login/index.php">'.get_string('login', $tagslang).'
+                    <a href="'.get_login_url().'">'.get_string('login', $tagslang).'
                         </a> '.get_string('tagunits', $tagslang);
             }
         }
index 6d2e79c..76b95bd 100644 (file)
     $loginasguest = optional_param('loginasguest', 0, PARAM_BOOL); // hmm, is this still needed?
 
     if (!isloggedin()) {
-        $wwwroot = $CFG->wwwroot;
-        if (!empty($CFG->loginhttps)) {
-            $wwwroot = str_replace('http:','https:', $wwwroot);
-        }
         // do not use require_login here because we are usually comming from it
-        redirect($wwwroot.'/login/index.php');
+        redirect(get_login_url());
     }
 
     if (!$course = $DB->get_record('course', array('id'=>$id))) {
index 93012ea..919a2da 100644 (file)
 
     if (isguestuser()) {
         print_box_start('centerpara');
-        if (empty($CFG->loginhttps)) {
-            $loginurl = $CFG->wwwroot .'/login/index.php';
-        } else {
-            $wwwroot = str_replace('http:','https:', $CFG->wwwroot);
-            $loginurl = $wwwroot .'/login/index.php';
-        }
+        $loginurl = get_login_url();
         print_single_button($loginurl, null, get_string('login'));
         print_box_end();
     }
index a3b4349..c63a6bc 100644 (file)
@@ -1861,6 +1861,27 @@ function course_setup($courseorid=0) {
 
 }
 
+/**
+ * Returns full login url.
+ *
+ * @param bool $loginguest add login guest param
+ * @return string login url
+ */
+function get_login_url($loginguest=false) {
+    global $CFG;
+
+    if (empty($CFG->loginhttps) or $loginguest) { //do not require https for guest logins
+        $loginguest = $loginguest ? '?loginguest=true' : '';
+        $url = "$CFG->wwwroot/login/index.php$loginguest";
+
+    } else {
+        $wwwroot = str_replace('http:','https:', $CFG->wwwroot);
+        $url = "$wwwroot/login/index.php";
+    }
+
+    return $url;
+}
+
 /**
  * This function checks that the current user is logged in and has the
  * required privileges
@@ -1906,17 +1927,12 @@ function require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsu
             $SESSION->fromurl  = $_SERVER['HTTP_REFERER'];
         }
         if ($autologinguest and !empty($CFG->guestloginbutton) and !empty($CFG->autologinguests) and ($COURSE->id == SITEID or $COURSE->guest) ) {
-            $loginguest = '?loginguest=true';
-        } else {
-            $loginguest = '';
-        }
-        if (empty($CFG->loginhttps) or $loginguest) { //do not require https for guest logins
-            redirect($CFG->wwwroot .'/login/index.php'. $loginguest);
+            $loginguest = true;
         } else {
-            $wwwroot = str_replace('http:','https:', $CFG->wwwroot);
-            redirect($wwwroot .'/login/index.php');
+            $loginguest = false;
         }
-        exit;
+        redirect(get_login_url($loginguest));
+        exit; // never reached
     }
 
 /// loginas as redirection if needed
@@ -1956,13 +1972,6 @@ function require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsu
         redirect($CFG->wwwroot .'/user/edit.php?id='. $USER->id .'&amp;course='. SITEID);
     }
 
-/// Make sure current IP matches the one for this session (if required)
-    if (!empty($CFG->tracksessionip)) {
-        if ($USER->sessionIP != md5(getremoteaddr())) {
-            print_error('sessionipnomatch', 'error');
-        }
-    }
-
 /// Make sure the USER has a sesskey set up.  Used for checking script parameters.
     sesskey();
 
@@ -2069,7 +2078,7 @@ function require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsu
                 case 1:    /// Guests always allowed
                     if (!has_capability('moodle/course:view', $COURSE->context)) {    // Prohibited by capability
                         print_header_simple();
-                        notice(get_string('guestsnotallowed', '', format_string($COURSE->fullname)), "$CFG->wwwroot/login/index.php");
+                        notice(get_string('guestsnotallowed', '', format_string($COURSE->fullname)), get_login_url());
                     }
                     if (!empty($cm) and !$cm->visible) { // Not allowed to see module, send to course page
                         redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course,
@@ -2094,7 +2103,7 @@ function require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsu
                     print_header_simple('', '',
                             build_navigation(array(array('name' => $strloggedinasguest, 'link' => null, 'type' => 'misc'))));
                     if (empty($USER->access['rsw'][$COURSE->context->path])) {  // Normal guest
-                        notice(get_string('guestsnotallowed', '', format_string($COURSE->fullname)), "$CFG->wwwroot/login/index.php");
+                        notice(get_string('guestsnotallowed', '', format_string($COURSE->fullname)), get_login_url());
                     } else {
                         notify(get_string('guestsnotallowed', '', format_string($COURSE->fullname)));
                         echo '<div class="notifyproblem">'.switchroles_form($COURSE->id).'</div>';
index 82a5b55..470e770 100644 (file)
@@ -95,6 +95,29 @@ class moodle_session {
         session_set_user($user);
     }
 
+    protected function check_security() {
+        global $CFG;
+
+        if (!empty($_SESSION['USER']->id)) {
+            /// Make sure current IP matches the one for this session (if required)
+            $remoteaddr = getremoteaddr();
+
+            if (empty($_SESSION['USER']->sessionip)) {
+                $_SESSION['USER']->sessionip = $remoteaddr;
+            }
+
+            if ($_SESSION['USER']->sessionip != $remoteaddr) {
+                if (!is_guestuser($_SESSION['USER'])) {
+                    $link = '';
+                } else {
+                    
+                }
+                print_error('sessionipnomatch', 'error');
+            }
+        }
+
+    }
+
     /**
      * Terminates active moodle session
      */
index 39c5eb2..464e6c8 100644 (file)
@@ -3506,11 +3506,7 @@ function user_login_string($course=NULL, $user=NULL) {
         $realuserinfo = '';
     }
 
-    if (empty($CFG->loginhttps)) {
-        $wwwroot = $CFG->wwwroot;
-    } else {
-        $wwwroot = str_replace('http:','https:',$CFG->wwwroot);
-    }
+    $loginurl = get_login_url();
 
     if (empty($course->id)) {
         // $course->id is not defined during installation
@@ -3525,7 +3521,7 @@ function user_login_string($course=NULL, $user=NULL) {
         }
         if (isset($user->username) && $user->username == 'guest') {
             $loggedinas = $realuserinfo.get_string('loggedinasguest').
-                      " (<a $CFG->frametarget href=\"$wwwroot/login/index.php\">".get_string('login').'</a>)';
+                      " (<a $CFG->frametarget href=\"$loginurl\">".get_string('login').'</a>)';
         } else if (!empty($user->access['rsw'][$context->path])) {
             $rolename = '';
             if ($role = $DB->get_record('role', array('id'=>$user->access['rsw'][$context->path]))) {
@@ -3540,7 +3536,7 @@ function user_login_string($course=NULL, $user=NULL) {
         }
     } else {
         $loggedinas = get_string('loggedinnot', 'moodle').
-                      " (<a $CFG->frametarget href=\"$wwwroot/login/index.php\">".get_string('login').'</a>)';
+                      " (<a $CFG->frametarget href=\"$loginurl\">".get_string('login').'</a>)';
     }
     return '<div class="logininfo">'.$loggedinas.'</div>';
 }
index e4d895a..5775936 100644 (file)
@@ -21,7 +21,7 @@
         if (empty($SESSION->wantsurl)) {
             $SESSION->wantsurl = $CFG->httpswwwroot.'/login/change_password.php';
         }
-        redirect($CFG->httpswwwroot.'/login/index.php');
+        redirect(get_login_url());
     }
 
     // do not require change own password cap if change forced
index 8a04a55..1598ca6 100644 (file)
@@ -18,7 +18,7 @@ $systemcontext = get_context_instance(CONTEXT_SYSTEM);
 $strforgotten = get_string('passwordforgotten');
 $strlogin     = get_string('login');
 
-$navigation = build_navigation(array(array('name' => $strlogin, 'link' => "$CFG->wwwroot/login/index.php", 'type' => 'misc'),
+$navigation = build_navigation(array(array('name' => $strlogin, 'link' => get_login_url(), 'type' => 'misc'),
                                      array('name' => $strforgotten, 'link' => null, 'type' => 'misc')));
 
 // if alternatepasswordurl is defined, then we'll just head there
@@ -91,7 +91,7 @@ if ($p_secret !== false) {
 $mform = new login_forgot_password_form();
 
 if ($mform->is_cancelled()) {
-    redirect($CFG->httpswwwroot.'/login/index.php');
+    redirect(get_login_url());
 
 } else if ($data = $mform->get_data()) {
 /// find the user in the database and mail info
index 4ee44b3..1247590 100644 (file)
@@ -29,7 +29,7 @@
     $mform_signup = new login_signup_form();
 
     if ($mform_signup->is_cancelled()) {
-        redirect($CFG->httpswwwroot.'/login/index.php');
+        redirect(get_login_url());
 
     } else if ($user = $mform_signup->get_data()) {
         $user->confirmed   = 0;
index a339fc9..491dd6d 100644 (file)
@@ -51,7 +51,7 @@
             if (empty($SESSION->wantsurl)) {
                 $SESSION->wantsurl = $CFG->httpswwwroot.'/message/edit.php';
             }
-            redirect($CFG->httpswwwroot.'/login/index.php');
+            redirect(get_login_url());
         }
     }
 
index 028c3b9..60944b7 100644 (file)
         $navigation = build_navigation('', $cm);
         print_header_simple(format_string($chat->name), '', $navigation,
                       '', '', true, '', navmenu($course, $cm));
-        $wwwroot = $CFG->wwwroot.'/login/index.php';
-        if (!empty($CFG->loginhttps)) {
-            $wwwroot = str_replace('http:','https:', $wwwroot);
-        }
 
         notice_yesno(get_string('noguests', 'chat').'<br /><br />'.get_string('liketologin'),
-                $wwwroot, $CFG->wwwroot.'/course/view.php?id='.$course->id);
+                get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id);
 
         print_footer($course);
         exit;
index c1664e9..6b00ca3 100644 (file)
         $sitecontext = get_context_instance(CONTEXT_SYSTEM);
 
         if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) {      // Guest on whole site
-            $wwwroot = $CFG->wwwroot.'/login/index.php';
-            if (!empty($CFG->loginhttps)) {
-                $wwwroot = str_replace('http:','https:', $wwwroot);
-            }
             notice_yesno(get_string('noguestchoose', 'choice').'<br /><br />'.get_string('liketologin'),
-                         $wwwroot, $_SERVER['HTTP_REFERER']);
+                         get_login_url(), $_SERVER['HTTP_REFERER']);
 
         } else if (has_capability('moodle/legacy:guest', $context, NULL, false)) {   // Guest in this course only
             $SESSION->wantsurl = $FULLME;
index 564065d..6210a9b 100644 (file)
     }
 
     if (isguest()) {   // Guests can't change forum
-        $wwwroot = $CFG->wwwroot.'/login/index.php';
-        if (!empty($CFG->loginhttps)) {
-            $wwwroot = str_replace('http:','https:', $wwwroot);
-        }
-
         $navigation = build_navigation('', $cm);
         print_header($course->shortname, $course->fullname, $navigation, '', '', true, "", navmenu($course, $cm));
         notice_yesno(get_string('noguesttracking', 'forum').'<br /><br />'.get_string('liketologin'),
-                     $wwwroot, $returnto);
+                     get_login_url(), $returnto);
         print_footer($course);
         exit;
     }
index 28ef64c..e451b88 100644 (file)
 
     if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) {
 
-        $wwwroot = $CFG->wwwroot.'/login/index.php';
-        if (!empty($CFG->loginhttps)) {
-            $wwwroot = str_replace('http:', 'https:', $wwwroot);
-        }
-
         if (!empty($forum)) {      // User is starting a new discussion in a forum
             if (! $forum = $DB->get_record('forum', array('id' => $forum))) {
                 print_error('invalidforumid', 'forum');
@@ -62,7 +57,7 @@
         print_header($course->shortname, $course->fullname, $navigation, '' , '', true, "", navmenu($course, $cm));
 
         notice_yesno(get_string('noguestpost', 'forum').'<br /><br />'.get_string('liketologin'),
-                     $wwwroot, get_referer(false));
+                     get_login_url(), get_referer(false));
         print_footer($course);
         exit;
     }
index fbcf8c6..c2876e4 100644 (file)
     require_login($course->id, false, $cm);
 
     if (isguest()) {   // Guests can't subscribe
-        $wwwroot = $CFG->wwwroot.'/login/index.php';
-        if (!empty($CFG->loginhttps)) {
-            $wwwroot = str_replace('http:','https:', $wwwroot);
-        }
 
         $navigation = build_navigation('', $cm);
         print_header($course->shortname, $course->fullname, $navigation, '', '', true, "", navmenu($course, $cm));
 
         notice_yesno(get_string('noguestsubscribe', 'forum').'<br /><br />'.get_string('liketologin'),
-                     $wwwroot, $_SERVER['HTTP_REFERER']);
+                     get_login_url(), $_SERVER['HTTP_REFERER']);
         print_footer($course);
         exit;
     }
index dda980a..388bdae 100644 (file)
 
 /// Guests can't do a quiz, so offer them a choice of logging in or going back.
     if (isguestuser()) {
-        $loginurl = $CFG->wwwroot.'/login/index.php';
-        if (!empty($CFG->loginhttps)) {
-            $loginurl = str_replace('http:','https:', $loginurl);
-        }
-
         notice_yesno('<p>' . get_string('guestsno', 'quiz') . "</p>\n\n<p>" .
-                get_string('liketologin') . "</p>\n", $loginurl, get_referer(false));
+                get_string('liketologin') . "</p>\n", get_login_url(), get_referer(false));
         finish_page($course);
     }
 
index 449a954..1c052e6 100644 (file)
     $mymoodlestr = get_string('mymoodle','my');
 
     if (isguest()) {
-        $wwwroot = $CFG->wwwroot.'/login/index.php';
-        if (!empty($CFG->loginhttps)) {
-            $wwwroot = str_replace('http:','https:', $wwwroot);
-        }
-
         print_header($mymoodlestr);
         notice_yesno(get_string('noguest', 'my').'<br /><br />'.get_string('liketologin'),
-                     $wwwroot, $CFG->wwwroot);
+                     get_login_url(), $CFG->wwwroot);
         print_footer();
         die();
     }
index 8973ed9..26eb415 100644 (file)
@@ -35,7 +35,7 @@
     }
 
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
+        print_error('beadmin', 'search', get_login_url());
     }
 
 /// check for php5 (lib.php)
index 4f4790d..5ab8d5e 100644 (file)
@@ -32,7 +32,7 @@
     }
 
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
+        print_error('beadmin', 'search', get_login_url());
     } //if
 
     try {
index 84bfb84..c4b4e29 100644 (file)
@@ -49,7 +49,7 @@ $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
     }
 
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
+        print_error('beadmin', 'search', get_login_url());
     }
 
 /// confirmation flag to prevent accidental reindexing (indexersplash.php is the correct entry point)
index c5790ae..b30b410 100644 (file)
@@ -33,7 +33,7 @@ ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path
     }
 
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
+        print_error('beadmin', 'search', get_login_url());
     }
 
     require_once("$CFG->dirroot/search/indexlib.php");
index 31cb5e6..9b7cb7a 100644 (file)
@@ -24,7 +24,7 @@
     }
 
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-      print_error('onlyadmins', 'error', "$CFG->wwwroot/login/index.php");
+      print_error('onlyadmins', 'error', get_login_url());
     } //if
 
     mtrace('<pre>Server Time: '.date('r',time()));
index b5eaa44..ab5d56d 100644 (file)
@@ -35,7 +35,7 @@
     }
 
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
+        print_error('beadmin', 'search', get_login_url());
     }
 
     try {
index 4544635..15172d3 100644 (file)
@@ -22,7 +22,7 @@
         if (empty($SESSION->wantsurl)) {
             $SESSION->wantsurl = $CFG->httpswwwroot.'/user/edit.php';
         }
-        redirect($CFG->httpswwwroot.'/login/index.php');
+        redirect(get_login_url());
     }
 
     // Guest can not edit
index e00bbcb..e8983df 100644 (file)
@@ -50,7 +50,7 @@
     if (!empty($CFG->forceloginforprofiles)) {
         require_login();
         if (isguest()) {
-            redirect("$CFG->wwwroot/login/index.php");
+            redirect(get_login_url());
         }
     }