<?php
/**
* This file handles the The creation of LDAP instance
*
* @package Library
* @subpackage LdapFactory
*/

class LdapFactory
{
	/**
	* initializeLdap
	* Initialise the LDAP Instance according to the user account type $ldapType
	*
	* @param String		$ldapType 		User Account Type
	* @param String		$ldapHost 		LDAP Server Host (hostname or ip address)
	* @param Integer	$ldapPort 		LDAP Server Port
	* @param String		$username 		LDAP Connect Username - Authorized User to connect to LDAP Server
	* @param String		$password 		Password for Connect Username
	* @param String		$baseDn 		The Base DN where our LDAP will operate from
	* @param Boolean	$ldapVersion3 	The Indication flag whether this LDAP Connection is using LDAP Version 3 connection.
	* @param Boolean 	$negotiateTLS 	The Indication flag whether this LDAP Connection is using TLS Negotiation.
	* @param Integer	$followReferral The option for Referral for this LDAP Connection
	*
	* @return Mixed		return not success return null 
	*/
	function initializeLdap ($ldapType,$ldapHost, $ldapPort, $username, $password, $baseDn , $ldapVersion3, $negotiateTLS, $followReferral)
	{
		switch ($ldapType) {
			case 'ed':
			require_once(dirname(__FILE__).'/NovellEDirectory.php');
			return new NovellEDirectory($ldapHost, $ldapPort, $username, $password, $baseDn , $ldapVersion3, $negotiateTLS, $followReferral);
			break;
			case 'po2307':
			require_once(dirname(__FILE__).'/PosixRfc.php');
			return new PosixRfc($ldapHost, $ldapPort, $username, $password, $baseDn , $ldapVersion3, $negotiateTLS, $followReferral);
			break;
			case 'po2307bis':
			require_once(dirname(__FILE__).'/PosixRfcBis.php');
			return new PosixRfcBis($ldapHost, $ldapPort, $username, $password, $baseDn , $ldapVersion3, $negotiateTLS, $followReferral);
			break;
			case 'sam':
			require_once(dirname(__FILE__).'/Samba.php');
			return new Samba($ldapHost, $ldapPort, $username, $password, $baseDn , $ldapVersion3, $negotiateTLS, $followReferral);
			break;
			case 'ad':
			default:
			require_once(dirname(__FILE__).'/MsActiveDirectory.php');
			return new MsActiveDirectory($ldapHost, $ldapPort, $username, $password, $baseDn , $ldapVersion3, $negotiateTLS, $followReferral);
			break;
		}
	}
}