private function _update_watchers() { $watchers = $this->list_watchers(); if (empty($watchers)) { return; } $diff = $this->_get_diff(); if (empty($diff)) { // No sense to email empty diffs return; } // Construct the message $message = array(); $user_string = midcom::get('i18n')->get_string('anonymous', 'net.nemein.wiki'); if (midcom::get('auth')->user) { $user = midcom::get('auth')->user->get_storage(); $user_string = $user->name; } // Title for long notifications $message['title'] = sprintf(midcom::get('i18n')->get_string('page %s has been updated by %s', 'net.nemein.wiki'), $this->title, $user_string); // Content for long notifications $message['content'] = "{$message['title']}\n\n"; // TODO: Get RCS diff here $message['content'] .= midcom::get('i18n')->get_string('page modifications', 'net.nemein.wiki') . ":\n"; $message['content'] .= "\n{$diff}\n\n"; $message['content'] .= midcom::get('i18n')->get_string('link to page', 'net.nemein.wiki') . ":\n"; $message['content'] .= midcom::get('permalinks')->create_permalink($this->guid); // Content for short notifications $topic = new midcom_db_topic($this->topic); $message['abstract'] = sprintf(midcom::get('i18n')->get_string('page %s has been updated by %s in wiki %s', 'net.nemein.wiki'), $this->title, $user_string, $topic->extra); debug_add("Processing list of Wiki subscribers"); // Send the message out foreach ($watchers as $recipient) { debug_add("Notifying {$recipient}..."); org_openpsa_notifications::notify('net.nemein.wiki:page_updated', $recipient, $message); } }
private function _report_abuse($data) { // Report the abuse $moderators = $this->_config->get('moderators'); if ($this->_comment->report_abuse() && $moderators) { // Prepare notification message $message = array(); $message['title'] = sprintf($data['l10n']->get('comment %s reported as abuse'), $this->_comment->title); $message['content'] = ''; $logs = $this->_comment->get_logs(); if (count($logs) > 0) { $message['content'] .= $data['l10n']->get('moderation history') . ":\n\n"; foreach ($logs as $time => $log) { $reported = strftime('%x %X', strtotime("{$time}Z")); $message['content'] .= $data['l10n']->get(sprintf('%s: %s by %s (from %s)', "{$reported}:\n", $data['l10n']->get($log['action']), $log['reporter'], $log['ip'])) . "\n\n"; } } $message['content'] = "\n\n" . midcom::get('permalinks')->create_permalink($this->_comment->objectguid); $message['abstract'] = sprintf($data['l10n']->get('comment %s reported as abuse'), $this->_comment->title); $message['abstract'] = " " . midcom::get('permalinks')->create_permalink($this->_comment->objectguid); // Notify moderators $moderator_guids = explode('|', $moderators); foreach ($moderator_guids as $moderator_guid) { if (empty($moderator_guid)) { continue; } org_openpsa_notifications::notify('net.nehmer.comments:report_abuse', $moderator_guid, $message); } } }
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); } } } }
private function _send_notifications() { //Get the parent object try { $parent = midcom::get('dbfactory')->get_object_by_guid($this->objectguid); } catch (midcom_error $e) { $e->log(); return false; } if (empty($this->title) && empty($this->content)) { // No need to send notifications about empty rating entries return false; } // Construct the message $message = $this->_construct_message(); $authors = explode('|', substr($parent->metadata->authors, 1, -1)); if (empty($authors)) { // Fall back to original creator if authors are not set for some reason $authors = array(); $authors[] = $parent->metadata->creator; } if (!empty($authors)) { //Go through all the authors foreach ($authors as $author) { // Send the notification to each author of the original document org_openpsa_notifications::notify('net.nehmer.comments:comment_posted', $author, $message); } } //Get all the subscriptions $subscriptions = $parent->list_parameters('net.nehmer.comments:subscription'); if (!empty($subscriptions)) { //Go through each subscription foreach ($subscriptions as $user_guid => $subscription_time) { // Send notice org_openpsa_notifications::notify('net.nehmer.comments:subscription', $user_guid, $message); } } }
public function load_schemadb() { $notifier = new org_openpsa_notifications(); return $notifier->load_schemadb(); }
function notify($type = 'update', $event = false, $nl = "\n") { $l10n = midcom::get('i18n')->get_l10n('org.openpsa.calendar'); $recipient = $this->get_person_obj(); if (!$recipient) { debug_add('recipient could not be gotten, aborting', MIDCOM_LOG_WARN); return false; } //In general we should have the event passed to us since we might be notifying about changes that have not been committed yet if (!$event) { $event = $this->get_event_obj(); } if ($recipient->id == midcom_connection::get_user() && !$event->send_notify_me) { //Do not send notification to current user debug_add('event->send_notify_me is false and recipient is current user, aborting notify'); return false; } $message = array(); $action = 'org.openpsa.calendar:noevent'; switch ($type) { //Event information was updated case 'update': //PONDER: This in theory should have the old event title $action = 'org.openpsa.calendar:event_update'; $message['title'] = sprintf($l10n->get('event "%s" was updated'), $event->title); $message['abstract'] = sprintf($l10n->get('event "%s" (%s) was updated'), $event->title, $event->format_timeframe()); $message['content'] = sprintf($l10n->get('event "%s" was modified, updated information below.') . "{$nl}{$nl}", $event->title); $message['content'] .= $event->details_text(false, $this, $nl); break; //Participant was added to the event //Participant was added to the event case 'add': $action = 'org.openpsa.calendar:event_add'; $message['title'] = sprintf($l10n->get('you have been added to event "%s"'), $event->title); $message['abstract'] = sprintf($l10n->get('you have been added to event "%s" (%s)'), $event->title, $event->format_timeframe()); $message['content'] = sprintf($l10n->get('you have been added to event "%s" participants list, event information below.') . "{$nl}{$nl}", $event->title); $message['content'] .= $event->details_text(false, $this, $nl); break; //Participant was removed from event //Participant was removed from event case 'remove': $action = 'org.openpsa.calendar:event_remove'; $message['title'] = sprintf($l10n->get('you have been removed from event "%s"'), $event->title); $message['abstract'] = sprintf($l10n->get('you have been removed from event "%s" (%s)'), $event->title, $event->format_timeframe()); $message['content'] = sprintf($l10n->get('you have been removed from event "%s" (%s) participants list.'), $event->title, $event->format_timeframe()); break; //Event was cancelled (=deleted) //Event was cancelled (=deleted) case 'cancel': $action = 'org.openpsa.calendar:event_cancel'; $message['title'] = sprintf($l10n->get('event "%s" was cancelled'), $event->title); $message['abstract'] = sprintf($l10n->get('event "%s" (%s) was cancelled'), $event->title, $event->format_timeframe()); $message['content'] = sprintf($l10n->get('event "%s" (%s) was cancelled.'), $event->title, $event->format_timeframe()); break; default: debug_add("action '{$type}' is invalid, aborting notification", MIDCOM_LOG_ERROR); return false; } if ($type == 'cancel' || $type == 'remove') { // TODO: Create iCal export with correct delete commands } else { $encoder = new org_openpsa_calendar_vcal(); $vcal_data = $encoder->get_headers(); $vcal_data .= $encoder->export_event($event); $vcal_data .= $encoder->get_footers(); $message['attachments'] = array(array('name' => midcom_helper_misc::generate_urlname_from_string(sprintf('%s on %s', $event->title, date('Ymd_Hi', $event->start))) . '.ics', 'mimetype' => 'text/calendar', 'content' => $vcal_data)); } return org_openpsa_notifications::notify($action, $recipient->guid, $message); }
/** * Function to send a notification to owner of the deliverable - guid of deliverable is passed */ public function new_notification_message($args, &$handler) { if (!isset($args['deliverable'])) { $msg = 'deliverable GUID not set, aborting'; debug_add($msg, MIDCOM_LOG_ERROR); $handler->print_error($msg); return false; } try { $deliverable = new org_openpsa_sales_salesproject_deliverable_dba($args['deliverable']); } catch (midcom_error $e) { $msg = 'no deliverable with passed GUID: ' . $args['deliverable'] . ' , aborting'; debug_add($msg, MIDCOM_LOG_ERROR); $handler->print_error($msg); return false; } //get the owner of the salesproject the deliverable belongs to try { $project = new org_openpsa_sales_salesproject_dba($deliverable->salesproject); } catch (midcom_error $e) { $msg = 'Failed to load salesproject: ' . $e->getMessage(); debug_add($msg, MIDCOM_LOG_ERROR); $handler->print_error($msg); return false; } $content = sprintf($this->_l10n->get('agreement %s ends on %s. click here: %s'), $deliverable->title, strftime('%x', $deliverable->end), midcom::get('permalinks')->create_permalink($deliverable->guid)); $message = array('title' => sprintf($this->_l10n->get('notification for agreement %s'), $deliverable->title), 'content' => $content); return org_openpsa_notifications::notify('org.openpsa.sales:new_notification_message', $project->owner, $message); }
private function _notify_owner($calculator, $cycle_number, $next_run, $invoiced_sum, $tasks_completed, $tasks_not_completed, $new_task = null) { $siteconfig = org_openpsa_core_siteconfig::get_instance(); $message = array(); $salesproject = org_openpsa_sales_salesproject_dba::get_cached($this->_deliverable->salesproject); try { $owner = midcom_db_person::get_cached($salesproject->owner); } catch (midcom_error $e) { $e->log(); return; } $customer = $salesproject->get_customer(); if (is_null($next_run)) { $next_run_label = midcom::get('i18n')->get_string('no more cycles', 'org.openpsa.sales'); } else { $next_run_label = strftime('%x %X', $next_run); } // Title for long notifications $message['title'] = sprintf(midcom::get('i18n')->get_string('subscription cycle %d closed for agreement %s (%s)', 'org.openpsa.sales'), $cycle_number, $this->_deliverable->title, $customer->get_label()); // Content for long notifications $message['content'] = "{$message['title']}\n\n"; $message['content'] .= midcom::get('i18n')->get_string('invoiced', 'org.openpsa.sales') . ": {$invoiced_sum}\n\n"; if ($invoiced_sum > 0) { $invoice = $calculator->get_invoice(); $message['content'] .= midcom::get('i18n')->get_string('invoice', 'org.openpsa.invoices') . " {$invoice->number}:\n"; $url = $siteconfig->get_node_full_url('org.openpsa.invoices'); $message['content'] .= $url . 'invoice/' . $invoice->guid . "/\n\n"; } if (count($tasks_completed) > 0) { $message['content'] .= "\n" . midcom::get('i18n')->get_string('tasks completed', 'org.openpsa.sales') . ":\n"; foreach ($tasks_completed as $task) { $message['content'] .= "{$task->title}: {$task->reportedHours}h\n"; } } if (count($tasks_not_completed) > 0) { $message['content'] .= "\n" . midcom::get('i18n')->get_string('tasks not completed', 'org.openpsa.sales') . ":\n"; foreach ($tasks_not_completed as $task) { $message['content'] .= "{$task->title}: {$task->reportedHours}h\n"; } } if ($new_task) { $message['content'] .= "\n" . midcom::get('i18n')->get_string('created new task', 'org.openpsa.sales') . ":\n"; $message['content'] .= "{$task->title}\n"; } $message['content'] .= "\n" . midcom::get('i18n')->get_string('next run', 'org.openpsa.sales') . ": {$next_run_label}\n\n"; $message['content'] .= midcom::get('i18n')->get_string('agreement', 'org.openpsa.projects') . ":\n"; $url = $siteconfig->get_node_full_url('org.openpsa.sales'); $message['content'] .= $url . 'deliverable/' . $this->_deliverable->guid . '/'; // Content for short notifications $message['abstract'] = sprintf(midcom::get('i18n')->get_string('%s: closed subscription cycle %d for agreement %s. invoiced %d. next cycle %s', 'org.openpsa.sales'), $customer->get_label(), $cycle_number, $this->_deliverable->title, $invoiced_sum, $next_run_label); // Send the message out org_openpsa_notifications::notify('org.openpsa.sales:new_subscription_cycle', $owner->guid, $message); }