/** * Adds a group of users(by their IDs) to a certain group * * @access public * @param int $guid Group's ID * @param array $users Array with user id * @return mixed True on success or Jaws_Error on failure */ function AddUsersToGroup($guid, $users) { $userModel = new Jaws_User(); $group = $userModel->GetGroup((int) $guid); if (!$group) { return new Jaws_Error(_t('USERS_GROUPS_GROUP_NOT_EXIST')); } $postedUsers = array(); foreach ($users as $k => $v) { $postedUsers[$v] = $v; } $list = $userModel->GetUsers(); foreach ($list as $user) { if ($userModel->UserIsInGroup($user['id'], $guid)) { if (!isset($postedUsers[$user['id']])) { if (!$GLOBALS['app']->Session->IsSuperAdmin() && $user['superadmin']) { continue; } $userModel->DeleteUserFromGroup($user['id'], $guid); } } else { if (isset($postedUsers[$user['id']])) { $userModel->AddUserToGroup($user['id'], $guid); } } } return true; }
/** * Manage group * * @access public * @return string XHTML template of a form */ function ManageGroup() { if (!$GLOBALS['app']->Session->Logged()) { Jaws_Header::Location($this->gadget->urlMap('LoginBox', array('referrer' => bin2hex(Jaws_Utils::getRequestURL(true))))); } $this->gadget->CheckPermission('ManageUserGroups'); $gid = (int) jaws()->request->fetch('gid', 'get'); $user = $GLOBALS['app']->Session->GetAttribute('user'); // Load the template $tpl = $this->gadget->template->load('Groups.html'); $tpl->SetBlock('manage_group'); $jUser = new Jaws_User(); $group = $jUser->GetGroup($gid, $user); $response = $GLOBALS['app']->Session->PopResponse('Users.GroupMember'); if (!empty($response)) { $tpl->SetVariable('type', $response['type']); $tpl->SetVariable('text', $response['text']); } $tpl->SetVariable('title', _t('USERS_MANAGE_GROUPS', $group['title'])); $tpl->SetVariable('menubar', $this->MenuBar('Groups')); $tpl->SetVariable('submenubar', $this->SubMenuBar('Members', array('Members', 'EditGroup'), array('gid' => $gid))); $tpl->SetVariable('base_script', BASE_SCRIPT); $tpl->SetVariable('lbl_actions', _t('GLOBAL_ACTIONS')); $tpl->SetVariable('lbl_no_action', _t('GLOBAL_NO_ACTION')); $tpl->SetVariable('lbl_delete', _t('GLOBAL_DELETE')); $tpl->SetVariable('icon_ok', STOCK_OK); $tpl->SetVariable('gid', $gid); $tpl->SetVariable('lbl_edit_group', _t('USERS_EDIT_GROUP')); $tpl->SetVariable('url_edit_group', $this->gadget->urlMap('EditUserGroup', array('gid' => $gid))); $members = $jUser->GetUsers($gid); $tpl->SetVariable('lbl_members', _t('USERS_GROUPS_MEMBERS')); $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('lbl_nickname', _t('USERS_USERS_NICKNAME')); foreach ($members as $member) { $tpl->SetBlock('manage_group/member'); $tpl->SetVariable('id', $member['id']); $tpl->SetVariable('username', $member['username']); $tpl->SetVariable('nickname', $member['nickname']); // user's profile $tpl->SetVariable('user_url', $this->gadget->urlMap('Profile', array('user' => $member['username']))); $tpl->ParseBlock('manage_group/member'); } $allUsers = $jUser->GetUsers(); if (count($allUsers) != count($members)) { $tpl->SetBlock('manage_group/all_users'); $tpl->SetVariable('lbl_group_member', _t('USERS_MANAGE_GROUPS_MEMBERS')); $tpl->SetVariable('lbl_users', _t('USERS_USERS')); $tpl->SetVariable('lbl_add_user_to_group', _t('USERS_GROUPS_ADD_USER')); foreach ($allUsers as $user) { if (in_array($user, $members)) { continue; } $tpl->SetBlock('manage_group/all_users/user'); $tpl->SetVariable('user', $user['id']); $tpl->SetVariable('username', $user['username']); $tpl->SetVariable('nickname', $user['nickname']); $tpl->ParseBlock('manage_group/all_users/user'); } $tpl->ParseBlock('manage_group/all_users'); } $tpl->ParseBlock('manage_group'); return $tpl->Get(); }