public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); $sort = !empty($configdata['sort']) ? $configdata['sort'] : null; $limit = !empty($configdata['limitto']) ? $configdata['limitto'] : null; $view = $instance->get_view(); $baseurl = $view->get('type') == 'dashboard' ? $view->get_url() . '?id=' . $view->get('id') : $view->get_url(); $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'block=' . $instance->get('id'); $userid = $view->get('owner'); if (!$userid) { return ''; } $smarty = smarty_core(); require_once 'group.php'; // Group stuff if (!empty($limit)) { list($usergroups, $count) = group_get_user_groups($userid, null, $sort, $limit, 0); } else { $usergroups = group_get_user_groups($userid, null, $sort); $count = count($usergroups); } foreach ($usergroups as $group) { $group->roledisplay = get_string($group->role, 'grouptype.' . $group->grouptype); } $groups = array('data' => $usergroups, 'count' => $count, 'limit' => $limit, 'offset' => 0); $pagination = array('baseurl' => $baseurl, 'id' => 'mygroups_pagination', 'datatable' => 'usergroupstable', 'jsonscript' => 'blocktype/mygroups/mygroups.json.php', 'resultcounttextsingular' => get_string('group', 'group'), 'resultcounttextplural' => get_string('groups', 'group')); self::render_items($groups, 'blocktype:mygroups:mygroupslist.tpl', $configdata, $pagination); $smarty->assign('USERGROUPS', $groups); $smarty->assign('userid', $userid); return $smarty->fetch('blocktype:mygroups:mygroups.tpl'); }
function pieform_element_filebrowser_configure_tabs($viewowner, $prefix) { if ($viewowner['type'] == 'institution' && $viewowner['id'] == 'mahara') { // No filebrowser tabs for site views return null; } $tabs = array(); $subtabs = array(); $upload = null; $selectedsubtab = null; if ($viewowner['type'] == 'institution') { $selectedtab = param_variable($prefix . '_owner', 'institution'); $upload = $selectedtab == 'institution'; $tabs['institution'] = get_string('institutionfiles', 'admin'); } else { if ($viewowner['type'] == 'group') { $selectedtab = param_variable($prefix . '_owner', 'group'); $upload = $selectedtab == 'group'; $tabs['user'] = get_string('myfiles', 'artefact.file'); $tabs['group'] = get_string('groupfiles', 'artefact.file'); } else { // $viewowner['type'] == 'user' global $USER; $selectedtab = param_variable($prefix . '_owner', 'user'); $upload = $selectedtab == 'user'; $tabs['user'] = get_string('myfiles', 'artefact.file'); if ($groups = $USER->get('grouproles')) { $tabs['group'] = get_string('groupfiles', 'artefact.file'); require_once get_config('libroot') . 'group.php'; $groups = group_get_user_groups($USER->get('id')); if ($selectedtab == 'group') { if (!($selectedsubtab = (int) param_variable($prefix . '_ownerid', 0))) { $selectedsubtab = $groups[0]->id; } foreach ($groups as &$g) { $subtabs[$g->id] = $g->name; } } } if ($institutions = $USER->get('institutions')) { $tabs['institution'] = get_string('institutionfiles', 'admin'); $institutions = get_records_select_array('institution', 'name IN (' . join(',', array_map('db_quote', array_keys($institutions))) . ')'); if ($selectedtab == 'institution') { if (!($selectedsubtab = param_variable($prefix . '_ownerid', ''))) { $selectedsubtab = $institutions[0]->name; } $selectedsubtab = hsc($selectedsubtab); foreach ($institutions as &$i) { $subtabs[$i->name] = $i->displayname; } } } } } $tabs['site'] = get_string('sitefiles', 'admin'); return array('tabs' => $tabs, 'subtabs' => $subtabs, 'owner' => $selectedtab, 'ownerid' => $viewowner['type'] == 'group' ? $viewowner['id'] : $selectedsubtab, 'upload' => $upload); }
private function getGroupsList() { $list = array(); foreach (group_get_user_groups($this->user->get('id')) as $group) { $list[$group->role][] = $group->id; $list['member'][] = $group->id; } return $list; }
function group_get_user_admintutor_groups() { $groups = array(); foreach (group_get_user_groups() as $g) { if ($g->role == 'admin' || $g->see_submitted_views) { $groups[] = $g; } } return $groups; }
/** * creates the profile sideblock */ function profile_sideblock() { global $USER, $SESSION; safe_require('notification', 'internal'); require_once 'group.php'; require_once 'institution.php'; $data = array('id' => $USER->get('id'), 'myname' => display_name($USER, null, true), 'username' => $USER->get('username'), 'url' => profile_url($USER), 'profileiconurl' => get_config('wwwroot') . 'artefact/file/profileicons.php'); $authinstance = $SESSION->get('mnetuser') ? $SESSION->get('authinstance') : $USER->get('authinstance'); if ($authinstance) { $authobj = AuthFactory::create($authinstance); if ($authobj->authname == 'xmlrpc') { $peer = get_peer($authobj->wwwroot); if ($SESSION->get('mnetuser')) { $data['mnetloggedinfrom'] = get_string('youhaveloggedinfrom1', 'auth.xmlrpc', $authobj->wwwroot, $peer->name); } else { $data['peer'] = array('name' => $peer->name, 'wwwroot' => $peer->wwwroot); } } } $invitedgroups = get_records_sql_array('SELECT g.*, gmi.ctime, gmi.reason FROM {group} g JOIN {group_member_invite} gmi ON gmi.group = g.id WHERE gmi.member = ? AND g.deleted = ?', array($USER->get('id'), 0)); $data['invitedgroups'] = $invitedgroups ? count($invitedgroups) : 0; $data['invitedgroupsmessage'] = $data['invitedgroups'] == 1 ? get_string('invitedgroup') : get_string('invitedgroups'); $data['pendingfriends'] = count_records('usr_friend_request', 'owner', $USER->get('id')); $data['pendingfriendsmessage'] = $data['pendingfriends'] == 1 ? get_string('pendingfriend') : get_string('pendingfriends'); // Check if we want to limit the displayed groups by the account setting $limitto = null; $limit = $USER->get_account_preference('groupsideblockmaxgroups'); if (isset($limit) && is_numeric($limit)) { $limitto = intval($limit); } $sort = null; if ($sortorder = $USER->get_account_preference('groupsideblocksortby')) { $sort = $sortorder; } if ($limitto === null) { $data['groups'] = group_get_user_groups($USER->get('id'), null, $sort); $total = count($data['groups']); } else { if ($limitto === 0) { $data['groups'] = null; } else { list($data['groups'], $total) = group_get_user_groups($USER->get('id'), null, $sort, $limitto); } } $limitstr = ''; if (!empty($limitto) && $limitto < $total) { switch ($sort) { case 'earliest': $limitstr = get_string('numberofmygroupsshowingearliest', 'blocktype.mygroups', $limitto, $total); break; case 'latest': $limitstr = get_string('numberofmygroupsshowinglatest', 'blocktype.mygroups', $limitto, $total); break; default: $limitstr = get_string('numberofmygroupsshowing', 'blocktype.mygroups', $limitto, $total); break; } } $data['grouplimitstr'] = $limitstr; $data['views'] = get_records_sql_array('SELECT v.id, v.title, v.urlid, v.owner FROM {view} v INNER JOIN {view_tag} vt ON (vt.tag = ? AND vt.view = v.id) WHERE v.owner = ? ORDER BY v.title', array(get_string('profile'), $USER->get('id'))); if ($data['views']) { require_once 'view.php'; foreach ($data['views'] as $v) { $view = new View(0, (array) $v); $view->set('dirty', false); $v->fullurl = $view->get_url(); } } $data['artefacts'] = get_records_sql_array('SELECT a.id, a.artefacttype, a.title FROM {artefact} a INNER JOIN {artefact_tag} at ON (a.id = at.artefact AND tag = ?) WHERE a.owner = ? ORDER BY a.title', array(get_string('profile'), $USER->get('id'))); if (!empty($data['artefacts'])) { // check if we have any blogposts and fetch their blog id if we do foreach ($data['artefacts'] as $key => $value) { if ($value->artefacttype == 'blogpost') { $value->blogid = get_field('artefact', 'parent', 'id', $value->id); } } } return $data; }
$id = param_integer('id'); $blockid = param_integer('block'); $view = new View($id); if (!can_view_view($view)) { json_reply(true, get_string('accessdenied', 'error')); } $bi = new Blockinstance($blockid); $configdata = $bi->get('configdata'); $sort = !empty($configdata['sort']) ? $configdata['sort'] : null; $limit = !empty($configdata['limitto']) ? $configdata['limitto'] : null; $baseurl = $bi->get_view()->get_url(); $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'block=' . $bi->get('id'); $userid = $bi->get_view()->get('owner'); if (!$userid) { json_reply(true, get_string('accessdenied', 'error')); } $smarty = smarty_core(); // Group stuff if (!empty($limit)) { list($usergroups, $count) = group_get_user_groups($userid, null, $sort, $limit, $offset); } else { $usergroups = group_get_user_groups($userid, null, $sort); $count = count($usergroups); } foreach ($usergroups as $group) { $group->roledisplay = get_string($group->role, 'grouptype.' . $group->grouptype); } $groups = array('data' => $usergroups, 'count' => $count, 'limit' => $limit, 'offset' => $offset); $pagination = array('baseurl' => $baseurl, 'id' => 'mygroups_pagination', 'datatable' => 'usergroupstable', 'jsonscript' => 'blocktype/mygroups/mygroups.json.php', 'resultcounttextsingular' => get_string('group', 'group'), 'resultcounttextplural' => get_string('groups', 'group')); PluginBlocktypeMygroups::render_items($groups, 'blocktype:mygroups:mygroupslist.tpl', $configdata, $pagination); json_reply(false, array('data' => $groups));
$remoteusermessage = false; $remoteuseracceptform = false; $remoteusernewfriendform = false; $remoteuserfriendscontrol = false; $remoteuserrelationship = false; if (!empty($loggedinid) && $loggedinid != $userid) { $invitedlist = array(); // Groups admin'ed by the logged in user that the displayed user has been invited to $requestedlist = array(); // Groups admin'ed by the logged in user that the displayed user has requested membership of // Get all groups where either: // - the logged in user is an admin, or // - the logged in user has a role which is allowed to assess submitted views, or // - the logged in user is a member & is allowed to invite friends (when the displayed user is a friend) $groups = array(); foreach (group_get_user_groups() as $g) { if ($g->role == 'admin' || $g->see_submitted_views || $is_friend && $g->invitefriends) { $groups[] = $g; } } if ($groups) { $invitelist = array(); // List of groups the displayed user can be invited to join $controlledlist = array(); // List of groups the displayed user can be directly added to foreach ($groups as $group) { if (array_key_exists($group->id, $allusergroups)) { if ($allusergroups[$group->id]->type == 'invite') { $invitedlist[$group->id] = $group->name; } else { if ($allusergroups[$group->id]->type == 'request') {
/** * creates the profile sideblock */ function profile_sideblock() { global $USER, $SESSION; safe_require('notification', 'internal'); require_once 'group.php'; require_once 'institution.php'; $data = array('id' => $USER->get('id'), 'myname' => display_name($USER, null, true), 'username' => $USER->get('username'), 'url' => profile_url($USER), 'profileiconurl' => get_config('wwwroot') . 'artefact/file/profileicons.php'); $authinstance = $SESSION->get('mnetuser') ? $SESSION->get('authinstance') : $USER->get('authinstance'); if ($authinstance) { $authobj = AuthFactory::create($authinstance); if ($authobj->authname == 'xmlrpc') { $peer = get_peer($authobj->wwwroot); if ($SESSION->get('mnetuser')) { $data['mnetloggedinfrom'] = get_string('youhaveloggedinfrom', 'auth.xmlrpc', $authobj->wwwroot, institution_display_name($peer->institution)); } else { $data['peer'] = array('name' => $peer->name, 'wwwroot' => $peer->wwwroot); } } } $invitedgroups = get_records_sql_array('SELECT g.*, gmi.ctime, gmi.reason FROM {group} g JOIN {group_member_invite} gmi ON gmi.group = g.id WHERE gmi.member = ? AND g.deleted = ?', array($USER->get('id'), 0)); $data['invitedgroups'] = $invitedgroups ? count($invitedgroups) : 0; $data['invitedgroupsmessage'] = $data['invitedgroups'] == 1 ? get_string('invitedgroup') : get_string('invitedgroups'); $data['pendingfriends'] = count_records('usr_friend_request', 'owner', $USER->get('id')); $data['pendingfriendsmessage'] = $data['pendingfriends'] == 1 ? get_string('pendingfriend') : get_string('pendingfriends'); $data['groups'] = group_get_user_groups($USER->get('id')); $data['views'] = get_records_sql_array('SELECT v.id, v.title, v.urlid, v.owner FROM {view} v INNER JOIN {view_tag} vt ON (vt.tag = ? AND vt.view = v.id) WHERE v.owner = ? ORDER BY v.title', array(get_string('profile'), $USER->get('id'))); if ($data['views']) { require_once 'view.php'; foreach ($data['views'] as $v) { $view = new View(0, (array) $v); $view->set('dirty', false); $v->fullurl = $view->get_url(); } } $data['artefacts'] = get_records_sql_array('SELECT a.id, a.artefacttype, a.title FROM {artefact} a INNER JOIN {artefact_tag} at ON (a.id = at.artefact AND tag = ?) WHERE a.owner = ? ORDER BY a.title', array(get_string('profile'), $USER->get('id'))); return $data; }
/** * Provides an element to manage a view ACL * * @param array $element The element to render * @param Pieform $form The form to render the element for * @return string The HTML for the element */ function pieform_element_viewacl(Pieform $form, $element) { global $USER, $SESSION, $LANGDIRECTION; $strlen = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen'; $smarty = smarty_core(); $smarty->left_delimiter = '{{'; $smarty->right_delimiter = '}}'; $value = $form->get_value($element); // Look for the presets and split them into two groups require_once get_config('libroot') . 'antispam.php'; $public = false; if (is_probationary_user()) { $public = false; } else { if (get_config('allowpublicviews') && $USER->institution_allows_public_views()) { $public = true; } else { if (get_config('allowpublicprofiles') && $element['viewtype'] == 'profile') { $public = true; } } } $allpresets = array('public', 'loggedin', 'friends'); $allowedpresets = array(); $loggedinindex = 0; if ($public) { $allowedpresets[] = 'public'; $loggedinindex = 1; } $allowedpresets[] = 'loggedin'; if ($form->get_property('userview')) { $allowedpresets[] = 'friends'; } $accesslist = array(); if ($value) { foreach ($value as $item) { if (is_array($item)) { if ($item['type'] == 'public') { $item['publicallowed'] = (int) $public; } if (in_array($item['type'], $allpresets)) { $item['name'] = get_string($item['type'] == 'loggedin' ? 'registeredusers' : $item['type'], 'view'); $item['preset'] = true; } else { $item['name'] = pieform_render_viewacl_getvaluebytype($item['type'], $item['id']); } if ($strlen($item['name']) > 30) { $item['shortname'] = str_shorten_text($item['name'], 30, true); } // only show access that is still current. Expired access will be deleted if the form is saved if ($form->is_submitted() || empty($item['stopdate']) || time() <= strtotime($item['stopdate'])) { $accesslist[] = $item; } } } } $defaultaccesslist = $accesslist ? 0 : 1; $myinstitutions = array(); foreach ($USER->get('institutions') as $i) { $myinstitutions[] = array('type' => 'institution', 'id' => $i->institution, 'start' => null, 'end' => null, 'name' => hsc($i->displayname), 'preset' => false); } foreach ($allowedpresets as &$preset) { $preset = array('type' => $preset, 'id' => $preset, 'start' => null, 'end' => null, 'name' => get_string($preset == 'loggedin' ? 'registeredusers' : $preset, 'view'), 'preset' => true); } $allgroups = array('type' => 'allgroups', 'id' => 'allgroups', 'start' => null, 'end' => null, 'name' => get_string('allmygroups', 'group'), 'preset' => true); $mygroups = array(); foreach (group_get_user_groups($USER->get('id')) as $g) { $group = array('type' => 'group', 'id' => $g->id, 'start' => null, 'end' => null, 'name' => $g->name, 'preset' => false); if ($strlen($g->name) > 30) { $group['shortname'] = str_shorten_text($g->name, 30, true); } $mygroups[] = $group; } $faves = array(); foreach (get_user_favorites($USER->get('id')) as $u) { $fave = array('type' => 'user', 'id' => $u->id, 'start' => null, 'end' => null, 'name' => $u->name, 'preset' => false); if ($strlen($u->name) > 30) { $fave['shortname'] = str_shorten_text($u->name, 30, true); } $faves[] = $fave; } require_once get_config('libroot') . 'pieforms/pieform/elements/calendar.php'; $options = array('dateFormat' => get_string('calendar_dateFormat', 'langconfig'), 'timeFormat' => get_string('calendar_timeFormat', 'langconfig'), 'stepHour' => 1, 'stepMinute' => 5); $options = pieform_element_calendar_get_lang_strings($options, $LANGDIRECTION); $datepickeroptionstr = ''; foreach ($options as $key => $option) { if (is_numeric($option)) { $datepickeroptionstr .= $key . ': ' . $option . ','; } else { if (is_array($option)) { foreach ($option as $k => $v) { if (!is_numeric($v)) { if (preg_match('/^\'(.*)\'$/', $v, $match)) { $v = $match[1]; } $option[$k] = json_encode($v); } } $option = '[' . implode(',', $option) . ']'; $datepickeroptionstr .= $key . ': ' . $option . ','; } else { $datepickeroptionstr .= $key . ': ' . json_encode($option) . ','; } } } $smarty->assign('datepickeroptions', $datepickeroptionstr); $smarty->assign('viewtype', $element['viewtype']); $smarty->assign('potentialpresets', json_encode($allowedpresets)); $smarty->assign('loggedinindex', $loggedinindex); $smarty->assign('accesslist', json_encode($accesslist)); $smarty->assign('defaultaccesslist', $defaultaccesslist); $smarty->assign('viewid', $form->get_property('viewid')); $smarty->assign('formname', $form->get_property('name')); $smarty->assign('myinstitutions', json_encode($myinstitutions)); $smarty->assign('allowcomments', $element['allowcomments']); $smarty->assign('allgroups', json_encode($allgroups)); $smarty->assign('mygroups', json_encode($mygroups)); $smarty->assign('faves', json_encode($faves)); return $smarty->fetch('form/viewacl.tpl'); }
/** * creates the profile sideblock */ function profile_sideblock() { global $USER, $SESSION; safe_require('notification', 'internal'); require_once 'group.php'; $data = array('id' => $USER->get('id'), 'myname' => display_name($USER, null, true), 'username' => $USER->get('username'), 'profileicon' => $USER->get('profileicon') ? $USER->get('profileicon') : 0); if ($SESSION->get('mnetuser')) { $authinstance = $SESSION->get('authinstance'); if ($authinstance) { $authobj = AuthFactory::create($authinstance); $peer = get_peer($authobj->wwwroot); $data['mnetloggedinfrom'] = get_string('youhaveloggedinfrom', 'auth.xmlrpc', $authobj->wwwroot, $peer->name); } } $data['unreadnotifications'] = call_static_method(generate_class_name('notification', 'internal'), 'unread_count', $USER->get('id')); $data['unreadnotificationsmessage'] = $data['unreadnotifications'] == 1 ? get_string('unreadmessage') : get_string('unreadmessages'); $invitedgroups = get_records_sql_array('SELECT g.*, gmi.ctime, gmi.reason FROM {group} g JOIN {group_member_invite} gmi ON gmi.group = g.id WHERE gmi.member = ? AND g.deleted = ?', array($USER->get('id'), 0)); $data['invitedgroups'] = $invitedgroups ? count($invitedgroups) : 0; $data['invitedgroupsmessage'] = $data['invitedgroups'] == 1 ? get_string('invitedgroup') : get_string('invitedgroups'); $data['pendingfriends'] = count_records('usr_friend_request', 'owner', $USER->get('id')); $data['pendingfriendsmessage'] = $data['pendingfriends'] == 1 ? get_string('pendingfriend') : get_string('pendingfriends'); $data['groups'] = group_get_user_groups($USER->get('id')); $data['views'] = get_records_sql_array('SELECT v.id, v.title FROM {view} v INNER JOIN {view_tag} vt ON (vt.tag = ? AND vt.view = v.id) WHERE v.owner = ? ORDER BY v.title', array(get_string('profile'), $USER->get('id'))); $data['artefacts'] = get_records_sql_array('SELECT a.id, a.artefacttype, a.title FROM {artefact} a INNER JOIN {artefact_tag} at ON (a.id = at.artefact AND tag = ?) WHERE a.owner = ? ORDER BY a.title', array(get_string('profile'), $USER->get('id'))); return $data; }