Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
ldap_bridge_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 
31 {
32 
33 
39  {
40  $this->Asset_Edit_Fns();
41 
42  $this->static_screens = Array(
43  'details' => Array(
44  'name' => 'Details',
45  'force_unlock' => TRUE,
46  'lock_type' => 'attributes',
47  ),
48  'permissions' => Array(
49  'name' => 'Permissions',
50  'force_unlock' => TRUE,
51  'lock_type' => 'permissions',
52  ),
53  'linking' => Array(
54  'name' => 'Linking',
55  'force_unlock' => TRUE,
56  'lock_type' => 'links',
57  ),
58  'settings' => Array(
59  'name' => 'Settings',
60  'force_unlock' => TRUE,
61  'lock_type' => 'all',
62  ),
63  'history' => Array(
64  'name' => 'History',
65  'force_unlock' => TRUE,
66  'lock_type' => 'none',
67  ),
68  'logs' => Array(
69  'name' => 'Logs',
70  'force_unlock' => TRUE,
71  'lock_type' => 'none',
72  ),
73  );
74 
75  }//end constructor
76 
77 
88  function paintConnectionTest(&$asset, &$o, $prefix)
89  {
90  $conn = @$asset->connectToLdap();
91  if (is_null($conn) || is_null($conn->ptr)) {
92  // the conncection failed
93  echo '<span style="color: red"><b>'.translate('ldap_unable_to_connect').'</b></span>';
94  } else {
95  echo '<span style="color: green"><b>'.translate('ldap_connected').'</b></span>';
96  }
97 
98  return FALSE;
99 
100  }//end paintConnectionTest()
101 
102 
113  function processConnectionTest(&$asset, &$o, $prefix)
114  {
115  return FALSE;
116 
117  }//end processConnectionTest()
118 
119 
130  function paintConnectionOptions(&$asset, &$o, $prefix)
131  {
132  $configured_options = $asset->attr('ldap_options');
133 
134  // display defined connection options
135  foreach ($asset->getConnectionOptions() as $option => $checked_value) {
136  $checked = FALSE;
137  if (isset($configured_options[$option])) {
138  $checked = TRUE;
139  }
140 
141  if ($asset->writeAccess('attributes')) {
142  $element_name = $prefix.'_ldap_options['.$option.']';
143 
144  check_box($element_name, $checked_value, $checked);
145  ?>
146  <label for="<?php echo $element_name; ?>"><?php echo translate('option_'.strtolower($option)); ?></label><br />
147  <?php
148  } else {
149  $display_image = 'cross';
150  if ($checked) $display_image = 'tick';
151 
152  $mask = '<img src="'.sq_web_path('lib').'/web/images/'.$display_image.'.gif" />';
153  echo $mask.' '.translate('option_'.strtolower($option)).'<br />';
154  }
155  }//end for
156  return $asset->writeAccess('attributes');
157 
158  }//end paintConnectionOptions()
159 
160 
171  function processConnectionOptions(&$asset, &$o, $prefix)
172  {
173  $configured_options = Array();
174  $element_name = $prefix.'_ldap_options';
175 
176  // for security, use defined connection options only
177  foreach ($asset->getConnectionOptions() as $option => $value) {
178  if (isset($_REQUEST[$element_name][$option])) {
179  $configured_options[$option] = $value;
180  }
181  }//end for
182 
183  // only non-default LDAP options are stored, otherwise omitted
184  $asset->setAttrValue('ldap_options', $configured_options);
185 
186  return $asset->writeAccess('attributes');
187 
188  }//end processConnectionOptions()
189 
190 
201  function paintAttributes(&$asset, &$o, $prefix)
202  {
203  $write_access = $asset->writeAccess('attributes');
204 
205  $current = $asset->attr('attributes');
206  $required = Array(
207  'user' => Array(
208  'uid' => translate('ldap_user_id'),
209  'cn' => translate('ldap_common_name'),
210  'fn' => translate('ldap_first_name'),
211  'sn' => translate('ldap_last_name'),
212  'email' => translate('ldap_email_address'),
213  ),
214  'group' => Array(
215  'mo' => translate('ldap_group_membership'),
216  'gm' => translate('ldap_group_members_attribute'),
217  'ou' => translate('ldap_group_name'),
218  ),
219  );
220 
221  if ($write_access) {
222  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
223  }
224 
225  foreach ($required as $section => $section_data) {
226  $o->openSection(translate('ldap_attributes_section_'.$section));
227  foreach ($section_data as $code => $name) {
228  $o->openField($name);
229  $default = (isset($current[$code])) ? $current[$code] : '';
230  if ($write_access) {
231  text_box($prefix.'_attributes['.$code.']', $default, 20);
232  } else {
233  echo $default;
234  }
235  $o->closeField();
236  }
237  $o->closeSection();
238  }
239 
240  return $write_access;
241 
242  }//end paintAttributes()
243 
244 
255  function processAttributes(&$asset, &$o, $prefix)
256  {
257  if (isset($_POST[$prefix.'_attributes'])) {
258  $new_attributes = Array();
259  foreach ($_POST[$prefix.'_attributes'] as $code => $name) {
260  $name = (string)$name;
261  if (empty($name)) continue;
262  $new_attributes[(string)$code] = $name;
263  }
264  return $asset->setAttrValue('attributes', $new_attributes);
265  }
266 
267  return FALSE;
268 
269  }//end processAttributes()
270 
271 
282  function paintUserSetup(&$asset, &$o, $prefix)
283  {
284  $write_access = $asset->writeAccess('attributes');
285 
286  $current = $asset->attr('user_attributes');
287  $sort_by = (isset($current['sort_by'])) ? $current['sort_by'] : '';
288 
289  // connect through the bridge and find out what type of information
290  // we get back for the users
291  $user = $asset->getAsset($asset->id.':'.$asset->attr('bind_dn'), '', FALSE, FALSE, TRUE);
292  if (is_null($user)) {
293  trigger_localised_error('LDAP0001', E_USER_WARNING);
294  return;
295  }
296 
297  $user_type = $asset->attr('user_type');
298  $GLOBALS['SQ_SYSTEM']->am->includeAsset($user_type);
299  $ldap_asset = new $user_type();
300  $ldap_asset_attrs = array_keys($ldap_asset->vars);
301 
302  ?>
303  <table class="sq-backend-table">
304  <tr>
305  <td class="sq-backend-table-header"><?php echo translate('ldap_attribute_name'); ?></td>
306  <td class="sq-backend-table-header"><?php echo translate('ldap_common_name'); ?></td>
307  <td class="sq-backend-table-header"><?php echo translate('display_question'); ?></td>
308  <td class="sq-backend-table-header"><?php echo translate('ldap_use_for_sorting_question'); ?></td>
309  </tr>
310  <?php
311 
312  foreach ($user->vars as $field_name => $field_data) {
313  if (isset($current['show'][$field_name])) {
314  $show = TRUE;
315  $display_name = $current['show'][$field_name];
316  } else {
317  $show = FALSE;
318  $display_name = (isset($current['hide'][$field_name])) ? $current['hide'][$field_name] : $field_name;
319  }
320 
321  ?>
322  <tr>
323  <td class="sq-backend-table-cell"><b><?php echo $field_name; ?></b></td>
324  <td class="sq-backend-table-cell">
325  <?php
326  if ($write_access) {
327  text_box($prefix.'_user_attribute_fields['.$field_name.'][name]', $display_name);
328  } else {
329  echo $display_name;
330  }
331  ?>
332  </td>
333  <td class="sq-backend-table-cell">
334  <?php
335  if ($write_access) {
336  check_box($prefix.'_user_attribute_fields['.$field_name.'][show]', 1, $show);
337  } else {
338  echo ($show) ? translate('yes') : '';
339  }
340  ?>
341  </td>
342  <td class="sq-backend-table-cell">
343  <?php
344  if ($write_access) {
345  if (!in_array($field_name, $ldap_asset_attrs)){
346  radio_button($prefix.'_sort_by', $field_name, ($field_name == $sort_by));
347  }
348  } else {
349  echo ($sort_by == $field_name) ? translate('yes') : '';
350  }
351  ?>
352  </td>
353  </tr>
354  <?php
355  }//end foreach $user fields
356 
357  ?></table><?php
358 
359  return $write_access;
360 
361  }//end paintUserSetup()
362 
363 
374  function processUserSetup(&$asset, &$o, $prefix)
375  {
376  if (!isset($_POST[$prefix.'_user_attribute_fields'])) {
377  return FALSE;
378  }
379 
380  $user_attributes = Array('show' => Array(), 'hide' => Array());
381  foreach ($_POST[$prefix.'_user_attribute_fields'] as $field_name => $field_data) {
382  $show_hide = (isset($field_data['show']) && $field_data['show']) ? 'show' : 'hide';
383  $user_attributes[$show_hide][$field_name] = $field_data['name'];
384  }
385  $user_attributes['sort_by'] = (isset($_POST[$prefix.'_sort_by'])) ? $_POST[$prefix.'_sort_by'] : '';
386 
387  return $asset->setAttrValue('user_attributes', $user_attributes);
388 
389  }//end processUserSetup()
390 
391 
402  function paintLDAPNotAvailable(&$asset, &$o, $prefix)
403  {
404  ?>
405  <p class="sq-backend-warning"><strong><?php echo translate('ldap_not_available_line_1'); ?></strong></p>
406  <p><?php echo translate('ldap_not_available_line_2'); ?></p>
407  <?php
408  return FALSE;
409 
410  }//end paintLDAPNotAvailable()
411 
412 
423  function processLDAPNotAvailable(&$asset, &$o, $prefix)
424  {
425  return FALSE;
426 
427  }//end processLDAPNotAvailable()
428 
429 
436  function ldapAvailable()
437  {
438  return extension_loaded('ldap');
439 
440  }//end ldapAvailable()
441 
442 
449  function ldapNotAvailable()
450  {
451  return !$this->ldapAvailable();
452 
453  }//end ldapNotAvailable()
454 
455 
456 }//end class
457 
458 ?>