Esempio n. 1
0
 /**
  * Displays a list of groups
  *
  * @return	void
  */
 public function displayTask()
 {
     // Incoming
     $this->view->filters = array('gid' => Request::getState($this->_option . '.' . $this->_controller . '.gid', 'gid', ''));
     // Ensure we have a group ID
     if (!$this->view->filters['gid']) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_GROUPS_MISSING_ID'), 'error');
         return;
     }
     // Load the group page
     $group = new Group();
     $group->read($this->view->filters['gid']);
     $this->view->filters['gidNumber'] = $group->get('gidNumber');
     $this->view->filters['search'] = urldecode(trim(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')));
     $this->view->filters['status'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.status', 'status', ''));
     // Sorting options
     $this->view->filters['sort'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'name'));
     $this->view->filters['sort_Dir'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'));
     // Filters for returning results
     $this->view->filters['limit'] = Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int');
     $this->view->filters['start'] = Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int');
     // In case limit has been changed, adjust limitstart accordingly
     $this->view->filters['start'] = $this->view->filters['limit'] != 0 ? floor($this->view->filters['start'] / $this->view->filters['limit']) * $this->view->filters['limit'] : 0;
     $tbl = new Tables\Group($this->database);
     $this->view->total = $tbl->countMembers($this->view->filters);
     $this->view->rows = $tbl->findMembers($this->view->filters);
     //add invite emails to list
     if ($this->view->filters['status'] == '' || $this->view->filters['status'] == 'invitee') {
         //get group invite emails
         $hubzeroGroupInviteEmail = new \Hubzero\User\Group\InviteEmail($this->database);
         $inviteemails = $hubzeroGroupInviteEmail->getInviteEmails($group->get('gidNumber'));
         //add invite emails to list
         foreach ($inviteemails as $inviteemail) {
             $this->view->rows[$inviteemail['email']] = new \stdClass();
             $this->view->rows[$inviteemail['email']]->name = $inviteemail['email'];
             $this->view->rows[$inviteemail['email']]->username = null;
             $this->view->rows[$inviteemail['email']]->email = $inviteemail['email'];
             $this->view->rows[$inviteemail['email']]->uidNumber = null;
             $this->view->rows[$inviteemail['email']]->role = 'inviteemail';
         }
     }
     $this->view->group = $group;
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->display();
 }
 /**
  * Up
  **/
 public function up()
 {
     // select all groups with duplicate cname's
     $query = "SELECT gidNumber, cn, description\n\t\t\t\t  FROM `#__xgroups` WHERE cn IN (\n\t\t\t\t\t  SELECT cn FROM `#__xgroups` GROUP BY cn HAVING COUNT(*) > 1\n\t\t\t\t  ) ORDER BY gidNumber;";
     $this->db->setQuery($query);
     $duplicateGroups = $this->db->loadObjectList();
     // var to hold original groups
     $original = array();
     // loop through each group
     foreach ($duplicateGroups as $duplicateGroup) {
         // make sure to keep the original group
         if (!in_array($duplicateGroup->cn, $original)) {
             $original[] = $duplicateGroup->cn;
             continue;
         }
         // delete group
         // also deletes membership related stuff
         $hzGroup = \Hubzero\User\Group::getInstance($duplicateGroup->gidNumber);
         $hzGroup->delete();
     }
     // // Add unique index to cn column
     if ($this->db->tableExists('#__xgroups')) {
         if (!$this->db->tableHasKey('#__xgroups', 'idx_cn')) {
             $query = "ALTER TABLE `#__xgroups` ADD UNIQUE INDEX `idx_cn` (`cn`);";
             $this->db->setQuery($query);
             $this->db->query();
         }
     }
 }
 /**
  * Up
  **/
 public function up()
 {
     // include com_wishlist files
     require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php';
     // Load some objects
     $wishlist = new \Components\Wishlist\Tables\Wishlist($this->db);
     $wish = new \Components\Wishlist\Tables\Wish($this->db);
     // Get records
     $lists = $wishlist->getRecords(array('category' => 'group'));
     // vars to hold counts
     $deletedLists = 0;
     $deletedWishes = 0;
     // check to make sure each group wishlist has a valid group
     foreach ($lists as $list) {
         // load group
         $group = \Hubzero\User\Group::getInstance($list->referenceid);
         // if group doesnt exist we need to remove the list and wishes
         if (!$group || !is_object($group)) {
             // Get wishes
             $wishes = $wish->get_wishes($list->id, array('filterby' => 'all', 'sortby' => ''), 1);
             // delete each wish
             foreach ($wishes as $item) {
                 $wish->load($item->id);
                 $wish->delete();
                 $deletedWishes++;
             }
             // delete wishlist
             $wishlist->load($list->id);
             $wishlist->delete();
             $deletedLists++;
         }
     }
 }
Esempio n. 4
0
 /**
  * Constructor - sets output mechanism and arguments for use by command
  *
  * @param   \Hubzero\Console\Output    $output     The ouput renderer
  * @param   \Hubzero\Console\Arguments $arguments  The command arguments
  * @return  void
  **/
 public function __construct(Output $output, Arguments $arguments)
 {
     parent::__construct($output, $arguments);
     // Do we have a group arg?
     if ($cname = $this->arguments->getOpt('group')) {
         $group = \Hubzero\User\Group::getInstance($cname);
     } else {
         // Get the current directory
         $currentDirectory = getcwd();
         // Remove web root
         $currentDirectory = str_replace(PATH_APP, '', $currentDirectory);
         // Get group upload directory
         $groupsConfig = \Component::params('com_groups');
         $groupsDirectory = trim($groupsConfig->get('uploadpath', '/site/groups'), DS);
         // Are we within the groups upload path
         if (strpos($currentDirectory, $groupsDirectory)) {
             $gid = str_replace($groupsDirectory, '', $currentDirectory);
             $gid = trim($gid, DS);
             // Get group instance
             $group = \Hubzero\User\Group::getInstance($gid);
         }
     }
     // Make sure we have a group & its super!
     if (isset($group) && $group && $group->isSuperGroup()) {
         $this->group = $group;
     } else {
         $this->output->error('Error: Provided group is not valid');
     }
 }
Esempio n. 5
0
 /**
  * Override Execute Method
  *
  * @return 	void
  */
 public function execute()
 {
     //get the cname, active tab, and action for plugins
     $this->cn = Request::getVar('cn', '');
     $this->active = Request::getVar('active', '');
     $this->action = Request::getVar('action', '');
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_ERROR_MUST_BE_LOGGED_IN'));
         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->group = Group::getInstance($this->cn);
     // Ensure we found the group info
     if (!$this->group || !$this->group->get('gidNumber')) {
         $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND'));
     }
     // Check authorization
     if ($this->_authorize() != 'manager' && !$this->_authorizedForTask('group.pages')) {
         $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH'));
     }
     //continue with parent execute method
     parent::execute();
 }
Esempio n. 6
0
 /**
  * Constructor
  *
  * @param   integer  $referenceid  Scope ID (group, course, etc.)
  * @return  void
  */
 public function __construct($referenceid = 0)
 {
     $this->set('referenceid', $referenceid)->set('category', 'group')->set('option', $this->_segments['option']);
     $this->_item = \Hubzero\User\Group::getInstance($referenceid);
     if (!$this->_item) {
         $this->_item = new \Hubzero\User\Group();
     }
     $this->_segments['cn'] = $this->_item->get('cn');
     $this->_segments['active'] = 'wishlist';
 }
Esempio n. 7
0
 /**
  * Loads the plugin language file
  *
  * @param   string   $extension  The extension for which a language file should be loaded
  * @param   string   $basePath   The basepath to use
  * @return  boolean  True, if the file has successfully loaded.
  */
 public function loadLanguage($extension = '', $basePath = PATH_APP)
 {
     if (empty($extension)) {
         $extension = 'plg_' . $this->_type . '_' . $this->_name;
     }
     $group = \Hubzero\User\Group::getInstance(Request::getCmd('cn'));
     if ($group && $group->isSuperGroup()) {
         $basePath = PATH_APP . DS . 'site' . DS . 'groups' . DS . $group->get('gidNumber');
     }
     $lang = \App::get('language');
     return $lang->load(strtolower($extension), $basePath, null, false, true) || $lang->load(strtolower($extension), PATH_APP . DS . 'plugins' . DS . $this->_type . DS . $this->_name, null, false, true) || $lang->load(strtolower($extension), PATH_APP . DS . 'plugins' . DS . $this->_type . DS . $this->_name, null, false, true) || $lang->load(strtolower($extension), PATH_CORE . DS . 'plugins' . DS . $this->_type . DS . $this->_name, null, false, true);
 }
Esempio n. 8
0
 /**
  * Constructor
  *
  * @param   integer  $scope_id  Scope ID (group, course, etc.)
  * @return  void
  */
 public function __construct($scope_id)
 {
     $group = \Hubzero\User\Group::getInstance($scope_id);
     if (!$group) {
         $group = new \Hubzero\User\Group();
         $group->set('cn', '_unknown_');
     }
     $this->_segments['cn'] = $group->get('cn');
     $this->_segments['active'] = 'forum';
     $this->_segments['scope'] = '';
     $this->_name = $group->get('cn');
 }
Esempio n. 9
0
 /**
  * Override Execute Method
  *
  * @return 	void
  */
 public function execute()
 {
     // Incoming
     $this->gid = Request::getVar('gid', '');
     // Ensure we have a group ID
     if (!$this->gid) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=manage', false), Lang::txt('COM_GROUPS_MISSING_ID'), 'error');
         return;
     }
     $this->group = Group::getInstance($this->gid);
     parent::execute();
 }
Esempio n. 10
0
 /**
  * Display members of a group
  *
  * @apiMethod GET
  * @apiUri    /groups/{id}/members/list
  * @apiParameter {
  * 		"name":          "id",
  * 		"description":   "Group identifier",
  * 		"type":          "integer",
  * 		"required":      true,
  * 		"default":       0
  * }
  * @apiParameter {
  * 		"name":          "list",
  * 		"description":   "Comma-separated list of member status",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       "",
  * 		"allowedValues": "members, managers, invitees, applicants"
  * }
  * @apiParameter {
  * 		"name":          "start",
  * 		"description":   "Number of where to start returning results.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       0
  * }
  * @return  void
  */
 public function listTask()
 {
     $id = Request::getInt('id', 0);
     $group = \Hubzero\User\Group::getInstance($id);
     if (!$group) {
         throw new Exception(Lang::txt('COM_GROUPS_ERROR_MISSING_RECORD'), 404);
     }
     // get all group members, managers, etc
     $members = $group->get('members');
     $managers = $group->get('managers');
     $invitees = $group->get('invitees');
     $applicants = $group->get('applicants');
     // get what the user wants back
     $list = Request::getVar('list', 'members, managers, invitees, applicants');
     // split by comma
     if (is_string($list)) {
         $list = explode(',', $list);
         $list = array_map('trim', $list);
         $list = array_map('strtolower', $list);
     }
     // var to hold return
     $response = array();
     // add members
     if (in_array('members', $list)) {
         foreach ($members as $k => $member) {
             $members[$k] = array('uidNumber' => $member);
         }
         $response['members'] = $members;
     }
     // add managers
     if (in_array('managers', $list)) {
         foreach ($managers as $k => $manager) {
             $managers[$k] = array('uidNumber' => $manager);
         }
         $response['managers'] = $managers;
     }
     // add invitees
     if (in_array('invitees', $list)) {
         foreach ($invitees as $k => $invitee) {
             $invitees[$k] = array('uidNumber' => $invitee);
         }
         $response['invitees'] = $invitees;
     }
     // add managers
     if (in_array('applicants', $list)) {
         foreach ($applicants as $k => $applicant) {
             $applicants[$k] = array('uidNumber' => $applicant);
         }
         $response['applicants'] = $applicants;
     }
     $this->send($response);
 }
Esempio n. 11
0
 /**
  * Override Execute Method
  *
  * @return  void
  */
 public function execute()
 {
     $id = Request::getInt('gidNumber');
     // Load the group page
     $this->group = Group::getInstance($id);
     // Ensure we found the group info
     if (!$this->group || !$this->group->get('gidNumber')) {
         App::abort(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND'));
     }
     //build path to the group folder
     $this->path = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/groups'), DS) . DS . $this->group->get('gidNumber');
     //continue with parent execute method
     parent::execute();
 }
Esempio n. 12
0
 /**
  * Constructor
  *
  * @param   integer  $scope_id  Scope ID (group, course, etc.)
  * @return  void
  */
 public function __construct($scope_id = 0)
 {
     $this->set('scope_id', $scope_id);
     $group = \Hubzero\User\Group::getInstance($scope_id);
     if (!$group || !$group->get('cn')) {
         $group = new \Hubzero\User\Group();
         $group->set('gidNumber', $scope_id);
         $group->set('cn', $scope_id);
         $group->set('description', Lang::txt('(unknown)'));
     }
     $this->_group = $group;
     $this->_segments['cn'] = $group->get('cn');
     $this->_segments['active'] = 'collections';
     $this->set('option', $this->_segments['option']);
 }
Esempio n. 13
0
 /**
  * Method is called after user data is deleted from the database
  *
  * @param array  $user   holds the user data
  * @param bool   $succes true if user was succesfully stored in the database
  * @param string $msg    message
  */
 public function onUserAfterDelete($user, $succes, $msg)
 {
     // Check params for group name
     $groupAlias = $this->params->get('group', false);
     if ($groupAlias) {
         // Get the group
         $group = \Hubzero\User\Group::getInstance($groupAlias);
         if (is_object($group)) {
             // Remove the user from the group
             $group->remove('members', array($user['id']));
             // Update the groups
             $group->update();
         }
     }
 }
Esempio n. 14
0
 /**
  * Constructor
  *
  * @param   integer  $scope_id  Scope ID (group, course, etc.)
  * @return  void
  */
 public function __construct($scope_id = 0)
 {
     $this->set('scope_id', $scope_id);
     $this->_item = UserGroup::getInstance($scope_id);
     if (!$this->_item instanceof UserGroup) {
         $this->_item = new UserGroup();
     }
     $this->_segments['cn'] = $this->_item->get('cn');
     $this->_segments['active'] = 'blog';
     $groupParams = Component::params('com_groups');
     $uploadpath = $groupParams->get('uploadpath', '/site/groups');
     $uploadpath = trim($uploadpath, DS) . DS . $this->get('scope_id') . DS . 'uploads' . DS . 'blog';
     $this->set('path', $uploadpath);
     $this->set('scope', $this->_segments['cn'] . '/blog');
     $this->set('option', $this->_segments['option']);
 }
Esempio n. 15
0
 /**
  * Build search query and add it to the $results
  *
  * @param      object $request  \Components\Search\Models\Basic\Request
  * @param      object &$results \Components\Search\Models\Basic\Result\Set
  * @param      object $authz    \Components\Search\Models\Basic\Authorization
  * @return     void
  */
 public static function onSearch($request, &$results, $authz)
 {
     $terms = $request->get_term_ar();
     $weight = 'match(e.title, e.content) against(\'' . join(' ', $terms['stemmed']) . '\')';
     $addtl_where = array();
     foreach ($terms['mandatory'] as $mand) {
         $addtl_where[] = "(e.title LIKE '%{$mand}%' OR e.content LIKE '%{$mand}%')";
     }
     foreach ($terms['forbidden'] as $forb) {
         $addtl_where[] = "(e.title NOT LIKE '%{$forb}%' AND e.content NOT LIKE '%{$forb}%')";
     }
     // Commenting out Access check as it was never used and column was removed from table
     // during events refactoring
     //
     // @author Chris Smoak
     // @date   4/20/2014
     //
     // $addtl_where[] = '(e.access IN (' . implode(',', User::getAuthorisedViewLevels()) . '))';
     $rows = new \Components\Search\Models\Basic\Result\Sql("SELECT\n\t\t\t\te.title,\n\t\t\t\te.content AS description,\n\t\t\t\te.scope,\n\t\t\t\te.scope_id,\n\t\t\t\tconcat('index.php?option=com_events&task=details&id=', e.id) AS link,\n\t\t\t\t{$weight} AS weight,\n\t\t\t\tpublish_up AS date,\n\t\t\t\t'Events' AS section\n\t\t\tFROM `#__events` e\n\t\t\tWHERE\n\t\t\t\tstate = 1 AND\n\t\t\t\tapproved AND {$weight} > 0" . ($addtl_where ? ' AND ' . join(' AND ', $addtl_where) : '') . " ORDER BY {$weight} DESC");
     foreach ($rows->to_associative() as $row) {
         if (!$row) {
             continue;
         }
         // check group perms
         if ($row->scope == 'group') {
             // load group
             $group = \Hubzero\User\Group::getInstance($row->scope_id);
             // make sure we found one
             if (!$group) {
                 continue;
             }
             // get group calendar access
             $access = \Hubzero\User\Group\Helper::getPluginAccess($group, 'calendar');
             // is calendar off
             // is calendar for registered users & not logged in
             // is calendar for members only and we are not a member
             if ($access == 'nobody' || $access == 'registered' && User::isGuest() || $access == 'members' && !in_array(User::get('id'), $group->get('members'))) {
                 continue;
             }
         }
         $row->set_description(preg_replace('/(\\[+.*?\\]+|\\{+.*?\\}+|[=*])/', '', $row->get_description()));
         $results->add($row);
     }
 }
Esempio n. 16
0
 /**
  * Return data on a resource sub view (this will be some form of HTML)
  *
  * @param   object   $resource  Current resource
  * @param   string   $option    Name of the component
  * @param   integer  $miniview  View style
  * @return  array
  */
 public function onResourcesSub($resource, $option, $miniview = 0)
 {
     $arr = array('area' => $this->_name, 'html' => '', 'metadata' => '');
     if (!$resource->group_owner || substr($resource->group_owner, 0, strlen('app-')) == 'app-') {
         return $arr;
     }
     $group = \Hubzero\User\Group::getInstance($resource->group_owner);
     if (!$group || !$group->get('gidNumber')) {
         return $arr;
     }
     // Pass the view some info
     $view = $this->view('default', 'display')->set('option', $option)->set('resource', $resource)->set('params', $this->params)->set('group', $group);
     if ($miniview) {
         $view->setLayout('mini');
     }
     // Return the output
     $arr['html'] = $view->setErrors($this->getErrors())->loadTemplate();
     return $arr;
 }
Esempio n. 17
0
 /**
  * Get items reported as abusive
  *
  * @param   integer  $refid     Comment ID
  * @param   string   $category  Item type (kb)
  * @param   integer  $parent    Parent ID
  * @return  array
  */
 public function getReportedItem($refid, $category, $parent)
 {
     if ($category != 'forum') {
         return null;
     }
     $query = "SELECT rc.id, rc.comment as `text`, rc.parent, rc.created_by as author, rc.created, rc.title as subject, rc.anonymous as anon, 'forum' AS parent_category,\n\t\t\t\t\ts.alias AS section, c.alias AS category, rc.scope, rc.scope_id, rc.object_id, rc.thread\n\t\t\t\t\tFROM `#__forum_posts` AS rc\n\t\t\t\t\tLEFT JOIN `#__forum_categories` AS c ON c.id = rc.category_id\n\t\t\t\t\tLEFT JOIN `#__forum_sections` AS s ON s.id = c.section_id\n\t\t\t\t\tWHERE rc.id=" . $refid;
     $database = App::get('db');
     $database->setQuery($query);
     $rows = $database->loadObjectList();
     if ($rows) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'models' . DS . 'manager.php';
         foreach ($rows as $key => $row) {
             /*$thread = $row->id;
             		if ($row->parent)
             		{
             			$thread = $this->_getThread($row->parent);
             		}*/
             if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $row->text, $matches)) {
                 $rows[$key]->text = preg_replace('/^(<!-- \\{FORMAT:.*\\} -->)/i', '', $row->text);
             }
             switch ($row->scope) {
                 case 'course':
                     require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'course.php';
                     $offering = \Components\Courses\Models\Offering::getInstance($row->scope_id);
                     $course = \Components\Courses\Models\Course::getInstance($offering->get('course_id'));
                     $url = 'index.php?option=com_courses&gid=' . $course->get('alias') . '&controller=offering&offering=' . $offering->get('alias') . '&active=discussions&thread=' . $row->thread;
                     break;
                 case 'group':
                     $group = \Hubzero\User\Group::getInstance($row->scope_id);
                     $url = 'index.php?option=com_groups&cn=' . $group->get('cn') . '&active=forum&scope=' . $row->section . '/' . $row->category . '/' . $parent;
                     break;
                 case 'site':
                 default:
                     $url = 'index.php?option=com_forum&section=' . $row->section . '&category=' . $row->category . '&thread=' . $parent;
                     break;
             }
             $rows[$key]->href = Route::url($url);
         }
     }
     return $rows;
 }
