public function execute() { $ids = waRequest::request('id', array(), 'array_int'); if (!$ids) { throw new waException('Contact id not specified.'); } // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException(_w('Access denied')); } $groups = waRequest::post('groups', array(), 'array_int'); $counters = array(); $ugm = new waUserGroupsModel(); if ($this->getRequest()->request('set')) { foreach ($ids as $id) { $ugm->delete($id, array()); } } foreach ($ids as $id) { if ($groups) { $ugm->add(array_map(wa_lambda('$gid', 'return array(' . $id . ', $gid);'), $groups)); } } $gm = new waGroupModel(); foreach ($groups as $gid) { $cnt = $ugm->countByField(array('group_id' => $gid)); $gm->updateCount($gid, $cnt); $counters[$gid] = $cnt; } $this->response['counters'] = $counters; $this->response['message'] = _w("%d user has been added", "%d users have been added", count($ids)); $this->response['message'] .= ' '; $this->response['message'] .= _w("to %d group", "to %d groups", count($groups)); }
public function execute() { // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException(_w('Access denied')); } $contacts = $this->getRequest()->post('contacts', array(), 'array_int'); $groups = $this->getRequest()->post('groups', array(), 'array_int'); if (!$contacts || !$groups) { return; } $ugm = new waUserGroupsModel(); $gm = new waGroupModel(); foreach ($contacts as $id) { if ($groups) { $ugm->delete($id, $groups); } } $counters = array(); foreach ($groups as $gid) { $cnt = $ugm->countByField(array('group_id' => $gid)); $gm->updateCount($gid, $cnt); $counters[$gid] = $cnt; } $contacts_count = count($contacts); $groups_count = count($groups); $this->response['message'] = sprintf(_w("%d user excluded", "%d users excluded", $contacts_count), $contacts_count); $this->response['message'] .= ' '; $this->response['message'] .= sprintf(_w("from %d group", "from %d groups", $groups_count), $groups_count); $this->response['counters'] = $counters; }
public function execute() { // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException(_w('Access denied')); } $group = null; $group_id = waRequest::get('id'); if ($group_id) { $group_model = new waGroupModel(); $group = $group_model->getById($group_id); } // only allowed to global admin $is_global_admin = wa()->getUser()->getRights('webasyst', 'backend'); $right_model = new waContactRightsModel(); $fullAccess = $right_model->get(-$group_id, 'webasyst', 'backend'); $apps = wa()->getApps(); if (!$fullAccess) { $appAccess = $right_model->getApps($group_id, 'backend'); } $noAccess = true; foreach ($apps as $app_id => &$app) { $app['id'] = $app_id; $app['customizable'] = isset($app['rights']) ? (bool) $app['rights'] : false; $app['access'] = $fullAccess ? 2 : 0; if (!$app['access'] && isset($appAccess[$app_id])) { $app['access'] = $appAccess[$app_id]; } $noAccess = $noAccess && !$app['access']; } unset($app); $user_groups = new waUserGroupsModel(); $users_count = $user_groups->countByField(array('group_id' => $group_id)); $this->view->assign('users_count', $users_count); $this->view->assign('apps', $apps); $this->view->assign('noAccess', $noAccess); $this->view->assign('fullAccess', $fullAccess); $this->view->assign('is_global_admin', $is_global_admin); $this->view->assign('group', $group); $this->view->assign('icons', waGroupModel::getIcons()); }