public static function render_instance(BlockInstance $instance, $editing = false) { if ($group = self::get_group($instance)) { require_once 'group.php'; $role = group_user_access($group->id); if ($role || $group->public) { $limit = 5; $configdata = $instance->get('configdata'); if (!empty($configdata['limit'])) { $limit = intval($configdata['limit']); } $foruminfo = get_records_sql_array(' SELECT p.id, p.subject, p.body, p.poster, p.topic, t.forum, pt.subject AS topicname, u.firstname, u.lastname, u.username, u.preferredname, u.email, u.profileicon, u.admin, u.staff, u.deleted, u.urlid FROM {interaction_forum_post} p INNER JOIN {interaction_forum_topic} t ON (t.id = p.topic) INNER JOIN {interaction_instance} i ON (i.id = t.forum) INNER JOIN {interaction_forum_post} pt ON (pt.topic = p.topic AND pt.parent IS NULL) INNER JOIN {usr} u ON p.poster = u.id WHERE i.group = ? AND i.deleted = 0 AND t.deleted = 0 AND p.deleted = 0 ORDER BY p.ctime DESC', array($group->id), 0, $limit); if ($foruminfo) { $userfields = array('firstname', 'lastname', 'username', 'preferredname', 'email', 'profileicon', 'admin', 'staff', 'deleted', 'urlid'); foreach ($foruminfo as $f) { $f->author = (object) array('id' => $f->poster); foreach ($userfields as $uf) { $f->author->{$uf} = $f->{$uf}; unset($f->{$uf}); } } } $smarty = smarty_core(); $smarty->assign('group', $group); $smarty->assign('foruminfo', $foruminfo); if ($instance->get_view()->get('type') == 'grouphomepage') { return $smarty->fetch('blocktype:recentforumposts:latestforumposts.tpl'); } return $smarty->fetch('blocktype:recentforumposts:recentforumposts.tpl'); } } return ''; }
/** * Returns a form to mark a view as unobjectionable, * if the user is allowed to do that. * * @returns array Form elements. */ function notrude_form() { global $USER, $view, $artefact; $owner = $view->get('owner'); if (!($owner && ($USER->get('admin') || $USER->is_admin_for_user($owner)) || $view->get('group') && $USER->get('admin') || $view->get('group') && group_user_access($view->get('group'), $USER->get('id')) == 'admin')) { return; } if ($artefact) { $params = array('artefact', $artefact->get('id')); } else { $params = array('view', $view->get('id')); } $isrude = get_record_select('objectionable', 'objecttype = ? AND objectid = ? AND resolvedby IS NULL LIMIT 1', $params); if (!$isrude) { return; } return array('name' => 'notrude_form', 'class' => 'form-inline', 'method' => 'post', 'elements' => array('objection' => array('type' => 'hidden', 'value' => $isrude->id), 'text' => array('type' => 'html', 'class' => 'pbm', 'value' => get_string('viewobjectionableunmark', 'view')), 'submit' => array('type' => 'button', 'usebuttontag' => true, 'class' => 'btn-default', 'value' => '<span class="icon icon-lg icon-times text-danger prs"></span> ' . get_string('notobjectionable')))); }
/** * Returns a form to mark a view as unobjectionable, * if the user is allowed to do that. * * @returns array Form elements. */ function notrude_form() { global $USER, $view, $artefact; $owner = $view->get('owner'); if (!($owner && ($USER->get('admin') || $USER->is_admin_for_user($owner)) || $view->get('group') && $USER->get('admin') || $view->get('group') && group_user_access($view->get('group'), $USER->get('id')) == 'admin')) { return; } if ($artefact) { $params = array('artefact', $artefact->get('id')); } else { $params = array('view', $view->get('id')); } $isrude = get_record_select('objectionable', 'objecttype = ? AND objectid = ? AND resolvedby IS NULL LIMIT 1', $params); if (!$isrude) { return; } return array('name' => 'notrude_form', 'method' => 'post', 'elements' => array('objection' => array('type' => 'hidden', 'value' => $isrude->id), 'text' => array('type' => 'html', 'value' => get_string('viewobjectionableunmark', 'view')), 'submit' => array('type' => 'submit', 'value' => get_string('notobjectionable')))); }
function groupadminsform_submit(Pieform $form, $values) { global $SESSION, $group, $admins; $newadmins = array_diff($values['admins'], $admins); $demoted = array_diff($admins, $values['admins']); db_begin(); if ($demoted) { $demoted = join(',', array_map('intval', $demoted)); execute_sql("\n UPDATE {group_member}\n SET role = 'member'\n WHERE role = 'admin' AND \"group\" = ?\n AND member IN ({$demoted})", array($group->id)); } $dbnow = db_format_timestamp(time()); foreach ($newadmins as $id) { if (group_user_access($group->id, $id)) { group_change_role($group->id, $id, 'admin'); } else { group_add_user($group->id, $id, 'admin'); } } db_commit(); $SESSION->add_ok_msg(get_string('groupadminsupdated', 'admin')); redirect(get_config('wwwroot') . 'admin/groups/groups.php'); }
public static function render_instance(BlockInstance $instance, $editing = false) { if ($group = self::get_group($instance)) { require_once 'group.php'; $role = group_user_access($group->id); if ($role || $group->public) { $limit = 5; $configdata = $instance->get('configdata'); if (!empty($configdata['limit'])) { $limit = intval($configdata['limit']); } $foruminfo = get_records_sql_array(' SELECT p.id, p.subject, p.body, p.poster, p.topic, t.forum, pt.subject AS topicname FROM {interaction_forum_post} p INNER JOIN {interaction_forum_topic} t ON (t.id = p.topic) INNER JOIN {interaction_instance} i ON (i.id = t.forum) INNER JOIN {interaction_forum_post} pt ON (pt.topic = p.topic AND pt.parent IS NULL) WHERE i.group = ? AND i.deleted = 0 AND t.deleted = 0 AND p.deleted = 0 ORDER BY p.ctime DESC', array($group->id), 0, $limit); $smarty = smarty_core(); $smarty->assign('group', $group); $smarty->assign('foruminfo', $foruminfo); if ($instance->get_view()->get('type') == 'grouphomepage') { return $smarty->fetch('blocktype:recentforumposts:latestforumposts.tpl'); } return $smarty->fetch('blocktype:recentforumposts:recentforumposts.tpl'); } } return ''; }
$userid = param_integer('userid'); $jointype = param_variable('jointype'); // Prevent group membership changing done by ordinary members, Tutors can only // add members to group and cannot remove anyone. Group admins can do anything. // With regard to invitation, both admins and tutors can invite people. foreach (array_unique(array_merge($initialgroups, $resultgroups)) as $groupid) { if (!group_user_access($groupid)) { json_reply('local', get_string('accessdenied', 'error')); break; } switch (group_user_access($groupid)) { case 'member': json_reply('local', get_string('accessdenied', 'error')); break; case 'tutor': if ($usertype = group_user_access($groupid, $userid)) { if ($usertype == 'member' && in_array($groupid, array_diff($initialgroups, $resultgroups))) { json_reply('local', get_string('cantremovemember', 'group')); } elseif ($usertype != 'member' && in_array($groupid, array_diff($initialgroups, $resultgroups))) { json_reply('local', get_string('cantremoveuserisadmin', 'group')); } } } } $groupdata = get_records_select_assoc('group', 'id IN (' . join(',', array_unique(array_merge($initialgroups, $resultgroups))) . ')'); if ($jointype == 'controlled') { db_begin(); //remove group membership if ($groupstoremove = array_diff($initialgroups, $resultgroups)) { $groupstoremovemail = ''; foreach ($groupstoremove as $groupid) {
function group_get_groupinfo_data($group) { safe_require('artefact', 'file'); safe_require('interaction', 'forum'); $group->admins = group_get_admins(array($group->id)); $group->settingsdescription = group_display_settings($group); if (get_config('allowgroupcategories')) { $group->categorytitle = $group->category ? get_field('group_category', 'title', 'id', $group->category) : ''; } if (group_can_list_members($group, group_user_access($group->id))) { $group->membercount = count_records('group_member', 'group', $group->id); } $group->viewcount = count_records('view', 'group', $group->id); $group->filecounts = ArtefactTypeFileBase::count_user_files(null, $group->id, null); $group->forumcounts = PluginInteractionForum::count_group_forums($group->id); $group->topiccounts = PluginInteractionForum::count_group_topics($group->id); $group->postcounts = PluginInteractionForum::count_group_posts($group->id); return $group; }
if (empty($c->author)) { if (!isset($commenters[$c->authorname])) { $commenters[$c->authorname] = array(); } $commenters[$c->authorname]['commenter'] = $c->authorname; $commenters[$c->authorname]['count'] = isset($commenters[$c->authorname]['count']) ? $commenters[$c->authorname]['count'] + 1 : 1; if ($commenters[$c->authorname]['count'] == 1) { $extcommenters++; } $extcomments++; } else { if (!isset($commenters[$c->author->id])) { $commenters[$c->author->id] = array(); } $commenters[$c->author->id]['commenter'] = (int) $c->author->id; $commenters[$c->author->id]['member'] = group_user_access($group->id, $c->author->id); $commenters[$c->author->id]['count'] = isset($commenters[$c->author->id]['count']) ? $commenters[$c->author->id]['count'] + 1 : 1; if (empty($commenters[$c->author->id]['member'])) { if ($commenters[$c->author->id]['count'] == 1) { $extcommenters++; } $extcomments++; } else { if ($commenters[$c->author->id]['count'] == 1) { $membercommenters++; } $membercomments++; } } } $data['id'] = (int) $data['id'];
* */ define('INTERNAL', 1); define('MENUITEM', 'groups'); require dirname(dirname(__FILE__)) . '/init.php'; require_once 'pieforms/pieform.php'; require_once 'group.php'; $groupid = param_integer('id'); $userid = param_integer('user'); define('GROUP', $groupid); $group = group_current_group(); $user = get_record('usr', 'id', $userid, 'deleted', 0); if (!$user) { throw new UserNotFoundException(get_string('usernotfound', 'group', $userid)); } if ($group->jointype != 'invite' || group_user_access($groupid) != 'admin') { throw new AccessDeniedException(get_string('cannotinvitetogroup', 'group')); } if (record_exists('group_member', 'group', $groupid, 'member', $userid) || record_exists('group_member_invite', 'group', $groupid, 'member', $userid)) { throw new UserException(get_string('useralreadyinvitedtogroup', 'group')); } define('TITLE', get_string('invitemembertogroup', 'group', display_name($userid), $group->name)); $roles = group_get_role_info($groupid); foreach ($roles as $k => &$v) { $v = $v->display; } safe_require('grouptype', $group->grouptype); $form = pieform(array('name' => 'invitetogroup', 'autofocus' => false, 'method' => 'post', 'elements' => array('reason' => array('type' => 'textarea', 'cols' => 50, 'rows' => 4, 'title' => get_string('reason')), 'role' => array('type' => 'select', 'options' => $roles, 'title' => get_string('Role', 'group'), 'defaultvalue' => call_static_method('GroupType' . $group->grouptype, 'default_role')), 'submit' => array('type' => 'submitcancel', 'value' => array(get_string('invite', 'group'), get_string('cancel')), 'goto' => get_config('wwwroot') . 'user/view.php?id=' . $userid)))); $smarty = smarty(); $smarty->assign('subheading', TITLE); $smarty->assign('form', $form);
protected static function get_data($groupid, $editing = false) { global $USER; if (!defined('GROUP')) { define('GROUP', $groupid); } // get the currently requested group $group = group_current_group(); $role = group_user_access($group->id); if ($role) { $bi = group_get_homepage_view_groupview_block($group->id); $configdata = $bi->get('configdata'); $limit = isset($configdata['count']) ? intval($configdata['count']) : 5; $limit = $limit > 0 ? $limit : 5; // Get all views created in the group $sort = array(array('column' => 'type=\'grouphomepage\'', 'desc' => true)); $data['groupviews'] = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, 0, true, $sort); foreach ($data['groupviews']->data as &$view) { if (!$editing && isset($view['template']) && $view['template']) { $view['form'] = pieform(create_view_form(null, null, $view['id'])); } } // For group members, display a list of views that others have // shared to the group $data['sharedviews'] = View::get_sharedviews_data($limit, 0, $group->id); foreach ($data['sharedviews']->data as &$view) { if (!$editing && isset($view['template']) && $view['template']) { $view['form'] = pieform(create_view_form($group, null, $view->id)); } } $data['sharedcollections'] = View::get_sharedcollections_data($limit, 0, $group->id); if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) { // Display a list of views submitted to the group list($collections, $views) = View::get_views_and_collections(null, null, null, null, false, $group->id); $allsubmitted = array_merge(array_values($collections), array_values($views)); $data['allsubmitted'] = array('data' => array_slice($allsubmitted, 0, $limit), 'count' => count($allsubmitted), 'limit' => $limit, 'offset' => 0); } } if ($group->submittableto) { require_once 'pieforms/pieform.php'; // A user can submit more than one view to the same group, but no view can be // submitted to more than one group. // Display a list of views this user has submitted to this group, and a submission // form containing drop-down of their unsubmitted views. list($collections, $views) = View::get_views_and_collections($USER->get('id'), null, null, null, false, $group->id); $data['mysubmitted'] = array_merge(array_values($collections), array_values($views)); // Only render the submission form in viewing mode if (!$editing) { $data['group_view_submission_form'] = group_view_submission_form($group->id); } } $data['group'] = $group; return $data; }
/** * Returns a datastructure describing the tabs that appear on a group page * * @param object $group Database record of group to get tabs for * @return array */ function group_get_menu_tabs() { static $menu; $group = group_current_group(); if (!$group) { return null; } $menu = array('info' => array('path' => 'groups/info', 'url' => 'group/view.php?id=' . $group->id, 'title' => get_string('About', 'group'), 'weight' => 20), 'members' => array('path' => 'groups/members', 'url' => 'group/members.php?id=' . $group->id, 'title' => get_string('Members', 'group'), 'weight' => 30)); if ($group->public || group_user_access($group->id)) { $menu['forums'] = array('path' => 'groups/forums', 'url' => 'interaction/forum/index.php?group=' . $group->id, 'title' => get_string('nameplural', 'interaction.forum'), 'weight' => 40); } $menu['views'] = array('path' => 'groups/views', 'url' => 'view/groupviews.php?group=' . $group->id, 'title' => get_string('Views', 'group'), 'weight' => 50); if (group_user_access($group->id)) { safe_require('grouptype', $group->grouptype); $artefactplugins = call_static_method('GroupType' . $group->grouptype, 'get_group_artefact_plugins'); if ($plugins = get_records_array('artefact_installed', 'active', 1)) { foreach ($plugins as &$plugin) { if (!in_array($plugin->name, $artefactplugins)) { continue; } safe_require('artefact', $plugin->name); $plugin_menu = call_static_method(generate_class_name('artefact', $plugin->name), 'group_tabs', $group->id); $menu = array_merge($menu, $plugin_menu); } } } if (defined('MENUITEM')) { $key = substr(MENUITEM, strlen('groups/')); if ($key && isset($menu[$key])) { $menu[$key]['selected'] = true; } } return $menu; }
/** * Given a user, makes sure they have been added to all groups that are marked * as ones that users should be auto-added to * * @param array $eventdata Event data passed from activity_occured, the key 'id' = userid */ function add_user_to_autoadd_groups($eventdata) { require_once 'group.php'; $userid = $eventdata['id']; if ($autoaddgroups = get_column('group', 'id', 'usersautoadded', true)) { foreach ($autoaddgroups as $groupid) { if (!group_user_access($groupid, $userid)) { group_add_user($groupid, $userid); } } } }
/** * Get all views for a (user,group,institution), grouping views * into their collections. Empty collections not returned. * * @param mixed $owner integer userid or array of userids * @param mixed $group integer groupid or array of groupids * @param mixed $institution string institution name or array of institution names * @param string $matchconfig record all matches with given config hash (see set_access) * @param boolean $includeprofile include profile view * @param integer $submittedgroup return only views & collections submitted to this group * @param $string $sort Order to sort by (defaults to 'c.name, v.title') * * @return array, array */ function get_views_and_collections($owner = null, $group = null, $institution = null, $matchconfig = null, $includeprofile = true, $submittedgroup = null, $sort = null) { $excludelocked = $group && group_user_access($group) != 'admin'; // Anonymous public viewing of a group with 'Allow submissions' checked needs to avoid including the dummy root profile page. if ($owner == '0') { $includeprofile = false; } $sql = "\n SELECT v.id, v.type, v.title, v.accessconf, v.ownerformat, v.startdate, v.stopdate, v.template,\n v.owner, v.group, v.institution, v.urlid, v.submittedgroup, v.submittedhost, " . db_format_tsfield('v.submittedtime', 'submittedtime') . ", v.submittedstatus,\n c.id AS cid, c.name AS cname,\n c.submittedgroup AS csubmitgroup, c.submittedhost AS csubmithost, " . db_format_tsfield('c.submittedtime', 'csubmittime') . ", c.submittedstatus AS csubmitstatus\n FROM {view} v\n LEFT JOIN {collection_view} cv ON v.id = cv.view\n LEFT JOIN {collection} c ON cv.collection = c.id\n WHERE v.type IN ('portfolio'"; $sql .= $includeprofile ? ", 'profile') " : ') '; $sql .= $excludelocked ? 'AND v.locked != 1 ' : ''; if (is_null($owner) && is_null($group) && is_null($institution)) { $values = array(); } else { list($ownersql, $values) = self::multiple_owner_sql((object) array('owner' => $owner, 'group' => $group, 'institution' => $institution)); $sql .= "AND v.{$ownersql} "; } if ($submittedgroup) { $sql .= 'AND v.submittedgroup = ? '; $values[] = (int) $submittedgroup; } if ($sort == null) { $sql .= 'ORDER BY c.name, v.title'; } else { $sql .= "ORDER BY {$sort}"; } $records = get_records_sql_assoc($sql, $values); $collections = array(); $views = array(); if (!$records) { return array($collections, $views); } self::get_extra_view_info($records, false, false); foreach ($records as &$r) { $vid = $r['id']; $cid = $r['cid']; $v = array('id' => $vid, 'type' => $r['type'], 'name' => $r['displaytitle'], 'url' => $r['fullurl'], 'startdate' => $r['startdate'], 'stopdate' => $r['stopdate'], 'template' => $r['template'], 'owner' => $r['owner'], 'submittedgroup' => $r['submittedgroup'], 'submittedhost' => $r['submittedhost'], 'submittedtime' => $r['submittedtime'], 'submittedstatus' => $r['submittedstatus']); if (isset($r['user'])) { $v['ownername'] = display_name($r['user']); $v['ownerurl'] = profile_url($r['user']); } // If filtering by submitted views, and the view is submitted, but the collection isn't, // then ignore the collection and return the view by itself. if ($cid && (!$submittedgroup || $r['csubmitgroup'] == $r['submittedgroup'])) { if (!isset($collections[$cid])) { $collections[$cid] = array('id' => $cid, 'name' => $r['cname'], 'url' => $r['fullurl'], 'owner' => $r['owner'], 'group' => $r['group'], 'institution' => $r['institution'], 'submittedgroup' => $r['csubmitgroup'], 'submittedhost' => $r['csubmithost'], 'submittedtime' => $r['csubmittime'], 'submittedstatus' => $r['csubmitstatus'], 'template' => $r['template'], 'views' => array()); if (isset($r['user'])) { $collections[$cid]['ownername'] = $v['ownername']; $collections[$cid]['ownerurl'] = $v['ownerurl']; } if ($matchconfig && $matchconfig == $r['accessconf']) { $collections[$cid]['match'] = true; } } $collections[$cid]['views'][$vid] = $v; } else { $views[$vid] = $v; if ($matchconfig && $matchconfig == $r['accessconf']) { $views[$vid]['match'] = true; } } } return array($collections, $views); }
/** * Get views which have been explicitly shared to a group and are * not owned by the group */ public static function get_sharedviews_data($limit = 10, $offset = 0, $groupid) { global $USER; $userid = $USER->get('id'); require_once get_config('libroot') . 'group.php'; if (!group_user_access($groupid)) { throw new AccessDeniedException(get_string('accessdenied', 'error')); } $from = ' FROM {view} v INNER JOIN {view_access} a ON (a.view = v.id) INNER JOIN {group_member} m ON (a.group = m.group AND (a.role = m.role OR a.role IS NULL)) WHERE a.group = ? AND m.member = ? AND (v.group IS NULL OR v.group != ?)'; $ph = array($groupid, $userid, $groupid); $count = count_records_sql('SELECT COUNT(*) ' . $from, $ph); $viewdata = get_records_sql_assoc(' SELECT v.id,v.title,v.startdate,v.stopdate,v.description,v.group,v.owner,v.ownerformat,v.institution ' . $from . ' ORDER BY v.title, v.id', $ph, $offset, $limit); if ($viewdata) { View::get_extra_view_info($viewdata, false); } else { $viewdata = array(); } return (object) array('data' => array_values($viewdata), 'count' => $count); }
/** * Given a post id & the id of an image artefact, check that the logged-in user * has permission to see the image in the context of the post. */ public static function can_see_attached_file($file, $postid) { global $USER; require_once 'group.php'; if (!$file instanceof ArtefactTypeImage) { return false; } $post = get_record_sql(' SELECT p.body, p.poster, g.id AS groupid, g.public FROM {interaction_forum_post} p INNER JOIN {interaction_forum_topic} t ON (t.id = p.topic AND t.deleted = 0) INNER JOIN {interaction_forum_post} fp ON (fp.parent IS NULL AND fp.topic = t.id) INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted = 0) INNER JOIN {group} g ON (f.group = g.id AND g.deleted = 0) WHERE p.id = ? AND p.deleted = 0', array($postid)); if (!$post) { return false; } if (!$post->public && !group_user_access($post->groupid, $USER->get('id'))) { return false; } // Check that the author of the post is allowed to publish the file $poster = new User(); $poster->find_by_id($post->poster); if (!$poster->can_publish_artefact($file)) { return false; } // Load the post as an html fragment & make sure it has the image in it $page = new DOMDocument(); libxml_use_internal_errors(true); $success = $page->loadHTML($post->body); libxml_use_internal_errors(false); if (!$success) { return false; } $xpath = new DOMXPath($page); $srcstart = get_config('wwwroot') . 'artefact/file/download.php?file=' . $file->get('id') . '&'; $query = '//img[starts-with(@src,"' . $srcstart . '")]'; $elements = $xpath->query($query); if ($elements->length < 1) { return false; } return true; }
* * @package mahara * @subpackage core * @author Catalyst IT Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz * */ define('INTERNAL', 1); define('MENUITEM', 'groups'); require dirname(dirname(__FILE__)) . '/init.php'; require_once get_config('docroot') . 'interaction/lib.php'; require_once get_config('libroot') . 'group.php'; define('GROUP', param_integer('id')); $group = group_current_group(); if (group_user_access($group->id, $USER->get('id')) != 'admin') { throw new AccessDeniedException(get_string('notallowedtoeditinteraction', 'group')); } define('TITLE', get_string('groupinteractions', 'group')); $interactiontypes = array_flip(array_map(create_function('$a', 'return $a->name;'), plugins_installed('interaction'))); if (!($interactions = get_records_select_array('interaction_instance', '"group" = ? AND deleted = ?', array($group->id, 0), 'plugin, ctime', 'id, plugin, title'))) { $interactions = array(); } $names = array(); foreach (array_keys($interactiontypes) as $plugin) { $names[$plugin] = array('single' => get_string('name', 'interaction.' . $plugin), 'plural' => get_string('nameplural', 'interaction.' . $plugin)); } foreach ($interactions as $i) { if (!is_array($interactiontypes[$i->plugin])) { $interactiontypes[$i->plugin] = array(); }
$allgroups = array_unique(array_merge($initialgroups, $resultgroups)); $groupdata = get_records_select_assoc('group', 'id IN (' . join(',', array_fill(0, count($allgroups), '?')) . ')', $allgroups); foreach (group_get_grouptypes() as $grouptype) { safe_require('grouptype', $grouptype); } foreach ($allgroups as $groupid) { if (!($loggedinrole = group_user_access($groupid))) { json_reply('local', get_string('accessdenied', 'error')); } if ($loggedinrole == 'admin') { continue; } if (!in_array($loggedinrole, call_static_method('GroupType' . $groupdata[$groupid]->grouptype, 'get_view_assessing_roles'))) { json_reply('local', get_string('accessdenied', 'error')); } if (group_user_access($groupid, $userid) && in_array($groupid, array_diff($initialgroups, $resultgroups))) { json_reply('local', get_string('cantremovememberfromgroup', 'group', hsc($groupdata[$groupid]->name))); } } if ($addtype == 'add') { db_begin(); //remove group membership if ($groupstoremove = array_diff($initialgroups, $resultgroups)) { $groupstoremovemail = ''; foreach ($groupstoremove as $groupid) { group_remove_user($groupid, $userid, $role = null); $groupstoremovemail .= $groupdata[$groupid]->name . "\n"; } } //add group membership if ($groupstoadd = array_diff($resultgroups, $initialgroups)) {
function pieform_element_filebrowser_move(Pieform $form, $element, $data) { global $USER; $artefactid = $data['artefact']; // Artefact being moved $newparentid = $data['newparent']; // Folder to move it to try { $artefact = artefact_instance_from_id($artefactid); } catch (ArtefactNotFoundException $e) { $result = array('error' => true, 'message' => get_string('movingfailed', 'artefact.file'), 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $data['folder'])); return $result; } if (!$USER->can_edit_artefact($artefact)) { return array('error' => true, 'message' => get_string('movefailednotowner', 'artefact.file')); } if (!in_array($artefact->get('artefacttype'), PluginArtefactFile::get_artefact_types())) { return array('error' => true, 'message' => get_string('movefailednotfileartefact', 'artefact.file')); } if ($newparentid > 0) { if ($newparentid == $artefactid) { return array('error' => true, 'message' => get_string('movefaileddestinationinartefact', 'artefact.file')); } if ($newparentid == $artefact->get('parent')) { return array('error' => false, 'message' => get_string('filealreadyindestination', 'artefact.file')); } try { $newparent = artefact_instance_from_id($newparentid); } catch (ArtefactNotFoundException $e) { $parentfolder = $element['folder'] ? $element['folder'] : null; $result = array('error' => true, 'message' => get_string('movingfailed', 'artefact.file'), 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $data['folder'])); return $result; } if (!$USER->can_edit_artefact($newparent)) { return array('error' => true, 'message' => get_string('movefailednotowner', 'artefact.file')); } else { if ($newparent->get('locked')) { return array('error' => true, 'message' => get_string('cannoteditfoldersubmitted', 'artefact.file')); } } $group = $artefact->get('group'); if ($group && $group !== $newparent->get('group')) { return array('error' => true, 'message' => get_string('movefailednotowner', 'artefact.file')); } if ($newparent->get('artefacttype') != 'folder') { return array('error' => true, 'message' => get_string('movefaileddestinationnotfolder', 'artefact.file')); } $nextparentid = $newparent->get('parent'); while (!empty($nextparentid)) { if ($nextparentid != $artefactid) { $ancestor = artefact_instance_from_id($nextparentid); $nextparentid = $ancestor->get('parent'); } else { return array('error' => true, 'message' => get_string('movefaileddestinationinartefact', 'artefact.file')); } } } else { // $newparentid === 0 if ($artefact->get('parent') == null) { return array('error' => false, 'message' => get_string('filealreadyindestination', 'artefact.file')); } $group = $artefact->get('group'); if ($group) { // Use default grouptype artefact permissions to check if the // user can move a file to the group's root directory require_once get_config('libroot') . 'group.php'; $permissions = group_get_default_artefact_permissions($group); if (!$permissions[group_user_access($group)]->edit) { return array('error' => true, 'message' => get_string('movefailednotowner', 'artefact.file')); } } $newparentid = null; } if ($oldparentid = $artefact->get('parent')) { $oldparent = artefact_instance_from_id($oldparentid); if ($oldparent->get('locked')) { return array('error' => true, 'message' => get_string('cannotremovefromsubmittedfolder', 'artefact.file')); } } if ($artefact->move($newparentid)) { return array('error' => false, 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $data['folder'])); } return array('error' => true, 'message' => get_string('movefailed', 'artefact.file')); }
*/ define('PUBLIC', 1); define('INTERNAL', 1); define('MENUITEM', 'groups/forums'); define('SECTION_PLUGINTYPE', 'interaction'); define('SECTION_PLUGINNAME', 'forum'); define('SECTION_PAGE', 'index'); require dirname(dirname(dirname(__FILE__))) . '/init.php'; require_once 'group.php'; safe_require('interaction', 'forum'); require_once 'pieforms/pieform.php'; require_once get_config('docroot') . 'interaction/lib.php'; $groupid = param_integer('group'); define('GROUP', $groupid); $group = group_current_group(); $membership = group_user_access($groupid); if (!$membership && !$group->public) { throw new GroupAccessDeniedException(get_string('cantviewforums', 'interaction.forum')); } define('TITLE', $group->name . ' - ' . get_string('nameplural', 'interaction.forum')); $breadcrumbs = array(array(get_config('wwwroot') . 'group/view.php?id=' . $groupid, $group->name), array(get_config('wwwroot') . 'interaction/forum/index.php?group=' . $groupid, get_string('nameplural', 'interaction.forum'))); $forums = get_records_sql_array('SELECT f.id, f.title, f.description, m.user AS moderator, COUNT(t.id) AS topiccount, s.forum AS subscribed FROM {interaction_instance} f LEFT JOIN ( SELECT m.forum, m.user FROM {interaction_forum_moderator} m INNER JOIN {usr} u ON (m.user = u.id AND u.deleted = 0) ) m ON m.forum = f.id LEFT JOIN {interaction_forum_topic} t ON (t.forum = f.id AND t.deleted != 1) INNER JOIN {interaction_forum_instance_config} c ON (c.forum = f.id AND c.field = \'weight\') LEFT JOIN {interaction_forum_subscription_forum} s ON (s.forum = f.id AND s."user" = ?)
protected static function get_data($groupid) { global $USER; if (!defined('GROUP')) { define('GROUP', $groupid); } // get the currently requested group $group = group_current_group(); $group->ctime = strftime(get_string('strftimedate'), $group->ctime); // if the user isn't logged in an the group isn't public don't show anything if (!is_logged_in() && !$group->public) { throw new AccessDeniedException(); } // find the group administrators $group->admins = get_column_sql("SELECT \"member\"\n FROM {group_member}\n WHERE \"group\" = ?\n AND \"role\" = 'admin'", array($group->id)); $role = group_user_access($group->id); $group->role = $role; // logged in user can do stuff if (is_logged_in()) { $afterjoin = param_variable('next', 'view'); if ($role) { if ($role == 'admin') { $group->membershiptype = 'admin'; $group->requests = count_records('group_member_request', 'group', $group->id); } else { $group->membershiptype = 'member'; } $group->canleave = group_user_can_leave($group->id); } else { if ($group->jointype == 'invite' and $invite = get_record('group_member_invite', 'group', $group->id, 'member', $USER->get('id'))) { $group->membershiptype = 'invite'; $group->invite = group_get_accept_form('invite', $group->id, $afterjoin); } else { if ($group->jointype == 'request' and $request = get_record('group_member_request', 'group', $group->id, 'member', $USER->get('id'))) { $group->membershiptype = 'request'; } else { if ($group->jointype == 'open') { $group->groupjoin = group_get_join_form('joingroup', $group->id, $afterjoin); } } } } } $group->settingsdescription = group_display_settings($group); if (get_config('allowgroupcategories')) { $group->categorytitle = $group->category ? get_field('group_category', 'title', 'id', $group->category) : ''; } $filecounts = ArtefactTypeFileBase::count_user_files(null, $group->id, null); return array('group' => $group, 'filecounts' => $filecounts); }
* @author Catalyst IT Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later * @copyright For copyright information on Mahara, please see the README file distributed with this software. * */ define('INTERNAL', 1); define('MENUITEM', 'groups/groupsiown'); require dirname(dirname(__FILE__)) . '/init.php'; require_once 'pieforms/pieform.php'; require_once 'group.php'; require_once get_config('libroot') . 'antispam.php'; require_once 'embeddedimage.php'; if ($id = param_integer('id', null)) { define('TITLE', get_string('editgroup', 'group')); define('GROUP', $id); if (!group_user_access($id)) { $SESSION->add_error_msg(get_string('canteditdontown', 'group')); redirect('/group/mygroups.php'); } $group_data = group_get_groups_for_editing(array($id)); if (count($group_data) != 1) { throw new GroupNotFoundException(get_string('groupnotfound', 'group', $id)); } $group_data = $group_data[0]; // Fix dates to unix timestamps instead of formatted timestamps. $group_data->editwindowstart = isset($group_data->editwindowstart) ? strtotime($group_data->editwindowstart) : null; $group_data->editwindowend = isset($group_data->editwindowend) ? strtotime($group_data->editwindowend) : null; } else { define('TITLE', get_string('creategroup', 'group')); if (!group_can_create_groups()) { throw new AccessDeniedException(get_string('accessdenied', 'error'));
* */ define('INTERNAL', 1); define('MENUITEM', 'groups'); require dirname(dirname(__FILE__)) . '/init.php'; require_once 'pieforms/pieform.php'; require_once 'group.php'; $groupid = param_integer('id'); $userid = param_integer('user'); define('GROUP', $groupid); $group = group_current_group(); $user = get_record('usr', 'id', $userid, 'deleted', 0); if (!$user) { throw new UserNotFoundException(get_string('usernotfound', 'group', $userid)); } $role = group_user_access($groupid); if ($role != 'admin' && !group_user_can_assess_submitted_views($group->id, $USER->get('id'))) { if (!$group->invitefriends || !is_friend($user->id, $USER->get('id'))) { throw new AccessDeniedException(get_string('cannotinvitetogroup', 'group')); } } if (record_exists('group_member', 'group', $groupid, 'member', $userid) || record_exists('group_member_invite', 'group', $groupid, 'member', $userid)) { throw new UserException(get_string('useralreadyinvitedtogroup', 'group')); } define('TITLE', get_string('invitemembertogroup', 'group', display_name($userid), $group->name)); $roles = group_get_role_info($groupid); foreach ($roles as $k => &$v) { $v = $v->display; } safe_require('grouptype', $group->grouptype); $form = pieform(array('name' => 'invitetogroup', 'autofocus' => false, 'method' => 'post', 'elements' => array('reason' => array('type' => 'textarea', 'cols' => 50, 'rows' => 4, 'title' => get_string('reason')), 'role' => array('type' => 'select', 'options' => $roles, 'title' => get_string('Role', 'group'), 'defaultvalue' => call_static_method('GroupType' . $group->grouptype, 'default_role'), 'ignore' => $role != 'admin'), 'submit' => array('type' => 'submitcancel', 'value' => array(get_string('invite', 'group'), get_string('cancel')), 'goto' => profile_url($user)))));
define('SECTION_PLUGINNAME', 'view'); define('SECTION_PAGE', 'groupviews'); require dirname(dirname(__FILE__)) . '/init.php'; require_once get_config('libroot') . 'view.php'; require_once get_config('libroot') . 'group.php'; require_once 'pieforms/pieform.php'; //@todo: group menu; group sideblock $limit = param_integer('limit', 5); $offset = param_integer('offset', 0); define('GROUP', param_integer('group')); $group = group_current_group(); if (!is_logged_in() && !$group->public) { throw new AccessDeniedException(); } define('TITLE', $group->name . ' - ' . get_string('groupviews', 'view')); $member = group_user_access($group->id); $shared = param_boolean('shared', 0) && $member; $can_edit = group_user_can_edit_views($group->id); $smarty = smarty(); $smarty->assign('heading', $group->name); if ($can_edit) { $data = View::get_myviews_data($limit, $offset, $group->id); } else { $data = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, $offset); } $userid = $USER->get('id'); $pagination = build_pagination(array('url' => get_config('wwwroot') . 'view/groupviews.php?group=' . $group->id, 'count' => $data->count, 'limit' => $limit, 'offset' => $offset, 'resultcounttextsingular' => get_string('view', 'view'), 'resultcounttextplural' => get_string('views', 'view'))); $smarty->assign('groupviews', 1); $smarty->assign('member', $member); $smarty->assign('views', $data->data); $smarty->assign('pagination', $pagination['html']);
protected static function get_data($groupid, $editing = false) { global $USER; if (!defined('GROUP')) { define('GROUP', $groupid); } // get the currently requested group $group = group_current_group(); $role = group_user_access($group->id); $bi = group_get_homepage_view_groupview_block($group->id); $configdata = $bi->get('configdata'); if (!isset($configdata['sortsubmittedby']) || $configdata['sortsubmittedby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) { $sortsubmittedby = 'c.name, v.title'; } else { $sortsubmittedby = 'c.submittedtime DESC, v.submittedtime DESC'; } if ($role) { $limit = isset($configdata['count']) ? intval($configdata['count']) : 5; $limit = $limit > 0 ? $limit : 5; // Get all views created in the group // Sortorder: Group homepage should be first, then sort by sortorder $sort = array(array('column' => "type='grouphomepage'", 'desc' => true)); // Find out what order to sort them by (default is titles) if (!isset($configdata['sortgroupviewsby']) || $configdata['sortgroupviewsby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) { $sort[] = array('column' => 'title'); } else { $sort[] = array('column' => 'mtime', 'desc' => true); } $data['groupviews'] = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, 0, true, $sort); foreach ($data['groupviews']->data as &$view) { if (!$editing && isset($view['template']) && $view['template']) { $view['form'] = pieform(create_view_form(null, null, $view['id'])); } } // Find out what order to sort them by (default is titles) if (!isset($configdata['sortsharedviewsby']) || $configdata['sortsharedviewsby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) { $sortsharedviewsby = 'v.title'; $sortsharedcollectionsby = array(array('column' => 'c.name')); } else { $sortsharedviewsby = 'v.mtime DESC'; $sortsharedcollectionsby = array(array('column' => 'GREATEST(c.mtime, (SELECT MAX(v.mtime) FROM {view} v INNER JOIN {collection_view} cv ON v.id=cv.view WHERE cv.collection=c.id))', 'desc' => true)); } // For group members, display a list of views that others have // shared to the group if (empty($configdata['showsharedviews'])) { $data['sharedviews'] = (object) array('data' => array(), 'count' => 0, 'limit' => $limit, 'offset' => 0); } else { $data['sharedviews'] = View::get_sharedviews_data($limit, 0, $group->id, $configdata['showsharedviews'] == 2 ? false : true, $sortsharedviewsby); foreach ($data['sharedviews']->data as &$view) { if (!$editing && isset($view['template']) && $view['template']) { $view['form'] = pieform(create_view_form($group, null, $view->id)); } } } if (empty($configdata['showsharedcollections'])) { $data['sharedcollections'] = (object) array('data' => array(), 'count' => 0, 'limit' => $limit, 'offset' => 0); } else { $data['sharedcollections'] = View::get_sharedcollections_data($limit, 0, $group->id, $configdata['showsharedcollections'] == 2 ? false : true, $sortsharedcollectionsby); } if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) { // Display a list of views submitted to the group list($collections, $views) = View::get_views_and_collections(null, null, null, null, false, $group->id, $sortsubmittedby); $allsubmitted = array_merge(array_values($collections), array_values($views)); $data['allsubmitted'] = array('data' => array_slice($allsubmitted, 0, $limit), 'count' => count($allsubmitted), 'limit' => $limit, 'offset' => 0); } } if ($group->submittableto) { require_once 'pieforms/pieform.php'; // A user can submit more than one view to the same group, but no view can be // submitted to more than one group. // Display a list of views this user has submitted to this group, and a submission // form containing drop-down of their unsubmitted views. list($collections, $views) = View::get_views_and_collections($USER->get('id'), null, null, null, false, $group->id, $sortsubmittedby); $data['mysubmitted'] = array_merge(array_values($collections), array_values($views)); // Only render the submission form in viewing mode if (!$editing) { $data['group_view_submission_form'] = group_view_submission_form($group->id); } } $data['group'] = $group; return $data; }
* @author Catalyst IT Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ define('INTERNAL', 1); define('MENUITEM', 'groups'); require dirname(dirname(__FILE__)) . '/init.php'; require_once 'pieforms/pieform.php'; require 'group.php'; $groupid = param_integer('id'); $returnto = param_alpha('returnto', 'mygroups'); define('GROUP', $groupid); $group = group_current_group(); define('TITLE', $group->name); if (!group_user_access($group->id)) { throw new AccessDeniedException(get_string('notamember', 'group')); } if (!group_user_can_leave($group)) { throw new AccessDeniedException(get_string('cantleavegroup', 'group')); } $goto = get_config('wwwroot') . 'group/' . $returnto . '.php' . ($returnto == 'view' ? '?id=' . $groupid : ''); $views = count_records_sql('SELECT COUNT(*) FROM {view} v INNER JOIN {view_access_group} a ON a.group = ? AND a.view = v.id WHERE v.owner = ?', array($groupid, $USER->get('id'))); $form = pieform(array('name' => 'leavegroup', 'renderer' => 'div', 'autofocus' => false, 'method' => 'post', 'elements' => array('submit' => array('type' => 'submitcancel', 'value' => array(get_string('yes'), get_string('no')), 'goto' => $goto), 'returnto' => array('type' => 'hidden', 'value' => $returnto)))); $smarty = smarty(); $smarty->assign('subheading', get_string('leavespecifiedgroup', 'group', $group->name));
/** * Can a user access a given forum? * * @param int $forumid id of forum * @param int $userid optional id of user, defaults to logged in user * * @returns constant access level or false */ function user_can_access_forum($forumid, $userid = null) { if (empty($userid)) { global $USER; $userid = $USER->get('id'); } else { if (!is_int($userid)) { throw new InvalidArgumentException("non integer user id given to user_can_access_forum: {$userid}"); } } if (!is_int($forumid)) { throw new InvalidArgumentException("non integer forum id given to user_can_access_forum: {$forumid}"); } $membership = 0; $groupid = get_field('interaction_instance', '"group"', 'id', $forumid); $groupmembership = group_user_access((int) $groupid, (int) $userid); if (!$groupmembership) { return $membership; } $membership = $membership | INTERACTION_FORUM_MEMBER; if ($groupmembership == 'admin') { $membership = $membership | INTERACTION_FORUM_ADMIN | INTERACTION_FORUM_MOD; } if (record_exists('interaction_forum_moderator', 'forum', $forumid, 'user', $userid)) { $membership = $membership | INTERACTION_FORUM_MOD; } return $membership; }
/** * Indicates whether the user has permission to use the artefact in their own Pages. The name * refers to the "publish" permission for group files. * * If a user has "publish" permission on an artefact, it is assumed the also have "edit" and * "view" permission (i.e. can view it in the artefact chooser -- see $USER->can_view_artefact()) * * @param ArtefactType $a * @return boolean */ public function can_publish_artefact($a) { $parent = $a->get_parent_instance(); if ($parent) { if (!$this->can_view_artefact($parent)) { return false; } } if ($this->get('id') and $this->get('id') == $a->get('owner')) { return true; } if ($i = $a->get('institution')) { if ($i == 'mahara') { return $this->get('admin'); } return $this->in_institution($i) || $this->can_edit_institution($i); } if (!($group = $a->get('group'))) { return false; } require_once 'group.php'; if (!($role = group_user_access($group, $this->id))) { return false; } if ($role == 'admin') { return true; } if ($this->id == $a->get('author')) { return true; } return $a->role_has_permission($role, 'republish'); }
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz * */ define('PUBLIC', 1); define('INTERNAL', 1); define('JSON', 1); require dirname(dirname(__FILE__)) . '/init.php'; require_once 'group.php'; require_once 'searchlib.php'; $id = param_integer('id'); $query = trim(param_variable('query', '')); $offset = param_integer('offset', 0); $limit = param_integer('limit', 10); define('GROUP', $id); $group = group_current_group(); if (!is_logged_in() && !$group->public) { throw new AccessDeniedException(get_string('accessdenied', 'error')); } $membershiptype = param_variable('membershiptype', ''); if (!empty($membershiptype)) { if (group_user_access($id) != 'admin') { json_reply('local', get_string('accessdenied', 'error')); } } $results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype); if (!param_integer('html', 1)) { json_reply(false, $results); } list($html, $pagination, $count, $offset, $membershiptype) = group_get_membersearch_data($results, $id, $query, $membershiptype); json_reply(false, array('message' => null, 'data' => array('tablerows' => $html, 'pagination' => $pagination['html'], 'pagination_js' => $pagination['javascript'], 'count' => $count, 'results' => $count . ' ' . ($count == 1 ? get_string('result') : get_string('results')), 'offset' => $offset, 'membershiptype' => $membershiptype)));
function pieform_element_filebrowser_view_group_folder($group, $folder) { global $USER; if ($folder) { if (!$folder instanceof ArtefactTypeFolder) { $folder = new ArtefactTypeFolder($folder); } return $USER->can_view_artefact($folder); } require_once get_config('libroot') . 'group.php'; // Group root directory: use default grouptype artefact permissions if (!($role = group_user_access($group))) { return false; } $permissions = group_get_default_artefact_permissions($group); return $permissions[$role]->view; }
* @package mahara * @subpackage interaction * @author Catalyst IT Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ define('INTERNAL', 1); define('MENUITEM', 'groups'); require dirname(dirname(__FILE__)) . '/init.php'; require_once get_config('docroot') . 'interaction/lib.php'; require_once 'pieforms/pieform.php'; require_once 'group.php'; $id = param_integer('id'); $instance = interaction_instance_from_id($id); define('GROUP', $instance->get('group')); $group = group_current_group(); $membership = group_user_access((int) $group->id); if ($membership != 'admin') { throw new AccessDeniedException(get_string('notallowedtodeleteinteractions', 'group')); } define('TITLE', get_string('deleteinteraction', 'group', get_string('name', 'interaction.' . $instance->get('plugin')), $instance->get('title'))); // submit handler in interaction/lib.php $returnto = param_alpha('returnto', 'view'); $form = pieform(array('name' => 'delete_interaction', 'renderer' => 'div', 'elements' => array('id' => array('type' => 'hidden', 'value' => $id), 'submit' => array('type' => 'submitcancel', 'value' => array(get_string('yes'), get_string('no')), 'goto' => get_config('wwwroot') . 'interaction/' . $instance->get('plugin') . ($returnto == 'index' ? '/index.php?group=' . $instance->get('group') : '/view.php?id=' . $instance->get('id')))))); $smarty = smarty(array('tablerenderer')); $smarty->assign('form', $form); $smarty->assign('heading', $group->name); $smarty->assign('subheading', TITLE); $smarty->assign('message', get_string('deleteinteractionsure', 'group')); $smarty->display('interaction/delete.tpl');