Browse Source

custom pages clean up: remove unnecessary requires

Laurent Opprecht 12 years ago
parent
commit
21683bf5ed

+ 0 - 1
custompages/first_login.php

@@ -1,7 +1,6 @@
 <?php
 require_once('language.php');
 require_once(dirname(__FILE__).'/../main/inc/global.inc.php');
-//require_once (api_get_path(LIBRARY_PATH).'conditionallogin.lib.php'); moved to autologin
 require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
 
 if (! isset($_SESSION['conditional_login']['uid']))

+ 3 - 4
index.php

@@ -79,16 +79,15 @@ if (api_get_setting('allow_terms_conditions') == 'true') {
 	unset($_SESSION['info_current_user']);
 }
 //If we are not logged in and customapages activated
-if (!api_get_user_id() && api_get_setting('use_custom_pages') == 'true' )
+if (!api_get_user_id() && CustomPages::enabled())
 {
-  require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';
   if(Request::get('loggedout'))
   {      
-    CustomPages::displayPage('loggedout');
+    CustomPages::display(CustomPages::LOGGED_OUT);
   }
   else
   {      
-    CustomPages::displayPage('index-unlogged');
+    CustomPages::display(CustomPages::INDEX_UNLOGGED);
   }
 }
 

+ 7 - 7
main/auth/inscription.php

@@ -14,7 +14,7 @@ require_once '../inc/global.inc.php';
 require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
 require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
 require_once api_get_path(LIBRARY_PATH).'legal.lib.php';
