Add an option to keep deleted contacts, and only admins can purge them

This commit is contained in:
Nathan Gray 2010-02-10 23:07:43 +00:00
parent ad79f404e9
commit 63117b9ceb
4 changed files with 68 additions and 5 deletions

View File

@ -134,6 +134,15 @@ class addressbook_bo extends addressbook_so
*/
protected $tracking;
/**
* Keep deleted addresses, or really delete them
* Set in Admin -> Addressbook -> Site Configuration
* ''=really delete, 'history'=keep, only admins delete
*
* @var string
*/
protected $delete_history = '';
function __construct($contact_app='addressbook')
{
parent::__construct($contact_app);
@ -262,6 +271,9 @@ class addressbook_bo extends addressbook_so
$this->categories = new categories($this->user,'addressbook');
$this->tracking = new addressbook_tracking($this);
$config = config::read('phpgwapi');
$this->delete_history = $config['history'];
}
/**
@ -661,11 +673,26 @@ class addressbook_bo extends addressbook_so
$id = is_array($c) ? $c['id'] : $c;
$ok = false;
if ($this->check_perms(EGW_ACL_DELETE,$c,$deny_account_delete) && ($ok = parent::delete($id,$check_etag)))
if ($this->check_perms(EGW_ACL_DELETE,$c,$deny_account_delete))
{
egw_link::unlink(0,'addressbook',$id);
$GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $id, 'delete', time());
$this->tracking->track(array('id' => $id), array('id' => $id), null, true);
if(!($old = $this->read($id))) return false;
if($this->delete_history != '' && $old['tid'] != addressbook_so::DELETED_TYPE)
{
$delete = $old;
$delete['tid'] = addressbook_so::DELETED_TYPE;
$ok = $this->save($delete);
egw_link::unlink(0,'addressbook',$id,'','!file');
}
elseif($ok = parent::delete($id,$check_etag))
{
egw_link::unlink(0,'addressbook',$id);
}
// Don't notify of final purge
if($ok && $old['tid'] != addressbook_so::DELETED_TYPE) {
$GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $id, 'delete', time());
$this->tracking->track(array('id' => $id), array('id' => $id), null, true);
}
}
else
{
@ -776,7 +803,8 @@ class addressbook_bo extends addressbook_so
}
// Record change history
$this->tracking->track($to_write, $old);
$deleted = ($old['tid'] == addressbook_so::DELETED_TYPE || $contact['tid'] == addressbook_so::DELETED_TYPE);
$this->tracking->track($to_write, $old, null, $deleted);
}
return $this->error ? false : $contact['id'];

View File

@ -164,6 +164,13 @@ class addressbook_so
*/
var $content_types = array();
/**
* Special content type to indicate a deleted addressbook
*
* @var String;
*/
const DELETED_TYPE = 'D';
/**
* total number of matches of last search
*
@ -303,6 +310,17 @@ class addressbook_so
'icon' => 'navbar.png'
)));
}
// Add in deleted type for admins
if($this->is_admin()) {
$this->content_types[self::DELETED_TYPE] = array(
'name' => lang('Deleted'),
'options' => array(
'template' => 'addressbook.edit',
'icon' => 'deleted.png'
)
);
}
}
/**
@ -585,6 +603,12 @@ class addressbook_so
{
$filter['adr_one_countryname'] = $GLOBALS['egw']->country->get_full_name($filter['adr_one_countryname']);
}
// Hide deleted items unless type is specifically deleted
if(array_key_exists('tid', $filter) && $filter['tid'] !== self::DELETED_TYPE) {
$filter[] = 'contact_tid != \'' . self::DELETED_TYPE . '\'';
}
$backend =& $this->get_backend(null,$filter['owner']);
// single string to search for --> create so_sql conformant search criterial for the standard search columns
if ($criteria && !is_array($criteria))

View File

@ -67,6 +67,17 @@
{lang_(empty_=_use_global_limit,_no_=_no_export_at_all)}:</td>
<td><input name="newsettings[contact_export_limit]" value="{value_contact_export_limit}" size="5"></td>
</tr>
<tr class="th">
<td colspan="2">&nbsp;<b>{lang_History_logging}</b></td>
</tr>
<tr class="row_on">
<td>&nbsp;{lang_Prevent_deleting_of_contacts}</td>
<td>
<select name="newsettings[history]">
<option value="">{lang_No}</option>
<option value="history"{selected_history_history}>{lang_Yes,_only_admins_can_purge_deleted_items}</option>
</select>
</td>
<tr class="th">
<td colspan="2">&nbsp;<b>{lang_Contact_maintenance}</b></td>
</tr>

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B