private function _count_membership_objects($gid, $pid) { $qb = midcom_db_member::new_query_builder(); $qb->add_constraint('gid', '=', $gid); $qb->add_constraint('uid', '=', $pid); return $qb->count(); }
/** * * @param mixed $handler_id The ID of the handler. * @param array &$data The local request data. */ public function _show_list($handler_id, array &$data) { if ($handler_id == 'mycontacts_xml') { $schemadb_person = midcom_helper_datamanager2_schema::load_database($this->_config->get('schemadb_person')); $datamanager = new midcom_helper_datamanager2_datamanager($schemadb_person); $xml = '<contacts></contacts>'; $simplexml = simplexml_load_string($xml); foreach ($data['mycontacts'] as $person) { $contact = $simplexml->addChild('contact'); $contact->addAttribute('guid', $person->guid); $datamanager->autoset_storage($person); $person_data = $datamanager->get_content_xml(); foreach ($person_data as $key => $value) { $contact->addChild($key, $value); } $mc = midcom_db_member::new_collector('uid', $person->id); $memberships = $mc->get_values('gid'); $qb = org_openpsa_contacts_group_dba::new_query_builder(); $qb->add_constraint('gid', 'IN', $memberships); $qb->add_constraint('orgOpenpsaObtype', '>', org_openpsa_contacts_list_dba::MYCONTACTS); $organisations = $qb->execute(); foreach ($organisations as $organisation) { $contact->addChild('company', str_replace('&', '&', ${$organisation}->get_label())); } } echo $simplexml->asXml(); } else { midcom_show_style("show-mycontacts-header"); foreach ($data['mycontacts'] as $person) { $data['person'] = $person; midcom_show_style("show-mycontacts-item"); } midcom_show_style("show-mycontacts-footer"); } }
public function testCRUD() { midcom::get('auth')->request_sudo('midcom.core'); $person = new midcom_db_person(); $stat = $person->create(); $this->assertTrue($stat); $this->register_object($person); $person = new midcom_db_person($person->guid); $this->assertEquals('person #' . $person->id, $person->name); $this->assertEquals('person #' . $person->id, $person->rname); $person->firstname = ' Firstname '; $person->lastname = ' Lastname '; $stat = $person->update(); $this->assertTrue($stat); $this->assertEquals('Firstname Lastname', $person->name); $this->assertEquals('Lastname, Firstname', $person->rname); $group = $this->create_object('midcom_db_group'); $attributes = array('gid' => $group->id, 'uid' => $person->id); $member = $this->create_object('midcom_db_member', $attributes); $stat = $person->delete(); $this->assertTrue($stat); $qb = midcom_db_member::new_query_builder(); $qb->add_constraint('id', '=', $member->id); $this->assertEquals(0, $qb->count()); midcom::get('auth')->drop_sudo(); }
public function list_members() { $mc = midcom_db_member::new_collector('gid', $this->id); $mc->add_order('uid.lastname'); $mc->add_order('uid.firstname'); return $mc->get_values('uid'); }
/** * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_action($handler_id, array $args, array &$data) { midcom::get('auth')->require_valid_user(); // Check if we get the group $data['group'] = new org_openpsa_contacts_group_dba($args[0]); // Check if the action is a valid one $data['action'] = $args[1]; switch ($args[1]) { case "update_member_title": // Ajax save handler $update_succeeded = false; $errstr = null; if (array_key_exists('member_title', $_POST) && is_array($_POST['member_title'])) { foreach ($_POST['member_title'] as $id => $title) { $update_succeeded = false; try { $member = new midcom_db_member($id); $member->require_do('midgard:update'); $member->extra = $title; $update_succeeded = $member->update(); } catch (midcom_error $e) { $e->log(); } $errstr = midcom_connection::get_error_string(); } } $response = new midcom_response_xml(); $response->result = $update_succeeded; $response->status = $errstr; return $response; case "members": // Group person listing, always work even if there are none $this->_view = "area_group_members"; break; case "subgroups": // Group person listing, always work even if there are none $this->_view = "area_group_subgroups"; break; default: throw new midcom_error('Unknown action ' . $args[1]); } }
function _send_notifications($method = 'updated') { $message = $this->_construct_message($method); $subscriptions = array(); $tmp_subscriptions = $this->list_parameters('fi.kilonkipinat.todos:subscribe'); if (!empty($subscriptions)) { //Go through each subscription foreach ($tmp_subscriptions as $user_guid => $subscription_time) { $subscriptions[$user_guid] = true; } } if ($this->person != 0 && $this->person != '') { $person = new fi_kilonkipinat_account_person_dba($this->person); if ($this->person == $person->id) { $subscriptions[$person->guid] = true; } } if ($this->supervisor != 0 && $this->supervisor != '') { $person = new fi_kilonkipinat_account_person_dba($this->supervisor); if ($this->supervisor == $person->id) { $subscriptions[$person->guid] = true; } } if ($this->grp != 0 && $this->grp != '') { $grp = new midcom_db_group($this->grp); if ($this->grp == $grp->id) { $mc = midcom_db_member::new_collector('sitegroup', $_MIDGARD['sitegroup']); $mc->add_constraint('gid', '=', $this->grp); $mc->add_value_property('uid'); $mc->execute(); $tmp_keys = $mc->list_keys(); foreach ($tmp_keys as $guid => $tmp_key) { $person = new fi_kilonkipinat_account_person_dba($mc->get_subkey($guid, 'uid')); if ($person->id != '' && $person->id != 0 && $person->guid != '') { $subscriptions[$person->guid] = true; } } } } if (isset($subscriptions[$_MIDCOM->auth->user->guid])) { $subscriptions[$_MIDCOM->auth->user->guid] = false; } if (count($subscriptions) > 0) { foreach ($subscriptions as $user_guid => $status) { if ($status) { // Send notice org_openpsa_notifications::notify('fi.kilonkipinat.todos:subscribe', $user_guid, $message); } } } }
/** * Loads and prepares the schema database. */ public function load_schemadb() { $schemadb = midcom_helper_datamanager2_schema::load_database($this->_config->get('schemadb_group')); $qb = midcom_db_member::new_query_builder(); $qb->add_constraint('gid', '=', $this->_group->id); if ($qb->count_unchecked() > $this->_config->get('list_users_max') && isset($schemadb['default']->fields['persons'])) { unset($schemadb['default']->fields['persons']); $field_order_key = array_search('persons', $schemadb['default']->field_order); if ($field_order_key !== false) { unset($schemadb['default']->field_order[$field_order_key]); } } unset($qb); return $schemadb; }
/** * Function for listing groups tasks contacts are members of * * @param org_openpsa_projects_task_dba &$task The task we're working with * @param string $mode By which property should groups be listed */ static function task_groups(&$task, $mode = 'id') { //TODO: Localize something for the empty choice ? $ret = array(0 => ''); $seen = array(); if (!midcom::get('componentloader')->load_graceful('org.openpsa.contacts')) { //PONDER: Maybe we should raise a fatal error ?? return $ret; } //Make sure the currently selected customer (if any) is listed if ($task->customer && !isset($ret[$task->customer])) { //Make sure we can read the current customer for the name midcom::get('auth')->request_sudo(); $company = new org_openpsa_contacts_group_dba($task->customer); midcom::get('auth')->drop_sudo(); $seen[$company->id] = true; self::task_groups_put($ret, $mode, $company); } $task->get_members(); if (!is_array($task->contacts) || count($task->contacts) == 0) { return $ret; } $mc = midcom_db_member::new_collector('metadata.deleted', false); $mc->add_constraint('uid', 'IN', array_keys($task->contacts)); /* Skip magic groups */ $mc->add_constraint('gid.name', 'NOT LIKE', '\\_\\_%'); $memberships = $mc->get_values('gid'); if (empty($memberships)) { return $ret; } foreach ($memberships as $gid) { if (isset($seen[$gid]) && $seen[$gid] == true) { continue; } try { $company = new org_openpsa_contacts_group_dba($gid); } catch (midcom_error $e) { continue; } $seen[$company->id] = true; self::task_groups_put($ret, $mode, $company); } reset($ret); asort($ret); return $ret; }
/** * The handler for the index article. * * @param mixed $handler_id the array key from the request array * @param array $args the arguments given to the handler * @param Array &$data The local request data. * @return boolean Indicating success. */ function _handler_index($handler_id, $args, &$data) { $this->_request_data['name'] = "fi.kilonkipinat.account"; $this->_update_breadcrumb_line($handler_id); $title = $this->_l10n_midcom->get('index'); $_MIDCOM->set_pagetitle(":: {$title}"); $root_group_guid = $this->_config->get('root_group_to_show'); $persons = array(); if (isset($root_group_guid) && $root_group_guid != null && $root_group_guid != '') { $root_group = new midcom_db_group($root_group_guid); if ($root_group && $root_group->guid == $root_group_guid) { $mc_members = midcom_db_member::new_collector('gid', $root_group->id); $mc_members->add_value_property('uid'); $mc_members->execute(); $member_guids = $mc_members->list_keys(); $member_ids = array(); foreach ($member_guids as $guid => $array) { $member_ids[] = $mc_members->get_subkey($guid, 'uid'); } $qb_persons = fi_kilonkipinat_account_person_dba::new_query_builder(); $qb_persons->add_constraint('id', 'IN', $member_ids); $qb_persons->add_order('lastname', 'ASC'); $qb_persons->add_order('nickname', 'ASC'); $qb_persons->add_order('firstname', 'ASC'); $persons = $qb_persons->execute(); } } $this->_request_data['requests'] = ''; if ($_MIDCOM->auth->admin) { $regs_topic = midcom_helper_find_node_by_component('fi.kilonkipinat.accountregistration'); $regs_prefix = ''; if ($regs_topic) { $regs_prefix = $regs_topic['18']; } $mc = fi_kilonkipinat_accountregistration_accountrequest_dba::new_collector('status', FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_EMAILVALIDATED); // $mc->add_constraint('status', '=', fi_kilonkipinat_accountregistration_interface::FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_EMAILVALIDATED); $requests_count = $mc->count(); if ($requests_count > 0 && $regs_prefix != '') { $this->_request_data['requests'] = '<a href="' . $regs_prefix . 'list_pending/">' . $requests_count . ' tunnushakemusta</a>'; } } $this->_request_data['persons'] = $persons; return true; }
private function _get_members_array() { if ($this->_members_loaded) { return $this->members; } $members = array(); $mc = midcom_db_member::new_collector('gid', $this->id); $uids = $mc->get_values('uid'); foreach ($uids as $uid) { $members[$uid] = true; } $this->_members_loaded = true; return $members; }
/** * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_group_memberships($handler_id, array $args, array &$data) { // Check if we get the person $data['person'] = new org_openpsa_contacts_person_dba($args[0]); $qb = midcom_db_member::new_query_builder(); $qb->add_constraint('uid', '=', $data['person']->id); $data['memberships'] = $qb->execute(); // Group person listing, always work even if there are none midcom::get()->skip_page_style = true; }
private function _populate_calendar_from_filter($user, $from, $to) { // New UI for showing resources foreach ($user->list_parameters('org.openpsa.calendar.filters') as $type => $value) { $selected = @unserialize($value); // Skip empty if (!$selected || empty($selected)) { continue; } // Include each type switch ($type) { case 'people': foreach ($selected as $guid) { $person = new midcom_db_person($guid); if (isset($this->_shown_persons[$person->id]) && $this->_shown_persons[$person->id] === true) { continue; } $this->_calendar->_resources[$person->guid] = $this->_populate_calendar_resource($person, $from, $to); $this->_shown_persons[$person->id] = true; } break; case 'groups': foreach ($selected as $guid) { // Get the group try { $group = new midcom_db_group($guid); } catch (midcom_error $e) { $e->log(); continue; } // Get the members $mc = midcom_db_member::new_collector('gid', $group->id); $mc->add_order('metadata.score', 'DESC'); $user_ids = $mc->get_values('uid'); foreach ($user_ids as $user_id) { if (isset($this->_shown_persons[$user_id]) && $this->_shown_persons[$user_id] === true) { continue; } $person = new midcom_db_person($user_id); $this->_calendar->_resources[$person->guid] = $this->_populate_calendar_resource($person, $from, $to); $this->_shown_persons[$person->id] = true; } } break; } } }
function _on_execute() { debug_push_class(__CLASS__, __FUNCTION__); if (!$_MIDCOM->auth->request_sudo('fi.kilonkipinat.emailmappings')) { $msg = "Could not get sudo, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } $email_group_guid = $this->_config->get('group_for_emails'); if ($email_group_guid == null) { // Email group not set in global config, we try to search for topic // $nap_topic = midcom_helper_find_node_by_component('fi.kilonkipinat.emailmappings'); // $topic = new midcom_db_topic($nap_topic[MIDCOM_NAV_GUID]); $qb = midcom_db_topic::new_query_builder(); $qb->add_constraint('component', '=', 'fi.kilonkipinat.emailmappings'); $qb->add_constraint('name', '<>', ''); $qb->set_limit(1); $topics = $qb->execute(); $topic = False; if (count($topics) > 0) { $topic = $topics[0]; } if ($topic && $topic->guid && $topic->guid != '') { $real_config = new midcom_helper_configuration($topic, 'fi.kilonkipinat.emailmappings'); $email_group_guid = $real_config->get('group_for_emails'); } else { $msg = "Could not find topic for config, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } $emails = array(); $usernames = array(); $file_content = ''; if ($email_group_guid != null) { $email_group = new midcom_db_group($email_group_guid); if ($email_group && $email_group->guid && $email_group->guid != '' && $email_group->guid == $email_group_guid) { $mc_members = midcom_db_member::new_collector('gid', $email_group->id); $mc_members->add_value_property('uid'); $mc_members->execute(); $member_keys = $mc_members->list_keys(); $person_ids = array(); foreach ($member_keys as $guid => $content) { $person_id = $mc_members->get_subkey($guid, 'uid'); $person_ids[] = $person_id; unset($person_id); } $mc_persons = fi_kilonkipinat_account_person_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']); if (count($person_ids) > 0) { $mc_persons->add_constraint('id', 'IN', $person_ids); } $mc_persons->add_constraint('username', '<>', ''); $mc_persons->add_constraint('email', '<>', ''); $mc_persons->add_constraint('email', 'LIKE', '%@%'); $mc_persons->add_value_property('username'); $mc_persons->add_value_property('email'); $mc_persons->execute(); $person_keys = $mc_persons->list_keys(); foreach ($person_keys as $guid => $content) { $person_username = $mc_persons->get_subkey($guid, 'username'); $person_email = $mc_persons->get_subkey($guid, 'email'); if (strstr($person_email, '@kilonkipinat.fi') || strstr($person_email, '@lists.kilonkipinat.fi')) { debug_add('illegal content in email-address for person guid ' . $guid . ', continuing to next person', MIDCOM_LOG_ERROR); continue; } if (isset($emails[$person_email]) || isset($usernames[$person_username])) { continue; } $emails[$person_email] = $person_email; $usernames[$person_username] = $person_username; $file_content .= "\n" . $person_username . ': ' . $person_email; } } else { $msg = "Could not instantiate group for emailmapping, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } else { $msg = "Could not find group for emailmapping, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } if ($file_content != '') { $file_content .= "\n\n"; $filename = '/root/mailaliases/aliases_automatic'; if (is_writable($filename)) { if (!file_put_contents($filename, $file_content)) { $msg = "Tried to write aliases file, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } else { $msg = "Couldn't write to aliases file, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } $file2_content = ''; $mc_mappings = fi_kilonkipinat_emailmappings_emailmapping_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']); $mc_mappings->add_value_property('name'); $mc_mappings->add_value_property('persons'); if (count($usernames) != 0) { $mc_mappings->add_constraint('name', 'NOT IN', $usernames); } $mc_mappings->execute(); $mapping_keys = $mc_mappings->list_keys(); foreach ($mapping_keys as $guid => $content) { $key = $mc_mappings->get_subkey($guid, 'name'); $person_guids = $mc_mappings->get_subkey($guid, 'persons'); $tmp_guids = explode('|', $person_guids); $guids = array(); foreach ($tmp_guids as $guid2) { $guids[] = trim(str_replace('|', '', $guid2)); } $persons_mc = fi_kilonkipinat_account_person_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']); $persons_mc->add_value_property('email'); if (count($guids) > 0) { $persons_mc->add_constraint('guid', 'IN', $guids); } $persons_mc->add_constraint('email', '<>', ''); $persons_mc->execute(); $persons_tmp = $persons_mc->list_keys(); $emails = ''; foreach ($persons_tmp as $guid3 => $content2) { $email = $persons_mc->get_subkey($guid3, 'email'); if ($emails != '') { $emails .= ', '; } $emails .= $email; } if (strlen($emails) > 3 && strstr($emails, "@")) { $file2_content .= "\n" . $key . ': ' . $emails; } } if ($file2_content != '') { $file2_content .= "\n\n"; $filename2 = '/root/mailaliases/aliases_mappings'; if (is_writable($filename2)) { if (!file_put_contents($filename2, $file2_content)) { $msg = "Tried to write aliases file 2, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } else { $msg = "Couldn't write to aliases file 2, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } $_MIDCOM->auth->drop_sudo(); debug_pop(); }
/** * Find out how a person prefers to get the event notification * * @param string $action Key of the event in format component:event * @param string $recipient GUID of the receiving person * @return Array options supported by user */ private static function _merge_notification_prefences($component, $action, $recipient) { // TODO: Should we sudo here to ensure getting correct prefs regardless of ACLs? $preference = 'none'; try { $recipient = new midcom_db_person($recipient); } catch (midcom_error $e) { return $preference; } // If user has preference for this message, we use that $personal_preferences = $recipient->list_parameters('org.openpsa.notifications'); if (count($personal_preferences) > 0 && array_key_exists("{$component}:{$action}", $personal_preferences)) { $preference = $personal_preferences[$action]; return $preference; } // Fall back to component defaults $customdata = midcom::get('componentloader')->get_all_manifest_customdata('org.openpsa.notifications'); if (!empty($customdata[$component][$action]['default'])) { $preference = $customdata[$component][$action]['default']; } // Seek possible preferences for this action from user's groups $qb = new midgard_query_builder('midgard_parameter'); $qb->add_constraint('domain', '=', 'org.openpsa.notifications'); $qb->add_constraint('name', '=', "{$component}:{$action}"); // Seek user's groups $member_qb = midcom_db_member::new_query_builder(); $member_qb->add_constraint('uid', '=', (int) $recipient->id); $memberships = $member_qb->execute(); $qb->begin_group('OR'); foreach ($memberships as $member) { $group = new midcom_db_group($member->gid); $qb->add_constraint('parentguid', '=', $group->guid); } $qb->end_group(); $group_preferences = $qb->execute(); if (count($group_preferences) > 0) { foreach ($group_preferences as $preference) { $preference = $preference->value; } } return $preference; }
/** * The handler for the index article. * * @param mixed $handler_id the array key from the request array * @param array $args the arguments given to the handler * @param Array &$data The local request data. * @return boolean Indicating success. */ function _handler_manageRequest($handler_id, $args, &$data) { $_MIDCOM->auth->require_admin_user(); $this->_request_data['name'] = "fi.kilonkipinat.accountregistration"; $this->_update_breadcrumb_line($handler_id); $title = $this->_l10n_midcom->get('fi.kilonkipinat.accountregistration'); $_MIDCOM->set_pagetitle(":: {$title}"); $prefix = $this->_request_data['prefix']; $request = new fi_kilonkipinat_accountregistration_accountrequest_dba(trim($args[0])); if (!isset($request) || !isset($request->guid) || $request->guid == '' || $request->guid != $args[0]) { debug_push_class(__CLASS__, __FUNCTION__); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to load request, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string()); // This will exit. } $this->_request_data['request'] = $request; if (isset($_POST) && isset($_POST['username'])) { if (isset($_POST['isduplicate']) && $_POST['isduplicate'] == '1') { $request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_INVALID; $request->update(); $message['title'] = $this->_l10n_midcom->get("Poistettu"); $message['content'] = $this->_l10n_midcom->get("Kyseinen hakemus on merkattu duplikaatiksi, ts poistettu."); } else { if (isset($_POST['merge_user_guid']) && $_POST['merge_user_guid'] != '') { $person = new fi_kilonkipinat_account_person_dba(trim($_POST['merge_user_guid'])); } else { $qb = fi_kilonkipinat_account_person_dba::new_query_builder(); $qb->add_constraint('username', '=', trim($_POST['username'])); $results = $qb->execute(); if (count($results) > 0) { $message['title'] = $this->_l10n_midcom->get("error"); $message['content'] = $this->_l10n_midcom->get("Kyseinen tyyppi on jo olemassa"); } else { $person = new fi_kilonkipinat_account_person_dba(); $person->username = trim($_POST['username']); $person->create(); } } if (isset($person)) { $person->firstname = $request->firstname; $person->lastname = $request->lastname; $person->email = $request->email; $password = fi_kilonkipinat_accountregistration_viewer::generatePassword($this->_config->get('password_length')); // Enforce crypt mode $salt = chr(rand(64, 126)) . chr(rand(64, 126)); $crypt_password = crypt($password, $salt); $person->password = $crypt_password; $person->update(); if (isset($_POST['add_to_groups']) && count($_POST['add_to_groups']) > 0) { foreach ($_POST['add_to_groups'] as $group_guid) { $group = new midcom_db_group($group_guid); if (isset($group) && isset($group->guid) && $group->guid == $group_guid) { $membership = new midcom_db_member(); $membership->uid = $person->id; $membership->gid = $group->id; $membership->create(); } } } $person->set_privilege('midgard:owner', "user:{$person->guid}"); $request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_RESOLVED; $request->personGuid = $person->guid; $request->update(); $subject = 'Tunnuksesi kilonkipinat.fi-sivustolle'; $body = sprintf('Hei %s', $person->firstname); $body .= "\n\n"; $body .= sprintf('käyttäjätunnus: %s', $person->username); $body .= "\n\n"; $body .= sprintf('salasana: %s', $password); $mail = new org_openpsa_mail(); $mail->from = $this->_config->get('mail_sender_title') . ' <' . $this->_config->get('mail_sender_address') . '>'; $mail->to = $person->firstname . ' ' . $person->lastname . ' <' . $person->email . '>'; $mail->body = $body; $mail->subject = $subject; $message = array(); if ($mail->send('mail')) { $message['title'] = $this->_l10n_midcom->get("Onnistui"); $message['content'] = ''; } else { $message['title'] = $this->_l10n_midcom->get("error"); $message['content'] = $this->_l10n_midcom->get("Oops, something went wrong."); } } } $this->_request_data['message'] = $message; } return true; }
/** * Support for contacts person merge */ function org_openpsa_contacts_duplicates_merge_person(&$person1, &$person2, $mode) { switch ($mode) { case 'all': break; case 'future': // Contacts does not have future references so we have nothing to transfer... return true; break; default: // Mode not implemented debug_add("mode {$mode} not implemented", MIDCOM_LOG_ERROR); return false; break; } $qb = midcom_db_member::new_query_builder(); $qb->begin_group('OR'); // We need the remaining persons memberships later when we compare the two $qb->add_constraint('uid', '=', $person1->id); $qb->add_constraint('uid', '=', $person2->id); $qb->end_group(); $members = $qb->execute(); if ($members === false) { // Some error with QB debug_add('QB Error', MIDCOM_LOG_ERROR); return false; } // Transfer memberships $membership_map = array(); foreach ($members as $member) { if ($member->uid != $person1->id) { debug_add("Transferred membership #{$member->id} to person #{$person1->id} (from #{$member->uid})"); $member->uid = $person1->id; } if (!isset($membership_map[$member->gid]) || !is_array($membership_map[$member->gid])) { $membership_map[$member->gid] = array(); } $membership_map[$member->gid][] = $member; } unset($members); // Merge memberships foreach ($membership_map as $members) { foreach ($members as $member) { if (count($members) == 1) { // We only have one membership in this group, skip rest of the logic if (!$member->update()) { // Failure updating member debug_add("Failed to update member #{$member->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } continue; } // TODO: Compare memberships to determine which of them are identical and thus not worth keeping if (!$member->update()) { // Failure updating member debug_add("Failed to update member #{$member->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } } } // Transfer metadata dependencies from classes that we drive $classes = array('midcom_db_member', 'org_openpsa_contacts_person_dba', 'org_openpsa_contacts_group_dba'); $metadata_fields = array('creator' => 'guid', 'revisor' => 'guid'); foreach ($classes as $class) { $ret = org_openpsa_contacts_duplicates_merge::person_metadata_dependencies_helper($class, $person1, $person2, $metadata_fields); if (!$ret) { // Failure updating metadata debug_add("Failed to update metadata dependencies in class {$class}, errsrtr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } } // Copy fields missing from person1 and present in person2 over $skip_properties = array('id' => true, 'guid' => true); $changed = false; foreach ($person2 as $property => $value) { // Copy only simple properties not marked to be skipped missing from person1 if (empty($person2->{$property}) || !empty($person1->{$property}) || isset($skip_properties[$property]) || is_array($value) || is_object($value)) { continue; } $person1->{$property} = $value; $changed = true; } // Avoid unnecessary updates if ($changed) { if (!$person1->update()) { // Error updating person debug_add("Error updating person #{$person1->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } } // PONDER: sensible way to do the same for parameters ?? return true; }
private function _batch_process() { foreach ($_POST['midcom_admin_user'] as $person_id) { try { if (is_numeric($person_id)) { $person = new midcom_db_person((int) $person_id); } else { $person = new midcom_db_person($person_id); } } catch (midcom_error $e) { continue; } switch ($_POST['midcom_admin_user_action']) { case 'removeaccount': if (!$this->_config->get('allow_manage_accounts')) { break; } $person->parameter('midcom.admin.user', 'username', $person->username); $person->username = ''; $person->password = ''; if ($person->update()) { midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('user account revoked for %s'), $person->name)); } break; case 'groupadd': if (isset($_POST['midcom_admin_user_group'])) { $member = new midcom_db_member(); $member->uid = $person->id; $member->gid = (int) $_POST['midcom_admin_user_group']; if ($member->create()) { midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('user %s added to group'), $person->name)); } } break; } } }
/></td> <?php $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX); $linked = 0; foreach ($data['list_fields'] as $field) { $value = $data['person']->{$field}; if ($linked < 2 && $data['person']->can_do('midgard:update')) { if (!$value) { $value = "<{$field}>"; } $value = "<a href=\"{$prefix}__mfa/asgard_midcom.admin.user/edit/{$data['person']->guid}/\">{$value}</a>"; $linked++; } echo "<td>{$value}</td>\n"; } $qb = midcom_db_member::new_query_builder(); $qb->add_constraint('uid', '=', $data['person']->id); $memberships = $qb->execute(); $groups = array(); foreach ($memberships as $member) { // Quick and dirty on-demand group-loading if ($member->gid != 0 && (!isset($data['groups'][$member->gid]) || !is_object($data['groups'][$member->gid]))) { $data['groups'][$member->gid] = new midcom_db_group((int) $member->gid); } if (!isset($data['groups'][$member->gid]) || !is_object($data['groups'][$member->gid])) { if ($member->gid == 0) { $groups[] = 'Midgard Administrators'; } else { $groups[] = "#{$member->gid}"; } continue;
/** * Checks whether the given user is a member of this group. * * @param midcom_db_person The person to check. * @return boolean Indicating membership. */ function is_member($person) { $qb = midcom_db_member::new_query_builder(); $qb->add_constraint('gid', '=', $this->id); $qb->add_constraint('uid', '=', $person->id); $result = $qb->count(); if ($result == 0) { return false; } return true; }
private function _process_member($member) { $adder = array(); $adder['campaign_member'] = $member; try { $adder['person'] = org_openpsa_contacts_person_dba::get_cached($member->person); } catch (midcom_error $e) { $e->log(); return false; } $qb_memberships = midcom_db_member::new_query_builder(); $qb_memberships->add_constraint('uid', '=', $member->person); $memberships = $qb_memberships->execute_unchecked(); if (!is_array($memberships) || count($memberships) == 0) { return $adder; } switch ($this->membership_mode) { case 'all': foreach ($memberships as $k2 => $membership) { $adder['organization_member'] = $membership; try { $adder['organization'] = org_openpsa_contacts_group_dba::get_cached($membership->gid); } catch (midcom_error $e) { debug_add("Error fetching org_openpsa_contacts_group_dba #{$membership->gid}, skipping", MIDCOM_LOG_WARN); return false; } return $adder; } break; default: // Fall-trough intentional // Fall-trough intentional case 'first': // Fall-trough intentional // Fall-trough intentional case 'last': foreach ($memberships as $k2 => $membership) { $adder['organization_member'] = $membership; try { $adder['organization'] = org_openpsa_contacts_group_dba::get_cached($membership->gid); } catch (midcom_error $e) { debug_add("Error fetching org_openpsa_contacts_group_dba #{$membership->gid}, skipping", MIDCOM_LOG_WARN); return false; } // Get only first or last membership if ($this->membership_mode != 'last') { break; } } return $adder; break; } }
echo "</td>"; echo "\t\t</tr>"; } echo "</table>"; echo '<a href="' . $prefix . 'list/my/">Näytä kaikki</a>'; } else { echo "<p>Ei nakkeja</p>"; } ?> </div> </div> <div class="fi_kilonkipinat_website_toggler_container"> <?php $my_groups = array(); $mc_my_groups = midcom_db_member::new_collector('sitegroup', $_MIDGARD['sitegroup']); $mc_my_groups->add_constraint('uid', '=', $_MIDGARD['user']); $mc_my_groups->add_value_property('gid'); $mc_my_groups->execute(); $tmp_keys = $mc_my_groups->list_keys(); foreach ($tmp_keys as $guid => $tmp_key) { $group_id = $mc_my_groups->get_subkey($guid, 'gid'); $my_groups[$group_id] = $group_id; } $qb_my_groups = fi_kilonkipinat_todos_todoitem_dba::new_query_builder(); $qb_my_groups->add_constraint('grp', 'IN', $my_groups); $qb_my_groups->add_constraint('grp', '<>', 0); $qb_my_groups->add_order('deadline', 'ASC'); $qb_my_groups->add_constraint('status', '<', FI_KILONKIPINAT_TODOS_TODOITEM_STATUS_RESOLVED); $my_groups_count = $qb_my_groups->count(); $qb_my_groups->set_limit(5);
function isInMyGroups($grp_id) { $mc = midcom_db_member::new_collector('uid', $_MIDGARD['user']); $mc->add_constraint('gid', '=', $grp_id); if ($mc->count() > 0) { return true; } else { return false; } }
/** * Get querybuilder for JSON user list */ public function get_qb($field = null, $direction = 'ASC') { $qb = midcom_db_person::new_collector('metadata.deleted', false); //@todo constraint username <> '' ? if ($this->_group) { $mc = midcom_db_member::new_collector('gid', $this->_group->id); $members = $mc->get_values('uid'); if (empty($members)) { $qb->add_constraint('id', '=', 0); } else { $qb->add_constraint('id', 'IN', $members); } } if (!is_null($field)) { if ($field == 'username') { midcom_core_account::add_username_order($qb, $direction); } else { $qb->add_order($field, $direction); } } $qb->add_order('lastname'); $qb->add_order('firstname'); $qb->add_order('id'); return $qb; }
/** * Adds a user to a given Midgard Group. Caller must ensure access permissions * are right. * * @param string $name The name of the group we should be added to. * @return boolean Indicating success. * * @todo Check if user is already assigned to the group. */ function add_to_group($name) { $group = midcom::get('auth')->get_midgard_group_by_name($name); if (!$group) { debug_add("Failed to add the person {$this->id} to group {$name}, the group does not exist.", MIDCOM_LOG_WARN); return false; } $storage = $group->get_storage(); $member = new midcom_db_member(); $member->uid = $this->id; $member->gid = $storage->id; if (!$member->create()) { debug_add("Failed to add the person {$this->id} to group {$name}, object could not be created.", MIDCOM_LOG_WARN); debug_add('Last Midgard error was: ' . midcom_connection::get_error_string(), MIDCOM_LOG_WARN); debug_print_r('Tried to create this object:', $member); return false; } return true; }
/** * Calculates P for the given two persons being duplicates * @param array person1 * @param array person2 * @return array with overall P and matched checks */ function p_duplicate_person($person1, $person2) { $ret['p'] = 0; //TODO: read weight values from configuration $ret['email_match'] = false; if (!empty($person1['email']) && $person1['email'] == $person2['email']) { $ret['email_match'] = true; $ret['p'] += 1; } $ret['handphone_match'] = false; if (!empty($person1['handphone']) && $person1['handphone'] == $person2['handphone']) { $ret['handphone_match'] = true; $ret['p'] += 1; } $ret['fname_lname_city_match'] = false; if (!empty($person1['firstname']) && !empty($person1['lastname']) && !empty($person1['city']) && $person1['firstname'] == $person2['firstname'] && $person1['lastname'] == $person2['lastname'] && $person1['city'] == $person2['city']) { $ret['fname_lname_city_match'] = true; $ret['p'] += 0.5; } $ret['fname_lname_street_match'] = false; if (!empty($person1['firstname']) && !empty($person1['lastname']) && !empty($person1['street']) && $person1['firstname'] == $person2['firstname'] && $person1['lastname'] == $person2['lastname'] && $person1['street'] == $person2['street']) { $ret['fname_lname_street_match'] = true; $ret['p'] += 0.9; } $ret['fname_hphone_match'] = false; if (!empty($person1['firstname']) && !empty($person1['homephone']) && $person1['firstname'] == $person2['firstname'] && $person1['homephone'] == $person2['homephone']) { $ret['fname_hphone_match'] = true; $ret['p'] += 0.7; } $ret['fname_lname_company_match'] = false; // We cannot do this check if person1 hasn't been created yet... if (empty($person1['guid'])) { return $ret; } // Get membership maps if (!isset($this->_membership_cache[$person1['guid']]) || !is_array($this->_membership_cache[$person1['guid']])) { $this->_membership_cache[$person1['guid']] = array(); $mc = midcom_db_member::new_collector('uid', $person1['id']); $memberships = $mc->get_values('gid'); foreach ($memberships as $member) { $this->_membership_cache[$person1['guid']][$member] = $member; } } $person1_memberships =& $this->_membership_cache[$person1['guid']]; if (!isset($this->_membership_cache[$person2['guid']]) || !is_array($this->_membership_cache[$person2['guid']])) { $this->_membership_cache[$person2['guid']] = array(); $mc = midcom_db_member::new_collector('uid', $person2['id']); $memberships = $mc->get_values('gid'); foreach ($memberships as $member) { $this->_membership_cache[$person2['guid']][$member] = $member; } } $person2_memberships =& $this->_membership_cache[$person2['guid']]; foreach ($person1_memberships as $gid) { if (isset($person2_memberships[$gid]) && !empty($person2_memberships[$gid])) { $ret['fname_lname_company_match'] = true; $ret['p'] += 0.5; break; } } // All checks done, return return $ret; }
private function _import_subscribers_organization_member($subscriber, $person, $organization) { // Check if person is already in organization $member = null; $qb = midcom_db_member::new_query_builder(); $qb->add_constraint('uid', '=', $person->id); $qb->add_constraint('gid', '=', $organization->id); $members = $qb->execute_unchecked(); if (count($members) > 0) { // Match found, use it // Use first match $member = $members[0]; } if (!$member) { // We didn't have person matching the email in DB. Create a new one. $member = new midcom_db_member(); $member->uid = $person->id; $member->gid = $organization->id; if (!$member->create()) { $this->_request_data['new_objects']['organization_member'] =& $member; debug_add("Failed to create organization member, reason " . midcom_connection::get_error_string()); return false; } } if (!$this->_datamanager_process('organization_member', $subscriber, $member)) { return false; } return $member; }
private function _populate_schema_contacts_for_customer(&$customer) { $fields =& $this->_schemadb['default']->fields; // We know the customer company, present contact as a select widget $persons_array = array(); $member_mc = midcom_db_member::new_collector('gid', $customer->id); $members = $member_mc->get_values('uid'); foreach ($members as $member) { try { $person = org_openpsa_contacts_person_dba::get_cached($member); $persons_array[$person->id] = $person->rname; } catch (midcom_error $e) { } } asort($persons_array); $fields['customerContact']['widget'] = 'select'; $fields['customerContact']['type_config']['options'] = $persons_array; // And display the organization too $organization_array = array(); $organization_array[$customer->id] = $customer->official; $fields['customer']['widget'] = 'select'; $fields['customer']['type_config']['options'] = $organization_array; }
$username = str_replace('Ö', 'o', $username); $username = str_replace('Å', 'a', $username); $username = str_replace('å', 'a', $username); $person->username = $username; // Generate a random password and activation Hash $password = '******'; $length = 8; // Create a random password for ($i = 0; $i < $length; $i++) { $password .= chr(rand(97, 122)); } $person->password = $password; $person->create(); $group = new midcom_db_group(); $group->get_by_path('/kkp_admins/editoijat'); $member = new midcom_db_member(); $member->uid = $person->id; $member->gid = $group->id; $member->create(); $mail = new org_openpsa_mail(); $mail->from = '*****@*****.**'; $mail->subject = '[KKp-web] Tunnukset sivustolle'; $mail->body = "Hei\n\nTunnus: " . $username; $mail->body .= "\nSalasana: " . str_replace('**', '', $password); $mail->to = $person->email; $mail->send(); $status = 'Tunnukset lähetetty.'; } } $_MIDCOM->auth->drop_sudo(); }
/** * The handler for the index article. * * @param mixed $handler_id the array key from the request array * @param array $args the arguments given to the handler * @param Array &$data The local request data. * @return boolean Indicating success. */ function _handler_all($handler_id, $args, &$data) { $_MIDCOM->auth->require_valid_user(); $this->_request_data['name'] = "fi.kilonkipinat.todos"; $this->_component_data['active_leaf'] = "{$this->_topic->id}_LIST_ALL"; $this->_update_breadcrumb_line($handler_id); $title = 'Nakit'; $_MIDCOM->set_pagetitle(":: {$title}"); $qb = new org_openpsa_qbpager('fi_kilonkipinat_todos_todoitem_dba', 'fi_kilonkipinat_todos_list_my'); $data['qb'] = $qb; $data['filters'] = fi_kilonkipinat_todos_viewer::prepare_todoitem_qb($data, $this->_config); $data['qb']->begin_group('OR'); $data['qb']->add_constraint('visibility', '=', FI_KILONKIPINAT_TODOS_TODOITEM_VISIBILITY_PUBLIC); $data['qb']->add_constraint('person', '=', $_MIDGARD['user']); $data['qb']->add_constraint('supervisor', '=', $_MIDGARD['user']); $data['qb']->end_group(); $data['qb']->add_order('status'); $data['qb']->add_order('deadline'); if ($handler_id == 'list_all_count') { $data['qb']->results_per_page = $args[0]; } elseif (isset($data['filters']['filter_limit'])) { $data['qb']->results_per_page = (int) $data['filters']['filter_limit']; } else { $data['qb']->results_per_page = $this->_config->get('index_entries'); } $data['todoitems'] = $data['qb']->execute(); $data['handler_id'] = $handler_id; $persons = array(); $root_group = new midcom_db_group($this->_config->get('root_group_to_show')); $person_ids = array(); $mc_groups = midcom_db_member::new_collector('sitegroup', $_MIDGARD['sitegroup']); $mc_groups->add_constraint('gid', '=', $root_group->id); $mc_groups->add_value_property('uid'); $mc_groups->execute(); $tmp_keys = $mc_groups->list_keys(); foreach ($tmp_keys as $guid => $tmp_key) { $person_id = $mc_groups->get_subkey($guid, 'uid'); $person_ids[$person_id] = $person_id; } $mc_persons = fi_kilonkipinat_account_person_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']); $mc_persons->add_constraint('id', 'IN', $person_ids); $mc_persons->add_value_property('id'); $mc_persons->add_value_property('nickname'); $mc_persons->add_value_property('firstname'); $mc_persons->add_value_property('lastname'); $mc_persons->execute(); $tmp_persons = $mc_persons->list_keys(); foreach ($tmp_persons as $guid => $tmp_key) { $persons[] = array('id' => $mc_persons->get_subkey($guid, 'id'), 'nickname' => $mc_persons->get_subkey($guid, 'nickname'), 'firstname' => $mc_persons->get_subkey($guid, 'firstname'), 'lastname' => $mc_persons->get_subkey($guid, 'lastname')); } $data['persons'] = $persons; return true; }