glpi / inc / vigilotemplate.class.php @ 79397eb3
History | View | Annotate | Download (1.49 KB)
1 | 0d761a49 | Romain CHOLLET | <?php
|
---|---|---|---|
2 | |||
3 | if (!defined('GLPI_ROOT')) { |
||
4 | die("Sorry. You can't access directly to this file"); |
||
5 | } |
||
6 | |||
7 | class PluginVigiloVigiloTemplate extends CommonDBTM { |
||
8 | static function getAllTemplates() { |
||
9 | $hosttdir = "/etc/vigilo/vigiconf/conf.d/hosttemplates"; |
||
10 | $hosttemplates_files = scandir($hosttdir); |
||
11 | $templates = array(); |
||
12 | $pattern = "<template name=\"(\w*)\">"; |
||
13 | |||
14 | foreach($hosttemplates_files as $file) { |
||
15 | $filepath = $hosttdir . DIRECTORY_SEPARATOR . $file; |
||
16 | $test_filepath = preg_match("/(.*).xml$/", $filepath); |
||
17 | 79397eb3 | Romain CHOLLET | |
18 | 0d761a49 | Romain CHOLLET | if (is_file($filepath) AND !empty($test_filepath)) { |
19 | preg_match_all($pattern, file_get_contents($filepath), $matches); |
||
20 | 79397eb3 | Romain CHOLLET | |
21 | 0d761a49 | Romain CHOLLET | foreach ($matches[1] as $match) { |
22 | $templates[] = $match; |
||
23 | } |
||
24 | } |
||
25 | } |
||
26 | |||
27 | sort($templates, SORT_STRING); |
||
28 | array_unshift($templates, '-----'); |
||
29 | return $templates; |
||
30 | } |
||
31 | |||
32 | 79397eb3 | Romain CHOLLET | static function getAjaxArrayTemplates() { |
33 | |||
34 | $templates = PluginVigiloVigiloTemplate::getAllTemplates(); |
||
35 | $id = 0; |
||
36 | $ret = array(); |
||
37 | |||
38 | foreach($templates as $t) { |
||
39 | $ret[] = array("id" => $id, "text" => $t); |
||
40 | $id++;
|
||
41 | } |
||
42 | |||
43 | return $ret; |
||
44 | } |
||
45 | |||
46 | 0d761a49 | Romain CHOLLET | static function getVigiloTemplateNameByID($id) { |
47 | |||
48 | if (is_numeric($id)) { |
||
49 | if ($id === '0') return "NULL"; |
||
50 | $templates = PluginVigiloVigiloTemplate::getAllTemplates(); |
||
51 | return $templates[$id]; |
||
52 | } |
||
53 | } |
||
54 | } |