public function _on_updated() { // Invalidate topic in cache to refresh all views // TODO: Do this only on status changes if (isset($GLOBALS['disable_activitystream'])) { return true; } if ($_MIDCOM->auth->request_sudo('midcom')) { // This is here because creating an object calls create and update..... and we don't want duplicate entry's $qb = midcom_helper_activitystream_activity_dba::new_query_builder(); $qb->set_limit(1); $qb->add_constraint('application', '=', 'fi.kilonkipinat.forms'); $qb->add_constraint('target', '=', $this->guid); $groups = $qb->execute(); if ($groups && is_array($groups) && count($groups) > 0) { $new_object = false; } else { $new_object = true; } $actor = midcom_db_person::get_cached($_MIDGARD['user']); $activity = new midcom_helper_activitystream_activity_dba(); $activity->target = $this->guid; $activity->application = 'fi.kilonkipinat.forms'; $activity->actor = $actor->id; $activity->verb = 'http://activitystrea.ms/schema/1.0/post'; if ($new_object) { $activity->summary = sprintf('%s loi kulukorvauslomakkeen', $actor->name); } else { $activity->summary = sprintf('%s muokkasi kulukorvauslomaketta', $actor->name); } $activity->create(); $_MIDCOM->auth->drop_sudo(); } return true; }
public function _on_updated() { // Invalidate topic in cache to refresh all views // TODO: Do this only on status changes $topic = midcom_db_topic::get_cached($this->topic); if ($topic->guid) { $_MIDCOM->cache->invalidate($topic->guid); } if (isset($GLOBALS['disable_activitystream'])) { return true; } if ($_MIDCOM->auth->request_sudo('midcom')) { $actor = midcom_db_person::get_cached($_MIDGARD['user']); $activity = new midcom_helper_activitystream_activity_dba(); $activity->target = $this->guid; $activity->application = 'fi.kilonkipinat.account'; $activity->actor = $actor->id; $activity->verb = 'http://activitystrea.ms/schema/1.0/post'; if ($this->id == $actor->id) { $activity->summary = sprintf('%s muokkasi omaa tunnustaan', $actor->name); } else { $tmp_name = $this->firstname . ' ' . $this->lastname; $activity->summary = sprintf('%s muokkasi %s:n tunnusta', $actor->name, $tmp_name); } $activity->create(); $_MIDCOM->auth->drop_sudo(); } return true; }
/** * Method for exporting event in vCalendar format * * @param org_openpsa_calendar_event_dba $event The event we're working on * @param array compatibility options to override * @return string vCalendar data */ public function export_event(org_openpsa_calendar_event_dba $event, $compatibility = array()) { $encoder = new org_openpsa_helpers_vxparser(); $encoder->merge_compatibility($compatibility); // Simple key/value pairs, for multiple occurrences of same key use array as value $vcal_keys = array(); // For extended key data, like charset $vcal_key_parameters = array(); // TODO: handle UID smarter $vcal_keys['UID'] = "{$event->guid}-midgardGuid"; $revised = $event->metadata->revised; $created = $event->metadata->created; $vcal_keys['LAST-MODIFIED'] = $encoder->vcal_stamp($revised, array('TZID' => 'UTC')) . 'Z'; $vcal_keys['CREATED'] = $encoder->vcal_stamp($created, array('TZID' => 'UTC')) . 'Z'; /** * The real meaning of the DTSTAMP is fuzzy at best * http://www.kanzaki.com/docs/ical/dtstamp.html is less than helpful * http://lists.osafoundation.org/pipermail/ietf-calsify/2007-July/001750.html * seems to suggest that using the revision would be best */ $vcal_keys['DTSTAMP'] =& $vcal_keys['LAST-MODIFIED']; // Type handling switch ($event->orgOpenpsaAccesstype) { case org_openpsa_core_acl::ACCESS_PUBLIC: $vcal_keys['CLASS'] = 'PUBLIC'; break; default: case org_openpsa_core_acl::ACCESS_PRIVATE: $vcal_keys['CLASS'] = 'PRIVATE'; break; } // "busy" or "transparency" as vCalendar calls it if ($event->busy) { $vcal_keys['TRANSP'] = 'OPAQUE'; } else { $vcal_keys['TRANSP'] = 'TRANSPARENT'; } // tentative vs confirmed $vcal_keys['STATUS'] = 'CONFIRMED'; // we don't categorize events, at least yet $vcal_keys['CATEGORIES'] = 'MEETING'; // we don't handle priorities $vcal_keys['PRIORITY'] = 1; // Basic fields $vcal_keys['SUMMARY'] = $encoder->escape_separators($event->title); $vcal_keys['DESCRIPTION'] = $encoder->escape_separators($event->description); $vcal_keys['LOCATION'] = $encoder->escape_separators($event->location); // Start & End in UTC $vcal_keys['DTSTART'] = $encoder->vcal_stamp($event->start, array('TZID' => 'UTC')) . 'Z'; $vcal_keys['DTEND'] = $encoder->vcal_stamp($event->end, array('TZID' => 'UTC')) . 'Z'; // Participants $vcal_keys['ATTENDEE'] = array(); $vcal_key_parameters['ATTENDEE'] = array(); // Safety, otherwise the notice will make output invalid if (!is_array($event->participants)) { $event->participants = array(); } foreach ($event->participants as $uid => $bool) { // Just a safety if (!$bool) { continue; } $person = midcom_db_person::get_cached($uid); if (empty($person->email)) { // Attendee must have email address of valid format, these must also be unique. $person->email = preg_replace('/[^0-9_\\x61-\\x7a]/i', '_', strtolower($person->name)) . '*****@*****.**'; } $vcal_keys['ATTENDEE'][] = "mailto:{$person->email}"; $vcal_key_parameters['ATTENDEE'][] = array('ROLE' => 'REQ-PARTICIPANT', 'CUTYPE' => 'INDIVIDUAL', 'PARTSTAT' => 'ACCEPTED', 'CN' => $encoder->escape_separators($person->rname, true)); } $ret = "BEGIN:VEVENT{$this->_newline}"; $ret .= $encoder->export_vx_variables_recursive($vcal_keys, $vcal_key_parameters, false, $this->_newline); $ret .= "END:VEVENT{$this->_newline}"; return $ret; }
/** * Get a preference for the current user * * @param string $preference Name of the preference */ public static function get_preference($preference) { static $preferences = array(); if (!midcom::get('auth')->user) { return; } if (!isset($preferences[$preference])) { $person = midcom_db_person::get_cached(midcom::get('auth')->user->guid); $preferences[$preference] = $person->get_parameter('midgard.admin.asgard:preferences', $preference); } return $preferences[$preference]; }
public function _on_deleted() { $this->_invalidate_person_cache(); if (!midcom::get('auth')->request_sudo('midcom')) { return; } // Create an Activity Log entry for the membership addition try { $actor = midcom_db_person::get_cached($this->uid); $target = midcom_db_group::get_cached($this->gid); } catch (midcom_error $e) { $e->log(); return; } $activity = new midcom_helper_activitystream_activity_dba(); $activity->target = $target->guid; $activity->actor = $actor->id; $activity->verb = 'http://community-equity.org/schema/1.0/leave'; if (midcom::get('auth')->is_valid_user() && $actor->guid == midcom::get('auth')->user->guid) { $activity->summary = sprintf(midcom::get('i18n')->get_string('%s left group %s', 'midcom'), $actor->name, $target->official); } else { $activity->summary = sprintf(midcom::get('i18n')->get_string('%s was removed from group %s', 'midcom'), $actor->name, $target->official); } $activity->create(); midcom::get('auth')->drop_sudo(); }
private function _update_task() { $task = org_openpsa_projects_task_dba::get_cached($this->task); if ($this->type == org_openpsa_projects_task_status_dba::PROPOSED) { try { $recipient = midcom_db_person::get_cached($this->targetPerson); //Creator will naturally accept his own proposal... if ($recipient->guid == $this->metadata->creator) { return org_openpsa_projects_workflow::accept($task, 0, $this->comment); } } catch (midcom_error $e) { $e->log(); } } //See if the parent status needs updating if ($task->status == $this->type) { debug_add("Task status is up to date, returning"); return; } $needs_update = false; if ($task->status < $this->type) { // This doesn't really do anything yet, it's moved here from workflow.php if ($this->type == org_openpsa_projects_task_status_dba::ACCEPTED) { switch ($task->acceptanceType) { case ORG_OPENPSA_TASKACCEPTANCE_ALLACCEPT: case ORG_OPENPSA_TASKACCEPTANCE_ONEACCEPTDROP: debug_add('Acceptance mode not implemented', MIDCOM_LOG_ERROR); return false; break; default: case ORG_OPENPSA_TASKACCEPTANCE_ONEACCEPT: //PONDER: Should this be superseded by generic method for querying the status objects to set the latest status ?? debug_add("Required accept received, setting task status to accepted"); // $needs_update = true; break; } } else { $needs_update = true; } } else { $needs_update = true; } if ($needs_update) { debug_add("Setting task status to {$this->type}"); $task->status = $this->type; $task->_skip_acl_refresh = true; $task->update(); } }
/** * Check for potential busy conflicts to allow more graceful handling of those conditions * * Also allows normal events to "rob" resources from tentative ones. * NOTE: return false for *no* (or resolved automatically) conflicts and true for unresolvable conflicts */ function run($rob_tentative = false) { //If we're not busy it's not worth checking if (!$this->_event->busy) { debug_add('we allow overlapping, so there is no point in checking others'); return true; } //If this event is tentative always disallow robbing resources from other tentative events if ($this->_event->tentative) { $rob_tentative = false; } //We need sudo to see busys in events we normally don't see and to rob resources from tentative events midcom::get('auth')->request_sudo('org.openpsa.calendar'); //Storage for events that have been modified due the course of this method $modified_events = array(); /* * Look for duplicate events only if we have participants or resources, otherwise we incorrectly get all events at * the same timeframe as duplicates since there are no participant constraints to narrow things down */ $ret_ev = $this->_load_participants(); $ret_ev2 = $this->_load_resources(); // TODO: Shared tasks need a separate check (different member object) // Both QBs returned empty sets if (empty($ret_ev) && empty($ret_ev2)) { //No busy events found within the timeframe midcom::get('auth')->drop_sudo(); debug_add('no overlaps found'); return true; } foreach ($ret_ev as $member) { $this->_process_participant($member, $modified_events, $rob_tentative); } foreach ($ret_ev2 as $member) { $this->_process_resource($member, $modified_events, $rob_tentative); } if (is_array($this->busy_members) || is_array($this->busy_resources)) { //Unresolved conflicts (note return value is for conflicts not lack of them) midcom::get('auth')->drop_sudo(); debug_print_r('unresolvable conflicts found', $this->busy_members); midcom_connection::set_error(MGD_ERR_ERROR); return false; } foreach ($modified_events as $event) { //These events have been robbed of (some of) their resources $creator = midcom_db_person::get_cached($event->metadata->creator); if ((count($event->participants) == 0 || count($event->participants) == 1 && array_key_exists($creator->id, $event->participants)) && count($event->resources) == 0) { /* If modified event has no-one or only creator as participant and no resources then delete it (as it's unlikely the stub event is useful anymore) */ debug_add("event {$event->title} (#{$event->id}) has been robbed of all of its resources, calling delete"); //TODO: take notifications and repeats into account $event->delete(); } else { //Otherwise just commit the changes //TODO: take notifications and repeats into account debug_add("event {$event->title} (#{$event->id}) has been robbed of some its resources, calling update"); $event->update(); } } midcom::get('auth')->drop_sudo(); //No conflicts found or they could be automatically resolved $this->busy_members = false; $this->busy_resources = false; return true; }
/** * @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_edit($handler_id, array $args, array &$data) { $this->_person = new midcom_db_person($args[0]); $this->_person->require_do('midgard:update'); if ($this->_person->id != midcom_connection::get_user()) { midcom::get('auth')->require_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface'); } //get existing account for gui $this->_account = new midcom_core_account($this->_person); //if we have no username there is no account if (!$this->_account->get_username()) { // Account needs to be created first, relocate return new midcom_response_relocate("account/create/" . $this->_person->guid . "/"); } // if there is no password set (due to block), show ui-message for info $midcom_person = midcom_db_person::get_cached($this->_person->id); $account_helper = new org_openpsa_user_accounthelper($midcom_person); if ($account_helper->is_blocked()) { midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.user'), $this->_l10n->get("Account was blocked, since there is no password set."), 'error'); } $data['controller'] = $this->get_controller('nullstorage'); $formmanager = $data["controller"]->formmanager; switch ($data['controller']->process_form()) { case 'save': if (!$this->_update_account($formmanager->_types)) { break; } //Fall-through //Fall-through case 'cancel': return new midcom_response_relocate("view/" . $this->_person->guid . "/"); } $this->add_stylesheet(MIDCOM_STATIC_URL . "/midcom.helper.datamanager2/legacy.css"); midcom::get('head')->enable_jquery(); midcom::get('head')->set_pagetitle("{$this->_person->firstname} {$this->_person->lastname}"); $this->_prepare_request_data(); $this->_update_breadcrumb_line('edit account'); // Add toolbar items org_openpsa_helpers::dm2_savecancel($this); $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "account/delete/{$this->_person->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('delete account'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png')); }
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); }
/** * Get person by given ID, caches results. * * @see read_metadata_from_object() * @param string $id GUID or ID to get person for * @return midcom_db_person object */ private function _read_metadata_from_object_get_person_cached($id) { try { $person = midcom_db_person::get_cached($id); } catch (midcom_error $e) { return false; } return $person; }
echo $contact->show(); } } ?> <div class="org_openpsa_helper_box history status"> <?php $qb = org_openpsa_projects_task_status_dba::new_query_builder(); $qb->add_constraint('task', '=', $task->id); $qb->add_order('timestamp', 'DESC'); $qb->add_order('type', 'DESC'); $ret = $qb->execute(); if (is_array($ret) && count($ret) > 0) { echo "<h3>" . $data['l10n']->get('status history') . "</h3>\n"; echo "<div class=\"current-status {$task->status_type}\">" . $data['l10n']->get('task status') . ': ' . $data['l10n']->get($task->status_type) . "</div>\n"; echo "<ul>\n"; $fallback_creator = midcom_db_person::get_cached(1); foreach ($ret as $status_change) { echo "<li>"; $status_changer_label = $data['l10n']->get('system'); $target_person_label = $data['l10n']->get('system'); if ($status_change->metadata->creator && $status_change->metadata->creator != $fallback_creator->guid) { $status_changer = org_openpsa_widgets_contact::get($status_change->metadata->creator); $status_changer_label = $status_changer->show_inline(); } if ($status_change->targetPerson) { $target_person = org_openpsa_widgets_contact::get($status_change->targetPerson); $target_person_label = $target_person->show_inline(); } $message = sprintf($data['l10n']->get($status_change->get_status_message()), $status_changer_label, $target_person_label); $status_changed = strftime('%x %H:%M', $status_change->metadata->created); echo "<span class=\"date\">{$status_changed}</span>: <br />{$message}";
public function __construct($recipient) { $this->_component = 'org.openpsa.notifications'; $this->recipient = midcom_db_person::get_cached($recipient); parent::__construct(); }