Example #1
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' => '');
     $database = App::get('db');
     // Build the query that checks topic pages
     $sql1 = "SELECT v.id, v.pageid, MAX(v.version) AS version, w.title, w.pagename AS alias, v.pagetext AS introtext,\n\t\t\t\t\tNULL AS type, NULL AS published, NULL AS publish_up, w.scope, w.rating, w.times_rated, w.ranking, 'Topic' AS section, w.`group_cn`\n\t\t\t\tFROM `#__wiki_page` AS w\n\t\t\t\tJOIN `#__wiki_version` AS v ON w.id=v.pageid\n\t\t\t\tJOIN `#__wiki_page_links` AS wl ON wl.page_id=w.id\n\t\t\t\tWHERE v.approved=1 AND wl.scope='resource' AND wl.scope_id=" . $database->Quote($resource->id);
     if (!User::isGuest()) {
         if (User::authorize('com_resources', 'manage') || User::authorize('com_groups', 'manage')) {
             $sql1 .= '';
         } else {
             $ugs = \Hubzero\User\Helper::getGroups(User::get('id'), 'members');
             $groups = array();
             if ($ugs && count($ugs) > 0) {
                 foreach ($ugs as $ug) {
                     $groups[] = $ug->cn;
                 }
             }
             $g = "'" . implode("','", $groups) . "'";
             $sql1 .= "AND (w.access!=1 OR (w.access=1 AND (w.group_cn IN ({$g}) OR w.created_by='" . User::get('id') . "'))) ";
         }
     } else {
         $sql1 .= "AND w.access!=1 ";
     }
     $sql1 .= "GROUP BY pageid ORDER BY ranking DESC, title LIMIT 10";
     // Build the query that checks resource parents
     $sql2 = "SELECT DISTINCT r.id, NULL AS pageid, NULL AS version, r.title, r.alias, r.introtext, r.type, r.published, r.publish_up, " . " NULL AS scope, r.rating, r.times_rated, r.ranking, rt.type AS section, NULL AS `group` " . " FROM #__resource_types AS rt, #__resources AS r" . " JOIN #__resource_assoc AS a ON r.id=a.parent_id" . " LEFT JOIN #__resource_types AS t ON r.logical_type=t.id" . " WHERE r.published=1 AND a.child_id=" . $resource->id . " AND r.type=rt.id AND r.type!=8 ";
     if (!User::isGuest()) {
         if (User::authorize('com_resources', 'manage') || User::authorize('com_groups', 'manage')) {
             $sql2 .= '';
         } else {
             $sql2 .= "AND (r.access!=1 OR (r.access=1 AND (r.group_owner IN ({$g}) OR r.created_by='" . User::get('id') . "'))) ";
         }
     } else {
         $sql2 .= "AND r.access=0 ";
     }
     $sql2 .= "ORDER BY r.ranking LIMIT 10";
     // Build the final query
     $query = "SELECT k.* FROM (({$sql1}) UNION ({$sql2})) AS k ORDER BY ranking DESC LIMIT 10";
     // Execute the query
     $database->setQuery($query);
     $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse'));
     // Instantiate a view
     if ($miniview) {
         $view->setLayout('mini');
     }
     // Pass the view some info
     $view->option = $option;
     $view->resource = $resource;
     $view->related = $database->loadObjectList();
     foreach ($this->getErrors() as $error) {
         $view->setError($error);
     }
     // Return the output
     $arr['html'] = $view->loadTemplate();
     // Return the an array of content
     return $arr;
 }
Example #2
0
 /**
  * Display module content
  *
  * @return  void
  */
 public function display()
 {
     $database = \App::get('db');
     $this->moduleclass = $this->params->get('moduleclass');
     $limit = intval($this->params->get('limit', 10));
     // Find the user's most recent support tickets
     $database->setQuery("(\n\t\t\t\tSELECT id, summary, category, open, status, severity, owner, created, login, name,\n\t\t\t\t\t(SELECT COUNT(*) FROM #__support_comments as sc WHERE sc.ticket=st.id AND sc.access=0) as comments\n\t\t\t\tFROM #__support_tickets as st\n\t\t\t\tWHERE st.login="******" AND st.open=1 AND type=0\n\t\t\t\tORDER BY created DESC\n\t\t\t\tLIMIT {$limit}\n\t\t\t)\n\t\t\tUNION\n\t\t\t(\n\t\t\t\tSELECT id, summary, category, open, status, severity, owner, created, login, name,\n\t\t\t\t\t(SELECT COUNT(*) FROM #__support_comments as sc WHERE sc.ticket=st.id AND sc.access=0) as comments\n\t\t\t\tFROM #__support_tickets as st\n\t\t\t\tWHERE st.owner=" . $database->quote(User::get('id')) . " AND st.open=1 AND type=0\n\t\t\t\tORDER BY created DESC\n\t\t\t\tLIMIT {$limit}\n\t\t\t)");
     $this->rows = $database->loadObjectList();
     if ($database->getErrorNum()) {
         $this->setError($database->stderr());
         $this->rows = array();
     }
     $rows1 = array();
     $rows2 = array();
     if ($this->rows) {
         foreach ($this->rows as $row) {
             if ($row->owner == User::get('id')) {
                 $rows2[] = $row;
             } else {
                 $rows1[] = $row;
             }
         }
     }
     $this->rows1 = $rows1;
     $this->rows2 = $rows2;
     $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'members', 1);
     $groups = '';
     if ($xgroups) {
         $g = array();
         foreach ($xgroups as $xgroup) {
             $g[] = $database->quote($xgroup->cn);
         }
         $groups = implode(",", $g);
     }
     $this->rows3 = null;
     if ($groups) {
         // Find support tickets on the user's contributions
         $database->setQuery("SELECT id, summary, category, open, status, severity, owner, created, login, name,\n\t\t\t\t\t(SELECT COUNT(*) FROM `#__support_comments` as sc WHERE sc.ticket=st.id AND sc.access=0) as comments\n\t\t\t\tFROM `#__support_tickets` as st\n\t\t\t\tWHERE st.open=1 AND type=0 AND st.group IN ({$groups})\n\t\t\t\tORDER BY created DESC\n\t\t\t\tLIMIT {$limit}");
         $this->rows3 = $database->loadObjectList();
         if ($database->getErrorNum()) {
             $this->setError($database->stderr());
             $this->rows3 = null;
         }
     }
     require $this->getLayoutPath();
 }
Example #3
0
function authorized()
{
    global $conf;
    if ($conf['access_limit_to_group'] === false) {
        return true;
    }
    if ($conf['access_limit_to_group'] !== false && !User::isGuest()) {
        $groups = \Hubzero\User\Helper::getGroups(User::get('id'));
        if ($groups && count($groups)) {
            foreach ($groups as $g) {
                if ($g->cn == $conf['access_limit_to_group']) {
                    return true;
                }
            }
        }
    }
    return false;
}
Example #4
0
function dv_auth()
{
    global $dv_conf;
    if (isset($dd['acl']['allowed_users']) && (is_array($dd['acl']['allowed_users']) || $dd['acl']['allowed_users'] === false || $dd['acl']['allowed_users'] == 'registered')) {
        $dv_conf['acl']['allowed_users'] = $dd['acl']['allowed_users'];
    }
    if (isset($dd['acl']['allowed_groups']) && (is_array($dd['acl']['allowed_groups']) || $dd['acl']['allowed_groups'] === false)) {
        $dv_conf['acl']['allowed_groups'] = $dd['acl']['allowed_groups'];
    }
    if ($dv_conf['acl']['allowed_users'] === false && $dv_conf['acl']['allowed_groups'] === false) {
        return true;
    } elseif (User::isGuest()) {
        $redir_url = '?return=' . base64_encode($_SERVER['REQUEST_URI']);
        $login_url = '/login';
        $url = $login_url . $redir_url;
        header('Location: ' . $url);
        return;
    }
    if ($dv_conf['acl']['allowed_users'] !== false && $dv_conf['acl']['allowed_users'] == 'registered' && !User::isGuest()) {
        return true;
    } elseif (isset($dv_conf['acl']['allowed_users']) && is_array($dv_conf['acl']['allowed_users']) && !User::isGuest()) {
        if (in_array(User::get('username'), $dv_conf['acl']['allowed_users'])) {
            return true;
        }
    }
    if ($dv_conf['acl']['allowed_groups'] !== false && is_array($dv_conf['acl']['allowed_groups']) && !User::isGuest()) {
        $groups = \Hubzero\User\Helper::getGroups(User::get('id'));
        if ($groups && count($groups)) {
            foreach ($groups as $g) {
                if (in_array($g->cn, $dv_conf['acl']['allowed_groups'])) {
                    return true;
                }
            }
        }
    }
    return false;
}
Example #5
0
 /**
  * Return data on a publication sub view (this will be some form of HTML)
  *
  * @param      object  $publication 	Current publication
  * @param      string  $option    		Name of the component
  * @param      integer $miniview  		View style
  * @return     array
  */
 public function onPublicationSub($publication, $option, $miniview = 0)
 {
     $arr = array('html' => '', 'metadata' => '');
     // Check if our area is in the array of areas we want to return results for
     $areas = array('related');
     if (!array_intersect($areas, $this->onPublicationSubAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationSubAreas($publication)))) {
         return false;
     }
     $database = App::get('db');
     // Build the query that checks topic pages
     $sql1 = "SELECT v.id, v.page_id AS pageid, MAX(v.version) AS version, w.title, w.pagename AS alias, v.pagetext AS abstract,\n\t\t\t\t\tNULL AS category, NULL AS published, NULL AS publish_up, w.scope, w.rating, w.times_rated, w.ranking, 'wiki' AS class, 'Topic' AS section\n\t\t\t\tFROM `#__wiki_pages` AS w\n\t\t\t\tJOIN `#__wiki_versions` AS v ON w.id=v.page_id\n\t\t\t\tJOIN `#__wiki_links` AS wl ON wl.page_id=w.id\n\t\t\t\tWHERE v.approved=1 AND wl.scope='publication' AND wl.scope_id=" . $database->quote($publication->id);
     if (!User::isGuest()) {
         if (User::authorise('com_resources', 'manage') || User::authorise('com_groups', 'manage')) {
             $sql1 .= '';
         } else {
             $ugs = \Hubzero\User\Helper::getGroups(User::get('id'), 'members');
             $groups = array();
             $cns = array();
             if ($ugs && count($ugs) > 0) {
                 foreach ($ugs as $ug) {
                     $cns[] = $database->quote($ug->cn);
                     $groups[] = $database->quote($ug->gidNumber);
                 }
             }
             $g = implode(",", $groups);
             $c = implode(",", $cns);
             $sql1 .= "AND (w.access!=1 OR (w.access=1 AND ((w.scope=" . $database->quote('group') . " AND w.scope_id IN ({$g})) OR w.created_by=" . $database->quote(User::get('id')) . "))) ";
         }
     } else {
         $sql1 .= "AND w.access!=1 ";
     }
     $sql1 .= "GROUP BY pageid ORDER BY ranking DESC, title LIMIT 10";
     // Initiate a helper class
     $model = new \Components\Publications\Models\Publication($publication);
     $tags = $model->getTags();
     // Get version authors
     $authors = isset($publication->_authors) ? $publication->_authors : array();
     // Build the query that get publications related by tag
     $sql2 = "SELECT DISTINCT r.publication_id as id, NULL AS pageid, r.id AS version,\n\t\t\t\tr.title, C.alias, r.abstract, C.category, r.state as published,\n\t\t\t\tr.published_up, NULL AS scope, C.rating, C.times_rated, C.ranking,\n\t\t\t\trt.alias AS class, rt.name AS section" . "\n FROM #__publications as C, #__publication_categories AS rt, #__publication_versions AS r " . "\n JOIN #__tags_object AS a ON r.publication_id=a.objectid AND a.tbl='publications'" . "\n JOIN #__publication_authors AS PA ON PA.publication_version_id=r.id " . "\n WHERE C.id=r.publication_id ";
     if ($tags) {
         $tquery = array(0);
         foreach ($tags as $tagg) {
             $tquery[] = $database->quote($tagg->get('id'));
         }
         $sql2 .= " AND ( a.tagid IN (" . implode(',', $tquery) . ")";
         $sql2 .= count($authors) > 0 ? " OR " : "";
     }
     if (count($authors) > 0) {
         $aquery = '';
         foreach ($authors as $author) {
             $aquery .= "'" . $author->user_id . "',";
         }
         $aquery = substr($aquery, 0, strlen($aquery) - 1);
         $sql2 .= $tags ? "" : " AND ( ";
         $sql2 .= " PA.user_id IN (" . $aquery . ")";
     }
     $sql2 .= $tags || count($authors) > 0 ? ")" : "";
     $sql2 .= " AND r.publication_id !=" . $publication->id;
     $sql2 .= " AND C.category = rt.id AND C.category!=8 ";
     $sql2 .= "AND r.access=0 ";
     $sql2 .= "AND r.state=1 ";
     $sql2 .= "GROUP BY r.publication_id ORDER BY r.ranking LIMIT 10";
     // Build the final query
     $query = "SELECT k.* FROM (({$sql1}) UNION ({$sql2})) AS k ORDER BY ranking DESC LIMIT 10";
     // Execute the query
     $database->setQuery($query);
     $related = $database->loadObjectList();
     // Instantiate a view
     if ($miniview) {
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'related', 'name' => 'browse', 'layout' => 'mini'));
     } else {
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'related', 'name' => 'browse'));
     }
     // Pass the view some info
     $view->option = $option;
     $view->publication = $publication;
     $view->related = $related;
     if ($this->getError()) {
         $view->setError($this->getError());
     }
     // Return the output
     $arr['html'] = $view->loadTemplate();
     // Return the an array of content
     return $arr;
 }
