|
27 | 27 | ob_start(); |
28 | 28 | } |
29 | 29 |
|
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 |
34 | 35 |
|
| 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'); |
35 | 48 | include ('/usr/share/ocsinventory-reports/ocsreports/vendor/jfcherng/php-diff/example/demo_base.php'); |
36 | 49 |
|
37 | 50 | use Jfcherng\Diff\DiffHelper; |
|
56 | 69 | echo DiffHelper::getStyleSheet(); |
57 | 70 | echo "</style><br><br>"; |
58 | 71 |
|
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>"; |
81 | 72 |
|
| 73 | +printEnTete($l->g(23150)); |
82 | 74 | $form_name = 'compare_devices'; |
83 | 75 | $tab_options = $protectedPost; |
84 | 76 | $table_name = $form_name; |
|
89 | 81 | echo open_form($form_name, '', 'enctype="multipart/form-data"', 'form-horizontal'); |
90 | 82 | echo '<div class="col col-md-10" >'; |
91 | 83 |
|
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 | | - |
114 | 84 | // req to select from |
115 | 85 | $link = $_SESSION['OCS']["readServer"]; |
116 | 86 | $result = mysql2_query_secure("SELECT ID, DEVICEID FROM hardware WHERE deviceid <> '_SYSTEMGROUP_' AND deviceid <>'_DOWNLOADGROUP_'", $link); |
117 | 87 | $result = mysqli_fetch_all($result, MYSQLI_ASSOC); |
118 | 88 |
|
119 | | -// prepare array to display during selection |
| 89 | +// prepare array for selection |
120 | 90 | foreach ($result as $key => $value) { |
121 | 91 | $display[$key] = $value['DEVICEID']; |
122 | 92 | } |
123 | 93 |
|
124 | 94 | echo "<div> |
125 | 95 | <div>"; |
126 | | - |
127 | 96 | // select main device and other devices |
128 | 97 | 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>"; |
151 | 103 |
|
152 | 104 |
|
153 | 105 | // Display table of selected devices |
154 | 106 | $list_fields = array( |
155 | 107 | 'ID' => 'ID', |
156 | 108 | 'DEVICE ID' => 'DEVICEID', |
157 | 109 | ); |
158 | | - |
159 | 110 | $list_fields['SUP'] = 'ID'; |
160 | 111 | $tab_options['LBL_POPUP']['SUP'] = 'TYPE_NAME'; |
161 | | - |
162 | 112 | $default_fields = $list_fields; |
163 | 113 | $list_col_cant_del = $list_fields; |
164 | 114 |
|
165 | | -$devices = array($m_device, $o_device); |
| 115 | +$devices = array($result[$protectedPost['main_device']]['ID'], $result[$protectedPost['other_device']]['ID']); |
166 | 116 | $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.")"; |
169 | 119 | 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>"; |
172 | 123 | echo close_form(); |
173 | 124 |
|
174 | 125 |
|
175 | 126 | // TRAITEMENT XML ------------------------------------------------- |
176 | 127 | $xml = new DeviceXML(); |
177 | 128 |
|
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']); |
180 | 132 |
|
181 | 133 | // demo the no-inline-detail diff |
182 | 134 | $inlineResult = DiffHelper::calculate( |
183 | | - $oldString, |
184 | | - $newString, |
| 135 | + $main_device, |
| 136 | + $other_device, |
185 | 137 | // options : Unified, Combined, SideBySide, Inline |
186 | 138 | 'SideBySide', |
187 | 139 | $diffOptions, |
188 | 140 | // detail levels : word, line, char, none |
189 | 141 | ['detailLevel' => 'none'] + $rendererOptions |
190 | 142 | ); |
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>"; |
227 | 144 | // ----------------------------------------------------------------- |
228 | 145 |
|
229 | 146 | if (AJAX) { |
|
0 commit comments