Subversion Repositories computer_asset_manager_v1

Rev

Blame | Last modification | View Log | Download | RSS feed

<?php

   /*
    * NAME OF FILE
    * 
    * BRIEF DESCRIPTION OF FILE
    *
    * LONG DESCRIPTION OF FILE
    * 
    * Copyright (c) 2020 by the Daily Data, Inc. All rights reserved. Redistribution and use in source and binary forms, with or
    * without modification, are permitted provided that the following conditions are met:
    *     Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    *     Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
    *        disclaimer in the documentation and/or other materials provided with the distribution.
    *     Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this
    *       software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
    * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
    * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    * 20200113 rodo@dailydata.net v0.1
    * Initial build
    * 
    */

   include_once( '../../header.php' );
   include_once( './functions.php' );
   include_once( './dmidecode2array.php' );
   include_once( '../../includes/functions.php' );
   define ( DEBUG, false );
?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title>Computer Asset Management Program - Attributes - Load DMIDecode File</title>
      <link rel="stylesheet" type="text/css" href="../../camp.css">
   </head>
   <body>
      <?php include_once('../../menu.php'); ?>
      <div id="content">
         <h4>
            Import DMI Decode File
         </h4>
      <?php 
         if ( isset( $_POST["submit"] ) ) {
            //include_once( 'csvImporter.php' );
            $filename = tempnam( '/tmp', 'blk' );
            if ( move_uploaded_file( $_FILES["fileToUpload"]["tmp_name"], $filename ) ) {
               print "<p>Loading Data</p>\n";
               $data = file( $filename,  FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES  );
               //$data = file_get_contents( $filename );
               //print"<pre>"; print_r( $_REQUEST ); print "</pre>";
               $data = dmidecode2array( $data );
               
               $data = parseTabDelimFile (
                              $data,
                              isset( $_REQUEST['createattribute'] ),
                              false,
                              cleanInput( $_REQUEST['device_id'] )
                           );

               if ( $data['errors'] ) {
                  print "<p>The following errors were encountered</p>";
                  print "<p>" . implode( "</p><p>", $data['errors'] ) . "</p>";
                  print "<p>Could not import file</p>";
               } else {
                  $data = $data['sql'];
                  //print"<pre>"; print_r( $data ); print "</pre>";
                  print '<p>' . updateDatabase( $data ) . '</p>';
               }
            } else {
               print "<p>Error: move_uploaded_file failed to move to $filename</p>";
            }
            //unlink( $filename );
         } else {
      ?>
    <h4>Upload a File</h4>
    <p>Max size: <?php print maxUploadFileSize(); ?></p>
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
    <input type='hidden' name='referer' value='<?php print $_SERVER['HTTP_REFERER']; ?>' />
    <table>
       <tr>
          <td>
             Device
          </td>
          <td>
             <select name='device_id' >
                <option value='0'>------------</option>
                <?php print queryToSelect( getAllDevices(), $oldValues['device_id'] ); ?>
             </select>
          </td>
       </tr>
        <tr>
          <td>
             Choose File
          </td>
          <td>
             <input name="fileToUpload" type="file" />
          </td>
       </tr>
      <tr>
         <td>Create attributes if not found</td>
         <td> <input type="checkbox" name="createattribute" value="createattribute"> If an attribute is not found, create it?</td>
         
      </tr>
       <tr>
          <td colspan='2' align="center">
               <input type="submit" value="Upload CSV" name="submit">
         </td>
       </tr>
   </table>
   <?php } ?>
      </div>
   </body>
</html>