]> git.sur5r.net Git - contagged/blobdiff - inc/functions.php
Store tags in Thunderbird custom fields
[contagged] / inc / functions.php
index 52f101654d98554fbf3c55bc277ffd0f26e67dc8..bb24f23691114a22b7e5ff30d0729e96cb508ef1 100644 (file)
@@ -67,7 +67,7 @@ function do_ldap_bind($user,$pass,$dn=""){
   if(empty($dn)){
     //anonymous bind to lookup users
     //blank binddn or blank bindpw will result in anonymous bind
-    if(!ldap_bind($LDAP_CON,$conf['anonbinddn'],$conf['anonbindpw'])){
+    if(!@ldap_bind($LDAP_CON,$conf['anonbinddn'],$conf['anonbindpw'])){
       die("can not bind for user lookup");
     }
 
@@ -89,7 +89,7 @@ function do_ldap_bind($user,$pass,$dn=""){
   }
 
   //bind with dn
-  if(ldap_bind($LDAP_CON,$dn,$pass)){
+  if(@ldap_bind($LDAP_CON,$dn,$pass)){
     //bind successful -> set up session
     set_session($user,$pass,$dn);
     return true;
@@ -230,15 +230,19 @@ function prepare_ldap_entry($in){
             $out[$FIELDS["_$key"]][] = $value; //shouldn't happen, but to be sure
         }
     }else{
-        // no mapping found - assume it to be a LDAP attribute (shouldn't happen)
-        if(is_array($value)){
-            $out[$key] = $value;
-        }else{
-            $out[$key][] = $value;
-        }
+        // no mapping found we ignore it
     }
   }
 
+  // special tag handling for Thunderbird
+  if($conf['tbtaghack'] && in_array('contactPerson',$OCLASSES)){
+    if($in['marker'][0]) $out['custom1'][] = $in['marker'][0];
+    if($in['marker'][1]) $out['custom2'][] = $in['marker'][1];
+    if($in['marker'][2]) $out['custom3'][] = $in['marker'][2];
+    if($in['marker'][3]) $out['custom4'][] = $in['marker'][3];
+  }
+
+
   // add the Objectclasses
   $out['objectclass'] = $OCLASSES;
 
@@ -482,4 +486,28 @@ function utf8_encode_array(&$array) {
   }
 }
 
+/**
+ * Returns all the fields used in the template
+ *
+ * Returned fields are already decoded to LDAP internals
+ */
+function get_fields_from_template($tpl){
+    global $smarty;
+    global $FIELDS;
+    $tpl  = $smarty->template_dir.'/'.$tpl;
+    $data = @file_get_contents($tpl);
+    $matches = array();
+    preg_match_all('/\$entry\.(\w+)/',$data,$matches);
+    $matches = array_unique((array) $matches[1]);
+    $return  = array();
+    foreach($matches as $f){
+        if($FIELDS[$f]){
+            $return[] = $FIELDS[$f];
+        }elseif($FIELDS["_$f"]){
+            $return[] = $FIELDS["_$f"];
+        }
+    }
+    return $return;
+}
+
 ?>