# Event ICS

![Screenshot](/images/screenshot.png)

Attaches an ICS (iCal) file to event confirmation emails, so that people can easily
add to their calendar.

The extension is licensed under [AGPL-3.0](LICENSE.txt).

## Requirements

* PHP v7.2+
* CiviCRM 5.x

## Installation

Enable as a regular CiviCRM extension.

## Usage

Once enabled, it automatically attaches the ICS files to event confirmations.
This behaviour can be changed under Administer > CiviEvent > Event iCal Settings.

The settings can also be set on a per-event basis. It is also possible to
override the Location and Description included in the ICS file. Otherwise it
uses the location and description of the event.

It also provides the ability to attach buttons to make it easier to add to Outlook and Google
 (special formatting is required for Google calendars. Further information on how to add these
buttons to your Event registration below.

Currently ICS attachments are not added to confirmation emails from backend
registrations (i.e. registrations added by admins).

## Alter hook

We provide a EventICS hook so that you can modify the ICS details prior to the actual file being generated. This can be useful if you
want to simply use the Event Description each time, but perhaps trim it's contents in a repeating event.

It also allows for:

+ Modification of the actual Event Location/Date/Time
+ Modification of Description

### Example

Let's assume in this example depending on the type of regisration the person is directed to different locations

```php
function myextension_eventics_alter_event_data(&$event_info, &$eventics, &$mail_params) {
  if (empty($event_info) || empty($eventics)) {
    return;
  }

  foreach($event_info as $id => &$event) {
    if ($event['event_type'] == 'ABC') {
      // Grab the Participantion of the specific user
      $cid = $mail_params['contactId'];
      $participation_type = get_registration_type($cid);

      $location = 55;
      if ($participation_type == 'Gold') {
        $location = 100;
      }
      elseif ($participation_type == 'Volunteer') {
        $location = 205;
      }
      ...

      try {
        $location = \Civi\Api4\Contact::get(FALSE)
          ->addSelect('display_name', 'address.street_address', 'address.city', 'address.postal_code')
          ->addJoin('Address AS address', 'LEFT', ['address.contact_id', '=', 'id'])
          ->addWhere('address.is_primary', '=', TRUE)
          ->execute()
          ->first();

          $address = "{$distro['address.street_address']}, {$distro['address.city']}, Alberta, {$distro['address.postal_code']}";
          $event['location'] = $eventics['event_location'] = $address;
          $event['description'] = $eventics['event_description'] = "You can attend the event at <strong>{$distro['display_name']}>
            <a href=\"https://www.google.com/maps/dir/{$address_link}\">{$address}</a>.";

      } catch (Exception $e) {
        Civi::log()->warning('Hook Alter error '.$e->getMessage());
      }
    }
  }

```

## Adding Google / Outlook buttons to Registration Confirmation

After enabling the Google and Outlook link options in the Eventics Configuration
you will need to do the following:

1. Go to CiviCRM > Administer > Message Templates
2. Edit the Events - Registration Confirmation and Receipt (on-line)
3. Add the button code where ever you want within the template, which are defined by ```balh``` and ```blah```

Example code that can be used

```html
     {if $icslinks.gcalendarlink}
        <!-- Google button -->
         <a href="{$icslinks.gcalendarlink}" style="text-decoration: none; font-weight: normal;" target="_new" href=""><strong>{ts}Add to calendar (Google){/ts}</strong></a>
     {/if}
     {if $icslinks.icslink}
        <!-- Outlook button -->
         <a href="{$icslinks.icslink}" style="text-decoration: none; font-weight: normal;" target="_new" href=""><strong>{ts}Add to calendar (Outlook){/ts}</strong></a>
     {/if}

```
## Known Issues

Google displays "Organizer: Unknown", but according to [this Stack Overflow
answer](https://stackoverflow.com/a/15266752), that should be the expected
behaviour. Despite trying a few variants, I could not get it to work.

## Support

Please post bug reports in the issue tracker of this project on CiviCRM's Gitlab:
https://lab.civicrm.org/extensions/eventics/-/issues

While we do our best to provide free community support for this extension,
please consider financially contributing to support or development of this
extension.

Commercial support is available through Coop SymbioTIC:
https://www.symbiotic.coop/en

Coop Symbiotic is a worker-owned co-operative based in Canada. We have a strong
experience working with non-profits and CiviCRM. We provide affordable, fast,
turn-key hosting with regular upgrades and proactive monitoring, as well as custom
development and training.
