[2] | 1 | <?php |
---|
| 2 | /**********************************************************************************\ |
---|
| 3 | * Expresso Administração * |
---|
| 4 | * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br) * |
---|
| 5 | * ----------------------------------------------------------------------------------* |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \***********************************************************************************/ |
---|
| 11 | |
---|
| 12 | class sosectors |
---|
| 13 | { |
---|
| 14 | var $functions; |
---|
[396] | 15 | var $ldap_connection; |
---|
[2] | 16 | |
---|
| 17 | function sosectors() |
---|
| 18 | { |
---|
| 19 | $this->functions = createobject('expressoAdmin1_2.functions'); |
---|
[396] | 20 | |
---|
| 21 | if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) && |
---|
| 22 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) && |
---|
| 23 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) ) |
---|
| 24 | { |
---|
| 25 | $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'], |
---|
| 26 | $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'], |
---|
| 27 | $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']); |
---|
| 28 | } |
---|
| 29 | else |
---|
| 30 | { |
---|
| 31 | $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 32 | } |
---|
[2] | 33 | } |
---|
| 34 | |
---|
| 35 | function exist_sector_name($sector_name, $context) |
---|
| 36 | { |
---|
[396] | 37 | $search = ldap_list($this->ldap_connection, $context, "ou=" . $sector_name); |
---|
| 38 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 39 | |
---|
| 40 | if ($result['count'] == 0) |
---|
| 41 | return false; |
---|
| 42 | else |
---|
| 43 | return true; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | function write_ldap($dn, $info) |
---|
| 47 | { |
---|
[396] | 48 | if (ldap_add($this->ldap_connection, $dn, $info)) |
---|
[2] | 49 | { |
---|
[414] | 50 | $this->db_functions->write_log("write on ldap", "$dn"); |
---|
[396] | 51 | ldap_close($this->ldap_connection); |
---|
[2] | 52 | return true; |
---|
| 53 | } |
---|
| 54 | else |
---|
| 55 | { |
---|
[414] | 56 | echo lang('Error written in LDAP, function write_ldap'); |
---|
[396] | 57 | ldap_close($this->ldap_connection); |
---|
[2] | 58 | return false; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | function get_sector_users($context) |
---|
| 63 | { |
---|
| 64 | $justthese = array("cn", "uidNumber", "uid"); |
---|
| 65 | $filter="(&(phpgwAccountType=u)(uid=*))"; |
---|
[396] | 66 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
| 67 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 68 | return $result; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | function get_sector_groups($context) |
---|
| 72 | { |
---|
| 73 | $justthese = array("cn", "gidnumber"); |
---|
| 74 | $filter="(&(phpgwAccountType=g)(cn=*))"; |
---|
[396] | 75 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
| 76 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 77 | return $result; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | function get_sector_subsectors($context) |
---|
| 81 | { |
---|
| 82 | $justthese = array("ou"); |
---|
| 83 | $filter="(objectClass=organizationalUnit)"; |
---|
[396] | 84 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
| 85 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 86 | return $result; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | function delete_sector_ldap_recursively($connection, $dn) |
---|
| 90 | { |
---|
| 91 | //searching for sub entries |
---|
| 92 | $search=ldap_list($connection,$dn,"ObjectClass=organizationalUnit",array("")); |
---|
| 93 | $info = ldap_get_entries($connection, $search); |
---|
| 94 | |
---|
| 95 | for($i=0;$i<$info['count'];$i++) |
---|
| 96 | { |
---|
| 97 | //deleting recursively sub entries |
---|
| 98 | $result=$this->delete_sector_ldap_recursively($connection,$info[$i]['dn']); |
---|
| 99 | if(!$result) |
---|
| 100 | { |
---|
| 101 | //return result code, if delete fails |
---|
| 102 | return($result); |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | return(ldap_delete($connection,$dn)); |
---|
| 106 | } |
---|
[32] | 107 | |
---|
| 108 | function get_info($context) |
---|
| 109 | { |
---|
| 110 | $filter="(objectClass=organizationalUnit)"; |
---|
[396] | 111 | $search=ldap_search($this->ldap_connection, $context, $filter); |
---|
| 112 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[32] | 113 | return $result; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | function add_attribute($dn, $info) |
---|
| 117 | { |
---|
[396] | 118 | if (ldap_mod_add($this->ldap_connection, $dn, $info)) |
---|
[32] | 119 | { |
---|
[396] | 120 | ldap_close($this->ldap_connection); |
---|
[32] | 121 | return true; |
---|
| 122 | } |
---|
| 123 | else |
---|
| 124 | { |
---|
[396] | 125 | echo 'Erro na escrita no LDAP, funcao add_attribute: ' . ldap_error($this->ldap_connection); |
---|
| 126 | ldap_close($this->ldap_connection); |
---|
[32] | 127 | return false; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | function remove_attribute($dn, $info) |
---|
| 132 | { |
---|
[396] | 133 | if (ldap_mod_del($this->ldap_connection, $dn, $info)) |
---|
[32] | 134 | { |
---|
[396] | 135 | ldap_close($this->ldap_connection); |
---|
[32] | 136 | return true; |
---|
| 137 | } |
---|
| 138 | else |
---|
| 139 | { |
---|
[396] | 140 | echo 'Erro na escrita no LDAP, funcao remove_attribute: ' . ldap_error($this->ldap_connection); |
---|
| 141 | ldap_close($this->ldap_connection); |
---|
[32] | 142 | return false; |
---|
| 143 | } |
---|
| 144 | } |
---|
[2] | 145 | } |
---|
| 146 | ?> |
---|