diff --git a/module/user/control.php b/module/user/control.php index a1faf10717..41b07af140 100644 --- a/module/user/control.php +++ b/module/user/control.php @@ -1293,11 +1293,16 @@ class user extends control * @access public * @return string */ - public function ajaxGetGroup($visions) + public function ajaxGetGroup($visions, $i = 0) { $visions = explode(',', $visions); - $groups = $this->user->getGroupsByVisions($visions); - return print(html::select('groups[]', $groups, '', 'size=3 multiple=multiple class="form-control chosen"')); + $groupList = $this->user->getGroupsByVisions($visions); + if($i) + { + if($i > 1) $groupList = $groupList + array('ditto' => $this->lang->user->ditto); + return print(html::select("group[$i][]", $groupList, $i > 1 ? 'ditto' : '', 'size=3 multiple=multiple class="form-control chosen"')); + } + return print(html::select('group[]', $groupList, '', 'size=3 multiple=multiple class="form-control chosen"')); } /** diff --git a/module/user/js/batchcreate.js b/module/user/js/batchcreate.js index 919070450c..aa0b05134e 100644 --- a/module/user/js/batchcreate.js +++ b/module/user/js/batchcreate.js @@ -1,8 +1,8 @@ /** * Change group by role. - * - * @param string $role - * @param int $i + * + * @param string $role + * @param int $i * @access public * @return void */ @@ -10,20 +10,20 @@ function changeGroup(role, i) { if(role && roleGroup[role]) { - $('#group' + i).val(roleGroup[role]); + $('#group' + i).val(roleGroup[role]); } else { - $('#group' + i).val(''); + $('#group' + i).val(''); } $('#group' + i).trigger('chosen:updated'); } /** * Toggle checkbox and check password strength. - * - * @param object $obj - * @param int $i + * + * @param object $obj + * @param int $i * @access public * @return void */ @@ -69,3 +69,46 @@ $(document).on('click', '.chosen-with-drop', function() $(select).trigger("chosen:updated"); } }) + +$('select[id^="visions"]').each(function() +{ + var i = $(this).attr('id').replace(/[^0-9]/ig, ''); + var vision = $('#visions1 option:selected').val(); + + $.post(createLink('user', 'ajaxGetGroup', "visions=" + vision + '&i=' + i), function(data){ + $('#group' + i).replaceWith(data); + $('#group' + i + '_chosen').remove(); + $('#group' + i).chosen(); + }) +}) + +$("select[id^='visions']").change(function() +{ + var i = $(this).attr('id').replace(/[^0-9]/ig, ''); + var visions = []; + + $('select[id="visions' + i + '"] option:selected').each(function() + { + visions.push($(this).val()); + }); + + $.post(createLink('user', 'ajaxGetGroup', "visions=" + visions + '&i=' + i), function(data){ + $('#group' + i).replaceWith(data); + $('#group' + i + '_chosen').remove(); + $('#group' + i).chosen(); + }) + + for(n = i; n <= batchCreateCount; n++) + { + if($('select[id="visions' + n + '"] option:selected').val() != 'ditto' && n != i) break; + + ((function(n) + { + $.post(createLink('user', 'ajaxGetGroup', "visions=" + visions + '&i=' + n), function(data){ + $('#group' + n).replaceWith(data); + $('#group' + n + '_chosen').remove(); + $('#group' + n).chosen(); + }) + }(n))); + } +}); diff --git a/module/user/js/create.js b/module/user/js/create.js index 94f237cac4..d1cc1542b8 100644 --- a/module/user/js/create.js +++ b/module/user/js/create.js @@ -37,11 +37,10 @@ function changeVision() var link = createLink('user', 'ajaxGetGroup', 'visions=' + visions); $.post(link, function(data) { - $('#groups').replaceWith(data); - $('#groups_chosen').remove(); - $('#groups').chosen(); + $('#group').replaceWith(data); + $('#group_chosen').remove(); + $('#group').chosen(); }) - console.log(visions); } /** @@ -55,13 +54,13 @@ function changeGroup(role) { if(role && roleGroup[role]) { - $('#groups').val(roleGroup[role]); + $('#group').val(roleGroup[role]); } else { - $('#groups').val(''); + $('#group').val(''); } - $('#groups').trigger("chosen:updated"); + $('#group').trigger("chosen:updated"); } /** diff --git a/module/user/model.php b/module/user/model.php index f695823a80..43d5eb1af7 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -309,7 +309,7 @@ class userModel extends model ->setIF($this->post->password1 == false, 'password', '') ->setIF($this->post->email != false, 'email', trim($this->post->email)) ->join('visions', ',') - ->remove('new, groups, password1, password2, verifyPassword, passwordStrength') + ->remove('new, group, password1, password2, verifyPassword, passwordStrength') ->get(); if(empty($_POST['verifyPassword']) or $this->post->verifyPassword != md5($this->app->user->password . $this->session->rand)) @@ -353,9 +353,9 @@ class userModel extends model $userID = $this->dao->lastInsertID(); /* Set usergroup for account. */ - if(isset($_POST['groups'])) + if(isset($_POST['group'])) { - foreach($this->post->groups as $groupID) + foreach($this->post->group as $groupID) { $data = new stdclass(); $data->account = $this->post->account; @@ -387,7 +387,7 @@ class userModel extends model $users = fixer::input('post')->get(); $data = array(); $accounts = array(); - for($i = 0; $i < $this->config->user->batchCreate; $i++) + for($i = 1; $i < $this->config->user->batchCreate; $i++) { $users->account[$i] = trim($users->account[$i]); if($users->account[$i] != '') @@ -419,7 +419,7 @@ class userModel extends model $data[$i]->type = 'inside'; $data[$i]->realname = $users->realname[$i]; $data[$i]->role = $role; - $data[$i]->group = $users->group[$i] == 'ditto' ? (isset($prev['group']) ? $prev['group'] : '') : $users->group[$i]; + $data[$i]->group = in_array('ditto', $users->group[$i]) ? (isset($prev['group']) ? $prev['group'] : '') : $users->group[$i]; $data[$i]->email = $users->email[$i]; $data[$i]->gender = $users->gender[$i]; $data[$i]->password = md5(trim($users->password[$i])); @@ -475,12 +475,15 @@ class userModel extends model $userIDList = array(); foreach($data as $user) { - if($user->group) + if(is_array($user->group)) { - $group = new stdClass(); - $group->account = $user->account; - $group->group = $user->group; - $this->dao->replace(TABLE_USERGROUP)->data($group)->exec(); + foreach($user->group as $group) + { + $groups = new stdClass(); + $groups->account = $user->account; + $groups->group = $group; + $this->dao->insert(TABLE_USERGROUP)->data($groups)->exec(); + } } unset($user->group); $this->dao->insert(TABLE_USER)->data($user)->autoCheck()->exec(); diff --git a/module/user/view/batchcreate.html.php b/module/user/view/batchcreate.html.php index d41e71c735..2907ed280f 100644 --- a/module/user/view/batchcreate.html.php +++ b/module/user/view/batchcreate.html.php @@ -74,16 +74,16 @@ user->roleList = $lang->user->roleList + array('ditto' => $lang->user->ditto)?> $lang->user->ditto);?> $lang->user->ditto);?> - user->batchCreate; $i++):?> + user->batchCreate; $i++):?>