Exemplo n.º 1
0
 /**
  * Accept Group Invite Method
  *
  * @return  void
  */
 public function acceptTask()
 {
     //get invite token
     $token = Request::getVar('token', '', 'get');
     // Check if they're logged in
     if (User::isGuest()) {
         $link = null;
         if ($token) {
             $link = Route::url('index.php?option=com_groups&cn=' . $this->cn . '&task=accept&token=' . $token);
         }
         $this->loginTask(Lang::txt('COM_GROUPS_INVITE_MUST_BE_LOGGED_IN_TO_ACCEPT'), $link);
         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 = \Hubzero\User\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'));
     }
     //do we have permission to join group
     if ($this->view->group->get('type') == 2) {
         $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_FORBIDDEN'));
         return;
     }
     // 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 current members and invitees
     $members = $this->view->group->get('members');
     $invitees = $this->view->group->get('invitees');
     // Get invite emails
     $group_inviteemails = new \Hubzero\User\Group\InviteEmail();
     $inviteemails = $group_inviteemails->getInviteEmails($this->view->group->get('gidNumber'), true);
     $inviteemails_with_token = $group_inviteemails->getInviteEmails($this->view->group->get('gidNumber'), false);
     //are we already a member
     if (in_array(User::get('id'), $members)) {
         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')));
     //check to make sure weve been invited
     if ($token) {
         $sql = "SELECT * FROM `#__xgroups_inviteemails` WHERE token=" . $this->database->quote($token);
         $this->database->setQuery($sql);
         $invite = $this->database->loadAssoc();
         if ($invite) {
             $this->view->group->add('members', array(User::get('id')));
             $this->view->group->update();
             $sql = "DELETE FROM `#__xgroups_inviteemails` WHERE id=" . $this->database->quote($invite['id']);
             $this->database->setQuery($sql);
             $this->database->query();
         }
     } elseif (in_array(User::get('email'), $inviteemails)) {
         $this->view->group->add('members', array(User::get('id')));
         $this->view->group->update();
         $sql = "DELETE FROM `#__xgroups_inviteemails` WHERE email='" . User::get('email') . "' AND gidNumber='" . $this->view->group->get('gidNumber') . "'";
         $this->database->setQuery($sql);
         $this->database->query();
     } elseif (in_array(User::get('id'), $invitees)) {
         $this->view->group->add('members', array(User::get('id')));
         $this->view->group->remove('invitees', array(User::get('id')));
         $this->view->group->update();
     } else {
         $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_UNABLE_TO_JOIN'));
     }
     // log invites
     Log::log(array('gidNumber' => $this->view->group->get('gidNumber'), 'action' => 'membership_invite_accepted', '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' => 'accepted', 'scope' => 'group', 'scope_id' => $this->view->group->get('gidNumber'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_GROUP_USER_ACCEPTED', '<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_EMAIL_MEMBERSHIP_ACCEPTED_SUBJECT', $this->view->group->get('cn'));
     // Build the e-mail message
     $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'accepted'));
     $eview->option = $this->_option;
     $eview->sitename = Config::get('sitename');
     $eview->user = User::getInstance();
     $eview->group = $this->view->group;
     $body = $eview->loadTemplate();
     $body = str_replace("\n", "\r\n", $body);
     // 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');
     // Get the system administrator e-mail
     $emailadmin = 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_invite_accepted')->addPart($body, 'text/plain')->send();
     //set notification fro user
     $this->setNotification(Lang::txt('COM_GROUPS_INVITE_ACCEPTED_SUCCESS'), 'passed');
     // Action Complete. Redirect to appropriate page
     if ($return == 'browse') {
         App::redirect(Route::url('index.php?option=' . $this->_option));
     } else {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->view->group->get('cn')));
     }
 }
