home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 April
/
CMCD0404.ISO
/
Software
/
Freeware
/
Programare
/
groupoffice-com-2.01
/
classes
/
profiles.class.inc
< prev
next >
Wrap
Text File
|
2004-03-08
|
8KB
|
290 lines
<?php
/*
Copyright Intermesh 2003
Author: Markus Schabel <markus.schabel@tgm.ac.at>
Author: Michael Borko <michael.borko@tgm.ac.at>
Version: 1.0 Release date: 22 August 2003
Version: 1.5 Release date: 27 February 2004
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.
*/
class profiles
{
var $db;
var $ldap;
var $mapping;
var $group_mapping;
function profiles() {
global $GO_CONFIG;
$this->db = new db();
$this->db->connect();
if ( $GO_CONFIG->auth_db_type == "ldap" ) {
$this->ldap = new ldap();
$this->ldap->connect();
$this->ldap->bind();
$this->mapping['ldap'] = array(
'id' => 'uidnumber',
'username' => 'uid',
'password' => 'userpassword',
'authcode' => 'goauthcode',
'first_name' => 'givenname',
'middle_name' => 'middlename',
'last_name' => 'sn',
'initials' => 'initials',
'title' => 'title',
'sex' => 'gender',
'birthday' => 'birthday',
'email' => 'mail',
'company' => 'o',
'department' => 'ou',
'function' => 'businessrole', // TODO
'home_phone' => 'homephone',
'work_phone' => 'telephonenumber',
'fax' => 'homefacsimiletelephonenumber',
'cellular' => 'mobile',
'country' => 'homecountryname',
'state' => 'homestate',
'city' => 'homelocalityname',
'zip' => 'homepostalcode',
'address' => 'homepostaladdress',
'homepage' => 'homeurl', // TODO: homeurl, workurl, labeledURI
'work_address' => 'postaladdress',
'work_zip' => 'postalcode',
'work_country' => 'c',
'work_state' => 'st',
'work_city' => 'l',
'work_fax' => 'facsimiletelephonenumber',
'photo' => 'jpegphoto',
'acl_id' => 'goAclID',
'date_format' => 'godateformat',
'time_format' => 'gotimeformat',
'thousands_seperator' => 'gothousandsseperator',
'decimal_seperator' => 'gedecimalseperator',
'currency' => 'gocurrency',
'mail_client' => 'gomailclient',
'logins' => 'gologins',
'lastlogin' => 'golastlogin',
'registration_time' => 'goregistrationtime',
'samba_user' => '', // TODO
'max_rows_list' => 'gomaxrowslist',
'timezone' => 'gotimezone'
);
$this->group_mapping['ldap'] = array(
'id' => 'gidnumber',
'name' => 'sn',
'user_id' => 'memberuid'
);
}
}
function get_profile_ldap( $userid ) {
global $GO_SECURITY, $GO_CONFIG;
$this->ldap->search( "(&(uidNumber=$userid)(mail=*))", $this->ldap->PeopleDN );
if ( $this->ldap->num_entries() > 0 ) {
require_once( $GO_CONFIG->class_path."groups.class.inc" );
$groups = new groups();
if ( !$groups->is_in_group( $userid, $GO_SECURITY->group_everyone ) ) {
$groups->add_user_to_group( $userid, $GO_SECURITY->group_everyone );
}
$this->ldap->next_entry();
$row = array();
foreach ( $this->mapping['ldap'] as $key => $ldapkey ) {
if ( $ldapkey == '' ) {
$row[$key] = '';
} else if ( $ldapkey == 'goAclID' ) {
$this->db->query( "SELECT * FROM acl_items WHERE description=\"".$this->ldap->first_value( "mail" )."\"" );
if ( $this->db->next_record()) {
$row[$key] = $this->db->f("id");
} else {
$acl_id = $GO_SECURITY->get_new_acl( $this->ldap->first_value( "mail" ) );
$GO_SECURITY->add_group_to_acl( $GO_SECURITY->group_root, $acl_id );
$row[$key] = $acl_id;
}
} else if ( $ldapkey == "uid" ) {
$uids = $this->ldap->get_values( $ldapkey );
if ( $uids["count"] > 1 ) {
$dn = $this->ldap->dn();
$dn = substr( $dn, 0, strpos( $dn, "," ) );
$value = substr( $dn, strpos( $dn, "=" ) + 1 );
} else {
$value = utf8_decode( $uids[0] );
}
if ( !$value ) {
$value = '';
}
$row[$key] = $value;
} else {
$value = utf8_decode( $this->ldap->first_value( $ldapkey ) );
if ( !$value ) {
$value = '';
}
$row[$key] = $value;
}
}
return $row;
}
return false;
}
function convert_profile_ldap( $entry ) {
global $GO_SECURITY, $GO_CONFIG;
require_once( $GO_CONFIG->class_path."groups.class.inc" );
$groups = new groups();
if ( !$groups->is_in_group( $entry["uidnumber"][0], $GO_SECURITY->group_everyone ) ) {
$groups->add_user_to_group( $entry["uidnumber"][0], $GO_SECURITY->group_everyone );
}
$row = array();
foreach ( $this->mapping['ldap'] as $key => $ldapkey ) {
if ( $ldapkey == '' ) {
$row[$key] = '';
} else if ( $ldapkey == 'goAclID' ) {
if ( isset( $entry["mail"][0] ) ) {
$this->db->query( "SELECT * FROM acl_items WHERE description=\"".$entry["mail"][0]."\"" );
if ( $this->db->next_record()) {
$row[$key] = $this->db->f("id");
} else {
$acl_id = $GO_SECURITY->get_new_acl( $entry["mail"][0] );
$GO_SECURITY->add_group_to_acl( $GO_SECURITY->group_root, $acl_id );
$row[$key] = $acl_id;
}
}
} else if ( $ldapkey == "uid" ) {
$uids = $this->ldap->get_values( $ldapkey );
if ( $uids["count"] > 1 ) {
$dn = $this->ldap->dn();
$dn = substr( $dn, 0, strpos( $dn, "," ) );
$value = substr( $dn, strpos( $dn, "=" ) + 1 );
} else {
$value = utf8_decode( $uids[0] );
}
if ( !$value ) {
$value = '';
}
$row[$key] = $value;
} else {
if ( isset( $entry[$ldapkey] ) ) {
$value = utf8_decode( $entry[$ldapkey][0] );
} else {
$value = '';
}
if ( !$value ) {
$value = '';
}
$row[$key] = $value;
}
}
return $row;
}
function get_profile_sql( $userid ) {
$sql = "SELECT * FROM users WHERE id='$userid'";
$this->db->query( $sql );
if ($this->db->next_record())
{
return $this->db->Record;
}
return false;
}
function get_profile( $userid ) {
$sqlrecord = $this->get_profile_sql( $userid );
// echo "<pre>";
// var_dump( $sqlrecord );
// echo "</pre>";
if ( $this->ldap ) {
$ldaprecord = $this->get_profile_ldap( $userid );
if ( $sqlrecord ) {
foreach ( $sqlrecord as $key => $value ) {
if ( !$value ) {
$sqlrecord[$key] = $ldaprecord[$key];
}
}
} else {
return $ldaprecord;
}
}
return $sqlrecord;
}
function get_group_profile_ldap( $groupid ) {
global $GO_SECURITY, $GO_CONFIG;
$this->ldap->search( "(&(gidNumber=$groupid)(mail=*))", $this->ldap->GroupDN );
if ( $this->ldap->num_entries() > 0 ) {
$this->ldap->next_entry();
$row = array();
foreach ( $this->group_mapping['ldap'] as $key => $ldapkey ) {
if ( $ldapkey == '' ) {
$row[$key] = '';
} else {
$value = utf8_decode( $this->ldap->first_value( $ldapkey ) );
if ( !$value ) {
$value = '';
}
$row[$key] = $value;
}
}
return $row;
}
return false;
}
function convert_group_profile_ldap( $entry ) {
global $GO_SECURITY, $GO_CONFIG;
$row = array();
foreach ( $this->group_mapping['ldap'] as $key => $ldapkey ) {
if ( $ldapkey == '' ) {
$row[$key] = '';
} else {
if ( isset( $entry[$ldapkey] ) ) {
$value = utf8_decode( $entry[$ldapkey][0] );
} else {
$value = '';
}
if ( !$value ) {
$value = '';
}
$row[$key] = $value;
}
}
return $row;
}
function get_group_profile_sql( $groupid ) {
$sql = "SELECT * FROM groups WHERE id='$groupid'";
$this->db->query( $sql );
if ($this->db->next_record())
{
return $this->db->Record;
}
return false;
}
function get_group_profile( $groupid ) {
$sqlrecord = $this->get_group_profile_sql( $groupid );
if ( $this->ldap ) {
$ldaprecord = $this->get_group_profile_ldap( $groupid );
if ( $sqlrecord ) {
foreach ( $sqlrecord as $key => $value ) {
if ( !$value ) {
$sqlrecord[$key] = $ldaprecord[$key];
}
}
} else {
return $ldaprecord;
}
}
return $sqlrecord;
}
}
?>