1<?php
2/**
3 * @package tikiwiki
4 */
5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6//
7// All Rights Reserved. See copyright.txt for details and a complete list of authors.
8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9// $Id$
10
11require_once('tiki-setup.php');
12include_once('lib/minical/minicallib.php');
13if ($prefs['feature_minical'] != 'y') {
14	die;
15}
16if (! $user) {
17	die;
18}
19/**
20 * @param $item
21 * @return string
22 */
23function _csv($item)
24{
25	$item = str_replace('"', '""', $item);
26	//  if (strpos($item, ",") !== FALSE) {
27	$item = '"' . $item . '"';
28	//  }
29	return $item;
30}
31$events = $minicallib->minical_list_events($user, 0, -1, 'start_desc', '');
32header("Content-type: text/plain");
33//header( "Content-Disposition: attachment; filename=$file" );
34header("Content-Disposition: inline; filename=tiki-calendar");
35print ('"Subject","Start Date","Start Time","End Date","End Time","All day event","Reminder on/off","Reminder Date","Reminder Time","Meeting Organizer","Required Attendees","Optional Attendees","Meeting Resources","Billing Information","Categories","Description","Location","Mileage","Priority","Private","Sensitivity","Show time as"');
36print ("\r\n");
37foreach ($events['data'] as $event) {
38	$line = [];
39	$line[] = _csv($event['title']);
40	$line[] = _csv(date("n/j/Y", $event['start']));
41	$line[] = _csv(date("g:i:s A", $event['start']));
42	$line[] = _csv(date("n/j/Y", $event['end']));
43	$line[] = _csv(date("g:i:s A", $event['end']));
44	$line[] = _csv('False');
45	if ($prefs['minical_reminders']) {
46		$line[] = _csv('True');
47		$line[] = _csv(date("n/j/Y", $event['start'] - $prefs['minical_reminders']));
48		$line[] = _csv(date("g:i:s A", $event['start'] - $prefs['minical_reminders']));
49	} else {
50		$line[] = _csv('False');
51		$line[] = _csv('');
52		$line[] = _csv('');
53	}
54	$line[] = '';
55	$line[] = '';
56	$line[] = '';
57	$line[] = '';
58	$line[] = '';
59	$line[] = '';
60	$line[] = '';
61	$line[] = _csv($event['description']);
62	$line[] = '';
63	$line[] = _csv('Normal');
64	$line[] = _csv('False');
65	$line[] = _csv('Normal');
66	$line[] = _csv('2');
67	$theline = join(',', $line);
68	print ($theline);
69	print ("\r\n");
70}
71