コード例 #1
0
ファイル: Controller.php プロジェクト: rjsmelo/tiki
 function action_default_groups($input)
 {
     Services_Exception_Denied::checkGlobal('admin_users');
     Services_Exception_Denied::checkGlobal('group_add_member');
     $check = Services_Exception_BadRequest::checkAccess();
     //first pass - show confirm popup
     if (!empty($check['ticket'])) {
         $users = $input->asArray('checked');
         if (count($users) > 0) {
             $all_groups = $this->lib->list_all_groups();
             $all_groups = array_combine($all_groups, $all_groups);
             //provide redirect if js is not enabled
             $referer = Services_Utilities_Controller::noJsPath();
             return ['FORWARD' => ['controller' => 'access', 'action' => 'confirm_select', 'title' => tra('Set default group for selected users'), 'confirmAction' => $input->action->word(), 'confirmController' => 'user', 'customMsg' => tra('For these selected users:'), 'toList' => $all_groups, 'toMsg' => tra('Make this the default group:'), 'items' => $users, 'extra' => ['referer' => $referer], 'ticket' => $check['ticket'], 'modal' => '1']];
         } else {
             throw new Services_Exception(tra('No users were selected. Please select one or more users.'), 409);
         }
         //after confirm submit - perform action and return success feedback
     } elseif ($check === true && $_SERVER['REQUEST_METHOD'] === 'POST') {
         $groups = isset($input['checked_groups']) ? $input->asArray('checked_groups') : $input->asArray('toId');
         $users = json_decode($input['items'], true);
         if (!empty($users) && !empty($groups)) {
             global $user;
             $logslib = TikiLib::lib('logs');
             $userGroups = $this->lib->get_user_groups_inclusion($user);
             $groupperm = Perms::get()->group_add_member;
             $userperm = Perms::get()->group_join;
             foreach ($users as $assign_user) {
                 foreach ($groups as $group) {
                     if ($groupperm || array_key_exists($group, $userGroups) && $userperm) {
                         $this->lib->set_default_group($assign_user, $group);
                         $logmsg = sprintf(tra('group %s set as the default group for user %s.'), $group, $assign_user);
                         $logslib->add_log('adminusers', $logmsg, $user);
                     }
                 }
             }
             //return to page
             //if javascript is not enabled
             $extra = json_decode($input['extra'], true);
             if (!empty($extra['referer'])) {
                 $this->access->redirect($extra['referer'], tra('Default group(s) assigned'), null, 'feedback');
             }
             $msg = count($users) === 1 ? tra('For the following user:'******'For the following users:');
             $toMsg = tra('The following group has been set as the default group:');
             return ['extra' => 'post', 'feedback' => ['ajaxtype' => 'feedback', 'ajaxheading' => tra('Success'), 'ajaxitems' => $users, 'ajaxmsg' => $msg, 'ajaxtoMsg' => $toMsg, 'ajaxtoList' => $groups, 'modal' => '1']];
         } else {
             throw new Services_Exception(tra('No groups were selected. Please select one or more groups.'), 409);
         }
     }
 }