Example #6
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;
 }
Example #7
0
 /**
  * Processes the password set form
  *
  * @return  void
  */
 public function settingpasswordTask()
 {
     // Check for request forgeries
     Session::checkToken('post') or exit(Lang::txt('JINVALID_TOKEN'));
     // Get the token and user id from the verification process
     $token = User::getState('com_users.reset.token', null);
     $id = User::getState('com_users.reset.user', null);
     $no_html = Request::getInt('no_html', 0);
     // Check the token and user id
     if (empty($token) || empty($id)) {
         throw new Exception(Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_TOKENS_MISSING'), 403);
     }
     // Get the user object
     $user = \Hubzero\User\User::oneOrFail($id);
     // Check for a user and that the tokens match
     if ($user->tokens()->latest()->token !== $token) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=setpassword', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_USER_NOT_FOUND'), 'warning');
         return;
     }
     // Make sure the user isn't blocked
     if ($user->get('block')) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=setpassword', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_USER_NOT_FOUND'), 'warning');
         return;
     }
     if (\Hubzero\User\Helper::isXDomainUser($user->get('id'))) {
         throw new Exception(Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_LINKED_ACCOUNT'), 403);
     }
     $password_rules = \Hubzero\Password\Rule::all()->whereEquals('enabled', 1)->rows();
     $password1 = trim(Request::getVar('password1', null));
     $password2 = trim(Request::getVar('password2', null));
     if (!empty($password1)) {
         $msg = \Hubzero\Password\Rule::verify($password1, $password_rules, $user->get('username'));
     } else {
         $msg = array();
     }
     require_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'utility.php';
     $error = false;
     $changing = true;
     if (!$password1 || !$password2) {
         $error = Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_PASSWORD_TWICE');
     } elseif ($password1 != $password2) {
         $error = Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_PASSWORD_DONT_MATCH');
     } elseif (!\Components\Members\Helpers\Utility::validpassword($password1)) {
         $error = Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_PASSWORD_INVALID');
     } elseif (!empty($msg)) {
         $error = Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_PASSWORD_FAILS_REQUIREMENTS');
     }
     // If we're resetting password to the current password, just return true
     // That way you can't reset the counter on your current password, or invalidate it by putting it into history
     if (\Hubzero\User\Password::passwordMatches($user->get('id'), $password1)) {
         $error = false;
         $changing = false;
         $result = true;
     }
     if ($error) {
         if ($no_html) {
             $response = array('success' => false, 'message' => $error);
             echo json_encode($response);
             die;
         } else {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&task=setpassword', false), $error, 'warning');
             return;
         }
     }
     if ($changing) {
         // Encrypt the password and update the profile
         $result = \Hubzero\User\Password::changePassword($user->get('username'), $password1);
     }
     // Save the changes
     if (!$result) {
         if ($no_html) {
             $response = array('success' => false, 'message' => Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_GENERIC'));
             echo json_encode($response);
             die;
         } else {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&task=setpassword', false), Lang::txt('COM_MEMBERS_CREDENTIALS_ERROR_GENERIC'), 'warning');
             return;
         }
     }
     // Flush the user data from the session
     User::setState('com_users.reset.token', null);
     User::setState('com_users.reset.user', null);
     if ($no_html) {
         $response = array('success' => true, 'redirect' => Route::url('index.php?option=com_users&view=login', false));
         echo json_encode($response);
         die;
     } else {
         // Everything went well...go to the login page
         App::redirect(Route::url('index.php?option=com_users&view=login', false), Lang::txt('COM_MEMBERS_CREDENTIALS_PASSWORD_RESET_COMPLETE'), 'passed');
     }
 }
Example #8
0
 /**
  * @since	1.6
  */
 function processResetComplete($data)
 {
     // Get the form.
     $form = $this->getResetCompleteForm();
     // Check for an error.
     if ($form instanceof Exception) {
         return $form;
     }
     // Filter and validate the form data.
     $data = $form->filter($data);
     $return = $form->validate($data);
     // Check for an error.
     if ($return instanceof Exception) {
         return $return;
     }
     // Check the validation results.
     if ($return === false) {
         // Get the validation messages from the form.
         foreach ($form->getErrors() as $message) {
             $this->setError($message);
         }
         return false;
     }
     // Get the token and user id from the confirmation process.
     $app = JFactory::getApplication();
     $token = $app->getUserState('com_users.reset.token', null);
     $id = $app->getUserState('com_users.reset.user', null);
     // Check the token and user id.
     if (empty($token) || empty($id)) {
         return new Exception(Lang::txt('COM_USERS_RESET_COMPLETE_TOKENS_MISSING'), 403);
     }
     // Get the user object.
     $user = User::getInstance($id);
     // Check for a user and that the tokens match.
     if (empty($user) || $user->activation !== $token) {
         $this->setError(Lang::txt('COM_USERS_USER_NOT_FOUND'));
         return false;
     }
     // Make sure the user isn't blocked.
     if ($user->block) {
         $this->setError(Lang::txt('COM_USERS_USER_BLOCKED'));
         return false;
     }
     // Initiate profile classs
     $profile = User::getInstance($id);
     if (\Hubzero\User\Helper::isXDomainUser($user->get('id'))) {
         App::abort(403, Lang::txt('This is a linked account. To change your password you must change it using the procedures available where the account you are linked to is managed.'));
         return;
     }
     $password_rules = \Hubzero\Password\Rule::all()->whereEquals('enabled', 1)->rows();
     $password1 = $data['password1'];
     $password2 = $data['password2'];
     if (!empty($password1)) {
         $msg = \Hubzero\Password\Rule::verify($password1, $password_rules, $profile->get('username'));
     } else {
         $msg = array();
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'helpers' . DS . 'utility.php';
     if (!$password1 || !$password2) {
         $this->setError(Lang::txt('you must enter your new password twice to ensure we have it correct'));
     } elseif ($password1 != $password2) {
         $this->setError(Lang::txt('the new password and confirmation you entered do not match. Please try again'));
     } elseif (!\Components\Members\Helpers\Utility::validpassword($password1)) {
         $this->setError(Lang::txt('the password you entered was invalid password. You may be using characters that are not allowed'));
     } elseif (!empty($msg)) {
         $this->setError(Lang::txt('the password does not meet site password requirements. Please choose a password meeting all the requirements listed below.'));
     }
     if ($this->getError()) {
         $this->setError($this->getError());
         return false;
     }
     // Encrypt the password and update the profile
     $result = \Hubzero\User\Password::changePassword($profile->get('username'), $password1);
     // Save the changes
     if (!$result) {
         $this->setError(Lang::txt('There was an error changing your password.'));
         return false;
     }
     // Flush the user data from the session.
     $app->setUserState('com_users.reset.token', null);
     $app->setUserState('com_users.reset.user', null);
     return true;
 }
Example #9
0
 /**
  * Get all resources associated with a tag
  *
  * @param      string  $tag      Tag to find data for
  * @param      integer $id       Resource ID
  * @param      integer $type     Resource type
  * @param      string  $sortby   Sort data by
  * @param      string  $tag2     Secondary tag
  * @param      array   $filterby Extra, optional filters
  * @return     array
  */
 public function get_objects_on_tag($tag = '', $id = 0, $type = 0, $sortby = 'title', $tag2 = '', $filterby = array())
 {
     $now = \Date::toSql();
     if ($tag || $tag2) {
         $query = "SELECT C.id, TA.tag, COUNT(DISTINCT TA.tag) AS uniques, ";
         if ($type == 7) {
             $query .= "TV.title ";
         } else {
             $query .= "C.title ";
         }
         switch ($sortby) {
             case 'users':
                 $query .= ", (SELECT rs.users FROM #__resource_stats AS rs WHERE rs.resid=C.id AND rs.period=14 ORDER BY rs.datetime DESC LIMIT 1) AS users ";
                 break;
             case 'jobs':
                 $query .= ", (SELECT rs.jobs FROM #__resource_stats AS rs WHERE rs.resid=C.id AND rs.period=14 ORDER BY rs.datetime DESC LIMIT 1) AS jobs ";
                 break;
         }
         $query .= "FROM #__resources AS C ";
         if ($id) {
             $query .= "INNER JOIN #__resource_assoc AS RA ON (RA.child_id = C.id AND RA.parent_id=" . $id . ")";
         }
         if ($type == 7) {
             if (!empty($filterby)) {
                 $query .= " LEFT JOIN #__resource_taxonomy_audience AS TTA ON C.id=TTA.rid ";
             }
             $query .= ", #__tool_version as TV ";
         }
         $query .= ", `#__tags_object` AS RTA INNER JOIN #__tags AS TA ON (RTA.tagid = TA.id) ";
     } else {
         $query = "SELECT C.id,  ";
         if ($type == 7) {
             $query .= "TV.title ";
         } else {
             $query .= "C.title ";
         }
         switch ($sortby) {
             case 'users':
                 $query .= ", (SELECT rs.users FROM #__resource_stats AS rs WHERE rs.resid=C.id AND rs.period=12 ORDER BY rs.datetime DESC LIMIT 1) AS users ";
                 break;
             case 'jobs':
                 $query .= ", (SELECT rs.jobs FROM #__resource_stats AS rs WHERE rs.resid=C.id AND rs.period=12 ORDER BY rs.datetime DESC LIMIT 1) AS jobs ";
                 break;
         }
         $query .= "FROM #__resources AS C ";
         if ($id) {
             $query .= "INNER JOIN #__resource_assoc AS RA ON (RA.child_id = C.id AND RA.parent_id=" . $id . ")";
         }
         if ($type == 7) {
             if (!empty($filterby)) {
                 $query .= " LEFT JOIN #__resource_taxonomy_audience AS TTA ON C.id=TTA.rid ";
             }
             $query .= ", #__tool_version as TV ";
         }
     }
     $query .= "WHERE C.published=1 AND C.standalone=1 ";
     if ($type) {
         $query .= "AND C.type=" . $type . " ";
     }
     if ($type == 7) {
         $query .= " AND TV.toolname=C.alias AND TV.state=1 AND TV.revision = (SELECT MAX(revision) FROM #__tool_version as TV WHERE TV.toolname=C.alias AND TV.state=1 GROUP BY TV.toolid) ";
     }
     if (!empty($filterby) && $type == 7) {
         $fquery = " AND ((";
         for ($i = 0, $n = count($filterby); $i < $n; $i++) {
             $fquery .= " TTA." . $filterby[$i] . " = '1'";
             $fquery .= $i + 1 == $n ? "" : " OR ";
         }
         $fquery .= ") OR (";
         for ($i = 0, $n = count($filterby); $i < $n; $i++) {
             $fquery .= " TTA." . $filterby[$i] . " IS NULL";
             $fquery .= $i + 1 == $n ? "" : " OR ";
         }
         $fquery .= "))";
         $query .= $fquery;
     }
     $query .= "AND (C.publish_up = '0000-00-00 00:00:00' OR C.publish_up <= '" . $now . "') ";
     $query .= "AND (C.publish_down = '0000-00-00 00:00:00' OR C.publish_down >= '" . $now . "') AND ";
     if (!\User::isGuest()) {
         $xgroups = \Hubzero\User\Helper::getGroups(\User::get('id'), 'all');
         if ($xgroups != '') {
             $usersgroups = self::getUsersGroups($xgroups);
             if (count($usersgroups) > 1) {
                 $groups = implode("','", $usersgroups);
             } else {
                 $groups = count($usersgroups) ? $usersgroups[0] : '';
             }
             $query .= "(C.access=0 OR C.access=1 OR C.access=3 OR (C.access=4 AND (C.group_owner IN ('" . $groups . "') ";
             foreach ($usersgroups as $group) {
                 $query .= " OR C.group_access LIKE '%;" . $group . ";%'";
             }
             $query .= "))) ";
         } else {
             $query .= "(C.access=0 OR C.access=1 OR C.access=3) ";
         }
     } else {
         $query .= "(C.access=0 OR C.access=3) ";
     }
     if ($tag || $tag2) {
         if ($tag && !$tag2) {
             $query .= "AND RTA.objectid=C.id AND RTA.tbl='{$this->_scope}' AND (TA.tag IN ('" . $tag . "'))";
             $query .= " GROUP BY C.id HAVING uniques=1";
         } else {
             if ($tag2 && !$tag) {
                 $query .= "AND RTA.objectid=C.id AND RTA.tbl='{$this->_scope}' AND (TA.tag IN ('" . $tag2 . "'))";
                 $query .= " GROUP BY C.id HAVING uniques=1";
             } else {
                 if ($tag && $tag2) {
                     $query .= "AND RTA.objectid=C.id AND RTA.tbl='{$this->_scope}' AND (TA.tag IN ('" . $tag . "','" . $tag2 . "'))";
                     $query .= " GROUP BY C.id HAVING uniques=2";
                 }
             }
         }
     }
     switch ($sortby) {
         case 'ranking':
             $sort = "ranking DESC";
             break;
         case 'date':
             $sort = "publish_up DESC";
             break;
         case 'users':
             $sort = "users DESC";
             break;
         case 'jobs':
             $sort = "jobs DESC";
             break;
         default:
         case 'title':
             $sort = "title ASC";
             break;
     }
     $query .= " ORDER BY " . $sort . ", publish_up";
     $this->_db->setQuery($query);
     return $this->_db->loadObjectList();
 }
Example #10
0
 /**
  * Get the access level for this user and tool
  *
  * @param      string $tool  Tool name
  * @param      string $login Username
  * @return     boolean True if the user has access
  */
 private function _getToolAccess($tool, $login = '')
 {
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'tool.php';
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'group.php';
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'version.php';
     // Ensure we have a tool
     if (!$tool) {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_TOOL_NOT_FOUND'));
         Log::debug("mw::_getToolAccess({$tool},{$login}) FAILED null tool check");
         return false;
     }
     // Ensure we have a login
     if ($login == '') {
         $login = User::get('username');
         if ($login == '') {
             Log::debug("mw::_getToolAccess({$tool},{$login}) FAILED null user check");
             return false;
         }
     }
     $tv = new \Components\Tools\Tables\Version($this->database);
     $tv->loadFromInstance($tool);
     if (empty($tv->id)) {
         Log::debug("mw::_getToolAccess({$tool},{$login}) FAILED null tool version check");
         return false;
     }
     $tg = new \Components\Tools\Tables\Group($this->database);
     $this->database->setQuery("SELECT * FROM " . $tg->getTableName() . " WHERE toolid=" . $tv->toolid);
     $toolgroups = $this->database->loadObjectList();
     if (empty($toolgroups)) {
         //Log::debug("mw::_getToolAccess($tool,$login) WARNING: no tool member groups");
     }
     $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'members');
     if (empty($xgroups)) {
         //Log::debug("mw::_getToolAccess($tool,$login) WARNING: user not in any groups");
     }
     // Check if the user is in any groups for this app
     $ingroup = false;
     $groups = array();
     $indevgroup = false;
     if ($xgroups) {
         foreach ($xgroups as $xgroup) {
             $groups[] = $xgroup->cn;
         }
         if ($toolgroups) {
             foreach ($toolgroups as $toolgroup) {
                 if (in_array($toolgroup->cn, $groups)) {
                     $ingroup = true;
                     if ($toolgroup->role == 1) {
                         $indevgroup = true;
                     }
                 }
             }
         }
     }
     $admin = false;
     $ctconfig = Component::params('com_tools');
     if ($ctconfig->get('admingroup') != '' && in_array($ctconfig->get('admingroup'), $groups)) {
         $admin = true;
     }
     $exportAllowed = $this->_getToolExportControl($tv->exportControl);
     $tisPublished = $tv->state == 1;
     $tisDev = $tv->state == 3;
     $tisGroupControlled = $tv->toolaccess == '@GROUP';
     if ($tisDev) {
         if ($indevgroup) {
             //Log::debug("mw::_getToolAccess($tool,$login): DEV TOOL ACCESS GRANTED (USER IN DEVELOPMENT GROUP)");
             return true;
         } else {
             if ($admin) {
                 //Log::debug("mw::_getToolAccess($tool,$login): DEV TOOL ACCESS GRANTED (USER IN ADMIN GROUP)");
                 return true;
             } else {
                 Log::debug("mw::_getToolAccess({$tool},{$login}): DEV TOOL ACCESS DENIED (USER NOT IN DEVELOPMENT OR ADMIN GROUPS)");
                 $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_DEV_GROUP'));
                 return false;
             }
         }
     } else {
         if ($tisPublished) {
             if ($tisGroupControlled) {
                 if ($ingroup) {
                     //Log::debug("mw::_getToolAccess($tool,$login): PUBLISHED TOOL ACCESS GRANTED (USER IN ACCESS GROUP)");
                     return true;
                 } else {
                     if ($admin) {
                         //Log::debug("mw::_getToolAccess($tool,$login): PUBLISHED TOOL ACCESS GRANTED (USER IN ADMIN GROUP)");
                         return true;
                     } else {
                         Log::debug("mw::_getToolAccess({$tool},{$login}): PUBLISHED TOOL ACCESS DENIED (USER NOT IN ACCESS OR ADMIN GROUPS)");
                         $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_ACCESS_GROUP'));
                         return false;
                     }
                 }
             } else {
                 if (!$exportAllowed) {
                     Log::debug("mw::_getToolAccess({$tool},{$login}): PUBLISHED TOOL ACCESS DENIED (EXPORT DENIED)");
                     return false;
                 } else {
                     if ($admin) {
                         //Log::debug("mw::_getToolAccess($tool,$login): PUBLISHED TOOL ACCESS GRANTED (USER IN ADMIN GROUP)");
                         return true;
                     } else {
                         if ($indevgroup) {
                             //Log::debug("mw::_getToolAccess($tool,$login): PUBLISHED TOOL ACCESS GRANTED (USER IN DEVELOPMENT GROUP)");
                             return true;
                         } else {
                             //Log::debug("mw::_getToolAccess($tool,$login): PUBLISHED TOOL ACCESS GRANTED");
                             return true;
                         }
                     }
                 }
             }
         } else {
             Log::debug("mw::_getToolAccess({$tool},{$login}): UNPUBLISHED TOOL ACCESS DENIED (TOOL NOT PUBLISHED)");
             $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_VERSION_UNPUBLISHED'));
             return false;
         }
     }
     return false;
 }
Example #11
0
    $text = $this->suspended ? Lang::txt('COM_PROJECTS_SUSPENDED') : Lang::txt('COM_PROJECTS_INACTIVE');
    $status = '<span class="inactive">' . $text . '</span> ';
    if ($this->suspended) {
        $status .= $this->suspended == 1 ? ' (' . Lang::txt('COM_PROJECTS_BY_ADMIN') . ')' : ' (' . Lang::txt('COM_PROJECTS_BY_PROJECT_MANAGER') . ')';
    }
} elseif ($this->model->isPending()) {
    $status = '<span class="inactive">' . Lang::txt('COM_PROJECTS_PENDING_APPROVAL') . '</span> ';
}
$sysgroup = $this->config->get('group_prefix', 'pr-') . $this->model->get('alias');
$quota = $this->params->get('quota');
$quota = $quota ? $quota : \Components\Projects\Helpers\Html::convertSize(floatval($this->config->get('defaultQuota', '1')), 'GB', 'b');
$pubQuota = $this->params->get('pubQuota');
$pubQuota = $pubQuota ? $pubQuota : \Components\Projects\Helpers\Html::convertSize(floatval($this->config->get('pubQuota', '1')), 'GB', 'b');
$this->css();
// Get groups project owner belongs to
$groups = \Hubzero\User\Helper::getGroups($this->model->get('owned_by_user'), 'members', 1);
if ($this->model->groupOwner()) {
    $groups[] = $this->model->groupOwner();
}
?>
<script type="text/javascript">
function submitbutton(pressbutton)
{
	var form = document.adminForm;
	if (pressbutton == 'cancel') {
		submitform( pressbutton );
		return;
	}

	if (pressbutton == 'delete') {
		form.admin_action.value = 'delete';
Example #12
0
    /**
     * Recursive method to iterate over the condition tree and generate the query
     *
     * @param   mixed $condition Accepts either a JSON string or object
     * @return  string
     */
    public function getQuery($condition)
    {
        if (is_string($condition)) {
            $condition = json_decode($condition);
        }
        $user = User::getRoot();
        $op = ' ' . strtoupper($condition->operator) . ' ';
        $having = '';
        $e = array();
        $tags = array();
        $nottags = array();
        for ($i = 0; $i < count($condition->expressions); $i++) {
            $expr = $condition->expressions[$i];
            if (strtolower($expr->fldval) == 'tag') {
                $tags[] = $expr->val;
                if ($expr->opval == '!=') {
                    $nottags[] = $expr->val;
                }
            }
            /*if (strtolower($expr->fldval) == 'status' && $expr->val == '-1')
            			{
            				$condition->expressions[$i]->val = '0';
            
            				$exp = new stdClass;
            				$exp->fldval = 'open';
            				$exp->opval  = '=';
            				$exp->opdisp = 'is';
            				$exp->val    = '0';
            				array_push($condition->expressions, $exp);
            			}*/
        }
        for ($i = 0; $i < count($condition->expressions); $i++) {
            $uid = 'username';
            if (strtolower($expr->fldval) == 'owner') {
                $uid = 'id';
            }
            $expr = $condition->expressions[$i];
            switch ($expr->opval) {
                case 'lt':
                    $expr->opval = '<';
                    break;
                case 'lt=':
                    $expr->opval = '<=';
                    break;
                case 'gt':
                    $expr->opval = '>';
                    break;
                case 'gt=':
                    $expr->opval = '>=';
                    break;
                default:
                    break;
            }
            if ($expr->val == 'trivial') {
                $expr->val = 'minor';
            }
            //$prfx = (strtolower($expr->fldval) == 'tag') ? 't' : 'f';
            $prfx = 'f';
            if (strtolower($expr->fldval) == 'tag') {
                continue;
                $prfx = 't';
                if (count($tags) > 1 && strtoupper($condition->operator) == 'AND') {
                    // Skip adding multiple tags for AND conditions
                    // We need to do an IN () later
                    continue;
                }
            }
            if (strtoupper($expr->val) == 'NULL' || strtoupper($expr->val) == 'NULL') {
                $expr->opval = $expr->opval == '=' ? 'IS $1' : 'IS NOT $1';
            } else {
                if ($expr->val == '*') {
                    $expr->opval = 'IN ($1)';
                    if ($expr->fldval == 'group') {
                        $xgroups = \Hubzero\User\Helper::getGroups($user->get('id'), 'members');
                        $expr->val = '';
                        if ($xgroups) {
                            $g = array();
                            foreach ($xgroups as $xgroup) {
                                $g[] = $xgroup->cn;
                            }
                            $expr->val = "'" . implode("','", $g) . "'";
                        } else {
                            continue;
                        }
                    }
                }
            }
            if (strstr($expr->opval, '$1')) {
                if (strtolower($expr->fldval) == 'tag') {
                    //$e[] = '(' . $prfx . '.' . $this->_db->quoteName($expr->fldval) . ' ' . str_replace('$1', $expr->val, $expr->opval) . ' OR ' . $prfx . '.' . $this->_db->quoteName('raw_' . $expr->fldval) . ' ' . str_replace('$1', $expr->val, $expr->opval) . ')';
                } else {
                    $e[] = $prfx . '.' . $this->_db->quoteName($expr->fldval) . ' ' . str_replace('$1', $expr->val, $expr->opval);
                }
            } else {
                $uid = 'username';
                if (strtolower($expr->fldval) == 'owner') {
                    $uid = 'id';
                }
                if ($expr->val == '$me') {
                    $expr->val = $user->get($uid);
                } else {
                    if (strtolower($expr->fldval) == 'owner') {
                        $vuser = User::getInstance($expr->val);
                        if ($vuser) {
                            $expr->val = $vuser->get('id');
                        }
                    }
                }
                if (strtolower($expr->fldval) == 'status' && $expr->val == '-1') {
                    $condition->expressions[$i]->val = '0';
                    $e[] = '(' . $prfx . '.' . $this->_db->quoteName($expr->fldval) . ' ' . $expr->opval . ' ' . $this->_db->quote($expr->val) . ' AND ' . $prfx . '.' . $this->_db->quoteName('open') . ' = ' . $this->_db->quote('0') . ')';
                } else {
                    $e[] = $prfx . '.' . $this->_db->quoteName($expr->fldval) . ' ' . $expr->opval . ' ' . $this->_db->quote($expr->val);
                }
            }
        }
        if (count($tags) > 0) {
            if (implode("','", $tags) == implode("','", $nottags)) {
                $e[] = 'f.' . $this->_db->quoteName('id') . ' NOT IN (
							SELECT st.' . $this->_db->quoteName('objectid') . ' FROM #__tags_object AS st
							LEFT JOIN #__tags AS t ON st.' . $this->_db->quoteName('tagid') . '=t.' . $this->_db->quoteName('id') . '
							WHERE st.' . $this->_db->quoteName('tbl') . '=\'support\'
							AND (t.' . $this->_db->quoteName('tag') . str_replace('$1', "'" . implode("','", $tags) . "'", 'IN ($1)') . ' OR t.' . $this->_db->quoteName('raw_tag') . ' ' . str_replace('$1', "'" . implode("','", $tags) . "'", 'IN ($1)') . '))';
                $having = " GROUP BY f.id ";
            } else {
                if (count($tags) && count($nottags)) {
                    $e[] = '(t.' . $this->_db->quoteName('tag') . ' ' . str_replace('$1', "'" . implode("','", $tags) . "'", 'IN ($1)') . ' OR t.' . $this->_db->quoteName('raw_tag') . ' ' . str_replace('$1', "'" . implode("','", $tags) . "'", 'IN ($1)') . ')';
                    $e[] = 'f.' . $this->_db->quoteName('id') . ' NOT IN (
							SELECT jto.' . $this->_db->quoteName('objectid') . ' FROM #__tags_object AS jto
							JOIN #__tags AS jt ON jto.' . $this->_db->quoteName('tagid') . '=jt.' . $this->_db->quoteName('id') . '
							WHERE jto.' . $this->_db->quoteName('tbl') . '=\'support\'
							AND (jt.' . $this->_db->quoteName('tag') . str_replace('$1', "'" . implode("','", $nottags) . "'", 'IN ($1)') . ' OR jt.' . $this->_db->quoteName('raw_tag') . ' ' . str_replace('$1', "'" . implode("','", $nottags) . "'", 'IN ($1)') . '))';
                    $having = " GROUP BY f.id ";
                } else {
                    $e[] = '(t.' . $this->_db->quoteName('tag') . ' ' . str_replace('$1', "'" . implode("','", $tags) . "'", 'IN ($1)') . ' OR t.' . $this->_db->quoteName('raw_tag') . ' ' . str_replace('$1', "'" . implode("','", $tags) . "'", 'IN ($1)') . ')';
                    $having = " GROUP BY f.id ";
                    if (strtoupper($condition->operator) == 'OR') {
                        $h = 1;
                    } else {
                        $h = count($tags) - count($nottags);
                        $having .= "HAVING uniques='" . $h . "'";
                    }
                }
            }
        }
        $n = array();
        $nlen = count($condition->nestedexpressions);
        for ($k = 0; $k < $nlen; $k++) {
            $nestexpr = $condition->nestedexpressions[$k];
            $result = $this->getQuery($nestexpr);
            $n[] = $result;
        }
        $q = array();
        if (count($e) > 0) {
            $q[] = implode($op, $e);
        }
        if (count($n) > 0) {
            $q[] = implode($op, $n);
        }
        return '(' . implode($op, $q) . ')' . $having;
    }
