Subversion Repositories computer_asset_manager_v1

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
102 rodolico 1
<?php
2
 
3
   /*
4
    * NAME OF FILE
5
    * 
6
    * BRIEF DESCRIPTION OF FILE
7
    *
8
    * LONG DESCRIPTION OF FILE
9
    * 
10
    * Copyright (c) 2020 by the Daily Data, Inc. All rights reserved. Redistribution and use in source and binary forms, with or
11
    * without modification, are permitted provided that the following conditions are met:
12
    *     Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
13
    *     Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
14
    *        disclaimer in the documentation and/or other materials provided with the distribution.
15
    *     Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this
16
    *       software without specific prior written permission.
17
    *
18
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
19
    * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20
    * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
    * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23
    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
    *
25
    * 20200113 rodo@dailydata.net v0.1
26
    * Initial build
27
    * 
28
    */
29
 
30
   include_once( '../../header.php' );
31
   include_once( './functions.php' );
32
   include_once( './dmidecode2array.php' );
33
   include_once( '../../includes/functions.php' );
34
   define ( DEBUG, false );
35
?>
36
<?xml version="1.0" encoding="utf-8"?>
37
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
38
<html xmlns="http://www.w3.org/1999/xhtml">
39
   <head>
40
      <title>Computer Asset Management Program - Attributes - Load DMIDecode File</title>
41
      <link rel="stylesheet" type="text/css" href="../../camp.css">
42
   </head>
43
   <body>
44
      <?php include_once('../../menu.php'); ?>
45
      <div id="content">
46
         <h4>
47
            Import DMI Decode File
48
         </h4>
49
      <?php 
50
         if ( isset( $_POST["submit"] ) ) {
51
            //include_once( 'csvImporter.php' );
52
            $filename = tempnam( '/tmp', 'blk' );
53
            if ( move_uploaded_file( $_FILES["fileToUpload"]["tmp_name"], $filename ) ) {
54
               print "<p>Loading Data</p>\n";
55
               $data = file( $filename,  FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES  );
56
               //$data = file_get_contents( $filename );
57
               //print"<pre>"; print_r( $_REQUEST ); print "</pre>";
58
               $data = dmidecode2array( $data );
59
 
60
               $data = parseTabDelimFile (
61
                              $data,
62
                              isset( $_REQUEST['createattribute'] ),
63
                              false,
64
                              cleanInput( $_REQUEST['device_id'] )
65
                           );
66
 
67
               if ( $data['errors'] ) {
68
                  print "<p>The following errors were encountered</p>";
69
                  print "<p>" . implode( "</p><p>", $data['errors'] ) . "</p>";
70
                  print "<p>Could not import file</p>";
71
               } else {
72
                  $data = $data['sql'];
73
                  //print"<pre>"; print_r( $data ); print "</pre>";
74
                  print '<p>' . updateDatabase( $data ) . '</p>';
75
               }
76
            } else {
77
               print "<p>Error: move_uploaded_file failed to move to $filename</p>";
78
            }
79
            //unlink( $filename );
80
         } else {
81
      ?>
82
    <h4>Upload a File</h4>
83
    <p>Max size: <?php print maxUploadFileSize(); ?></p>
84
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
85
    <input type='hidden' name='referer' value='<?php print $_SERVER['HTTP_REFERER']; ?>' />
86
    <table>
87
       <tr>
88
          <td>
89
             Device
90
          </td>
91
          <td>
92
             <select name='device_id' >
93
                <option value='0'>------------</option>
94
                <?php print queryToSelect( getAllDevices(), $oldValues['device_id'] ); ?>
95
             </select>
96
          </td>
97
       </tr>
98
        <tr>
99
          <td>
100
             Choose File
101
          </td>
102
          <td>
103
             <input name="fileToUpload" type="file" />
104
          </td>
105
       </tr>
106
      <tr>
107
         <td>Create attributes if not found</td>
108
         <td> <input type="checkbox" name="createattribute" value="createattribute"> If an attribute is not found, create it?</td>
109
 
110
      </tr>
111
       <tr>
112
          <td colspan='2' align="center">
113
               <input type="submit" value="Upload CSV" name="submit">
114
         </td>
115
       </tr>
116
   </table>
117
   <?php } ?>
118
      </div>
119
   </body>
120
</html>