patch: UTF8 encoding with LDAP

Robert Marchand robert.marchand@umontreal.ca
Wed, 20 Jun 2001 14:38:41 -0400


---------------------- multipart/mixed attachment
Hi,

   here is patch to use an UTF8 encoded LDAP server with
   turba (0.0.3-cvs).

   The only thing needed is to add a parameter in the sources.php file
like this:

$cfgSources['Bottin_UdeM'] = array(
    'title' => 'Bottin UdeM - complet',
    'type' => 'ldap',
    'params' => array(
	...
        'encoding' => 'utf8',
        'objectclass' => 'person',
        'filter' => 'indic_public=o'
        ),
    'map' => array(
        '__key' => 'dn',
        'name' => 'cn',
        'email' => 'mail',
        'title' => 'title',
        'workPhone' => 'telephonenumber',
        'organization' => 'ou',
  	...

I have tested the patch with both our server (with the encoding
parameter) and bigfoot (without the parameter) and it works.  The only
thing is our server is read only so I didn't bother with the 'add' or
'edit' part.  More work may need to be done for a complete solution.

Thanks.

-- 
 Robert Marchand
 DGTIC-SIT
 Université de Montréal

---------------------- multipart/mixed attachment
*** ldap.php.ORIG	jeudi 31 mai 2001, 16:53:42 EDT
--- ldap.php	mercredi 20 juin 2001, 13:44:29 EDT
***************
*** 24,30 ****
      /** Handle for the current LDAP connection. */
      var $ds = 0;
      
!     
      /**
       * Constructs a new Turba LDAP driver object.
       *
--- 24,35 ----
      /** Handle for the current LDAP connection. */
      var $ds = 0;
      
! /* modif RM 2001/06/20 */
!     /** String containing the encoding charset. Only 'utf8' (beside the
! 	default behaviour) exists for now. 				*/
!     var $encoding = '';
! /* */
! 
      /**
       * Constructs a new Turba LDAP driver object.
       *
***************
*** 44,50 ****
              $this->errstr = 'Connection failure';
              return false;
          }
!         
          if (isset($this->params['bind_dn']) &&
              isset($this->params['bind_password'])) {
              if (!@ldap_bind($this->ds, $this->params['bind_dn'], $this->params['bind_password'])) {
--- 49,60 ----
              $this->errstr = 'Connection failure';
              return false;
          }
! 
! /* modif RM 2001/08/20 */
! 	if (!empty($this->params['encoding'])) {
! 		$this->encoding = $this->params['encoding'];
! 	}
! /* */        
          if (isset($this->params['bind_dn']) &&
              isset($this->params['bind_password'])) {
              if (!@ldap_bind($this->ds, $this->params['bind_dn'], $this->params['bind_password'])) {
***************
*** 73,78 ****
--- 83,91 ----
      {
          $filter = '(&';
          foreach ($criteria as $key => $val) {
+ /* modif: RM 2001/06/20 */
+ 	    if ($this->encoding == 'utf8') $val = utf8_encode($val);
+ /* */
              if (in_array($key, $strict_fields)) {
                  $filter .= ' (' . $key . '=' . $val . ')';
              } else {
***************
*** 172,177 ****
--- 185,195 ----
                      if (!empty($entry[$field])) {
                          for ($j = 0; $j < $entry[$field]['count']; $j++) {
                              if (!empty($addr[$field])) $addr[$field] .= ', ';
+ /* modif RM 2001/06/20 */
+ 			    if ($this->encoding == 'utf8') 
+                             	$addr[$field] .= utf8_decode($entry[$field][$j]);
+ 			    else
+ /* */	
                              $addr[$field] .= $entry[$field][$j];
                          }
                      }

---------------------- multipart/mixed attachment--