Line -... |
Line 1... |
- |
|
1 |
<?php
|
- |
|
2 |
include_once( '../../header.php' );
|
- |
|
3 |
?>
|
1 |
<?php
|
4 |
<?php
|
2 |
|
5 |
|
3 |
include_once( '../../header.php' );
|
6 |
include_once( '../../header.php' );
|
4 |
include_once( 'csvImporter.php' );
|
7 |
include_once( 'csvImporter.php' );
|
5 |
|
8 |
|
- |
|
9 |
/*
|
6 |
$filename = 'machine_licenses.csv';
|
10 |
* select $column from $table where $match = '$value'
|
- |
|
11 |
* if $add is true, will add row if it does not exist.
|
- |
|
12 |
* returns $column from the result (or '' if it does not exist)
|
- |
|
13 |
* Used mainly to get an index from a table with matching value
|
- |
|
14 |
*/
|
7 |
|
15 |
|
8 |
function getValue ( $table, $column, $match, $value, $add = false ) {
|
16 |
function getValue ( $table, $column, $match, $value, $add = false ) {
|
9 |
$return = getOneDBValue( "select $column from $table where $match = '$value'" );
|
17 |
$return = getOneDBValue( "select $column from $table where $match = '$value'" );
|
10 |
if ( $return === null ) {
|
18 |
if ( $return === null ) {
|
11 |
if ( $add ) {
|
19 |
if ( $add ) {
|
Line 16... |
Line 24... |
16 |
}
|
24 |
}
|
17 |
}
|
25 |
}
|
18 |
return $return;
|
26 |
return $return;
|
19 |
}
|
27 |
}
|
20 |
|
28 |
|
- |
|
29 |
/*
|
- |
|
30 |
* Adds/updates license in license table
|
- |
|
31 |
* if already licensed for this machine, returns 'Already Set'
|
- |
|
32 |
* if license exists and is for a different machine
|
- |
|
33 |
* mark it as removed
|
- |
|
34 |
* adds key to new machine
|
- |
|
35 |
* returns "Assigned"
|
- |
|
36 |
* Othewise, Adds key and assigns to machine
|
- |
|
37 |
* returns "Added"
|
- |
|
38 |
* NOTE: $device_id may be null which indicates license owned by client but unassigned
|
- |
|
39 |
*/
|
21 |
function updateLicense ( $client_id, $device_id, $license_product_id, $license ) {
|
40 |
function updateLicense ( $client_id, $device_id, $license_product_id, $license ) {
|
22 |
// see if the entry already exists
|
41 |
// see if the entry already exists
|
23 |
$results = queryDatabaseExtended( "select license_id,client_id,device_id from license where license_product_id = $license_product_id and license = '$license' and removed_date is null" );
|
42 |
$results = queryDatabaseExtended( "select license_id,client_id,device_id from license where license_product_id = $license_product_id and license = '$license' and removed_date is null" );
|
24 |
//print "<pre>"; print_r( $results ); print "</pre>"; die;
|
43 |
//print "<pre>"; print_r( $results ); print "</pre>"; die;
|
25 |
$db_license_id = $results['data'][0]['license_id'];
|
44 |
$db_license_id = $results['data'][0]['license_id'];
|
Line 42... |
Line 61... |
42 |
doSQL( "update license set removed_date = now() where license_id = $db_license_id" );
|
61 |
doSQL( "update license set removed_date = now() where license_id = $db_license_id" );
|
43 |
doSQL( "insert into license (client_id,device_id,license_product_id,license, added_date) values ( $client_id, $device_id, $license_product_id, '$license', now() )" );
|
62 |
doSQL( "insert into license (client_id,device_id,license_product_id,license, added_date) values ( $client_id, $device_id, $license_product_id, '$license', now() )" );
|
44 |
return "Reassigned";
|
63 |
return "Reassigned";
|
45 |
}
|
64 |
}
|
46 |
|
65 |
|
- |
|
66 |
/* import CSV, processing one line at a time
|
- |
|
67 |
* CSV may be delimited by anything defined in CsvImporter with auto-detect
|
- |
|
68 |
* returns table with results, suitable for embedding in div
|
- |
|
69 |
*/
|
- |
|
70 |
|
- |
|
71 |
function processFile ( $filename ) {
|
- |
|
72 |
$return = '';
|
- |
|
73 |
$fileInfo = new CsvImporter( $filename, true );
|
- |
|
74 |
while ( $line = $fileInfo->get(1) ) {
|
- |
|
75 |
foreach ( $line as $index => $values ) {
|
- |
|
76 |
$import[$values['client']][$values['device']][$values['license_product']] = $values['license'];
|
- |
|
77 |
}
|
- |
|
78 |
};
|
47 |
|
79 |
|
48 |
$fileInfo = new CsvImporter( $filename, true );
|
- |
|
49 |
while ( $line = $fileInfo->get(1) ) {
|
- |
|
50 |
foreach ( $line as $index => $values ) {
|
80 |
// process each line in turn, displaying results in table
|
51 |
$import[$values['client']][$values['device']][$values['license_product']] = $values['license'];
|
- |
|
52 |
}
|
- |
|
53 |
};
|
- |
|
54 |
|
- |
|
55 |
//print '<pre>'; print_r( $import ); print '</pre>';
|
- |
|
56 |
|
- |
|
57 |
print "<table border='1'><tr></tr><th>Client</th><th>ID</th><th>Machine</th><th>ID</th><th>Product</th><th>ID</th><th>License</th></tr>\n";
|
81 |
$return = "<table border='1'><tr></tr><th>Client</th><th>ID</th><th>Machine</th><th>ID</th><th>Product</th><th>ID</th><th>License</th></tr>\n";
|
58 |
foreach ( $import as $client => $data ) {
|
82 |
foreach ( $import as $client => $data ) {
|
59 |
$client_id = getValue ( 'client', 'client_id', 'name', $client );
|
- |
|
60 |
if ( $client_id === '' ) {
|
- |
|
61 |
print "<tr><td><b>Error</b></td><td colspan='7'>Could not find client ID for $client</td></tr>";
|
- |
|
62 |
continue;
|
- |
|
63 |
}
|
- |
|
64 |
foreach ( $data as $machine => $info ) {
|
- |
|
65 |
if ( $machine === '' ) {
|
- |
|
66 |
$machine_id = '';
|
83 |
// find client_id
|
67 |
} else {
|
- |
|
68 |
$machine_id = getValue( 'device', 'device_id', 'name', $machine );
|
84 |
$client_id = getValue ( 'client', 'client_id', 'name', $client );
|
69 |
if ( $machine_id === '' ) {
|
85 |
if ( $client_id === '' ) {
|
70 |
print "<td><b>Error</b></td><td>$client</td><td>$client_id</td>";
|
- |
|
71 |
print "<td colspan='5'>Could not find machine ID for $machine</td></tr>";
|
86 |
$return .= "<tr><td><b>Error</b></td><td colspan='7'>Could not find client ID for $client</td></tr>";
|
72 |
continue;
|
87 |
continue;
|
73 |
}
|
88 |
}
|
- |
|
89 |
// find machine_id
|
- |
|
90 |
foreach ( $data as $machine => $info ) {
|
- |
|
91 |
if ( $machine === '' ) {
|
- |
|
92 |
$machine_id = '';
|
- |
|
93 |
} else {
|
- |
|
94 |
$machine_id = getValue( 'device', 'device_id', 'name', $machine );
|
- |
|
95 |
if ( $machine_id === '' ) {
|
- |
|
96 |
$return .= "<td><b>Error</b></td><td>$client</td><td>$client_id</td>";
|
- |
|
97 |
$return .= "<td colspan='5'>Could not find machine ID for $machine</td></tr>";
|
- |
|
98 |
continue;
|
- |
|
99 |
}
|
74 |
}
|
100 |
}
|
- |
|
101 |
// now, locate each license_product_id and update the license information
|
- |
|
102 |
// if product does not exist, add it
|
- |
|
103 |
// thus, spelling counts or you'll get dup entries in license_product table
|
75 |
foreach ( $info as $product => $license ) {
|
104 |
foreach ( $info as $product => $license ) {
|
76 |
$product_id = getValue( 'license_product', 'license_product_id', 'name', $product, true );
|
105 |
$product_id = getValue( 'license_product', 'license_product_id', 'name', $product, true );
|
77 |
$action = updateLicense( $client_id, $machine_id, $product_id, $license );
|
106 |
$action = updateLicense( $client_id, $machine_id, $product_id, $license );
|
78 |
print "<tr>\n";
|
107 |
$return .= "<tr>\n";
|
79 |
print "<td>$action</td><td>$client</td><td>$client_id</td>";
|
108 |
$return .= "<td>$action</td><td>$client</td><td>$client_id</td>";
|
80 |
print "<td>$machine</td><td>$machine_id</td>";
|
109 |
$return .= "<td>$machine</td><td>$machine_id</td>";
|
81 |
print "<td>$product</td><td>$product_id</td><td>$license</td>\n";
|
110 |
$return .= "<td>$product</td><td>$product_id</td><td>$license</td>\n";
|
82 |
print "</tr>\n";
|
111 |
$return .= "</tr>\n";
|
83 |
|
112 |
|
84 |
}
|
113 |
}
|
85 |
} // for each machine
|
114 |
} // for each machine
|
86 |
} // for each client
|
115 |
} // for each client
|
87 |
print "</table>\n";
|
116 |
$return .= "</table>\n";
|
- |
|
117 |
return $return;
|
- |
|
118 |
} // function processFile
|
88 |
|
119 |
|
89 |
?>
|
120 |
?>
|
- |
|
121 |
<?xml version="1.0" encoding="utf-8"?>
|
- |
|
122 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
|
- |
|
123 |
|
- |
|
124 |
<html xmlns="http://www.w3.org/1999/xhtml">
|
- |
|
125 |
<head>
|
- |
|
126 |
<title>Computer Asset Management Program - MODULE NAME - PAGE NAME</title>
|
- |
|
127 |
<link rel="stylesheet" type="text/css" href="../../camp.css">
|
- |
|
128 |
</head>
|
- |
|
129 |
<body>
|
- |
|
130 |
<?php include_once('../../menu.php'); ?>
|
- |
|
131 |
<div id="content">
|
- |
|
132 |
<?php
|
- |
|
133 |
if ( $_REQUEST['fileToUpload'] ) {
|
- |
|
134 |
print processFile( $_FILES["fileToUpload"]["tmp_name"] );
|
- |
|
135 |
} else {
|
- |
|
136 |
?>
|
- |
|
137 |
<p>Upload a CSV file to be bulk imported into the license table</p>
|
- |
|
138 |
<p><b>Warning:</b> no error checking is done, ensure your file meets the proper specifications</p>
|
- |
|
139 |
<form action="upload.php" method="post" enctype="multipart/form-data">
|
- |
|
140 |
Select CSV to upload:
|
- |
|
141 |
<input type="file" name="fileToUpload" id="fileToUpload">
|
- |
|
142 |
<input type="submit" value="Upload CSV" name="submit">
|
- |
|
143 |
</form>
|
- |
|
144 |
<?php } ?>
|
- |
|
145 |
</div>
|
- |
|
146 |
</body>
|
- |
|
147 |
</html>
|