Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function create_tree($user,$pass){
- $connection=ldap_connect('10.0.1.253','389');
- ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
- if($connection){
- $bind = ldap_bind($connection, $user, $pass);
- $read=ldap_search($connection,"ou=Nuestra_Capital,dc=local,dc=com,dc=mx","(ou=*)") or exit("Create tree function unable to search!");
- $info=ldap_get_entries($connection,$read);
- $tree=array();
- for($i=0;$i<$info['count'];$i++){
- $parent=explode(',',$info[$i]['dn']);
- if(count($parent)==5){
- //headers
- $nam=explode("=",$parent[0]);
- $tree[$nam[1]]='';
- echo "im a head: ".$nam[1].'<br/>';
- }else{
- //$tree[$nam[1]][]=$info[$i]['dn'];
- $k=count($parent)-4;
- do{
- $child=explode('=',$parent[$k]);
- if($child[1]!='Nuestra_Capital'){
- if(array_key_exists($child[1],$tree) || array_key_exists($nam[1],$tree[$child[1]])){
- $ex=explode(",",$info[$i]['dn']);
- $res=(count($ex)-1)-$k;
- $tot=((count($ex)-1)-$res);
- $str=explode("=",$ex[$tot-$k]);
- $father=explode("=",$ex[($tot-$k)+1]);
- //echo "original : ".$info[$i]['dn'].'<br/>';
- //echo "parsed ".$k." : ".$child[1].'<br/>';
- echo "key exists: ".$child[1].'<br/>';
- echo "value to be added: ".$str[1].' ?</br>';
- $tree[$child[1]][]=$str[1];
- }else{
- //echo "original: ".$info[$i]['dn'].'<br/>';
- //echo "parsed ".$k.": ".$child[1].'<br/><br/><br/>';
- //$tree[$nam[1]][$father]=$nam[1];
- $tree[$child[1]]='';
- }
- }
- $k--;
- }while($k>=0);
- }
- }
- }
- ldap_close($connection);
- echo "==================== Array =====================<br/><pre>";
- echo var_dump($tree);
- echo "</pre>";
- //return $tree;
- }
- Desired Result :
- array(20) {
- ["IT_Admins"]=>
- string(0) ""
- ["Grupos"]=>
- string(0) ""
- ["usuarios_Generales"]=>
- string(0) ""
- ["Presidencia"]=>
- array(2) {
- [0]=>
- string(21) "Secretaria_Particular"
- [1]=>
- string(19) "Oficialia_de_Partes"
- }
- ["Sindicatura"]=>
- string(0) ""
- ["Direccion_de_administracion"]=>
- array(5) {
- [0]=>
- string(11) "Informatica"
- [1]=>
- string(29) "DEPARTAMENTO_DE_ADQUISICIONES"
- [2]=>
- string(33) "Departamento_de_Control_Vehicular"
- [3]=>
- string(56) "Departamento_de_Servicios_Generales_y_Eventos_Especiales"
- [4]=>
- string(50) "Departamento_de_Control_de_Almacenes_e_Inventarios"
- }
- ["Tesoreria"]=>
- array(6) {
- [0]=>
- string(20) "Direccion_de_Egresos"
- [1]=>
- string(21) "Direccion_de_Ingresos"
- array(3){
- [0]=>
- string(12) "test_failure" =>
- array(1){
- [0]=>
- string(16) "testing_failure2" =>
- array(1){
- [0]=>
- string(16) "testnig_failure3"
- }
- }
- }
- [2]=>
- string(48) "Direccion_de_Contabilidad_y_Control_Presupuestal"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement