Subversion Repositories computer_asset_manager_v1

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
41 rodolico 1
<?php
2
 
3
include_once( '../../header.php' ); 
4
include_once( 'csvImporter.php' );
5
 
6
$filename = 'machine_licenses.csv';
7
 
8
function getValue ( $table, $column, $match, $value, $add = false ) {
9
   $return = getOneDBValue( "select $column from $table where $match = '$value'" );
10
   if ( $return === null ) {
11
      if ( $add ) {
12
         $return = doSQL( "insert into $table ( $match ) values ( '$value' )" );
13
         return $return['insert_id'];
14
      } else {
15
         $return = '';
16
      }
17
   }
18
   return $return;
19
}
20
 
21
 
22
$fileInfo = new CsvImporter( $filename, true );
23
while ( $line = $fileInfo->get(1) ) {
24
   foreach ( $line as $index => $values ) {
25
      $import[$values['client']][$values['device']][$values['license_product']] = $values['license'];
26
   }
27
};
28
//print '<pre>'; print_r( $import ); print '</pre>';
29
 
30
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";
31
foreach ( $import as $client => $data ) {
32
   $client_id = getValue ( 'client', 'client_id', 'name', $client );
33
   if ( $client_id === '' ) {
34
      print "<tr><td><b>Error</b></td><td colspan='7'>Could not find client ID for $client</td></tr>";
35
      continue;
36
   }
37
   foreach ( $data as $machine => $info ) {
38
      if ( $machine === '' ) {
39
         $machine_id = '';
40
      } else {
41
         $machine_id = getValue( 'device', 'device_id', 'name', $machine );
42
         if ( $machine_id === '' ) {
43
            print "<td><b>Error</b></td><td>$client</td><td>$client_id</td>";
44
            print "<td colspan='5'>Could not find machine ID for $machine</td></tr>";
45
            continue;
46
         }
47
      }
48
      foreach ( $info as $product => $license ) {
49
         $product_id = getValue( 'license_product', 'license_product_id', 'name', $product, true );
50
         print "<tr>\n";
51
         print "<td>Adding</td><td>$client</td><td>$client_id</td>";
52
         print "<td>$machine</td><td>$machine_id</td>";
53
         print "<td>$product</td><td>$product_id</td><td>$license</td>\n";
54
         print "</tr>\n";
55
         if ( $machine_id === '' ) # allow licenses which are not assigned a machine
56
            $machine_id = 'null';
57
         doSQL( "insert into license (client_id,device_id,license_product_id,license) values ( $client_id, $machine_id, $product_id, '$license' )" );
58
      }
59
   } // for each machine
60
} // for each client
61
print "</table>\n";
62
 
63
 
64
 
65
?>