Example #13
0
 /**
  * Intro Page
  *
  * @return  void
  */
 public function displayTask()
 {
     // set the neeced layout
     $this->view->setLayout('display');
     // build the title
     $this->_buildTitle();
     // build pathway
     $this->_buildPathway();
     //vars
     $mytags = '';
     $this->view->mygroups = array('members' => null, 'invitees' => null, 'applicants' => null);
     $this->view->populargroups = array();
     $this->view->interestinggroups = array();
     //get the users profile
     $profile = \Hubzero\User\Profile::getInstance(User::get("id"));
     //if we have a users profile load their groups and groups matching their tags
     if (is_object($profile)) {
         //get users tags
         include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'tags.php';
         $mt = new \Components\Members\Models\Tags($profile->get("uidNumber"));
         $mytags = $mt->render('string');
         //get users groups
         $this->view->mygroups['members'] = \Hubzero\User\Helper::getGroups($profile->get("uidNumber"), 'members', 1);
         $this->view->mygroups['invitees'] = \Hubzero\User\Helper::getGroups($profile->get("uidNumber"), 'invitees', 1);
         $this->view->mygroups['applicants'] = \Hubzero\User\Helper::getGroups($profile->get("uidNumber"), 'applicants', 1);
         $this->view->mygroups = array_filter($this->view->mygroups);
         //get groups user may be interested in
         $this->view->interestinggroups = Group\Helper::getGroupsMatchingTagString($mytags, \Hubzero\User\Helper::getGroups($profile->get("uidNumber")));
     }
     //get the popular groups
     $this->view->populargroups = Group\Helper::getPopularGroups(3);
     //get featured groups
     $this->view->featuredgroups = Group\Helper::getFeaturedGroups($this->config->get('intro_featuredgroups_list', ''));
     //set some vars for view
     $this->view->config = $this->config;
     $this->view->title = $this->_title;
     // get view notifications
     $this->view->notifications = $this->getNotifications() ? $this->getNotifications() : array();
     //display view
     $this->view->display();
 }
