starting on export feature
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user