Explorar o código

(branch merge)

jkbockstael %!s(int64=13) %!d(string=hai) anos
pai
achega
5f673593f2

+ 32 - 0
main/auth/conditional_login/complete_phone_number.php

@@ -0,0 +1,32 @@
+<?php
+require_once(dirname(__FILE__).'/../../inc/global.inc.php');
+require_once (api_get_path(LIBRARY_PATH).'conditionallogin.lib.php');
+require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
+$url =  api_get_path(WEB_PATH).'main/auth/conditional_login/complete_phone_number.php';
+
+if (! isset($_SESSION['conditional_login']['uid']))
+  die("Not Authorised");
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html lang="fr" xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
+  </head>
+  <body>
+  <form id="data_completion" name="data_completion" method="post" action="<?php echo $url?>">
+        Téléphone : <input type="text" name="phone_number" />
+        <input type="submit" name="submit" value="Submit" />
+    </form>
+  </body>
+</html>
+<?php
+if (isset($_POST['submit'])){
+  $u = UserManager::get_user_info_by_id($_SESSION['conditional_login']['uid']);
+  $u['phone'] = $_POST['phone_number'];
+  $password = null; // we don't want to change the password 
+  $updated = UserManager::update_user($u['user_id'], $u['firstname'], $u['lastname'], $u['username'], $password, $u['auth_source'], $u['email'], $u['status'], $u['official_code'], $u['phone'], $u['picture_uri'], $u['expiration_date'], $u['active'], $u['creator_id'], $u['hr_dept_id'], $u['extra'], $u['language'],'');
+  if ($updated) {
+    ConditionalLogin::login();
+  }
+}
+?>

+ 32 - 0
main/auth/conditional_login/conditional_login.php

@@ -0,0 +1,32 @@
+<?php
+/*
+ This scrip is included by local.inc.php to redirect users to some url if some conditions are satisfied. Please populate the $dc_conditions array with a conditional function and an url. If the conditional function returns true the user will be redirected to URL at login
+
+ This array must be filled for this module to work. This is an example asking the user to enter his phone number if it is empty. Note you can enter more than one condition in the array. They will be checked in the array order.
+*/
+$dc_conditions = array();
+//array_push($dc_conditions, array(
+//  'conditional_function' => 'dc_check_phone_number',
+//  'url' => api_get_path(WEB_PATH).'main/auth/conditional_login/complete_phone_number.php'
+//));
+//array_push($dc_conditions, array(
+//  'conditional_function' => 'dc_check_first_login',
+//  'url' => api_get_path(WEB_PATH).'main/auth/conditional_login/first_login.php'
+//));
+require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
+/*
+  Please implements the functions of the $dc_conditions array. Each of these fucntion will take a user array (user_id, username, password (crypted), auth_sourcen, active, expiration_date)
+ */
+function dc_check_phone_number($user){
+  $uInfo = UserManager::get_user_info_by_id($user['user_id']);
+  if ( empty($uInfo['phone'])) {
+    return true;
+  }
+  return false;
+}
+
+function dc_check_first_login($user){
+  $uInfo = UserManager::get_user_info_by_id($user['user_id']);
+  return(($uInfo['extra']['already_logged_in'] === 'false'));
+}
+?>

+ 1 - 0
main/auth/external_logininfo/newUser.php

@@ -84,6 +84,7 @@ if ($user !== false && ($chamilo_uid = external_add_user($user)) !== false) {
     $uidReset = true;
     $_user['user_id'] = $chamilo_uid;
     api_session_register('_uid');
+    event_login();
 } else {
 	$loginFailed = true;
 	unset($_user['user_id']);

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

@@ -0,0 +1,28 @@
+<?php
+// Conditional login
+// Used to implement the loading of custom pages
+// 2011, Noel Dieschburg <noel@cblue.be>
+
+class ConditionalLogin {
+
+  public static function check_conditions($user) {
+    if (file_exists(api_get_path(SYS_PATH).'main/auth/conditional_login/conditional_login.php')) {
+      include_once(api_get_path(SYS_PATH).'main/auth/conditional_login/conditional_login.php');
+      foreach ($dc_conditions as $dc_condition) {
+        if ($dc_condition['conditional_function']($user)) {
+          $_SESSION['conditional_login']['uid'] = $user['user_id'];
+          $_SESSION['conditional_login']['can_login'] = false;
+          header("Location:". $dc_condition['url']);
+          exit();
+        }
+      }
+    }
+  }
+
+  public static function login(){
+    $_SESSION['conditional_login']['can_login'] = true;
+    header('location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login').$param);
+    exit();
+  }
+}
+?>

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

