function _on_execute() { debug_push_class(__CLASS__, __FUNCTION__); if (!$_MIDCOM->auth->request_sudo('fi.kilonkipinat.accountregistration')) { $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; } $time_for_old = date('Y-m-d 00:00', time() - 3600 * 24); $qb_resetrequests = fi_kilonkipinat_accountregistration_resetrequest_dba::new_query_builder(); $qb_resetrequests->add_constraint('metadata.revised', '<', $time_for_old); $qb_resetrequests->add_constraint('status', '=', FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_NEW); $results = $qb_resetrequests->execute(); foreach ($results as $result) { $result->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_INVALID; $result->update(); } $time_for_old = date('Y-m-d 00:00', time() - 3600 * 24 * 31); $qb_accounts = fi_kilonkipinat_accountregistration_accountrequest_dba::new_query_builder(); $qb_accounts->add_constraint('metadata.revised', '<', $time_for_old); $qb_accounts->add_constraint('status', '=', FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_NEW); $results2 = $qb_accounts->execute(); foreach ($results2 as $result) { $result->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_INVALID; $result->update(); } $_MIDCOM->auth->drop_sudo(); debug_pop(); }
function &dm2_create_callback(&$controller) { $this->_event = new fi_kilonkipinat_events_event_dba(); $this->_event->topic = $this->_request_data['content_topic']->id; if (!$this->_event->create()) { debug_push_class(__CLASS__, __FUNCTION__); debug_print_r('We operated on this object:', $this->_event); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to create a new event, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string()); // This will exit. } return $this->_event; }
function &dm2_create_callback(&$controller) { $this->_jobgroup = new fi_kilonkipinat_account_jobhistory_jobgroup_dba(); $this->_jobgroup->_use_activitystream = false; $this->_use_activitystream = false; if (!$this->_jobgroup->create()) { debug_push_class(__CLASS__, __FUNCTION__); debug_print_r('We operated on this object:', $this->_jobgroup); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to create a new jobgroup, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string()); // This will exit. } return $this->_jobgroup; }
/** * Set the content topic to use. This will check against the configuration setting 'symlink_topic'. * We don't do sanity checking here for performance reasons, it is done when accessing the topic, * that should be enough. * * @access protected */ function _determine_content_topic() { $guid = $this->_config->get('symlink_topic'); if (is_null($guid) || $guid == false) { // No symlink topic // Workaround, we should talk to a DBA object automatically here in fact. $this->_content_topic = new midcom_db_topic($this->_topic->id); debug_pop(); return; } $this->_content_topic = new midcom_db_topic($guid); if (!$this->_content_topic) { debug_push_class(__CLASS__, __FUNCTION__); debug_add('Failed to open symlink content topic, (might also be an invalid object) last Midgard Error: ' . midcom_application::get_error_string(), MIDCOM_LOG_ERROR); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Failed to open symlink content topic.'); // This will exit. } }
/** * 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; }
<div id="fi_kilonkipinat_events_locations"> <table class="tablesorter"> <thead> <tr> <th>Nimi</th> <th>Osoite</th> </tr> </thead> <tbody> <?php foreach ($locations as $location) { if (!$data['datamanager_location']->autoset_storage($location)) { debug_push_class(__CLASS__, __FUNCTION__); debug_add("The datamanager for location {$location->id} could not be initialized, skipping it."); debug_print_r('Object was:', $trip); debug_pop(); continue; } $view_location = $data['datamanager_location']->get_content_html(); ?> <tr> <td><a href="<?php echo $prefix . 'location/view/' . $location->guid; ?> "><?php echo $location->title; ?> </a></td> <td><span class="location">&(view_location['location']:h);</span></td> </tr> <?php
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 initialization event handler post-processes the maxlength setting. * * @return boolean Indicating Success */ function _on_initialize() { if (!array_key_exists('value', $this->_type) || is_array($this->_type->value) || is_object($this->_type->value)) { debug_push_class(__CLASS__, __FUNCTION__); debug_add("Warning, the field {$this->name} does not have a value member or it is an array or object, you cannot use the text widget with it.", MIDCOM_LOG_WARN); debug_pop(); return false; } if ($this->maxlength == -1) { if (array_key_exists('maxlength', $this->_type)) { $this->maxlength = $this->_type->maxlength; } } if ($this->maxlength < 0) { $this->maxlength = 0; } return true; }
/** * Object create callback * * @param mixed $handler_id The ID of the handler. */ function &dm2_create_callback(&$controller) { $this->_object = new fi_opengov_datacatalog_dataset_suggestion_dba(); if ($_MIDCOM->auth->request_sudo('fi.opengov.datacatalog')) { if (!$this->_object->create()) { debug_push_class(__CLASS__, __FUNCTION__); debug_print_r('We operated on this object:', $this->_object); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to create a new dataset suggestion, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string()); // This will exit. } } $_MIDCOM->auth->drop_sudo(); /** * in order to display this UI message to anonymous users * allow midcom:ajax in code_init_after_midcom */ $_MIDCOM->uimessages->add($_MIDCOM->i18n->get_string('thank_you', 'fi.opengov.datacatalog'), $_MIDCOM->i18n->get_string('suggestion_recorded_feedback', 'fi.opengov.datacatalog')); return $this->_object; }
/** * * @param mixed $handler_id The ID of the handler. * @param mixed &$data The local request data. */ function _show_upcoming($handler_id, &$data) { if ($handler_id == 'upcoming_trips') { midcom_show_style('trips-header'); foreach ($this->_events as $trip) { if (!$this->_request_data['datamanager']->autoset_storage($trip)) { debug_push_class(__CLASS__, __FUNCTION__); debug_add("The datamanager for trip {$trip->id} could not be initialized, skipping it."); debug_print_r('Object was:', $trip); debug_pop(); continue; } $this->_request_data['view_trip'] = $data['datamanager']->get_content_html(); $this->_request_data['trip'] = $trip; midcom_show_style('trips-item'); } midcom_show_style('trips-footer'); } else { midcom_show_style('meetings-header'); foreach ($this->_events as $meeting) { if (!$this->_request_data['datamanager']->autoset_storage($meeting)) { debug_push_class(__CLASS__, __FUNCTION__); debug_add("The datamanager for meeting {$meeting->id} could not be initialized, skipping it."); debug_print_r('Object was:', $trip); debug_pop(); continue; } $this->_request_data['view_meeting'] = $data['datamanager']->get_content_html(); $this->_request_data['meeting'] = $meeting; midcom_show_style('meetings-item'); } midcom_show_style('meetings-footer'); } }
/** * Object create callback * * @param mixed $handler_id The ID of the handler. */ function &dm2_create_callback(&$controller) { $this->_object = new fi_opengov_datacatalog_dataset_dba(); $this->_object->organization = array_pop($_POST['fi_opengov_datacatalog_organization_chooser_widget_selections']); $this->_object->license = array_pop($_POST['fi_opengov_datacatalog_license_chooser_widget_selections']); if (!$this->_object->create()) { debug_push_class(__CLASS__, __FUNCTION__); debug_print_r('We operated on this object:', $this->_object); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to create a new dataset, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string()); // This will exit. } /* if the dataset is created based on a suggestion then delete the suggestion */ if (isset($this->_defaults['suggestion'])) { $suggestion = new fi_opengov_datacatalog_dataset_suggestion_dba($this->_defaults['suggestion']); $suggestion->delete(); } return $this->_object; }
function &dm2_create_callback(&$controller) { $this->_todo = new fi_kilonkipinat_todos_todoitem_dba(); $this->_todo->topic = $this->_request_data['content_topic']->id; $this->_todo->status = FI_KILONKIPINAT_TODOS_TODOITEM_STATUS_NEW; if (!$this->_todo->create()) { debug_push_class(__CLASS__, __FUNCTION__); debug_print_r('We operated on this object:', $this->_todo); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to create a new todo, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string()); // This will exit. } return $this->_todo; }
/** * Prepares the imploded storage string. All entries containing the pipe char (used as glue) * will be logged and skipped silently. * * @return string The imploded data string. */ function _get_imploded_options() { $glue = $this->multiple_separator; if ($this->others) { if (is_string($this->others)) { $this->others = array($this->others => $this->others); } $options = array_merge($this->selection, $this->others); } else { $options = $this->selection; } $result = array(); foreach ($options as $key) { if (strpos($key, $glue) !== false) { debug_push_class(__CLASS__, __FUNCTION__); debug_add("The option key '{$key}' contained the multiple separator ({$this->multiple_separator}) char, which is not allowed for imploded storage targets. ignoring silently.", MIDCOM_LOG_WARN); debug_pop(); continue; } $result[] = $key; } return implode($glue, $result); }
/** * Object create callback * * @param mixed $handler_id The ID of the handler. */ function &dm2_create_callback(&$controller) { $this->_object = new fi_opengov_datacatalog_info_dba(); $this->_object->type = $this->_request_data['type']; if (!$this->_object->create()) { debug_push_class(__CLASS__, __FUNCTION__); debug_print_r('We operated on this object:', $this->_object); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to create a new info [' . $this->_request_data['type'] . '], cannot continue. Last Midgard error was: ' . midcom_application::get_error_string()); // This will exit. } return $this->_object; }