Projet

Général

Profil

Paste
Télécharger (4,72 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_user / ldap_user.theme.inc @ bc175c27

1
<?php
2

    
3
/**
4
 * @file
5
 *   theme functions for ldap_user module
6
 */
7

    
8
/**
9
 * turns array of variables to a form embedded in one table for each ldap server
10
 */
11
function theme_ldap_user_conf_form($variables) {
12

    
13
  $form = $variables['form'];
14
  $tables = array();
15

    
16
  foreach ($form as $key => $element) {
17
    $parts = explode('__', $key);
18
    if (count($parts) == 4 && isset($element['#row']) && isset($element['#col'])) {
19
      list($direction, $discard, $column_name, $i) = $parts;
20
      $row = $element['#row'];
21
      $col = $element['#col'];
22
      $tables[$direction]['rows'][$row][$col] = array('data' => drupal_render($form[$key]), 'class' => array('module'), 'colspan' => 1);
23
    }
24
  }
25

    
26
  $output = drupal_render_children($form);
27
  $ldap_user_conf_admin = ldap_user_conf('admin');
28

    
29
  foreach ($tables as $direction => $table) {
30
    if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
31

    
32
      $direction_text = 'todrupal';
33

    
34
      $header = array(
35
        array(
36
          'data' => t('Remove'),
37
          'rowspan' => 1,
38
          'class' => 'mixedcase'
39
        ),
40
        array(
41
          'data' => t('Source LDAP Tokens. (See http://drupal.org/node/1245736) ') ,
42
          'class' => 'mixedcase',
43
          'rowspan' => 1,
44
          'colspan' => 2,
45
        ),
46
        array(
47
          'data' => t('Target Drupal Attribute'),
48
          'rowspan' => 1,
49
          'class' => 'mixedcase',
50
        ),
51
        array('data' => t('When Should Attribute Be Synchronized to Drupal?'),
52
          'colspan' => count($ldap_user_conf_admin->provisionsDrupalEvents),
53
          'rowspan' => 1,
54
          'class' => 'mixedcase'
55
        ),
56

    
57
      );
58

    
59
      $second_header = array(
60
        array('data' => t(''),
61
              'header' => TRUE,
62
              'class' => 'mixedcase',
63
              ),
64
        array('data' => t('e.g: "[sn]", "[mail:0]", "[ou:last]", "[sn], [givenName]" etc.
65
                Constants such as "17" or "imported" should not be enclosed in [].'),
66
              'header' => TRUE,
67
              'class' => 'mixedcase',
68
              ),
69
        array('data' => t('Convert From Binary?'),
70
              'class' => 'mixedcase',
71
              'header' => TRUE
72
              ),
73
        array('data' => "",
74
              'header' => TRUE,
75
              ),
76
      );
77

    
78
      foreach ($ldap_user_conf_admin->provisionsDrupalEvents as $col_id => $col_name) {
79
        $second_header[] = array('data' => $col_name, 'header' => TRUE, 'class' => 'mixedcase');
80
      }
81
    }
82
    else { // to ldap
83

    
84
      $direction_text = 'toldap';
85

    
86
      $header = array(
87
        array(
88
          'data' => t('Remove'),
89
          'rowspan' => 1,
90
          'class' => 'mixedcase'
91
        ),
92
        array(
93
          'data' => t('Source Drupal User Attribute') ,
94
          'class' => 'mixedcase',
95
          'rowspan' => 1,
96
          'colspan' => 3,
97
        ),
98
        array(
99
          'data' => t('Target LDAP Token'),
100
          'rowspan' => 1,
101
          'class' => 'mixedcase',
102
        ),
103
        array(
104
          'data' => t('When Should Attribute Be Synchronized to LDAP?'),
105
          'colspan' => count($ldap_user_conf_admin->provisionsLdapEvents),
106
          'rowspan' => 1,
107
          'class' => 'mixedcase',
108
        ),
109
      );
110

    
111
      $second_header = array(
112
        array(
113
          'data' => t(''),
114
          'header' => TRUE
115
        ),
116
        array(
117
          'data' => t('(Select "user tokens" to use token field)'),
118
          'header' => TRUE,
119
          'class' => 'mixedcase'
120
        ),
121
        array(
122
          'data' => t('Source Drupal User tokens such as: "[property.name]", "[field.field_fname] [field.field_lname]". Constants such as "from_drupal" or "18" should not be enclosed in []'),
123
          'header' => TRUE,
124
          'class' => 'mixedcase'
125
        ),
126
        array(
127
          'data' => t('Convert From Binary'),
128
          'header' => TRUE,
129
          'class' => 'mixedcase'
130
        ),
131
        array(
132
          'data' => t('Use singular token format such as [sn], [givenName], etc.'),
133
          'header' => TRUE,
134
          'class' => 'mixedcase'
135
        ),
136
      );
137
      foreach ($ldap_user_conf_admin->provisionsLdapEvents as $col_id => $col_name) {
138
        $second_header[] = array('data' => $col_name, 'header' => TRUE, 'class' => 'mixedcase');
139
      }
140
    }
141

    
142
    // #col is ignored, so sort table columns here
143
    foreach ($table['rows'] as $row_id => $row) {
144
      $discard = ksort($row);
145
      $table['rows'][$row_id] = $row;
146
    }
147

    
148
    $table['header'] = $header;
149
    $table['attributes'] = array('class' => array('ldap-provision-' . $direction_text));
150
    array_unshift($table['rows'], $second_header);
151
    $table_themed = theme('table', $table);
152
    $rendered_table = theme('table', $table);
153
    $output = str_replace( '[replace_with_table__' . $direction . ']', $rendered_table, $output);
154
  }
155

    
156
  return $output;
157

    
158
}