Changeset 4269 in subversion


Ignore:
Timestamp:
Nov 25, 2010 1:53:14 PM (2 years ago)
Author:
thomasb
Message:

Complete implementation of rcube_kolab_contacts; add localization texts for proprietary contact fields

Location:
trunk/plugins/kolab_addressbook
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/kolab_addressbook/kolab_addressbook.php

    r4247 r4269  
    2424        // load required plugin 
    2525        $this->require_plugin('kolab_core'); 
     26         
     27        $this->add_texts('localization'); 
    2628         
    2729        // register hooks 
     
    122124            // TODO: add more Kolab-specific fields 
    123125             
    124             // TODO: re-order fields 
     126            // re-order fields according to the coltypes list 
     127            $block = array(); 
     128            $contacts = reset($this->sources); 
     129            foreach ($contacts->coltypes as $col => $prop) { 
     130                if (isset($p['form']['info']['content'][$col])) 
     131                    $block[$col] = $p['form']['info']['content'][$col]; 
     132            } 
     133             
     134            $p['form']['info']['content'] = $block; 
    125135        } 
    126136         
  • trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php

    r4267 r4269  
    2828      'department'   => array('limit' => 1), 
    2929      'gender'       => array('limit' => 1), 
    30       'birthday'     => array('limit' => 1), 
     30      'initials'     => array('type' => 'text', 'size' => 6, 'limit' => 1, 'label' => 'kolab_addressbook.initials'), 
    3131      'email'        => array('subtypes' => null), 
    3232      'phone'        => array(), 
     
    3434      'website'      => array('limit' => 1, 'subtypes' => null), 
    3535      'address'      => array('limit' => 2, 'subtypes' => array('home','business')), 
     36      'birthday'     => array('limit' => 1), 
     37      'anniversary'  => array('type' => 'date', 'size' => 12, 'limit' => 1, 'label' => 'kolab_addressbook.anniversary'), 
     38      // TODO: define more Kolab-specific fields such as: office-location, profession, manager-name, assistant, spouse-name, children, language, latitude, longitude, pgp-publickey, free-busy-url 
    3639      'notes'        => array(), 
    37       // define additional coltypes 
    38       'initials'     => array('type' => 'text', 'size' => 6, 'limit' => 1), 
    39       'anniversary'  => array('type' => 'date', 'size' => 12, 'limit' => 1), 
    40       // TODO: define more Kolab-specific fields such as: office-location, profession, manager-name, assistant, spouse-name, children, language, latitude, longitude, pgp-publickey, free-busy-url 
    4140    ); 
    4241     
     
    4948    private $contacts; 
    5049    private $distlists; 
     50    private $groupmembers; 
    5151    private $id2uid; 
    5252    private $filter; 
     
    8686        $this->coltypes['phone']['subtypes'] = $format->_phone_types; 
    8787        $this->coltypes['address']['subtypes'] = $format->_address_types; 
    88         $this->coltypes['anniversary']['label'] = rcube_label('anniversary'); 
     88         
     89        // set localized labels for proprietary cols 
     90        foreach ($this->coltypes as $col => $prop) { 
     91            if (is_string($prop['label'])) 
     92                $this->coltypes[$col]['label'] = rcube_label($prop['label']); 
     93        } 
    8994         
    9095        // fetch objects from the given IMAP folder 
     
    209214    public function search($fields, $value, $strict=false, $select=true) 
    210215    { 
     216        // search by ID 
     217        if ($fields == $this->primary_key) { 
     218            return $this->get_record($value); 
     219        } 
     220         
    211221        // TODO: currently not implemented 
    212222        return new rcube_result_set(0, ($this->list_page-1) * $this->page_size); 
     
    269279        $this->_fetch_groups(); 
    270280         
    271         foreach ($this->distlists as $gid => $group) { 
    272             foreach ($group['member'] as $member) { 
    273                 if ($member['ID'] == $id) 
    274                     $out[$gid] = $group['last-name']; 
    275             } 
     281        foreach ((array)$this->groupmembers[$id] as $gid) { 
     282            if ($group = $this->distlists[$gid]) 
     283                $out[$gid] = $group['last-name']; 
    276284        } 
    277285         
     
    375383    { 
    376384        $this->_fetch_contacts(); 
     385        $this->_fetch_groups(); 
    377386         
    378387        if (!is_array($ids)) 
     
    392401                } 
    393402                else { 
    394                     // TODO: remove from distribution lists 
    395                     unset($this->contacts[$id], $this->id2uid[$id]); 
     403                    // remove from distribution lists 
     404                    foreach ((array)$this->groupmembers[$id] as $gid) 
     405                        $this->remove_from_group($gid, $id); 
     406                     
     407                    // clear internal cache 
     408                    unset($this->contacts[$id], $this->id2uid[$id], $this->groupmembers[$id]); 
    396409                    $count++; 
    397410                } 
     
    433446    function create_group($name) 
    434447    { 
    435         // TODO: implement this 
    436         return false; 
    437     } 
    438  
    439     /** 
    440      * Delete the given group and all linked group members 
    441      * 
    442      * @param string Group identifier 
    443      * @return boolean True on success, false if no data was changed 
    444      */ 
    445     function delete_group($gid) 
    446     { 
    447         // TODO: implement this 
    448         return false; 
    449     } 
    450  
    451     /** 
    452      * Rename a specific contact group 
    453      * 
    454      * @param string Group identifier 
    455      * @param string New name to set for this group 
    456      * @return boolean New name on success, false if no data was changed 
    457      */ 
    458     function rename_group($gid, $newname) 
    459     { 
    460         $this->_fetch_groups(); 
    461         $list = $this->distlists[$gid]; 
    462          
    463         if ($newname != $list['last-name']) { 
    464             $list['last-name'] = $newname; 
    465             $saved = $this->liststorage->save($list, $list['uid']); 
    466         } 
     448        $this->_fetch_groups(); 
     449        $result = false; 
     450         
     451        $list = array( 
     452            'uid' => $this->liststorage->generateUID(), 
     453            'last-name' => $name, 
     454            'member' => array(), 
     455        ); 
     456        $saved = $this->liststorage->save($list); 
    467457 
    468458        if (PEAR::isError($saved)) { 
     
    474464            return false; 
    475465        } 
     466        else { 
     467            $id = md5($list['uid']); 
     468            $this->distlists[$record['ID']] = $list; 
     469            $result = array('id' => $id, 'name' => $name); 
     470        } 
     471 
     472        return $result; 
     473    } 
     474 
     475    /** 
     476     * Delete the given group and all linked group members 
     477     * 
     478     * @param string Group identifier 
     479     * @return boolean True on success, false if no data was changed 
     480     */ 
     481    function delete_group($gid) 
     482    { 
     483        $this->_fetch_groups(); 
     484        $result = false; 
     485         
     486        if ($list = $this->distlists[$gid]) 
     487            $deleted = $this->liststorage->delete($list['uid']); 
     488 
     489        if (PEAR::isError($deleted)) { 
     490            raise_error(array( 
     491              'code' => 600, 'type' => 'php', 
     492              'file' => __FILE__, 'line' => __LINE__, 
     493              'message' => "Error deleting distribution-list object from the Kolab server:" . $deleted->getMessage()), 
     494            true, false); 
     495        } 
     496        else 
     497            $result = true; 
     498         
     499        return $result; 
     500    } 
     501 
     502    /** 
     503     * Rename a specific contact group 
     504     * 
     505     * @param string Group identifier 
     506     * @param string New name to set for this group 
     507     * @return boolean New name on success, false if no data was changed 
     508     */ 
     509    function rename_group($gid, $newname) 
     510    { 
     511        $this->_fetch_groups(); 
     512        $list = $this->distlists[$gid]; 
     513         
     514        if ($newname != $list['last-name']) { 
     515            $list['last-name'] = $newname; 
     516            $saved = $this->liststorage->save($list, $list['uid']); 
     517        } 
     518 
     519        if (PEAR::isError($saved)) { 
     520            raise_error(array( 
     521              'code' => 600, 'type' => 'php', 
     522              'file' => __FILE__, 'line' => __LINE__, 
     523              'message' => "Error saving distribution-list object to Kolab server:" . $saved->getMessage()), 
     524            true, false); 
     525            return false; 
     526        } 
    476527 
    477528        return $newname; 
     
    497548        $list = $this->distlists[$gid]; 
    498549 
    499         foreach ($list['member'] as $i => $member) 
     550        foreach ((array)$list['member'] as $i => $member) 
    500551            $exists[] = $member['ID']; 
    501              
     552         
    502553        // substract existing assignments from list 
    503554        $ids = array_diff($ids, $exists); 
    504          
     555 
    505556        foreach ($ids as $contact_id) { 
    506557            if ($uid = $this->id2uid[$contact_id]) { 
     
    513564                    ); 
    514565                } 
     566                $this->groupmembers[$contact_id][] = $gid; 
    515567                $added++; 
    516568            } 
     
    569621        } 
    570622        else { 
     623            // remove group assigments in local cache 
     624            foreach ($ids as $id) { 
     625                $j = array_search($gid, $this->groupmembers[$id]); 
     626                unset($this->groupmembers[$id][$j]); 
     627            } 
    571628            $this->distlists[$gid] = $list; 
    572629            return true; 
     
    603660    { 
    604661        if (!isset($this->distlists)) { 
    605             $this->distlists = array(); 
     662            $this->distlists = $this->groupmembers = array(); 
    606663            foreach ((array)$this->liststorage->getObjects() as $record) { 
    607664                // FIXME: folders without any distribution-list objects return contacts instead ?! 
     
    609666                    continue; 
    610667                $record['ID'] = md5($record['uid']); 
    611                 foreach ($record['member'] as $i => $member) 
    612                     $record['member'][$i]['ID'] = md5($member['uid']); 
     668                foreach ((array)$record['member'] as $i => $member) { 
     669                    $mid = md5($member['uid']); 
     670                    $record['member'][$i]['ID'] = $mid; 
     671                    $this->groupmembers[$mid][] = $record['ID']; 
     672                } 
    613673                $this->distlists[$record['ID']] = $record; 
    614674            } 
     
    638698        foreach ((array)$record['email'] as $i => $email) 
    639699            $out['email'][] = $email['smtp-address']; 
     700             
     701        if (!$record['email'] && $record['emails']) 
     702            $out['email'] = preg_split('/,\s*/', $record['emails']); 
    640703 
    641704        foreach ((array)$record['phone'] as $i => $phone) 
Note: See TracChangeset for help on using the changeset viewer.