📜 ⬆️ ⬇️

SMS Notifications + Event Logging in Google Calendar for PHP

Inspired by: The wonders of automation or how to send SMS real geeks .
If people make such sophistication, then it is very necessary.

For a couple of hours, a class was developed to add events to Google Calendar. And the Google calendar will be to send us SMS.

To use, we need to properly set up our calendar (it’s worth to have a separate account for this):
1. Set the calendar time zone to be the same as on the server.
2. Configure SMS notifications (Settings -> Settings for mobile devices)
3. Set the default notification for the calendar. (Calendar settings - Notifications)
We set the default to notify 1 minute before the event via SMS. You can add more mail notification.
Everything. Calendar prepared.

For the script to work, we need part of ZendFramework.
The gdata classset: framework.zend.com/download/gdata .
')
And the script code with a class and an example of use:

<?
require_once 'Zend/Loader.php' ;
Zend_Loader::loadClass( 'Zend_Gdata' );
Zend_Loader::loadClass( 'Zend_Gdata_AuthSub' );
Zend_Loader::loadClass( 'Zend_Gdata_ClientLogin' );
Zend_Loader::loadClass( 'Zend_Gdata_Calendar' );

class GCAlerter
{
public $gcCalendar;
public $gcTimeCorrect;

public function __construct($user, $pass, $tc)
{
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, "cl" );
$ this ->gcCalendar = new Zend_Gdata_Calendar($client);
$ this ->gcTimeCorrect = $tc;
}

public function Alert($text)
{
$quickAddText = "$text " .date( "h:i" ,time() + $ this ->gcTimeCorrect);
$ event = $ this ->gcCalendar->newEventEntry();
$ event ->content = $ this ->gcCalendar->newContent($quickAddText);
$ event ->quickAdd = $ this ->gcCalendar->newQuickAdd( 'true' );
$newEvent = $ this ->gcCalendar->insertEvent($ event );
return $newEvent->id->text;
}
}

$user = "mycal@gmail.com" ;
$pass = 'mypass' ;
$timecorr = 2*60; // 2*60 = 2 min, 10*60 = 10min

$gcAlerter = new GCAlerter($user, $pass, $timecorr);
$gcAlerter->Alert( "OMG I`m die!!!" );
?>


* This source code was highlighted with Source Code Highlighter
.


$ timecorr - time adjustment variable.
Time on the server and Google time may vary due to incorrect server time. It is not always possible to fix it.
In fact, we use this parameter to adjust the required time so that the notification arrives no later than a minute after the event.

Source: https://habr.com/ru/post/45161/


All Articles