Exemplo n.º 2
0
         break;
     case '1':
         $type = Lang::txt('COM_GROUPS_TYPE_HUB');
         break;
     case '2':
         $type = Lang::txt('COM_GROUPS_TYPE_PROJECT');
         break;
     case '3':
         $type = Lang::txt('COM_GROUPS_TYPE_SUPER');
         break;
     case '4':
         $type = Lang::txt('COM_GROUPS_TYPE_COURSE');
         break;
 }
 //get group invite emails
 $hubzeroGroupInviteEmail = new \Hubzero\User\Group\InviteEmail($database);
 $inviteemails = $hubzeroGroupInviteEmail->getInviteEmails($group->get('gidNumber'));
 //get group membership
 $members = $group->get('members');
 $managers = $group->get('managers');
 $applicants = $group->get('applicants');
 $invitees = $group->get('invitees');
 //remove any managers from members list
 $true_members = array_diff($members, $managers);
 //build membership tooltip
 $tip = '<table><tbody>';
 $tip .= '<tr><th>' . Lang::txt('COM_GROUPS_MEMBERS') . '</th><td>' . count($true_members) . '</td></tr>';
 $tip .= '<tr><th>' . Lang::txt('COM_GROUPS_MANAGERS') . '</th><td>' . count($managers) . '</td></tr>';
 $tip .= '<tr><th>' . Lang::txt('COM_GROUPS_APPLICANTS') . '</th><td>' . count($applicants) . '</td></tr>';
 $tip .= '<tr><th>' . Lang::txt('COM_GROUPS_INVITEES') . '</th><td>' . (count($invitees) + count($inviteemails)) . '</td></tr>';
 $tip .= '</tbody></table>';
