diff --git a/ihtml/themes/breezy/islocked.tpl b/ihtml/themes/breezy/islocked.tpl index c29695996855d51de54271dee0cf66d13351aa9f..2ce28a31ad5fb25049dd1486050a2ce7d4d46639 100644 --- a/ihtml/themes/breezy/islocked.tpl +++ b/ihtml/themes/breezy/islocked.tpl @@ -7,9 +7,14 @@ <div> <p> <b>{t}Warning{/t}:</b> {$message} + <ul> + {foreach from=$locks item=lock} + <li>{t 1=$lock.object 2=$lock.user}"%1" was locked by "%1"{/t}</li> + {/foreach} + </ul> </p> <p> - {t}If this lock detection is false, the other person has obviously closed the webbrowser during the edit operation. You may want to take over the lock by pressing the 'Edit anyway' button.{/t} + {t 1=$action}If this lock detection is false, the other person may have closed the webbrowser during the edit operation. You may want to take over the lock by pressing the "%1" button.{/t} </p> <p class="plugbottom"> diff --git a/include/class_management.inc b/include/class_management.inc index 9a1a45a146121f6b06c1cecde2f3f10334861735..5f9435469bde599c5cee59727bcf8fd34210f3c5 100644 --- a/include/class_management.inc +++ b/include/class_management.inc @@ -338,7 +338,7 @@ class management if (count($this->dns)) { // check locks - if ($user = get_multiple_locks($this->dns)) { + if ($user = get_locks($this->dns)) { return gen_locked_message($user, $this->dns); } diff --git a/include/functions.inc b/include/functions.inc index a6aabb2f57f424e83faac07b9432bed2bbd33199..07178f2422cc23ef022c6172cac356be910dc157 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -776,67 +776,52 @@ function del_user_locks($userdn) * * \param string $object subject whose locks are to be searched * - * \return string Returns the user who owns the lock or '' if no lock is found - * or an error occured. + * \return string Returns the dn of the user who owns the lock or '' if no lock is found + * or FALSE if an error occured. */ -function get_lock ($object) +function get_lock($object) { global $config; /* Sanity check */ if ($object == '') { msg_dialog::display(_('Internal error'), _('Error while adding a lock. Contact the developers!'), ERROR_DIALOG); - return ''; + return FALSE; } /* Allow readonly access, the plugin constructor will restrict the acls */ - if (isset($_POST['open_readonly'])) return ''; - - /* Get LDAP link, check for presence of the lock entry */ - $user = ''; - $ldap = $config->get_ldap_link(); - $ldap->cd(get_ou('lockRDN').get_ou('fusiondirectoryRDN').$config->current['BASE']); - $ldap->search('(&(objectClass=gosaLockEntry)(gosaObject='.base64_encode($object).'))', array('gosaUser')); - if (!$ldap->success()) { - msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), '', LDAP_SEARCH), LDAP_ERROR); + if (isset($_POST['open_readonly'])) { return ''; } - /* Check for broken locking information in LDAP */ - if ($ldap->count() > 1) { - - /* Hmm. We're removing broken LDAP information here and issue a warning. */ - msg_dialog::display(_('Warning'), _('Found multiple locks for object to be locked. This should not happen - cleaning up multiple references.'), WARNING_DIALOG); - - /* Clean up these references now... */ - while ($attrs = $ldap->fetch()) { - $ldap->rmdir($attrs['dn']); - } - + $locks = get_locks($object); + if ($locks === FALSE) { + return FALSE; + } elseif (empty($locks)) { return ''; - - } elseif ($ldap->count() == 1) { - $attrs = $ldap->fetch(); - $user = $attrs['gosaUser'][0]; + } else { + return $locks[0]['user']; } - return $user; } /*! - * \brief Get locks for multiple objects + * \brief Get locks for objects * * Similar as get_lock(), but for multiple objects. * - * \param array $objects Array of Objects for which a lock will be searched + * \param mixed $objects Array of dns for which a lock will be searched or dn of a single object * - * \return A numbered array containing all found locks as an array with key 'dn' - * and key 'user' or '' if an error occured. + * \return A numbered array containing all found locks as an array with key 'object' + * and key 'user', or FALSE if an error occured. */ -function get_multiple_locks($objects) +function get_locks($objects) { global $config; + if (is_array($objects) && count($objects == 1)) { + $objects = reset($objects); + } if (is_array($objects)) { $filter = '(&(objectClass=gosaLockEntry)(|'; foreach ($objects as $obj) { @@ -848,22 +833,36 @@ function get_multiple_locks($objects) } /* Get LDAP link, check for presence of the lock entry */ - $user = ''; $ldap = $config->get_ldap_link(); $ldap->cd(get_ou('lockRDN').get_ou('fusiondirectoryRDN').$config->current['BASE']); $ldap->search($filter, array('gosaUser','gosaObject')); if (!$ldap->success()) { msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), '', LDAP_SEARCH), LDAP_ERROR); - return ''; + return FALSE; } - $users = array(); + $locks = array(); while ($attrs = $ldap->fetch()) { - $dn = base64_decode($attrs['gosaObject'][0]); - $user = $attrs['gosaUser'][0]; - $users[] = array('dn' => $dn, 'user' => $user); + $locks[] = array( + 'object' => base64_decode($attrs['gosaObject'][0]), + 'user' => $attrs['gosaUser'][0], + 'dn' => $attrs['dn'] + ); } - return $users; + + if (!is_array($objects) && (count($locks) > 1)) { + /* Hmm. We're removing broken LDAP information here and issue a warning. */ + msg_dialog::display(_('Warning'), _('Found multiple locks for object to be locked. This should not happen - cleaning up multiple references.'), WARNING_DIALOG); + + /* Clean up these references now... */ + foreach ($locks as $lock) { + $ldap->rmdir($lock['dn']); + } + + return FALSE; + } + + return $locks; } @@ -1481,8 +1480,8 @@ function strict_uid_mode() * * Example usage: * \code - * if (($user = get_lock($this->dn)) != '') { - * return(gen_locked_message($user, $this->dn, TRUE)); + * if ($locks = get_locks($this->dn)) { + * return gen_locked_message($locks, $this->dn, TRUE); * } * \endcode * @@ -1495,7 +1494,7 @@ function strict_uid_mode() * * */ -function gen_locked_message($user, $dn, $allow_readonly = FALSE) +function gen_locked_message($locks, $dn, $allow_readonly = FALSE) { session::set('dn', $dn); $remove = FALSE; @@ -1551,15 +1550,16 @@ function gen_locked_message($user, $dn, $allow_readonly = FALSE) $msg = $dn; } - $smarty->assign ('dn', $msg); + $smarty->assign('dn', $msg); if ($remove) { - $smarty->assign ('action', _('Continue anyway')); + $smarty->assign('action', _('Continue anyway')); } else { - $smarty->assign ('action', _('Edit anyway')); + $smarty->assign('action', _('Edit anyway')); } - $smarty->assign ('message', sprintf(_("You're going to edit the LDAP entry/entries %s"), "<b>".$msg."</b>", "")); + $smarty->assign('message', sprintf(_("You're going to edit the LDAP entry/entries %s"), "<b>".$msg."</b>", "")); + $smarty->assign('locks', $locks); - return $smarty->fetch (get_template_path('islocked.tpl')); + return $smarty->fetch(get_template_path('islocked.tpl')); } diff --git a/include/simpleplugin/class_simpleManagement.inc b/include/simpleplugin/class_simpleManagement.inc index 5daa5c549f15a7fd3aa9af11539baf4f9f358738..05ed7a785df0dc7069337e013770afdede9bbb2a 100644 --- a/include/simpleplugin/class_simpleManagement.inc +++ b/include/simpleplugin/class_simpleManagement.inc @@ -479,7 +479,7 @@ class simpleManagement extends management $this->dns = $target; // check locks - if ($user = get_multiple_locks($this->dns)) { + if ($user = get_locks($this->dns)) { return gen_locked_message($user, $this->dns); } @@ -658,7 +658,7 @@ class simpleManagement extends management if (count($this->dns)) { // check locks - if ($user = get_multiple_locks($this->dns)) { + if ($user = get_locks($this->dns)) { return gen_locked_message($user, $this->dns); }