Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

glpi / src / inc / vigilotemplate.class.php @ 077e4de7

History | View | Annotate | Download (1.47 KB)

1
<?php
2

    
3
class PluginVigiloVigiloTemplate extends CommonDBTM
4
{
5
    public static function getAllTemplates()
6
    {
7
        $hosttdir = "/etc/vigilo/vigiconf/conf.d/hosttemplates";
8
        $hosttemplates_files = scandir($hosttdir);
9
        $templates = array();
10
        $pattern = "<template name=\"(\w*)\">";
11

    
12
        foreach ($hosttemplates_files as $file) {
13
            $filepath = $hosttdir . DIRECTORY_SEPARATOR . $file;
14
            $test_filepath = preg_match("/(.*).xml$/", $filepath);
15

    
16
            if (is_file($filepath) && !empty($test_filepath)) {
17
                preg_match_all($pattern, file_get_contents($filepath), $matches);
18

    
19
                foreach ($matches[1] as $match) {
20
                    $templates[] = $match;
21
                }
22
            }
23
        }
24

    
25
        sort($templates, SORT_STRING);
26
        array_unshift($templates, '-----');
27
        return $templates;
28
    }
29

    
30
    public static function getAjaxArrayTemplates()
31
    {
32
        $templates = PluginVigiloVigiloTemplate::getAllTemplates();
33
        $id = 0;
34
        $ret = array();
35

    
36
        foreach ($templates as $t) {
37
            $ret[] = array("id" => $id, "text" => $t);
38
            $id++;
39
        }
40

    
41
        return $ret;
42
    }
43

    
44
    public static function getVigiloTemplateNameByID($id)
45
    {
46
        if (is_numeric($id)) {
47
            if ($id === '0') {
48
                return "NULL";
49
            }
50
            $templates = PluginVigiloVigiloTemplate::getAllTemplates();
51
            return $templates[$id];
52
        }
53
    }
54
}