Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. function create_tree($user,$pass){
  2. $connection=ldap_connect('10.0.1.253','389');
  3. ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
  4. if($connection){
  5. $bind = ldap_bind($connection, $user, $pass);
  6. $read=ldap_search($connection,"ou=Nuestra_Capital,dc=local,dc=com,dc=mx","(ou=*)") or exit("Create tree function unable to search!");
  7. $info=ldap_get_entries($connection,$read);
  8. $tree=array();
  9. for($i=0;$i<$info['count'];$i++){
  10. $parent=explode(',',$info[$i]['dn']);
  11. if(count($parent)==5){
  12. //headers
  13. $nam=explode("=",$parent[0]);
  14. $tree[$nam[1]]='';
  15. echo "im a head: ".$nam[1].'<br/>';
  16. }else{
  17. //$tree[$nam[1]][]=$info[$i]['dn'];
  18. $k=count($parent)-4;
  19. do{
  20. $child=explode('=',$parent[$k]);
  21. if($child[1]!='Nuestra_Capital'){
  22. if(array_key_exists($child[1],$tree) || array_key_exists($nam[1],$tree[$child[1]])){
  23. $ex=explode(",",$info[$i]['dn']);
  24. $res=(count($ex)-1)-$k;
  25. $tot=((count($ex)-1)-$res);
  26. $str=explode("=",$ex[$tot-$k]);
  27. $father=explode("=",$ex[($tot-$k)+1]);
  28.  
  29. //echo "original : ".$info[$i]['dn'].'<br/>';
  30. //echo "parsed ".$k." : ".$child[1].'<br/>';
  31. echo "key exists: ".$child[1].'<br/>';
  32. echo "value to be added: ".$str[1].' ?</br>';
  33. $tree[$child[1]][]=$str[1];
  34. }else{
  35. //echo "original: ".$info[$i]['dn'].'<br/>';
  36. //echo "parsed ".$k.": ".$child[1].'<br/><br/><br/>';
  37. //$tree[$nam[1]][$father]=$nam[1];
  38. $tree[$child[1]]='';
  39. }
  40. }
  41. $k--;
  42. }while($k>=0);
  43. }
  44. }
  45. }
  46. ldap_close($connection);
  47. echo "==================== Array =====================<br/><pre>";
  48. echo var_dump($tree);
  49. echo "</pre>";
  50. //return $tree;
  51. }
  52.  
  53. Desired Result :
  54.  
  55. array(20) {
  56. ["IT_Admins"]=>
  57. string(0) ""
  58. ["Grupos"]=>
  59. string(0) ""
  60. ["usuarios_Generales"]=>
  61. string(0) ""
  62. ["Presidencia"]=>
  63. array(2) {
  64. [0]=>
  65. string(21) "Secretaria_Particular"
  66. [1]=>
  67. string(19) "Oficialia_de_Partes"
  68. }
  69. ["Sindicatura"]=>
  70. string(0) ""
  71. ["Direccion_de_administracion"]=>
  72. array(5) {
  73. [0]=>
  74. string(11) "Informatica"
  75. [1]=>
  76. string(29) "DEPARTAMENTO_DE_ADQUISICIONES"
  77. [2]=>
  78. string(33) "Departamento_de_Control_Vehicular"
  79. [3]=>
  80. string(56) "Departamento_de_Servicios_Generales_y_Eventos_Especiales"
  81. [4]=>
  82. string(50) "Departamento_de_Control_de_Almacenes_e_Inventarios"
  83. }
  84. ["Tesoreria"]=>
  85. array(6) {
  86. [0]=>
  87. string(20) "Direccion_de_Egresos"
  88. [1]=>
  89. string(21) "Direccion_de_Ingresos"
  90. array(3){
  91. [0]=>
  92. string(12) "test_failure" =>
  93. array(1){
  94. [0]=>
  95. string(16) "testing_failure2" =>
  96. array(1){
  97. [0]=>
  98. string(16) "testnig_failure3"
  99.  
  100. }
  101. }
  102. }
  103. [2]=>
  104. string(48) "Direccion_de_Contabilidad_y_Control_Presupuestal"
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement