Location: PHPKode > projects > LDAPted > ldapted/includes/extsource/LDAPSelection.php
<?php
/***************************************************************************
 *
 *                                  LDAPSelection.php
 *                              -------------------
 *
 *   begin                : Friday, Jul 5, 2002
 *   copyright            : (C) 2002 The Kabramps Team
 *   email                : hide@address.com,
 *                          hide@address.com
 *
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   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 2 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.
 *   (http://www.gnu.org/licenses/gpl.html)
 *
 ***************************************************************************/

class LDAPSelection extends Selection {
  
  function LDAPSelection ($attribute, $xmlDoc) {
    $this->init($attribute, $xmlDoc);
  }
  
  function get_selections($value = array()) {
    global $host;
    global $bind_dn;
    global $pw;
    
    $fields = $this->xmlDoc->get_selection_fields($this->attribute);
    if ( $fields["searchbase"] ) {
      $basedn = $fields["searchbase"];
    } else {
      $basedn = $this->xmlDoc->get_basedn();
    }
    $returnattrib = $fields["returnAttrib"];
    $filter = $fields["filter"];
    
    $ldap = new LDAPinterface ($host, $bind_dn, $pw);
    $result = $ldap->search( $basedn, array($returnattrib), $filter,true);
    $return = array();
    // generate the selection and filter out the existing values
    // given bei the 'value' array.
    for ($i=0; $i<count($result);$i++){
      if ( count($value) > 0) {
	for ($j=0; $j<count($value);$j++) {
	  if ($result[$i][$returnattrib][0] == $value[$j]) {
	    $j=count($value);
	  } elseif ($j == (count($value)-1)) {
	    $return[] = $result[$i][$returnattrib][0];
	  }
	}
      } else {
	$return[] = $result[$i][$returnattrib][0];
      }
    }
    return $return;
  }
  
}
?>
Return current item: LDAPted