/** * Save imported class data to database * * @param $classes * * @return int */ function save_data($classes) { $count = 0; $usergroup = new UserGroup(); foreach ($classes as $index => $class) { $usersToAdd = isset($class['users']) ? $class['users'] : null; unset($class['users']); $id = $usergroup->save($class); if ($id) { if (!empty($usersToAdd)) { $usersToAddList = explode(',', $usersToAdd); $userIdList = array(); foreach ($usersToAddList as $username) { $userInfo = api_get_user_info_from_username($username); $userIdList[] = $userInfo['user_id']; } if (!empty($userIdList)) { $usergroup->subscribe_users_to_usergroup($id, $userIdList, false); } } $count++; } } return $count; }
public function groups($nickname = null) { $user = $this->load_user($nickname); $this->assign("user", $user); if ($this->post && isset($_POST['group_id'])) { $group = Group::find_by_iD($_POST['group_id']); if ($group) { $userGroup = new UserGroup(); $userGroup->group_id = $group->id; $userGroup->user_id = $user->id; if ($userGroup->save()) { Site::Flash('notice', 'The user has been added to the group'); Redirect("admin/users/" . $user->permalink() . '/groups'); } } } $userGroups = array(); foreach ($user->groups() as $ug) { $userGroups[] = $ug->id; } $allGroups = Group::find_all(); $groups = array(); foreach ($allGroups as $group) { if (in_array($group->id, $userGroups)) { continue; } $groups[$group->id] = $group->name; } $this->assign('groups', $groups); $this->title = "{$user->nickname} :: Groups"; $this->render("user/groups.tpl"); }
/** * Called before the controller action. You can use this method to configure and customize components * or perform logic that needs to happen before each controller action. * * @param object $c current controller object * @return void */ function beforeFilter(&$c) { $user = $this->__getActiveUser(); UsermgmtInIt($this); $pageRedirect = $c->Session->read('permission_error_redirect'); $c->Session->delete('permission_error_redirect'); $controller = $c->params['controller']; $action = $c->params['action']; $actionUrl = $controller . '/' . $action; $requested = isset($controller->params['requested']) && $controller->params['requested'] == 1 ? true : false; $permissionFree = array('users/login', 'users/logout', 'users/register', 'users/userVerification', 'users/forgotPassword', 'users/activatePassword', 'pages/display', 'users/accessDenied', 'users/customer_register', 'users/customer_login'); if ((empty($pageRedirect) || $actionUrl != 'users/login') && !$requested && !in_array($actionUrl, $permissionFree)) { App::import("Model", "Usermgmt.UserGroup"); $userGroupModel = new UserGroup(); if (!$this->isLogged()) { if (!$userGroupModel->isGuestAccess($controller, $action)) { $c->log('permission: actionUrl-' . $actionUrl, LOG_DEBUG); $c->Session->write('permission_error_redirect', '/users/login'); $c->Session->setFlash('You need to be signed in to view this page.'); $c->Session->write('Usermgmt.OriginAfterLogin', '/' . $c->params->url); $c->redirect('/login'); } } else { if (!$userGroupModel->isUserGroupAccess($controller, $action, $this->getGroupId())) { $c->log('permission: actionUrl-' . $actionUrl, LOG_DEBUG); $c->Session->write('permission_error_redirect', '/users/login'); $c->redirect('/accessDenied'); } } } }
function load_groupcp() { global $mybb, $db, $cache, $templates, $title, $header, $headerinclude, $footer, $theme, $group; if ($mybb->settings['rpgsuite_groupmanagecp'] && $mybb->input['action'] == "managegroup") { // Get group id if ($mybb->input['gid'] && $mybb->usergroup['issupermod']) { $gid = intval($mybb->input['gid']); $groupnav = '&gid=' . $gid; } else { $gid = $mybb->user['displaygroup']; $groupnav = ''; } $cpcontent = ""; if ($mybb->settings['rpgsuite_groupranks_custom']) { $customranklink = '<a href="modcp.php?action=managegroup§ion=customranks' . $groupnav . '">Manage Custom Ranks</a>'; } else { $customranklink = ''; } $usergroup = new UserGroup($mybb, $db, $cache); if ($usergroup->initialize($gid)) { $group = $usergroup->get_info(); if (handle_form($usergroup)) { $url = "modcp.php?action=managegroup&gid=" . $gid; if ($mybb->input['section']) { $url .= "§ion=" . $mybb->input['section']; } redirect($url, "Your pack settings were successfully updated."); } if ($mybb->input['section'] == 'groupoptions') { $title = 'Manage Options'; add_breadcrumb('Manage Options'); $cpcontent = load_groupmod_options($usergroup); } else { if ($mybb->input['section'] == 'groupmembers') { $title = 'Manage Members'; add_breadcrumb('Manage Members'); $cpcontent = load_groupmod_members($usergroup); } else { if ($mybb->input['section'] == 'customranks' && $mybb->settings['rpgsuite_groupranks_custom']) { $ttile = 'Manage Custom Ranks'; add_breadcrumb('Manage Custom Ranks'); $cpcontent = load_groupmod_customranks($usergroup); } else { $title = 'Manage Ranks'; add_breadcrumb('Manage Ranks'); $cpcontent = load_groupmod_ranks($usergroup); } } } // Add group styling eval("\$headerinclude .= \"" . $templates->get('rpgmisc_groupstyle') . "\";"); } else { $cpcontent = "Invalid Group"; } eval("\$groupmanagecp = \"" . $templates->get('rpggroupmanagecp_full') . "\";"); output_page($groupmanagecp); exit; } }
function update_display_group($uid, $gid) { global $mybb, $db, $cache; $usergroup = new UserGroup($mybb, $db, $cache); if ($usergroup->initialize($gid)) { $usergroup->add_member($uid); } }
public function setUp() { parent::setUp(); $this->role = Role::getNewInstance('__testrole__'); $this->role->save(); $this->userGroup = UserGroup::getNewInstance('Any random group name'); $this->userGroup->save(); }
public function GetPermissions($objectId) { $userGroup = new UserGroup(); if (!($result = $userGroup->GetPermissionsForObject('lkcampaigngroup', 'CampaignID', $objectId))) { return $this->SetError($userGroup->GetErrorMessage()); } return $result; }
/** * Assign the user to a group * * @param Entity\UserGroup $group * @return void */ public function setGroup(UserGroup $group) { $this->group = $group; // The association must be defined in both directions if (!$group->getUsers()->contains($this)) { $group->addUser($this); } }
public function createFromArray($data) { $data = (object) $data; $instance = new UserGroup(); $instance->setId($data->id); $instance->setName($data->name); return $instance; }
function addUserGroupSubmit($p) { $grp = new UserGroup(); $grp->setName($p['name']); $grp->setInfo($p['info']); $grp->setLevel($p['level']); $grp->save(); redir('a/usergroups'); }
public function addUser($oUser) { if ($this->containsUser($oUser)) { return; } $oUserGroup = new UserGroup(); $oUserGroup->setUser($oUser); $this->addUserGroup($oUserGroup); }
function saveUserGroupSubmit($p) { $grp = new UserGroup($p['g_id']); $grp->setName($p['name']); $grp->setInfo($p['info']); $grp->setLevel($p['level']); $grp->save(); return true; }
/** * Callback method that will be called in place of the effect() * method of a mock policy. * @return integer AUTHORIZATION_PERMIT */ public function mockEffect() { // Add a user group to the authorized context // of the authorization context manipulation policy. $policy = $this->getAuthorizationContextManipulationPolicy(); $userGroup = new UserGroup(); $userGroup->setRoleId(ROLE_ID_TEST); $policy->addAuthorizedContextObject(ASSOC_TYPE_USER_GROUP, $userGroup); return AUTHORIZATION_PERMIT; }
/** * add user to groups * * @param array $group_name */ public function addToGroups($group_name) { $group_ids = Group::findGroupIdByNames($group_name); foreach ($group_ids as $group_id) { $user_group = new UserGroup(); $user_group->user_id = $this->getId(); $user_group->group_id = $group_id; $user_group->save(); } }
function checkIdeabox($id = 0) { global $db, $langs; if (isset($id) && $id > 0) { $usergroup = new UserGroup($db); return $usergroup->listGroupsForUser($id); } else { return false; } }
public function run() { $model = new UserGroup(); if (isset($_POST['UserGroup'])) { $model->attributes = $_POST['UserGroup']; $model->acl = isset($_POST['acls']) ? $_POST['acls'] : array(); if ($model->save()) { $this->controller->message('success', Yii::t('admin', 'Add Success'), $this->controller->createUrl('index')); } } $this->controller->render('create', array('model' => $model, 'acls' => $this->controller->acl())); }
/** * Save imported class data to database */ function save_data($classes) { $number_of_added_classes = 0; $usergroup = new UserGroup(); foreach ($classes as $index => $class) { $id = $usergroup->save($class); if ($id) { $number_of_added_classes++; } } return $number_of_added_classes; }
/** * 保存用户到用户组 */ static function UserGroupSave($user_id, $group) { \Yii::app()->db->createCommand()->update('users', array('yourself' => $_POST['self'] ? 1 : 0), 'id=:id', array('id' => $user_id)); if ($group) { UserGroup::model()->deleteAllByAttributes(array('user_id' => $user_id)); foreach ($group as $group_id) { $model = new UserGroup(); $model->group_id = $group_id; $model->user_id = $user_id; $model->save(); } } }
public function run() { $model = new UserGroup(); //条件 $criteria = new CDbCriteria(); $count = $model->count($criteria); //分页 $pages = new CPagination($count); $pages->pageSize = 10; $pages->applyLimit($criteria); //查询 $result = $model->findAll($criteria); $this->controller->render('index', array('datalist' => $result, 'pages' => $pages)); }
public function ListSecurity($dataSetId, $groupId) { if ($dataSetId == 0 || $dataSetId == '') { return $this->SetError(25001, __('Missing dataSetId')); } $userGroup = new UserGroup(); if (!($result = $userGroup->GetPermissionsForObject('lkdatasetgroup', 'DataSetID', $dataSetId))) { return $this->SetError($userGroup->GetErrorMessage()); } $security = array(); foreach ($result as $row) { $security[] = array('groupid' => Kit::ValidateParam($row['groupid'], _INT), 'group' => Kit::ValidateParam($row['group'], _STRING), 'view' => Kit::ValidateParam($row['view'], _INT), 'edit' => Kit::ValidateParam($row['edit'], _INT), 'del' => Kit::ValidateParam($row['del'], _INT), 'isuserspecific' => Kit::ValidateParam($row['isuserspecific'], _INT)); } return $security; }
function rankview_bit($gid) { global $db, $mybb, $cache; $usergroup = new UserGroup($mybb, $db, $cache); if ($usergroup->initialize($gid)) { $group = $usergroup->get_info(); if ($group['hasranks']) { return "Viewing <a href='index.php?action=showranks&gid=" . $gid . "'>" . $group['title'] . " Ranks</a>"; } else { return "Viewing <a href='index.php?action=showranks&gid=" . $gid . "'>" . $group['title'] . " Members</a>"; } } else { return "Viewing <a href='index.php?action=showranks'>Group Members</a>"; } }
function showUpdate($id = 0) { $this->data['id'] = $id; $this->data['groups'] = UserGroup::get(); // WHEN UPDATE SHOW CURRENT INFOMATION if ($id != 0) { $item = $this->model->find($id); // CHECK SUPER USER if ($item->isSuperUser()) { return Redirect::to($this->moduleURL . 'show-list'); } // END SUPER USER $item->group = $item->getGroups()->first(); if ($item) { $this->data['item'] = $item; } else { return Redirect::to($this->moduleURL . 'show-list'); } } if (Request::isMethod('post')) { if ($this->postUpdate($id, $this->data)) { return $this->redirectAfterSave(Input::get('save')); } } $this->layout->content = View::make('showUpdate', $this->data); }
public function getAll() { if (!isset($this->Elements) || $this->countElements() < 0) { return UserGroup::getEmptyInstance(); } return $this->Elements; }
function GroupBuilder($_reqGroup = "", $_reqOperator = "", $allowCom = true) { $reqGroup = UserGroup::ReadParams(); $this->ReqGroup = !empty($reqGroup) ? $reqGroup : $_reqGroup; $this->ReqOperator = !empty($_GET[GET_EXTERN_INTERN_USER_ID]) ? Encoding::Base64UrlDecode($_GET[GET_EXTERN_INTERN_USER_ID]) : $_reqOperator; $this->GroupValues["groups_online"] = array(); $this->GroupValues["groups_offline"] = array(); $this->GroupValues["groups_online_amounts"] = array(); $this->GroupValues["groups_output"] = array(); $this->GroupValues["groups_hidden"] = array(); $this->GroupValues["set_by_get_user"] = null; $this->GroupValues["set_by_get_group"] = null; $this->GroupValues["set_by_cookie"] = null; $this->GroupValues["set_by_standard"] = null; $this->GroupValues["set_by_online"] = null; $this->GroupValues["req_for_user"] = !empty($this->ReqOperator); $this->GroupValues["req_for_group"] = !empty($this->ReqGroup); $this->Parameters = Communication::GetTargetParameters($allowCom); if ($this->Parameters["include_group"] != null || $this->Parameters["include_user"] != null) { foreach (Server::$Groups as $gid => $group) { if (!($this->Parameters["include_group"] != null && in_array($gid, $this->Parameters["include_group"]))) { if (!($this->Parameters["include_user"] != null && in_array($gid, Server::$Operators[Operator::GetSystemId($this->Parameters["include_user"])]->GetGroupList(false)))) { $this->GroupValues["groups_hidden"][] = $gid; } } } } if ($this->Parameters["exclude"] != null) { $this->GroupValues["groups_hidden"] = $this->Parameters["exclude"]; } }
public function setUp() { ActiveRecordModel::getApplication()->clearCachedVars(); ActiveRecordModel::beginTransaction(); if (empty($this->autoincrements)) { foreach ($this->getUsedSchemas() as $table) { $res = $this->db->executeQuery("SHOW TABLE STATUS LIKE '{$table}'"); $res->next(); $this->autoincrements[$table] = (int) $res->getInt("Auto_increment"); } } if ($this instanceof BackendControllerTestCase) { ClassLoader::import('application.model.user.SessionUser'); ClassLoader::import('application.model.user.UserGroup'); // set up user $group = UserGroup::getNewInstance('Unit tester'); $group->save(); $group->setAllRoles(); $group->save(); $user = User::getNewInstance('*****@*****.**', null, $group); $user->save(); SessionUser::setUser($user); } if ($this instanceof ControllerTestCase) { $this->request = self::getApplication()->getRequest(); } }
/** * Set up needed stuff for the plugin **/ public function install() { Post::add_new_type('project'); // Give anonymous users access $group = UserGroup::get_by_name('anonymous'); $group->grant('post_project', 'read'); }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { UserGroup::create([]); } }
public function action_plugin_activation($file) { DB::register_table('abbrev'); /* * Create the database table, or upgrade it */ $dbms = DB::get_driver_name(); $sql = 'CREATE TABLE ' . DB::table('abbrev') . ' ' . '('; if ($dbms == 'sqlite') { $sql .= 'xid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,'; } else { if ($dbms == 'mysql') { $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT,' . 'UNIQUE KEY xid (xid),'; } else { $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT,' . 'UNIQUE KEY xid (xid),'; } } $sql .= 'abbrev VARCHAR(255),' . 'caseful INTEGER DEFAULT 0,' . "prefix VARCHAR(16) DEFAULT '\\b'," . "postfix VARCHAR(16) DEFAULT '\\b'," . 'priority INTEGER DEFAULT 100,' . 'definition VARCHAR(255)' . ')'; if (!DB::dbdelta($sql)) { Utils::debug(DB::get_errors()); } if ($file == str_replace('\\', '/', $this->get_file())) { ACL::create_token(self::PLUGIN_TOKEN, _t('Allow use of Abbrev plugin'), 'Category', false); $group = UserGroup::get_by_name('admin'); $group->grant(self::PLUGIN_TOKEN); } }
function write_user_list() { $this->write_block_begin('User list'); $this->write_form_begin('user_group_add.php', 'get'); $this->write_form_preserve('redirect'); echo '<label>Search for users: '; $this->write_form_field('text', 'user_filter', @$_REQUEST['user_filter']); echo '</label>'; $this->write_form_end('Show'); echo '<small>Make sure your lab partner has logged in with Justitia at least once.</small>'; if (!isset($_REQUEST['user_filter'])) { return; } $filter = '%' . @$_REQUEST['user_filter'] . '%'; echo '<table class="user-list">' . "\n"; $users = User::all($filter); foreach ($users as $user) { echo '<tr>'; echo '<td>', htmlspecialchars($user->name_and_login()), '</td>'; if (UserGroup::contains($user)) { echo '<td>[already in group]</td>'; } else { echo '<td><a href="user_group_add.php?add=' . $user->userid . '&redirect=' . urlencode($_REQUEST['redirect']) . '">[add to group]</a></td>'; } echo "</tr>\n"; } echo '</table>'; $this->write_block_end(); }
/** * Create a new UserGroup object and save it to the database * @param array $paramarray An associative array of UserGroup fields * @return UserGroup the UserGroup that was created * @todo Make this function accept only a name, since you can't set an id into an autoincrement field, and we don't try. */ public static function create($paramarray) { $usergroup = new UserGroup($paramarray); if ($usergroup->insert()) { return $usergroup; } else { // Does the group already exist? if (isset($paramarray['name'])) { $exists = DB::get_value('SELECT count(1) FROM {groups} WHERE name = ?', array($paramarray['name'])); if ($exists) { return UserGroup::get_by_name($paramarray['name']); } } return false; } }