";
- }
+ // Do not replace escaped \$ - This is required to be able to search for e.g. windows machines.
+ if ($this->value == "") {
+ $filter= preg_replace("/\\$/", '*', $filter);
+ } else {
+ $filter= preg_replace("/\\$/", "*".normalizeLdap($this->value)."*", $filter);
+ }
- /* Save alphabet */
- $this->alphabet= "
$alphabet
";
+ $result= array_merge($result, call_user_func(array($backend, 'query'), $this->base, $this->scope, $filter, $this->attributes, $this->category, $this->objectStorage));
+ }
- return ($this->alphabet);
+ return ($result);
}
- function renderApply()
+ function update()
{
- return ("");
- }
+ if (isset($_POST['FILTER_PID']) && $_POST['FILTER_PID'] == $this->pid) {
+ // Save input field
+ if (isset($_POST['search_filter'])) {
+ $this->value= validate($_POST['search_filter']);
+ }
+ // Save scope if needed
+ if ($this->scopeMode == "auto" && isset($_POST['act']) && $_POST['act'] == "toggle-subtree") {
+ $this->scope= ($this->scope == "one")?"sub":"one";
+ }
+
+ // Switch filter?
+ if (isset($_POST['act'])) {
+ foreach ($this->searches as $tag => $cfg) {
+ if ($_POST['act'] == "filter-$tag") {
+ $this->setSearch($tag);
+ break;
+ }
+ }
+ }
+ }
- function renderScope()
- {
- $checked= $this->scope == "sub"?" checked":"";
- return " "._("Search in subtrees");
}
- function renderFilter()
+ function getCompletitionList($config, $value="*")
{
- $smarty= get_smarty();
- $smarty->assign("ALPHABET", $this->renderAlphabet());
- $smarty->assign("APPLY", $this->renderApply());
- $smarty->assign("SCOPE", $this->renderScope());
- $smarty->assign("BASE", $this->renderBase());
-
- // Load template and replace elementsHtml[]
- foreach ($this->elements as $tag => $element) {
- $htmlCode= "";
- switch ($element->type) {
- case "textfield":
- $htmlCode = $this->getTextfield($tag);
- break;
+ global $class_mapping;
+ $res= array();
- case "checkbox":
- $htmlCode = $this->getCheckbox($tag);
- break;
+ // Load result attributes
+ $attributes= $config['autocomplete']['attribute'];
+ if (!is_array($attributes)) {
+ $attributes= array($attributes);
+ }
- case "combobox":
- $htmlCode = $this->getCombobox($element);
- break;
+ // Do the query
+ $result= array();
- default:
- die ("Unknown element type specified!");
+ // Is backend available?
+ # FIXME
+ $queries= $config['query'];
+ if (!isset($queries[0])){
+ $queries= array($queries);
+ }
+ foreach ($queries as $query) {
+ $backend= "filter".$query['backend'];
+ if (!isset($class_mapping["$backend"])) {
+ die("Invalid backend specified in search config.");
+ }
+ $filter= preg_replace("/\\$/", "*".normalizeLdap($value)."*", $query['filter']);
+
+ $result= array_merge($result, call_user_func(array($backend, 'query'), $this->base, $this->scope, $filter, $attributes,
+ $this->category, $this->objectStorage));
+ }
+
+ foreach ($result as $entry) {
+ foreach ($attributes as $attribute) {
+ if (is_array($entry[$attribute])) {
+ for ($i= 0; $i<$entry[$attribute]['count']; $i++) {
+ if (mb_stristr($entry[$attribute][$i], $value)) {
+ $res[]= $entry[$attribute][$i];
+ }
+ }
+ } else {
+ $res[]= $entry[$attribute];
+ }
}
- $smarty->assign("$tag", $htmlCode);
}
- // Load template
- return ("".$smarty->fetch(get_template_path("filter/$this->templatePath")));
+ return $res;
}
- function query()
+ function processAutocomplete()
{
global $class_mapping;
$result= array();
- // Go thru all queries and merge results
- foreach ($this->query as $query) {
- if (!isset($query->backend) || !isset($query->filter) || !isset($query->attribute)) {
- die("No backend specified in search config.");
- }
+ // Introduce maximum number of entries
+ $max= 25;
- // Is backend available?
- $backend= "filter".(string)$query->backend;
- if (!isset($class_mapping["$backend"])) {
- die("Invalid backend specified in search config.");
- }
+ if(isset($this->searches[$this->search]['autocomplete'])){
+ $result= $this->getCompletitionList($this->searches[$this->search], $_POST['search_filter']);
+ $result= array_unique($result);
+ asort($result);
- // Load filter and attributes
- $filter= $query->filter;
- $attributes= array();
- foreach($query->attribute as $attr) {
- $attributes[]= (string)$attr;
- }
-
- // Generate final filter
- foreach ($this->elements as $tag => $element) {
- $e_set= (string)$element->set;
- $e_unset= (string)$element->unset;
-
- if ($this->elementValues[$tag] == "") {
- $e_unset= preg_replace('/\$/', $this->elementValues[$tag], $e_unset);
- $filter= preg_replace("/\\$$tag/", $e_unset, $filter);
- } else {
- $e_set= preg_replace('/\$/', $this->elementValues[$tag], $e_set);
- $filter= preg_replace("/\\$$tag/", $e_set, $filter);
+ echo '
";
}
}
- if (isset($_POST['FILTER_LOADED'])) {
- // Load post values and adapt filter, base and scope accordingly - but
- // only if we didn't get a _GET
- foreach ($this->elements as $tag => $element) {
- if (isset($_POST[$tag])){
- $this->elementValues[$tag]= validate($_POST[$tag]);
- } else {
- $this->elementValues[$tag]= "";
- }
+ // User defined filters
+ $first= true;
+ foreach (userFilter::getFilter($this->category) as $tag => $config) {
+ if ($tag == $this->search) {
+ $result.= "