Revision 79397eb3
[#1572] Chargement du champ vigilo_template en ajax
Change-Id: I2874cda44e4f06a0f5f5c6dc3c9081229f73627f
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/2322
Reviewed-by: Francois POIROTTE <francois.poirotte@c-s.fr>
Tested-by: Francois POIROTTE <francois.poirotte@c-s.fr>
Vigilo/VigiloHost.php | ||
---|---|---|
43 | 43 |
if ($template_name && $template_name !== "N/A") { |
44 | 44 |
$this->children[] = new VigiloHostTemplate($this->computer->getField("template_name")); |
45 | 45 |
} |
46 |
/*$refs = array( |
|
47 |
"glpi_operatingsystems" => "operatingsystems_id", |
|
48 |
"glpi_operatingsystemversions" => "operatingsystemversions_id", |
|
49 |
"glpi_operatingsystemservicepacks" => "operatingsystemservicepacks_id", |
|
50 |
); |
|
51 |
|
|
52 |
$model = array(); |
|
53 |
foreach ($refs as $table => $field) { |
|
54 |
$id = $this->computer->fields[$field]; |
|
55 |
$value = Dropdown::getDropdownName($table, $id); |
|
56 |
if ($value !== "" && $value !== null && $value !== " " |
|
57 |
&& $value !== false && $value !== "-----" && $value !== 'N/A' |
|
58 |
) { |
|
59 |
$model[] = $value; |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
if (!count($model)) { |
|
64 |
$model = "default"; |
|
65 |
} else { |
|
66 |
$model = implode(" - ", $model); |
|
67 |
} |
|
68 |
|
|
69 |
$this->children[] = new VigiloHostTemplate($model);*/ |
|
70 |
|
|
71 | 46 |
|
72 | 47 |
$template_number = $this->computer->getField("vigilo_template"); |
73 | 48 |
if ($template_number !== '0' && $template_number !== 'N/A') { |
Vigilo/VigiloTestSoftware.php | ||
---|---|---|
24 | 24 |
|
25 | 25 |
public function addRelevantTestWith($softwareName) |
26 | 26 |
{ |
27 |
if (strstr($softwareName, "vigilo-test"))
|
|
27 |
if (strstr($softwareName, "vigilo-test")) |
|
28 | 28 |
{ |
29 | 29 |
$functionArray=array("addCustomTest", array($softwareName)); |
30 | 30 |
} |
... | ... | |
41 | 41 |
protected function addCustomTest($softwareName) |
42 | 42 |
{ |
43 | 43 |
$software_name = str_replace('vigilo-test-', '', $softwareName); |
44 |
$explode_software_name = explode('-', $software_name, 2);
|
|
44 |
$explode_software_name = explode('-', $software_name, 2);
|
|
45 | 45 |
$args=array(); |
46 | 46 |
switch(strtolower($explode_software_name[0])) |
47 | 47 |
{ |
48 |
case "process":
|
|
48 |
case "process": |
|
49 | 49 |
$args[]=new VigiloArg('processname', $explode_software_name[1]); |
50 | 50 |
$explode_software_name[0] = "Process"; |
51 | 51 |
break; |
52 |
case "service":
|
|
52 |
case "service": |
|
53 | 53 |
$args[]=new VigiloArg('svcname', $explode_software_name[1]); |
54 | 54 |
$explode_software_name[0] = "Service"; |
55 | 55 |
break; |
56 |
case "tcp":
|
|
57 |
$args[]=new VigiloArg('port', $explode_software_name[1]);
|
|
56 |
case "tcp": |
|
57 |
$args[]=new VigiloArg('port', $explode_software_name[1]); |
|
58 | 58 |
$explode_software_name[0] = "TCP"; |
59 | 59 |
break; |
60 | 60 |
default: return; |
61 | 61 |
} |
62 | 62 |
|
63 |
return new VigiloTest($explode_software_name[0], $args);
|
|
63 |
return new VigiloTest($explode_software_name[0], $args); |
|
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
protected function addNTPTest() |
ajax/getVTValue.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
if (strpos(filter_input(INPUT_SERVER, "PHP_SELF"), "getVTValue.php")) { |
|
4 |
include ("../../../inc/includes.php"); |
|
5 |
header("Content-Type: text/html; charset=UTF-8"); |
|
6 |
Html::header_nocache(); |
|
7 |
} |
|
8 |
if (!defined('GLPI_ROOT')) { |
|
9 |
die("Can not acces directly to this file"); |
|
10 |
} |
|
11 |
|
|
12 |
$ret = array(); |
|
13 |
$tmp = PluginVigiloVigiloTemplate::getAjaxArrayTemplates(); |
|
14 |
|
|
15 |
foreach ($tmp as $template) { |
|
16 |
$ret['results'][] = $template; |
|
17 |
} |
|
18 |
|
|
19 |
$ret['count'] = count($ret['results']); |
|
20 |
|
|
21 |
/*$ret['results'][] = array("id" => 0, "text" => "-----"); |
|
22 |
$ret['results'][] = array("id" => 1, "text" => "linux"); |
|
23 |
$ret['results'][] = array("id" => 2, "text" => "windows"); |
|
24 |
*/ |
|
25 |
echo json_encode($ret); |
|
26 |
|
|
27 |
?> |
hook.php | ||
---|---|---|
37 | 37 |
if ($computer->getField("is_template")==0) { |
38 | 38 |
global $DB; |
39 | 39 |
$template_id = PluginVigiloVigiloTemplate::getVigiloTemplateNameByID($computer->getField("vigilo_template")); |
40 |
|
|
40 |
|
|
41 | 41 |
if(!empty($template_id)) { |
42 | 42 |
$query = "UPDATE glpi_computers |
43 | 43 |
SET vigilo_template = '" . PluginVigiloVigiloTemplate::getVigiloTemplateNameByID($computer->getField("vigilo_template")) . |
44 | 44 |
"' WHERE id = " . $computer->getField("id") . ";"; |
45 | 45 |
$DB->queryOrDie($query, "update vigilo_template field"); |
46 | 46 |
} |
47 |
|
|
47 |
|
|
48 | 48 |
$query = "UPDATE glpi_computers |
49 | 49 |
SET is_dynamic = ' 1 |
50 | 50 |
' WHERE id = " . $computer->getField("id") . ";"; |
... | ... | |
96 | 96 |
global $DB; |
97 | 97 |
$computer=new Computer(); |
98 | 98 |
$computer->getFromDB($computer_software_version->getField("computers_id")); |
99 |
$this->update($computer);
|
|
99 |
$this->update($computer); |
|
100 | 100 |
} |
101 | 101 |
|
102 | 102 |
public function manageSoftwares($software) |
inc/computer.class.php | ||
---|---|---|
8 | 8 |
static function showComputerInfo($item) { |
9 | 9 |
global $CFG_GLPI; |
10 | 10 |
$templates = PluginVigiloVigiloTemplate::getAllTemplates(); |
11 |
$value = array_search($item->getField('vigilo_template'), $templates);
|
|
12 |
if (empty($value)) {
|
|
13 |
$value = 0;
|
|
11 |
$value = $item->getField('vigilo_template');
|
|
12 |
if ($value === 'NULL') {
|
|
13 |
$value = '-----';
|
|
14 | 14 |
} |
15 | 15 |
echo '<table class="tab_cadre_fixe tab_glpi" width="100%">'; |
16 | 16 |
echo '<tr class="tab_bg_1"><th colspan="4">Vigilo Template</th></tr>'; |
17 | 17 |
echo '<tr class="tab_bg_1">'; |
18 | 18 |
echo '<td>Vigilo Template</td>'; |
19 | 19 |
echo '<td>'; |
20 |
Dropdown::showFromArray('vigilo_template', $templates, array('value' => $value)); |
|
20 |
Dropdown::show('PluginVigiloComputer', array("name" => "vigilo_template", |
|
21 |
"emptylabel" => $value, |
|
22 |
"url" => $CFG_GLPI["root_doc"] . "/plugins/vigilo/ajax/getVTValue.php")); |
|
23 |
$ret = array(); |
|
24 |
$tmp = PluginVigiloVigiloTemplate::getAllTemplates(); |
|
21 | 25 |
echo '</td></tr>'; |
22 | 26 |
echo '</table>'; |
23 | 27 |
return TRUE; |
inc/vigilotemplate.class.php | ||
---|---|---|
14 | 14 |
foreach($hosttemplates_files as $file) { |
15 | 15 |
$filepath = $hosttdir . DIRECTORY_SEPARATOR . $file; |
16 | 16 |
$test_filepath = preg_match("/(.*).xml$/", $filepath); |
17 |
|
|
17 | 18 |
if (is_file($filepath) AND !empty($test_filepath)) { |
18 | 19 |
preg_match_all($pattern, file_get_contents($filepath), $matches); |
20 |
|
|
19 | 21 |
foreach ($matches[1] as $match) { |
20 | 22 |
$templates[] = $match; |
21 | 23 |
} |
... | ... | |
27 | 29 |
return $templates; |
28 | 30 |
} |
29 | 31 |
|
32 |
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 |
|
|
30 | 46 |
static function getVigiloTemplateNameByID($id) { |
31 | 47 |
|
32 | 48 |
if (is_numeric($id)) { |
setup.php | ||
---|---|---|
22 | 22 |
"Software" => array($hookObj,"manageSoftwares"), |
23 | 23 |
"Location" => array($hookObj,"updateGroups"), |
24 | 24 |
"Entity" => array($hookObj,"updateGroups"), |
25 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
25 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
26 | 26 |
"Manufacturer" => array($hookObj,"updateGroups")); |
27 | 27 |
$hooks['item_update'][$p] = array("Computer" => array($hookObj, "update"), |
28 | 28 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
... | ... | |
35 | 35 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
36 | 36 |
"Software" => array($hookObj,"manageSoftwares"), |
37 | 37 |
"Location" => array($hookObj,"updateGroups"), |
38 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
38 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
39 | 39 |
"Entity" => array($hookObj,"updateGroups"), |
40 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
40 |
"Manufacturer" => array($hookObj,"updateGroups"));
|
|
41 | 41 |
$hooks['item_purge'][$p] = array("Computer" => array($hookObj, "delete"), |
42 | 42 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
43 | 43 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
... | ... | |
49 | 49 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
50 | 50 |
"Software" => array($hookObj,"manageSoftwares"), |
51 | 51 |
"Location" => array($hookObj,"updateGroups"), |
52 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
52 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
53 | 53 |
"Entity" => array($hookObj,"updateGroups"), |
54 | 54 |
"Manufacturer" => array($hookObj,"updateGroups")); |
55 | 55 |
$hooks['item_delete'][$p] = array("Computer" => array($hookObj, "delete"), |
... | ... | |
63 | 63 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
64 | 64 |
"Software" => array($hookObj,"manageSoftwares"), |
65 | 65 |
"Location" => array($hookObj,"updateGroups"), |
66 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
66 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
67 | 67 |
"Entity" => array($hookObj,"updateGroups"), |
68 | 68 |
"Manufacturer" => array($hookObj,"updateGroups")); |
69 | 69 |
$hooks['item_restore'][$p] = array("Computer" => array($hookObj, "add"), |
... | ... | |
77 | 77 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
78 | 78 |
"Software" => array($hookObj,"manageSoftwares"), |
79 | 79 |
"Location" => array($hookObj,"updateGroups"), |
80 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
80 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
81 | 81 |
"Entity" => array($hookObj,"updateGroups"), |
82 | 82 |
"Manufacturer" => array($hookObj,"updateGroups")); |
83 | 83 |
$hooks["menu_toadd"][$p]['plugins'] = 'PluginVigiloMenu'; |
... | ... | |
85 | 85 |
$hooks['autoinventory_information'][$p] = array( |
86 | 86 |
'Computer' => array('PluginVigiloComputer', |
87 | 87 |
'showComputerInfo')); |
88 |
$hooks['autoinventory_information'][$p] = array( |
|
89 |
'Printer' => array('PluginVigiloPrinter', |
|
90 |
'showPrinterInfo')); |
|
91 | 88 |
|
92 |
if (!FieldExists('glpi_computers', 'vigilo_template'))
|
|
89 |
if (!FieldExists('glpi_computers', 'vigilo_template')) |
|
93 | 90 |
{ |
94 | 91 |
$query = "ALTER TABLE glpi_computers ADD vigilo_template VARCHAR(30)"; |
95 | 92 |
$DB->queryOrDie($query, "Ajout d'une colonne vigilo_template dans la table glpi_computers"); |
96 | 93 |
} |
97 |
|
|
98 |
if (!FieldExists('glpi_printers', 'vigilo_template')) |
|
99 |
{ |
|
100 |
$query = "ALTER TABLE glpi_printers ADD vigilo_template VARCHAR(30)"; |
|
101 |
$DB->queryOrDie($query, "Ajout d'une colonne vigilo_template dans la table glpi_printers"); |
|
102 |
} |
|
103 | 94 |
} |
104 | 95 |
|
105 | 96 |
function getSearchOptions() { |
Also available in: Unified diff