- new feature to merge contacts into one

- added missing link::unlink if contacts get deleted
- some tweaks in the edit template: n_fn was not readonly, added focus for n_prefix to onclick
This commit is contained in:
Ralf Becker 2006-12-19 11:25:44 +00:00
parent 33d333f56f
commit 7a653f4a1d
6 changed files with 128 additions and 9 deletions

View File

@ -403,12 +403,18 @@ class bocontacts extends socontacts
{
$contact = array($contact);
}
if (!is_object($GLOBALS['egw']->link))
{
require_once(EGW_API_INC.'/class.bolink.inc.php');
$GLOBALS['egw']->link =& new bolink();
}
foreach($contact as $c)
{
$id = is_array($c) ? $c['id'] : $c;
if ($this->check_perms(EGW_ACL_DELETE,$c) && parent::delete($id))
{
$GLOBALS['egw']->link->unlink(0,'addressbook',$id);
$GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $id, 'delete', time());
}
else
@ -813,4 +819,94 @@ class bocontacts extends socontacts
include(EGW_INCLUDE_ROOT.'/addressbook/setup/setup.inc.php');
$GLOBALS['egw']->hooks->register_hooks('addressbook',$setup_info['addressbook']['hooks']);
}
/**
* Merges some given addresses into the first one and delete the others
*
* If one of the other addresses is an account, everything is merged into the account.
* If two accounts are in $ids, the function fails (returns false).
*
* @param array $ids contact-id's to merge
* @return int number of successful merged contacts, false on a fatal error (eg. cant merge two accounts)
*/
function merge($ids)
{
$this->error = false;
foreach(self::search(array('id'=>$ids),false) as $contact) // $this->search calls the extended search from ui!
{
if ($contact['account_id'])
{
if (!is_null($account))
{
echo $this->error = 'Can not merge more then one account!';
return false; // we dont deal with two accounts!
}
$account = $contact;
continue;
}
$pos = array_search($contact['id'],$ids);
$contacts[$pos] = $contact;
}
if (!is_null($account)) // we found an account, so we merge the contacts into it
{
$target = $account;
unset($account);
}
else // we found no account, so we merge all but the first into the first
{
$target = $contacts[0];
unset($contacts[0]);
}
if (!$this->check_perms(EGW_ACL_EDIT,$target))
{
echo $this->error = 'No edit permission for the target contact!';
return 0;
}
foreach($contacts as $contact)
{
foreach($contact as $name => $value)
{
if (!$value) continue;
switch($name)
{
case 'id':
case 'tid':
case 'owner':
case 'private':
break; // ignored
case 'cat_id': // cats are all merged together
if (!is_array($target['cat_id'])) $target['cat_id'] = $target['cat_id'] ? explode(',',$target['cat_id']) : array();
$target['cat_id'] = array_unique(array_merge($target['cat_id'],is_array($value)?$value:explode(',',$value)));
break;
default:
if (!$target[$name]) $target[$name] = $value;
break;
}
}
}
if (!$this->save($target)) return 0;
if (!is_object($GLOBALS['egw']->link))
{
require_once(EGW_API_INC.'/class.bolink.inc.php');
$GLOBALS['egw']->link =& new bolink();
}
$success = 1;
foreach($contacts as $contact)
{
if (!$this->check_perms(EGW_ACL_DELETE,$contact))
{
continue;
}
foreach($GLOBALS['egw']->link->get_links('addressbook',$contact['id']) as $data)
{
$GLOBALS['egw']->link->link('addressbook',$target['id'],$data['app'],$data['id'],$data['remark'],$target['owner']);
}
if ($this->delete($contact['id'])) $success++;
}
return $success;
}
}

View File

