Create new users cvs directly in class (usergroup) -ref #6680

1.9.x
baelmyhu 11 years ago
parent d7551fdfaf
commit 1e3b364cad
  1. 20
      main/admin/user_import.php
  2. 19
      main/inc/lib/usergroup.lib.php

@ -65,12 +65,12 @@ function validate_data($users)
$user['error'] = get_lang('WrongStatus');
$errors[] = $user;
}
// 4. Check classname
// 4. Check classid
$usergroup = new UserGroup();
if (!empty($user['ClassName'])) {
$className = explode('|', trim($user['ClassName']));
foreach ($className as $class) {
if (!$usergroup->usergroup_exists($class)) {
if (!empty($user['ClassId'])) {
$classId = explode('|', trim($user['ClassId']));
foreach ($classId as $id) {
if (!UserGroup::usergroupIdExists($id)) {
$user['error'] = get_lang('ClassNameNotAvailable');
$errors[] = $user;
}
@ -177,16 +177,14 @@ function save_data($users)
}
}
$usergroup = new UserGroup();
if (!empty($user['ClassName'])) {
$className = explode('|', trim($user['ClassName']));
foreach ($className as $class) {
$classId = $usergroup->get_id_by_name($class);
$usergroup->addUser($user_id, $classId);
if (!empty($user['ClassId'])) {
$classId = explode('|', trim($user['ClassId']));
foreach ($classId as $id) {
$usergroup->addUser($user_id, $id);
}
}
// Saving extra fields.
global $extra_fields;

@ -851,9 +851,22 @@ class UserGroup extends Model
$userId = intval($userId);
$classId = intval($classId);
$sql = "INSERT INTO $table_rel_user SET user_id = '".$userId."', usergroup_id='".$classId."'";
Database::query($sql);
Database::query($sql);
}
/**
* Return true if usergroup with id=$inId existes in the database
* @param int $inId
* @return bool
*/
public static function usergroupIdExists($inId)
{
$row = Database::select('count(*) as count', Database::get_main_table(TABLE_USERGROUP), array('where' => array("id = ?" => $inId)), 'first');
return ($row['count'] > 0);
}
}
/* 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));*/

Loading…
Cancel
Save