Skip to content

Commit ed051fb

Browse files
committed
table display for selection, delete old files
1 parent ac71dbe commit ed051fb

File tree

10 files changed

+44
-390
lines changed

10 files changed

+44
-390
lines changed

hook.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</hook>
66
<hook type="submenu">
77
<mainmenuidentifier>ms_extension</mainmenuidentifier>
8-
<identifier>ms_compare_xmls</identifier>
9-
<translation>23152</translation>
8+
<identifier>ms_compare_devices</identifier>
9+
<translation>23151</translation>
1010
</hook>
1111
</hookstore>

infos.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"displayName" : "Compare XMLs",
2+
"displayName" : "Compare Devices",
33
"author" : ["Léa DROGUET"],
44
"contributor" : [],
55
"supportedAgent" : ["Unix"],

install.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* This function is called on installation and is used to
1010
* create database schema for the plugin
1111
*/
12-
function extension_install_compare_xmls()
12+
function extension_install_compare_devices()
1313
{
1414

1515
}
@@ -18,15 +18,15 @@ function extension_install_compare_xmls()
1818
* This function is called on removal and is used to
1919
* destroy database schema for the plugin
2020
*/
21-
function extension_delete_compare_xmls()
21+
function extension_delete_compare_devices()
2222
{
2323

2424
}
2525

2626
/**
2727
* This function is called on plugin upgrade
2828
*/
29-
function extension_upgrade_compare_xmls()
29+
function extension_upgrade_compare_devices()
3030
{
3131

3232
}

language/en_GB/en_GB.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
23152 Compare devices
1+
23150 Compare devices :
2+
23151 Compare devices
Lines changed: 36 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,24 @@
2727
ob_start();
2828
}
2929

30-
include_once('Difference_Class.php');
31-
include_once('ArrayFromXML_Class.php');
32-
include_once('Table_Class.php');
33-
require_once('create_XML.php');
30+
/*
31+
/!\ WARNING /!\
32+
Make sure https://github.com/jfcherng/php-diff is installed on server,
33+
otherwise differences won't display as the extension requires this
34+
third party library
3435
36+
TODO :
37+
- improve selectors (what if 10+ devices)
38+
- table isnt displaying selected devices (?)
39+
40+
THINK HARDER :
41+
- autocompleted inputs vs dropdown selectors ?
42+
in case 1 vs 15 > cant display 15 selectors but two autocompleted inputs could do
43+
44+
- php-diff only displays diff 1vs1
45+
- php-diff table are not (yet) collapsable
46+
*/
47+
require_once('create_XML.php');
3548
include ('/usr/share/ocsinventory-reports/ocsreports/vendor/jfcherng/php-diff/example/demo_base.php');
3649

3750
use Jfcherng\Diff\DiffHelper;
@@ -56,29 +69,8 @@
5669
echo DiffHelper::getStyleSheet();
5770
echo "</style><br><br>";
5871

59-
/*
60-
/!\ WARNING /!\
61-
Make sure https://github.com/jfcherng/php-diff is installed on server,
62-
otherwise differences won't display as the extension requires this
63-
third party library
64-
65-
TODO :
66-
- improve selectors (what if 10+ devices)
67-
- table isnt displaying selected devices (?)
68-
69-
THINK HARDER :
70-
- autocompleted inputs vs dropdown selectors ?
71-
in case 1 vs 15 > cant display 15 selectors but two autocompleted inputs could do
72-
73-
- php-diff only displays diff 1vs1
74-
- php-diff table are not (yet) collapsable
75-
*/
76-
77-
78-
// printEnTete($l->g(9000));
79-
// temporary header :
80-
echo "<h2> Compare devices : </h2>";
8172

73+
printEnTete($l->g(23150));
8274
$form_name = 'compare_devices';
8375
$tab_options = $protectedPost;
8476
$table_name = $form_name;
@@ -89,141 +81,66 @@
8981
echo open_form($form_name, '', 'enctype="multipart/form-data"', 'form-horizontal');
9082
echo '<div class="col col-md-10" >';
9183

92-
if (isset($protectedPost['SUP_PROF']) && $protectedPost['SUP_PROF'] != "") {
93-
// TODO : Remove device from table
94-
$result_remove = 0;
95-
unset($protectedPost['SUP_PROF']);
96-
if ($result_remove == true) {
97-
msg_success($l->g(572));
98-
} else {
99-
msg_error($l->g(573));
100-
}
101-
}
102-
103-
// IF DEVICE IS ADDED
104-
if (isset($protectedPost['add_device'])) {
105-
var_dump($protectedPost['add_device']);
106-
/* if($result == true){
107-
msg_success($l->g(572));
108-
}else{
109-
msg_error($l->g(573));
110-
}
111-
unset($protectedPost['add_device']); */
112-
}
113-
11484
// req to select from
11585
$link = $_SESSION['OCS']["readServer"];
11686
$result = mysql2_query_secure("SELECT ID, DEVICEID FROM hardware WHERE deviceid <> '_SYSTEMGROUP_' AND deviceid <>'_DOWNLOADGROUP_'", $link);
11787
$result = mysqli_fetch_all($result, MYSQLI_ASSOC);
11888

119-
// prepare array to display during selection
89+
// prepare array for selection
12090
foreach ($result as $key => $value) {
12191
$display[$key] = $value['DEVICEID'];
12292
}
12393

