Adding an ics file to the notification.

971 views
Skip to first unread message

Craig Tucker

unread,
Nov 7, 2014, 1:15:42 PM11/7/14
to easy-app...@googlegroups.com
I am playing with adding an ics file to the notification so clients can easily add the appointment to their calendar and it can also be used to add the appointment to other calendars I have.  This is what I have done so far and it is not really ready for full use yet:

In application/libraries/notifications.php 
after line 102       $email_html = $this->replace_template_variables($replace_array, $email_html);
I have added the following:

        //Create ICS File
        $email_ics = 'BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN
VERSION:2.0
METHOD:REQUEST
BEGIN:VEVENT
ORGANIZER:MAILTO:'.$company_settings['company_name'].' '.$company_settings['company_link'].'
DTSTART:'.gmdate('Ymd\THis\Z', strtotime($appointment_data['start_datetime'])).'
DTEND:'.gmdate('Ymd\THis\Z', strtotime($appointment_data['end_datetime'])).'
LOCATION: //I added my company address here, I need to find the proper variable for this.
TRANSP:OPAQUE
SEQUENCE:0
UID:'.$appointment_link.'
DTSTAMP:'.gmdate("Ymd\THis\Z").'
DESCRIPTION:'.$message.' '.$appointment_link.'
SUMMARY:'.$service_data['name'].'
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR';

I after the following:        
$mail->Body    = $email_html;

I added:
$mail->AddStringAttachment($email_ics,'appointment.ics','base64','text/calendar');


This adds an ICS file to the notification email.  It looks good in gmail but needs more work to do what I want in outlook.

Problems:  It would be best to make this an inline condition rather than an attachment because then it would show up in outlook with the accept, decline buttons.  I think this would be best but I am not sure how to make this happen yet.  Also, I need to alter the METHOD portion of the ics file to change from request to delete when the client chooses to delete. That will be easy but I do not have time for it now.

So, this is what I have done.  I hope others want to play with this and make it better.  I will keep plugging away at it. 

Craig

Alex Tselegidis

unread,
Nov 23, 2014, 8:34:58 AM11/23/14
to easy-app...@googlegroups.com
Well done!

Craig Tucker

unread,
Nov 27, 2014, 12:39:37 PM11/27/14
to easy-app...@googlegroups.com
To get the accept/tentative/decline buttons to work in phpmailer for outlook adjustments were necessary. 

/application/libraries/external/class.phpmailer.php (changes based upon https://github.com/PHPMailer/PHPMailer/issues/47 comments from reblutus)
/application/views/emails/iCal.php (I added this)
/application/libraries/notifications.php (multiple changes made here for the notification of appointment and deletion, I added some variables etc. )
/application/controllers/appointments.php (I had to modify elements of this as well, a minor problem persists, discussed below).

I have made changes to the following files to get the buttons to work.  So it works now in outlook and will automatically add the file to the calendar.  The problem is that it will not work with google calendar.

Google works by adding the following string for both the appointment notifications and the cancellations:
 
                $mailer->AddStringAttachment($email_ics,'appointment.ics, '7bit','text/calendar; charset=utf-8');

But, with this the accept/tentative/decline buttons do not show up in Outlook.  Frustrating.  There must be a way to get both.

Also, all runs smoothly except on the back end, canceling appointments does not resolve correctly.  I think I messed up on my code in appoingments.php at line 273 through 298 but I am not sure what is wrong there. 

So, my quest continues to get the ics files to work in all environments. 


class.phpmailer.php
iCal.php
notifications.php
appointments.php

Craig Tucker

unread,
Nov 27, 2014, 11:30:38 PM11/27/14
to easy-app...@googlegroups.com
While trying to figure out why my delete screen hangs when in the back end, I noticed that the back end also needs some adjustments to shoot out a delete ics.  The attached file does this. 

The remaining problems:
  1. when deleting items the delete window hangs--although the item is in fact deleted.  Manual refresh of the browser shows it gone.
  2. At this time, it appears that Google Calendar requires an attached ics file to generate accept/decline buttons
  3. This method works fine for Outlook to get an ics file with accept/decline buttons
  4. The two methods appear to be mutually exclusive in phpmailer.
backend_api.php

Liz Baker

unread,
Dec 7, 2014, 4:04:34 PM12/7/14
to easy-app...@googlegroups.com
I have this currently working beautifully for my existing calendar, but as soon as I am able to create,read, update, delete my existing clients and users table I cannot plug it right in. I have a 12 hour dealine for that. As soon as I can I will send my zips. I also have the backend mobile friendly.

Craig Tucker

unread,
Dec 15, 2014, 1:44:59 AM12/15/14
to easy-app...@googlegroups.com
That is great Liz.  I am still having trouble getting the Yes / Maybe / No buttons  in gmail along with the Accept/tentative/decline buttons in Outlook.  I can get one or the other and not both.  I would like to see what you have done for the backend file.
Reply all
Reply to author
Forward
0 new messages