Projet

Général

Profil

Paste
Télécharger (2,37 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_help / ldap_help.examples.inc @ 91af538d

1
<?php
2

    
3
/**
4
 * @file
5
 * The ldap_help issues provides a filtered watchdog view for ldap issues.
6
 */
7

    
8
/**
9
 * The goal of this function is to illustrate samples from various ldap
10
 * implementations (AD, openldap, etc) alongside default/common
11
 * ldap module configurations.  The data for the ldaps and the configuration
12
 * should be the same as is used in the simpletets.
13
 */
14
function ldap_help_examples() {
15
  module_load_include('php', 'ldap_test', 'LdapTestFunctions.class');
16
  $test_functions = new LdapTestFunctions();
17
  drupal_add_library('system', 'drupal.collapse');
18
  $sample_ldaps = [
19
    'activedirectory' => 'activedirectory1',
20
    'openldap' => 'openldap1',
21
  ];
22

    
23
  $form = [];
24
  foreach ($sample_ldaps as $ldap_type => $sample_ldap_id) {
25

    
26
    $sample_ldap_id = $sample_ldaps[$ldap_type];
27
    $test_functions->populateFakeLdapServerData(LDAP_TEST_LDAP_NAME, $sample_ldap_id);
28
    $data = $test_functions->data['ldap_servers'][$sample_ldap_id]['ldap'];
29
    $form[$sample_ldap_id] = [
30
      '#type' => 'fieldset',
31
      '#title' => $ldap_type,
32
      '#description' => '',
33
      '#attributes' => ['class' => ['collapsible', 'collapsed']],
34
      '#collapsible' => TRUE,
35
      '#collapsed' => TRUE,
36
    ];
37
    foreach (['people', 'groups'] as $ou) {
38
      $form[$sample_ldap_id][$ou] = [
39
        '#type' => 'fieldset',
40
        '#title' => "ou=$ou",
41
        '#description' => '',
42
        '#attributes' => ['class' => ['collapsible', 'collapsed']],
43
        '#collapsible' => TRUE,
44
        '#collapsed' => TRUE,
45
      ];
46
    }
47

    
48
    foreach ($data as $dn => $item) {
49
      $ou = ldap_servers_get_all_rdn_values_from_dn($dn, 'ou');
50
      $ou = $ou[0];
51
      unset($item['count']);
52

    
53
      $li = [];
54
      foreach ($item as $attr => $values) {
55
        unset($values['count']);
56
        if (count($values) == 1) {
57
          $li[] = "$attr: " . $values[0] . '<br/>';
58
        }
59
        else {
60
          $li[] = theme('item_list', ['items' => $values, 'type' => 'ul', 'title' => $attr]);
61
        }
62
      }
63
      $form[$sample_ldap_id][$ou][$dn] = [
64
        '#type' => 'fieldset',
65
        '#attributes' => ['class' => ['collapsible', 'collapsed']],
66
        '#title' => $dn,
67
        '#collapsible' => TRUE,
68
        '#collapsed' => TRUE,
69
      ];
70
      $form[$sample_ldap_id][$ou][$dn][] = [
71
        '#markup' => theme('item_list', ['items' => $li, 'type' => 'ul', 'title' => '']),
72
      ];
73

    
74
    }
75
  }
76

    
77
  return drupal_render($form);
78
}