Add history logging to addressbook

This commit is contained in:
Nathan Gray 2010-02-08 17:53:47 +00:00
parent df51d3a409
commit 0db5355347
5 changed files with 56 additions and 10 deletions

View File

@ -126,6 +126,13 @@ class addressbook_bo extends addressbook_so
*/
var $categories;
/**
* Tracking changes
*
* @var object
*/
protected $tracking;
function __construct($contact_app='addressbook')
{
parent::__construct($contact_app);
@ -253,6 +260,8 @@ class addressbook_bo extends addressbook_so
$this->org_fields = unserialize($GLOBALS['egw_info']['server']['org_fileds_to_update']);
}
$this->categories = new categories($this->user,'addressbook');
$this->tracking = new addressbook_tracking($this);
}
/**
@ -650,6 +659,7 @@ class addressbook_bo extends addressbook_so
{
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);
}
else
{
@ -736,6 +746,10 @@ class addressbook_bo extends addressbook_so
}
}
}
// Get old record for tracking changes
$old = $this->read($contact['id']);
// we dont update the content-history, if we run inside setup (admin-account-creation)
if(!($this->error = parent::save($to_write)) && is_object($GLOBALS['egw']->contenthistory))
{
@ -754,6 +768,9 @@ class addressbook_bo extends addressbook_so
$to_write['location'] = 'editaccountcontact';
$GLOBALS['egw']->hooks->process($to_write,False,True); // called for every app now, not only enabled ones));
}
// Record change history
$this->tracking->track($to_write, $old);
}
return $this->error ? false : $contact['id'];

View File

@ -53,10 +53,6 @@ class addressbook_contactform
$contact = new addressbook_bo();
if ($content['owner']) // save the contact in the addressbook
{
if ($content['email_contactform']) // only necessary as long addressbook is not doing this itself
{
$tracking = new addressbook_tracking($contact);
}
if (($id = $contact->save($content)))
{
// check for fileuploads and attach the found files
@ -67,9 +63,6 @@ class addressbook_contactform
egw_link::link('addressbook',$id,egw_link::VFS_APPNAME,$value,$name);
}
}
unset($content['modified']); unset($content['modifier']); // not interesting for new entries
$tracking->do_notifications($content,null); // only necessary as long addressbook is not doing this itself
return '<p align="center">'.$content['msg'].'</p>';
}

View File

@ -71,6 +71,13 @@ class addressbook_tracking extends bo_tracking
parent::__construct(); // calling the constructor of the extended class
$this->contacts =& $bocontacts;
if(is_object($bocontacts->somain)) {
$this->field2history = array_combine($bocontacts->somain->db_cols, $bocontacts->somain->db_cols);
unset($this->field2history['modified']);
unset($this->field2history['modifier']);
unset($this->field2history['etag']);
}
}
/**
@ -234,4 +241,4 @@ class addressbook_tracking extends bo_tracking
}
return $details;
}
}
}

View File

@ -1456,6 +1456,10 @@ class addressbook_ui extends addressbook_bo
'to_app' => 'addressbook',
'to_id' => $content['link_to']['to_id'],
);
// Enable history
$this->setup_history($content, $sel_options);
$content['photo'] = $this->photo_src($content['id'],$content['jpegphoto'],'photo');
if ($content['private']) $content['owner'] .= 'p';
@ -1666,6 +1670,10 @@ class addressbook_ui extends addressbook_bo
{
$content['owner'] .= 'p';
}
// Enable history
$this->setup_history($content, $sel_options);
// disable not needed tabs
$readonlys['tabs']['cats'] = !($content['cat_tab'] = $this->config['cat_tab']);
$readonlys['tabs']['custom'] = !$this->customfields;
@ -2132,4 +2140,23 @@ class addressbook_ui extends addressbook_bo
$this->tmpl->read('addressbook.index.cat_add');
return $this->tmpl->exec('addressbook.addressbook_ui.cat_add',$content,$sel_options,$readonlys,$content, 2);
}
/**
* Set up history log widget
*/
protected function setup_history(&$content, &$sel_options) {
$content['history'] = array(
'id' => $content['id'],
'app' => 'addressbook',
'status-widgets' => array(
'owner' => 'select-account',
'cat_id' => 'select-cat',
),
);
foreach($this->content_types as $id => $settings) {
$content['history']['status-widgets']['tid'][$id] = $settings['name'];
}
$sel_options['status'] = $this->contact_fields;
}
}

File diff suppressed because one or more lines are too long