calendar choosing, timezone fix, import all
this is version 1.0 =)
This commit is contained in:
parent
af3fcfb457
commit
e64d8415bc
@ -34,6 +34,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
this.initForm()
|
||||
],
|
||||
buttons: [
|
||||
this.createSubmitAllButton(),
|
||||
this.createSubmitButton(),
|
||||
this.createCancelButton()
|
||||
]
|
||||
@ -81,7 +82,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
var parsedData = new Array(eventdata.events.length);
|
||||
|
||||
for(var i=0; i < eventdata.events.length; i++) {
|
||||
parsedData[i] = new Array(eventdata.events[i]["SUMMARY"], parseInt(eventdata.events[i]["DTSTART"]), parseInt(eventdata.events[i]["DTEND"]), eventdata.events[i]["LOCATION"], eventdata.events[i]["DESCRIPTION"]);
|
||||
parsedData[i] = new Array(eventdata.events[i]["SUMMARY"], new Date(parseInt(eventdata.events[i]["DTSTART"])), new Date(parseInt(eventdata.events[i]["DTEND"])), eventdata.events[i]["LOCATION"], eventdata.events[i]["DESCRIPTION"]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +128,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
createSelectBox: function() {
|
||||
ctx = container.getContextByName('calendar');
|
||||
model = ctx.getModel();
|
||||
defaultFolder = model.getDefaultFolder();
|
||||
defaultFolder = model.getDefaultFolder(); // @type: Zarafa.hierarchy.data.MAPIFolderRecord
|
||||
subFolders = defaultFolder.getChildren();
|
||||
|
||||
var myStore = new Ext.data.ArrayStore({
|
||||
@ -162,6 +163,8 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
|
||||
return {
|
||||
xtype: "selectbox",
|
||||
ref: 'calendarselector',
|
||||
id: 'calendarselector',
|
||||
editable: false,
|
||||
name: "choosen_calendar",
|
||||
width: 100,
|
||||
@ -206,6 +209,22 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
border: false,
|
||||
text: _("Import"),
|
||||
anchor: "100%",
|
||||
handler: this.importCheckedEvents,
|
||||
scope: this,
|
||||
allowBlank: false
|
||||
}
|
||||
},
|
||||
|
||||
createSubmitAllButton: function() {
|
||||
return {
|
||||
xtype: "button",
|
||||
ref: "submitAllButton",
|
||||
id: "submitAllButton",
|
||||
disabled: true,
|
||||
width: 100,
|
||||
border: false,
|
||||
text: _("Import All"),
|
||||
anchor: "100%",
|
||||
handler: this.importAllEvents,
|
||||
scope: this,
|
||||
allowBlank: false
|
||||
@ -238,7 +257,8 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
waitMsg: 'Uploading and parsing calendar...',
|
||||
url: 'plugins/calendarimporter/php/upload.php',
|
||||
failure: function(file, action) {
|
||||
Ext.getCmp('submitButton').disable(); // momstly called...
|
||||
Ext.getCmp('submitButton').disable();
|
||||
Ext.getCmp('submitAllButton').disable();
|
||||
Ext.MessageBox.show({
|
||||
title : _('Error'),
|
||||
msg : _(action.result.errors[action.result.errors.type]),
|
||||
@ -249,6 +269,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
success: function(file, action){
|
||||
uploadField.reset();
|
||||
Ext.getCmp('submitButton').enable();
|
||||
Ext.getCmp('submitAllButton').enable();
|
||||
this.timezone = action.result.response.calendar["X-WR-TIMEZONE"];
|
||||
this.insert(this.items.length,this.createGrid(action.result.response));
|
||||
this.doLayout();
|
||||
@ -286,20 +307,92 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
|
||||
importAllEvents: function () {
|
||||
//receive existing calendar store
|
||||
var selIndex = this.calendarselector.selectedIndex;
|
||||
var calValue = this.calendarselector.value;
|
||||
|
||||
if(selIndex == -1) { // no calendar choosen
|
||||
Ext.MessageBox.show({
|
||||
title : _('Error'),
|
||||
msg : _('You have to choose a calendar!'),
|
||||
icon : Ext.MessageBox.ERROR,
|
||||
buttons : Ext.MessageBox.OK
|
||||
});
|
||||
} else {
|
||||
|
||||
var calendarStore = new Zarafa.calendar.AppointmentStore();
|
||||
var calendarFolder = container.getHierarchyStore().getDefaultFolder('calendar');
|
||||
if(calValue != "calendar") {
|
||||
var subFolders = calendarFolder.getChildren();
|
||||
|
||||
for(i=0;i<subFolders.length;i++) {
|
||||
// loo up right folder
|
||||
// TODO: improve!!
|
||||
if(subFolders[i].getDisplayName() == calValue) {
|
||||
calendarFolder = subFolders[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//receive Records from grid rows
|
||||
this.eventgrid.selModel.selectAll(); // select all entries
|
||||
var newRecords = this.eventgrid.selModel.getSelections();
|
||||
Ext.each(newRecords, function(newRecord) {
|
||||
var record = this.convertToAppointmentRecord(calendarFolder,newRecord.data);
|
||||
console.log(record);
|
||||
calendarStore.add(record);
|
||||
}, this);
|
||||
calendarStore.save();
|
||||
this.dialog.close();
|
||||
}
|
||||
},
|
||||
|
||||
importCheckedEvents: function () {
|
||||
//receive existing calendar store
|
||||
var selIndex = this.calendarselector.selectedIndex;
|
||||
var calValue = this.calendarselector.value;
|
||||
|
||||
if(selIndex == -1) { // no calendar choosen
|
||||
Ext.MessageBox.show({
|
||||
title : _('Error'),
|
||||
msg : _('You have to choose a calendar!'),
|
||||
icon : Ext.MessageBox.ERROR,
|
||||
buttons : Ext.MessageBox.OK
|
||||
});
|
||||
} else {
|
||||
if(this.eventgrid.selModel.getCount() < 1) {
|
||||
Ext.MessageBox.show({
|
||||
title : _('Error'),
|
||||
msg : _('You have to choose at least one event to import!'),
|
||||
icon : Ext.MessageBox.ERROR,
|
||||
buttons : Ext.MessageBox.OK
|
||||
});
|
||||
} else {
|
||||
var calendarStore = new Zarafa.calendar.AppointmentStore();
|
||||
var calendarFolder = container.getHierarchyStore().getDefaultFolder('calendar');
|
||||
if(calValue != "calendar") {
|
||||
var subFolders = calendarFolder.getChildren();
|
||||
|
||||
for(i=0;i<subFolders.length;i++) {
|
||||
// loo up right folder
|
||||
// TODO: improve!!
|
||||
if(subFolders[i].getDisplayName() == calValue) {
|
||||
calendarFolder = subFolders[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//receive Records from grid rows
|
||||
var newRecords = this.eventgrid.selModel.getSelections();
|
||||
Ext.each(newRecords, function(newRecord) {
|
||||
var record = this.convertToAppointmentRecord(calendarFolder,newRecord.data);
|
||||
calendarStore.add(record);
|
||||
}, this);
|
||||
calendarStore.save();
|
||||
this.dialog.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ext.reg('calendarimporter.importpanel', Zarafa.plugins.calendarimporter.dialogs.ImportPanel);
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE plugin SYSTEM "manifest.dtd">
|
||||
<plugin version="2">
|
||||
<info>
|
||||
<version>0.1</version>
|
||||
<version>1.0</version>
|
||||
<name>calendarimporter</name>
|
||||
<title>ICS Calendar Importer</title>
|
||||
<author>Christoph Haas</author>
|
||||
|
@ -5,10 +5,12 @@
|
||||
* PHP Version 5
|
||||
*
|
||||
* @category Parser
|
||||
* @author Martin Thoma
|
||||
* @author Christoph Haas <mail@h44z.net>
|
||||
* @modified 17.11.2012 by Christoph Haas (original at http://code.google.com/p/ics-parser/)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
* @version SVN: 13
|
||||
* @example $ical = new ical('MyCal.ics');
|
||||
* @version SVN: 16
|
||||
* @example $ical = new ical('calendar.ics');
|
||||
* print_r( $ical->events() );
|
||||
*/
|
||||
|
||||
@ -18,8 +20,7 @@
|
||||
* @param {string} filename The name of the file which should be parsed
|
||||
* @constructor
|
||||
*/
|
||||
class ICal
|
||||
{
|
||||
class ICal {
|
||||
/* How many ToDos are in this ical? */
|
||||
public /** @type {int} */ $todo_count = 0;
|
||||
|
||||
@ -35,6 +36,9 @@ class ICal
|
||||
/* Which keyword has been added to cal at last? */
|
||||
private /** @type {string} */ $_lastKeyWord;
|
||||
|
||||
/* The default timezone, used to convert UTC Time */
|
||||
private /** @type {string} */ $default_timezone = "Europe/Vienna";
|
||||
|
||||
/**
|
||||
* Creates the iCal-Object
|
||||
*
|
||||
@ -42,8 +46,7 @@ class ICal
|
||||
*
|
||||
* @return Object The iCal-Object
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
public function __construct($filename) {
|
||||
if (!$filename) {
|
||||
$this->errors = "No filename specified";
|
||||
return false;
|
||||
@ -54,7 +57,7 @@ class ICal
|
||||
$this->errors = "Not a valid ical file";
|
||||
return false;
|
||||
} else {
|
||||
// TODO: Fix multiline-description problem (see http://tools.ietf.org/html/rfc2445#section-4.8.1.5)
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
$add = $this->keyValueFromString($line);
|
||||
@ -96,80 +99,7 @@ class ICal
|
||||
$type = "VCALENDAR";
|
||||
break;
|
||||
default:
|
||||
$this->addCalendarComponentWithKeyAndValue($type,
|
||||
$keyword,
|
||||
$value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $this->cal;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the iCal-Object
|
||||
*
|
||||
* @param {string} $filecontent The content of the iCal-file
|
||||
*
|
||||
* @return Object The iCal-Object
|
||||
*/
|
||||
public function setContent($filecontent)
|
||||
{
|
||||
if (!$filecontent) {
|
||||
$this->errors = "No filecontent";
|
||||
return false;
|
||||
}
|
||||
|
||||
$lines = explode("\n", $filecontent);
|
||||
if (stristr($lines[0], 'BEGIN:VCALENDAR') === false) {
|
||||
$this->errors = "Not a valid ical file";
|
||||
return false;
|
||||
} else {
|
||||
// TODO: Fix multiline-description problem (see http://tools.ietf.org/html/rfc2445#section-4.8.1.5)
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
$add = $this->keyValueFromString($line);
|
||||
if ($add === false) {
|
||||
$this->addCalendarComponentWithKeyAndValue($type, false, $line);
|
||||
continue;
|
||||
}
|
||||
|
||||
list($keyword, $value) = $add;
|
||||
|
||||
switch ($line) {
|
||||
// http://www.kanzaki.com/docs/ical/vtodo.html
|
||||
case "BEGIN:VTODO":
|
||||
$this->todo_count++;
|
||||
$type = "VTODO";
|
||||
break;
|
||||
|
||||
// http://www.kanzaki.com/docs/ical/vevent.html
|
||||
case "BEGIN:VEVENT":
|
||||
//echo "vevent gematcht";
|
||||
$this->event_count++;
|
||||
$type = "VEVENT";
|
||||
break;
|
||||
|
||||
//all other special strings
|
||||
case "BEGIN:VCALENDAR":
|
||||
case "BEGIN:DAYLIGHT":
|
||||
// http://www.kanzaki.com/docs/ical/vtimezone.html
|
||||
case "BEGIN:VTIMEZONE":
|
||||
case "BEGIN:STANDARD":
|
||||
$type = $value;
|
||||
break;
|
||||
case "END:VTODO": // end special text - goto VCALENDAR key
|
||||
case "END:VEVENT":
|
||||
case "END:VCALENDAR":
|
||||
case "END:DAYLIGHT":
|
||||
case "END:VTIMEZONE":
|
||||
case "END:STANDARD":
|
||||
$type = "VCALENDAR";
|
||||
break;
|
||||
default:
|
||||
$this->addCalendarComponentWithKeyAndValue($type,
|
||||
$keyword,
|
||||
$value);
|
||||
$this->addCalendarComponentWithKeyAndValue($type, $keyword, $value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -186,10 +116,7 @@ class ICal
|
||||
*
|
||||
* @return {None}
|
||||
*/
|
||||
public function addCalendarComponentWithKeyAndValue($component,
|
||||
$keyword,
|
||||
$value)
|
||||
{
|
||||
public function addCalendarComponentWithKeyAndValue($component, $keyword, $value) {
|
||||
if ($keyword == false) {
|
||||
$keyword = $this->last_keyword;
|
||||
|
||||
@ -215,6 +142,10 @@ class ICal
|
||||
$keyword = $keyword[0]; // remove additional content like VALUE=DATE
|
||||
}
|
||||
|
||||
if (stristr($keyword, "TIMEZONE")) {
|
||||
$this->default_timezone = $value; // store the calendertimezone
|
||||
}
|
||||
|
||||
switch ($component) {
|
||||
case "VTODO":
|
||||
$this->cal[$component][$this->todo_count - 1][$keyword] = $value;
|
||||
@ -242,10 +173,8 @@ class ICal
|
||||
*
|
||||
* @return {array} array("VCALENDAR", "Begin")
|
||||
*/
|
||||
public function keyValueFromString($text)
|
||||
{
|
||||
public function keyValueFromString($text) {
|
||||
preg_match("/(^[^a-z:]+)[:]([\w\W]*)/", $text, $matches);
|
||||
error_log("Matching: " . count($matches) . " " . $text);
|
||||
if (count($matches) == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -261,8 +190,7 @@ class ICal
|
||||
*
|
||||
* @return {int}
|
||||
*/
|
||||
public function iCalDateToUnixTimestamp($icalDate)
|
||||
{
|
||||
public function iCalDateToUnixTimestamp($icalDate) {
|
||||
$icalDate = str_replace('T', '', $icalDate);
|
||||
$icalDate = str_replace('Z', '', $icalDate);
|
||||
|
||||
@ -286,7 +214,15 @@ class ICal
|
||||
(int)$date[2],
|
||||
(int)$date[3],
|
||||
(int)$date[1]);
|
||||
return $timestamp;
|
||||
|
||||
|
||||
$utcdate = new DateTime();
|
||||
$utcdate->setTimestamp($timestamp);
|
||||
$utcdate->setTimezone(new DateTimeZone($this->default_timezone));
|
||||
$utcoffset = $utcdate->getOffset();
|
||||
|
||||
|
||||
return ($timestamp + $utcoffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -295,8 +231,7 @@ class ICal
|
||||
*
|
||||
* @return {array}
|
||||
*/
|
||||
public function events()
|
||||
{
|
||||
public function events() {
|
||||
$array = $this->cal;
|
||||
return $array['VEVENT'];
|
||||
}
|
||||
@ -306,8 +241,7 @@ class ICal
|
||||
*
|
||||
* @return {array}
|
||||
*/
|
||||
public function calendar()
|
||||
{
|
||||
public function calendar() {
|
||||
$array = $this->cal;
|
||||
return $array['VCALENDAR'];
|
||||
}
|
||||
@ -317,8 +251,7 @@ class ICal
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
public function hasEvents()
|
||||
{
|
||||
public function hasEvents() {
|
||||
return ( count($this->events()) > 0 ? true : false );
|
||||
}
|
||||
|
||||
@ -335,8 +268,7 @@ class ICal
|
||||
*
|
||||
* @return {mixed}
|
||||
*/
|
||||
public function eventsFromRange($rangeStart = false, $rangeEnd = false)
|
||||
{
|
||||
public function eventsFromRange($rangeStart = false, $rangeEnd = false) {
|
||||
$events = $this->sortEventsWithOrder($this->events(), SORT_ASC);
|
||||
|
||||
if (!$events) {
|
||||
@ -380,8 +312,7 @@ class ICal
|
||||
*
|
||||
* @return {array}
|
||||
*/
|
||||
public function sortEventsWithOrder($events, $sortOrder = SORT_ASC)
|
||||
{
|
||||
public function sortEventsWithOrder($events, $sortOrder = SORT_ASC) {
|
||||
$extendedEvents = array();
|
||||
|
||||
// loop through all events by adding two new elements
|
||||
|
@ -47,7 +47,7 @@ class Plugincalendarimporter extends Plugin {
|
||||
'plugins' => Array(
|
||||
'calendarimporter' => Array(
|
||||
'enable' => PLUGIN_CALENDARIMPORTER_USER_DEFAULT_ENABLE,
|
||||
'default_calendar' => PLUGIN_CALENDARIMPORTER_DEFAULT
|
||||
'default_calendar' => PLUGIN_CALENDARIMPORTER_DEFAULT // currently not used, maybe in next release
|
||||
)
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user