Exemplo n.º 3
0
 /**
  * Return data on a group view (this will be some form of HTML)
  *
  * @param      object  $group      Current group
  * @param      string  $option     Name of the component
  * @param      string  $authorized User's authorization level
  * @param      integer $limit      Number of records to pull
  * @param      integer $limitstart Start of records to pull
  * @param      string  $action     Action to perform
  * @param      array   $access     What can be accessed
  * @param      array   $areas      Active area(s)
  * @return     array
  */
 public function onGroup($group, $option, $authorized, $limit = 0, $limitstart = 0, $action = '', $access, $areas = null)
 {
     $returnhtml = true;
     $active = 'members';
     // The output array we're returning
     $arr = array('html' => '', 'metadata' => '');
     //get this area details
     $this_area = $this->onGroupAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas) && $limit) {
         if (!in_array($this_area['name'], $areas)) {
             $returnhtml = false;
         }
     }
     // Set some variables so other functions have access
     $this->authorized = $authorized;
     $this->action = $action;
     $this->_option = $option;
     $this->group = $group;
     $this->name = substr($option, 4, strlen($option));
     // Only perform the following if this is the active tab/plugin
     if ($returnhtml) {
         //set group members plugin access level
         $group_plugin_acl = $access[$active];
         //get the group members
         $members = $group->get('members');
         //if set to nobody make sure cant access
         if ($group_plugin_acl == 'nobody') {
             $arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_OFF', ucfirst($active)) . '</p>';
             return $arr;
         }
         //check if guest and force login if plugin access is registered or members
         if (User::isGuest() && ($group_plugin_acl == 'registered' || $group_plugin_acl == 'members')) {
             $url = Route::url('index.php?option=com_groups&cn=' . $group->get('cn') . '&active=' . $active, false, true);
             App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url)), Lang::txt('GROUPS_PLUGIN_REGISTERED', ucfirst($active)), 'warning');
             return;
         }
         //check to see if user is member and plugin access requires members
         if (!in_array(User::get('id'), $members) && $group_plugin_acl == 'members' && $authorized != 'admin') {
             $arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_REQUIRES_MEMBER', ucfirst($active)) . '</p>';
             return $arr;
         }
         // Set the page title
         //Document::setTitle(Lang::txt(strtoupper($this->_option)).': '.$this->group->description.': '.Lang::txt('PLG_GROUPS_MEMBERS'));
         $this->css('members.css')->js('members.js');
         $gparams = new \Hubzero\Config\Registry($group->get('params'));
         $this->membership_control = $gparams->get('membership_control', 1);
         $oparams = Component::params($this->_option);
         $this->display_system_users = $oparams->get('display_system_users', 'no');
         switch ($gparams->get('display_system_users', "global")) {
             case 'yes':
                 $this->display_system_users = 'yes';
                 break;
             case 'no':
                 $this->display_system_users = 'no';
                 break;
             case 'global':
                 $this->display_system_users = $this->display_system_users;
                 break;
         }
         // Do we need to perform any actions?
         if ($action) {
             if (is_numeric($action)) {
                 Request::setVar('member', $action);
                 $action = 'profile';
             }
             $action = strtolower(trim($action));
             if (!method_exists($this, $action)) {
                 App::abort(404, Lang::txt('PLG_GROUPS_MESSAGES_ERROR_ACTION_NOTFOUND'));
             }
             // Perform the action
             $this->{$action}();
             // Did the action return anything? (HTML)
             if (isset($this->_output) && $this->_output != '') {
                 $arr['html'] = $this->_output;
             }
         }
         if (!$arr['html']) {
             // Get group members based on their status
             // Note: this needs to happen *after* any potential actions ar performed above
             $view = $this->view('default', 'browse');
             $view->membership_control = $this->membership_control;
             $view->option = $option;
             $view->group = $group;
             $view->authorized = $authorized;
             $this->database = App::get('db');
             $view->q = Request::getVar('q', '');
             $view->filter = Request::getVar('filter', '');
             if (!in_array($view->filter, array('members', 'managers', 'invitees', 'pending'))) {
                 $view->filter = '';
             }
             $view->role_filter = Request::getVar('role_filter', '');
             if ($view->authorized != 'manager' && $view->authorized != 'admin') {
                 $view->filter = $view->filter == 'managers' ? $view->filter : 'members';
             }
             try {
                 // Get messages plugin access level
                 $view->messages_acl = \Hubzero\User\Group\Helper::getPluginAccess($group, 'messages');
             } catch (Exception $e) {
                 // Plugin is not enabled.
                 $view->messages_acl = 'nobody';
             }
             //get all member roles
             $db = App::get('db');
             $sql = "SELECT * FROM `#__xgroups_roles` WHERE gidNumber=" . $db->quote($group->get('gidNumber'));
             $db->setQuery($sql);
             $view->member_roles = $db->loadAssocList();
             $group_inviteemails = new \Hubzero\User\Group\InviteEmail();
             $view->current_inviteemails = $group_inviteemails->getInviteEmails($this->group->get('gidNumber'), true);
             switch ($view->filter) {
                 case 'invitees':
                     $view->groupusers = $view->q ? $group->search('invitees', $view->q) : $group->get('invitees');
                     foreach ($view->current_inviteemails as $ie) {
                         $view->groupusers[] = $ie;
                     }
                     $view->managers = array();
                     break;
                 case 'pending':
                     $view->groupusers = $view->q ? $group->search('applicants', $view->q) : $group->get('applicants');
                     $view->managers = array();
                     break;
                 case 'managers':
                     $view->groupusers = $view->q ? $group->search('managers', $view->q) : $group->get('managers');
                     $view->groupusers = $view->role_filter ? \Hubzero\User\Group\Helper::search_roles($group, $view->role_filter) : $view->groupusers;
                     $view->managers = $group->get('managers');
                     break;
                 case 'members':
                 default:
                     $view->groupusers = $view->q ? $group->search('members', $view->q) : $group->get('members');
                     $view->groupusers = $view->role_filter ? \Hubzero\User\Group\Helper::search_roles($group, $view->role_filter) : $view->groupusers;
                     $view->managers = $group->get('managers');
                     break;
             }
             //if we dont want to display system users
             //filter values through callback above and then reset array keys
             if ($this->display_system_users == 'no' && is_array($view->groupusers)) {
                 $view->groupusers = array_map(array($this, "isSystemUser"), $view->groupusers);
                 $view->groupusers = array_values(array_filter($view->groupusers));
             }
             // sort users before display
             $view->groupusers = $this->sortAlphabetically($view->groupusers);
             $view->limit = Request::getInt('limit', $this->params->get('display_limit', 50));
             $view->start = Request::getInt('limitstart', 0);
             $view->start = $view->limit == 0 ? 0 : $view->start;
             $view->no_html = Request::getInt('no_html', 0);
             $view->params = $this->params;
             if ($this->getError()) {
                 $view->setError($this->getError());
             }
             $arr['html'] = $view->loadTemplate();
         }
     }
     //return metadata
     $arr['metadata']['count'] = count($group->get('members'));
     //do we have any pending requests
     $pending = $group->get("applicants");
     if (count($pending) > 0 && in_array(User::get('id'), $group->get("managers"))) {
         $title = Lang::txt('PLG_GROUPS_MEMBERS_GROUP_HAS_REQUESTS', $group->get('description'), count($pending));
         $link = Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=members&filter=pending');
         $arr['metadata']['alert'] = '<a class="alrt" href="' . $link . '"><span><h5>' . Lang::txt('PLG_GROUPS_MEMBERS_ALERT') . '</h5>' . $title . '</span></a>';
     }
     // Return the output
     return $arr;
 }
