public function routes(&$router) { // Get all contact groups $router->get('/contacts/groups', function () use($router) { $groups = ContactsGroups::load($GLOBALS['user']->id); $users = array(); foreach ($groups as $index => $group) { $members = ContactsGroups::loadMembers($GLOBALS['user']->id, $group['group_id']); if (!$router->compact()) { foreach ($members as $user_id) { if (!isset($users[$user_id])) { $user = $router->dispatch('get', '/user(/:user_id)', $user_id); $users[$user_id] = $user['user']; } } } $groups[$index]['members'] = $members; } $router->render($router->compact() ? compact('groups') : compact('groups', 'users')); }); // Create new contact group $router->post('/contacts/groups', function () use($router) { $name = trim(Request::get('name')); if (!$name) { $router->halt(406, 'No name provided'); } AddNewStatusgruppe($name, $GLOBALS['user']->id, 0); $router->render($router->dispatch('get', '/contacts/groups')); }); // Get members of contact group $router->get('/contacts/groups/:group_id', function ($group_id) use($router) { if (!ContactsGroups::exists($group_id)) { $router->halt(404, 'Contact group "%s" not found', $group_id); } $members = ContactsGroups::loadMembers($GLOBALS['user']->id, $group_id); if ($router->compact()) { $router->render(compact('members')); } $users = array(); foreach ($members as $user_id) { $user = $router->dispatch('get', '/user(/:user_id)', $user_id); $users[] = $user['user']; } $router->render(compact('members', 'users')); }); // Remove contact group $router->delete('/contacts/groups/:group_id', function ($group_id) use($router) { if (!ContactsGroups::exists($group_id)) { $router->halt(404, 'Contact group "%s" not found', $group_id); } DeleteStatusgruppe($group_id); $router->halt(200, 'Contact group "%s" has been deleted', $group_id); }); // Put a user into contact group $router->put('/contacts/groups/:group_id/:user_id', function ($group_id, $user_id) use($router) { if (!ContactsGroups::exists($group_id)) { $router->halt(404, 'Contact group "%s" not found', $group_id); } $user = \User::find($user_id); if (!$user) { $router->halt(404, 'User "%s" not found', $user_id); } if (!InsertPersonStatusgruppe($user_id, $group_id)) { $router->halt(500); } $router->render($router->dispatch('get', '/contacts/groups/:group_id', $group_id)); }); // Remove user from contact group $router->delete('/contacts/groups/:group_id/:user_id', function ($group_id, $user_id) use($router) { if (!ContactsGroups::exists($group_id)) { $router->halt(404, 'Contact group "%s" not found', $group_id); } $user = \User::find($user_id); if (!$user) { $router->halt(404, 'User "%s" not found', $user_id); } $username = $user->username; RemovePersonStatusgruppe($username, $group_id); $router->halt(200); }); }
/** * Assign/add a user to a statusgruppe. */ public function assign_action() { $this->check_ticket(); $role_id = Request::option('role_id'); if ($role_id) { $group = new Statusgruppe($role_id); $range_id = $group->getRange_id(); $group = new Statusgruppe($range_id); while ($group->getRange_id()) { $range_id = $group->getRange_id(); $group = new Statusgruppe($range_id); } if (InsertPersonStatusgruppe($this->user->user_id, $role_id)) { $globalperms = get_global_perm($this->user->user_id); $query = "INSERT IGNORE INTO user_inst (Institut_id, user_id, inst_perms)\n VALUES (?, ?, ?)\n ON DUPLICATE KEY UPDATE inst_perms = VALUES(inst_perms)"; $statement = DBManager::get()->prepare($query); $statement->execute(array($range_id, $this->user->user_id, $globalperms)); if ($statement->rowCount() == 1) { log_event('INST_USER_ADD', $range_id, $this->user->user_id, $globalperms); } else { if ($statement->rowCount() == 2) { log_event('INST_USER_STATUS', $range_id, $this->user->user_id, $globalperms); } } checkExternDefaultForUser($this->user->user_id); $_SESSION['edit_about_data']['open'] = $role_id; $this->reportSuccess(_('Die Person wurde in die ausgewählte Gruppe eingetragen!')); } else { $this->reportError(_('Fehler beim Eintragen in die Gruppe!')); } } $this->redirect('settings/statusgruppen#' . $role_id); }
function addToStatusgroup($range_id, $statusgruppe_id, $workgroup_mode) { $mp = MultiPersonSearch::load("contacts_statusgroup_" . $statusgruppe_id); if (count($mp->getAddedUsers()) !== 0) { foreach ($mp->getAddedUsers() as $m) { $quickfilters = $mp->getQuickfilterIds(); if (in_array($m, $quickfilters[_("Veranstaltungsteilnehmende")])) { InsertPersonStatusgruppe ($m, $statusgruppe_id, false); } elseif (in_array($m, $quickfilters[_("Mitarbeiter/-innen")])) { $writedone = InsertPersonStatusgruppe ($m, $statusgruppe_id, false); if ($writedone) { if ($workgroup_mode == TRUE) { $globalperms = get_global_perm($m); if ($globalperms == "tutor" || $globalperms == "dozent") { insert_seminar_user($range_id, $m, "tutor"); } else { insert_seminar_user($range_id, $m, "autor"); } } else { insert_seminar_user($range_id, $m, "autor"); } } checkExternDefaultForUser($m); } else { $writedone = InsertPersonStatusgruppe ($m, $statusgruppe_id, false); if ($writedone) { if ($workgroup_mode == TRUE) { $globalperms = get_global_perm($m); if ($globalperms == "tutor" || $globalperms == "dozent") { insert_seminar_user($range_id, $m, "tutor"); } else { insert_seminar_user($range_id, $m, "autor"); } } else { insert_seminar_user($range_id, $m, "autor"); } } } } } $mp->clearSession(); }