Subversion Repositories computer_asset_manager_v1

Rev

Rev 100 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
99 rodolico 1
<?php
2
   include_once( '../../header.php' );
3
   include_once( './functions.php' );
4
   include_once( '../../includes/functions.php' );
5
 
6
?>
7
 
8
<?xml version="1.0" encoding="utf-8"?>
9
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
10
<html xmlns="http://www.w3.org/1999/xhtml">
11
   <head>
12
     <title>Daily Data - Computer Asset Management Program</title>
13
     <link rel="stylesheet" type="text/css" href="../../camp.css">
14
   </head>
15
   <body>
16
      <?php include_once('../../menu.php'); ?>
17
      <div id="content">
18
      <?php 
19
         if ( isset( $_POST["submit"] ) ) {
20
            include_once( 'csvImporter.php' );
21
            $filename = tempnam( '/tmp', 'blk' );
22
            if ( move_uploaded_file( $_FILES["fileToUpload"]["tmp_name"], $filename ) ) {
23
               print "<p>Loading Data</p>\n";
102 rodolico 24
               $data = file( $filename,  FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES  );
25
               //$data = file_get_contents( $filename );
26
               //print"<pre>"; print_r( $_REQUEST ); print "</pre>";
99 rodolico 27
               $data = parseTabDelimFile (
28
                              $data,
100 rodolico 29
                              isset( $_REQUEST['createattribute'] ),
30
                              isset( $_REQUEST['createdevice'] ),
99 rodolico 31
                              cleanInput( $_REQUEST['device_id'] ),
32
                              cleanInput( $_REQUEST['site_id'] ),
33
                              cleanInput( $_REQUEST['client_id'] )
34
                           );
102 rodolico 35
               if ( $data['errors'] ) {
36
                  print "<h4>Error: Could not import</h4><h5>The following errors were encountered</h5>";
37
                  print "<ul><li>" . implode( "</li><li>", $data['errors'] ) . "</li></ul>";
38
               } else {
39
                  $data = $data['sql'];
40
                  //print"<pre>"; print_r( $data ); print "</pre>";
41
                  print '<p>' . updateDatabase( $data ) . '</p>';
42
               }
99 rodolico 43
            } else {
44
               print "<p>Error: move_uploaded_file failed to move to $filename</p>";
45
            }
46
            //unlink( $filename );
47
         } else {
48
      ?>
49
    <h4>Upload a File</h4>
50
    <p>Max size: <?php print maxUploadFileSize(); ?></p>
51
   <p>Choose default device, site and client if your spreadsheet does not have those columns, or they are unpopulated</p>
52
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
53
    <input type='hidden' name='referer' value='<?php print $_SERVER['HTTP_REFERER']; ?>' />
54
    <input type='hidden' name='file_id' value='<?php print $oldValues['file_id']; ?>' />
55
    <table>
56
       <tr>
57
          <td>
58
             Default Device
59
          </td>
60
          <td>
61
             <select name='device_id' >
62
                <option value='0'>------------</option>
63
                <?php print queryToSelect( getAllDevices(), $oldValues['device_id'] ); ?>
64
             </select>
65
          </td>
66
       </tr>
67
       <tr>
68
          <td>
69
             Default Site
70
          </td>
71
          <td>
72
             <select name='site_id' >
73
                <option value='0'>------------</option>
74
                <?php print queryToSelect( getSites(), $oldValues['site_id'] ); ?>
75
             </select>
76
          </td>
77
       </tr>
78
       <tr>
79
          <td>
80
             Default Client
81
          </td>
82
          <td>
83
             <select name='client_id' >
84
                <option value='0'>------------</option>
85
                <?php print queryToSelect(getClients(), $oldValues['client_id'] ); ?>
86
             </select>
87
          </td>
88
       </tr>
89
        <tr>
90
          <td>
91
             Choose File
92
          </td>
93
          <td>
94
             <input name="fileToUpload" type="file" />
95
          </td>
96
       </tr>
97
      <tr>
98
         <td>Create device if not found</td>
99
         <td> <input type="checkbox" name="createdevice" value="createdevice"></td>
100
      </tr>
101
      <tr>
102
         <td>Create attributes if not found</td>
103
         <td> <input type="checkbox" name="createattribute" value="createattribute"></td>
104
      </tr>
105
       <tr>
106
          <td colspan='2' align="center">
107
               <input type="submit" value="Upload CSV" name="submit">
108
         </td>
109
       </tr>
110
   </table>
111
   </form>
112
        <h4>
113
            Bulk Upload Attributes File
114
         </h4>
115
         <p>
116
            Here you can upload a CSV (tab delimited) containing attributes and values. The first line of the file must be the
117
            column headers. Each following line will contain the values.
118
         </p>
119
         <p>
120
            <a href="<?php print dirname($_SERVER['SCRIPT_NAME']) . '/device_attribute_master.csv'; ?>">Get master csv file</a>.
121
            This contains all attributes as of 2020-01-15. Just delete any lines/columns you do not use.
122
         </p>
123
         <table border='1'>
124
            <tr>
125
               <th>Header Name</th>
126
               <th>Field Contents</th>
127
            </tr>
128
            <tr>
129
               <td><b>value</b></td>
130
               <td>The value to be placed in the attribute table for this device. May not contain line returns</td>
131
            </tr>
132
            <tr>
133
               <td><b>attribute</b></td>
134
               <td>The name of the attribute exactly as found in the attrib table</td>
135
            </tr>
136
            <tr>
137
               <td><b>attrib_id</b></td>
138
               <td>The index of the attribute from the attrib table</td>
139
            </tr>
140
            <tr>
141
               <td>device</td>
142
               <td>The name of the device exactly as found in the device table</td>
143
            </tr>
144
            <tr>
145
               <td>device_id</td>
146
               <td>The index of the device from the device table</td>
147
            </tr>
148
            <tr>
149
               <td>site</td>
150
               <td>The name of the site exactly as found in the site table</td>
151
            </tr>
152
            <tr>
153
               <td>site_id</td>
154
               <td>The index of the site from the site table</td>
155
            </tr>
156
            <tr>
157
               <td>client</td>
158
               <td>The name of the client exactly as found in the client table</td>
159
            </tr>
160
            <tr>
161
               <td>site_id</td>
162
               <td>The index of the client from the client table</td>
163
            </tr>
164
            <tr>
165
               <td>replace_existing</td>
166
               <td>If set to non-zero, device attributes which already exist will be updated<br />if empty or set to 0, a new row will always be created</td>
167
            </tr>
168
         </table>
169
         <p><b>Bolded items are required</b>, however you may choose either attribute or attrib_id (or both)</p>
170
      <?php } ?>
171
      </div>
172
   </body>
173
</html>
174