Exemplo n.º 4
0
 /**
  * Cancels invite(s)
  *
  * @return void
  */
 public function uninviteTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     $gid = Request::getVar('gid', '');
     // Load the group page
     $this->group = new Group();
     $this->group->read($gid);
     $authorized = $this->authorized;
     $users = array();
     $useremails = array();
     // Get all the group's invitees
     $invitees = $this->group->get('invitees');
     // Incoming array of users to demote
     $mbrs = Request::getVar('id', array());
     $mbrs = !is_array($mbrs) ? array($mbrs) : $mbrs;
     foreach ($mbrs as $mbr) {
         //check to see if we are uninviting email
         if (filter_var($mbr, FILTER_VALIDATE_EMAIL)) {
             $useremails[] = $mbr;
         } else {
             // Retrieve user's account info
             $targetuser = User::getInstance($mbr);
             // Ensure we found an account
             if (is_object($targetuser)) {
                 $uid = $targetuser->get('id');
                 if (in_array($uid, $invitees)) {
                     $users[] = $uid;
                 }
             } else {
                 $this->setError(Lang::txt('COM_GROUPS_USER_NOTFOUND') . ' ' . $mbr);
             }
         }
     }
     // Remove users from members list
     $this->group->remove('invitees', $users);
     //remove any invite emails
     if (count($useremails) > 0) {
         $hubzeroGroupInviteEmail = new \Hubzero\User\Group\InviteEmail($this->database);
         $hubzeroGroupInviteEmail->removeInvites($this->group->get('gidNumber'), $useremails);
     }
     // Save changes
     $this->group->update();
     // log
     Log::log(array('gidNumber' => $this->group->get('gidNumber'), 'action' => 'group_members_uninvited', 'comments' => array_merge($users, $useremails)));
     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_UNINVITED'));
     }
 }
