Line 13... |
Line 13... |
13 |
*/
|
13 |
*/
|
14 |
|
14 |
|
15 |
function processFile ( $filename, $delimiter, $encapsulation = '"', $escape = '\\', $deviceNotFoundIsNull = false) {
|
15 |
function processFile ( $filename, $delimiter, $encapsulation = '"', $escape = '\\', $deviceNotFoundIsNull = false) {
|
16 |
$return = '';
|
16 |
$return = '';
|
17 |
$fileInfo = new CsvImporter( $filename, true, $delimiter, $enclosure, $escape );
|
17 |
$fileInfo = new CsvImporter( $filename, true, $delimiter, $enclosure, $escape );
|
- |
|
18 |
$numLines = 0;
|
18 |
|
19 |
|
19 |
/*
|
20 |
/*
|
20 |
* load the information in a hash list, similar to
|
21 |
* load the information in a hash list, similar to
|
21 |
* client1
|
22 |
* client1
|
22 |
* machine1
|
23 |
* machine1
|
Line 27... |
Line 28... |
27 |
* client2
|
28 |
* client2
|
28 |
* ...
|
29 |
* ...
|
29 |
*/
|
30 |
*/
|
30 |
while ( $line = $fileInfo->get(1) ) {
|
31 |
while ( $line = $fileInfo->get(1) ) {
|
31 |
foreach ( $line as $index => $values ) {
|
32 |
foreach ( $line as $index => $values ) {
|
32 |
$import[$values['client']][$values['device']][$values['license_product']] = $values['license'];
|
33 |
$import[$values['client']][$values['license_product']][$values['license']] = $values['device'];
|
- |
|
34 |
$numLines++;
|
33 |
}
|
35 |
}
|
34 |
};
|
36 |
};
|
35 |
|
- |
|
- |
|
37 |
$return .= "<p>$numLines lines read</p>";
|
- |
|
38 |
$numLines = 0; // reset so we can count the number of lines processed
|
36 |
// process each client/machine/license in turn, displaying results in table
|
39 |
// process each client/machine/license in turn, displaying results in table
|
37 |
$return .= "<table border='1'><tr></tr><th>Status</th><th>Client</th><th>ID</th><th>Machine</th><th>ID</th><th>Product</th><th>ID</th><th>License</th></tr>\n";
|
40 |
$return .= "<table border='1'><tr></tr><th>Status</th><th>Client</th><th>ID</th><th>Machine</th><th>ID</th><th>Product</th><th>ID</th><th>License</th></tr>\n";
|
38 |
foreach ( $import as $client => $data ) {
|
41 |
foreach ( $import as $client => $data ) {
|
39 |
// find client_id
|
42 |
// find client_id
|
40 |
$client_id = getValue ( 'client', 'client_id', 'name', $client );
|
43 |
$client_id = getValue ( 'client', 'client_id', 'name', $client );
|
41 |
if ( $client_id === '' ) { // can't find client, so big error
|
44 |
if ( $client_id === '' ) { // can't find client, so big error
|
42 |
$return .= "<tr><td><b>Error</b></td><td colspan='7'>Could not find client ID for $client</td></tr>";
|
45 |
$return .= "<tr><td><b>Error</b></td><td colspan='7'>Could not find client ID for $client</td></tr>";
|
43 |
continue;
|
46 |
continue;
|
44 |
}
|
47 |
}
|
45 |
// find machine_id
|
48 |
foreach ( $data as $product => $info ) {
|
46 |
foreach ( $data as $machine => $info ) {
|
49 |
foreach ( $info as $license => $machine ) {
|
- |
|
50 |
$numLines++;
|
47 |
if ( $machine === '' ) { // can't find machine
|
51 |
if ( $machine === '' ) { // can't find machine
|
48 |
$machine_id = '';
|
52 |
$machine_id = '';
|
49 |
} else {
|
53 |
} else {
|
50 |
$machine_id = getValue( 'device', 'device_id', 'name', $machine );
|
54 |
$machine_id = getValue( 'device', 'device_id', 'name', $machine );
|
51 |
// if we can't find it and they don't want to continue
|
55 |
// if we can't find it and they don't want to continue
|
52 |
if ( $machine_id === '' and ! $deviceNotFoundIsNull ) {
|
56 |
if ( $machine_id === '' and ! $deviceNotFoundIsNull ) {
|
53 |
$return .= "<td><b>Error</b></td><td>$client</td><td>$client_id</td>";
|
57 |
$return .= "<td><b>Error</b></td><td>$client</td><td>$client_id</td>";
|
54 |
$return .= "<td colspan='5'>Could not find machine ID for $machine</td></tr>";
|
58 |
$return .= "<td colspan='5'>Could not find machine ID for $machine</td></tr>";
|
55 |
continue; //ignor
|
59 |
continue; //ignor
|
- |
|
60 |
}
|
56 |
}
|
61 |
}
|
57 |
}
|
- |
|
58 |
// now, locate each license_product_id and update the license information
|
62 |
// now, locate each license_product_id and update the license information
|
59 |
// if product does not exist, add it
|
63 |
// if product does not exist, add it
|
60 |
// thus, spelling counts or you'll get dup entries in license_product table
|
64 |
// thus, spelling counts or you'll get dup entries in license_product table
|
61 |
foreach ( $info as $product => $license ) {
|
- |
|
62 |
# look for product name, but don't update it if it doesn't exist
|
65 |
# look for product name, but don't update it if it doesn't exist
|
63 |
$product_id = getValue( 'license_product', 'license_product_id', 'name', $product, false );
|
66 |
$product_id = getValue( 'license_product', 'license_product_id', 'name', $product, false );
|
64 |
/*
|
67 |
/*
|
65 |
* Some software (like Belarc) show product names as publiser - product name, ie
|
68 |
* Some software (like Belarc) show product names as publiser - product name, ie
|
66 |
* Microsoft - Office 2017
|
69 |
* Microsoft - Office 2017
|
Line 87... |
Line 90... |
87 |
|
90 |
|
88 |
}
|
91 |
}
|
89 |
} // for each machine
|
92 |
} // for each machine
|
90 |
} // for each client
|
93 |
} // for each client
|
91 |
$return .= "</table>\n";
|
94 |
$return .= "</table>\n";
|
- |
|
95 |
$return .= "<p>$numLines processed</p>";
|
92 |
return $return;
|
96 |
return $return;
|
93 |
} // function processFile
|
97 |
} // function processFile
|
94 |
|
98 |
|
95 |
?>
|
99 |
?>
|
96 |
<?xml version="1.0" encoding="utf-8"?>
|
100 |
<?xml version="1.0" encoding="utf-8"?>
|