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 >
Text File  |  2004-03-08  |  8KB  |  290 lines

  1. <?php
  2. /*
  3.    Copyright Intermesh 2003
  4.    Author: Markus Schabel <markus.schabel@tgm.ac.at>
  5.    Author: Michael Borko <michael.borko@tgm.ac.at>
  6.    Version: 1.0 Release date: 22 August 2003
  7.    Version: 1.5 Release date: 27 February 2004
  8.  
  9.    This program is free software; you can redistribute it and/or modify it
  10.    under the terms of the GNU General Public License as published by the
  11.    Free Software Foundation; either version 2 of the License, or (at your
  12.    option) any later version.
  13. */
  14.  
  15. class profiles
  16. {
  17.   var $db;
  18.   var $ldap;
  19.  
  20.   var $mapping;
  21.   var $group_mapping;
  22.  
  23.   function profiles() {
  24.     global $GO_CONFIG;
  25.  
  26.     $this->db = new db();
  27.     $this->db->connect();
  28.  
  29.     if ( $GO_CONFIG->auth_db_type == "ldap" ) {
  30.       $this->ldap = new ldap();
  31.       $this->ldap->connect();
  32.       $this->ldap->bind();
  33.       $this->mapping['ldap'] = array(
  34.       'id'        => 'uidnumber',
  35.       'username'    => 'uid',
  36.       'password'    => 'userpassword',
  37.       'authcode'    => 'goauthcode',
  38.       'first_name'    => 'givenname',
  39.       'middle_name'    => 'middlename',
  40.       'last_name'    => 'sn',
  41.       'initials'    => 'initials',
  42.       'title'        => 'title',
  43.       'sex'        => 'gender',
  44.       'birthday'    => 'birthday',
  45.       'email'        => 'mail',
  46.       'company'    => 'o',
  47.       'department'    => 'ou',
  48.       'function'    => 'businessrole',    // TODO
  49.       'home_phone'    => 'homephone',
  50.       'work_phone'    => 'telephonenumber',
  51.       'fax'        => 'homefacsimiletelephonenumber',
  52.       'cellular'    => 'mobile',
  53.       'country'    => 'homecountryname',
  54.       'state'        => 'homestate',
  55.       'city'        => 'homelocalityname',
  56.       'zip'        => 'homepostalcode',
  57.       'address'    => 'homepostaladdress',
  58.       'homepage'    => 'homeurl',    // TODO: homeurl, workurl, labeledURI
  59.       'work_address'    => 'postaladdress',
  60.       'work_zip'    => 'postalcode',
  61.       'work_country'    => 'c',
  62.       'work_state'    => 'st',
  63.       'work_city'    => 'l',
  64.       'work_fax'    => 'facsimiletelephonenumber',
  65.       'photo'        => 'jpegphoto',
  66.       'acl_id'    => 'goAclID',
  67.       'date_format'    => 'godateformat',
  68.       'time_format'    => 'gotimeformat',
  69.       'thousands_seperator'    => 'gothousandsseperator',
  70.       'decimal_seperator'    => 'gedecimalseperator',
  71.       'currency'    => 'gocurrency',
  72.       'mail_client'    => 'gomailclient',
  73.       'logins'    => 'gologins',
  74.       'lastlogin'    => 'golastlogin',
  75.       'registration_time'    => 'goregistrationtime',
  76.       'samba_user'    => '',            // TODO
  77.       'max_rows_list'    => 'gomaxrowslist',
  78.       'timezone'    => 'gotimezone'
  79.         );
  80.  
  81.       $this->group_mapping['ldap'] = array(
  82.           'id'            => 'gidnumber',
  83.           'name'          => 'sn',
  84.           'user_id'       => 'memberuid'
  85.           );
  86.     }
  87.   }
  88.  
  89.   function get_profile_ldap( $userid ) {
  90.     global $GO_SECURITY, $GO_CONFIG;
  91.     $this->ldap->search( "(&(uidNumber=$userid)(mail=*))", $this->ldap->PeopleDN );
  92.     if ( $this->ldap->num_entries() > 0 ) {
  93.       require_once( $GO_CONFIG->class_path."groups.class.inc" );
  94.       $groups = new groups();
  95.       if ( !$groups->is_in_group( $userid, $GO_SECURITY->group_everyone ) ) {
  96.     $groups->add_user_to_group( $userid, $GO_SECURITY->group_everyone );
  97.       }
  98.       $this->ldap->next_entry();
  99.       $row = array();
  100.       foreach ( $this->mapping['ldap'] as $key => $ldapkey ) {
  101.     if ( $ldapkey == '' ) {
  102.       $row[$key] = '';
  103.     } else if ( $ldapkey == 'goAclID' ) {
  104.       $this->db->query( "SELECT * FROM acl_items WHERE description=\"".$this->ldap->first_value( "mail" )."\"" );
  105.       if ( $this->db->next_record()) {
  106.         $row[$key] = $this->db->f("id");
  107.       } else {
  108.         $acl_id = $GO_SECURITY->get_new_acl( $this->ldap->first_value( "mail" ) );
  109.         $GO_SECURITY->add_group_to_acl( $GO_SECURITY->group_root, $acl_id );
  110.         $row[$key] = $acl_id;
  111.       }
  112.     } else if ( $ldapkey == "uid" ) {
  113.       $uids = $this->ldap->get_values( $ldapkey );
  114.       if ( $uids["count"] > 1 ) {
  115.         $dn = $this->ldap->dn();
  116.         $dn = substr( $dn, 0, strpos( $dn, "," ) );
  117.         $value = substr( $dn, strpos( $dn, "=" ) + 1 );
  118.       } else {
  119.         $value = utf8_decode( $uids[0] );
  120.       }
  121.       if ( !$value ) {
  122.         $value = '';
  123.       }
  124.       $row[$key] = $value;
  125.     } else {
  126.       $value = utf8_decode( $this->ldap->first_value( $ldapkey ) );
  127.       if ( !$value ) {
  128.         $value = '';
  129.       }
  130.       $row[$key] = $value;
  131.     }
  132.       }
  133.       return $row;
  134.     }
  135.     return false;
  136.   }
  137.  
  138.   function convert_profile_ldap( $entry ) {
  139.     global $GO_SECURITY, $GO_CONFIG;
  140.     require_once( $GO_CONFIG->class_path."groups.class.inc" );
  141.     $groups = new groups();
  142.     if ( !$groups->is_in_group( $entry["uidnumber"][0], $GO_SECURITY->group_everyone ) ) {
  143.       $groups->add_user_to_group( $entry["uidnumber"][0], $GO_SECURITY->group_everyone );
  144.     }
  145.     $row = array();
  146.     foreach ( $this->mapping['ldap'] as $key => $ldapkey ) {
  147.       if ( $ldapkey == '' ) {
  148.     $row[$key] = '';
  149.       } else if ( $ldapkey == 'goAclID' ) {
  150.     if ( isset( $entry["mail"][0] ) ) {
  151.       $this->db->query( "SELECT * FROM acl_items WHERE description=\"".$entry["mail"][0]."\"" );
  152.       if ( $this->db->next_record()) {
  153.         $row[$key] = $this->db->f("id");
  154.       } else {
  155.         $acl_id = $GO_SECURITY->get_new_acl( $entry["mail"][0] );
  156.         $GO_SECURITY->add_group_to_acl( $GO_SECURITY->group_root, $acl_id );
  157.         $row[$key] = $acl_id;
  158.       }
  159.     }
  160.       } else if ( $ldapkey == "uid" ) {
  161.     $uids = $this->ldap->get_values( $ldapkey );
  162.     if ( $uids["count"] > 1 ) {
  163.       $dn = $this->ldap->dn();
  164.       $dn = substr( $dn, 0, strpos( $dn, "," ) );
  165.       $value = substr( $dn, strpos( $dn, "=" ) + 1 );
  166.     } else {
  167.       $value = utf8_decode( $uids[0] );
  168.     }
  169.     if ( !$value ) {
  170.       $value = '';
  171.     }
  172.     $row[$key] = $value;
  173.       } else {
  174.     if ( isset( $entry[$ldapkey] ) ) {
  175.       $value = utf8_decode( $entry[$ldapkey][0] );
  176.     } else {
  177.       $value = '';
  178.     }
  179.     if ( !$value ) {
  180.       $value = '';
  181.     }
  182.     $row[$key] = $value;
  183.       }
  184.     }
  185.     return $row;
  186.   }
  187.  
  188.   function get_profile_sql( $userid ) {
  189.     $sql = "SELECT * FROM users WHERE id='$userid'";
  190.     $this->db->query( $sql );
  191.     if ($this->db->next_record())
  192.     {
  193.       return $this->db->Record;
  194.     }
  195.     return false;
  196.   }
  197.  
  198.   function get_profile( $userid ) {
  199.     $sqlrecord = $this->get_profile_sql( $userid );
  200.     //    echo "<pre>";
  201.     //    var_dump( $sqlrecord );
  202.     //    echo "</pre>";
  203.     if ( $this->ldap ) {
  204.       $ldaprecord = $this->get_profile_ldap( $userid );
  205.       if ( $sqlrecord ) {
  206.     foreach ( $sqlrecord as $key => $value ) {
  207.       if ( !$value ) {
  208.         $sqlrecord[$key] = $ldaprecord[$key];
  209.       }
  210.     }
  211.       } else {
  212.     return $ldaprecord;
  213.       }
  214.     }
  215.     return $sqlrecord;
  216.   }
  217.  
  218.   function get_group_profile_ldap( $groupid ) {
  219.     global $GO_SECURITY, $GO_CONFIG;
  220.     $this->ldap->search( "(&(gidNumber=$groupid)(mail=*))", $this->ldap->GroupDN );
  221.     if ( $this->ldap->num_entries() > 0 ) {
  222.       $this->ldap->next_entry();
  223.       $row = array();
  224.       foreach ( $this->group_mapping['ldap'] as $key => $ldapkey ) {
  225.     if ( $ldapkey == '' ) {
  226.       $row[$key] = '';
  227.     } else {
  228.       $value = utf8_decode( $this->ldap->first_value( $ldapkey ) );
  229.       if ( !$value ) {
  230.         $value = '';
  231.       }
  232.       $row[$key] = $value;
  233.     }
  234.       }
  235.       return $row;
  236.     }
  237.     return false;
  238.   }
  239.  
  240.   function convert_group_profile_ldap( $entry ) {
  241.     global $GO_SECURITY, $GO_CONFIG;
  242.     $row = array();
  243.     foreach ( $this->group_mapping['ldap'] as $key => $ldapkey ) {
  244.       if ( $ldapkey == '' ) {
  245.     $row[$key] = '';
  246.       } else {
  247.     if ( isset( $entry[$ldapkey] ) ) {
  248.       $value = utf8_decode( $entry[$ldapkey][0] );
  249.     } else {
  250.       $value = '';
  251.     }
  252.     if ( !$value ) {
  253.       $value = '';
  254.     }
  255.     $row[$key] = $value;
  256.       }
  257.     }
  258.     return $row;
  259.   }
  260.  
  261.   function get_group_profile_sql( $groupid ) {
  262.     $sql = "SELECT * FROM groups WHERE id='$groupid'";
  263.     $this->db->query( $sql );
  264.     if ($this->db->next_record())
  265.     {
  266.       return $this->db->Record;
  267.     }
  268.     return false;
  269.   }
  270.  
  271.   function get_group_profile( $groupid ) {
  272.     $sqlrecord = $this->get_group_profile_sql( $groupid );
  273.     if ( $this->ldap ) {
  274.       $ldaprecord = $this->get_group_profile_ldap( $groupid );
  275.       if ( $sqlrecord ) {
  276.     foreach ( $sqlrecord as $key => $value ) {
  277.       if ( !$value ) {
  278.         $sqlrecord[$key] = $ldaprecord[$key];
  279.       }
  280.     }
  281.       } else {
  282.     return $ldaprecord;
  283.       }
  284.     }
  285.     return $sqlrecord;
  286.   }
  287.  
  288. }
  289. ?>
  290.