Commit 29de2c8f authored by mku's avatar mku

ZP-143 #comment Configurable fileas #time 2h

git-svn-id: https://z-push.org/svn/z-push/trunk@1456 b7dd7b3b-3a3c-0410-9da9-bee62a6cc5b5
parent 687a9e05
......@@ -1291,6 +1291,16 @@ class MAPIProvider {
$this->setASbody($contact->asbody, $props, $contactprops);
}
//set fileas
if (defined('FILEAS_ORDER')) {
$lastname = (isset($contact->lastname)) ? $contact->lastname : "";
$firstname = (isset($contact->firstname)) ? $contact->firstname : "";
$middlename = (isset($contact->middlename)) ? $contact->middlename : "";
$company = (isset($contact->companyname)) ? $contact->companyname : "";
$props[$contactprops["fileas"]] = Utils::BuildFileAs($lastname, $firstname, $middlename, $company);
}
else ZLog::Write(LOGLEVEL_DEBUG, "FILEAS_ORDER not defined");
mapi_setprops($mapimessage, $props);
}
......
......@@ -118,6 +118,22 @@
// This can also be disabled by setting it to false
define('SINK_FORCERECHECK', 300);
// Set the fileas order contacts. Possible values are:
// SYNC_FILEAS_FIRSTLAST - fileas will be "Firstname Middlename Lastname"
// SYNC_FILEAS_LASTFIRST - fileas will be "Lastname, Firstname Middlename"
// SYNC_FILEAS_COMPANYONLY - fileas will be "Company"
// SYNC_FILEAS_COMPANYLAST - fileas will be "Company (Lastname, Firstname Middlename)"
// SYNC_FILEAS_COMPANYFIRST - fileas will be "Company (Firstname Middlename Lastname)"
// SYNC_FILEAS_LASTCOMPANY - fileas will be "Lastname, Firstname Middlename (Company)"
// SYNC_FILEAS_FIRSTCOMPANY - fileas will be "Firstname Middlename Lastname (Company)"
// The company-fileas will only be set if a contact has a company set. If one of
// company-fileas is selected and a contact doesn't have a company set, it will default
// to SYNC_FILEAS_FIRSTLAST or SYNC_FILEAS_LASTFIRST (depending on if last or first
// option is selected for company).
// If SYNC_FILEAS_COMPANYONLY is selected and company of the contact is not set
// SYNC_FILEAS_FIRSTLAST will be used
define('FILEAS_ORDER', SYNC_FILEAS_FIRSTLAST);
/**********************************************************************************
* Backend settings
*/
......
......@@ -1040,4 +1040,11 @@ define("MAPI_E_NOT_ENOUGH_MEMORY_64BIT", 2147942414);
define("SYNC_SETTINGSOOF_BODYTYPE_HTML", "HTML");
define("SYNC_SETTINGSOOF_BODYTYPE_TEXT", "TEXT");
define("SYNC_FILEAS_FIRSTLAST", 1);
define("SYNC_FILEAS_LASTFIRST", 2);
define("SYNC_FILEAS_COMPANYONLY", 3);
define("SYNC_FILEAS_COMPANYLAST", 4);
define("SYNC_FILEAS_COMPANYFIRST", 5);
define("SYNC_FILEAS_LASTCOMPANY", 6);
define("SYNC_FILEAS_FIRSTCOMPANY", 7);
?>
\ No newline at end of file
......@@ -134,6 +134,110 @@ class Utils {
return ($out)?$out:null;
}
/**
* Build the fileas string from the components according to the configuration.
*
* @param string $lastname
* @param string $firstname
* @param string $middlename
* @param string $company
*
* @access public
* @return string fileas
*/
static public function BuildFileAs($lastname = "", $firstname = "", $middlename = "", $company = "") {
if (defined('FILEAS_ORDER')) {
$fileas = $lastfirst = $firstlast = "";
$names = trim ($firstname . " " . $middlename);
$lastname = trim($lastname);
$company = trim($company);
// lastfirst is "lastname, firstname middlename"
// firstlast is "firstname middlename lastname"
if (strlen($lastname) > 0) {
$lastfirst = $lastname;
if (strlen($names) > 0){
$lastfirst .= ", $names";
$firstlast = "$names $lastname";
}
else {
$firstlast = $lastname;
}
}
elseif (strlen($names) > 0) {
$lastfirst = $firstlast = $names;
}
// if fileas with a company is selected
// but company is emtpy then it will
// fallback to firstlast or lastfirst
// (depending on which is selected for company)
switch (FILEAS_ORDER) {
case SYNC_FILEAS_COMPANYONLY:
if (strlen($company) > 0) {
$fileas = $company;
}
elseif (strlen($firstlast) > 0)
$fileas = $firstlast;
break;
case SYNC_FILEAS_COMPANYLAST:
if (strlen($company) > 0) {
$fileas = $company;
if (strlen($lastfirst) > 0)
$fileas .= "($lastfirst)";
}
elseif (strlen($lastfirst) > 0)
$fileas = $lastfirst;
break;
case SYNC_FILEAS_COMPANYFIRST:
if (strlen($company) > 0) {
$fileas = $company;
if (strlen($firstlast) > 0) {
$fileas .= " ($firstlast)";
}
}
elseif (strlen($firstlast) > 0) {
$fileas = $firstlast;
}
break;
case SYNC_FILEAS_FIRSTCOMPANY:
if (strlen($firstlast) > 0) {
$fileas = $firstlast;
if (strlen($company) > 0) {
$fileas .= " ($company)";
}
}
elseif (strlen($company) > 0) {
$fileas = $company;
}
break;
case SYNC_FILEAS_LASTCOMPANY:
if (strlen($lastfirst) > 0) {
$fileas = $lastfirst;
if (strlen($company) > 0) {
$fileas .= " ($company)";
}
}
elseif (strlen($company) > 0) {
$fileas = $company;
}
break;
case SYNC_FILEAS_LASTFIRST:
if (strlen($lastfirst) > 0) {
$fileas = $lastfirst;
}
break;
default:
$fileas = $firstlast;
break;
}
if (strlen($fileas) == 0)
ZLog::Write(LOGLEVEL_DEBUG, "Fileas is empty.");
return $fileas;
}
ZLog::Write(LOGLEVEL_DEBUG, "FILEAS_ORDER not defined. Add it to your config.php.");
return null;
}
/**
* Checks if the PHP-MAPI extension is available and in a requested version
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment