Also apply the __toString fix to UserInfo
[cacert-mgr.git] / external / ZendFramework-1.9.5 / demos / Zend / Gdata / Calendar.php
1 <?php
2 /**
3 * Zend Framework
4 *
5 * LICENSE
6 *
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
14 *
15 * @category Zend
16 * @package Zend_Gdata
17 * @subpackage Demos
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 */
21
22 /**
23 * PHP sample code for the Google Calendar data API. Utilizes the
24 * Zend Framework Gdata components to communicate with the Google API.
25 *
26 * Requires the Zend Framework Gdata components and PHP >= 5.1.4
27 *
28 * You can run this sample both from the command line (CLI) and also
29 * from a web browser. When running through a web browser, only
30 * AuthSub and outputting a list of calendars is demonstrated. When
31 * running via CLI, all functionality except AuthSub is available and dependent
32 * upon the command line options passed. Run this script without any
33 * command line options to see usage, eg:
34 * /usr/local/bin/php -f Calendar.php
35 *
36 * More information on the Command Line Interface is available at:
37 * http://www.php.net/features.commandline
38 *
39 * NOTE: You must ensure that the Zend Framework is in your PHP include
40 * path. You can do this via php.ini settings, or by modifying the
41 * argument to set_include_path in the code below.
42 *
43 * NOTE: As this is sample code, not all of the functions do full error
44 * handling. Please see getEvent for an example of how errors could
45 * be handled and the online code samples for additional information.
46 */
47
48 /**
49 * @see Zend_Loader
50 */
51 require_once 'Zend/Loader.php';
52
53 /**
54 * @see Zend_Gdata
55 */
56 Zend_Loader::loadClass('Zend_Gdata');
57
58 /**
59 * @see Zend_Gdata_AuthSub
60 */
61 Zend_Loader::loadClass('Zend_Gdata_AuthSub');
62
63 /**
64 * @see Zend_Gdata_ClientLogin
65 */
66 Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
67
68 /**
69 * @see Zend_Gdata_HttpClient
70 */
71 Zend_Loader::loadClass('Zend_Gdata_HttpClient');
72
73 /**
74 * @see Zend_Gdata_Calendar
75 */
76 Zend_Loader::loadClass('Zend_Gdata_Calendar');
77
78 /**
79 * @var string Location of AuthSub key file. include_path is used to find this
80 */
81 $_authSubKeyFile = null; // Example value for secure use: 'mykey.pem'
82
83 /**
84 * @var string Passphrase for AuthSub key file.
85 */
86 $_authSubKeyFilePassphrase = null;
87
88 /**
89 * Returns the full URL of the current page, based upon env variables
90 *
91 * Env variables used:
92 * $_SERVER['HTTPS'] = (on|off|)
93 * $_SERVER['HTTP_HOST'] = value of the Host: header
94 * $_SERVER['SERVER_PORT'] = port number (only used if not http/80,https/443)
95 * $_SERVER['REQUEST_URI'] = the URI after the method of the HTTP request
96 *
97 * @return string Current URL
98 */
99 function getCurrentUrl()
100 {
101 global $_SERVER;
102
103 /**
104 * Filter php_self to avoid a security vulnerability.
105 */
106 $php_request_uri = htmlentities(substr($_SERVER['REQUEST_URI'], 0, strcspn($_SERVER['REQUEST_URI'], "\n\r")), ENT_QUOTES);
107
108 if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
109 $protocol = 'https://';
110 } else {
111 $protocol = 'http://';
112 }
113 $host = $_SERVER['HTTP_HOST'];
114 if ($_SERVER['SERVER_PORT'] != '' &&
115 (($protocol == 'http://' && $_SERVER['SERVER_PORT'] != '80') ||
116 ($protocol == 'https://' && $_SERVER['SERVER_PORT'] != '443'))) {
117 $port = ':' . $_SERVER['SERVER_PORT'];
118 } else {
119 $port = '';
120 }
121 return $protocol . $host . $port . $php_request_uri;
122 }
123
124 /**
125 * Returns the AuthSub URL which the user must visit to authenticate requests
126 * from this application.
127 *
128 * Uses getCurrentUrl() to get the next URL which the user will be redirected
129 * to after successfully authenticating with the Google service.
130 *
131 * @return string AuthSub URL
132 */
133 function getAuthSubUrl()
134 {
135 global $_authSubKeyFile;
136 $next = getCurrentUrl();
137 $scope = 'http://www.google.com/calendar/feeds/';
138 $session = true;
139 if ($_authSubKeyFile != null) {
140 $secure = true;
141 } else {
142 $secure = false;
143 }
144 return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure,
145 $session);
146 }
147
148 /**
149 * Outputs a request to the user to login to their Google account, including
150 * a link to the AuthSub URL.
151 *
152 * Uses getAuthSubUrl() to get the URL which the user must visit to authenticate
153 *
154 * @return void
155 */
156 function requestUserLogin($linkText)
157 {
158 $authSubUrl = getAuthSubUrl();
159 echo "<a href=\"{$authSubUrl}\">{$linkText}</a>";
160 }
161
162 /**
163 * Returns a HTTP client object with the appropriate headers for communicating
164 * with Google using AuthSub authentication.
165 *
166 * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after
167 * it is obtained. The single use token supplied in the URL when redirected
168 * after the user succesfully authenticated to Google is retrieved from the
169 * $_GET['token'] variable.
170 *
171 * @return Zend_Http_Client
172 */
173 function getAuthSubHttpClient()
174 {
175 global $_SESSION, $_GET, $_authSubKeyFile, $_authSubKeyFilePassphrase;
176 $client = new Zend_Gdata_HttpClient();
177 if ($_authSubKeyFile != null) {
178 // set the AuthSub key
179 $client->setAuthSubPrivateKeyFile($_authSubKeyFile, $_authSubKeyFilePassphrase, true);
180 }
181 if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
182 $_SESSION['sessionToken'] =
183 Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token'], $client);
184 }
185 $client->setAuthSubToken($_SESSION['sessionToken']);
186 return $client;
187 }
188
189 /**
190 * Processes loading of this sample code through a web browser. Uses AuthSub
191 * authentication and outputs a list of a user's calendars if succesfully
192 * authenticated.
193 *
194 * @return void
195 */
196 function processPageLoad()
197 {
198 global $_SESSION, $_GET;
199 if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) {
200 requestUserLogin('Please login to your Google Account.');
201 } else {
202 $client = getAuthSubHttpClient();
203 outputCalendarList($client);
204 }
205 }
206
207 /**
208 * Returns a HTTP client object with the appropriate headers for communicating
209 * with Google using the ClientLogin credentials supplied.
210 *
211 * @param string $user The username, in e-mail address format, to authenticate
212 * @param string $pass The password for the user specified
213 * @return Zend_Http_Client
214 */
215 function getClientLoginHttpClient($user, $pass)
216 {
217 $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
218
219 $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
220 return $client;
221 }
222
223 /**
224 * Outputs an HTML unordered list (ul), with each list item representing an event
225 * in the user's calendar. The calendar is retrieved using the magic cookie
226 * which allows read-only access to private calendar data using a special token
227 * available from within the Calendar UI.
228 *
229 * @param string $user The username or address of the calendar to be retrieved.
230 * @param string $magicCookie The magic cookie token
231 * @return void
232 */
233 function outputCalendarMagicCookie($user, $magicCookie)
234 {
235 $gdataCal = new Zend_Gdata_Calendar();
236 $query = $gdataCal->newEventQuery();
237 $query->setUser($user);
238 $query->setVisibility('private-' . $magicCookie);
239 $query->setProjection('full');
240 $eventFeed = $gdataCal->getCalendarEventFeed($query);
241 echo "<ul>\n";
242 foreach ($eventFeed as $event) {
243 echo "\t<li>" . $event->title->text . "</li>\n";
244 $sl = $event->getLink('self')->href;
245 }
246 echo "</ul>\n";
247 }
248
249 /**
250 * Outputs an HTML unordered list (ul), with each list item representing a
251 * calendar in the authenticated user's calendar list.
252 *
253 * @param Zend_Http_Client $client The authenticated client object
254 * @return void
255 */
256 function outputCalendarList($client)
257 {
258 $gdataCal = new Zend_Gdata_Calendar($client);
259 $calFeed = $gdataCal->getCalendarListFeed();
260 echo "<h1>" . $calFeed->title->text . "</h1>\n";
261 echo "<ul>\n";
262 foreach ($calFeed as $calendar) {
263 echo "\t<li>" . $calendar->title->text . "</li>\n";
264 }
265 echo "</ul>\n";
266 }
267
268 /**
269 * Outputs an HTML unordered list (ul), with each list item representing an
270 * event on the authenticated user's calendar. Includes the start time and
271 * event ID in the output. Events are ordered by starttime and include only
272 * events occurring in the future.
273 *
274 * @param Zend_Http_Client $client The authenticated client object
275 * @return void
276 */
277 function outputCalendar($client)
278 {
279 $gdataCal = new Zend_Gdata_Calendar($client);
280 $query = $gdataCal->newEventQuery();
281 $query->setUser('default');
282 $query->setVisibility('private');
283 $query->setProjection('full');
284 $query->setOrderby('starttime');
285 $query->setFutureevents(true);
286 $eventFeed = $gdataCal->getCalendarEventFeed($query);
287 // option 2
288 // $eventFeed = $gdataCal->getCalendarEventFeed($query->getQueryUrl());
289 echo "<ul>\n";
290 foreach ($eventFeed as $event) {
291 echo "\t<li>" . $event->title->text . " (" . $event->id->text . ")\n";
292 // Zend_Gdata_App_Extensions_Title->__toString() is defined, so the
293 // following will also work on PHP >= 5.2.0
294 //echo "\t<li>" . $event->title . " (" . $event->id . ")\n";
295 echo "\t\t<ul>\n";
296 foreach ($event->when as $when) {
297 echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n";
298 }
299 echo "\t\t</ul>\n";
300 echo "\t</li>\n";
301 }
302 echo "</ul>\n";
303 }
304
305 /**
306 * Outputs an HTML unordered list (ul), with each list item representing an
307 * event on the authenticated user's calendar which occurs during the
308 * specified date range.
309 *
310 * To query for all events occurring on 2006-12-24, you would query for
311 * a startDate of '2006-12-24' and an endDate of '2006-12-25' as the upper
312 * bound for date queries is exclusive. See the 'query parameters reference':
313 * http://code.google.com/apis/gdata/calendar.html#Parameters
314 *
315 * @param Zend_Http_Client $client The authenticated client object
316 * @param string $startDate The start date in YYYY-MM-DD format
317 * @param string $endDate The end date in YYYY-MM-DD format
318 * @return void
319 */
320 function outputCalendarByDateRange($client, $startDate='2007-05-01',
321 $endDate='2007-08-01')
322 {
323 $gdataCal = new Zend_Gdata_Calendar($client);
324 $query = $gdataCal->newEventQuery();
325 $query->setUser('default');
326 $query->setVisibility('private');
327 $query->setProjection('full');
328 $query->setOrderby('starttime');
329 $query->setStartMin($startDate);
330 $query->setStartMax($endDate);
331 $eventFeed = $gdataCal->getCalendarEventFeed($query);
332 echo "<ul>\n";
333 foreach ($eventFeed as $event) {
334 echo "\t<li>" . $event->title->text . " (" . $event->id->text . ")\n";
335 echo "\t\t<ul>\n";
336 foreach ($event->when as $when) {
337 echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n";
338 }
339 echo "\t\t</ul>\n";
340 echo "\t</li>\n";
341 }
342 echo "</ul>\n";
343 }
344
345 /**
346 * Outputs an HTML unordered list (ul), with each list item representing an
347 * event on the authenticated user's calendar which matches the search string
348 * specified as the $fullTextQuery parameter
349 *
350 * @param Zend_Http_Client $client The authenticated client object
351 * @param string $fullTextQuery The string for which you are searching
352 * @return void
353 */
354 function outputCalendarByFullTextQuery($client, $fullTextQuery='tennis')
355 {
356 $gdataCal = new Zend_Gdata_Calendar($client);
357 $query = $gdataCal->newEventQuery();
358 $query->setUser('default');
359 $query->setVisibility('private');
360 $query->setProjection('full');
361 $query->setQuery($fullTextQuery);
362 $eventFeed = $gdataCal->getCalendarEventFeed($query);
363 echo "<ul>\n";
364 foreach ($eventFeed as $event) {
365 echo "\t<li>" . $event->title->text . " (" . $event->id->text . ")\n";
366 echo "\t\t<ul>\n";
367 foreach ($event->when as $when) {
368 echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n";
369 echo "\t\t</ul>\n";
370 echo "\t</li>\n";
371 }
372 }
373 echo "</ul>\n";
374 }
375
376 /**
377 * Creates an event on the authenticated user's default calendar with the
378 * specified event details.
379 *
380 * @param Zend_Http_Client $client The authenticated client object
381 * @param string $title The event title
382 * @param string $desc The detailed description of the event
383 * @param string $where
384 * @param string $startDate The start date of the event in YYYY-MM-DD format
385 * @param string $startTime The start time of the event in HH:MM 24hr format
386 * @param string $endDate The end date of the event in YYYY-MM-DD format
387 * @param string $endTime The end time of the event in HH:MM 24hr format
388 * @param string $tzOffset The offset from GMT/UTC in [+-]DD format (eg -08)
389 * @return string The ID URL for the event.
390 */
391 function createEvent ($client, $title = 'Tennis with Beth',
392 $desc='Meet for a quick lesson', $where = 'On the courts',
393 $startDate = '2008-01-20', $startTime = '10:00',
394 $endDate = '2008-01-20', $endTime = '11:00', $tzOffset = '-08')
395 {
396 $gc = new Zend_Gdata_Calendar($client);
397 $newEntry = $gc->newEventEntry();
398 $newEntry->title = $gc->newTitle(trim($title));
399 $newEntry->where = array($gc->newWhere($where));
400
401 $newEntry->content = $gc->newContent($desc);
402 $newEntry->content->type = 'text';
403
404 $when = $gc->newWhen();
405 $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
406 $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
407 $newEntry->when = array($when);
408
409 $createdEntry = $gc->insertEvent($newEntry);
410 return $createdEntry->id->text;
411 }
412
413 /**
414 * Creates an event on the authenticated user's default calendar using
415 * the specified QuickAdd string.
416 *
417 * @param Zend_Http_Client $client The authenticated client object
418 * @param string $quickAddText The QuickAdd text for the event
419 * @return string The ID URL for the event
420 */
421 function createQuickAddEvent ($client, $quickAddText) {
422 $gdataCal = new Zend_Gdata_Calendar($client);
423 $event = $gdataCal->newEventEntry();
424 $event->content = $gdataCal->newContent($quickAddText);
425 $event->quickAdd = $gdataCal->newQuickAdd(true);
426
427 $newEvent = $gdataCal->insertEvent($event);
428 return $newEvent->id->text;
429 }
430
431 /**
432 * Creates a new web content event on the authenticated user's default
433 * calendar with the specified event details. For simplicity, the event
434 * is created as an all day event and does not include a description.
435 *
436 * @param Zend_Http_Client $client The authenticated client object
437 * @param string $title The event title
438 * @param string $startDate The start date of the event in YYYY-MM-DD format
439 * @param string $endDate The end time of the event in HH:MM 24hr format
440 * @param string $icon URL pointing to a 16x16 px icon representing the event.
441 * @param string $url The URL containing the web content for the event.
442 * @param string $height The desired height of the web content pane.
443 * @param string $width The desired width of the web content pane.
444 * @param string $type The MIME type of the web content.
445 * @return string The ID URL for the event.
446 */
447 function createWebContentEvent ($client, $title = 'World Cup 2006',
448 $startDate = '2006-06-09', $endDate = '2006-06-09',
449 $icon = 'http://www.google.com/calendar/images/google-holiday.gif',
450 $url = 'http://www.google.com/logos/worldcup06.gif',
451 $height = '120', $width = '276', $type = 'image/gif'
452 )
453 {
454 $gc = new Zend_Gdata_Calendar($client);
455 $newEntry = $gc->newEventEntry();
456 $newEntry->title = $gc->newTitle(trim($title));
457
458 $when = $gc->newWhen();
459 $when->startTime = $startDate;
460 $when->endTime = $endDate;
461 $newEntry->when = array($when);
462
463 $wc = $gc->newWebContent();
464 $wc->url = $url;
465 $wc->height = $height;
466 $wc->width = $width;
467
468 $wcLink = $gc->newLink();
469 $wcLink->rel = "http://schemas.google.com/gCal/2005/webContent";
470 $wcLink->title = $title;
471 $wcLink->type = $type;
472 $wcLink->href = $icon;
473
474 $wcLink->webContent = $wc;
475 $newEntry->link = array($wcLink);
476
477 $createdEntry = $gc->insertEvent($newEntry);
478 return $createdEntry->id->text;
479 }
480
481 /**
482 * Creates a recurring event on the authenticated user's default calendar with
483 * the specified event details.
484 *
485 * @param Zend_Http_Client $client The authenticated client object
486 * @param string $title The event title
487 * @param string $desc The detailed description of the event
488 * @param string $where
489 * @param string $recurData The iCalendar recurring event syntax (RFC2445)
490 * @return void
491 */
492 function createRecurringEvent ($client, $title = 'Tennis with Beth',
493 $desc='Meet for a quick lesson', $where = 'On the courts',
494 $recurData = null)
495 {
496 $gc = new Zend_Gdata_Calendar($client);
497 $newEntry = $gc->newEventEntry();
498 $newEntry->title = $gc->newTitle(trim($title));
499 $newEntry->where = array($gc->newWhere($where));
500
501 $newEntry->content = $gc->newContent($desc);
502 $newEntry->content->type = 'text';
503
504 /**
505 * Due to the length of this recurrence syntax, we did not specify
506 * it as a default parameter value directly
507 */
508 if ($recurData == null) {
509 $recurData =
510 "DTSTART;VALUE=DATE:20070501\r\n" .
511 "DTEND;VALUE=DATE:20070502\r\n" .
512 "RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20070904\r\n";
513 }
514
515 $newEntry->recurrence = $gc->newRecurrence($recurData);
516
517 $gc->post($newEntry->saveXML());
518 }
519
520 /**
521 * Returns an entry object representing the event with the specified ID.
522 *
523 * @param Zend_Http_Client $client The authenticated client object
524 * @param string $eventId The event ID string
525 * @return Zend_Gdata_Calendar_EventEntry|null if the event is found, null if it's not
526 */
527 function getEvent($client, $eventId)
528 {
529 $gdataCal = new Zend_Gdata_Calendar($client);
530 $query = $gdataCal->newEventQuery();
531 $query->setUser('default');
532 $query->setVisibility('private');
533 $query->setProjection('full');
534 $query->setEvent($eventId);
535
536 try {
537 $eventEntry = $gdataCal->getCalendarEventEntry($query);
538 return $eventEntry;
539 } catch (Zend_Gdata_App_Exception $e) {
540 var_dump($e);
541 return null;
542 }
543 }
544
545 /**
546 * Updates the title of the event with the specified ID to be
547 * the title specified. Also outputs the new and old title
548 * with HTML br elements separating the lines
549 *
550 * @param Zend_Http_Client $client The authenticated client object
551 * @param string $eventId The event ID string
552 * @param string $newTitle The new title to set on this event
553 * @return Zend_Gdata_Calendar_EventEntry|null The updated entry
554 */
555 function updateEvent ($client, $eventId, $newTitle)
556 {
557 $gdataCal = new Zend_Gdata_Calendar($client);
558 if ($eventOld = getEvent($client, $eventId)) {
559 echo "Old title: " . $eventOld->title->text . "<br />\n";
560 $eventOld->title = $gdataCal->newTitle($newTitle);
561 try {
562 $eventOld->save();
563 } catch (Zend_Gdata_App_Exception $e) {
564 var_dump($e);
565 return null;
566 }
567 $eventNew = getEvent($client, $eventId);
568 echo "New title: " . $eventNew->title->text . "<br />\n";
569 return $eventNew;
570 } else {
571 return null;
572 }
573 }
574
575 /**
576 * Adds an extended property to the event specified as a parameter.
577 * An extended property is an arbitrary name/value pair that can be added
578 * to an event and retrieved via the API. It is not accessible from the
579 * calendar web interface.
580 *
581 * @param Zend_Http_Client $client The authenticated client object
582 * @param string $eventId The event ID string
583 * @param string $name The name of the extended property
584 * @param string $value The value of the extended property
585 * @return Zend_Gdata_Calendar_EventEntry|null The updated entry
586 */
587 function addExtendedProperty ($client, $eventId,
588 $name='http://www.example.com/schemas/2005#mycal.id', $value='1234')
589 {
590 $gc = new Zend_Gdata_Calendar($client);
591 if ($event = getEvent($client, $eventId)) {
592 $extProp = $gc->newExtendedProperty($name, $value);
593 $extProps = array_merge($event->extendedProperty, array($extProp));
594 $event->extendedProperty = $extProps;
595 $eventNew = $event->save();
596 return $eventNew;
597 } else {
598 return null;
599 }
600 }
601
602
603 /**
604 * Adds a reminder to the event specified as a parameter.
605 *
606 * @param Zend_Http_Client $client The authenticated client object
607 * @param string $eventId The event ID string
608 * @param integer $minutes Minutes before event to set reminder
609 * @return Zend_Gdata_Calendar_EventEntry|null The updated entry
610 */
611 function setReminder($client, $eventId, $minutes=15)
612 {
613 $gc = new Zend_Gdata_Calendar($client);
614 $method = "alert";
615 if ($event = getEvent($client, $eventId)) {
616 $times = $event->when;
617 foreach ($times as $when) {
618 $reminder = $gc->newReminder();
619 $reminder->setMinutes($minutes);
620 $reminder->setMethod($method);
621 $when->reminder = array($reminder);
622 }
623 $eventNew = $event->save();
624 return $eventNew;
625 } else {
626 return null;
627 }
628 }
629
630 /**
631 * Deletes the event specified by retrieving the atom entry object
632 * and calling Zend_Feed_EntryAtom::delete() method. This is for
633 * example purposes only, as it is inefficient to retrieve the entire
634 * atom entry only for the purposes of deleting it.
635 *
636 * @param Zend_Http_Client $client The authenticated client object
637 * @param string $eventId The event ID string
638 * @return void
639 */
640 function deleteEventById ($client, $eventId)
641 {
642 $event = getEvent($client, $eventId);
643 $event->delete();
644 }
645
646 /**
647 * Deletes the event specified by calling the Zend_Gdata::delete()
648 * method. The URL is typically in the format of:
649 * http://www.google.com/calendar/feeds/default/private/full/<eventId>
650 *
651 * @param Zend_Http_Client $client The authenticated client object
652 * @param string $url The url for the event to be deleted
653 * @return void
654 */
655 function deleteEventByUrl ($client, $url)
656 {
657 $gdataCal = new Zend_Gdata_Calendar($client);
658 $gdataCal->delete($url);
659 }
660
661 /**
662 * Main logic for running this sample code via the command line or,
663 * for AuthSub functionality only, via a web browser. The output of
664 * many of the functions is in HTML format for demonstration purposes,
665 * so you may wish to pipe the output to Tidy when running from the
666 * command-line for clearer results.
667 *
668 * Run without any arguments to get usage information
669 */
670 if (isset($argc) && $argc >= 2) {
671 switch ($argv[1]) {
672 case 'outputCalendar':
673 if ($argc == 4) {
674 $client = getClientLoginHttpClient($argv[2], $argv[3]);
675 outputCalendar($client);
676 } else {
677 echo "Usage: php {$argv[0]} {$argv[1]} " .
678 "<username> <password>\n";
679 }
680 break;
681 case 'outputCalendarMagicCookie':
682 if ($argc == 4) {
683 outputCalendarMagicCookie($argv[2], $argv[3]);
684 } else {
685 echo "Usage: php {$argv[0]} {$argv[1]} " .
686 "<username> <magicCookie>\n";
687 }
688 break;
689 case 'outputCalendarByDateRange':
690 if ($argc == 6) {
691 $client = getClientLoginHttpClient($argv[2], $argv[3]);
692 outputCalendarByDateRange($client, $argv[4], $argv[5]);
693 } else {
694 echo "Usage: php {$argv[0]} {$argv[1]} " .
695 "<username> <password> <startDate> <endDate>\n";
696 }
697 break;
698 case 'outputCalendarByFullTextQuery':
699 if ($argc == 5) {
700 $client = getClientLoginHttpClient($argv[2], $argv[3]);
701 outputCalendarByFullTextQuery($client, $argv[4]);
702 } else {
703 echo "Usage: php {$argv[0]} {$argv[1]} " .
704 "<username> <password> <fullTextQuery>\n";
705 }
706 break;
707 case 'outputCalendarList':
708 if ($argc == 4) {
709 $client = getClientLoginHttpClient($argv[2], $argv[3]);
710 outputCalendarList($client);
711 } else {
712 echo "Usage: php {$argv[0]} {$argv[1]} " .
713 "<username> <password>\n";
714 }
715 break;
716 case 'updateEvent':
717 if ($argc == 6) {
718 $client = getClientLoginHttpClient($argv[2], $argv[3]);
719 updateEvent($client, $argv[4], $argv[5]);
720 } else {
721 echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " .
722 "<eventId> <newTitle>\n";
723 }
724 break;
725 case 'setReminder':
726 if ($argc == 6) {
727 $client = getClientLoginHttpClient($argv[2], $argv[3]);
728 setReminder($client, $argv[4], $argv[5]);
729 } else {
730 echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " .
731 "<eventId> <minutes>\n";
732 }
733 break;
734 case 'addExtendedProperty':
735 if ($argc == 7) {
736 $client = getClientLoginHttpClient($argv[2], $argv[3]);
737 addExtendedProperty($client, $argv[4], $argv[5], $argv[6]);
738 } else {
739 echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " .
740 "<eventId> <name> <value>\n";
741 }
742 break;
743 case 'deleteEventById':
744 if ($argc == 5) {
745 $client = getClientLoginHttpClient($argv[2], $argv[3]);
746 deleteEventById($client, $argv[4]);
747 } else {
748 echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " .
749 "<eventId>\n";
750 }
751 break;
752 case 'deleteEventByUrl':
753 if ($argc == 5) {
754 $client = getClientLoginHttpClient($argv[2], $argv[3]);
755 deleteEventByUrl($client, $argv[4]);
756 } else {
757 echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " .
758 "<eventUrl>\n";
759 }
760 break;
761 case 'createEvent':
762 if ($argc == 12) {
763 $client = getClientLoginHttpClient($argv[2], $argv[3]);
764 $id = createEvent($client, $argv[4], $argv[5], $argv[6], $argv[7],
765 $argv[8], $argv[9], $argv[10], $argv[11]);
766 print "Event created with ID: $id\n";
767 } else {
768 echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " .
769 "<title> <description> <where> " .
770 "<startDate> <startTime> <endDate> <endTime> <tzOffset>\n";
771 echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <password> " .
772 "'Tennis with Beth' 'Meet for a quick lesson' 'On the courts' " .
773 "'2008-01-01' '10:00' '2008-01-01' '11:00' '-08'\n";
774 }
775 break;
776 case 'createQuickAddEvent':
777 if ($argc == 5) {
778 $client = getClientLoginHttpClient($argv[2], $argv[3]);
779 $id = createQuickAddEvent($client, $argv[4]);
780 print "Event created with ID: $id\n";
781 } else {
782 echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " .
783 "<quickAddText>\n";
784 echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <password> " .
785 "'Dinner at the beach on Thursday 8 PM'\n";
786 }
787 break;
788 case 'createWebContentEvent':
789 if ($argc == 12) {
790 $client = getClientLoginHttpClient($argv[2], $argv[3]);
791 $id = createWebContentEvent($client, $argv[4], $argv[5], $argv[6],
792 $argv[7], $argv[8], $argv[9], $argv[10], $argv[11]);
793 print "Event created with ID: $id\n";
794 } else {
795 echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " .
796 "<title> <startDate> <endDate> <icon> <url> <height> <width> <type>\n\n";
797 echo "This creates a web content event on 2007/06/09.\n";
798 echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <password> " .
799 "'World Cup 2006' '2007-06-09' '2007-06-10' " .
800 "'http://www.google.com/calendar/images/google-holiday.gif' " .
801 "'http://www.google.com/logos/worldcup06.gif' " .
802 "'120' '276' 'image/gif'\n";
803 }
804 break;
805 case 'createRecurringEvent':
806 if ($argc == 7) {
807 $client = getClientLoginHttpClient($argv[2], $argv[3]);
808 createRecurringEvent($client, $argv[4], $argv[5], $argv[6]);
809 } else {
810 echo "Usage: php {$argv[0]} {$argv[1]} <username> <password> " .
811 "<title> <description> <where>\n\n";
812 echo "This creates an all-day event which occurs first on 2007/05/01" .
813 "and repeats weekly on Tuesdays until 2007/09/04\n";
814 echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <password> " .
815 "'Tennis with Beth' 'Meet for a quick lesson' 'On the courts'\n";
816 }
817 break;
818 }
819 } else if (!isset($_SERVER["HTTP_HOST"])) {
820 // running from command line, but action left unspecified
821 echo "Usage: php {$argv[0]} <action> [<username>] [<password>] " .
822 "[<arg1> <arg2> ...]\n\n";
823 echo "Possible action values include:\n" .
824 "outputCalendar\n" .
825 "outputCalendarMagicCookie\n" .
826 "outputCalendarByDateRange\n" .
827 "outputCalendarByFullTextQuery\n" .
828 "outputCalendarList\n" .
829 "updateEvent\n" .
830 "deleteEventById\n" .
831 "deleteEventByUrl\n" .
832 "createEvent\n" .
833 "createQuickAddEvent\n" .
834 "createWebContentEvent\n" .
835 "createRecurringEvent\n" .
836 "setReminder\n" .
837 "addExtendedProperty\n";
838 } else {
839 // running through web server - demonstrate AuthSub
840 processPageLoad();
841 }