/** * * * @param array $pa_group_ids * @param array $pa_options Supported options are: * user_id - if set, only user groups owned by the specified user_id will be added */ public function addACLUserGroups($pa_group_ids, $pa_options = null) { if (!($vn_id = (int) $this->getPrimaryKey())) { return null; } require_once __CA_MODELS_DIR__ . '/ca_acl.php'; $vn_table_num = $this->tableNum(); $vn_user_id = isset($pa_options['user_id']) && $pa_options['user_id'] ? $pa_options['user_id'] : null; $va_current_groups = $this->getACLUserGroups(); $t_acl = new ca_acl(); foreach ($pa_group_ids as $vn_group_id => $vn_access) { if ($vn_user_id) { // verify that group we're linking to is owned by the current user $t_group = new ca_user_groups($vn_group_id); if ($t_group->get('user_id') != $vn_user_id && $t_group->get('user_id')) { continue; } } $t_acl->clear(); $t_acl->load(array('group_id' => $vn_group_id, 'table_num' => $vn_table_num, 'row_id' => $vn_id)); // try to load existing record $t_acl->setMode(ACCESS_WRITE); $t_acl->set('table_num', $vn_table_num); $t_acl->set('row_id', $vn_id); $t_acl->set('group_id', $vn_group_id); $t_acl->set('access', $vn_access); if ($t_acl->getPrimaryKey()) { $t_acl->update(); } else { $t_acl->insert(); } if ($t_acl->numErrors()) { $this->errors = $t_acl->errors; return false; } } return true; }
/** * Determines whether current user is a member of the specified group. * * @access public * @param mixed $ps_group The group to test for the current user for membership in. Group may be specified by name, short name or id. * @return bool Returns true if user is a member of the group, false if not. */ public function inGroup($ps_group) { if (!($pn_user_id = $this->getPrimaryKey())) { return false; } $vb_got_group = 0; $t_group = new ca_user_groups(); if (is_numeric($ps_group)) { $vb_got_group = $t_group->load($ps_group); } if (!$vb_got_group) { if (!$t_group->load(array("name" => $ps_group))) { if (!$t_group->load(array("name_short" => $ps_group))) { return false; } } $vb_got_group = 1; } if ($vb_got_group) { $o_db = $this->getDb(); $qr_res = $o_db->query("\n\t\t\t\tSELECT relation_id \n\t\t\t\tFROM ca_users_x_groups\n\t\t\t\tWHERE\n\t\t\t\t\t(user_id = ?) AND\n\t\t\t\t\t(group_id = ?)\n\t\t\t", (int) $pn_user_id, (int) $t_group->getPrimaryKey()); if ($qr_res->nextRow()) { return true; } else { return false; } } else { $this->postError(945, _t("Group '%1' does not exist", $ps_group), "User->inGroup()"); return false; } }
public function getGroupsAsDOM() { $t_group = new ca_user_groups(); $vo_groups = $this->opo_dom->createElement("groups"); $qr_groups = $this->opo_db->query("SELECT * FROM ca_user_groups WHERE parent_id IS NOT NULL"); while ($qr_groups->nextRow()) { $t_group->load($qr_groups->get("group_id")); $vo_group = $this->opo_dom->createElement("group"); $vo_group->setAttribute("code", $this->makeIDNO($t_group->get("code"))); $vo_group->appendChild($this->opo_dom->createElement("name", caEscapeForXML($t_group->get("name")))); $vo_group->appendChild($this->opo_dom->createElement("description", caEscapeForXML($t_group->get("description")))); if (is_array($va_roles = $t_group->getGroupRoles())) { $vo_roles = $this->opo_dom->createElement("roles"); foreach ($va_roles as $va_role) { $vo_roles->appendChild($this->opo_dom->createElement("role", $this->makeIDNO($va_role["code"]))); } $vo_group->appendChild($vo_roles); } $vo_groups->appendChild($vo_group); } return $vo_groups; }
public function processGroups() { // Create root group $t_user_group = $this->opb_updating ? ca_user_groups::find(array('code' => 'Root', 'parent_id' => null), array('returnAs' => 'firstModelInstance')) : false; $t_user_group = $t_user_group ? $t_user_group : new ca_user_groups(); $t_user_group->setMode(ACCESS_WRITE); $t_user_group->set('name', 'Root'); if ($t_user_group->getPrimaryKey()) { $t_user_group->update(); } else { $t_user_group->set('code', 'Root'); $t_user_group->set('parent_id', null); $t_user_group->insert(); } if ($t_user_group->numErrors()) { $this->addError("Errors creating root user group 'Root': " . join("; ", $t_user_group->getErrors())); return false; } if ($this->ops_base_name) { // "merge" profile and its base $va_groups = array(); if ($this->opo_base->groups) { foreach ($this->opo_base->groups->children() as $vo_group) { $va_groups[self::getAttribute($vo_group, "code")] = $vo_group; } } if ($this->opo_profile->groups) { foreach ($this->opo_profile->groups->children() as $vo_group) { $va_groups[self::getAttribute($vo_group, "code")] = $vo_group; } } } else { if ($this->opo_profile->groups) { foreach ($this->opo_profile->groups->children() as $vo_group) { $va_groups[self::getAttribute($vo_group, "code")] = $vo_group; } } } if (is_array($va_groups)) { foreach ($va_groups as $vs_group_code => $vo_group) { $t_group = $this->opb_updating ? ca_user_groups::find(array('code' => $vs_group_code, 'parent_id' => null), array('returnAs' => 'firstModelInstance')) : false; $t_group = $t_group ? $t_group : new ca_user_groups(); $t_group->setMode(ACCESS_WRITE); $t_group->set('name', trim((string) $vo_group->name)); $t_group->set('description', trim((string) $vo_group->description)); if ($t_group->getPrimaryKey()) { $t_group->update(); } else { $t_group->set('code', $vs_group_code); $t_group->set('parent_id', null); $t_group->insert(); } $va_roles = array(); if ($vo_group->roles) { foreach ($vo_group->roles->children() as $vo_role) { $va_roles[] = trim((string) $vo_role); } } $t_group->addRoles($va_roles); if ($t_group->numErrors()) { $this->addError("Errors inserting user group {$vs_group_code}: " . join("; ", $t_group->getErrors())); return false; } } } return true; }
function joinGroup() { $t_user_group = new ca_user_groups(); $pn_group_id = $this->request->getParameter("group_id", pInteger); if ($pn_group_id) { if ($this->request->isLoggedIn()) { if (!$this->request->user->inGroup($pn_group_id)) { $this->request->user->addToGroups($pn_group_id); $this->request->session->setVar("join_user_group_id", ""); $vs_group_message = _t("You were added to the group"); } else { $this->request->session->setVar("join_user_group_id", ""); $vs_group_message = _t("You are already a member of the group"); } $this->notification->addNotification($vs_group_message, __NOTIFICATION_TYPE_INFO__); $this->response->setRedirect(caNavUrl($this->request, "", "Sets", "Index")); } else { $t_user_group->load($pn_group_id); $this->request->session->setVar("join_user_group_id", $pn_group_id); $this->view->setVar("message", _t("Login/Register to join \"%1\"", $t_user_group->get("name"))); $this->loginForm(); } } else { $this->view->setVar("message", _t("Invalid user group")); } }
/** * */ public function Info() { $o_dm = Datamodel::load(); $t_group = new ca_user_groups(); $this->view->setVar('group_count', $t_group->getGroupCount($this->request->user->getUserID())); if ($t_group = $this->getGroupObject()) { $this->view->setVar('t_item', $t_group); $this->view->setVar('result_context', $o_result_context = new ResultContext($this->request, 'ca_user_groups', 'basic_search')); } return $this->render('widget_group_info_html.php', true); }
function saveUserGroup() { if (!$this->request->isLoggedIn()) { $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'loginForm')); return; } global $g_ui_locale_id; // current locale_id for user $va_errors = array(); $o_purifier = new HTMLPurifier(); $t_user_group = new ca_user_groups(); if ($pn_group_id = $this->request->getParameter('group_id', pInteger)) { $t_user_group->load($pn_group_id); } # --- check for errors # --- group name - required $ps_name = $o_purifier->purify($this->request->getParameter('name', pString)); if (!$ps_name) { $va_errors["name"] = _t("Please enter the name of your user group"); } else { $this->view->setVar("name", $ps_name); } # --- user group description - optional $ps_description = $o_purifier->purify($this->request->getParameter('description', pString)); $this->view->setVar("description", $ps_description); if (sizeof($va_errors) == 0) { $t_user_group->setMode(ACCESS_WRITE); $t_user_group->set('name', $ps_name); $t_user_group->set('description', $ps_description); if ($t_user_group->get("group_id")) { $t_user_group->update(); } else { $t_user_group->set('user_id', $this->request->getUserID()); $t_user_group->set('code', 'lb_' . $this->request->getUserID() . '_' . time()); $t_user_group->insert(); if ($t_user_group->get("group_id")) { $t_user_group->addUsers($this->request->getUserID()); } } if ($t_user_group->numErrors()) { $va_errors["general"] = join("; ", $t_user_group->getErrors()); $this->view->setVar('errors', $va_errors); $this->userGroupForm(); } else { # --- add current user to group $this->view->setVar("message", _t('Saved user group.')); $this->render("Form/reload_html.php"); } } else { $this->view->setVar('errors', $va_errors); $this->userGroupForm(); } }
* WITHOUT ANY WARRANTIES whatsoever, including any implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * This source code is free and modifiable under the terms of * GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See * the "license.txt" file for details, or visit the CollectiveAccess web site at * http://www.CollectiveAccess.org * * @package CollectiveAccess * @subpackage theme/default * @license http://www.gnu.org/copyleft/gpl.html GNU Public License version 3 * * ---------------------------------------------------------------------- */ $va_user_groups = $this->getVar("user_groups"); $t_user_group = new ca_user_groups(); ?> <div id="caFormOverlay"><div class="pull-right pointer" onclick="caMediaPanel.hidePanel(); return false;"><span class="glyphicon glyphicon-remove-circle"></span></div> <H1><?php print _t("Your User Groups"); ?> </H1> <?php if (sizeof($va_user_groups)) { foreach ($va_user_groups as $va_user_group) { $t_user_group->load($va_user_group["group_id"]); print "<div><a href='#' onClick='\$(\"#userGroup" . $va_user_group["group_id"] . "\").slideToggle();'><div class='pull-right'><span class='glyphicon glyphicon-expand'></span></div>" . $va_user_group["name"] . "</a></div>"; print "<div id='userGroup" . $va_user_group["group_id"] . "' style='display:none; padding-left:20px;'>"; print '<dl>'; if ($va_user_group["description"]) { print "<dt>" . _t("Description") . "</dt><dd>" . $va_user_group["description"] . "</dd>";
} ?> </div><!-- end col-md-5 or 10 --> <div class="col-sm-2 col-md-3 col-lg-3 col-lg-offset-2"> <?php if (is_array($va_activity_stream) && sizeof($va_activity_stream)) { ?> <h2><?php print _t("activity stream"); ?> </h2> <div class="activitystream"> <?php $o_dm = new Datamodel(); $t_activity_set = new ca_sets(); $t_group = new ca_user_groups(); foreach ($va_activity_stream as $va_activity) { print "<div><small>"; print $va_activity["fname"] . " " . $va_activity["lname"] . " "; switch ($va_activity["logged_table_num"]) { case $o_dm->getTableNum("ca_set_items"): switch ($va_activity["changetype"]) { case "I": print _t("added an item to %1", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"]))); break; # ---------------------------------------- # ---------------------------------------- case "U": print _t("changed an item in %1", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"]))); break; # ----------------------------------------