Example #14
0
 /**
  * restrictAccess 
  * 
  * @access public
  * @return void
  */
 public function restrictAccess()
 {
     if (User::isGuest()) {
         $accessFilter = "(access_level:public)";
     } else {
         $user = User::get('id');
         $userFilter = 'OR (access_level:private AND owner_type:user AND owner:' . $user . ')';
         $accessFilter = "(access_level:public) OR (access_level:registered) " . $userFilter;
         $userGroups = \Hubzero\User\Helper::getGroups($user);
         if (!empty($userGroups)) {
             $groupFilter = 'OR (access_level:private AND owner_type:group AND (owner:';
             $i = 0;
             foreach ($userGroups as $group) {
                 $groupFilter .= $group->gidNumber;
                 if ($i >= count($userGroups) - 1) {
                     $groupFilter .= '))';
                 } else {
                     $groupFilter .= ' ';
                 }
                 $i++;
             }
             $accessFilter .= ' ' . $groupFilter;
         }
         $addon = Event::trigger('search.onAddPermissionSet');
         foreach ($addon as $add) {
             $accessFilter .= $add;
         }
     }
     $this->query->createFilterQuery('userPerms')->setQuery($accessFilter);
 }
Example #15
0
 /**
  * Authorize current user
  *
  * @param      mixed $idx Index value
  * @return     array
  */
 private function _authorize($reviewer = false)
 {
     $this->_authorized = true;
     // NOT logged in
     if (User::isGuest()) {
         // If the project is active and public
         if ($this->isPublic() && $this->isActive()) {
             // Allow public view access
             $this->params->set('access-view-project', true);
         }
         return;
     }
     // Check reviewer access?
     if ($reviewer) {
         // Get user groups
         if (!isset($this->_userGroups)) {
             $ugs = \Hubzero\User\Helper::getGroups(User::get('id'));
             $this->_userGroups = $this->getGroupProperty($ugs);
         }
         switch (strtolower($reviewer)) {
             case 'general':
             case 'admin':
             default:
                 $reviewer = 'admin';
                 $group = \Hubzero\User\Group::getInstance($this->config()->get('admingroup'));
                 break;
             case 'sensitive':
                 $group = \Hubzero\User\Group::getInstance($this->config()->get('sdata_group'));
                 break;
             case 'sponsored':
                 $group = \Hubzero\User\Group::getInstance($this->config()->get('ginfo_group'));
                 break;
             case 'reports':
                 $group = \Hubzero\User\Group::getInstance($this->config()->get('reportgroup'));
                 break;
         }
         $authorized = false;
         if ($this->_userGroups && count($this->_userGroups) > 0) {
             foreach ($this->_userGroups as $cn) {
                 if ($group && $cn == $group->get('cn')) {
                     $authorized = true;
                 }
             }
         }
         $this->params->set('access-reviewer-' . strtolower($reviewer) . '-project', $authorized);
         return;
     }
     // Allowed to create a project
     if (!$this->exists()) {
         $cg = $this->config()->get('creatorgroup');
         $cg = explode(',', $cg);
         $cg = array_map('trim', $cg);
         if (!empty($cg) && !empty($cg[0])) {
             foreach ($cg as $c) {
                 $group = \Hubzero\User\Group::getInstance($c);
                 if ($group) {
                     if ($group->is_member_of('members', User::get('id')) || $group->is_member_of('managers', User::get('id'))) {
                         $this->params->set('access-create-project', true);
                     }
                 }
             }
         } else {
             $this->params->set('access-create-project', true);
         }
     }
     // Is user project member?
     $member = $this->member();
     if (empty($member) || !$member->id) {
         if ($this->isPublic() && $this->isActive()) {
             // Allow public view access
             $this->params->set('access-view-project', true);
         }
     } else {
         $this->params->set('access-view-project', true);
         $this->params->set('access-member-project', true);
         // internal project view
         // Project roles
         switch ($member->role) {
             case 1:
                 // Manager
                 $this->params->set('access-manager-project', true);
                 // May edit project properties
                 $this->params->set('access-content-project', true);
                 // May add/edit/delete all content
                 // Owner (principal user/creator)
                 if ($this->owner('id') == $member->userid) {
                     $this->params->set('access-owner-project', true);
                 }
                 break;
             case 2:
             case 3:
             default:
                 // Collaborator/author
                 $this->params->set('access-content-project', true);
                 break;
             case 5:
                 // Read-only
                 $this->params->set('access-readonly-project', true);
                 break;
         }
     }
 }
