Browse Source

manual merge

Yannick Warnier 11 years ago
parent
commit
91d094fa95
3 changed files with 43 additions and 17 deletions
  1. 17 7
      main/admin/user_import.php
  2. 10 10
      main/admin/user_list.php
  3. 16 0
      main/inc/lib/usergroup.lib.php

+ 17 - 7
main/admin/user_import.php

@@ -16,6 +16,7 @@ require '../inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
 require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(LIBRARY_PATH).'classmanager.lib.php';
+require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
 require_once api_get_path(LIBRARY_PATH).'import.lib.php';
 
 // Set this option to true to enforce strict purification for usenames.
@@ -65,10 +66,14 @@ function validate_data($users)
             $errors[] = $user;
         }
         // 4. Check classname
+        $usergroup = new UserGroup();
         if (!empty($user['ClassName'])) {
-            if (!ClassManager :: class_name_exists($user['ClassName'])) {
-                $user['error'] = get_lang('ClassNameNotAvailable');
-                $errors[] = $user;
+            $className = explode('|', trim($user['ClassName']));
+            foreach ($className as $class) {
+                if (!$usergroup->usergroup_exists($class)) {
+                    $user['error'] = get_lang('ClassNameNotAvailable');
+                    $errors[] = $user;
+                }
             }
         }
         // 5. Check authentication source
@@ -171,12 +176,17 @@ function save_data($users)
                     }
                 }
             }
-
+            $usergroup = new UserGroup();
             if (!empty($user['ClassName'])) {
-                $class_id = ClassManager :: get_class_id($user['ClassName']);
-                ClassManager :: add_user($user_id, $class_id);
+                $className = explode('|', trim($user['ClassName']));
+                foreach ($className as $class) {
+                    $classId = $usergroup->get_id_by_name($class);
+                    $usergroup->addUser($user_id, $classId);
+                }
+                
             }
 
+
             // Saving extra fields.
             global $extra_fields;
 
@@ -475,4 +485,4 @@ if ($count_fields > 0) {
 </pre>
     </blockquote>
 <?php
-Display :: display_footer();
+Display :: display_footer();

+ 10 - 10
main/admin/user_list.php

@@ -654,16 +654,16 @@ if (!empty($action)) {
                 break;
 			case 'show_message' :
                 if (!empty($_GET['message'])) {
-                    $message = Display :: return_message(stripslashes($_GET['message']), 'confirmation');
-                }
-
-                if (!empty($_GET['warn'])) {
-                	// to prevent too long messages
-                	if ($_GET['warn'] == 'session_message'){
-                        $_GET['warn'] = $_SESSION['session_message_import_users'];
-                	}
-                	$message = Display::return_message(urldecode($_GET['warn']),'warning', false);
-                }
+                    $message = Display::return_message(stripslashes($_GET['message']), 'confirmation');
+                } else {
+                    if (!empty($_GET['warn'])) {
+                        // to prevent too long messages
+                    	if ($_GET['warn'] == 'session_message'){
+                            $_GET['warn'] = $_SESSION['session_message_import_users'];
+                    	}
+                    	$message = Display::return_message(Security::remove_XSS($_GET['warn']), 'warning', false);
+                    }
+               }
 
 				break;
 			case 'delete_user' :

+ 16 - 0
main/inc/lib/usergroup.lib.php

@@ -839,5 +839,21 @@ class UserGroup extends Model
         return $response;
 
     }
+    /**
+    * Add a user to a class. If the class is subscribed to a course, the new
+    * user will also be subscribed to that course.
+    * @param int $user_id The user id
+    * @param int $class_id The class id
+    */
+    public function addUser($userId, $classId)
+    {   
+        $table_rel_user = Database::get_main_table(TABLE_USERGROUP_REL_USER);
+        $userId  = intval($userId);
+        $classId = intval($classId);
+        $sql = "INSERT INTO $table_rel_user SET user_id = '".$userId."', usergroup_id='".$classId."'";
+	 Database::query($sql);
+    }
+    
+       
 }
 /* CREATE TABLE IF NOT EXISTS access_url_rel_usergroup (access_url_id int unsigned NOT NULL, usergroup_id int unsigned NOT NULL, PRIMARY KEY (access_url_id, usergroup_id));*/