Rev 100 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
<?php
include_once( '../../header.php' );
include_once( './functions.php' );
include_once( '../../includes/functions.php' );
?>
<?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>Daily Data - Computer Asset Management Program</title>
<link rel="stylesheet" type="text/css" href="../../camp.css">
</head>
<body>
<?php include_once('../../menu.php'); ?>
<div id="content">
<?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 = parseTabDelimFile (
$data,
isset( $_REQUEST['createattribute'] ),
isset( $_REQUEST['createdevice'] ),
cleanInput( $_REQUEST['device_id'] ),
cleanInput( $_REQUEST['site_id'] ),
cleanInput( $_REQUEST['client_id'] )
);
if ( $data['errors'] ) {
print "<h4>Error: Could not import</h4><h5>The following errors were encountered</h5>";
print "<ul><li>" . implode( "</li><li>", $data['errors'] ) . "</li></ul>";
} 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>
<p>Choose default device, site and client if your spreadsheet does not have those columns, or they are unpopulated</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']; ?>' />
<input type='hidden' name='file_id' value='<?php print $oldValues['file_id']; ?>' />
<table>
<tr>
<td>
Default Device
</td>
<td>
<select name='device_id' >
<option value='0'>------------</option>
<?php print queryToSelect( getAllDevices(), $oldValues['device_id'] ); ?>
</select>
</td>
</tr>
<tr>
<td>
Default Site
</td>
<td>
<select name='site_id' >
<option value='0'>------------</option>
<?php print queryToSelect( getSites(), $oldValues['site_id'] ); ?>
</select>
</td>
</tr>
<tr>
<td>
Default Client
</td>
<td>
<select name='client_id' >
<option value='0'>------------</option>
<?php print queryToSelect(getClients(), $oldValues['client_id'] ); ?>
</select>
</td>
</tr>
<tr>
<td>
Choose File
</td>
<td>
<input name="fileToUpload" type="file" />
</td>
</tr>
<tr>
<td>Create device if not found</td>
<td> <input type="checkbox" name="createdevice" value="createdevice"></td>
</tr>
<tr>
<td>Create attributes if not found</td>
<td> <input type="checkbox" name="createattribute" value="createattribute"></td>
</tr>
<tr>
<td colspan='2' align="center">
<input type="submit" value="Upload CSV" name="submit">
</td>
</tr>
</table>
</form>
<h4>
Bulk Upload Attributes File
</h4>
<p>
Here you can upload a CSV (tab delimited) containing attributes and values. The first line of the file must be the
column headers. Each following line will contain the values.
</p>
<p>
<a href="<?php print dirname($_SERVER['SCRIPT_NAME']) . '/device_attribute_master.csv'; ?>">Get master csv file</a>.
This contains all attributes as of 2020-01-15. Just delete any lines/columns you do not use.
</p>
<table border='1'>
<tr>
<th>Header Name</th>
<th>Field Contents</th>
</tr>
<tr>
<td><b>value</b></td>
<td>The value to be placed in the attribute table for this device. May not contain line returns</td>
</tr>
<tr>
<td><b>attribute</b></td>
<td>The name of the attribute exactly as found in the attrib table</td>
</tr>
<tr>
<td><b>attrib_id</b></td>
<td>The index of the attribute from the attrib table</td>
</tr>
<tr>
<td>device</td>
<td>The name of the device exactly as found in the device table</td>
</tr>
<tr>
<td>device_id</td>
<td>The index of the device from the device table</td>
</tr>
<tr>
<td>site</td>
<td>The name of the site exactly as found in the site table</td>
</tr>
<tr>
<td>site_id</td>
<td>The index of the site from the site table</td>
</tr>
<tr>
<td>client</td>
<td>The name of the client exactly as found in the client table</td>
</tr>
<tr>
<td>site_id</td>
<td>The index of the client from the client table</td>
</tr>
<tr>
<td>replace_existing</td>
<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>
</tr>
</table>
<p><b>Bolded items are required</b>, however you may choose either attribute or attrib_id (or both)</p>
<?php } ?>
</div>
</body>
</html>