starting on export feature
This commit is contained in:
parent
8540bd9104
commit
dae8a7e610
@ -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.
|
||||
|
@ -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;i<btn.records.length;i++) {
|
||||
recordIds.push(btn.records[i].get("entryid"));
|
||||
}
|
||||
|
||||
var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
|
||||
successCallback: this.downloadVCF,
|
||||
scope: this
|
||||
});
|
||||
|
||||
// request attachment preperation
|
||||
container.getRequest().singleRequest(
|
||||
'contactmodule',
|
||||
'export',
|
||||
{
|
||||
storeid : btn.records[0].get("store_entryid"),
|
||||
records: recordIds
|
||||
},
|
||||
responseHandler
|
||||
);
|
||||
},
|
||||
|
||||
downloadVCF: function(response) {
|
||||
var downloadFrame = Ext.getBody().createChild({
|
||||
tag: 'iframe',
|
||||
cls: 'x-hidden'
|
||||
});
|
||||
|
||||
var url = document.URL;
|
||||
var link = url.substring(0, url.lastIndexOf('/') + 1);
|
||||
|
||||
link += "index.php?sessionid=" + container.getUser().getSessionId() + "&load=custom&name=download_vcf";
|
||||
link = Ext.urlAppend(link, "token=" + encodeURIComponent(response.download_token));
|
||||
link = Ext.urlAppend(link, "filename=" + encodeURIComponent(response.filename));
|
||||
|
||||
downloadFrame.dom.contentWindow.location = link;
|
||||
},
|
||||
|
||||
/**
|
||||
* Insert import button in all attachment suggestions
|
||||
|
47
php/download.php
Normal file
47
php/download.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
class DownloadHandler
|
||||
{
|
||||
|
||||
public static function doDownload() {
|
||||
if (isset($_GET["token"])) {
|
||||
$token = $_GET["token"];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($_GET["filename"])) {
|
||||
$filename = $_GET["filename"];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// validate token
|
||||
if (!ctype_alnum($token)) { // token is a md5 hash
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD . "vcf_" . $token . ".vcf";
|
||||
|
||||
if(!file_exists($file)) { // invalid token
|
||||
return false;
|
||||
}
|
||||
|
||||
// set headers here
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
|
||||
// no caching
|
||||
header('Expires: 0'); // set expiration time
|
||||
header('Content-Description: File Transfer');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Content-Length: ' . filesize($file));
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Pragma: public');
|
||||
flush();
|
||||
|
||||
// print the downloaded file
|
||||
readfile($file);
|
||||
ignore_user_abort(true);
|
||||
unlink($file);
|
||||
}
|
||||
}
|
@ -65,6 +65,9 @@ class ContactModule extends Module {
|
||||
case "import":
|
||||
$result = $this->importContacts($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();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user