/** * * * @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; }
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; }
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")); } }
private function getGroupObject($pb_set_view_vars = true, $pn_group_id = null) { if (!($t_group = $this->pt_group)) { if (!($vn_group_id = $this->request->getParameter('group_id', pInteger))) { $vn_group_id = $pn_group_id; } $t_group = new ca_user_groups($vn_group_id); } // Check if user actually owns the specified object if ($t_group->getPrimaryKey() && $t_group->get('user_id') != $this->request->user->getUserID()) { return false; } if ($pb_set_view_vars) { $this->view->setVar('group_id', $vn_group_id); $this->view->setVar('t_group', $t_group); } $this->pt_group = $t_group; return $t_group; }
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(); } }
break; # ---------------------------------------- # ---------------------------------------- case "D": print _t("removed and item from %1", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"]))); break; # ---------------------------------------- } break; # ---------------------------------------- # ---------------------------------------- case $o_dm->getTableNum("ca_sets_x_user_groups"): $t_group->load($va_activity["snapshot"]["group_id"]); switch ($va_activity["changetype"]) { case "I": print _t("shared %1 with %2", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"])), $t_group->get("name")); break; # ---------------------------------------- # ---------------------------------------- case "U": print _t("changed how they share %1 with %2", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"])), $t_group->get("name")); break; # ---------------------------------------- # ---------------------------------------- case "D": print _t("unshared %1 with %2", caNavLink($this->request, $va_activity["name"], "", "", "Sets", "setDetail", array("set_id" => $va_activity["set_id"])), $t_group->get("name")); break; # ---------------------------------------- } break; # ----------------------------------------