Location: PHPKode > projects > LDAP User Management System > lums-0.6/lib/functions.php
<?php
function LUMS_helper_create_password($password)
{
	global $LUMS_Config;

	if (! isset($password) || $password == '')
		return array('No password provided', '');

	switch($LUMS_Config[Main][encryption_scheme]){
		case 'crypt':
			$encrypted = '{CRYPT}' . crypt($password);
			break;
		case 'md5':
			$encrypted = '{MD5}' . base64_encode(md5($password,1));
			break;
		case 'sha1':
			$encrypted = '{SHA}' . base64_encode(sha1($password,1));
			break;
		default:
			return array('No encryption scheme available','');
	}

	return array('',$encrypted);
}

function LUMS_helper_check_syntax($L_info, $syntax)
{
	if (!is_array($L_info))
		$L_info2[] = $L_info;
	else
		$L_info2 = $L_info;
	foreach ($L_info2 as $value){
		switch ($syntax){
			case 'string':
				if (! is_string($value))
					return 0;
				break;
			case 'integer':
				if (! is_numeric($value))
					return 0;
				break;
			case 'mail':
				return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $value);
				break;
			case 'telephonenumber':
				break;
			case 'dn':
				if (! is_string($value))
					return 0;
				break;
			case 'binary':
				break;
		}
	}

	return 1;
}

function LUMS_helper_check_uniqueness($L_conn, $L_basedn, $attribute_name, $L_info)
{
	if (!is_array($L_info))
		$L_info2[] = $L_info;
	else
		$L_info2 = $L_info;
	foreach ($L_info2 as $value){
		$filter = '(' . $attribute_name . '=' . $L_info . ')';
		$sr=@ldap_search($L_conn, $L_basedn, $filter);
        	if ($sr)
                	$results = @ldap_get_entries($L_conn, $sr);
        	else
                	return 0;

        	if ($results[count] > 0)
			return 0;
	}

	return 1;
}

function LUMS_incrementfun_incrementbyone($L_conn, $L_countersdn, $L_countername, $L_interfaceid)
{
	$filter = 'cn=' . $L_countername;
	$base = $filter . ',' . $L_countersdn;
	$sr = @ldap_read ($L_conn, $base, $filter);
	if ($sr)
		$results = @ldap_get_entries($L_conn, $sr);
	else
		return 0;

	if ($results[count] == 0){
		#We need to create the counter since it wasn't found

		$info[objectclass] = 'top';
		$info[objectclass] = 'person';
		$info[cn] = $L_countername;
		$info[sn] = 1 . '.' . $L_interfaceid;
		$entrydn = 'cn=' . $info[cn] . ',' . $L_countersdn;

		if (! @ldap_add($L_conn, $entrydn, $info))
			return 0;

		return $info[sn];
	}
	else {
		print_r($results);

		$counter = $results[0]['sn'][0];

		if ($counter == '' || ! is_numeric($counter))
			return 0;
		$parts = explode('.',$counter);
		if (! is_numeric($parts[0]))
			return 0;
		$counter = $parts[0];
		$counter++;
		$counter = $counter . '.' . $L_interfaceid;
		$info[sn] = $counter;

		if (! @ldap_mod_replace($L_conn, $results[0]['dn'], $info))
			return 0;

		return $counter;
	}

}

function LUMS_trans_elot743($s)
/* Translates  a string to elot 743    */
/* Greeks with Latin Characters        */
{
    $s=ereg_replace("([áåçÁÅÇ])[õý]([âãäæëìíñáéõåïçùÜßýÝüÞþúûÂÃÄÆËÌÍÑÁÉÕÅÏÇÙ¶º¾¸¼¹¿ÚÛ])","\\1v\\2",$s);
    $s=ereg_replace("([áåçÁÅÇ])[Õ¾]([âãäæëìíñáéõåïçùÜßýÝüÞþúûÁÂÃÄÆËÌÍÑÁÉÕÅÏÇÙ¶º¾¸¼¹¿ÚÛ])","\\1V\\2",$s);
    $s=ereg_replace("([áåçÁÅÇ])[õý]([èêîðóôö÷øÈÊÎÐÓÔÖ×Ø\b])","\\1f\\2",$s);
    $s=ereg_replace("([áåçÁÅÇ])[Õ¾]([èêîðóôö÷øÈÊÎÐÓÔÖ×Ø\b])","\\1F\\2",$s);
    
    $s=ereg_replace("ï[õý]","ou",$s);
    $s=ereg_replace("Ï[Õ¾]","OU",$s);
    $s=ereg_replace("Ï[õý]","Ou",$s);
    
    $s=ereg_replace("ãã","ng",$s);
    $s=ereg_replace("ÃÃ","NG",$s);
    $s=ereg_replace("Ãã","Ng",$s);
    
    $s=ereg_replace("ã÷","nch",$s);
    $s=ereg_replace("Ã×","NCH",$s);
    $s=ereg_replace("Ã÷","Nch",$s);
    
    $s=ereg_replace("ãî","nx",$s);
    $s=ereg_replace("ÃÎ","NX",$s);
    $s=ereg_replace("Ãî","Nx",$s);
    
    $s=ereg_replace("(^ìð|ìð$)","b",$s);
    $s=ereg_replace("(^^ÌÐ|^Ìð|ÌÐ$)","B",$s);
    
    $s=ereg_replace("è","th",$s);
    $s=ereg_replace("È([ÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙ¶º¾¸¼¹¿ÚÛ ])","TH\\1",$s);;
    $s=ereg_replace("È([áâãäåæçèéêëìíîïðñóôõö÷øùÜßýÝüÞþúûÀàò])","Th\\1",$s);;
    $s=ereg_replace("è","TH",$s);
	  
    $s=ereg_replace("÷","ch",$s);
    $s=ereg_replace("×([ÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙ¶º¾¸¼¹¿ÚÛ ])","CH\\1",$s);
    $s=ereg_replace("×([áâãäåæçèéêëìíîïðñóôõö÷øùÜßýÝüÞþúûÀàò])","Ch\\1",$s);
    $s=ereg_replace("×","CH",$s);
	
    $s=ereg_replace("ø","ps",$s);
    $s=ereg_replace("Ø([ÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙ¶º¾¸¼¹¿ÚÛ ])","PS\\1",$s);
    $s=ereg_replace("Ø([áâãäåæçèéêëìíîïðñóôõö÷øùÜßýÝüÞþúûÀàò])","Ps\\1",$s);
	$s=ereg_replace("Ø","PS",$s);
	
    $s=strtr($s,"áâãäåæçéêëìíîïðñóôõöùÜßýÝüÞþúûÀàò", "avgdeziiklmnxoprstyfoaiyeoioieiys");
    $s=strtr($s,"ÁÂÃÄÅÆÇÉÊËÌÍÎÏÐÑÓÔÕÖÙ¢¶º¾¸¼¹¿ÚÛ","AVGDEZIIKLMNXOPRSTYFOÁAIYEOIOIY");

	return $s;
}

function LUMS_helper_upcase_gr($s)
/* Creates all the letters of a string to uppercase    */
{
    $s=strtr($s,"áâãäåæçèéêëìíîïðñóôõö÷øùÜßýÝüÞþúûÀàò","ÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙÁÉÕÅÏÇÙIYÉÕÓ");
$s=strtoupper($s);
	return $s;
}

?>
Return current item: LDAP User Management System