Aleksander Machniak
2014-07-08 43b225d18333530abf17f5ca39140d417cc69490
plugins/acl/acl.php
@@ -9,18 +9,18 @@
 *
 * Copyright (C) 2011-2012, Kolab Systems AG
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */
class acl extends rcube_plugin
@@ -86,8 +86,9 @@
        $this->load_config();
        $search = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC, true);
        $sid    = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC);
        $reqid  = rcube_utils::get_input_value('_reqid', rcube_utils::INPUT_GPC);
        $users  = array();
        $keys   = array();
        if ($this->init_ldap()) {
            $max  = (int) $this->rc->config->get('autocomplete_max', 15);
@@ -105,17 +106,25 @@
                }
                if ($user) {
                    if ($record['name'])
                        $user = $record['name'] . ' (' . $user . ')';
                    $display = rcube_addressbook::compose_search_name($record);
                    $user    = array('name' => $user, 'display' => $display);
                    $users[] = $user;
                    $keys[]  = $display ?: $user['name'];
                }
            }
        }
        sort($users, SORT_LOCALE_STRING);
        if (count($users)) {
            // sort users index
            asort($keys, SORT_LOCALE_STRING);
            // re-sort users according to index
            foreach ($keys as $idx => $val) {
                $keys[$idx] = $users[$idx];
            }
            $users = array_values($keys);
        }
        $this->rc->output->command('ksearch_query_results', $users, $search, $sid);
        $this->rc->output->command('ksearch_query_results', $users, $search, $reqid);
        $this->rc->output->send();
    }
@@ -148,8 +157,10 @@
        // Load localization and include scripts
        $this->load_config();
        $this->specials = $this->rc->config->get('acl_specials', $this->specials);
        $this->add_texts('localization/', array('deleteconfirm', 'norights',
            'nouser', 'deleting', 'saving'));
            'nouser', 'deleting', 'saving', 'newuser', 'editperms'));
        $this->rc->output->add_label('save', 'cancel');
        $this->include_script('acl.js');
        $this->rc->output->include_script('list.js');
        $this->include_stylesheet($this->local_skin_path().'/acl.css');
@@ -233,7 +244,8 @@
        // Advanced rights
        $attrib['id'] = 'advancedrights';
        foreach ($supported as $idx => $val) {
        foreach ($supported as $key => $val) {
            $id = "acl$val";
            $ul .= html::tag('li', null,
                $input->show('', array(
                    'name' => "acl[$val]", 'value' => $val, 'id' => $id))
@@ -283,7 +295,7 @@
        $textfield = new html_inputfield($attrib);
        $fields['user'] = html::label(array('for' => 'iduser'), $this->gettext('username'))
        $fields['user'] = html::label(array('for' => $attrib['id']), $this->gettext('username'))
            . ' ' . $textfield->show();
        // Add special entries
@@ -305,7 +317,7 @@
                    . $val);
            }
            $out = html::tag('ul', array('id' => 'usertype'), $ul, html::$common_attrib);
            $out = html::tag('ul', array('id' => 'usertype', 'class' => $attrib['class']), $ul, html::$common_attrib);
        }
        // Display text input alone
        else {
@@ -383,7 +395,6 @@
            $table->add_header(array('class' => 'acl'.$key, 'title' => $label), $label);
        }
        $i = 1;
        $js_table = array();
        foreach ($acl as $user => $rights) {
            if ($this->rc->storage->conn->user == $user) {
@@ -399,7 +410,7 @@
            }
            $table->add_row(array('id' => 'rcmrow'.$userid));
            $table->add('user', rcube::Q($user));
            $table->add('user', html::a(array('id' => 'rcmlinkrow'.$userid), rcube::Q($user)));
            foreach ($items as $key => $right) {
                $in = $this->acl_compare($userrights, $right);
@@ -432,8 +443,9 @@
        $acl   = trim(rcube_utils::get_input_value('_acl', rcube_utils::INPUT_GPC));
        $oldid = trim(rcube_utils::get_input_value('_old', rcube_utils::INPUT_GPC));
        $acl   = array_intersect(str_split($acl), $this->rights_supported());
        $users = $oldid ? array($user) : explode(',', $user);
        $acl    = array_intersect(str_split($acl), $this->rights_supported());
        $users  = $oldid ? array($user) : explode(',', $user);
        $result = 0;
        foreach ($users as $user) {
            $user = trim($user);
@@ -650,8 +662,9 @@
     */
    private function init_ldap()
    {
        if ($this->ldap)
        if ($this->ldap) {
            return $this->ldap->ready;
        }
        // get LDAP config
        $config = $this->rc->config->get('acl_users_source');
@@ -663,7 +676,7 @@
        // not an array, use configured ldap_public source
        if (!is_array($config)) {
            $ldap_config = (array) $this->rc->config->get('ldap_public');
            $config = $ldap_config[$config];
            $config      = $ldap_config[$config];
        }
        $uid_field = $this->rc->config->get('acl_users_field', 'mail');
@@ -689,12 +702,13 @@
        );
        // search in UID and name fields
        $config['search_fields'] = array_values($config['fieldmap']);
        $config['search_fields']   = array_values($config['fieldmap']);
        $config['required_fields'] = array($uid_field);
        // set search filter
        if ($filter)
        if ($filter) {
            $config['filter'] = $filter;
        }
        // disable vlv
        $config['vlv'] = false;