Esempio n. 18
0
 /**
  * Remove unused group folders
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function cleanGroupFolders(\Components\Cron\Models\Job $job)
 {
     // get group params
     $groupParameters = Component::params('com_groups');
     // get group upload path
     $groupUploadPath = ltrim($groupParameters->get('uploadpath', '/site/groups'), DS);
     // get group folders
     $groupFolders = Filesystem::directories(PATH_APP . DS . $groupUploadPath);
     // loop through each group folder
     foreach ($groupFolders as $groupFolder) {
         // load group object for each folder
         $hubzeroGroup = \Hubzero\User\Group::getInstance(trim($groupFolder));
         // if we dont have a group object delete folder
         if (!is_object($hubzeroGroup)) {
             // delete folder
             Filesystem::delete(PATH_APP . DS . $groupUploadPath . DS . $groupFolder);
         }
     }
     // job is no longer active
     return true;
 }
Esempio n. 19
0
 /**
  * Generate macro output
  *
  * @return     string
  */
 public function render()
 {
     //get the args passed in
     $args = explode(',', $this->args);
     //parse each arg into key value pair
     foreach ($args as $a) {
         $kv[] = explode('=', trim($a));
     }
     //set final args
     foreach ($kv as $k) {
         $arg[$k[0]] = isset($k[1]) ? $k[1] : $k[0];
     }
     //set a default
     //$default_events = 3;
     //get the user defined # of events
     //$num_events = (isset($arg['number']) && is_numeric($arg['number']) && $arg['number'] > 0) ? $arg['number'] : $default_events;
     //get the group
     $cn = Request::getVar('cn');
     //get the group object based on gid
     $group = \Hubzero\User\Group::getInstance($cn);
     //check to make sure we have a valid group
     if (!is_object($group)) {
         return '[This macro is designed for Groups only]';
     }
     //array of filters
     $filters = array('id' => isset($arg['id']) ? $arg['id'] : null, 'limit' => isset($arg['number']) ? $arg['number'] : 3);
     //get group events
     $events = $this->getGroupEvents($group, $filters);
     //create the html container
     $html = '<div class="upcoming_events">';
     //display the title
     $html .= isset($arg['title']) && $arg['title'] != '' ? '<h3>' . $arg['title'] . '</h3>' : '';
     //render the events
     $html .= $this->renderEvents($group, $events);
     //close the container
     $html .= '</div>';
     //return rendered events
     return $html;
 }
 /**
  * Up
  **/
 public function up()
 {
     // get groups who dont have a created value
     $query = "SELECT * FROM `#__xgroups` WHERE `created` IS NULL ";
     $this->db->setQuery($query);
     $groups = $this->db->loadObjectList();
     // get created logs
     $query2 = "SELECT `gidNumber`,`timestamp`,`actorid` FROM `#__xgroups_log` WHERE `action`='group_created'";
     $this->db->setQuery($query2);
     $logs = $this->db->loadAssocList('gidNumber');
     //check each group to see if we have a created log
     foreach ($groups as $group) {
         if (isset($logs[$group->gidNumber])) {
             $log = $logs[$group->gidNumber];
             $hubzeroUserGroup = \Hubzero\User\Group::getInstance($group->gidNumber);
             if (is_object($hubzeroUserGroup)) {
                 $hubzeroUserGroup->set('created', $log['timestamp']);
                 $hubzeroUserGroup->set('created_by', $log['actorid']);
                 $hubzeroUserGroup->update();
             }
         }
     }
 }
