From: cajus Date: Fri, 7 Aug 2009 15:33:14 +0000 (+0000) Subject: Updated filter class X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c3c300644262f498db741b149b68cb03d8afab3c;p=gosa.git Updated filter class git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14008 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_filter.inc b/gosa-core/include/class_filter.inc index 7b1867c79..607b95a69 100755 --- a/gosa-core/include/class_filter.inc +++ b/gosa-core/include/class_filter.inc @@ -6,8 +6,6 @@ class filter { var $elements= array(); var $elementValues= array(); var $alphabetElements= array(); - var $search; - var $definition; var $category= ""; var $objectStorage= array(); var $objectBase= ""; @@ -18,8 +16,7 @@ class filter { var $baseMode= false; var $scopeMode= "auto"; var $alphabet= null; - var $templatePath= ""; - var $target= ""; + function filter($filename) { @@ -28,101 +25,85 @@ class filter { } } + function load($filename) { - // Load data into array - $xmlData= simplexml_load_file($filename); - if ($xmlData === false) { + $contents = file_get_contents($filename); + $this->xmlData= xml::xml2array($contents, 1); + + if (!isset($this->xmlData['filter'])) { return false; } - // Load definition - if (isset($xmlData->definition)) { - foreach ($xmlData->definition as $entry) { - if (!isset($entry->target) || !isset($entry->template)) { - return false; - } - - // Move information - $this->templatePath= (string)$entry->template; - $this->target= (string)$entry->target; - - // One is enough - break; - } - } + $this->xmlData= $this->xmlData["filter"]; // Load filter - if (isset($xmlData->search)) { - foreach ($xmlData->search as $entry) { - if (!isset($entry->query) || !isset($entry->base) || !isset($entry->scope)) { - return false; - } - - // Move information - $this->baseMode= (string)$entry->base; - $this->scopeMode= (string)$entry->scope; - $this->query= $entry->query; - - // One is enough - break; + if (isset($this->xmlData['search'])) { + if (!isset($this->xmlData['search']['query'][0])){ + $this->xmlData['search']['query']= array($this->xmlData['search']['query']); } + + // Move information + $entry= $this->xmlData['search']; + $this->baseMode= $entry['base']; + $this->scopeMode= $entry['scope']; + $this->query= $entry['query']; + } else { + return false; } // Generate formular data - if (isset($xmlData->element)) { - foreach ($xmlData->element as $element) { + if (isset($this->xmlData['element'])) { + if (!isset($this->xmlData['element'][0])){ + $this->xmlData['element']= array($this->xmlData['element']); + } + foreach ($this->xmlData['element'] as $element) { // Ignore elements without type - if (!isset($element->type)) { + if (!isset($element['type']) || !isset($element['tag'])) { next; } - $tag= (string)$element->tag; + $tag= $element['tag']; + + // Fix arrays + if (isset($element['value']) && !isset($element['value'][0])) { + $element['value']= array($element['value']); + } // Store element for quick access $this->elements[$tag] = $element; // Preset elementValues with default values if exist - if (isset($element->default)) { - $this->elementValues[$tag] = (string)$element->default; + if (isset($element['default']) && !is_array($element['default'])) { + $this->elementValues[$tag] = $element['default']; } else { $this->elementValues[$tag] = ""; } // Does this element react on alphabet links? - if (isset($element->alphabet) && (string)$element->alphabet == "true") { + if (isset($element['alphabet']) && $element['alphabet'] == "true") { $this->alphabetElements[]= $tag; } } } - // Save definition - if (isset($xmlData->definition)) { - $this->definition = $xmlData->definition; - } - - // Save search - if (isset($xmlData->search)) { - $this->search = $xmlData->search; - } - return true; } function getTextfield($element) { - $tag= (string)$element->tag; + $tag= $element['tag']; $result= ""; - if (isset($element->autocomplete)) { + if (isset($element['autocomplete'])) { $frequency= "0.5"; $characters= "1"; - if (isset($element->autocomplete->frequency)) { - $frequency= (string)$element->autocomplete->frequency; + if (isset($element['autocomplete']['frequency'])) { + $frequency= $element['autocomplete']['frequency']; } - if (isset($element->autocomplete->characters)) { - $characters= (string)$element->autocomplete->characters; + if (isset($element['autocomplete']['characters'])) { + $characters= $element['autocomplete']['characters']; } $result.= "
". "