autocomplete.php 2.93 KB
Newer Older
1
2
3
4
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2003-2010  Cajus Pollmeier
5
  Copyright (C) 2011-2016  FusionDirectory
6
7
8
9
10
11
12
13
14
15
16
17
18

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
19
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20
21
22
23
24
*/

/* Basic setup, remove eventually registered sessions */
@require_once ("../include/php_setup.inc");
@require_once ("functions.inc");
25
@require_once ("variables.inc");
26
27
28

session_cache_limiter("private");
session::start();
29
reset_errors();
30
31

/* Logged in? Simple security check */
32
if (!session::global_is_set('ui')) {
33
  logging::log('security', 'unknown', '', array(), 'Error: autocomplete.php called without session');
34
  header('Location: index.php');
35
36
37
38
39
40
41
42
  exit;
}

/* Base completition or filter completition? */
if (isset($_GET['type']) && $_GET['type'] == "base") {

  // Find dn based on name and description
  if (session::is_set("pathMapping") && count($_POST) == 1) {
43
44
45
    $res          = "";
    $pathMapping  = session::get("pathMapping");
    $search       = preg_replace('/&quot;/', '"', current($_POST));
46
47
48
49
50
51

    $config = session::global_get('config');
    foreach ($config->department_info as $dn => $info) {
      if (!isset($pathMapping[$dn])) {
        continue;
      }
52
      if (mb_stristr($info['name'], $search) !== FALSE) {
53
        $res .= "<li>".mark($search, $pathMapping[$dn]).($info['description'] == '' ? "" : "<span class='informal'> [".mark($search, $info['description'])."]</span>")."</li>";
54
55
        continue;
      }
56
      if (mb_stristr($info['description'], $search) !== FALSE) {
57
        $res .= "<li>".mark($search, $pathMapping[$dn]).($info['description'] == '' ? "" : "<span class='informal'> [".mark($search, $info['description'])."]</span>")."</li>";
58
59
        continue;
      }
60
      if (mb_stristr($pathMapping[$dn], $search) !== FALSE) {
61
        $res .= "<li>".mark($search, $pathMapping[$dn]).($info['description'] == '' ? "" : "<span class='informal'> [".mark($search, $info['description'])."]</span>")."</li>";
62
63
64
65
66
67
68
69
70
71
72
73
74
        continue;
      }
    }

    /* Return results */
    if (!empty($res)) {
      echo "<ul>$res</ul>";
    }
  }

} else {

  $ui = session::global_get('ui');
75
  $config = session::global_get('config');
76
77

  /* Is there a filter object arround? */
78
79
  if (session::is_set('autocomplete')) {
    $filter = session::get('autocomplete');
80
81
82
83
84
    $filter->processAutocomplete();
  }
}

?>