Beispiel #1
0
 /**
  * Add membership request for user
  *
  * @return  array
  */
 public function dorequestTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_INVITE_MUST_BE_LOGGED_IN_TO_REQUEST'));
         return;
     }
     Request::checkToken();
     //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;
     }
     //make sure group has restricted policy
     if ($this->view->group->get('join_policy') != 1) {
         return;
     }
     //add user to applicants
     $this->view->group->add('applicants', array(User::get('id')));
     $this->view->group->update();
     // Instantiate the reason object and bind the incoming data
     $row = new Reason($this->database);
     $row->uidNumber = User::get('id');
     $row->gidNumber = $this->view->group->get('gidNumber');
     $row->reason = Request::getVar('reason', Lang::txt('GROUPS_NO_REASON_GIVEN'), 'post');
     $row->reason = \Hubzero\Utility\Sanitize::stripAll($row->reason);
     $row->date = Date::toSql();
     // Check and store the reason
     if (!$row->check()) {
         return App::abort(500, $row->getError());
     }
     if (!$row->store()) {
         return App::abort(500, $row->getError());
     }
     // Log the membership request
     Log::log(array('gidNumber' => $this->view->group->get('gidNumber'), 'action' => 'membership_requested', 'comments' => array(User::get('id'))));
     // 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' => 'requested', 'scope' => 'group', 'scope_id' => $this->view->group->get('gidNumber'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_GROUP_USER_REQUESTED', '<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]);
     // E-mail subject
     $subject = Lang::txt('COM_GROUPS_JOIN_REQUEST_EMAIL_SUBJECT', $this->view->group->get('cn'));
     // Build the e-mail message
     $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'request'));
     $eview->option = $this->_option;
     $eview->sitename = Config::get('sitename');
     $eview->user = User::getInstance();
     $eview->group = $this->view->group;
     $eview->row = $row;
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     // 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');
     // build array of managers
     $managers = array();
     foreach ($this->view->group->get('managers') as $m) {
         $profile = User::getInstance($m);
         if ($profile) {
             $managers[$profile->get('email')] = $profile->get('name');
         }
     }
     // create new message
     $message = new \Hubzero\Mail\Message();
     // build message object and send
     $message->setSubject($subject)->addFrom($from['email'], $from['name'])->setTo($managers)->addHeader('X-Mailer', 'PHP/' . phpversion())->addHeader('X-Component', 'com_groups')->addHeader('X-Component-Object', 'group_membership_requested')->addPart($html, 'text/plain')->send();
     //tell the user they just did good
     $this->setNotification(Lang::txt('COM_GROUPS_INVITE_REQUEST_FORWARDED'), 'passed');
     // Push through to the groups listing
     App::redirect($url);
 }
Beispiel #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));
 }
 /**
  * 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'));
     }
 }
Beispiel #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));
 }