| Line 1... | Line 1... | 
          
            | 1 | <?php 
 | 1 | <?php 
 | 
          
            | 2 |    include_once( '../../header.php' ); 
 | 2 |    include_once( '../../header.php' );
 | 
          
            | - |   | 3 |    include_once( './functions.php' );
 | 
          
            | 3 | ?>
 | 4 | ?>
 | 
          
            | 4 | <?php
 | 5 | <?php
 | 
          
            | 5 |  
 | 6 |  
 | 
          
            | 6 | include_once( '../../header.php' ); 
 | 7 | include_once( '../../header.php' ); 
 | 
          
            | 7 | include_once( 'csvImporter.php' );
 | 8 | include_once( 'csvImporter.php' );
 | 
          
            | 8 |  
 | 9 |  
 | 
          
            | 9 | /* 
 | - |   | 
          
            | 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 |  */
 | - |   | 
          
            | 15 |  
 | - |   | 
          
            | 16 | function getValue ( $table, $column, $match, $value, $add = false ) {
 | - |   | 
          
            | 17 |    $return = getOneDBValue( "select $column from $table where $match = '$value'" );
 | - |   | 
          
            | 18 |    if ( $return === null ) {
 | - |   | 
          
            | 19 |       if ( $add ) {
 | - |   | 
          
            | 20 |          $return = doSQL( "insert into $table ( $match ) values ( '$value' )" );
 | - |   | 
          
            | 21 |          return $return['insert_id'];
 | - |   | 
          
            | 22 |       } else {
 | - |   | 
          
            | 23 |          $return = '';
 | - |   | 
          
            | 24 |       }
 | - |   | 
          
            | 25 |    }
 | - |   | 
          
            | 26 |    return $return;
 | - |   | 
          
            | 27 | }
 | - |   | 
          
            | 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 |  */
 | - |   | 
          
            | 40 | function updateLicense ( $client_id, $device_id, $license_product_id, $license ) {
 | - |   | 
          
            | 41 |    // see if the entry already exists
 | - |   | 
          
            | 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" );
 | - |   | 
          
            | 43 |    //print "<pre>"; print_r( $results ); print "</pre>"; die;
 | - |   | 
          
            | 44 |    $db_license_id = $results['data'][0]['license_id'];
 | - |   | 
          
            | 45 |    $db_client_id = $results['data'][0]['client_id'];
 | - |   | 
          
            | 46 |    $db_device_id = $results['data'][0]['device_id'];
 | - |   | 
          
            | 47 |    // SQL does not understand an empty string, so we replace it with the keyword null for queries
 | - |   | 
          
            | 48 |    $queryDeviceID = $device_id ? $device_id : 'null';
 | - |   | 
          
            | 49 |    if ( ! $results ) { # this was not found, so just add it
 | - |   | 
          
            | 50 |       doSQL( "insert into license (client_id,device_id,license_product_id,license, added_date) values ( $client_id, $queryDeviceID, $license_product_id, '$license', now() )" );
 | - |   | 
          
            | 51 |       return "Added";
 | - |   | 
          
            | 52 |    }
 | - |   | 
          
            | 53 |    if ( $client_id == $db_client_id && $device_id == $db_device_id or $db_device_id  ) { // already done, so just leave alone
 | - |   | 
          
            | 54 |       return "Already Set";
 | - |   | 
          
            | 55 |    }
 | - |   | 
          
            | 56 |    if ( ! $db_device_id ) { # key was not assigned before, so just assign it
 | - |   | 
          
            | 57 |       doSQL( "update license set device_id = $queryDeviceID,added_date = now() where license_id = $db_license_id" );
 | - |   | 
          
            | 58 |       return "Assigned";
 | - |   | 
          
            | 59 |    }
 | - |   | 
          
            | 60 |    // at this point, there is already an entry, but it is for a different machine, so we need to update it, ie remove the old, add the new
 | - |   | 
          
            | 61 |    doSQL( "update license set removed_date = now() where license_id = $db_license_id" );
 | - |   | 
          
            | 62 |    doSQL( "insert into license (client_id,device_id,license_product_id,license, added_date) values ( $client_id, $queryDeviceID, $license_product_id, '$license', now() )" );
 | - |   | 
          
            | 63 |    return "Reassigned";
 | - |   | 
          
            | 64 | }
 | - |   | 
          
            | 65 |  
 | - |   | 
          
            | 66 | /* import CSV, processing one line at a time
 | 10 | /* import CSV, processing one line at a time
 | 
          
            | 67 |  * CSV may be delimited by anything defined in CsvImporter with auto-detect
 | 11 |  * CSV may be delimited by anything defined in CsvImporter with auto-detect
 | 
          
            | 68 |  * returns table with results, suitable for embedding in div
 | 12 |  * returns table with results, suitable for embedding in div
 | 
          
            | 69 |  */
 | 13 |  */
 | 
          
            | 70 |  
 | 14 |  
 |