From 3ac5cdb4acc4b82c0b306df4e64081a7f7e4213d Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Sun, 30 Oct 2011 12:33:09 -0400
Subject: [PATCH] Also merge properties of child cols of composite address book fields + remove undefined fields from template

---
 program/include/rcube_ldap.php     |   10 +++++++---
 program/steps/addressbook/func.inc |    9 +++++++--
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index 5563475..a816325 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -119,9 +119,13 @@
 
         // support for composite address
         if ($this->fieldmap['street'] && $this->fieldmap['locality']) {
-            $this->coltypes['address'] = array('limit' => max(1, $this->coltypes['locality']['limit']), 'subtypes' => $this->coltypes['locality']['subtypes']);
-            foreach (array('street','locality','zipcode','region','country') as $childcol)
-                unset($this->coltypes[$childcol]);  // remove address child col from global coltypes list
+            $this->coltypes['address'] = array('limit' => max(1, $this->coltypes['locality']['limit']), 'subtypes' => $this->coltypes['locality']['subtypes'], 'childs' => array());
+            foreach (array('street','locality','zipcode','region','country') as $childcol) {
+                if ($this->fieldmap[$childcol]) {
+                    $this->coltypes['address']['childs'][$childcol] = array('type' => 'text');
+                    unset($this->coltypes[$childcol]);  // remove address child col from global coltypes list
+                }
+            }
         }
         else if ($this->coltypes['address'])
             $this->coltypes['address'] = array('type' => 'textarea', 'childs' => null, 'limit' => 1, 'size' => 40);
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index 2082dbd..2b06e62 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -140,8 +140,13 @@
         $CONTACT_COLTYPES = array_intersect_key($CONTACT_COLTYPES, $contact_cols);
         // add associative coltypes definition
         if (!$CONTACTS->coltypes[0]) {
-            foreach ($CONTACTS->coltypes as $col => $colprop)
+            foreach ($CONTACTS->coltypes as $col => $colprop) {
+                if (is_array($colprop['childs'])) {
+                    foreach ($colprop['childs'] as $childcol => $childprop)
+                        $colprop['childs'][$childcol] = array_merge((array)$CONTACT_COLTYPES[$col]['childs'][$childcol], $childprop);
+                }
                 $CONTACT_COLTYPES[$col] = $CONTACT_COLTYPES[$col] ? array_merge($CONTACT_COLTYPES[$col], $colprop) : $colprop;
+            }
         }
     }
 
@@ -597,7 +602,7 @@
 
                         $coltypes[$field] += (array)$colprop;
                         $coltypes[$field]['count']++;
-                        $val = strtr($template, $composite);
+                        $val = preg_replace('/\{\w+\}/', '', strtr($template, $composite));
                     }
                     else if ($edit_mode) {
                         // call callback to render/format value

--
Gitblit v1.9.1