Changeset 23 for trunk/phpgwapi
- Timestamp:
- 05/07/07 15:06:04 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpgwapi/inc/class.sector_search_ldap.inc.php
r2 r23 98 98 return $sectors_list; 99 99 } 100 101 // Retorna os organizações com os options prontos 102 function get_organizations($context, $selected='', $referral=false ,$show_invisible_ou=false) 103 { 104 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 105 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 106 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 107 108 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 109 110 if ($referral) 111 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1); 112 else 113 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 114 115 ldap_bind($ldap_conn,$dn,$passwd); 116 117 $justthese = array("dn"); 118 $filter = $show_invisible_ou ? "(ou=*)" : "(& (ou=*) (!(phpgwAccountVisible=-1)) )"; 119 $search=ldap_search($ldap_conn, $context, $filter, $justthese); 120 121 ldap_sort($ldap_conn, $search, "ou"); 122 $info = ldap_get_entries($ldap_conn, $search); 123 ldap_close($ldap_conn); 124 125 // Retiro o count do array info e inverto o array para ordenação. 126 for ($i=0; $i<$info["count"]; $i++) 127 { 128 $dn = $info[$i]["dn"]; 129 130 // Necessário, pq em uma busca com ldapsearch ou=*, traz tb o próprio ou. 131 if (strtolower($dn) == $context) 132 continue; 133 134 $array_dn = ldap_explode_dn ( $dn, 1 ); 135 136 $array_dn_reverse = array_reverse ( $array_dn, true ); 137 138 array_pop ( $array_dn_reverse ); 139 140 $inverted_dn[$dn] = implode ( ".", $array_dn_reverse ); 141 } 142 143 // Ordenação 144 natcasesort($inverted_dn); 145 146 // Construção do select 147 $level = 0; 148 foreach ($inverted_dn as $dn=>$invert_ufn) 149 { 150 $display = ''; 151 152 $array_dn_reverse = explode ( ".", $invert_ufn ); 153 $array_dn = array_reverse ( $array_dn_reverse, true ); 154 155 $level = count( $array_dn ) - 4; 156 157 if ($level == 0) 158 $display .= '+'; 159 else { 160 for ($i=0; $i<$level; $i++) 161 $display .= '---'; 162 } 163 164 reset ( $array_dn ); 165 $display .= ' ' . (current ( $array_dn ) ); 166 167 $dn = trim(strtolower($dn)); 168 if ( $dn == $selected ) 169 $select = ' selected'; 170 else 171 $select = ''; 172 $options .= "<option value='$dn'$select>$display</option>"; 173 } 174 175 // Cria a primeira entrada na combo 176 $first_sector_ufn = ldap_dn2ufn($context); 177 $first_sector_string = split(",", $first_sector_ufn); 178 $options = "<option value='$context'>" . strtoupper($first_sector_string[0]) . "</option>" . $options; 179 180 return $options; 181 } 100 182 } 101 183 ?>
Note: See TracChangeset
for help on using the changeset viewer.