コード例 #1
0
 /**
  * Cancel Membership Task
  *
  * @return  void
  */
 public function cancelTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_INVITE_MUST_BE_LOGGED_IN_TO_CANCEL'));
         return;
     }
     //check to make sure we have  cname
     if (!$this->cn) {
         $this->_errorHandler(400, Lang::txt('COM_GROUPS_ERROR_NO_ID'));
     }
     // Load the group page
     $this->view->group = Group::getInstance($this->cn);
     // Ensure we found the group info
     if (!$this->view->group || !$this->view->group->get('gidNumber')) {
         $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND'));
     }
     // Get the group params
     $gparams = new Registry($this->view->group->get('params'));
     // If membership is managed in seperate place disallow action
     if ($gparams->get('membership_control', 1) == 0) {
         $this->setNotification(Lang::txt('COM_GROUPS_MEMBERSHIP_MANAGED_ELSEWHERE'), 'error');
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->view->group->get('cn')));
         return;
     }
     //get request vars
     $return = strtolower(trim(Request::getVar('return', '', 'get')));
     // Remove the user from the group
     $this->view->group->remove('managers', User::get('id'));
     $this->view->group->remove('members', User::get('id'));
     $this->view->group->remove('applicants', User::get('id'));
     $this->view->group->remove('invitees', User::get('id'));
     if ($this->view->group->update() === false) {
         $this->setNotification(Lang::txt('GROUPS_ERROR_CANCEL_MEMBERSHIP_FAILED'), 'error');
     }
     // delete member roles
     require_once PATH_CORE . DS . 'plugins' . DS . 'groups' . DS . 'members' . DS . 'role.php';
     \GroupsMembersRole::deleteRolesForUserWithId(User::get('id'));
     // Log the membership cancellation
     Log::log(array('gidNumber' => $this->view->group->get('gidNumber'), 'action' => 'membership_cancelled', 'comments' => array(User::get('id'))));
     // Remove record of reason wanting to join group
     $reason = new Reason($this->database);
     $reason->deleteReason(User::get('id'), $this->view->group->get('gidNumber'));
     // Email subject
     $subject = Lang::txt('COM_GROUPS_EMAIL_MEMBERSHIP_CANCELLED_SUBJECT', $this->view->group->get('cn'));
     // Build the e-mail message
     $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'cancelled'));
     $eview->option = $this->_option;
     $eview->sitename = Config::get('sitename');
     $eview->user = User::getRoot();
     $eview->group = $this->view->group;
     $message = $eview->loadTemplate();
     $message = str_replace("\n", "\r\n", $message);
     // Get the system administrator e-mail
     $emailadmin = Config::get('mailfrom');
     // Build the "from" portion of the e-mail
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_name));
     $from['email'] = Config::get('mailfrom');
     // E-mail the administrator
     if (!Event::trigger('xmessage.onSendMessage', array('groups_cancelled_me', $subject, $message, $from, $this->view->group->get('managers'), $this->_option))) {
         $this->setError(Lang::txt('GROUPS_ERROR_EMAIL_MANAGERS_FAILED') . ' ' . $emailadmin);
     }
     // Action Complete. Redirect to appropriate page
     App::redirect(Route::url('index.php?option=com_members&id=' . User::get('id') . '&active=groups'), Lang::txt('COM_GROUPS_INVITE_CANCEL_SUCCESS'), 'passed');
 }
コード例 #2
0
ファイル: members.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Remove one or more users
  *
  * @return     void
  */
 private function confirmremove()
 {
     if ($this->authorized != 'manager' && $this->authorized != 'admin') {
         return false;
     }
     if ($this->membership_control == 0) {
         return false;
     }
     // Get all the group's managers
     $managers = $this->group->get('managers');
     // Get all the group's managers
     $members = $this->group->get('members');
     // Set a flag for emailing any changes made
     $admchange = '';
     $users_mem = array();
     $users_man = array();
     // Incoming array of users to remove
     $mbrs = Request::getVar('users', array(0));
     // Figure out how many managers are being deleted
     $intersect = array_intersect($managers, $mbrs);
     // Only admins can demote the last manager
     if ($this->authorized != 'admin' && (count($managers) == 1 && count($intersect) > 0)) {
         $this->setError(Lang::txt('PLG_GROUPS_MESSAGES_ERROR_LAST_MANAGER'));
         return;
     }
     foreach ($mbrs as $mbr) {
         // Retrieve user's account info
         $targetuser = User::getInstance($mbr);
         // Ensure we found an account
         if (is_object($targetuser)) {
             $admchange .= "\t\t" . $targetuser->get('name') . "\r\n";
             $admchange .= "\t\t" . $targetuser->get('username') . ' (' . $targetuser->get('email') . ')';
             $admchange .= count($mbrs) > 1 ? "\r\n" : '';
             $uid = $targetuser->get('id');
             if (in_array($uid, $members)) {
                 $users_mem[] = $uid;
             }
             if (in_array($uid, $managers)) {
                 $users_man[] = $uid;
             }
             GroupsMembersRole::deleteRolesForUserWithId($uid);
             $this->notifyUser($targetuser);
         } else {
             $this->setError(Lang::txt('PLG_GROUPS_MESSAGES_ERROR_USER_NOTFOUND') . ' ' . $mbr);
         }
     }
     // Remove users from members list
     $this->group->remove('members', $users_mem);
     // Make sure there's always at least one manager left
     if ($this->authorized != 'admin' && count($users_man) >= count($managers)) {
         $this->setError(Lang::txt('PLG_GROUPS_MESSAGES_ERROR_LAST_MANAGER'));
     } else {
         // Remove users from managers list
         $this->group->remove('managers', $users_man);
     }
     // Save changes
     $this->group->update();
     // log invites
     \Components\Groups\Models\Log::log(array('gidNumber' => $this->group->get('gidNumber'), 'action' => 'membership_removed', 'comments' => $users_mem));
     App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=members'));
 }