Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

glpi / src / inc / vigilotemplate.class.php @ 0e8eed1f

History | View | Annotate | Download (1.48 KB)

1 0d761a49 Romain CHOLLET
<?php
2
3 077e4de7 Francois POIROTTE
class PluginVigiloVigiloTemplate extends CommonDBTM
4
{
5
    public static function getAllTemplates()
6
    {
7 0e8eed1f Francois POIROTTE
        $hosttdir = VIGILO_CONFDIR . DIRECTORY_SEPARATOR . 'hosttemplates');
8 0d761a49 Romain CHOLLET
        $hosttemplates_files = scandir($hosttdir);
9
        $templates = array();
10
        $pattern = "<template name=\"(\w*)\">";
11
12 077e4de7 Francois POIROTTE
        foreach ($hosttemplates_files as $file) {
13 0d761a49 Romain CHOLLET
            $filepath = $hosttdir . DIRECTORY_SEPARATOR . $file;
14
            $test_filepath = preg_match("/(.*).xml$/", $filepath);
15 79397eb3 Romain CHOLLET
16 077e4de7 Francois POIROTTE
            if (is_file($filepath) && !empty($test_filepath)) {
17 0d761a49 Romain CHOLLET
                preg_match_all($pattern, file_get_contents($filepath), $matches);
18 79397eb3 Romain CHOLLET
19 0d761a49 Romain CHOLLET
                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 077e4de7 Francois POIROTTE
    public static function getAjaxArrayTemplates()
31
    {
32 79397eb3 Romain CHOLLET
        $templates = PluginVigiloVigiloTemplate::getAllTemplates();
33
        $id = 0;
34
        $ret = array();
35
36 077e4de7 Francois POIROTTE
        foreach ($templates as $t) {
37 79397eb3 Romain CHOLLET
            $ret[] = array("id" => $id, "text" => $t);
38
            $id++;
39
        }
40
41
        return $ret;
42
    }
43
44 077e4de7 Francois POIROTTE
    public static function getVigiloTemplateNameByID($id)
45
    {
46 0d761a49 Romain CHOLLET
        if (is_numeric($id)) {
47 077e4de7 Francois POIROTTE
            if ($id === '0') {
48
                return "NULL";
49
            }
50 0d761a49 Romain CHOLLET
            $templates = PluginVigiloVigiloTemplate::getAllTemplates();
51
            return $templates[$id];
52
        }
53
    }
54
}