12494
echo "<div>
12595
<div>";
126-
12796
// select main device and other devices
12897
formGroup('select', 'main_device', 'Main device to compare :', '', '', '', '', $result, $display, "required");
129-
// echo "<input type='submit' name='add_main_device' id='add_main_device' class='btn btn-success' value='Add'><br><br>";
130-
131-
// TODO : hide other device if main device not selected yet + remove already selected devices from list
132-
formGroup('select', 'other_device[]', 'Other devices to compare :', '', '', '', '', $result, $display, "required");
133-
// echo "<input type='submit' name='add_other_device' id='add_other_device' class='btn btn-success' value='Add'>";
134-
135-
136-
// use code below to display multiple selectors (bs)
137-
/* if (isset($protectedPost['add_other_device'])) {
138-
formGroup('select', 'other_device', 'Other devices to compare :', '', '', '', '', $result, $display, "required");
139-
}
140-
echo "<input type='submit' name='add_device' id='add_device' class='btn btn-success' value='Add device to comparison'><br><br>";
141-
*/
142-
143-
144-
echo "</div></div></br></br></br></br>";
145-
146-
// quick check
147-
// var_dump($result);
148-
$m_device = $result[$protectedPost['main_device']]['ID'];
149-
$o_device = $result[$protectedPost['other_device'][0]]['ID'];
150-
echo "<br>comparing $m_device with $o_device";
98+
formGroup('select', 'other_device', 'Other device to compare :', '', '', '', '', $result, $display, "required");
99+
// submit values
100+
echo "<input type='submit' name='compare' id='compare' class='btn btn-success' value='Compare devices'>";
101+
echo "</div>
102+
</div>";
151103

152104

153105
// Display table of selected devices
154106
$list_fields = array(
155107
'ID' => 'ID',
156108
'DEVICE ID' => 'DEVICEID',
157109
);
158-
159110
$list_fields['SUP'] = 'ID';
160111
$tab_options['LBL_POPUP']['SUP'] = 'TYPE_NAME';
161-
162112
$default_fields = $list_fields;
163113
$list_col_cant_del = $list_fields;
164114

165-
$devices = array($m_device, $o_device);
115+
$devices = array($result[$protectedPost['main_device']]['ID'], $result[$protectedPost['other_device']]['ID']);
166116
$in = implode(",", $devices);
167-
$queryDetails = "SELECT ID, DEVICEID FROM hardware WHERE deviceid <> '_SYSTEMGROUP_' AND deviceid <>'_DOWNLOADGROUP_' AND id IN ($in)";
168-
117+
// query for table display
118+
$queryDetails = "SELECT ID, DEVICEID FROM hardware WHERE deviceid <> '_SYSTEMGROUP_' AND deviceid <>'_DOWNLOADGROUP_' AND id IN (".$in.")";
169119
ajaxtab_entete_fixe($list_fields, $default_fields, $tab_options, $list_col_cant_del);
170-
echo "<input type='submit' name='compare' id='compare' class='btn btn-success' value='Compare devices'>";
171-
echo "</div></div>";
120+
121+
echo "</div>
122+
</div>";
172123
echo close_form();
173124

174125

175126
// TRAITEMENT XML -------------------------------------------------
176127
$xml = new DeviceXML();
177128

178-
$oldString = $xml->createXML($m_device);
179-
$newString = $xml->createXML($o_device);
129+
// createXML acutally only creates xml structure in a string
130+
$main_device = $xml->createXML($result[$protectedPost['main_device']]['ID']);
131+
$other_device = $xml->createXML($result[$protectedPost['other_device']]['ID']);
180132

181133
// demo the no-inline-detail diff
182134
$inlineResult = DiffHelper::calculate(
183-
$oldString,
184-
$newString,
135+
$main_device,
136+
$other_device,
185137
// options : Unified, Combined, SideBySide, Inline
186138
'SideBySide',
187139
$diffOptions,
188140
// detail levels : word, line, char, none
189141
['detailLevel' => 'none'] + $rendererOptions
190142
);
191-
192-
echo "<br><br>$inlineResult";
193-
194-
// old table display below
195-
196-
/* function getArrayFromXml($xml, $elem) {
197-
$xml_device = $xml->createXML($elem);
198-
print_r($xml_device, true);
199-
$xml_md = simplexml_load_string($xml_device);
200-
// encode Xml file into Json
201-
$json = json_encode($xml_md);
202-
// decode ...
203-
$array_md = json_decode($json, TRUE);
204-
return $array_md;
205-
}
206-
207-
$array = getArrayFromXml($xml, $m_device);
208-
// var_dump($array);
209-
echo "<br><br>";
210-
$o_array = getArrayFromXml($xml, $o_device);
211-
// var_dump($o_device);
212-
213-
echo "<br><br> DIFFERENCES ";
214-
$diffs = new Difference();
215-
$diffsV1 = $diffs->getDifferencesV1($array, $o_array);
216-
// var_dump($diffsV1);
217-
218-
// show main device array
219-
$mainDeviceTable = new Tabletizer();
220-
echo $mainDeviceTable->fromArray($array);
221-
222-
223-
// create table
224-
$table = new Tabletizer();
225-
echo $table->fromArray($diffsV1); */
226-
143+
echo "<div class='col col-md-10' style='overflow-y: auto; height:300px;'><br><br>$inlineResult</div>";
227144
// -----------------------------------------------------------------
228145

229146
if (AJAX) {

ms_compare_xmls/ArrayFromXML_Class.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

ms_compare_xmls/Difference_Class.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)