@@ -2657,6 +2657,7 @@ function api_get_language_id($language) {
  **/
 function api_get_language_from_type($lang_type){
   global $_user;
+  global $_course;
   $toreturn = false;
   switch ($lang_type) {
   case 'platform_lang' : 
@@ -2665,16 +2666,16 @@ function api_get_language_from_type($lang_type){
       $toreturn = $temp_lang;
     break;
   case 'user_profil_lang' : 
-    if (isset($_user['language'])) 
+    if (isset($_user['language']) && !empty($_user['language']) ) 
       $toreturn = $_user['language'];
     break;
   case 'user_selected_lang' : 
-    if (isset($_SESSION['user_language_choice'])) 
+    if (isset($_SESSION['user_language_choice']) && !empty($_SESSION['user_language_choice']) ) 
       $toreturn = ($_SESSION['user_language_choice']);
     break;
   case 'course_lang' : 
-    if ($_course['language']) 
-      $language_interface = $_course['language'];
+    if ($_course['language'] && !empty($_course['language']) )  
+      $toreturn = $_course['language'];
     break;
   default : 
     $toreturn = false;

+ 1 - 0
main/inc/lib/usermanager.lib.php

@@ -162,6 +162,7 @@ class UserManager
 				$res = $res && self::update_extra_field_value($return, $fname, $fvalue);
 			}
 		}
+    self::update_extra_field_value($return, 'already_logged_in', 'false');
 		return $return;
 	}
 

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

@@ -129,12 +129,24 @@ The course id is stored in $_cid session variable.
 */
 
 require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
+require_once (api_get_path(LIBRARY_PATH).'conditionallogin.lib.php');
 
 // verified if exists the username and password in session current
 if (isset($_SESSION['info_current_user'][1]) && isset($_SESSION['info_current_user'][2])) {
 	require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
 	require_once (api_get_path(LIBRARY_PATH).'legal.lib.php');
 }
+//Conditional login
+if (isset($_SESSION['conditional_login']['uid']) && $_SESSION['conditional_login']['can_login']=== true){
+	require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
+  $uData = UserManager::get_user_info_by_id($_SESSION['conditional_login']['uid']);
+  ConditionalLogin::check_conditions($uData);
+  $_user['user_id'] = $_SESSION['conditional_login']['uid'];
+  api_session_register('_user');
+  api_session_unregister('conditional_login');
+  $uidReset=true;
+  event_login();
+} 
 // parameters passed via GET
 $logout = isset($_GET["logout"]) ? $_GET["logout"] : '';
 $gidReq = isset($_GET["gidReq"]) ? Database::escape_string($_GET["gidReq"]) : '';
@@ -243,7 +255,7 @@ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) {
     $result = Database::query($sql);
 
     if (Database::num_rows($result) > 0) {
-      $uData = Database::fetch_array($result);
+       $uData = Database::fetch_array($result);
 
       if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE) {
         //the authentification of this user is managed by Chamilo itself
@@ -313,6 +325,7 @@ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) {
                   if (is_array($my_url_list) && count($my_url_list)>0 ){
                     // the user have the permissions to enter at this site
                     if (in_array($current_access_url_id, $my_url_list)) {
+                      ConditionalLogin::check_conditions($uData);
                       $_user['user_id'] = $uData['user_id'];
                       api_session_register('_user');
                       event_login();
@@ -331,6 +344,7 @@ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) {
                 } else { //Only admins of the "main" (first) Chamilo portal can login wherever they want
                   //var_dump($current_access_url_id, $my_url_list); exit;
                   if (in_array(1, $my_url_list)) { //Check if this admin have the access_url_id = 1 which means the principal
+                    ConditionalLogin::check_conditions($uData);
                     $_user['user_id'] = $uData['user_id'];
                     api_session_register('_user');
                     event_login();
@@ -349,6 +363,7 @@ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) {
                   }
                 }
               } else {
+                ConditionalLogin::check_conditions($uData);
                 $_user['user_id'] = $uData['user_id'];
                 api_session_register('_user');
                 event_login();
@@ -774,8 +789,10 @@ if (isset($uidReset) && $uidReset) {	// session data refresh requested
 
             $is_platformAdmin        = (bool) (! is_null( $uData['is_admin']));
             $is_allowedCreateCourse  = (bool) (($uData ['status'] == 1) or (api_get_setting('drhCourseManagerRights') and $uData['status'] == 4));
+            ConditionalLogin::check_conditions($uData);
 
             api_session_register('_user');
+            UserManager::update_extra_field_value($_user['user_id'], 'already_logged_in', 'true');
         } else {
         	header('location:'.api_get_path(WEB_PATH));
             //exit("WARNING UNDEFINED UID !! ");

+ 5 - 4
main/install/db_main.sql

@@ -791,10 +791,10 @@ VALUES
 ('custom_tab_2_url', NULL, 'textfield', 'Platform', '', 'CustomTab2URLTitle', 'CustomTab2URLComment', NULL, NULL, 0),
 ('custom_tab_3_name', NULL, 'textfield', 'Platform', '', 'CustomTab3NameTitle', 'CustomTab3NameComment', NULL, NULL, 0),
 ('custom_tab_3_url', NULL, 'textfield', 'Platform', '', 'CustomTab3URLTitle', 'CustomTab3URLComment', NULL, NULL, 0),
-('languagePriority1', NULL, 'radio', 'Languages', '', 'LanguagePriority1Title', 'LanguagePriority1Comment', NULL, NULL, 0),
-('languagePriority2', NULL, 'radio', 'Languages','', 'LanguagePriority2Title', 'LanguagePriority2Comment', NULL, NULL, 0), 
-('languagePriority3', NULL, 'radio', 'Languages','', 'LanguagePriority3Title', 'LanguagePriority3Comment', NULL, NULL, 0), 
-('languagePriority4', NULL, 'radio', 'Languages', '','LanguagePriority4Title', 'LanguagePriority4Comment', NULL, NULL, 0),
+('languagePriority1', NULL, 'radio', 'Languages', 'course_lang', 'LanguagePriority1Title', 'LanguagePriority1Comment', NULL, NULL, 0),
+('languagePriority2', NULL, 'radio', 'Languages','user_profil_lang', 'LanguagePriority2Title', 'LanguagePriority2Comment', NULL, NULL, 0), 
+('languagePriority3', NULL, 'radio', 'Languages','user_selected_lang', 'LanguagePriority3Title', 'LanguagePriority3Comment', NULL, NULL, 0), 
+('languagePriority4', NULL, 'radio', 'Languages', 'platform_lang','LanguagePriority4Title', 'LanguagePriority4Comment', NULL, NULL, 0),
 ('activate_send_event_by_mail', NULL, 'radio', 'Platform', 'false', 'ActivateSendEventByMailTitle', 'ActivateSendEventByMailComment', NULL, NULL, 0);
 
 
@@ -2324,6 +2324,7 @@ CREATE TABLE legal (
 );
 
 INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable) values (1, 'legal_accept','Legal',0,0);
+INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable) values (1, 'already_logged_in','Already logged in',0,0);
 
 --
 -- Table structure for certificate with gradebook

+ 5 - 4
main/install/migrate-db-1.8.6.2-1.8.7-pre.sql

@@ -136,12 +136,13 @@ CREATE TABLE `event_type_message` (`id` int(11) NOT NULL AUTO_INCREMENT, `event_
 CREATE TABLE `user_rel_event_type` (`id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `event_type_id` int(11) NOT NULL, PRIMARY KEY (`id`));
 INSERT INTO `event_type` VALUES (1, 'course_deleted','courseDeletedTitle','courseDeletedComment'),(2,'course_created','courseCreatedTitle','courseCreatedComment'),(3,'user_deleted','userDeletedTitle','userDeletedComment'),(4,'user_created','userCreatedTitle','userCreatedComment'), (5, 'session_created','sessionCreatedTitle','sessionCreatedComment'), (6,'session_deleted','sessionDeletedTitle','sessionDeletedComment'), (7,'session_category_created','sessionCategoryCreatedTitle','sessionCategoryCreatedComment'),(8,'session_category_deleted','sessionCategoryDeletedTitle','sessionCategoryDeletedComment'),(9,'settings_changed','settingsChangedTitle','settingsChangedComment'),(10,'user_subscribed','userSubscribedTitle','userSubscribedComment'), (11,'user_unsubscribed','userUnsubscribedTitle','userUnsubscribedComment');
 INSERT INTO `event_type_message` (`id`,`event_type_id`, `language_id`, `message`,`subject`) VALUES (1,4,10,'Bonjour, \r\n\r\nL\'utilisateur %username% (%firstname% %lastname%) a été créé.\r\nEmail : %mail%\r\n\r\nBien à vous.',''),(2,1,10,'Delete formation',''),(3,2,10,'Create formation',''),(4,3,10,'Bonjour, \r\n\r\nL\'utilisateur %username% (%firstname% %lastname%) a été supprimé.\r\n\r\nBien à vous.',''),(6,5,10,'Create session test',''),(7,6,10,'Delete session',''),(8,7,10,'Create category session',''),(9,8,10,'Delete category session',''),(10,9,10,'Change setting',''),(11,10,10,'Subscribe',''),(12,11,10,'Unsubscribe','');
+INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable) values (1, 'already_logged_in','Already logged in',0,0);
 CREATE TABLE announcement_rel_group (group_id int NOT NULL, announcement_id int NOT NULL, PRIMARY KEY (group_id, announcement_id));
 
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES  ('languagePriority1', NULL, 'radio', 'Languages', '', 'LanguagePriority1Title', 'LanguagePriority1Comment', NULL, NULL, 0); 
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('languagePriority2', NULL, 'radio', 'Languages', '', 'LanguagePriority2Title', 'LanguagePriority2Comment', NULL, NULL, 0); 
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('languagePriority3', NULL, 'radio', 'Languages', '', 'LanguagePriority3Title', 'LanguagePriority3Comment', NULL, NULL, 0); 
-INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('languagePriority4', NULL, 'radio', 'Languages', '', 'LanguagePriority4Title', 'LanguagePriority4Comment', NULL, NULL, 0); 
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES  ('languagePriority1', NULL, 'radio', 'Languages', 'course_lang', 'LanguagePriority1Title', 'LanguagePriority1Comment', NULL, NULL, 0); 
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('languagePriority2', NULL, 'radio', 'Languages', 'user_profil_lang', 'LanguagePriority2Title', 'LanguagePriority2Comment', NULL, NULL, 0); 
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('languagePriority3', NULL, 'radio', 'Languages', 'user_selected_lang', 'LanguagePriority3Title', 'LanguagePriority3Comment', NULL, NULL, 0); 
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('languagePriority4', NULL, 'radio', 'Languages', 'platform_lang', 'LanguagePriority4Title', 'LanguagePriority4Comment', NULL, NULL, 0); 
 INSERT INTO settings_options (variable, value, display_text) VALUES ('languagePriority1','platform_lang','PlatformLanguage'), ('languagePriority1','user_profil_lang','UserLanguage'), ('languagePriority1','user_selected_lang','UserSelectedLanguage'), ('languagePriority1','course_lang','CourseLanguage'), ('languagePriority2','platform_lang','PlatformLanguage'), ('languagePriority2','user_profil_lang','UserLanguage'), ('languagePriority2','user_selected_lang','UserSelectedLanguage'), ('languagePriority2','course_lang','CourseLanguage'), ('languagePriority3','platform_lang','PlatformLanguage'), ('languagePriority3','user_profil_lang','UserLanguage'), ('languagePriority3','user_selected_lang','UserSelectedLanguage'), ('languagePriority3','course_lang','CourseLanguage'), ('languagePriority4','platform_lang','PlatformLanguage'), ('languagePriority4','user_profil_lang','UserLanguage'), ('languagePriority4','user_selected_lang','UserSelectedLanguage'), ('languagePriority4','course_lang','CourseLanguage');