From 2b00ad6155b346a5c40392b2f31f9ee917f3f4fc Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 22 Mar 2012 11:34:35 +0100 Subject: Add created/modified by information in edit form --- lib/kolab_client_task.php | 53 ++++++++++++++++++++++++++++++++++++++++++++--- lib/locale/en_US.php | 3 +++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php index d8c3fd8..2a49344 100644 --- a/lib/kolab_client_task.php +++ b/lib/kolab_client_task.php @@ -39,6 +39,7 @@ class kolab_client_task protected $ajax_only = false; protected $page_title = 'Kolab Admin Panel'; protected $menu = array(); + protected $cache = array(); protected static $translation = array(); @@ -488,6 +489,31 @@ class kolab_client_task } /** + * Returns user name. + * + * @param string $dn User DN attribute value + * + * @return string User name (displayname) + */ + protected function user_name($dn) + { + if (!empty($this->cache['user_names']) && isset($this->cache['user_names'][$dn])) { + return $this->cache['user_names'][$dn]; + } + + if (preg_match('/^cn=([a-z ]+)$/i', $dn, $m)) { + $username = $m[1]; + } + else { + $result = $this->api->get('user.info', array('user' => $dn)); + $user = $result->get($dn); + $username = $user['displayname']; + } + + return $this->cache['user_names'][$dn] = $username; + } + + /** * Returns list of system capabilities. * * @return array List of system capabilities @@ -745,6 +771,27 @@ class kolab_client_task } } else { + // Add common information fields + $add_fields = array( + 'creatorsname' => 'createtimestamp', + 'modifiersname' => 'modifytimestamp', + ); + foreach ($add_fields as $idx => $val) { + if (!empty($data[$idx])) { + if ($value = $this->user_name($data[$idx])) { + if ($data[$val]) { + $value .= ' (' . strftime('%x %X', strtotime($data[$val])) . ')'; + } + + $fields[$idx] = array( + 'label' => $idx, + 'section' => 'system', + 'value' => $value, + ); + } + } + } + // Add debug information ksort($data); $debug = kolab_html::escape(print_r($data, true)); @@ -752,9 +799,9 @@ class kolab_client_task $debug = str_replace("\n ", "\n", $debug); $debug = '
' . $debug . '
'; $fields['debug'] = array( - 'label' => 'debug', + 'label' => 'debug', 'section' => 'system', - 'value' => $debug, + 'value' => $debug, ); } @@ -816,7 +863,7 @@ class kolab_client_task $field['description'] = "$name.$idx.desc"; $field['section'] = $section_idx; - if (!empty($data[$idx])) { + if (empty($field['value']) && !empty($data[$idx])) { $field['value'] = $data[$idx]; // Convert data for the list field with autocompletion diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php index aaaee08..773810b 100644 --- a/lib/locale/en_US.php +++ b/lib/locale/en_US.php @@ -10,6 +10,9 @@ $LANG['internalerror'] = 'Internal system error!'; $LANG['welcome'] = 'Welcome to the Kolab Groupware Server Maintenance'; $LANG['reqtime'] = 'Request time: $1 sec.'; $LANG['debug'] = 'Debug info'; +$LANG['info'] = 'Information'; +$LANG['creatorsname'] = 'Created by'; +$LANG['modifiersname'] = 'Modified by'; $LANG['login.username'] = 'Username:'; $LANG['login.password'] = 'Password:'; -- cgit v1.1