diff --git a/js/data/ResponseHandler.js b/js/data/ResponseHandler.js index 6b38745..dea5600 100644 --- a/js/data/ResponseHandler.js +++ b/js/data/ResponseHandler.js @@ -55,6 +55,14 @@ Zarafa.plugins.contactimporter.data.ResponseHandler = Ext.extend(Zarafa.core.dat doImport : function(response) { this.successCallback(response); }, + + /** + * Call the successCallback callback function. + * @param {Object} response Object contained the response data. + */ + doExport : function(response) { + this.successCallback(response); + }, /** * Call the successCallback callback function. diff --git a/js/plugin.contactimporter.js b/js/plugin.contactimporter.js index f4588d5..35cc34a 100644 --- a/js/plugin.contactimporter.js +++ b/js/plugin.contactimporter.js @@ -50,6 +50,9 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, { /* add import button to south navigation */ this.registerInsertionPoint("navigation.south", this.createImportButton, this); + + /* export a contact via rightclick */ + this.registerInsertionPoint('context.contact.contextmenu.actions', this.createItemExportInsertionPoint, this); }, /** @@ -74,6 +77,66 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, { return button; }, + + /** + * This method hooks to the contact context menu and allows users to export users to vcf. + * + * @param include + * @param btn + * @returns {Object} + */ + createItemExportInsertionPoint: function (include, btn) { + return { + text : dgettext('plugin_files', 'Export VCF'), + handler: this.exportToVCF.createDelegate(this, [btn]), + scope : this, + iconCls: 'icon_contactimporter_export' + }; + }, + + exportToVCF: function(btn) { + if(btn.records.length == 0) { + return; // skip if no records where given! + } + + var recordIds = []; + + for(var i=0;iimportContacts($actionType, $actionData); break; + case "export": + $result = $this->exportContacts($actionType, $actionData); + break; case "importattachment": $result = $this->getAttachmentPath($actionType, $actionData); break; @@ -240,7 +243,54 @@ class ContactModule extends Module { $this->addActionData($actionType, $response); $GLOBALS["bus"]->addData($this->getResponseData()); } - + + private function exportContacts($actionType, $actionData) + { + // Get store id + $storeid = false; + if (isset($actionData["storeid"])) { + $storeid = $actionData["storeid"]; + } + + // Get records + $records = array(); + if (isset($actionData["records"])) { + $records = $actionData["records"]; + } + + $response = array(); + $error = false; + $error_msg = ""; + + // write csv + $token = $this->randomstring(16); + $file = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD . "vcf_" . $token . ".vcf"; + file_put_contents($file, ""); + + $store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeid)); + if ($store) { + for ($index = 0, $count = count($records); $index < $count; $index++) { + $message = mapi_msgstore_openentry($store, hex2bin($records[$index])); + + // get message properties. + $messageProps = mapi_getprops($message, array(PR_DISPLAY_NAME)); + file_put_contents($file, file_get_contents($file) . $messageProps[PR_DISPLAY_NAME]); + + // TODO: implement vcf + } + } else { + return false; + } + + $response['status'] = true; + $response['download_token'] = $token; + $response['filename'] = "test.csv"; + + $this->addActionData($actionType, $response); + $GLOBALS["bus"]->addData($this->getResponseData()); + } + + private function replaceStringPropertyTags($store, $properties) { $newProperties = array(); diff --git a/php/plugin.contactimporter.php b/php/plugin.contactimporter.php index 623a0cc..031e0fc 100644 --- a/php/plugin.contactimporter.php +++ b/php/plugin.contactimporter.php @@ -20,7 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ - +require_once __DIR__ . "/download.php"; + /** * contactimporter Plugin * @@ -40,6 +41,7 @@ class Plugincontactimporter extends Plugin { */ function init() { $this->registerHook('server.core.settings.init.before'); + $this->registerHook('server.index.load.custom'); } /** @@ -54,6 +56,11 @@ class Plugincontactimporter extends Plugin { case 'server.core.settings.init.before' : $this->injectPluginSettings($data); break; + case 'server.index.load.custom': + if ($data['name'] == 'download_vcf') { + DownloadHandler::doDownload(); + } + break; } }