Projet

Général

Profil

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

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

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5 bc175c27 Assos Assos
 * Theming functions for the LDAP authorization module.
6 85ad3d82 Assos Assos
 */
7
8 bc175c27 Assos Assos
/**
9
 *
10
 */
11 85ad3d82 Assos Assos
function theme_ldap_authorization_admin_index(&$variables) {
12
  $consumers = $variables['consumers'];
13
14
  $table = array(
15 bc175c27 Assos Assos
    'header' => array(t('LDAP Server ID'), t('Description'), t('Module'), t('Consumer Type'), t('Enabled'), t('Operations')),
16 85ad3d82 Assos Assos
    'attributes' => array('id' => 'ldap_consumer_confs', 'class' => 'data'),
17
    'colgroups' => array(),
18
    'sticky' => FALSE,
19
    'empty' => '',
20
    'caption' => t('LDAP Authorization Configurations'),
21
    'rows' => array(),
22
  );
23
24
  foreach ($consumers as $consumer_type => $consumer) {
25
26
    if ($consumer->consumerConf->inDatabase) {
27
      $admin = new LdapAuthorizationConsumerConfAdmin($consumer);
28 bc175c27 Assos Assos
      $actions = join(' | ', $admin->getLdapAuthorizationConsumerActions());
29 85ad3d82 Assos Assos
    }
30
    else {
31 bc175c27 Assos Assos
      $actions = l(t('add'), LDAP_SERVERS_MENU_BASE_PATH . '/authorization/add/' . $consumer->consumerType);
32 85ad3d82 Assos Assos
    }
33
34
    $table['rows'][] = array(
35
      $consumer->consumerConf->sid,
36
      $consumer->name,
37
      $consumer->consumerModule,
38
      $consumer_type,
39
      ($consumer->consumerConf->status) ? t('Yes') : t('No'),
40 bc175c27 Assos Assos
      $actions,
41 85ad3d82 Assos Assos
    );
42
  }
43
  return theme('table', $table);
44
45
}
46
47 bc175c27 Assos Assos
/**
48
 *
49
 */
50 85ad3d82 Assos Assos
function theme_ldap_authorization_test_results($variables) {
51
52
  $results = $variables['results'];
53
  $consumer = $variables['consumer'];
54
  $notifications = $variables['notifications'];
55
  $consumer_conf_link = l($consumer->consumerType, LDAP_SERVERS_MENU_BASE_PATH . '/authorization/edit/' . $consumer->consumerType);
56
  $server_link = l($consumer->consumerConf->sid, LDAP_SERVERS_MENU_BASE_PATH . '/servers/edit/' . $consumer->consumerConf->sid);
57
58
  $table = array(
59
    'header' => array(t('Drupal Username'), t('Authorization Type'), t('Authorization IDs'), t('Configuration'), t('LDAP Server Configuration')),
60
    'attributes' => array('id' => 'ldap_authorization_authorizations', 'class' => 'data'),
61
    'colgroups' => array(),
62
    'sticky' => FALSE,
63
    'empty' => '',
64
    'caption' => t('LDAP Authorizations Test Results for consumer %consumer', array('%consumer' => $consumer->name)),
65
    'rows' => array(),
66
  );
67
68
  if (count($results)) {
69
    foreach ($results as $username => $user_results) {
70
      $row = array();
71
      if ($user = user_load_by_name($username)) {
72
        $username_link = l($username, 'user/' . $user->uid . '/edit');
73
      }
74
      foreach ($user_results as $consumer_type => $authorizations) {
75
        if (is_array($authorizations) && count($authorizations) > 0) {
76
          $authorizations = $consumer->convertToFriendlyAuthorizationIds($authorizations);
77 bc175c27 Assos Assos
          $authorizations_text = theme('item_list', array('items' => array_values($authorizations), 'title' => NULL, 'type' => 'ul', 'attributes' => array()));
78 85ad3d82 Assos Assos
        }
79
        else {
80
          $authorizations_text = "";
81
        }
82
        $row = array($username, $consumer->name, $authorizations_text, $consumer_conf_link, $server_link);
83
        $table['rows'][] = $row;
84
      }
85
86
      foreach ($notifications[$username] as $consumer_type => $user_notifications) {
87
        $authorizations_text = "";
88
        if ($consumer_type == 'all') {
89
          $authorizations_text = ldap_authorization_map_errors($user_notifications, $consumer_conf_link);
90
        }
91
        elseif (is_array($user_notifications) && count($user_notifications) > 0) {
92
          foreach ($user_notifications as $i => $notification) {
93 bc175c27 Assos Assos
            $authorizations_text .= ldap_authorization_map_errors($notification, $consumer_conf_link);
94 85ad3d82 Assos Assos
          }
95
        }
96
        $row = array($username_link, $consumer->name, $authorizations_text, $consumer_conf_link, $server_link);
97
        $table['rows'][] = $row;
98
      }
99
    }
100
  }
101
102
  $output = theme('table', $table);
103
104
  return $output;
105
106 bc175c27 Assos Assos
}
107 85ad3d82 Assos Assos
108 bc175c27 Assos Assos
/**
109
 *
110
 */
111 85ad3d82 Assos Assos
function ldap_authorization_map_errors($err_id, $consumer_conf_link) {
112
113
  $tokens = array('%consumer_conf_link' => $consumer_conf_link);
114
  switch ($err_id) {
115
116
    case  LDAP_AUTHORIZATION_USER_LDAP_NOT_FOUND:
117
      $authorizations_text = t('LDAP entry for drupal user not found.', $tokens);
118 bc175c27 Assos Assos
      break;
119 85ad3d82 Assos Assos
120
    case LDAP_AUTHORIZATION_USER_NOT_LDAP_AUTHENTICATED:
121
      $authorizations_text = t('LDAP Authorizations not applied because user is not
122
      authenticated via LDAP and configuration requires is (%consumer_conf_link).', $tokens);
123 bc175c27 Assos Assos
      break;
124 85ad3d82 Assos Assos
125
    case LDAP_AUTHORIZATION_MAP_NOT_CONF_FOR_LOGON:
126
      $authorizations_text = t('LDAP Authorizations not configured to be executed on logon in  (%consumer_conf_link).', $tokens);
127 bc175c27 Assos Assos
      break;
128 85ad3d82 Assos Assos
129
    case LDAP_AUTHORIZATION_NOT_APPLY_USER_1:
130
      $authorizations_text = t('LDAP Authorizations not applicable to user 1.', $tokens);
131 bc175c27 Assos Assos
      break;
132 85ad3d82 Assos Assos
133
    case LDAP_AUTHORIZATION_SERVER_CONFIG_NOT_FOUND:
134
      $authorizations_text = t('Enabled LDAP server configuration not found for given ldap consumer type in (%consumer_conf_link).', $tokens);
135 bc175c27 Assos Assos
      break;
136 85ad3d82 Assos Assos
137
    default:
138
      $authorizations_text = "Failed.";
139
  }
140
141
  return $authorizations_text;
142
}