/** * Locates the root group */ static function find_root_group($name = '__org_openpsa_contacts') { static $root_groups = array(); //Check if we have already initialized if (!empty($root_groups[$name])) { return $root_groups[$name]; } $qb = midcom_db_group::new_query_builder(); $qb->add_constraint('owner', '=', 0); $qb->add_constraint('name', '=', $name); $results = $qb->execute(); if (is_array($results) && count($results) > 0) { foreach ($results as $group) { $root_groups[$name] = $group; } } else { debug_add("OpenPSA Contacts root group could not be found", MIDCOM_LOG_WARN); //Attempt to auto-initialize the group. midcom::get('auth')->request_sudo(); $grp = new midcom_db_group(); $grp->owner = 0; $grp->name = $name; $grp->official = midcom::get('i18n')->get_l10n('org.openpsa.contacts')->get($name); $ret = $grp->create(); midcom::get('auth')->drop_sudo(); if (!$ret) { throw new midcom_error("Could not auto-initialize the module, group creation failed: " . midcom_connection::get_error_string()); } $root_groups[$name] = $grp; } return $root_groups[$name]; }
function list_groups($parent) { $str = ''; $qb_groups = midcom_db_group::new_query_builder(); $qb_groups->add_constraint('owner', '=', $parent); $groups = $qb_groups->execute(); if (count($groups) > 0) { $str = "<ul>\n"; foreach ($groups as $group) { $str .= "<li>"; $str .= '<input name="add_to_groups[' . $group->guid . ']" id="group_' . $group->guid . '" type="checkbox" value="' . $group->guid . '"> <label for="group_' . $group->guid . '">' . $group->official . '</label>'; $str .= "</li>\n"; $str .= list_groups($group->id); } $str .= "</ul>"; } return $str; }
function emailimport_find_group($email) { //TODO: find possible groups based on the persons email $qb = midcom_db_group::new_query_builder(); $qb->add_constraint('email', '=', $email); $results = $qb->execute(); if (!empty($results)) { //Exact matche(s) found, return first return $results[0]; } list($user, $domain) = explode('@', $email, 2); $qb = midcom_db_group::new_query_builder(); $qb->add_constraint('email', 'LIKE', "%@{$domain}"); $results = $qb->execute(); if (empty($results)) { return false; } //PONDER: What to return in case of multiple matches ?, now we always return first return $results[0]; }
/** * Generates, loads and prepares the schema database. * * The operations are done on all available schemas within the DB. */ public function load_schemadb() { $schemadb = midcom_helper_datamanager2_schema::load_database($this->_config->get('schemadb_permissions')); // Populate additional assignee selector $additional_assignees = array('' => '', 'EVERYONE' => $this->_l10n->get('EVERYONE'), 'USERS' => $this->_l10n->get('USERS'), 'ANONYMOUS' => $this->_l10n->get('ANONYMOUS')); // List groups as potential assignees $qb = midcom_db_group::new_query_builder(); $groups = $qb->execute(); foreach ($groups as $group) { $additional_assignees["group:{$group->guid}"] = $group->get_label(); } $assignees = array(); // Populate all resources having existing privileges $existing_privileges = $this->_object->get_privileges(); foreach ($existing_privileges as $privilege) { if ($privilege->is_magic_assignee()) { // This is a magic assignee $label = midcom::get('i18n')->get_string($privilege->assignee, 'midgard.admin.asgard'); } else { //Inconsistent privilige base will mess here. Let's give a chance to remove ghosts $assignee = midcom::get('auth')->get_assignee($privilege->assignee); if (is_object($assignee)) { $label = $assignee->name; } else { $label = midcom::get('i18n')->get_string('ghost assignee for ' . $privilege->assignee, 'midgard.admin.asgard'); } } $assignees[$privilege->assignee] = $label; $key = str_replace(':', '_', $privilege->assignee); if (!isset($this->_row_labels[$key])) { $this->_row_labels[$key] = $label; } // This one is already an assignee, remove from 'Add assignee' options if (array_key_exists($privilege->assignee, $additional_assignees)) { unset($additional_assignees[$privilege->assignee]); } } asort($additional_assignees); // Add the 'Add assignees' choices to schema $schemadb['privileges']->fields['add_assignee']['type_config']['options'] = $additional_assignees; $header = ''; $header_items = array(); foreach ($assignees as $assignee => $label) { foreach ($this->_privileges as $privilege) { $privilege_components = explode(':', $privilege); if ($privilege_components[0] == 'midcom' || $privilege_components[0] == 'midgard') { // This is one of the core privileges, we handle it $privilege_label = $privilege; } else { // This is a component-specific privilege, call component to localize it $privilege_label = midcom::get('i18n')->get_string("privilege {$privilege_components[1]}", $privilege_components[0]); } if (!isset($header_items[$privilege_label])) { $header_items[$privilege_label] = " <th scope=\"col\" class=\"{$privilege_components[1]}\"><span>" . str_replace(' ', "\n", midcom::get('i18n')->get_string($privilege_label, 'midgard.admin.asgard')) . "</span></th>\n"; } $schemadb['privileges']->append_field(str_replace(':', '_', $assignee) . '_' . str_replace(':', '_', str_replace('.', '_', $privilege)), array('title' => $privilege_label, 'helptext' => sprintf(midcom::get('i18n')->get_string('sets privilege %s', 'midgard.admin.asgard'), $privilege), 'storage' => null, 'type' => 'privilege', 'type_config' => array('privilege_name' => $privilege, 'assignee' => $assignee), 'widget' => 'privilegeselection')); } } $header .= " <th align=\"left\" scope=\"col\" class=\"assignee_name\"><span> </span></th>\n"; foreach ($header_items as $key => $item) { $header .= $item; } $header .= " <th scope=\"col\" class=\"row_actions\"><span> </span></th>\n"; $this->_header = $header; return $schemadb; }