Example #16
0
 /**
  * Build a query from filters
  *
  * @param      array   $filters Filters to build query from
  * @param      boolean $admin   Admin access?
  * @return     string SQL
  */
 public function buildQuery($filters, $admin)
 {
     $filter = " WHERE report!=''";
     switch ($filters['status']) {
         case 'open':
             $filter .= " AND open=1";
             break;
         case 'closed':
             $filter .= " AND open=0";
             break;
         case 'all':
             $filter .= "";
             break;
         case 'new':
             $filter .= " AND open=1 AND status=0 AND owner=0 AND (resolved IS NULL OR resolved='') AND ((SELECT COUNT(*) FROM #__support_comments AS k WHERE k.ticket=f.id) <= 0)";
             break;
         case 'waiting':
             $filter .= " AND open=1 AND status=2";
             break;
     }
     if (isset($filters['severity']) && $filters['severity'] != '') {
         $filter .= " AND severity=" . $this->_db->quote($filters['severity']);
     }
     if ($admin) {
         switch ($filters['type']) {
             case '3':
                 $filter .= " AND type=3";
                 break;
             case '2':
                 $filter .= "";
                 break;
             case '1':
                 $filter .= " AND type=1";
                 break;
             case '0':
             default:
                 $filter .= " AND type=0";
                 break;
         }
     } else {
         $filter .= " AND type=0";
     }
     if (isset($filters['category']) && $filters['category'] != '') {
         $filter .= " AND category=" . $this->_db->quote($filters['category']);
     }
     if (isset($filters['owner']) && $filters['owner'] != '') {
         $filter .= " AND ";
         if ($admin == false && (!isset($filters['owner']) || $filters['owner'] != '') && (!isset($filters['reportedby']) || $filters['reportedby'] != '')) {
             $filter .= "(";
         }
         if (isset($filters['reportedby']) && $filters['reportedby'] != '') {
             $filter .= "(";
         }
         if ($filters['owner'] == 'none') {
             $filter .= "owner=0";
         } else {
             $filter .= "owner=" . $this->_db->quote($filters['owner']);
         }
     }
     if (isset($filters['reportedby']) && $filters['reportedby'] != '') {
         if (isset($filters['owner']) && $filters['owner'] != '') {
             $filter .= " OR ";
         } else {
             $filter .= " AND ";
         }
         $filter .= "login="******")";
         }
     }
     if (isset($filters['opened']) && $filters['opened']) {
         if (is_array($filters['opened'])) {
             $filter .= " AND (f.created >= " . $this->_db->quote($filters['opened'][0]) . " AND f.created <= " . $this->_db->quote($filters['opened'][1]) . ")";
         } else {
             $filter .= " AND f.created >= " . $this->_db->quote($filters['opened']);
         }
     }
     if (isset($filters['closed']) && $filters['closed']) {
         if (is_array($filters['closed'])) {
             $filter .= " AND (f.closed >= " . $this->_db->quote($filters['closed'][0]) . " AND f.closed <= " . $this->_db->quote($filters['closed'][1]) . ")";
         } else {
             $filter .= " AND f.closed >= " . $this->_db->quote($filters['closed']);
         }
     }
     if (isset($filters['group']) && $filters['group'] != '') {
         $filter .= " AND `group`=" . $this->_db->quote($filters['group']);
     }
     if ($admin == false && (!isset($filters['owner']) || $filters['owner'] != '') && (!isset($filters['reportedby']) || $filters['reportedby'] != '')) {
         if (!User::isGuest()) {
             $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'members');
             $groups = '';
             if ($xgroups) {
                 $g = array();
                 foreach ($xgroups as $xgroup) {
                     $g[] = $this->_db->quote($xgroup->cn);
                 }
                 $groups = implode(",", $g);
             }
             $filter .= $groups ? " OR `group` IN ({$groups})" : "";
         }
     }
     if (isset($filters['search']) && $filters['search'] != '') {
         $from = "(\n\t\t\t\t\t\t(SELECT f.id, f.summary, f.report, f.category, f.status, f.severity, f.resolved, f.owner, f.created, f.closed, f.login, f.name, f.email, f.type, f.section, f.group, u.name AS owner_name, u.id AS owner_id\n\t\t\t\t\t\t\tFROM {$this->_tbl} AS f LEFT JOIN #__users AS u ON u.id=f.owner ";
         if (isset($filters['tag']) && $filters['tag'] != '') {
             $from .= ", #__tags_object AS st, #__tags as t ";
         }
         if (isset($filters['search']) && $filters['search'] != '') {
             $from .= "WHERE ";
             $from .= "(LOWER(f.summary) LIKE " . $this->_db->quote('%' . strtolower($filters['search']) . '%') . "\n\t\t\t\t\t\tOR LOWER(f.report) LIKE " . $this->_db->quote('%' . strtolower($filters['search']) . '%') . "\n\t\t\t\t\t\tOR LOWER(u.username) LIKE " . $this->_db->quote('%' . strtolower($filters['search']) . '%') . "\n\t\t\t\t\t\tOR LOWER(f.name) LIKE " . $this->_db->quote('%' . strtolower($filters['search']) . '%') . "\n\t\t\t\t\t\tOR LOWER(f.login) LIKE " . $this->_db->quote('%' . strtolower($filters['search']) . '%');
             if (is_numeric($filters['search'])) {
                 $from .= " OR ";
                 $from .= "id=" . intval($filters['search']);
             }
             $from .= ") ";
         }
         if (isset($filters['tag']) && $filters['tag'] != '') {
             if (!isset($filters['search']) || $filters['search'] == '') {
                 $from .= "WHERE ";
             } else {
                 $from .= " AND ";
             }
             $from .= "st.objectid=f.id AND st.tbl='support' AND st.tagid=t.id AND t.tag=" . $this->_db->quote($filters['tag']);
         }
         $from .= ") UNION (\n\t\t\t\tSELECT g.id, g.summary, g.report, g.category, g.status, g.severity, g.resolved, g.owner, g.created, g.closed, g.login, g.name, g.email, g.type, g.section, g.group, ug.name AS owner_name, ug.id AS owner_id\n\t\t\t\tFROM #__support_comments AS w, {$this->_tbl} AS g LEFT JOIN #__users AS ug ON ug.id=g.owner\n\t\t\t\tWHERE w.ticket=g.id";
         if (isset($filters['search']) && $filters['search'] != '') {
             $from .= " AND LOWER(w.comment) LIKE " . $this->_db->quote('%' . strtolower($filters['search']) . '%');
         }
         $from .= ")) AS h";
     } else {
         $from = "{$this->_tbl} AS f\n\t\t\t\t\tLEFT JOIN #__users AS u ON u.id=f.owner";
         if (isset($filters['tag']) && $filters['tag'] != '') {
             $from .= ", #__tags_object AS st, #__tags as t";
         }
         if (isset($filters['tag']) && $filters['tag'] != '') {
             $filter .= " AND st.objectid=f.id AND st.tbl='support' AND st.tagid=t.id AND t.tag=" . $this->_db->quote($filters['tag']);
         }
     }
     $query = $from . " " . $filter;
     return $query;
 }
