Projet

Général

Profil

Paste
Télécharger (5,21 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_servers / ldap_servers.theme.inc @ 59ae487e

1
<?php
2

    
3
/**
4
 * @file
5
 * theming functions for ldap_servers module
6
 *
7
 */
8

    
9
/**
10
 * Returns HTML for ldap servers list.
11
 *
12
 * @param $variables
13
 *   An associative array containing:
14
 *   - ldap_servers: an array of one or more ldap server configurations.
15
 *   - actions:  true or false indicating include update, delete, etc. links
16
 *   - type:  'table', 'list', etc for style to render
17
 *
18
 * @ingroup themeable
19
 */
20
function theme_ldap_servers_list($variables) {
21
  extract($variables);
22

    
23
  $table = array(
24
    'header' => array(t('Name'), t('Type'), t('Enabled'), t('Server Address')),
25
    'attributes' => array('id' => 'ldap_servers_servers', 'class' => 'data'),
26
    'colgroups' => array(),
27
    'sticky' => FALSE,
28
    'empty' => '',
29
    'caption' => 'LDAP Server Configurations',
30
  );
31

    
32
  if ($actions) {
33
    $table['header'][] = "Operations";
34
  }
35
  if (count($ldap_servers)) {
36
    foreach ($ldap_servers as $sid => $ldap_server ) {
37
      $row =  array(
38
        $ldap_server->name,
39
        $ldap_server->ldap_type,
40
        ($ldap_server->status == 1) ? "Yes" : "No",
41
        $ldap_server->address
42
          );
43
      if ($actions) {
44
        $admin = new LdapServerAdmin($ldap_server->sid);
45
        $row[] = join(' | ', $admin->getLdapServerActions());
46
      }
47
      $table['rows'][] = $row;
48
    }
49
  }
50
  else {
51
    $table['rows'] = array();
52
  }
53
  $output = theme('table', $table);
54

    
55
  return $output;
56
}
57

    
58
/**
59
 * Returns HTML for ldap server.
60
 *
61
 * @param $variables
62
 *   An associative array containing:
63
 *   - ldap_servers_config: an array of one or more ldap server configurations.
64
 *   - actions:  true or false indicating include update, delete, etc. links
65
 *   - type:  'table', 'list', etc for style to render
66
 *
67
 * @ingroup themeable
68
 */
69

    
70
function theme_ldap_servers_server($variables) {
71
  extract($variables);  // $ldap_server, $actions, $type (see above)
72

    
73
  ldap_servers_module_load_include('php', 'ldap_servers', 'LdapServer.class');
74
  $properties = array();
75
  foreach (LdapServer::field_to_properties_map() as $field_name => $property_name) {
76
    $properties[] = "$field_name = " . print_r($ldap_server->$property_name, TRUE);
77
  }
78

    
79
  if ($actions) {
80
    $admin = new LdapServerAdmin($ldap_server->sid);
81
    $properties = join(' | ', $admin->getLdapServerActions());
82
  }
83

    
84
  $output = theme_item_list(
85
    array(
86
      'items' => $properties,
87
      'type' => 'ul',
88
      'title' => 'Server Properties',
89
      'attributes' => array()
90
      )
91
    );
92

    
93
  return $output;
94
}
95

    
96
function theme_ldap_servers_https_required($vars) {
97

    
98
  if (!isset($vars['site_contact_link']) || empty($vars['site_contact_link'])) {
99
    $vars['site_contact_link'] = 'site admin';
100
  }
101
  return t("You are accessing site_name using an unencrypted connection. For your security,
102
     site_name only supports account logins using a secure protocol such as HTTPS. You can switch
103
     to HTTPS by trying to view this page again after changing the URL in your browser's
104
     location bar to begin with \"https\" instead of \"http\". Please contact
105
      site_contact_link for help if this error continues.", $vars);
106

    
107
}
108

    
109
function theme_ldap_server_token_table($variables) {
110
  $header = array(
111
    array('data' => 'Token', 'sort' => 'asc'),
112
    array('data' => 'Value'),
113
  );
114
  foreach ($variables['tokens'] as $token => $value) {
115
    $rows[] = array('data' => array($token, $value));
116
  }
117
  $token_table = '<div class="content"><h2>' . t('Available Tokens') . '</h2>' .
118
    theme_table(array('colgroups' => NULL, 'caption' => 'tokens', 'header' => $header, 'rows' => $rows, 'sticky' => TRUE, 'attributes' => array(), 'empty' => 'No data')) .
119
    '</div>';
120

    
121
  return $token_table;
122
}
123

    
124
function theme_ldap_server_ldap_entry_table($variables) {
125
  if (!isset($variables['entry']) || !is_array($variables['entry'])) {
126
    return '<p>' . t('No Entry Returned.') . t('</p>');
127
  }
128

    
129
  $header = array('Attribute Name', 'Instance', 'Value', 'token');
130
  $rows = array();
131
  foreach ($variables['entry'] as $key => $value) {
132
    if (is_numeric($key) || $key == 'count') {
133
    }
134
    elseif (count($value) > 1) {
135
      $count = (int)$value['count'];
136
      foreach ($value as $i => $value2) {
137

    
138
        if ((string)$i == 'count') {
139
          continue;
140
        }
141
        elseif ($i == 0 && $count == 1) {
142
          $token = LDAP_SERVERS_TOKEN_PRE . $key . LDAP_SERVERS_TOKEN_POST;
143
        }
144
        elseif ($i == 0 && $count > 1) {
145
          $token = LDAP_SERVERS_TOKEN_PRE . $key . LDAP_SERVERS_TOKEN_DEL . '0' . LDAP_SERVERS_TOKEN_POST;
146
        }
147
        elseif (($i == $count - 1) && $count > 1) {
148
          $token = LDAP_SERVERS_TOKEN_PRE . $key . LDAP_SERVERS_TOKEN_DEL . 'last' . LDAP_SERVERS_TOKEN_POST;
149
        }
150
        elseif ($count > 1) {
151
          $token = LDAP_SERVERS_TOKEN_PRE . $key . LDAP_SERVERS_TOKEN_DEL . $i . LDAP_SERVERS_TOKEN_POST;
152
        }
153
        else {
154
          $token = "";
155
        }
156
        $rows[] = array('data' => array($key, $i, $value2, $token));
157
      }
158
    }
159
  }
160
  $entry_table = '<div class="content"><h2>' . t('LDAP Entry for %username (dn: %dn)', array('%dn' => $variables['dn'], '%username' => $variables['username'])) . '</h2>' . theme('table', array('colgroups' => NULL, 'caption' => 'ldap entry array', 'header' => $header, 'rows' => $rows, 'sticky' => TRUE, 'attributes' => array(), 'empty' => 'No data')) . '</div>';
161
  return $entry_table;
162
}