예제 #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 dirname(dirname(__DIR__)) . DS . 'models' . DS . 'member' . DS . 'role.php';
     \Components\Groups\Models\Member\Role::destroyByUser(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::getInstance();
     $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);
     }
     // Log activity
     $url = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->view->group->get('cn'));
     $recipients = array(['group', $this->view->group->get('gidNumber')], ['user', User::get('id')]);
     foreach ($this->view->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'cancelled', 'scope' => 'group', 'scope_id' => $this->view->group->get('gidNumber'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_GROUP_USER_CANCELLED', '<a href="' . $url . '">' . $this->view->group->get('description') . '</a>'), 'details' => array('title' => $this->view->group->get('description'), 'url' => $url, 'cn' => $this->view->group->get('cn'), 'gidNumber' => $this->view->group->get('gidNumber'))], 'recipients' => $recipients]);
     // 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
 /**
  * Deny one or more users membership
  *
  * @return     void
  */
 private function confirmdeny()
 {
     if ($this->authorized != 'manager' && $this->authorized != 'admin') {
         return false;
     }
     if ($this->membership_control == 0) {
         return false;
     }
     $database = App::get('db');
     $admchange = '';
     // An array for the users we're going to deny
     $users = array();
     // Incoming array of users to demote
     $mbrs = Request::getVar('users', array(0));
     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" : '';
             // Remove record of reason wanting to join group
             $reason = new Reason($database);
             $reason->deleteReason($targetuser->get('id'), $this->group->get('gidNumber'));
             // Add them to the array of users to deny
             $users[] = $targetuser->get('id');
             // Log activity
             $recipients = array(['group', $this->group->get('gidNumber')], ['user', $targetuser->get('id')]);
             foreach ($this->group->get('managers') as $recipient) {
                 $recipients[] = ['user', $recipient];
             }
             Event::trigger('system.logActivity', ['activity' => ['action' => 'denied', 'scope' => 'group.membership', 'scope_id' => $this->group->get('gidNumber'), 'description' => Lang::txt('PLG_GROUPS_MEMBERS_ACTIVITY_DENIED', '<a href="' . Route::url('index.php?option=com_members&id=' . $targetuser->get('id')) . '">' . $targetuser->get('name') . '</a>', '<a href="' . Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn')) . '">' . $this->group->get('description') . '</a>'), 'details' => array('user_id' => $targetuser->get('id'), 'group_id' => $this->group->get('gidNumber'))], 'recipients' => $recipients]);
             // E-mail the user, letting them know they've been denied
             $this->notifyUser($targetuser);
         } else {
             $this->setError(Lang::txt('PLG_GROUPS_MESSAGES_ERROR_USER_NOTFOUND') . ' ' . $mbr);
         }
     }
     // Remove users from managers list
     $this->group->remove('applicants', $users);
     // Save changes
     $this->group->update();
     // log invites
     \Components\Groups\Models\Log::log(array('gidNumber' => $this->group->get('gidNumber'), 'action' => 'membership_denied', 'comments' => $users));
 }
예제 #3
0
 /**
  * Denies user(s) group membership
  *
  * @return void
  */
 public function denyTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     $gid = Request::getVar('gid', '');
     // Load the group page
     $this->group = new Group();
     $this->group->read($gid);
     // An array for the users we're going to deny
     $users = array();
     // Incoming array of users to demote
     $mbrs = Request::getVar('id', array());
     $mbrs = !is_array($mbrs) ? array($mbrs) : $mbrs;
     foreach ($mbrs as $mbr) {
         // Retrieve user's account info
         $targetuser = User::getInstance($mbr);
         // Ensure we found an account
         if (is_object($targetuser)) {
             // Remove record of reason wanting to join group
             $reason = new Tables\Reason($this->database);
             $reason->deleteReason($targetuser->get('username'), $this->group->get('cn'));
             // Add them to the array of users to deny
             $users[] = $targetuser->get('id');
         } else {
             $this->setError(Lang::txt('COM_GROUPS_USER_NOTFOUND') . ' ' . $mbr);
         }
     }
     // Remove users from managers list
     $this->group->remove('applicants', $users);
     // Save changes
     $this->group->update();
     // log
     Log::log(array('gidNumber' => $this->group->get('gidNumber'), 'action' => 'group_members_denied', 'comments' => $users));
     if (!Request::getInt('no_html', 0)) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->group->get('cn'), false), Lang::txt('COM_GROUPS_MEMBER_DENIED'));
     }
 }