Example #17
0
 /**
  * Method is called after user data is deleted from the database
  *
  * @param   array    $user     holds the user data
  * @param   boolean  $success  true if user was succesfully stored in the database
  * @param   string   $msg      message
  * @return  boolean  True on success
  */
 public function onAfterDeleteUser($user, $succes, $msg)
 {
     $xprofile = \Hubzero\User\Profile::getInstance($user['id']);
     // remove user from groups
     \Hubzero\User\Helper::removeUserFromGroups($user['id']);
     if (is_object($xprofile)) {
         $xprofile->delete();
     }
     \Hubzero\Auth\Link::delete_by_user_id($user['id']);
     // Check if quota exists for the user
     require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'users_quotas.php';
     $quota = new \Components\Members\Tables\UsersQuotas($this->database);
     $quota->load(array('user_id' => $user['id']));
     if ($quota->id) {
         $quota->delete();
     }
     return true;
 }
Example #18
0
<h3 class="section-header">
	<?php 
echo Lang::txt('PLG_RESOURCES_SUPPORTINGDOCS');
?>
</h3>

<div id="supportingdocs" class="supportingdocs">
	<?php 
if ($children) {
    ?>
		<ul>
			<?php 
    $linkAction = 0;
    $base = $this->model->params->get('uploadpath');
    $i = 0;
    $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'all');
    $usersgroups = array();
    if (!empty($xgroups)) {
        foreach ($xgroups as $group) {
            if ($group->regconfirmed) {
                $usersgroups[] = $group->cn;
            }
        }
    }
    $allowedgroups = $this->model->resource->getGroups();
    foreach ($children as $child) {
        if ($child->access == 0 || $child->access == 1 && !User::isGuest() || $child->access == 3 && in_array($this->model->resource->group_owner, $usersgroups)) {
            $i++;
            $ftype = Filesystem::extension($child->path);
            if (substr($child->path, 0, 4) == 'http') {
                $ftype = 'html';
Example #19
0
 /**
  * Get groups
  *
  * @param   string  $role
  * @return  array
  */
 public function groups($role = 'all')
 {
     //return $this->manyToMany('Hubzero\User\Extended\Group', 'id', 'uidNumber');
     static $groups;
     if (!isset($groups)) {
         $groups = array('applicants' => array(), 'invitees' => array(), 'members' => array(), 'managers' => array(), 'all' => array());
         $all = Helper::getGroups($this->get('id'), 'all', 1);
         if ($all) {
             $groups['all'] = $all;
             foreach ($groups['all'] as $item) {
                 if ($item->registered) {
                     if (!$item->regconfirmed) {
                         $groups['applicants'][] = $item;
                     } else {
                         if ($item->manager) {
                             $groups['managers'][] = $item;
                         } else {
                             $groups['members'][] = $item;
                         }
                     }
                 } else {
                     $groups['invitees'][] = $item;
                 }
             }
         }
     }
     if ($role) {
         return isset($groups[$role]) ? $groups[$role] : array();
     }
     return $groups;
 }
Example #20
0
 /**
  * Authorization checks
  *
  * @param      string $assetType Asset type
  * @param      string $assetId   Asset id to check against
  * @return     void
  */
 protected function _authorize($assetType = 'component', $assetId = null)
 {
     $this->config->set('access-view-' . $assetType, true);
     if (User::get('guest')) {
         return;
     }
     // if no admin group is defined, allow superadmin to act as admin
     // otherwise superadmins can only act if they are also a member of the component admin group
     if ($admingroup = trim($this->config->get('admingroup', ''))) {
         // Check if they're a member of admin group
         $ugs = \Hubzero\User\Helper::getGroups(User::get('id'));
         if ($ugs && count($ugs) > 0) {
             $admingroup = strtolower($admingroup);
             foreach ($ugs as $ug) {
                 if (strtolower($ug->cn) == $admingroup) {
                     $this->config->set('access-manage-' . $assetType, true);
                     $this->config->set('access-admin-' . $assetType, true);
                     $this->config->set('access-create-' . $assetType, true);
                     $this->config->set('access-delete-' . $assetType, true);
                     $this->config->set('access-edit-' . $assetType, true);
                 }
             }
         }
     } else {
         $asset = $this->_option;
         if ($assetId) {
             $asset .= $assetType != 'component' ? '.' . $assetType : '';
             $asset .= $assetId ? '.' . $assetId : '';
         }
         $at = '';
         if ($assetType != 'component') {
             $at .= '.' . $assetType;
         }
         // Admin
         $this->config->set('access-admin-' . $assetType, User::authorise('core.admin', $asset));
         $this->config->set('access-manage-' . $assetType, User::authorise('core.manage', $asset));
         // Permissions
         $this->config->set('access-create-' . $assetType, User::authorise('core.create' . $at, $asset));
         $this->config->set('access-delete-' . $assetType, User::authorise('core.delete' . $at, $asset));
         $this->config->set('access-edit-' . $assetType, User::authorise('core.edit' . $at, $asset));
         $this->config->set('access-edit-state-' . $assetType, User::authorise('core.edit.state' . $at, $asset));
         $this->config->set('access-edit-own-' . $assetType, User::authorise('core.edit.own' . $at, $asset));
     }
 }
Example #21
0
 /**
  * Check authorization
  *
  * @return bool
  **/
 private function authorize()
 {
     static $authorized = null;
     if (!isset($authorized)) {
         $config = Component::params('com_time');
         $accessgroup = $config->get('accessgroup', 'time');
         $authorized = false;
         // Check if they're a member of admin group
         $ugs = \Hubzero\User\Helper::getGroups(User::get('id'));
         if ($ugs && count($ugs) > 0) {
             foreach ($ugs as $ug) {
                 if ($ug->cn == $accessgroup) {
                     $authorized = true;
                 }
             }
         }
     }
     return $authorized;
 }
Example #22
0
 /**
  * Authorize current user
  *
  * @param      mixed $idx Index value
  * @return     array
  */
 private function _authorize()
 {
     // NOT logged in
     if (User::isGuest()) {
         // If the resource is published and public
         if ($this->isPublished() && $this->get('master_access') == 0) {
             // Allow view access
             $this->params->set('access-view-publication', true);
             if ($this->get('master_access') == 0) {
                 $this->params->set('access-view-all-publication', true);
             }
         }
         $this->_authorized = true;
         return;
     }
     // Check if they're a site admin (from Joomla)
     $this->params->set('access-admin-publication', User::authorise('core.admin', null));
     $this->params->set('access-manage-publication', User::authorise('core.manage', null));
     if ($this->params->get('access-admin-publication') || $this->params->get('access-manage-publication')) {
         $this->params->set('access-view-publication', true);
         $this->params->set('access-view-all-publication', true);
         $this->params->set('access-create-publication', true);
         $this->params->set('access-delete-publication', true);
         $this->params->set('access-edit-publication', true);
         $this->params->set('access-edit-state-publication', true);
         // May curate
         $this->params->set('access-curator-publication', true);
     }
     // Get user groups
     $ugs = \Hubzero\User\Helper::getGroups(User::get('id'));
     $usersgroups = $this->getGroupProperty($ugs);
     // If they're not an admin
     if (!$this->params->get('access-admin-publication') && !$this->params->get('access-manage-publication')) {
         // If logged in and resource is published and public or registered
         if ($this->isPublished() && $this->get('master_access') <= 1) {
             // Allow view access
             $this->params->set('access-view-publication', true);
             $this->params->set('access-view-all-publication', true);
         }
         // Allowed groups (private access)
         if ($this->get('master_access') >= 2) {
             $groups = $this->getAccessGroups();
             if (array_intersect($usersgroups, $groups) > 1) {
                 $this->params->set('access-view-publication', true);
                 $this->params->set('access-view-all-publication', true);
             }
         }
     }
     // Project owners
     if ($this->owner()) {
         $this->params->set('access-owner-publication', true);
         $this->params->set('access-manage-publication', true);
         $this->params->set('access-view-publication', true);
         $this->params->set('access-view-all-publication', true);
         $this->params->set('access-create-publication', true);
         $this->params->set('access-delete-publication', true);
         $this->params->set('access-edit-publication', true);
         $this->params->set('access-edit-state-publication', true);
     }
     // Curator
     if ($this->get('curator') && User::get('id') == $this->get('curator')) {
         $this->params->set('access-curator-publication', true);
         $this->params->set('access-curator-assigned-publication', true);
     }
     // Curator from groups
     $curatorGroups = $this->curatorGroups();
     if (!empty($curatorGroups)) {
         if (array_intersect($usersgroups, $curatorGroups) > 1) {
             $this->params->set('access-curator-publication', true);
         }
     }
     // Curators have full view access and approval controls
     if ($this->params->get('access-curator-publication')) {
         $this->params->set('access-view-publication', true);
         $this->params->set('access-view-all-publication', true);
         $this->params->set('access-edit-state-publication', true);
         $this->params->set('access-manage-publication', true);
     }
     $this->_authorized = true;
 }
Example #23
0
 /**
  * Build panel content
  *
  * @return  string  HTML
  */
 public function buildContent($pub = NULL, $viewname = 'edit')
 {
     $name = $viewname == 'freeze' || $viewname == 'curator' ? 'freeze' : 'draft';
     // Get selector styles
     \Hubzero\Document\Assets::addPluginStylesheet('projects', 'team', 'selector');
     // Output HTML
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => $name, 'layout' => 'authors'));
     // Get authors
     if (!isset($pub->_authors)) {
         $pAuthors = new \Components\Publications\Tables\Author($this->_parent->_db);
         $pub->_authors = $pAuthors->getAuthors($pub->version_id);
         $pub->_submitter = $pAuthors->getSubmitter($pub->version_id, $pub->created_by);
     }
     // Get creator groups
     $view->groups = \Hubzero\User\Helper::getGroups($pub->_project->get('owned_by_user'), 'members', 1);
     $view->pub = $pub;
     $view->manifest = $this->_manifest;
     $view->step = $this->_blockId;
     // Get team members
     $objO = new \Components\Projects\Tables\Owner($this->_parent->_db);
     $view->teamids = $objO->getIds($pub->_project->get('id'), 'all', 0, 0);
     if ($this->getError()) {
         $view->setError($this->getError());
     }
     return $view->loadTemplate();
 }
Example #24
0
 /**
  * Retrieve records for items tagged with specific tags
  *
  * @param      array   $tags       Tags to match records against
  * @param      mixed   $limit      SQL record limit
  * @param      integer $limitstart SQL record limit start
  * @param      string  $sort       The field to sort records by
  * @param      mixed   $areas      An array or string of areas that should retrieve records
  * @return     mixed Returns integer when counting records, array when retrieving records
  */
 public function onTagView($tags, $limit = 0, $limitstart = 0, $sort = '', $areas = null)
 {
     $response = array('name' => $this->_name, 'title' => Lang::txt('PLG_TAGS_RESOURCES'), 'total' => 0, 'results' => null, 'sql' => '', 'children' => array());
     $database = App::get('db');
     $rt = new \Components\Resources\Tables\Type($database);
     foreach ($rt->getMajorTypes() as $category) {
         $response['children'][$category->alias] = array('name' => $category->alias, 'title' => $category->type, 'total' => 0, 'results' => null, 'sql' => '', 'id' => $category->id);
     }
     if (empty($tags)) {
         return $response;
     }
     $ids = array();
     foreach ($tags as $tag) {
         $ids[] = $tag->get('id');
     }
     // Instantiate some needed objects
     $rr = new \Components\Resources\Tables\Resource($database);
     // Build query
     $filters = array();
     $filters['tags'] = $ids;
     $filters['now'] = Date::toSql();
     $filters['sortby'] = $sort ? $sort : 'ranking';
     $filters['authorized'] = false;
     $filters['usergroups'] = \Hubzero\User\Helper::getGroups(User::get('id'), 'all');
     $filters['select'] = 'count';
     foreach ($response['children'] as $k => $t) {
         $filters['type'] = $t['id'];
         // Execute a count query for each area/category
         $database->setQuery($this->_buildPluginQuery($filters));
         $response['children'][$k]['total'] = $database->loadResult();
         $response['total'] += $response['children'][$k]['total'];
     }
     if ($areas && ($areas == $response['name'] || isset($response['children'][$areas]))) {
         // Push some CSS and JS to the tmeplate that may be needed
         \Hubzero\Document\Assets::addComponentStylesheet('com_resources');
         $filters['select'] = 'records';
         $filters['limit'] = $limit;
         $filters['limitstart'] = $limitstart;
         $filters['sortby'] = $sort ? $sort : 'date';
         // Check the area of return. If we are returning results for a specific area/category
         // we'll need to modify the query a bit
         if (isset($response['children'][$areas])) {
             $filters['type'] = $response['children'][$areas]['id'];
             $database->setQuery($this->_buildPluginQuery($filters));
             $response['children'][$areas]['results'] = $database->loadObjectList();
         } else {
             unset($filters['type']);
             $database->setQuery($this->_buildPluginQuery($filters));
             $response['results'] = $database->loadObjectList();
         }
     } else {
         $filters['select'] = 'records';
         $filters['limit'] = 'all';
         $filters['limitstart'] = $limitstart;
         $filters['sortby'] = $sort ? $sort : 'date';
         // Check the area of return. If we are returning results for a specific area/category
         // we'll need to modify the query a bit
         if (isset($response['children'][$areas])) {
             $filters['type'] = $response['children'][$areas]['id'];
             $response['children'][$key]['sql'] = $this->_buildPluginQuery($filters);
         } else {
             unset($filters['type']);
             $response['sql'] = $this->_buildPluginQuery($filters);
         }
     }
     return $response;
 }
Example #25
0
defined('_HZEXEC_') or die;
$no_html = Request::getInt('no_html', 0);
$user_messaging = $this->config->get('user_messaging', 0);
$prefix = $this->profile->get("name") . "'s";
$edit = false;
$password = false;
$messaging = false;
$tab = $this->active;
$tab_name = 'Dashboard';
//are we allowed to messagin user
switch ($user_messaging) {
    case 0:
        $mssaging = false;
        break;
    case 1:
        $common = \Hubzero\User\Helper::getCommonGroups(User::get('id'), $this->profile->get('id'));
        if (count($common) > 0) {
            $messaging = true;
        }
        break;
    case 2:
        $messaging = true;
        break;
}
//if user is this member turn on editing and password change, turn off messaging
if ($this->profile->get('id') == User::get("id")) {
    if ($this->active == "profile") {
        $edit = true;
        $password = true;
    }
    $messaging = false;
Example #26
0
 /**
  * Get the groups for a user
  *
  * @param   string  $role  The group set to return. Returns all groups if not set
  * @return  array   Array of groups
  */
 public function getGroups($role = 'all')
 {
     static $groups;
     if (!isset($groups)) {
         $groups = array('applicants' => array(), 'invitees' => array(), 'members' => array(), 'managers' => array(), 'all' => array());
         $groups['all'] = Helper::getGroups($this->get('uidNumber'), 'all', 1);
         if ($groups['all']) {
             foreach ($groups['all'] as $item) {
                 if ($item->registered) {
                     if (!$item->regconfirmed) {
                         $groups['applicants'][] = $item;
                     } else {
                         if ($item->manager) {
                             $groups['managers'][] = $item;
                         } else {
                             $groups['members'][] = $item;
                         }
                     }
                 } else {
                     $groups['invitees'][] = $item;
                 }
             }
         }
     }
     if ($role) {
         return isset($groups[$role]) ? $groups[$role] : false;
     }
     return $groups;
 }
Example #27
0
 /**
  * Send a message to one or more users
  *
  * @param      string  $type        Message type (maps to #__xmessage_component table)
  * @param      string  $subject     Message subject
  * @param      string  $message     Message to send
  * @param      array   $from        Message 'from' data (e.g., name, address)
  * @param      array   $to          List of user IDs
  * @param      string  $component   Component name
  * @param      integer $element     ID of object that needs an action item
  * @param      string  $description Action item description
  * @param      integer $group_id    Parameter description (if any) ...
  * @return     mixed   True if no errors else error message
  */
 public function onSendMessage($type, $subject, $message, $from = array(), $to = array(), $component = '', $element = null, $description = '', $group_id = 0, $bypassGroupsCheck = false)
 {
     // Do we have a message?
     if (!$message) {
         return false;
     }
     $database = App::get('db');
     // Create the message object
     $xmessage = Hubzero\Message\Message::blank();
     if ($type == 'member_message') {
         $time_limit = intval($this->params->get('time_limit', 30));
         $daily_limit = intval($this->params->get('daily_limit', 100));
         // First, let's see if they've surpassed their daily limit for sending messages
         $filters = array('created_by' => User::get('id'), 'daily_limit' => $daily_limit);
         $number_sent = $xmessage->getSentMessagesCount($filters);
         if ($number_sent >= $daily_limit) {
             return false;
         }
         // Next, we see if they've passed the time limit for sending consecutive messages
         $filters['limit'] = 1;
         $filters['start'] = 0;
         $sent = $xmessage->getSentMessages($filters);
         if ($sent->count() > 0) {
             $last_sent = $sent->first();
             $last_time = 0;
             if ($last_sent->created) {
                 $last_time = Date::of($last_sent->created)->toUnix();
             }
             $time_difference = Date::toUnix() + $time_limit - $last_time;
             if ($time_difference < $time_limit) {
                 return false;
             }
         }
     }
     // Store the message in the database
     $xmessage->set('message', is_array($message) && isset($message['plaintext']) ? $message['plaintext'] : $message);
     // Do we have a subject line? If not, create it from the message
     if (!$subject && $xmessage->get('message')) {
         $subject = substr($xmessage->get('message'), 0, 70);
         if (strlen($subject) >= 70) {
             $subject .= '...';
         }
     }
     $xmessage->set('subject', $subject);
     $xmessage->set('created', Date::toSql());
     $xmessage->set('created_by', User::get('id'));
     $xmessage->set('component', $component);
     $xmessage->set('type', $type);
     $xmessage->set('group_id', $group_id);
     if (!$xmessage->save()) {
         return $xmessage->getError();
     }
     if (is_array($message)) {
         $xmessage->set('message', $message);
     }
     // Do we have any recipients?
     if (count($to) > 0) {
         $mconfig = Component::params('com_members');
         // Get all the sender's groups
         if ($mconfig->get('user_messaging', 1) == 1 && !$bypassGroupsCheck) {
             $xgroups = User::groups('all');
             $usersgroups = array();
             if (!empty($xgroups)) {
                 foreach ($xgroups as $group) {
                     if ($group->regconfirmed) {
                         $usersgroups[] = $group->cn;
                     }
                 }
             }
         }
         // Loop through each recipient
         foreach ($to as $uid) {
             // Create a recipient object that ties a user to a message
             $recipient = Hubzero\Message\Recipient::blank();
             $recipient->set('uid', $uid);
             $recipient->set('mid', $xmessage->get('id'));
             $recipient->set('created', Date::toSql());
             $recipient->set('expires', Date::of(time() + 168 * 24 * 60 * 60)->toSql());
             $recipient->set('actionid', 0);
             //(is_object($action)) ? $action->id : 0; [zooley] Phasing out action items
             // Get the user's methods for being notified
             $notify = Hubzero\Message\Notify::blank();
             $methods = $notify->getRecords($uid, $type);
             $user = User::getInstance($uid);
             if (!is_object($user) || !$user->get('username')) {
                 continue;
             }
             if ($mconfig->get('user_messaging', 1) == 1 && ($type == 'member_message' || $type == 'group_message')) {
                 $pgroups = \Hubzero\User\Helper::getGroups($user->get('id'), 'all', 1);
                 $profilesgroups = array();
                 if (!empty($pgroups)) {
                     foreach ($pgroups as $group) {
                         if ($group->regconfirmed) {
                             $profilesgroups[] = $group->cn;
                         }
                     }
                 }
                 // Find the common groups
                 if (!$bypassGroupsCheck) {
                     $common = array_intersect($usersgroups, $profilesgroups);
                     if (count($common) <= 0) {
                         continue;
                     }
                 }
             }
             // Do we have any methods?
             if ($methods->count()) {
                 // Loop through each method
                 foreach ($methods as $method) {
                     $action = strtolower($method->method);
                     if ($action == 'internal') {
                         if (!$recipient->save()) {
                             $this->setError($recipient->getError());
                         }
                     } else {
                         if (!Event::trigger('onMessage', array($from, $xmessage, $user, $action))) {
                             $this->setError(Lang::txt('PLG_XMESSAGE_HANDLER_ERROR_UNABLE_TO_MESSAGE', $uid, $action));
                         }
                     }
                 }
             } else {
                 // First check if they have ANY methods saved (meaning they've changed their default settings)
                 // If They do have some methods, then they simply turned off everything for this $type
                 $methods = $notify->getRecords($uid);
                 if (!$methods || $methods->count() <= 0) {
                     // Load the default method
                     $p = Plugin::byType('members', 'messages');
                     $pp = new \Hubzero\Config\Registry(is_object($p) ? $p->params : '');
                     $d = $pp->get('default_method', 'email');
                     if (!$recipient->save()) {
                         $this->setError($recipient->getError());
                     }
                     // Use the Default in the case the user has no methods
                     if (!Event::trigger('onMessage', array($from, $xmessage, $user, $d))) {
                         $this->setError(Lang::txt('PLG_XMESSAGE_HANDLER_ERROR_UNABLE_TO_MESSAGE', $uid, $d));
                     }
                 }
             }
         }
     }
     return true;
 }
Example #28
0
 /**
  * Authorize current user
  *
  * @param      mixed $idx Index value
  * @return     array
  */
 private function _authorize()
 {
     // NOT logged in
     if (User::isGuest()) {
         // If the resource is published and public
         if ($this->published() && ($this->resource->access == 0 || $this->resource->access == 3)) {
             // Allow view access
             $this->params->set('access-view-resource', true);
             if ($this->resource->access == 0) {
                 $this->params->set('access-view-all-resource', true);
             }
         }
         $this->_authorized = true;
         return;
     }
     if ($this->isTool()) {
         $tconfig = Component::params('com_tools');
         if ($admingroup = trim($tconfig->get('admingroup', ''))) {
             // Check if they're a member of admin group
             $ugs = \Hubzero\User\Helper::getGroups(User::get('id'));
             if ($ugs && count($ugs) > 0) {
                 $admingroup = strtolower($admingroup);
                 foreach ($ugs as $ug) {
                     if (strtolower($ug->cn) == $admingroup) {
                         $this->params->set('access-view-resource', true);
                         $this->params->set('access-view-all-resource', true);
                         $this->params->set('access-admin-resource', true);
                         $this->params->set('access-manage-resource', true);
                         $this->params->set('access-create-resource', true);
                         $this->params->set('access-delete-resource', true);
                         $this->params->set('access-edit-resource', true);
                         $this->params->set('access-edit-state-resource', true);
                         $this->params->set('access-edit-own-resource', true);
                         break;
                     }
                 }
             }
         }
         if (!$this->params->get('access-admin-resource') && !$this->params->get('access-manage-resource')) {
             // If logged in and resource is published and public or registered
             if ($this->published() && ($this->resource->access == 0 || $this->resource->access == 1)) {
                 // Allow view access
                 $this->params->set('access-view-resource', true);
                 $this->params->set('access-view-all-resource', true);
             }
             if ($this->resource->group_owner) {
                 // For protected resources, make sure users can see abstract
                 if ($this->resource->access < 3) {
                     $this->params->set('access-view-resource', true);
                     $this->params->set('access-view-all-resource', true);
                 } else {
                     if ($this->resource->access == 3) {
                         $this->params->set('access-view-resource', true);
                     }
                 }
                 // Get the groups the user has access to
                 $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'all');
                 $usersgroups = array();
                 if (!empty($xgroups)) {
                     foreach ($xgroups as $group) {
                         if ($group->regconfirmed) {
                             $usersgroups[] = $group->cn;
                         }
                     }
                 }
                 // Get the groups that can access this resource
                 $allowedgroups = $this->resource->getGroups();
                 // Find what groups the user has in common with the resource, if any
                 $common = array_intersect($usersgroups, $allowedgroups);
                 // Check if the user is apart of the group that owns the resource
                 // or if they have any groups in common
                 if (in_array($this->resource->group_owner, $usersgroups) || count($common) > 0) {
                     $this->params->set('access-view-resource', true);
                     $this->params->set('access-view-all-resource', true);
                 }
             }
             $obj = new \Components\Tools\Tables\Tool($this->_db);
             $obj->loadFromName($this->resource->alias);
             // check if user in tool dev team
             if ($developers = $obj->getToolDevelopers($obj->id)) {
                 foreach ($developers as $dv) {
                     if ($dv->uidNumber == User::get('id')) {
                         $this->params->set('access-create-resource', true);
                         $this->params->set('access-delete-resource', true);
                         $this->params->set('access-edit-resource', true);
                         $this->params->set('access-edit-state-resource', true);
                         $this->params->set('access-edit-own-resource', true);
                     }
                 }
             }
         }
         $this->_authorized = true;
         return;
     } else {
         // Check if they're a site admin (from Joomla)
         $this->params->set('access-admin-resource', User::authorise('core.admin', null));
         $this->params->set('access-manage-resource', User::authorise('core.manage', null));
         if ($this->params->get('access-admin-resource') || $this->params->get('access-manage-resource')) {
             $this->params->set('access-view-resource', true);
             $this->params->set('access-view-all-resource', true);
             $this->params->set('access-create-resource', true);
             $this->params->set('access-delete-resource', true);
             $this->params->set('access-edit-resource', true);
             $this->params->set('access-edit-state-resource', true);
             $this->params->set('access-edit-own-resource', true);
             $this->_authorized = true;
             return;
         }
         // If they're not an admin
         // If logged in and resource is published and public or registered
         if ($this->published() && ($this->resource->access == 0 || $this->resource->access == 1)) {
             // Allow view access
             $this->params->set('access-view-resource', true);
             $this->params->set('access-view-all-resource', true);
         }
         // Check if they're the resource creator
         if ($this->resource->created_by == User::get('id')) {
             // Give full access
             $this->params->set('access-view-resource', true);
             $this->params->set('access-view-all-resource', true);
             $this->params->set('access-create-resource', true);
             $this->params->set('access-delete-resource', true);
             $this->params->set('access-edit-resource', true);
             $this->params->set('access-edit-state-resource', true);
             $this->params->set('access-edit-own-resource', true);
         } else {
             if (in_array(User::get('id'), $this->contributors('id'))) {
                 // Give full access
                 $this->params->set('access-view-resource', true);
                 $this->params->set('access-view-all-resource', true);
                 $this->params->set('access-create-resource', true);
                 $this->params->set('access-delete-resource', true);
                 $this->params->set('access-edit-resource', true);
                 $this->params->set('access-edit-state-resource', true);
                 $this->params->set('access-edit-own-resource', true);
             } else {
                 if ($this->resource->group_owner) {
                     // For protected resources, make sure users can see abstract
                     if ($this->resource->access < 3) {
                         $this->params->set('access-view-resource', true);
                         $this->params->set('access-view-all-resource', true);
                     } else {
                         if ($this->resource->access == 3) {
                             $this->params->set('access-view-resource', true);
                         }
                     }
                     // Get the groups the user has access to
                     $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'all');
                     $usersgroups = array();
                     if (!empty($xgroups)) {
                         foreach ($xgroups as $group) {
                             if ($group->regconfirmed) {
                                 $usersgroups[] = $group->cn;
                             }
                         }
                     }
                     // Get the groups that can access this resource
                     $allowedgroups = $this->resource->getGroups();
                     // Find what groups the user has in common with the resource, if any
                     $common = array_intersect($usersgroups, $allowedgroups);
                     // Check if the user is apart of the group that owns the resource
                     // or if they have any groups in common
                     if (in_array($this->resource->group_owner, $usersgroups) || count($common) > 0) {
                         $this->params->set('access-view-resource', true);
                         $this->params->set('access-view-all-resource', true);
                         // if (!empty($xgroups))
                         // {
                         // 	foreach ($xgroups as $group)
                         // 	{
                         // 		if ($this->resource->group_owner == $group->cn && $group->manager)
                         // 		{
                         // 			$this->params->set('access-delete-resource', true);
                         // 			$this->params->set('access-edit-resource', true);
                         // 			$this->params->set('access-edit-state-resource', true);
                         // 			$this->params->set('access-edit-own-resource', true);
                         // 			break;
                         // 		}
                         // 	}
                         // }
                     }
                 } else {
                     $this->params->set('access-view-resource', true);
                     $this->params->set('access-view-all-resource', true);
                 }
             }
         }
     }
     $this->_authorized = true;
 }
