started implementing import - not working atm

This commit is contained in:
Christoph Haas 2016-06-23 22:50:36 +02:00
parent c0debc99fc
commit 746278f891
2 changed files with 102 additions and 8 deletions

View File

@ -620,7 +620,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
buttons : Zarafa.common.dialogs.MessageBox.OK
});
} else {
var calendarFolder = this.getContactFolderByEntryid(folderValue);
var calendarFolder = this.getCalendarFolderByEntryid(calValue);
this.loadMask.show();
var uids = [];
@ -630,7 +630,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
uids.push(newRecord.data.record.internal_fields.event_uid);
}, this);
var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
var responseHandler = new Zarafa.plugins.calendarimporter.data.ResponseHandler({
successCallback: this.importEventsDone,
scope: this
});
@ -639,10 +639,10 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
'calendarmodule',
'import',
{
storeid : contactFolder.store_entryid,
folderid : contactFolder.entryid,
storeid : calendarFolder.store_entryid,
folderid : calendarFolder.entryid,
uids : uids,
vcf_filepath: this.vcffile
ics_filepath: this.icsfile
},
responseHandler
);
@ -655,8 +655,10 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
* @param {Object} response
*/
importEventsDone: function (response) {
this.loadMask.hide();
this.dialog.close();
var self = this.scope;
self.loadMask.hide();
self.dialog.close();
if (response.status == true) {
container.getNotifier().notify('info', 'Imported', 'Imported ' + response.count + ' events. Please reload your calendar!');
} else {

View File

@ -354,7 +354,99 @@ class CalendarModule extends Module
*/
private function importCalendar($actionType, $actionData)
{
// TODO: implement
// Get uploaded vcf path
$icsfile = false;
if (isset($actionData["ics_filepath"])) {
$icsfile = $actionData["ics_filepath"];
}
// Get store id
$storeid = false;
if (isset($actionData["storeid"])) {
$storeid = $actionData["storeid"];
}
// Get folder entryid
$folderid = false;
if (isset($actionData["folderid"])) {
$folderid = $actionData["folderid"];
}
// Get uids
$uids = array();
if (isset($actionData["uids"])) {
$uids = $actionData["uids"];
}
$response = array();
$error = false;
$error_msg = "";
// parse the ics file a last time...
$parser = null;
try {
$parser = VObject\Reader::read(
fopen($icsfile,'r')
);
} catch (Exception $e) {
$error = true;
$error_msg = $e->getMessage();
}
$events = array();
if (count($parser->VEVENT) > 0) {
$events = $this->parseCalendarToArray($parser);
$store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeid));
$folder = mapi_msgstore_openentry($store, hex2bin($folderid));
$importall = false;
if (count($uids) == count($events)) {
$importall = true;
}
$propValuesMAPI = array();
$properties = $GLOBALS['properties']->getAppointmentProperties();
$count = 0;
// iterate through all events and import them :)
foreach ($events as $event) {
if (isset($event["startdate"]) && ($importall || in_array($event["internal_fields"]["event_uid"], $uids))) {
// parse the arraykeys
// TODO: this is very slow...
foreach ($events as $key => $value) {
if ($key !== "internal_fields") {
if(isset($properties[$key])) {
$propValuesMAPI[$properties[$key]] = $value;
}
}
}
$propValuesMAPI[$properties["message_class"]] = "IPM.Appointment";
$propValuesMAPI[$properties["icon_index"]] = "1024";
$message = mapi_folder_createmessage($folder);
mapi_setprops($message, $propValuesMAPI);
mapi_savechanges($message);
if ($this->DEBUG) {
error_log("New event added: \"" . $propValuesMAPI[$properties["startdate"]] . "\".\n");
}
$count++;
}
}
$response['status'] = true;
$response['count'] = $count;
$response['message'] = "";
} else {
$response['status'] = false;
$response['count'] = 0;
$response['message'] = $error ? $error_msg : "ICS file empty!";
}
$this->addActionData($actionType, $response);
$GLOBALS["bus"]->addData($this->getResponseData());
}
/**