Exemplo n.º 5
0
 /**
  * Send a message
  *
  * @return     mixed
  */
 protected function _send()
 {
     // Ensure the user is logged in
     if (User::isGuest()) {
         return false;
     }
     //message
     $message = Lang::txt('PLG_GROUPS_MESSAGES_FROM_GROUP', $this->group->get('cn'));
     // Incoming array of users to message
     $mbrs = Request::getVar('users', array(0), 'post');
     switch ($mbrs[0]) {
         case 'invitees':
             $mbrs = $this->group->get('invitees');
             $action = 'group_invitees_message';
             $group_id = $this->group->get('gidNumber');
             break;
         case 'applicants':
             $mbrs = $this->group->get('applicants');
             $action = 'group_pending_message';
             $group_id = $this->group->get('gidNumber');
             break;
         case 'managers':
             $mbrs = $this->group->get('managers');
             $action = 'group_managers_message';
             $group_id = $this->group->get('gidNumber');
             break;
         case 'all':
             $mbrs = $this->group->get('members');
             $action = 'group_members_message';
             $group_id = $this->group->get('gidNumber');
             break;
         default:
             $message = Lang::txt('PLG_GROUPS_MESSAGES_FOR_GROUP_MEMBER', $this->group->get('cn'));
             foreach ($mbrs as $mbr) {
                 if (strstr($mbr, '_')) {
                     $role = explode('_', $mbr);
                     $db = App::get('db');
                     $sql = "SELECT uidNumber FROM `#__xgroups_member_roles` WHERE roleid=" . $db->Quote($role[1]);
                     $db->setQuery($sql);
                     $member_roles = $db->loadAssocList();
                     foreach ($member_roles as $member) {
                         $members[] = $member['uidNumber'];
                     }
                     $mbrs = $members;
                     $action = 'group_role_message';
                     $group_id = $this->group->get('gidNumber');
                 } else {
                     $action = '';
                     $group_id = 0;
                     break;
                 }
             }
             break;
     }
     // Incoming message and subject
     $s = Request::getVar('subject', Lang::txt('PLG_GROUPS_MESSAGES_SUBJECT'));
     $m = Request::getVar('message', '');
     // Ensure we have a message
     if (!$s || !$m) {
         $html = '<p class="error">You must enter all required fields</p>';
         $html .= $this->_create();
         return $html;
     }
     // get all group members
     $recipients = array();
     foreach ($mbrs as $mbr) {
         if ($profile = User::getInstance($mbr)) {
             $recipients[$profile->get('email')] = $profile->get('name');
         }
     }
     // add invite emails if sending to invitees
     if ($action == 'group_invitees_message') {
         // Get invite emails
         $db = App::get('db');
         $group_inviteemails = new \Hubzero\User\Group\InviteEmail();
         $current_inviteemails = $group_inviteemails->getInviteEmails($this->group->get('gidNumber'), true);
         foreach ($current_inviteemails as $current_inviteemail) {
             $recipients[$current_inviteemail] = $current_inviteemail;
         }
     }
     // define from details
     $from = array('name' => $this->group->get('description') . " Group on " . Config::get("fromname"), 'email' => Config::get("mailfrom"));
     // create url
     $sef = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn'));
     $sef = ltrim($sef, '/');
     // create subject
     $subject = $s . " [Email sent on Behalf of " . User::get('name') . "]";
     //message
     $plain = Lang::txt('PLG_GROUPS_MESSAGES_FROM_GROUP', $this->group->get('cn'));
     $plain .= "\r\n------------------------------------------------\r\n\r\n";
     $plain .= $m;
     // create message
     $plain .= "\r\n\r\n------------------------------------------------\r\n" . Request::base() . $sef . "\r\n";
     // create message object
     $message = new \Hubzero\Mail\Message();
     // set message details and send
     $message->setSubject($subject)->setFrom(array($from['email'] => $from['name']))->addPart($plain, 'text/plain');
     foreach ($recipients as $email => $name) {
         $message->setTo(array($email => $name))->send();
     }
     // add invite emails if sending to invitees
     /*if ($action == 'group_invitees_message')
     		{
     			// Get invite emails
     			$db = App::get('db');
     			$group_inviteemails = new \Hubzero\User\Group\InviteEmail();
     			$current_inviteemails = $group_inviteemails->getInviteEmails($this->group->get('gidNumber'), true);
     
     			$headers  = 'From: ' . $from['name'] . ' <' . $from['email'] . '>' . "\r\n";
     			$headers .= 'Reply-To: ' . $from['replytoname'] . ' <' . $from['replytoemail'] . '>' . "\r\n";
     			foreach ($current_inviteemails as $current_inviteemail)
     			{
     				mail($current_inviteemail, $subject, $message, $headers);
     			}
     		}*/
     // Log the action
     if ($action) {
         // log invites
         \Components\Groups\Models\Log::log(array('gidNumber' => $this->group->get('gidNumber'), 'action' => $action, 'comments' => array(User::get('id'))));
     }
     // Determine if we're returning HTML or not
     // (if no - this is an AJAX call)
     $no_html = Request::getInt('no_html', 0);
     if (!$no_html) {
         $html = '';
         if ($this->getError()) {
             $html .= '<p class="error">' . $this->getError() . '</p>';
         }
         $html .= $this->_sent();
         return $html;
     }
 }