@ -1,18 +1,21 @@ 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					<?php  
					 
					 
					 
					<?php  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					/* For licensing terms, see /license.txt */  
					 
					 
					 
					/* For licensing terms, see /license.txt */  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					/**  
					 
					 
					 
					/**  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					*	Code library for login process  
					 
					 
					 
					 * 	Code library for login process  
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					*  
					 
					 
					 
					 *  
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					* @author Olivier Cauberghe < olivier.cauberghe @ UGent . be > , Ghent University  
					 
					 
					 
					 * @author Olivier Cauberghe < olivier.cauberghe @ UGent . be > , Ghent University  
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					* @author Julio Montoya		< gugli100 @ gmail . com >   
					 
					 
					 
					 * @author Julio Montoya		< gugli100 @ gmail . com >   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					* @package chamilo.login  
					 
					 
					 
					 * @package chamilo.login  
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					*/  
					 
					 
					 
					 */  
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					/**  
					 
					 
					 
					/**  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 * Class  
					 
					 
					 
					 * Class  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 * @package chamilo.login  
					 
					 
					 
					 * @package chamilo.login  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 */  
					 
					 
					 
					 */  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					class Login  
					 
					 
					 
					class Login  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					{  
					 
					 
					 
					{  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    /**  
					 
					 
					 
					    /**  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     * Get user account list  
					 
					 
					 
					     * Get user account list  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     *  
					 
					 
					 
					     *  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -21,14 +24,15 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     * @param boolean $by_username  
					 
					 
					 
					     * @param boolean $by_username  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     * @return unknown  
					 
					 
					 
					     * @return unknown  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     */  
					 
					 
					 
					     */  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						public static function get_user_account_list($user, $reset = false, $by_username = false) {  
					 
					 
					 
					    public static function get_user_account_list($user, $reset = false, $by_username = false)  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        global $_configuration;  
					 
					 
					 
					        global $_configuration;  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        //$portal_url = $_configuration['root_web'];  
					 
					 
					 
					        //$portal_url = $_configuration['root_web'];  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        $portal_url = api_get_path(WEB_PATH);  
					 
					 
					 
					        $portal_url = api_get_path(WEB_PATH);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if ($_configuration['multiple_access_urls']) {  
					 
					 
					 
					        if ($_configuration['multiple_access_urls']) {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            $access_url_id = api_get_current_access_url_id();  
					 
					 
					 
					            $access_url_id = api_get_current_access_url_id();  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								if ($access_url_id != -1  ) { 
					 
					 
					 
					            if ($access_url_id != -1 ) { 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					                $url = api_get_access_url($access_url_id);  
					 
					 
					 
					                $url = api_get_access_url($access_url_id);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                $portal_url = $url['url'];  
					 
					 
					 
					                $portal_url = $url['url'];  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            }  
					 
					 
					 
					            }  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -38,11 +42,11 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            if ($by_username) {  
					 
					 
					 
					            if ($by_username) {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                $secret_word = self::get_secret_word($user['email']);  
					 
					 
					 
					                $secret_word = self::get_secret_word($user['email']);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                if ($reset) {  
					 
					 
					 
					                if ($reset) {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										$reset_link = $portal_url."main/auth/lostPassword.php?reset=".$secret_word."&id=".$user['uid'];   
					 
					 
					 
					                    $reset_link = $portal_url . "main/auth/lostPassword.php?reset=" . $secret_word . "& id=" . $user['uid'];  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					                } else {  
					 
					 
					 
					                } else {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										$reset_link = get_lang('Pass'). " : $user[password]"; 
					 
					 
					 
					                    $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.''; 
					 
					 
					 
					                 $user_account_list = get_lang('YourRegistrationData')  .  " : \n"  .  get_lang('UserName')  .  ' : '  .  $user['loginName']  .  "\n"  .  get_lang('ResetLink')  .  ' : '  .  $reset_link  .  ''; 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                if ($user_account_list) {  
					 
					 
					 
					                if ($user_account_list) {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                    $user_account_list = "\n-----------------------------------------------\n" . $user_account_list;  
					 
					 
					 
					                    $user_account_list = "\n-----------------------------------------------\n" . $user_account_list;  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -51,11 +55,11 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                foreach ($user as $this_user) {  
					 
					 
					 
					                foreach ($user as $this_user) {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                    $secret_word = self::get_secret_word($this_user['email']);  
					 
					 
					 
					                    $secret_word = self::get_secret_word($this_user['email']);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                    if ($reset) {  
					 
					 
					 
					                    if ($reset) {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
											$reset_link = $portal_url."main/auth/lostPassword.php?reset=".$secret_word."&id=".$this_user['uid'];   
					 
					 
					 
					                        $reset_link = $portal_url . "main/auth/lostPassword.php?reset=" . $secret_word . "& id=" . $this_user['uid'];  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					                    } else {  
					 
					 
					 
					                    } else {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
											$reset_link = get_lang('Pass'). " : $this_user[password]"; 
					 
					 
					 
					                        $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.''; 
					 
					 
					 
					                     $user_account_list[] = get_lang('YourRegistrationData')  .  " : \n"  .  get_lang('UserName')  .  ' : '  .  $this_user['loginName']  .  "\n"  .  get_lang('ResetLink')  .  ' : '  .  $reset_link  .  ''; 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					                }  
					 
					 
					 
					                }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                if ($user_account_list) {  
					 
					 
					 
					                if ($user_account_list) {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                    $user_account_list = implode("\n-----------------------------------------------\n", $user_account_list);  
					 
					 
					 
					                    $user_account_list = implode("\n-----------------------------------------------\n", $user_account_list);  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -65,8 +69,8 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            if (!$by_username) {  
					 
					 
					 
					            if (!$by_username) {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                $user = $user[0];  
					 
					 
					 
					                $user = $user[0];  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            }  
					 
					 
					 
					            }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							    $reset_link = get_lang('Pass'). " : $user[password]"; 
					 
					 
					 
					            $reset_link = get_lang('Pass') .  " : $user[password]"; 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						       	 $user_account_list = get_lang('YourRegistrationData')." : \n".get_lang('UserName').' : '.$user['loginName']."\n".$reset_link.'';	  
					 
					 
					 
					             $user_account_list = get_lang('YourRegistrationData')  .  " : \n"  .  get_lang('UserName')  .  ' : '  .  $user['loginName']  .  "\n"  .  $reset_link  .  ''; 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        }  
					 
					 
					 
					        }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        return $user_account_list;  
					 
					 
					 
					        return $user_account_list;  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    }  
					 
					 
					 
					    }  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -77,9 +81,10 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     * @param unknown_type $user  
					 
					 
					 
					     * @param unknown_type $user  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     * @author Olivier Cauberghe < olivier.cauberghe @ UGent . be > , Ghent University  
					 
					 
					 
					     * @author Olivier Cauberghe < olivier.cauberghe @ UGent . be > , Ghent University  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     */  
					 
					 
					 
					     */  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						public static function send_password_to_user($user, $by_username = false) {	  
					 
					 
					 
					    public static function send_password_to_user($user, $by_username = false)  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        global $_configuration;  
					 
					 
					 
					        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  
					 
					 
					 
					        if ($by_username) { // Show only for lost password  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            $user_account_list = self::get_user_account_list($user, false, $by_username); // BODY  
					 
					 
					 
					            $user_account_list = self::get_user_account_list($user, false, $by_username); // BODY  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -92,13 +97,13 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        $portal_url = $_configuration['root_web'];  
					 
					 
					 
					        $portal_url = $_configuration['root_web'];  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if ($_configuration['multiple_access_urls']) {  
					 
					 
					 
					        if ($_configuration['multiple_access_urls']) {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            $access_url_id = api_get_current_access_url_id();  
					 
					 
					 
					            $access_url_id = api_get_current_access_url_id();  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								if ($access_url_id != -1  ) { 
					 
					 
					 
					            if ($access_url_id != -1 ) { 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					                $url = api_get_access_url($access_url_id);  
					 
					 
					 
					                $url = api_get_access_url($access_url_id);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                $portal_url = $url['url'];  
					 
					 
					 
					                $portal_url = $url['url'];  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            }  
					 
					 
					 
					            }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        }  
					 
					 
					 
					        }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							 $email_body = get_lang('YourAccountParam')." ".$portal_url."\n\n$user_account_list"; 
					 
					 
					 
					         $email_body = get_lang('YourAccountParam')  .  " "  .  $portal_url  .  "\n\n$user_account_list"; 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        // SEND MESSAGE  
					 
					 
					 
					        // SEND MESSAGE  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);  
					 
					 
					 
					        $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');  
					 
					 
					 
					        $email_admin = api_get_setting('emailAdministrator');  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -106,7 +111,7 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {  
					 
					 
					 
					        if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            return get_lang('your_password_has_been_reset');  
					 
					 
					 
					            return get_lang('your_password_has_been_reset');  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        } else {  
					 
					 
					 
					        } else {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								 return get_lang('SystemUnableToSendEmailContact').' '.Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')).".< / p > "; 
					 
					 
					 
					             return get_lang('SystemUnableToSendEmailContact')  .  ' '  .  Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin'))  .  ".< / p > "; 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        }  
					 
					 
					 
					        }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    }  
					 
					 
					 
					    }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -118,9 +123,10 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     *  
					 
					 
					 
					     *  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     * @author Olivier Cauberghe < olivier.cauberghe @ UGent . be > , Ghent University  
					 
					 
					 
					     * @author Olivier Cauberghe < olivier.cauberghe @ UGent . be > , Ghent University  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     */  
					 
					 
					 
					     */  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    public static function handle_encrypted_password($user, $by_username = false) {	  
					 
					 
					 
					    public static function handle_encrypted_password($user, $by_username = false)  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        global $_configuration;  
					 
					 
					 
					        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  
					 
					 
					 
					        if ($by_username) { // Show only for lost password  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            $user_account_list = self::get_user_account_list($user, true, $by_username); // BODY  
					 
					 
					 
					            $user_account_list = self::get_user_account_list($user, true, $by_username); // BODY  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -131,25 +137,25 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        }  
					 
					 
					 
					        }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        $secret_word = self::get_secret_word($email_to);  
					 
					 
					 
					        $secret_word = self::get_secret_word($email_to);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        $email_body = get_lang('DearUser')." :\n".get_lang('password_request')."\n";  
					 
					 
					 
					        $email_body = get_lang('DearUser')  .  " :\n"  .  get_lang('password_request')  .  "\n";  
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        $email_body .= $user_account_list."\n-----------------------------------------------\n\n";  
					 
					 
					 
					        $email_body .= $user_account_list  .  "\n-----------------------------------------------\n\n";  
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        $email_body .= get_lang('PasswordEncryptedForSecurity');  
					 
					 
					 
					        $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);  
					 
					 
					 
					        $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');  
					 
					 
					 
					        $email_admin = api_get_setting('emailAdministrator');  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {  
					 
					 
					 
					        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');  
					 
					 
					 
					                return get_lang('YourPasswordHasBeenEmailed');  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            } else {  
					 
					 
					 
					            } else {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed'));  
					 
					 
					 
					                Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed'));  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            }  
					 
					 
					 
					            }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        } else {  
					 
					 
					 
					        } else {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            $message = get_lang('SystemUnableToSendEmailContact').' '.Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')).".< / p > ";  
					 
					 
					 
					            $message = get_lang('SystemUnableToSendEmailContact')  .  ' '  .  Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin'))  .  ".< / p > ";  
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					            if (api_get_setting('use_custom_pages') == 'true' ) {  
					 
					 
					 
					            if (CustomPages::enabled() ) {  
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					                return $message;  
					 
					 
					 
					                return $message;  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            } else {  
					 
					 
					 
					            } else {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					                Display::display_error_message($message, false);  
					 
					 
					 
					                Display::display_error_message($message, false);  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -161,19 +167,21 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     * Gets the secret word  
					 
					 
					 
					     * Gets the secret word  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     * @author Olivier Cauberghe < olivier.cauberghe @ UGent . be > , Ghent University  
					 
					 
					 
					     * @author Olivier Cauberghe < olivier.cauberghe @ UGent . be > , Ghent University  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     */  
					 
					 
					 
					     */  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						public static function get_secret_word($add) {  
					 
					 
					 
					    public static function get_secret_word($add)  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        global $_configuration;  
					 
					 
					 
					        global $_configuration;  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							 return $secret_word = md5($_configuration['security_key'].$add); 
					 
					 
					 
					         return $secret_word = md5($_configuration['security_key']  .  $add); 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    }  
					 
					 
					 
					    }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    /**  
					 
					 
					 
					    /**  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     * Resets a password  
					 
					 
					 
					     * Resets a password  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     * @author Olivier Cauberghe < olivier.cauberghe @ UGent . be > , Ghent University  
					 
					 
					 
					     * @author Olivier Cauberghe < olivier.cauberghe @ UGent . be > , Ghent University  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					     */  
					 
					 
					 
					     */  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						public static function reset_password($secret, $id, $by_username = false) {  
					 
					 
					 
					    public static function reset_password($secret, $id, $by_username = false)  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        $tbl_user = Database::get_main_table(TABLE_MAIN_USER);  
					 
					 
					 
					        $tbl_user = Database::get_main_table(TABLE_MAIN_USER);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        $id = intval($id);  
					 
					 
					 
					        $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"; 
					 
					 
					 
					         $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);  
					 
					 
					 
					        $result = Database::query($sql);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        $num_rows = Database::num_rows($result);  
					 
					 
					 
					        $num_rows = Database::num_rows($result);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -187,11 +195,14 @@ class Login 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            $user['password'] = api_generate_password();  
					 
					 
					 
					            $user['password'] = api_generate_password();  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            $crypted = $user['password'];  
					 
					 
					 
					            $crypted = $user['password'];  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            $crypted = api_get_encrypted_password($crypted);  
					 
					 
					 
					            $crypted = api_get_encrypted_password($crypted);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								$sql = "UPDATE ".$tbl_user. " SET password='$crypted' WHERE user_id = $id"; 
					 
					 
					 
					            $sql = "UPDATE " . $tbl_user .  " SET password='$crypted' WHERE user_id = $id"; 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					            $result = Database::query($sql);  
					 
					 
					 
					            $result = Database::query($sql);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            return self::send_password_to_user($user, $by_username);  
					 
					 
					 
					            return self::send_password_to_user($user, $by_username);  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        } else {  
					 
					 
					 
					        } else {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					            return get_lang('NotAllowed');  
					 
					 
					 
					            return get_lang('NotAllowed');  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        }  
					 
					 
					 
					        }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    }  
					 
					 
					 
					    }  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					     
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					}  
					 
					 
					 
					}