~ubuntu-branches/ubuntu/vivid/gosa/vivid

« back to all changes in this revision

Viewing changes to opsi/admin/opsiLicenses/class_filterOpsiLicense.inc

Tags: 2.7.1-1
* New upstream release
* Updated packaging to not include smarty (Closes: #620489)
* Fixed case of POSIX (Closes: #620486)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
class filterOpsiLicense {
 
4
 
 
5
    static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "")
 
6
    {
 
7
 
 
8
        if(!class_available('opsi')) return(array());
 
9
 
 
10
        $config= session::global_get('config');
 
11
        $ldap= $config->get_ldap_link(TRUE);
 
12
        $flag= ($scope == "sub")?GL_SUBSEARCH:0;
 
13
        $result= filterOpsiLicense::get_list($base, $filter, $attributes, $category, $objectStorage, $flag);
 
14
 
 
15
        // Prepare filter and split it into attribute and value to search for
 
16
        $filter=preg_replace("/\*/","",$filter);
 
17
        $attr = $value = "";
 
18
        if(!empty($filter) && preg_match("/=/", $filter)){
 
19
            list($attr,$value) = preg_split("/=/", $filter);
 
20
        }
 
21
 
 
22
        // Simple filtering 
 
23
        if(!empty($attr)){
 
24
            foreach($result as $key => $entry){
 
25
                if(!preg_match("/".$value."/i", $entry[$attr][0])){
 
26
                    unset($result[$key]);
 
27
                }
 
28
            }
 
29
        }
 
30
 
 
31
        return(filterACL::unifyResult($result));
 
32
    }
 
33
 
 
34
    static function get_list($base, $filter, $attributes, $category, $objectStorage, $flags= GL_SUBSEARCH)
 
35
    {
 
36
        $config= session::global_get('config');
 
37
        $si = new opsiLicenceHandler($config);
 
38
 
 
39
        if(!$si->enabled()) return(array());
 
40
 
 
41
        $res = $si->listPools();
 
42
        $result = array();
 
43
        if($si->is_error() || !is_array($res)){
 
44
            $this->init_successfull = FALSE;
 
45
            msg_dialog::display(_("Error"),msgPool::siError($si->get_error()),ERROR_DIALOG);
 
46
            return;
 
47
        }else{
 
48
 
 
49
            // Reset the list of licenses
 
50
            foreach($res as $item){
 
51
 
 
52
                $item['objectClass'] = array('fake_opsiLicense');
 
53
 
 
54
                // Fake an ldap entry, this enables ACL checks.
 
55
                $entry = array();
 
56
                $entry['dn'] = "opsi:cn=".$item['cn'][0].",".$config->current['BASE'];
 
57
                foreach($item as $name => $value){
 
58
                    $entry[] = $name;
 
59
                    $entry[$name] = $value;
 
60
                }
 
61
                $entry['count'] = count($item);
 
62
                $result[] = $entry;
 
63
            }
 
64
        }
 
65
        return($result);
 
66
    }
 
67
 
 
68
    static function unifyResult($result)
 
69
    {
 
70
        $res=array();
 
71
        foreach($result as $entry){
 
72
            if(!isset($res[$entry['dn']])){
 
73
                $res[$entry['dn']]=$entry;
 
74
            }
 
75
        }
 
76
        return(array_values($res)); 
 
77
    }
 
78
}
 
79
 
 
80
?>