Esempio n. 21
0
 /**
  * Display module contents
  *
  * @return  void
  */
 public function run()
 {
     $database = \App::get('db');
     $uid = User::get('id');
     //get the params
     $this->cls = $this->params->get('moduleclass_sfx');
     $this->limit = $this->params->get('limit', 5);
     $this->charlimit = $this->params->get('charlimit', 100);
     $this->feedlink = $this->params->get('feedlink', 'yes');
     $this->morelink = $this->params->get('morelink', '');
     // Get popular groups
     $popularGroups = Group\Helper::getPopularGroups();
     $counter = 0;
     $groupsToDisplay = array();
     foreach ($popularGroups as $g) {
         // Get the group
         $group = Group::getInstance($g->gidNumber);
         // Check join policy
         $joinPolicy = $group->get('join_policy');
         // If group is invite only or closed check if th user is a member of the group
         if ($joinPolicy > 1) {
             // if not a member do not display the group
             if (!$group->isMember($uid)) {
                 continue;
             }
         }
         $groupsToDisplay[] = $g;
         $counter++;
         if ($counter == $this->limit) {
             break;
         }
     }
     //set groups to view
     $this->groups = $groupsToDisplay;
     require $this->getLayoutPath();
 }
Esempio n. 22
0
 /**
  * Process data
  *
  * @return     void
  */
 protected function _process()
 {
     // New project?
     $new = $this->model->exists() ? false : true;
     // Are we in setup?
     $setup = $new || $this->model->inSetup() ? true : false;
     // Incoming
     $private = Request::getInt('private', 1);
     // Save section
     switch ($this->section) {
         case 'describe':
         case 'info':
             // Incoming
             $name = trim(Request::getVar('name', '', 'post'));
             $title = trim(Request::getVar('title', '', 'post'));
             $name = preg_replace('/ /', '', $name);
             $name = strtolower($name);
             // Clean up title from any scripting
             $title = preg_replace('/\\s+/', ' ', $title);
             $title = $this->_txtClean($title);
             // Check incoming data
             if ($setup && $new && !$this->model->check($name, $this->model->get('id'))) {
                 $this->setError(Lang::txt('COM_PROJECTS_ERROR_NAME_INVALID_OR_EMPTY'));
                 return false;
             } elseif (!$title) {
                 $this->setError(Lang::txt('COM_PROJECTS_ERROR_TITLE_SHORT_OR_EMPTY'));
                 return false;
             }
             if ($this->model->exists()) {
                 $this->model->set('modified', Date::toSql());
                 $this->model->set('modified_by', User::get('id'));
             } else {
                 $this->model->set('alias', $name);
                 $this->model->set('created', Date::toSql());
                 $this->model->set('created_by_user', User::get('id'));
                 $this->model->set('owned_by_group', $this->_gid);
                 $this->model->set('owned_by_user', User::get('id'));
                 $this->model->set('private', $this->config->get('privacy', 1));
             }
             $this->model->set('title', \Hubzero\Utility\String::truncate($title, 250));
             $this->model->set('about', trim(Request::getVar('about', '', 'post', 'none', 2)));
             $this->model->set('type', Request::getInt('type', 1, 'post'));
             // save advanced permissions
             if (isset($_POST['private'])) {
                 $this->model->set('private', $private);
             }
             if ($setup && !$this->model->exists()) {
                 // Copy params from default project type
                 $objT = $this->model->table('Type');
                 $this->model->set('params', $objT->getParams($this->model->get('type')));
             }
             // Save changes
             if (!$this->model->store()) {
                 $this->setError($this->model->getError());
                 return false;
             }
             // Save owners for new projects
             if ($new) {
                 $this->_identifier = $this->model->get('alias');
                 // Group owners
                 $objO = $this->model->table('Owner');
                 if ($this->_gid) {
                     if (!$objO->saveOwners($this->model->get('id'), User::get('id'), 0, $this->_gid, 0, 1, 1, '', $split_group_roles = 0)) {
                         $this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError());
                         return false;
                     }
                     // Make sure project creator is manager
                     $objO->reassignRole($this->model->get('id'), $users = array(User::get('id')), 0, 1);
                 } elseif (!$objO->saveOwners($this->model->get('id'), User::get('id'), User::get('id'), $this->_gid, 1, 1, 1)) {
                     $this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError());
                     return false;
                 }
             }
             break;
         case 'team':
             if ($new) {
                 return false;
             }
             // Save team
             $content = Event::trigger('projects.onProject', array($this->model, 'save', array('team')));
             if (isset($content[0]) && $this->next == $this->section) {
                 if (isset($content[0]['msg']) && !empty($content[0]['msg'])) {
                     $this->_setNotification($content[0]['msg']['message'], $content[0]['msg']['type']);
                 }
             }
             break;
         case 'settings':
             if ($new) {
                 return false;
             }
             // Save privacy
             if (isset($_POST['private'])) {
                 $this->model->set('private', $private);
                 // Save changes
                 if (!$this->model->store()) {
                     $this->setError($this->model->getError());
                     return false;
                 }
             }
             // Save params
             $incoming = Request::getVar('params', array());
             if (!empty($incoming)) {
                 foreach ($incoming as $key => $value) {
                     $this->model->saveParam($key, $value);
                     // If grant information changed
                     if ($key == 'grant_status') {
                         // Meta data for comment
                         $meta = '<meta>' . Date::of('now')->toLocal('M d, Y') . ' - ' . User::get('name') . '</meta>';
                         $cbase = $this->model->get('admin_notes');
                         $cbase .= '<nb:sponsored>' . Lang::txt('COM_PROJECTS_PROJECT_MANAGER_GRANT_INFO_UPDATE') . $meta . '</nb:sponsored>';
                         $this->model->set('admin_notes', $cbase);
                         // Save admin notes
                         if (!$this->model->store()) {
                             $this->setError($this->model->getError());
                             return false;
                         }
                         $admingroup = $this->config->get('ginfo_group', '');
                         if (\Hubzero\User\Group::getInstance($admingroup)) {
                             $admins = Helpers\Html::getGroupMembers($admingroup);
                             // Send out email to admins
                             if (!empty($admins)) {
                                 Helpers\Html::sendHUBMessage($this->_option, $this->model, $admins, Lang::txt('COM_PROJECTS_EMAIL_ADMIN_REVIEWER_NOTIFICATION'), 'projects_new_project_admin', 'admin', Lang::txt('COM_PROJECTS_PROJECT_MANAGER_GRANT_INFO_UPDATE'), 'sponsored');
                             }
                         }
                     }
                 }
             }
             break;
     }
 }
