|
|
@@ -1,7 +1,7 @@
|
|
|
<?php
|
|
|
|
|
|
include 'phpexcel/PHPExcel.php';
|
|
|
-include 'db.inc.php';
|
|
|
+include 'db.php';
|
|
|
|
|
|
ini_set('memory_limit', '256M');
|
|
|
|
|
|
@@ -38,12 +38,48 @@ $columns_to_fields = array(
|
|
|
$fields_by_col = array();
|
|
|
|
|
|
|
|
|
-$id_company = 1;
|
|
|
+$path = '../data';
|
|
|
|
|
|
|
|
|
-//TODO: scan respective directories for new files
|
|
|
+//scan respective directories for new files
|
|
|
+$companies = getCompanyDirectories();
|
|
|
+
|
|
|
+for($c = 0; $c < count($companies); $c++)
|
|
|
+{
|
|
|
+ $company = $companies[$c];
|
|
|
+
|
|
|
+ $id_company = $company['id_company'];
|
|
|
+ $name = $company['name'];
|
|
|
+ $ftp_directory = $company['ftp_directory'];
|
|
|
+
|
|
|
+ $ftp_full_path = "$path/$ftp_directory";
|
|
|
+
|
|
|
+
|
|
|
+ echo "scanning #$id_company $name\t$ftp_full_path:\t";
|
|
|
+
|
|
|
+
|
|
|
+ //check if the directory exists
|
|
|
+ if(!file_exists($ftp_full_path) || !is_dir($ftp_full_path))
|
|
|
+ {
|
|
|
+ echo "directory not found\n";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //find all spreadsheets
|
|
|
+ $files = glob("$ftp_full_path/*.xls");
|
|
|
+
|
|
|
+ echo 'found ' . count($files) . ' excel spreadsheet(s)' . PHP_EOL;
|
|
|
+
|
|
|
+
|
|
|
+ //go through each one
|
|
|
+ foreach($files as $filename)
|
|
|
+ {
|
|
|
+ processFile($filename, $id_company);
|
|
|
+ echo PHP_EOL;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-processFile('../test.xls', $id_company);
|
|
|
|
|
|
|
|
|
function processFile($filename, $id_company)
|
|
|
@@ -52,11 +88,13 @@ function processFile($filename, $id_company)
|
|
|
|
|
|
if(!file_exists($filename))
|
|
|
{
|
|
|
- echo "file doesn't exist\n";
|
|
|
+ echo "file doesn't exist" . PHP_EOL;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
$file_size = filesize($filename);
|
|
|
$file_hash = md5_file($filename);
|
|
|
|
|
|
@@ -84,7 +122,7 @@ function processFile($filename, $id_company)
|
|
|
if(count($rows))
|
|
|
{
|
|
|
$id_file = $rows[0]['id_file'];
|
|
|
- echo "re-running file #$id_file\n";
|
|
|
+ echo "re-processing file #$id_file" . PHP_EOL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -94,14 +132,14 @@ function processFile($filename, $id_company)
|
|
|
|
|
|
if(!$stmt_file->execute($params))
|
|
|
{
|
|
|
- echo "\nPDO::errorInfo():\n";
|
|
|
+ echo "PDO::errorInfo():" . PHP_EOL;
|
|
|
print_r($dbh->errorInfo());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$id_file = $dbh->lastInsertId();
|
|
|
|
|
|
- echo "processing new file #$id_file\n";
|
|
|
+ echo "processing new file #$id_file" . PHP_EOL;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -132,7 +170,7 @@ function processFile($filename, $id_company)
|
|
|
|
|
|
if(!$stmt_row)
|
|
|
{
|
|
|
- echo "\nPDO::errorInfo():\n";
|
|
|
+ echo "PDO::errorInfo():" . PHP_EOL;
|
|
|
print_r($dbh->errorInfo());
|
|
|
return;
|
|
|
}
|
|
|
@@ -156,7 +194,7 @@ function processFile($filename, $id_company)
|
|
|
|
|
|
$reader->setReadDataOnly(false);
|
|
|
|
|
|
- echo "Report detected as: $type\n";
|
|
|
+ echo "xls detected as: $type" . PHP_EOL;
|
|
|
|
|
|
// load the file
|
|
|
$excel = $reader->load($filename);
|