예제 #4
0
 /**
  * Approve membership for one or more users
  *
  * @return     void
  */
 private function approve()
 {
     if ($this->authorized != 'manager' && $this->authorized != 'admin') {
         return false;
     }
     if ($this->membership_control == 0) {
         return false;
     }
     $database = App::get('db');
     // Set a flag for emailing any changes made
     $admchange = '';
     // Note: we use two different lists to avoid situations where the user is already a member but somehow an applicant too.
     // Recording the list of applicants for removal separate allows for removing the duplicate entry from the applicants list
     // without trying to add them to the members list (which they already belong to).
     $users = array();
     $applicants = array();
     // Get all normal members (non-managers) of this group
     $members = $this->group->get('members');
     // Incoming array of users to promote
     $mbrs = Request::getVar('users', array(0));
     foreach ($mbrs as $mbr) {
         // Retrieve user's account info
         $targetuser = User::getInstance($mbr);
         // Ensure we found an account
         if (is_object($targetuser)) {
             $uid = $targetuser->get('id');
             // The list of applicants to remove from the applicant list
             $applicants[] = $uid;
             // Loop through existing members and make sure the user isn't already a member
             if (in_array($uid, $members)) {
                 $this->setError(Lang::txt('PLG_GROUPS_MESSAGES_ERROR_ALREADY_A_MEMBER', $mbr));
                 continue;
             }
             // Remove record of reason wanting to join group
             $reason = new Components\Groups\Tables\Reason($database);
             $reason->deleteReason($targetuser->get('id'), $this->group->get('gidNumber'));
             // Are they approved for membership?
             $admchange .= "\t\t" . $targetuser->get('name') . "\r\n";
             $admchange .= "\t\t" . $targetuser->get('username') . ' (' . $targetuser->get('email') . ')';
             $admchange .= count($mbrs) > 1 ? "\r\n" : '';
             // They user is not already a member, so we can go ahead and add them
             $users[] = $uid;
             // Log activity
             $recipients = array(['group', $this->group->get('gidNumber')], ['user', $uid]);
             foreach ($this->group->get('managers') as $recipient) {
                 $recipients[] = ['user', $recipient];
             }
             Event::trigger('system.logActivity', ['activity' => ['action' => 'approved', 'scope' => 'group.membership', 'scope_id' => $this->group->get('gidNumber'), 'description' => Lang::txt('PLG_GROUPS_MEMBERS_ACTIVITY_APPROVED', '<a href="' . Route::url('index.php?option=com_members&id=' . $uid) . '">' . $targetuser->get('name') . '</a>', '<a href="' . Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn')) . '">' . $this->group->get('description') . '</a>'), 'details' => array('user_id' => $uid, 'group_id' => $this->group->get('gidNumber'))], 'recipients' => $recipients]);
             // E-mail the user, letting them know they've been approved
             $this->notifyUser($targetuser);
         } else {
             $this->setError(Lang::txt('PLG_GROUPS_MESSAGES_ERROR_USER_NOTFOUND') . ' ' . $mbr);
         }
     }
     // Remove users from applicants list
     $this->group->remove('applicants', $applicants);
     // Add users to members list
     $this->group->add('members', $users);
     // Save changes
     $this->group->update();
     // log invites
     \Components\Groups\Models\Log::log(array('gidNumber' => $this->group->get('gidNumber'), 'action' => 'membership_approved', 'comments' => $users));
 }