Subversion Repositories computer_asset_manager_v1

Rev

Rev 78 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 78 Rev 101
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
-
 
3
   /*
-
 
4
    * Kludge script that reads a tab delimited text file and generates the SQL that will be used to insert the values
-
 
5
    * into CAMP attributes table.
-
 
6
    *
-
 
7
    * It has a lot of shortcuts, such as automatically creating new attribute keys if they don't exist and assuming
-
 
8
    * the device already does exist and is unique.
-
 
9
    */
-
 
10
 
3
   function tabDelimToArray($contents, $delimiter = "\t" ) {
11
   function tabDelimToArray($contents, $delimiter = "\t" ) {
4
      $rows = array();
12
      $rows = array();
5
      $headers = explode( $delimiter, array_shift( $contents ) );
13
      $headers = explode( $delimiter, array_shift( $contents ) );
6
      for  ( $line = 0; $line < count( $contents ); $line++ ) {
14
      for  ( $line = 0; $line < count( $contents ); $line++ ) {
7
         if ( $contents[$line] ) {
15
         if ( $contents[$line] ) {
Line 48... Line 56...
48
         continue;
56
         continue;
49
         */
57
         */
50
         if ( ! nullOrEmpty( $data[$i][$thisKey] ) ) {
58
         if ( ! nullOrEmpty( $data[$i][$thisKey] ) ) {
51
            $value = quoteString( $data[$i][$thisKey] );
59
            $value = quoteString( $data[$i][$thisKey] );
52
            $keyName = quoteString( $thisKey );
60
            $keyName = quoteString( $thisKey );
53
            $output[] = "insert into device_attrib select null,device_id,attrib_id,$value,now(),null from attrib, device where attrib.name = $keyName and device.name = $device";
61
            $output[] = "insert into attrib_device select null,device_id,attrib_id,$value,now(),null from attrib, device where attrib.name = $keyName and device.name = $device";
54
         } // if
62
         } // if
55
      } // foreach
63
      } // foreach
56
   } // for
64
   } // for
57
   print implode( ";\n", $output ) . ";\n";
65
   print implode( ";\n", $output ) . ";\n";
58
?>
66
?>