Example #29
0
 /**
  * Pull a list of records that were created within the time frame ($period)
  *
  * @param      object  $period     Time period to pull results for
  * @param      mixed   $limit      Number of records to pull
  * @param      integer $limitstart Start of records to pull
  * @param      array   $areas      Active area(s)
  * @param      array   $tagids     Array of tag IDs
  * @return     array
  */
 public function onWhatsnew($period, $limit = 0, $limitstart = 0, $areas = null, $tagids = array())
 {
     if (is_array($areas) && $limit) {
         $ars = $this->onWhatsnewAreas();
         if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($ars['resources']))) {
             return array();
         }
     }
     // Do we have a time period?
     if (!is_object($period)) {
         return array();
     }
     $database = App::get('db');
     // Instantiate some needed objects
     $rr = new \Components\Resources\Tables\Resource($database);
     // Build query
     $filters = array('startdate' => $period->cStartDate, 'enddate' => $period->cEndDate, 'sortby' => 'date');
     if (count($tagids) > 0) {
         $filters['tags'] = $tagids;
     }
     $filters['usergroups'] = \Hubzero\User\Helper::getGroups((int) User::get('id', 0), 'all');
     // Get categories
     $categories = $this->_cats;
     if (!is_array($categories)) {
         $rt = new \Components\Resources\Tables\Type($database);
         $categories = $rt->getMajorTypes();
     }
     // Normalize the category names
     // e.g., "Oneline Presentations" -> "onlinepresentations"
     $cats = array();
     for ($i = 0; $i < count($categories); $i++) {
         $cats[$categories[$i]->alias] = array();
         $cats[$categories[$i]->alias]['id'] = $categories[$i]->id;
     }
     $filters['authorized'] = false;
     if ($limit) {
         if ($this->_total != null) {
             $total = 0;
             $t = $this->_total;
             foreach ($t as $l) {
                 $total += $l;
             }
             if ($total == 0) {
                 return array();
             }
         }
         $filters['select'] = 'records';
         $filters['limit'] = $limit;
         $filters['limitstart'] = $limitstart;
         // Check the area of return. If we are returning results for a specific area/category
         // we'll need to modify the query a bit
         if (count($areas) == 1 && isset($areas[0]) && $areas[0] != 'resources') {
             $filters['type'] = $cats[$areas[0]]['id'];
         }
         // Get results
         $database->setQuery($rr->buildPluginQuery($filters));
         $rows = $database->loadObjectList();
         // Did we get any results?
         if ($rows) {
             include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'helper.php';
             // Loop through the results and set each item's HREF
             foreach ($rows as $key => $row) {
                 $resourceEx = new \Components\Resources\Helpers\Helper($row->id, $database);
                 $resourceEx->getContributors();
                 $rows[$key]->authors = $resourceEx->contributors;
                 if ($row->alias) {
                     $rows[$key]->href = Route::url('index.php?option=com_resources&alias=' . $row->alias);
                 } else {
                     $rows[$key]->href = Route::url('index.php?option=com_resources&id=' . $row->id);
                 }
                 if ($row->itext) {
                     $rows[$key]->text = $rows[$key]->itext;
                 } else {
                     if ($row->ftext) {
                         $rows[$key]->text = $rows[$key]->ftext;
                     }
                 }
             }
         }
         return $rows;
     } else {
         $filters['select'] = 'count';
         // Get a count
         $counts = array();
         $ares = $this->onWhatsnewAreas();
         foreach ($ares as $area => $val) {
             if (is_array($val)) {
                 foreach ($val as $a => $t) {
                     $filters['type'] = $cats[$a]['id'];
                     $database->setQuery($rr->buildPluginQuery($filters));
                     $counts[] = $database->loadResult();
                 }
             }
         }
         // Return the counts
         $this->_total = $counts;
         return $counts;
     }
 }
Example #30
0
 /**
  * Set a specific user to check permissions for
  *
  * @param   integer  $aro_foreign_key  User ID
  * @return  void
  */
 public function setUser($aro_foreign_key = null)
 {
     if ($aro_foreign_key) {
         if ($this->_user->get('id') != $aro_foreign_key) {
             $this->_user = User::getInstance($aro_foreign_key);
             $this->_user_groups = UserHelper::getGroups($this->_user->get('id'));
         }
     }
 }