Esempio n. 23
0
 /**
  * Approve a group
  *
  * @return void
  */
 public function approveTask()
 {
     // Incoming
     $ids = Request::getVar('id', array());
     // Get the single ID we're working with
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     // Do we have any IDs?
     if (!empty($ids)) {
         // foreach group id passed in
         foreach ($ids as $id) {
             // Load the group page
             $group = new Group();
             $group->read($id);
             // Ensure we found the group info
             if (!$group) {
                 continue;
             }
             //set the group to be published and update
             $group->set('approved', 1);
             $group->update();
             // log publishing
             Log::log(array('gidNumber' => $group->get('gidNumber'), 'action' => 'group_approved', 'comments' => 'approved by administrator'));
         }
         // Output messsage and redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_GROUPS_APPROVED'));
     }
 }
Esempio n. 24
0
 /**
  * Get Instance of Super Group Database
  *
  * Always returns the same instance whenever this method is called
  *
  * @param   array   $config  Array of database options
  * @param   string  $cname
  * @return  object  Database Object
  */
 public static function getDbo($config = array(), $cname = '')
 {
     // empty instance of db
     $db = \JDatabase::getInstance();
     // make sure we have a group object
     if (!($group = Group::getInstance(\Request::getVar('cn', $cname)))) {
         return $db;
     }
     // make sure we are a super group
     if (!$group->isSuperGroup()) {
         return $db;
     }
     // load super group db config if not passed in
     if (empty($config)) {
         // build path to config file
         $uploadPath = \Component::params('com_groups')->get('uploadpath');
         $configPath = PATH_APP . DS . trim($uploadPath, DS) . DS . $group->get('gidNumber') . DS . 'config' . DS . 'db.php';
         // make sure file exists
         if (!file_exists($configPath)) {
             return $db;
         }
         // include config
         $config = (include $configPath);
     }
     // return instance of db
     return \JDatabase::getInstance($config);
 }