@ -202,6 +202,7 @@ class uicontacts extends bocontacts
'delete' => lang('Delete'),
'csv' => lang('Export as CSV'),
'vcard' => lang('Export as VCard'), // ToDo: move this to importexport framework
'merge' => lang('Merge into first or account, deletes all other!'),
);
if ($GLOBALS['egw_info']['user']['apps']['infolog'])
{
@ -341,7 +342,7 @@ class uicontacts extends bocontacts
*/
function action($action,$checked,$use_all,&$success,&$failed,&$action_msg,$session_name)
{
//echo "<p>uicontacts::action('$action',".print_r($checked,true).','.(int)$use_all.",...)</p>\n";
echo "<p>uicontacts::action('$action',".print_r($checked,true).','.(int)$use_all.",...)</p>\n";
$success = $failed = 0;
if ($use_all)
@ -413,6 +414,13 @@ class uicontacts extends bocontacts
'action_title' => count($checked) > 1 ? lang('selected contacts') : '',
));
break;
case 'merge':
$success = $this->merge($checked,$error_msg);
$failed = count($checked) - (int)$success;
$action_msg = lang('merged');
$checked = array(); // to not start the single actions
break;
}
foreach($checked as $id)
{
@ -1019,7 +1027,7 @@ class uicontacts extends bocontacts
require_once(EGW_API_INC.'/class.country.inc.php');
$GLOBALS['egw']->country =& new country;
}
$content['adr_one_countryname'] = $content['adr_two_countryname'] =
$content['adr_one_countryname'] =
$GLOBALS['egw']->country->get_full_name($GLOBALS['egw_info']['user']['preferences']['common']['country']);
}
if (isset($_GET['owner']) && $_GET['owner'] !== '')
@ -1339,6 +1347,12 @@ $readonlys['button[vcard]'] = true;
return 'mailto:' . $email;
}
/**
* Extended search
*
* @param array $_content
* @return string
*/
function search($_content=array())
{
if(!empty($_content)) {

File diff suppressed because one or more lines are too long

View File

@ -184,6 +184,8 @@ list all customfields addressbook de Liste alle benutzerdefinierten Felder
load vcard addressbook de VCard laden
locations addressbook de Standorte
mark records as private addressbook de Eintrag als Privat kennzeichnen
merged addressbook en vereinigt
merge into first or account, deletes all other! addressbook en Vereinige im ersten oder Benutzerkonto, löscht alle anderen!
message phone addressbook de Anrufbeantworter
middle name addressbook de Zweiter Vorname
migration finished addressbook de Migration beendet

View File

@ -184,6 +184,8 @@ list all customfields addressbook en List all customfields
load vcard addressbook en Load VCard
locations addressbook en locations
mark records as private addressbook en Mark records as private
merged addressbook en merged
merge into first or account, deletes all other! addressbook en Merge into first or account, deletes all other!
message phone addressbook en Message Phone
middle name addressbook en Middle Name
migration finished addressbook en Migration finished

View File

@ -76,7 +76,7 @@
<rows>
<row>
<description value="Name"/>
<textbox rows="1" cols="3" id="n_fn" no_lang="1" onclick="set_style_by_class('table','editname','display','inline');" size="36" span="2" class="cursorHand"/>
<textbox rows="1" cols="3" id="n_fn" no_lang="1" onclick="set_style_by_class('table','editname','display','inline');" size="36" span="2" class="cursorHand" readonly="true"/>
</row>
<row>
<description/>
@ -226,12 +226,17 @@
<description value="Categories"/>
<listbox type="select-cat" id="cat_id" rows="3" options=",width:99%"/>
</row>
<row valign="top">
<row class="row_off" valign="top">
<image src="edit"/>
<description value="Notes"/>
<textbox multiline="true" rows="6" cols="50" id="note"/>
</row>
<row valign="top">
<row class="row_on" disabled="@disable_change_org">
<image src="check"/>
<description/>
<checkbox label="change all organisation members" id="change_org" span="all" statustext="Apply changes to all members, whose fields have the same previous content"/>
</row>
<row class="row_off" valign="top">
<image src="gear"/>
<menulist>
<menupopup type="select-account" readonly="true" label="Created"/>
@ -243,7 +248,7 @@
<date-time id="created" class="leftPad5" readonly="true"/>
</hbox>
</row>
<row>
<row class="row_on">
<description/>
<description value="Last modified"/>
<hbox readonly="true" options="0,0">