-require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';
+//require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';moved to autoload
 
 if (!empty($_SESSION['user_language_choice'])) {
     $user_selected_language = $_SESSION['user_language_choice'];
@@ -277,7 +277,7 @@ if (is_array($extra_data)) {
 
 $form->setDefaults($defaults);
 
-if (api_get_setting('use_custom_pages') != 'true') {
+if (!CustomPages::enabled()) {
   // Load terms & conditions from the current lang
   if (api_get_setting('allow_terms_conditions') == 'true') {
     $get = array_keys($_GET);
@@ -528,7 +528,7 @@ if ($form->validate()) {
             // 3. exit the page
             unset($user_id);
             
-            if (api_get_setting('use_custom_pages') != 'true') {
+            if (!CustomPages::enabled()) {
               Display :: display_footer();
             }
             exit;
@@ -610,14 +610,14 @@ if ($form->validate()) {
     // ?uidReset=true&uidReq=$_user['user_id']
 
     $display_text .= '<form action="'. $action_url. '"  method="post">'. "\n". '<button type="submit" class="next" name="next" value="'. get_lang('Next',null,$_user['language']). '" validationmsg=" '. get_lang('Next',null,$_user['language']). ' ">'. $button_text. '</button>'. "\n". '</form><br />'. "\n";
-  if (api_get_setting('use_custom_pages') == 'true') {
-    CustomPages::displayPage('registration-feedback', array('info' => $display_text));
+  if (CustomPages::enabled()) {
+    CustomPages::display(CustomPages::REGISTRATION_FEEDBACK, array('info' => $display_text));
   }
     echo $display_text;
 } else {
   // Custom pages
-  if (api_get_setting('use_custom_pages') == 'true') {
-    CustomPages::displayPage('registration', array('form' => $form));
+  if (CustomPages::enabled()) {
+    CustomPages::display(CustomPages::REGISTRATION, array('form' => $form));
   } else {
     $form->display();
   }

+ 6 - 7
main/auth/lostPassword.php

@@ -23,19 +23,18 @@ $language_file = array('registration', 'index');
 require_once '../inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'login.lib.php';
 require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
-require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';
+//require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';moved to autoload
 
 // Custom pages
 // Had to move the form handling in here, because otherwise there would 
 // already be some display output.
 global $_configuration;
 
-if (api_get_setting('use_custom_pages') == 'true') {
-
+if (CustomPages::enabled()) {
     //Reset Password when user goes to the link
     if ($_GET['reset'] && $_GET['id']){
         $mesg = Login::reset_password($_GET["reset"], $_GET["id"], true);
-        CustomPages::displayPage('index-unlogged', array('info' => $mesg));
+        CustomPages::display(CustomPages::INDEX_UNLOGGED, array('info' => $mesg));
     }
 
     //Check email/username and do the right thing
@@ -75,12 +74,12 @@ if (api_get_setting('use_custom_pages') == 'true') {
                 Login::send_password_to_user($user, $by_username);
             }
         } else {
-            CustomPages::displayPage('lostpassword',array('error' => get_lang('NoUserAccountWithThisEmailAddress')));
+            CustomPages::display(CustomPages::LOST_PASSWORD, array('error' => get_lang('NoUserAccountWithThisEmailAddress')));
         }
     } else {
-        CustomPages::displayPage('lostpassword');
+        CustomPages::display(CustomPages::LOGGED_OUT);
     }
-    CustomPages::displayPage('index-unlogged', array('info' => get_lang('YourPasswordHasBeenEmailed')));
+    CustomPages::display(CustomPages::INDEX_UNLOGGED, array('info' => get_lang('YourPasswordHasBeenEmailed')));
 }
 
 $tool_name = get_lang('LostPassword');

+ 1 - 1
main/inc/lib/autoload.class.php

@@ -119,7 +119,7 @@ class Autoload
         $result['CourseSession'] = '/main/coursecopy/classes/CourseSession.class.php';
         $result['CsvReader'] = '/main/inc/lib/system/io/csv_reader.class.php';
         $result['CsvWriter'] = '/main/inc/lib/system/io/csv_writer.class.php';
-        $result['CustomPages'] = '/main/inc/lib/custompages.lib.php';
+        $result['CustomPages'] = '/main/inc/lib/custom_pages.class.php';
         $result['DashboardManager'] = '/main/inc/lib/dashboard.lib.php';
         $result['DataForm'] = '/main/gradebook/lib/fe/dataform.class.php';
         $result['Debug'] = '/main/inc/lib/debug.lib.php';

+ 0 - 2
main/inc/lib/conditional_login.class.php

@@ -22,9 +22,7 @@ class ConditionalLogin {
     }
 
 	public static function login() {
-		//require_once api_get_path(LIBRARY_PATH).'loginredirection.lib.php'; moved to autologin
 	    $_SESSION['conditional_login']['can_login'] = true;
 		LoginRedirection::redirect();
-	    exit();
 	}
 }

+ 0 - 5
main/inc/lib/conditionallogin.lib.php

@@ -1,5 +0,0 @@
-<?php
-/**
- * Added to autologin
- * moved to conditional_login.class.php 
- */

+ 82 - 0
main/inc/lib/custom_pages.class.php

@@ -0,0 +1,82 @@
+<?php
+
+/**
+ *  Used to implement the loading of custom pages
+ * 
+ * @license see /license.txt
+ * @author 2011, Jean-Karim Bockstael <jeankarim@cblue.be>
+ * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
+ */
+class CustomPages
+{
+    const INDEX_LOGGED = 'index-logged';
+    const INDEX_UNLOGGED = 'index-unlogged';
+    const LOGGED_OUT = 'loggedout';
+    const REGISTRATION_FEEDBACK = 'registration-feedback';
+    const REGISTRATION = 'registration';
+    const LOST_PASSWORD = 'lostpassword';
+
+    /**
+     * Returns true if custom pages are enabled. False otherwise.
+     * @return bool
+     */
+    public static function enabled()
+    {
+        return api_get_setting('use_custom_pages') == 'true';
+    }
+
+    /**
+     * Returns the path to a custom page.
+     * 
+     * @param string $name
+     * @return string
+     */
+    public static function path($name = '')
+    {
+        return api_get_path(SYS_PATH) . 'custompages/' . $name;
+    }
+
+    /**
+     * If enabled display a custom page and exist. Otherwise log error and returns.
+     * 
+     * @param string $page_name
+     * @param array $content used to path data to the custom page
+     */
+    public static function display($page_name, $content = array())
+    {
+        if (!self::enabled()) {
+            return false;
+        }
+
+        $file = self::path($page_name . '.php');
+        if (file_exists($file)) {
+            include($file);
+            exit;
+        } else {
+            error_log('CustomPages::displayPage : could not read file ' . $file_name);
+        }
+    }
+
+    /**
+     * Does not look like this function is being used is being used 
+     * 
+     * @param type $url_id
+     * @return string 
+     */
+    public static function getURLImages($url_id = null)
+    {
+        if (is_null($url_id)) {
+            $url = 'http://' . $_SERVER['HTTP_HOST'] . '/';
+            $url_id = UrlManager::get_url_id($url);
+        }
+        $url_images_dir = api_get_path(SYS_PATH) . 'custompages/url-images/';
+        $images = array();
+        for ($img_id = 1; $img_id <= 3; $img_id++) {
+            if (file_exists($url_images_dir . $url_id . '_url_image_' . $img_id . '.png')) {
+                $images[] = api_get_path(WEB_PATH) . 'custompages/url-images/' . $url_id . '_url_image_' . $img_id . '.png';
+            }
+        }
+        return $images;
+    }
+
+}

+ 0 - 37
main/inc/lib/custompages.lib.php

@@ -1,37 +0,0 @@
-<?php
-// Custom Pages lib
-// Used to implement the loading of custom pages
-// 2011, Jean-Karim Bockstael <jeankarim@cblue.be>
-
-require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
-
-class CustomPages {
-	
-	public static function displayPage($page_name, $content=array()) {
-		$pages_dir = api_get_path(SYS_PATH).'custompages/';
-		$file_name = $pages_dir.$page_name.'.php';
-		if (file_exists($file_name)) {
-			include($file_name);
-			exit;
-		}
-		else {
-			error_log('CustomPages::displayPage : could not read file '.$file_name);
-		}
-	}
-
-	public static function getURLImages($url_id = null) {
-		if (is_null($url_id)) {
-			$url = 'http://'.$_SERVER['HTTP_HOST'].'/';
-			$url_id = UrlManager::get_url_id($url);
-		}
-		$url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
-		$images = array();
-		for ($img_id = 1; $img_id <= 3; $img_id++) {
-			 if (file_exists($url_images_dir.$url_id.'_url_image_'.$img_id.'.png')) {
-			 	$images[] = api_get_path(WEB_PATH).'custompages/url-images/'.$url_id.'_url_image_'.$img_id.'.png';
-			 }
-		}
-		return $images;
-	}
-}
-?>

+ 170 - 159
main/inc/lib/login.lib.php

@@ -1,126 +1,132 @@
 <?php
+
 /* For licensing terms, see /license.txt */
 /**
-*	Code library for login process
-*
-* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
-* @author Julio Montoya		<gugli100@gmail.com>
-* @package chamilo.login
-*/
+ * 	Code library for login process
+ *
+ * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
+ * @author Julio Montoya		<gugli100@gmail.com>
+ * @package chamilo.login
+ */
+
 /**
  * Class
  * @package chamilo.login
  */
-class Login 
+class Login
 {
-	/**
-	 * Get user account list
-	 *
-	 * @param unknown_type $user
-	 * @param boolean $reset
-	 * @param boolean $by_username
-	 * @return unknown
-	 */
-	public static function get_user_account_list($user, $reset = false, $by_username = false) {
-		global $_configuration;
+
+    /**
+     * Get user account list
+     *
+     * @param unknown_type $user
+     * @param boolean $reset
+     * @param boolean $by_username
+     * @return unknown
+     */
+    public static function get_user_account_list($user, $reset = false, $by_username = false)
+    {
+        global $_configuration;
         //$portal_url = $_configuration['root_web'];
-		$portal_url = api_get_path(WEB_PATH);
-        
-		if ($_configuration['multiple_access_urls']) {
-			$access_url_id = api_get_current_access_url_id();
-			if ($access_url_id != -1 ) {
-				$url = api_get_access_url($access_url_id);
-				$portal_url = $url['url'];                
-			}
-		}
-	
-		if ($reset) {	
-			if ($by_username) {	
-				$secret_word = self::get_secret_word($user['email']);
-				if ($reset)	{
-					$reset_link = $portal_url."main/auth/lostPassword.php?reset=".$secret_word."&id=".$user['uid'];
-				} else {
-					$reset_link = get_lang('Pass')." : $user[password]";
-				}
-				$user_account_list = get_lang('YourRegistrationData')." : \n".get_lang('UserName').' : '.$user['loginName']."\n".get_lang('ResetLink').' : '.$reset_link.'';
-	
-				if ($user_account_list) {
-					$user_account_list = "\n-----------------------------------------------\n" . $user_account_list;
-				}	
-			} else {	
-				foreach ($user as $this_user) {
-					$secret_word = self::get_secret_word($this_user['email']);
-					if ($reset)	{
-						$reset_link = $portal_url."main/auth/lostPassword.php?reset=".$secret_word."&id=".$this_user['uid'];
-					} else {
-						$reset_link = get_lang('Pass')." : $this_user[password]";
-					}
-					$user_account_list[] = get_lang('YourRegistrationData')." : \n".get_lang('UserName').' : '.$this_user['loginName']."\n".get_lang('ResetLink').' : '.$reset_link.'';
-				}	
-				if ($user_account_list) {
-					$user_account_list = implode("\n-----------------------------------------------\n", $user_account_list);
-				}
-			}	
-		} else {	
-			if (!$by_username) {
-		    	$user = $user[0];
-			}
-		    $reset_link = get_lang('Pass')." : $user[password]";
-	       	$user_account_list = get_lang('YourRegistrationData')." : \n".get_lang('UserName').' : '.$user['loginName']."\n".$reset_link.'';	
-		}
-		return $user_account_list;
-	}
-	
-	/**
-	 * This function sends the actual password to the user
-	 *
-	 * @param unknown_type $user
-	 * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
-	 */
-	public static function send_password_to_user($user, $by_username = false) {	
-		global $_configuration;
-		$email_subject = "[".api_get_setting('siteName')."] ".get_lang('LoginRequest'); // SUBJECT
-	
-		if ($by_username) { // Show only for lost password
-			$user_account_list = self::get_user_account_list($user, false, $by_username); // BODY
-			$email_to = $user['email'];
-		} else {
-			$user_account_list = self::get_user_account_list($user); // BODY
-			$email_to = $user[0]['email'];
-		}
-	
-		$portal_url = $_configuration['root_web'];
-		if ($_configuration['multiple_access_urls']) {
-			$access_url_id = api_get_current_access_url_id();
-			if ($access_url_id != -1 ) {
-				$url = api_get_access_url($access_url_id);
-				$portal_url = $url['url'];
-			}
-		}
-	
-		$email_body = get_lang('YourAccountParam')." ".$portal_url."\n\n$user_account_list";
-		// SEND MESSAGE
-		$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
-	    $email_admin = api_get_setting('emailAdministrator');
-
-		if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {
-            return get_lang('your_password_has_been_reset');            
-		} else {
-			return get_lang('SystemUnableToSendEmailContact').' '.Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')).".</p>";
-		}
-	}
-	
-	/**
-	 * Handle encrypted password, send an email to a user with his password 
-	 *
-	 * @param int	user id
-	 * @param bool	$by_username
-	 *
-	 * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
-	 */
-    public static function handle_encrypted_password($user, $by_username = false) {	
+        $portal_url = api_get_path(WEB_PATH);
+
+        if ($_configuration['multiple_access_urls']) {
+            $access_url_id = api_get_current_access_url_id();
+            if ($access_url_id != -1) {
+                $url = api_get_access_url($access_url_id);
+                $portal_url = $url['url'];
+            }
+        }
+
+        if ($reset) {
+            if ($by_username) {
+                $secret_word = self::get_secret_word($user['email']);
+                if ($reset) {
+                    $reset_link = $portal_url . "main/auth/lostPassword.php?reset=" . $secret_word . "&id=" . $user['uid'];
+                } else {
+                    $reset_link = get_lang('Pass') . " : $user[password]";
+                }
+                $user_account_list = get_lang('YourRegistrationData') . " : \n" . get_lang('UserName') . ' : ' . $user['loginName'] . "\n" . get_lang('ResetLink') . ' : ' . $reset_link . '';
+
+                if ($user_account_list) {
+                    $user_account_list = "\n-----------------------------------------------\n" . $user_account_list;
+                }
+            } else {
+                foreach ($user as $this_user) {
+                    $secret_word = self::get_secret_word($this_user['email']);
+                    if ($reset) {
+                        $reset_link = $portal_url . "main/auth/lostPassword.php?reset=" . $secret_word . "&id=" . $this_user['uid'];
+                    } else {
+                        $reset_link = get_lang('Pass') . " : $this_user[password]";
+                    }
+                    $user_account_list[] = get_lang('YourRegistrationData') . " : \n" . get_lang('UserName') . ' : ' . $this_user['loginName'] . "\n" . get_lang('ResetLink') . ' : ' . $reset_link . '';
+                }
+                if ($user_account_list) {
+                    $user_account_list = implode("\n-----------------------------------------------\n", $user_account_list);
+                }
+            }
+        } else {
+            if (!$by_username) {
+                $user = $user[0];
+            }
+            $reset_link = get_lang('Pass') . " : $user[password]";
+            $user_account_list = get_lang('YourRegistrationData') . " : \n" . get_lang('UserName') . ' : ' . $user['loginName'] . "\n" . $reset_link . '';
+        }
+        return $user_account_list;
+    }
+
+    /**
+     * This function sends the actual password to the user
+     *
+     * @param unknown_type $user
+     * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
+     */
+    public static function send_password_to_user($user, $by_username = false)
+    {
+        global $_configuration;
+        $email_subject = "[" . api_get_setting('siteName') . "] " . get_lang('LoginRequest'); // SUBJECT
+
+        if ($by_username) { // Show only for lost password
+            $user_account_list = self::get_user_account_list($user, false, $by_username); // BODY
+            $email_to = $user['email'];
+        } else {
+            $user_account_list = self::get_user_account_list($user); // BODY
+            $email_to = $user[0]['email'];
+        }
+
+        $portal_url = $_configuration['root_web'];
+        if ($_configuration['multiple_access_urls']) {
+            $access_url_id = api_get_current_access_url_id();
+            if ($access_url_id != -1) {
+                $url = api_get_access_url($access_url_id);
+                $portal_url = $url['url'];
+            }
+        }
+
+        $email_body = get_lang('YourAccountParam') . " " . $portal_url . "\n\n$user_account_list";
+        // SEND MESSAGE
+        $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
+        $email_admin = api_get_setting('emailAdministrator');
+
+        if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {
+            return get_lang('your_password_has_been_reset');
+        } else {
+            return get_lang('SystemUnableToSendEmailContact') . ' ' . Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')) . ".</p>";
+        }
+    }
+
+    /**
+     * Handle encrypted password, send an email to a user with his password 
+     *
+     * @param int	user id
+     * @param bool	$by_username
+     *
+     * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
+     */
+    public static function handle_encrypted_password($user, $by_username = false)
+    {
         global $_configuration;
-        $email_subject = "[".api_get_setting('siteName')."] ".get_lang('LoginRequest'); // SUBJECT
+        $email_subject = "[" . api_get_setting('siteName') . "] " . get_lang('LoginRequest'); // SUBJECT
 
         if ($by_username) { // Show only for lost password
             $user_account_list = self::get_user_account_list($user, true, $by_username); // BODY
@@ -131,67 +137,72 @@ class Login
         }
 
         $secret_word = self::get_secret_word($email_to);
-        $email_body = get_lang('DearUser')." :\n".get_lang('password_request')."\n";
-        $email_body .= $user_account_list."\n-----------------------------------------------\n\n";
+        $email_body = get_lang('DearUser') . " :\n" . get_lang('password_request') . "\n";
+        $email_body .= $user_account_list . "\n-----------------------------------------------\n\n";
         $email_body .= get_lang('PasswordEncryptedForSecurity');
 
-        $email_body .= "\n\n".get_lang('Formula').",\n".api_get_setting('administratorName')." ".api_get_setting('administratorSurname')."\n".get_lang('PlataformAdmin')." - ".api_get_setting('siteName');
+        $email_body .= "\n\n" . get_lang('Formula') . ",\n" . api_get_setting('administratorName') . " " . api_get_setting('administratorSurname') . "\n" . get_lang('PlataformAdmin') . " - " . api_get_setting('siteName');
 
         $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
         $email_admin = api_get_setting('emailAdministrator');
-        
+
         if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {
-            
-            if (api_get_setting('use_custom_pages') == 'true') {
+
+            if (CustomPages::enabled()) {
                 return get_lang('YourPasswordHasBeenEmailed');
             } else {
                 Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed'));
             }
         } else {
-            $message = get_lang('SystemUnableToSendEmailContact').' '.Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')).".</p>";
-            if (api_get_setting('use_custom_pages') == 'true') {
+            $message = get_lang('SystemUnableToSendEmailContact') . ' ' . Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')) . ".</p>";
+            if (CustomPages::enabled()) {
                 return $message;
             } else {
                 Display::display_error_message($message, false);
             }
         }
     }
-	
-	/**
-	 * Gets the secret word
-	 * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
-	 */
-	public static function get_secret_word($add) {
-		global $_configuration;
-		return $secret_word = md5($_configuration['security_key'].$add);
-	}
-	
-	/**
-	 * Resets a password
-	 * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
-	 */
-	public static function reset_password($secret, $id, $by_username = false) {
-		$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
-		$id = intval($id);
-		$sql = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, username AS loginName, password, email FROM ".$tbl_user." WHERE user_id=$id";
-		$result = Database::query($sql);
-		$num_rows = Database::num_rows($result);
-	
-		if ($result && $num_rows > 0) {
-			$user = Database::fetch_array($result);
-		} else {
-			return get_lang('CouldNotResetPassword'); 
-		}
-        	
-		if (self::get_secret_word($user['email']) == $secret) { // OK, secret word is good. Now change password and mail it.
-			$user['password'] = api_generate_password();
-			$crypted = $user['password'];
-			$crypted = api_get_encrypted_password($crypted);
-			$sql = "UPDATE ".$tbl_user." SET password='$crypted' WHERE user_id = $id";
-			$result = Database::query($sql);
-			return self::send_password_to_user($user, $by_username);
-		} else {
-			return get_lang('NotAllowed');
-		}
-	}	
+
+    /**
+     * Gets the secret word
+     * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
+     */
+    public static function get_secret_word($add)
+    {
+        global $_configuration;
+        return $secret_word = md5($_configuration['security_key'] . $add);
+    }
+
+    /**
+     * Resets a password
+     * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
+     */
+    public static function reset_password($secret, $id, $by_username = false)
+    {
+        $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
+        $id = intval($id);
+        $sql = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, username AS loginName, password, email FROM " . $tbl_user . " WHERE user_id=$id";
+        $result = Database::query($sql);
+        $num_rows = Database::num_rows($result);
+
+        if ($result && $num_rows > 0) {
+            $user = Database::fetch_array($result);
+        } else {
+            return get_lang('CouldNotResetPassword');
+        }
+
+        if (self::get_secret_word($user['email']) == $secret) { // OK, secret word is good. Now change password and mail it.
+            $user['password'] = api_generate_password();
+            $crypted = $user['password'];
+            $crypted = api_get_encrypted_password($crypted);
+            $sql = "UPDATE " . $tbl_user . " SET password='$crypted' WHERE user_id = $id";
+            $result = Database::query($sql);
+            return self::send_password_to_user($user, $by_username);
+        } else {
+            return get_lang('NotAllowed');
+        }
+    }
+
+   
+
 }

+ 2 - 3
main/inc/lib/login_redirection.class.php

@@ -52,9 +52,8 @@ Class LoginRedirection {
     }
 
     // Custom pages
-    if (api_get_setting('use_custom_pages') == 'true') {
-      require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';
-      CustomPages::displayPage('index-logged');
+    if (CustomPages::enabled()) {
+      CustomPages::display(CustomPages::INDEX_LOGGED);
     }
     header('location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login').$param);
     exit();

+ 0 - 7
main/inc/lib/loginredirection.lib.php

@@ -1,7 +0,0 @@
-<?php
-
-/**
- * Added to autologin
- * @see login_redirection.class.php
- *  
- */

+ 2 - 4
main/inc/lib/main_api.lib.php

@@ -2636,11 +2636,9 @@ function api_not_allowed($print_headers = false, $message = null) {
     $course     = api_get_course_id();
 
     global $this_section;
-    if (api_get_setting('use_custom_pages') == 'true' && !isset($_SESSION['_user']['user_id'])) {
+    if (CustomPages::enabled() && !isset($_SESSION['_user']['user_id'])) {
         $_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
-        require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';
-        CustomPages::displayPage('index-unlogged');
-        exit;
+        CustomPages::display(CustomPages::INDEX_UNLOGGED);
     }
 	
     $origin = isset($_GET['origin']) ? $_GET['origin'] : '';

+ 0 - 1
main/inc/local.inc.php

@@ -670,7 +670,6 @@ if (isset($uidReset) && $uidReset) {    // session data refresh requested
                     //If we just want to reset info without redirecting user
                     unset($_SESSION['noredirection']);
                 } else {
-                    //require_once api_get_path(LIBRARY_PATH).'loginredirection.lib.php'; moved to autologin
                     LoginRedirection::redirect();
                 }
             }