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(); }
/** * 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; }