Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
data_source_ldap_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_CORE_PACKAGE_PATH.'/data_source/data_source/data_source_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
56  function paintConnectionTest(&$asset, &$o, $prefix)
57  {
58  $conn = null;
59  $conn = @$asset->connectToLdap();
60 
61  if (is_null($conn) || is_null($conn->ptr)) {
62  // the conncection failed
63  echo '<span style="color: red"><b>'.translate('ldap_unable_to_connect').'</b></span>';
64  } else {
65  echo '<span style="color: green"><b>'.translate('ldap_connected').'</b></span>';
66  }
67 
68  return FALSE;
69 
70  }//end paintConnectionTest()
71 
72 
83  function processConnectionTest(&$asset, &$o, $prefix)
84  {
85 
86  return FALSE;
87 
88  }//end processConnectionTest()
89 
90 
101  function paintConnectionOptions(&$asset, &$o, $prefix)
102  {
103  $configured_options = $asset->attr('ldap_options');
104 
105  // display defined connection options
106  foreach ($asset->getConnectionOptions() as $option => $checked_value) {
107  $checked = FALSE;
108  if (isset($configured_options[$option])) {
109  $checked = TRUE;
110  }
111 
112  if ($asset->writeAccess('attributes')) {
113  $element_name = $prefix.'_ldap_options['.$option.']';
114 
115  check_box($element_name, $checked_value, $checked);
116  ?>
117  <label for="<?php echo $element_name; ?>"><?php echo translate('option_'.strtolower($option)); ?></label><br />
118  <?php
119  } else {
120  $display_image = 'cross';
121  if ($checked) $display_image = 'tick';
122 
123  $mask = '<img src="'.sq_web_path('lib').'/web/images/'.$display_image.'.gif" />';
124  echo $mask.' '.translate('option_'.strtolower($option)).'<br />';
125  }
126  }//end for
127  return $asset->writeAccess('attributes');
128 
129  }//end paintConnectionOptions()
130 
131 
142  function processConnectionOptions(&$asset, &$o, $prefix)
143  {
144  $configured_options = Array();
145  $element_name = $prefix.'_ldap_options';
146 
147  // for security, use defined connection options only
148  foreach ($asset->getConnectionOptions() as $option => $value) {
149  if (isset($_REQUEST[$element_name][$option])) {
150  $configured_options[$option] = $value;
151  }
152  }//end for
153 
154  // only non-default LDAP options are stored, otherwise omitted
155  $asset->setAttrValue('ldap_options', $configured_options);
156 
157  return $asset->writeAccess('attributes');
158 
159  }//end processConnectionOptions()
160 
161 
172  function paintLdapBridgeAsset(&$asset, &$o, $prefix)
173  {
174  // get root links
175  $ldap_bridge_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'ldap_bridge', FALSE, 'ldap_bridge');
176  if (empty($ldap_bridge_link)) {
177  $ldap_bridge_asset_id = NULL;
178  } else {
179  $ldap_bridge_asset_id = $ldap_bridge_link['minorid'];
180  }
181 
182  if ($asset->writeAccess('links')) {
183  asset_finder($prefix.'_ldap_bridge', $ldap_bridge_asset_id, Array('ldap_bridge'=>'D'));
184  } else {
185  if (empty($ldap_bridge_asset_id)) {
186  echo 'No LDAP bridge selected';
187  } else {
188  echo get_asset_tag_line($ldap_bridge_asset_id);
189  }
190  }
191  return TRUE;
192 
193  }//end paintLdapBridgeAsset()
194 
195 
206  function processLdapBridgeAsset(&$asset, &$o, $prefix)
207  {
208  $new_ldap_bridge_id = @$_REQUEST[$prefix.'_ldap_bridge']['assetid'];
209 
210  if (!$asset->writeAccess('links')) {
211  return FALSE;
212  }
213 
214  $current_ldap_bridge_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'ldap_bridge', FALSE, 'ldap_bridge');
215  $current_ldap_bridge_asset_id = @$current_ldap_bridge_link['minorid'];
216 
217  if (!empty($current_ldap_bridge_link)) {
218  // if the new ldap_bridge id is not null and is equal to the current
219  // ldap_bridge asset id then return
220  if ((!empty($new_ldap_bridge_id)) && ($current_ldap_bridge_asset_id === $new_ldap_bridge_id)) {
221  return TRUE;
222  } else {
223  // else means that we want to create a new link or we want to
224  // clear the link
225  $GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_ldap_bridge_link['linkid']);
226 
227  // if the new ldap_bridge id is empty means we want to clear the
228  // link we got nothing else to do so return TRUE
229  if (empty($new_ldap_bridge_id))return TRUE;
230  }
231  }
232 
233  if (!empty($new_ldap_bridge_id)) {
234  $new_ldap_bridge_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_ldap_bridge_id);
235  $result_id = $GLOBALS['SQ_SYSTEM']->am->createAssetLink($asset, $new_ldap_bridge_asset, SQ_LINK_NOTICE, 'ldap_bridge');
236  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($new_ldap_bridge_asset);
237 
238  if (empty($result_id)) {
239  trigger_error('Could not link the ldap_bridge to this asset', E_USER_WARNING);
240  return FALSE;
241  }
242  }
243 
244  return TRUE;
245 
246  }//end processLdapBridgeAsset()
247 
248 
259  function paintLDAPNotAvailable(&$asset, &$o, $prefix)
260  {
261  ?>
262  <p class="sq-backend-warning"><strong><?php echo translate('ldap_not_available_line_1'); ?></strong></p>
263  <p><?php echo translate('ldap_not_available_line_2'); ?></p>
264  <?php
265  return FALSE;
266 
267  }//end paintLDAPNotAvailable()
268 
269 
280  function processLDAPNotAvailable(&$asset, &$o, $prefix)
281  {
282  return FALSE;
283 
284  }//end processLDAPNotAvailable()
285 
286 
293  function ldapAvailable()
294  {
295  return extension_loaded('ldap');
296 
297  }//end ldapAvailable()
298 
299 
306  function ldapNotAvailable()
307  {
308  return !$this->ldapAvailable();
309 
310  }//end ldapNotAvailable()
311 
312 
313 //-- LDAP SEARCH FILTER QUERY --//
314 
325  function paintLdapSearchFilter(&$asset, &$o, $prefix)
326  {
327  $wa = $asset->writeAccess('attributes');
328  $search_filter = $asset->attr('search_filter');
329 
330  if ($wa) {
331  $dynamic_vars = $asset->attr('dynamic_vars');
332  if (!empty($dynamic_vars)) {
333  foreach ($dynamic_vars as $var => $value) {
334  $keywords['%%'.$var.'%%'] = $var;
335  }
336  keyword_selector($keywords, $prefix.'_search_filter');
337  }
338  text_area($prefix.'_search_filter', $search_filter, 60, 100, 0, 'style="width: 100%; height: 30em; font-family: \'Courier New\', Courier, monospace; display: block"');
339  } else {
340  if (!empty($search_filter)) {
341  echo nl2br($search_filter);
342  hidden_field($prefix.'_search_filter', $search_filter);
343  }
344  }
345  echo('&nbsp;');
346 
347  return $wa;
348 
349  }//end paintLdapSearchFilter()
350 
351 
362  function processLdapSearchFilter(&$asset, &$o, $prefix)
363  {
364  if (isset($_POST[$prefix.'_search_filter'])) {
365  return $asset->setAttrValue('search_filter', $_POST[$prefix.'_search_filter']);
366  }
367 
368  return FALSE;
369 
370  }//end processLdapSearchFilter()
371 
372 
373 }//end class
374 
375 ?>