forked from extern/egroupware
Addressbook cleanups from backport
This commit is contained in:
parent
0412ebbb33
commit
e377d1914c
@ -480,8 +480,8 @@ class addressbook_bo extends addressbook_so
|
|||||||
|
|
||||||
// fields that must not be touched
|
// fields that must not be touched
|
||||||
$fields_exclude = array(
|
$fields_exclude = array(
|
||||||
'id' => true,
|
'id' => true,
|
||||||
'tid' => true,
|
'tid' => true,
|
||||||
'owner' => true,
|
'owner' => true,
|
||||||
'private' => true,
|
'private' => true,
|
||||||
'created' => true,
|
'created' => true,
|
||||||
@ -490,9 +490,9 @@ class addressbook_bo extends addressbook_so
|
|||||||
'modifier' => true,
|
'modifier' => true,
|
||||||
'account_id' => true,
|
'account_id' => true,
|
||||||
'etag' => true,
|
'etag' => true,
|
||||||
'uid' => true,
|
'uid' => true,
|
||||||
'freebusy_uri' => true,
|
'freebusy_uri' => true,
|
||||||
'calendar_uri' => true,
|
'calendar_uri' => true,
|
||||||
'photo' => true,
|
'photo' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -674,21 +674,22 @@ class addressbook_bo extends addressbook_so
|
|||||||
$ok = false;
|
$ok = false;
|
||||||
if ($this->check_perms(EGW_ACL_DELETE,$c,$deny_account_delete))
|
if ($this->check_perms(EGW_ACL_DELETE,$c,$deny_account_delete))
|
||||||
{
|
{
|
||||||
if(!($old = $this->read($id))) return false;
|
if (!($old = $this->read($id))) return false;
|
||||||
if($this->delete_history != '' && $old['tid'] != addressbook_so::DELETED_TYPE)
|
if ($this->delete_history != '' && $old['tid'] != addressbook_so::DELETED_TYPE)
|
||||||
{
|
{
|
||||||
$delete = $old;
|
$delete = $old;
|
||||||
$delete['tid'] = addressbook_so::DELETED_TYPE;
|
$delete['tid'] = addressbook_so::DELETED_TYPE;
|
||||||
$ok = $this->save($delete);
|
$ok = $this->save($delete);
|
||||||
egw_link::unlink(0,'addressbook',$id,'','!file');
|
egw_link::unlink(0,'addressbook',$id,'','!file');
|
||||||
}
|
}
|
||||||
elseif($ok = parent::delete($id,$check_etag))
|
elseif (($ok = parent::delete($id,$check_etag)))
|
||||||
{
|
{
|
||||||
egw_link::unlink(0,'addressbook',$id);
|
egw_link::unlink(0,'addressbook',$id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't notify of final purge
|
// Don't notify of final purge
|
||||||
if($ok && $old['tid'] != addressbook_so::DELETED_TYPE) {
|
if ($ok && $old['tid'] != addressbook_so::DELETED_TYPE)
|
||||||
|
{
|
||||||
$GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $id, 'delete', time());
|
$GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $id, 'delete', time());
|
||||||
$this->tracking->track(array('id' => $id), array('id' => $id), null, true);
|
$this->tracking->track(array('id' => $id), array('id' => $id), null, true);
|
||||||
}
|
}
|
||||||
@ -761,11 +762,11 @@ class addressbook_bo extends addressbook_so
|
|||||||
$contact['modifier'] = $this->user;
|
$contact['modifier'] = $this->user;
|
||||||
$contact['modified'] = $this->now_su;
|
$contact['modified'] = $this->now_su;
|
||||||
// set full name and fileas from the content
|
// set full name and fileas from the content
|
||||||
if (strlen($fullname = $this->fullname($contact)) > 0 && (!isset($contact['n_fn']) || $contact['n_fn'] != $fullname)) {
|
if (!isset($contact['n_fn']))
|
||||||
$contact['n_fn'] = $fullname;
|
{
|
||||||
|
$contact['n_fn'] = $this->fullname($contact);
|
||||||
if (isset($contact['org_name'])) $contact['n_fileas'] = $this->fileas($contact);
|
if (isset($contact['org_name'])) $contact['n_fileas'] = $this->fileas($contact);
|
||||||
}
|
}
|
||||||
unset($fullname);
|
|
||||||
$to_write = $contact;
|
$to_write = $contact;
|
||||||
// (non-admin) user editing his own account, make sure he does not change fields he is not allowed to (eg. via SyncML or xmlrpc)
|
// (non-admin) user editing his own account, make sure he does not change fields he is not allowed to (eg. via SyncML or xmlrpc)
|
||||||
if (!$ignore_acl && !$contact['owner'] && !$this->is_admin($contact))
|
if (!$ignore_acl && !$contact['owner'] && !$this->is_admin($contact))
|
||||||
@ -1715,9 +1716,9 @@ class addressbook_bo extends addressbook_so
|
|||||||
. '()[ContactID]: ' . $contact['id']);
|
. '()[ContactID]: ' . $contact['id']);
|
||||||
}
|
}
|
||||||
// We only do a simple consistency check
|
// We only do a simple consistency check
|
||||||
if ((empty($found['n_family']) || $found['n_family'] == $contact['n_family'])
|
if (!$relax || ((empty($found['n_family']) || $found['n_family'] == $contact['n_family'])
|
||||||
&& (empty($found['n_given']) || $found['n_given'] == $contact['n_given'])
|
&& (empty($found['n_given']) || $found['n_given'] == $contact['n_given'])
|
||||||
&& (empty($found['org_name']) || $found['org_name'] == $contact['org_name']))
|
&& (empty($found['org_name']) || $found['org_name'] == $contact['org_name'])))
|
||||||
{
|
{
|
||||||
return array($found['id']);
|
return array($found['id']);
|
||||||
}
|
}
|
||||||
|
@ -99,21 +99,26 @@ class addressbook_sif extends addressbook_bo
|
|||||||
const xml_decl = '<?xml version="1.0" encoding="UTF-8"?>';
|
const xml_decl = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||||
const SIF_decl = '<SIFVersion>1.1</SIFVersion>';
|
const SIF_decl = '<SIFVersion>1.1</SIFVersion>';
|
||||||
|
|
||||||
function startElement($_parser, $_tag, $_attributes) {
|
function startElement($_parser, $_tag, $_attributes)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
function endElement($_parser, $_tag) {
|
function endElement($_parser, $_tag)
|
||||||
if(!empty($this->sifMapping[$_tag])) {
|
{
|
||||||
|
if (!empty($this->sifMapping[$_tag]))
|
||||||
|
{
|
||||||
$this->contact[$this->sifMapping[$_tag]] = trim($this->sifData);
|
$this->contact[$this->sifMapping[$_tag]] = trim($this->sifData);
|
||||||
}
|
}
|
||||||
unset($this->sifData);
|
unset($this->sifData);
|
||||||
}
|
}
|
||||||
|
|
||||||
function characterData($_parser, $_data) {
|
function characterData($_parser, $_data)
|
||||||
|
{
|
||||||
$this->sifData .= $_data;
|
$this->sifData .= $_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function siftoegw($sifData, $_abID=null) {
|
function siftoegw($sifData, $_abID=null)
|
||||||
|
{
|
||||||
|
|
||||||
#$tmpfname = tempnam('/tmp/sync/contents','sifc_');
|
#$tmpfname = tempnam('/tmp/sync/contents','sifc_');
|
||||||
|
|
||||||
@ -129,24 +134,26 @@ class addressbook_sif extends addressbook_bo
|
|||||||
xml_set_element_handler($this->xml_parser, "startElement", "endElement");
|
xml_set_element_handler($this->xml_parser, "startElement", "endElement");
|
||||||
xml_set_character_data_handler($this->xml_parser, "characterData");
|
xml_set_character_data_handler($this->xml_parser, "characterData");
|
||||||
$this->strXmlData = xml_parse($this->xml_parser, $sifData);
|
$this->strXmlData = xml_parse($this->xml_parser, $sifData);
|
||||||
if(!$this->strXmlData) {
|
if (!$this->strXmlData)
|
||||||
|
{
|
||||||
error_log(sprintf("XML error: %s at line %d",
|
error_log(sprintf("XML error: %s at line %d",
|
||||||
xml_error_string(xml_get_error_code($this->xml_parser)),
|
xml_error_string(xml_get_error_code($this->xml_parser)),
|
||||||
xml_get_current_line_number($this->xml_parser)));
|
xml_get_current_line_number($this->xml_parser)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->contact as $key => $value) {
|
foreach ($this->contact as $key => $value)
|
||||||
|
{
|
||||||
$value = preg_replace('/<\!\[CDATA\[(.+)\]\]>/Usim', '$1', $value);
|
$value = preg_replace('/<\!\[CDATA\[(.+)\]\]>/Usim', '$1', $value);
|
||||||
$value = $GLOBALS['egw']->translation->convert($value, 'utf-8');
|
$value = $GLOBALS['egw']->translation->convert($value, 'utf-8');
|
||||||
switch($key) {
|
switch ($key) {
|
||||||
case 'cat_id':
|
case 'cat_id':
|
||||||
if(!empty($value))
|
if (!empty($value))
|
||||||
{
|
{
|
||||||
$categories1 = explode(',', $value);
|
$categories1 = explode(',', $value);
|
||||||
$categories2 = explode(';', $value);
|
$categories2 = explode(';', $value);
|
||||||
$categories = count($categories1) > count($categories2) ? $categories1 : $categories2;
|
$categories = count($categories1) > count($categories2) ? $categories1 : $categories2;
|
||||||
$finalContact[$key] = implode(",", $this->find_or_add_categories($categories, $_abID));
|
$finalContact[$key] = implode(',', $this->find_or_add_categories($categories, $_abID));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -179,7 +186,7 @@ class addressbook_sif extends addressbook_bo
|
|||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
if($contact = $this->siftoegw($_sifdata, $contentID))
|
if (($contact = $this->siftoegw($_sifdata, $contentID)))
|
||||||
{
|
{
|
||||||
if ($contentID)
|
if ($contentID)
|
||||||
{
|
{
|
||||||
@ -200,12 +207,12 @@ class addressbook_sif extends addressbook_bo
|
|||||||
*/
|
*/
|
||||||
function addSIF($_sifdata, $_abID=null, $merge=false)
|
function addSIF($_sifdata, $_abID=null, $merge=false)
|
||||||
{
|
{
|
||||||
if(!$contact = $this->siftoegw($_sifdata, $_abID))
|
if (!$contact = $this->siftoegw($_sifdata, $_abID))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($_abID)
|
if ($_abID)
|
||||||
{
|
{
|
||||||
if (($old_contact = $this->read($_abID)))
|
if (($old_contact = $this->read($_abID)))
|
||||||
{
|
{
|
||||||
@ -254,9 +261,7 @@ class addressbook_sif extends addressbook_bo
|
|||||||
$fields = array_unique(array_values($this->sifMapping));
|
$fields = array_unique(array_values($this->sifMapping));
|
||||||
sort($fields);
|
sort($fields);
|
||||||
|
|
||||||
if(!($entry = $this->read($_id))) {
|
if (!($entry = $this->read($_id))) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sifContact = self::xml_decl . "\n<contact>" . self::SIF_decl;
|
$sifContact = self::xml_decl . "\n<contact>" . self::SIF_decl;
|
||||||
|
|
||||||
@ -265,16 +270,16 @@ class addressbook_sif extends addressbook_bo
|
|||||||
// fillup some defaults such as n_fn and n_fileas is needed
|
// fillup some defaults such as n_fn and n_fileas is needed
|
||||||
$this->fixup_contact($entry);
|
$this->fixup_contact($entry);
|
||||||
|
|
||||||
foreach($this->sifMapping as $sifField => $egwField)
|
foreach ($this->sifMapping as $sifField => $egwField)
|
||||||
{
|
{
|
||||||
if(empty($egwField)) continue;
|
if (empty($egwField)) continue;
|
||||||
|
|
||||||
#error_log("$sifField => $egwField");
|
#error_log("$sifField => $egwField");
|
||||||
#error_log('VALUE1: '.$entry[0][$egwField]);
|
#error_log('VALUE1: '.$entry[0][$egwField]);
|
||||||
$value = $GLOBALS['egw']->translation->convert($entry[$egwField], $sysCharSet, 'utf-8');
|
$value = $GLOBALS['egw']->translation->convert($entry[$egwField], $sysCharSet, 'utf-8');
|
||||||
#error_log('VALUE2: '.$value);
|
#error_log('VALUE2: '.$value);
|
||||||
|
|
||||||
switch($sifField)
|
switch ($sifField)
|
||||||
{
|
{
|
||||||
case 'Sensitivity':
|
case 'Sensitivity':
|
||||||
$value = 2 * $value; // eGW private is 0 (public) or 1 (private)
|
$value = 2 * $value; // eGW private is 0 (public) or 1 (private)
|
||||||
@ -287,7 +292,7 @@ class addressbook_sif extends addressbook_bo
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Categories':
|
case 'Categories':
|
||||||
if(!empty($value)) {
|
if (!empty($value)) {
|
||||||
$value = implode(", ", $this->get_categories($value));
|
$value = implode(", ", $this->get_categories($value));
|
||||||
$value = $GLOBALS['egw']->translation->convert($value, $sysCharSet, 'utf-8');
|
$value = $GLOBALS['egw']->translation->convert($value, $sysCharSet, 'utf-8');
|
||||||
} else {
|
} else {
|
||||||
|
@ -123,12 +123,9 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
*/
|
*/
|
||||||
function addVCard($_vcard, $_abID=null, $merge=false)
|
function addVCard($_vcard, $_abID=null, $merge=false)
|
||||||
{
|
{
|
||||||
if(!$contact = $this->vcardtoegw($_vcard, $_abID))
|
if (!($contact = $this->vcardtoegw($_vcard, $_abID))) return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($_abID)
|
if ($_abID)
|
||||||
{
|
{
|
||||||
if (($old_contact = $this->read($_abID)))
|
if (($old_contact = $this->read($_abID)))
|
||||||
{
|
{
|
||||||
@ -252,7 +249,7 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
$value = trim($entry[$databaseField]);
|
$value = trim($entry[$databaseField]);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($databaseField)
|
switch ($databaseField)
|
||||||
{
|
{
|
||||||
case 'private':
|
case 'private':
|
||||||
$value = $value ? 'PRIVATE' : 'PUBLIC';
|
$value = $value ? 'PRIVATE' : 'PUBLIC';
|
||||||
@ -671,24 +668,24 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($rowName == 'EMAIL')
|
if ($rowName == 'EMAIL')
|
||||||
{
|
{
|
||||||
$rowName .= ';X-egw-Ref' . $email++;
|
$rowName .= ';X-egw-Ref' . $email++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($rowName == 'TEL;CELL') ||
|
if (($rowName == 'TEL;CELL') ||
|
||||||
($rowName == 'TEL;CELL;VOICE'))
|
($rowName == 'TEL;CELL;VOICE'))
|
||||||
{
|
{
|
||||||
$rowName = 'TEL;CELL;X-egw-Ref' . $cell++;
|
$rowName = 'TEL;CELL;X-egw-Ref' . $cell++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($rowName == 'TEL') ||
|
if (($rowName == 'TEL') ||
|
||||||
($rowName == 'TEL;VOICE'))
|
($rowName == 'TEL;VOICE'))
|
||||||
{
|
{
|
||||||
$rowName = 'TEL;X-egw-Ref' . $tel++;
|
$rowName = 'TEL;X-egw-Ref' . $tel++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($rowName == 'URL')
|
if ($rowName == 'URL')
|
||||||
{
|
{
|
||||||
$rowName = 'URL;X-egw-Ref' . $url++;
|
$rowName = 'URL;X-egw-Ref' . $url++;
|
||||||
}
|
}
|
||||||
@ -711,7 +708,7 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
|
|
||||||
foreach ($rowNames as $vcardKey => $rowName)
|
foreach ($rowNames as $vcardKey => $rowName)
|
||||||
{
|
{
|
||||||
switch($rowName)
|
switch ($rowName)
|
||||||
{
|
{
|
||||||
case 'VERSION':
|
case 'VERSION':
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user