Esempio n. 25
0
 /**
  * Function to return group object 
  * 
  * @param   integer  $gidNumber  Group identifier
  * @return  object   Group object
  */
 private function groupExpander($gidNumber)
 {
     return Group::getInstance($gidNumber);
 }
Esempio n. 26
0
 /**
  * Check user access
  *
  * @param   array    $curatorgroups
  * @param   integer  $curator
  * @return  mixed    False if no access, string if has access
  */
 protected function _authorize($curatorgroups = array(), $curator = 0)
 {
     // Check if they are logged in
     if (User::isGuest()) {
         return false;
     }
     $authorized = false;
     // Check if they're a site admin (from Joomla)
     if (User::authorize($this->_option, 'manage')) {
         $authorized = 'admin';
     }
     if ($curator && $curator == User::get('id')) {
         $authorized = 'owner';
         return $authorized;
     }
     $curatorgroup = $this->config->get('curatorgroup', '');
     if ($curatorgroup) {
         $curatorgroups[] = $curatorgroup;
     }
     if (!empty($curatorgroups)) {
         foreach ($curatorgroups as $curatorgroup) {
             if ($group = \Hubzero\User\Group::getInstance($curatorgroup)) {
                 // Check if they're a member of this group
                 $ugs = \Hubzero\User\Helper::getGroups(User::get('id'));
                 if ($ugs && count($ugs) > 0) {
                     foreach ($ugs as $ug) {
                         if ($group && $ug->cn == $group->get('cn')) {
                             $authorized = $ug->cn == $curatorgroup ? 'curator' : 'limited';
                         }
                     }
                 }
             }
         }
     }
     return $authorized;
 }
Esempio n. 27
0
 /**
  * Get parent group
  *
  * @return  object
  */
 public function group()
 {
     return \Hubzero\User\Group::getInstance($this->get('group_id'));
 }
Esempio n. 28
0
						</a>
					<?php 
    }
    ?>
				</td>
				<td class="priority-4" style="white-space: nowrap;">
					<?php 
    echo $times;
    ?>
				</td>
				<td class="priority-5">
					<?php 
    if ($row->scope == 'group') {
        ?>
						<?php 
        $group = \Hubzero\User\Group::getInstance($row->scope_id);
        if (is_object($group)) {
            echo Lang::txt('COM_EVENTS_EVENT_GROUP', Route::url('index.php?option=com_events&group_id=' . $group->get('gidNumber')), $group->get('description'));
        } else {
            echo Lang::txt('COM_EVENTS_EVENT_GROUP_NOT_FOUND', $row->scope_id);
        }
        ?>
					<?php 
    } else {
        ?>
						<span>
							<?php 
        echo $this->escape(stripslashes($row->groupname));
        ?>
						</span>
					<?php 
Esempio n. 29
0
 /**
  * Save invitation
  *
  * @param      integer $projectid
  * @param      string  $actor      user id of person adding new member
  * @param      integer $userid
  * @param      integer $groupid
  * @param      integer $role
  * @param      integer $status
  * @param      integer $native
  * @param      string  $invited_email
  * @param      boolean $split_group_roles preserve group roles when adding to a project (manager/member)
  * @return     false if error, integer on success (number of saved records)
  */
 public function saveOwners($projectid = NULL, $actor = 0, $userid = 0, $groupid = 0, $role = 0, $status = 1, $native = 0, $invited_email = '', $split_group_roles = 0)
 {
     if ($projectid === NULL || !intval($projectid)) {
         return false;
     }
     $owners = array();
     $now = Date::toSql();
     $added = array();
     // Individual user added
     if ($userid && is_numeric($userid)) {
         $query = "SELECT status FROM {$this->_tbl} WHERE userid=" . $this->_db->quote($userid) . " AND projectid=" . $this->_db->quote($projectid) . " LIMIT 1";
         $this->_db->setQuery($query);
         $found = $this->_db->loadResult();
         if ($found === NULL) {
             // User not in project
             $query = "INSERT INTO {$this->_tbl} (`projectid`, `userid`, `groupid`, `added`, `status`, `native`, `role`, `invited_email` ) SELECT {$projectid}, {$userid}, {$groupid} , '{$now}', {$status}, {$native}, {$role}, '{$invited_email}' FROM DUAL WHERE NOT EXISTS (SELECT `id` FROM {$this->_tbl} WHERE `projectid` = {$projectid} AND `userid` = {$userid} LIMIT 1)";
             $this->_db->setQuery($query);
             if ($this->_db->query()) {
                 $added[] = $userid;
             }
         } elseif ($found != 1) {
             // Inactive/deleted - activate
             $query = "UPDATE {$this->_tbl} SET added = '{$now}', status = 1, role = " . $this->_db->quote($role) . ", groupid = " . $this->_db->quote($groupid) . "  WHERE projectid = " . $this->_db->quote($projectid) . " AND userid= " . $this->_db->quote($userid);
             $this->_db->setQuery($query);
             if ($this->_db->query()) {
                 $added[] = $userid;
             }
         }
     }
     // Group members added
     if ($groupid && !$userid) {
         $group = \Hubzero\User\Group::getInstance($groupid);
         $gidNumber = $group ? $group->get('gidNumber') : 0;
         if ($gidNumber) {
             $members = $group->get('members');
             $managers = $group->get('managers');
             $owners = $members + $managers;
             $owners = array_unique($owners);
             if (!in_array($actor, $owners)) {
                 $this->setError(Lang::txt('COM_PROJECTS_TEAM_ERROR_NEED_TO_BELONG_TO_GROUP'));
                 return $added;
             }
             foreach ($owners as $owner) {
                 $query = "SELECT status FROM {$this->_tbl} WHERE userid=" . $this->_db->quote($owner) . " AND projectid=" . $this->_db->quote($projectid) . " LIMIT 1";
                 $this->_db->setQuery($query);
                 $found = $this->_db->loadResult();
                 // Group managers become project managers
                 if ($split_group_roles) {
                     $role = in_array($owner, $managers) ? 1 : 0;
                 }
                 if ($found === NULL) {
                     // User not in project
                     $query = "INSERT INTO {$this->_tbl} (`projectid`, `userid`, `groupid`, `added`, `status`, `native`, `role`, `invited_email` ) SELECT {$projectid}, {$owner}, {$gidNumber}, '{$now}', {$status}, {$native}, {$role}, '{$invited_email}' FROM DUAL WHERE NOT EXISTS (SELECT `id` FROM {$this->_tbl} WHERE `projectid` = {$projectid} AND `userid` = {$userid} LIMIT 1)";
                     $this->_db->setQuery($query);
                     if ($this->_db->query()) {
                         $added[] = $owner;
                     }
                 } elseif ($found != 1) {
                     // Inactive/deleted - activate
                     $query = "UPDATE {$this->_tbl} SET added = " . $this->_db->quote($now) . ", status = 1, groupid = " . $this->_db->quote($gidNumber) . ", role = " . $this->_db->quote($role) . "  WHERE projectid = " . $this->_db->quote($projectid) . " AND userid = " . $this->_db->quote($owner);
                     $this->_db->setQuery($query);
                     if ($this->_db->query()) {
                         $added[] = $owner;
                     }
                 }
             }
         } else {
             $this->setError(Lang::txt('COM_PROJECTS_TEAM_ERROR_GROUP_NOT_FOUND'));
         }
     }
     return $added;
 }
Esempio n. 30
0
 /**
  * Assign members to a role
  *
  * @return  void
  */
 public function delegateTask()
 {
     Request::setVar('hidemainmenu', 1);
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     $gid = Request::getVar('gid', '');
     $roleid = Request::getInt('roleid', 0);
     if (!$gid) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_GROUPS_MISSING_ID'), 'error');
     }
     $group = new Group();
     $group->read($gid);
     foreach ($ids as $id) {
         $model = \Components\Groups\Models\Member\Role::oneByUserAndRole((int) $id, $roleid);
         if (!$model->get('id')) {
             $model->set('roleid', $roleid);
             $model->set('uidNumber', (int) $id);
             $model->save();
         }
     }
     $this->cancelTask();
 }