diff --git a/app/Http/Controllers/CsvController.php b/app/Http/Controllers/CsvController.php index 3f2504a7a4..4e40bbeed7 100644 --- a/app/Http/Controllers/CsvController.php +++ b/app/Http/Controllers/CsvController.php @@ -8,6 +8,8 @@ namespace FireflyIII\Http\Controllers; +use Auth; +use Crypt; use Illuminate\Http\Request; use Input; use League\Csv\Reader; @@ -42,7 +44,7 @@ class CsvController extends Controller $subTitle = trans('firefly.csv_import'); // can actually upload? - $uploadPossible = !is_writable(storage_path('upload')); + $uploadPossible = is_writable(storage_path('upload')); $path = storage_path('upload'); @@ -54,6 +56,21 @@ class CsvController extends Controller */ public function upload(Request $request) { + // possible column roles: + $roles = [ + '(ignore this column)', + 'Asset account name', + 'Expense or revenue account name', + 'Amount', + 'Date', + 'Currency', + 'Description', + 'Category', + 'Budget', + + ]; + + if (!$request->hasFile('csv')) { Session::flash('warning', 'No file uploaded.'); @@ -64,29 +81,31 @@ class CsvController extends Controller $reader = Reader::createFromPath($request->file('csv')->getRealPath()); $data = $reader->query(); $data->next(); // go to first row: - if ($hasHeaders) { - // first row = headers. + $count = count($data->current()); + $headers = []; + for ($i = 1; $i <= $count; $i++) { + $headers[] = trans('firefly.csv_row') . ' #' . $i; + } + if ($hasHeaders) { $headers = $data->current(); - } else { - $count = count($data->current()); - $headers = []; - for ($i = 1; $i <= $count; $i++) { - $headers[] = trans('firefly.csv_row') . ' #' . $i; - } } // example data is always the second row: $data->next(); $example = $data->current(); + // store file somewhere temporary (encrypted)? + $time = str_replace(' ', '-', microtime()); + $fileName = 'csv-upload-' . Auth::user()->id . '-' . $time . '.csv.encrypted'; + $fullPath = storage_path('upload') . DIRECTORY_SEPARATOR . $fileName; + $content = file_get_contents($request->file('csv')->getRealPath()); + $content = Crypt::encrypt($content); + file_put_contents($fullPath, $content); + Session::put('latestCSVUpload', $fullPath); - var_dump($headers); - var_dump($example); + $subTitle = trans('firefly.csv_process'); - // store file somewhere temporary? - - - exit; + return view('csv.upload', compact('headers', 'example', 'roles', 'subTitle')); } } \ No newline at end of file diff --git a/resources/twig/csv/upload.twig b/resources/twig/csv/upload.twig new file mode 100644 index 0000000000..4b0b34cd07 --- /dev/null +++ b/resources/twig/csv/upload.twig @@ -0,0 +1,71 @@ +{% extends "./layout/default.twig" %} + +{% block breadcrumbs %} + {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }} +{% endblock %} + +{% block content %} + + +
+
+
+
+

{{ 'csv_process'|_ }}

+ + +
+ +
+ +
+
+ {{ 'csv_process_text'|_ }} +
+
+ +
+
+
+
+
+
+

{{ 'csv_process_form'|_ }}

+ + +
+ +
+ +
+
+ + + + + + + + + {% for index,header in headers %} + + + + + + + + {% endfor %} +
{{ 'cvs_column_name'|_ }}{{ 'cvs_column_example'|_ }}{{ 'cvs_column_role'|_ }}{{ 'do_map_value'|_ }}
{{ header }}{{ example[index] }} + {{ Form.select(('role_'~index), roles) }} + + {{ Form.checkbox(('map_'~index),false) }} +
+ + +
+
+
+
+ +{% endblock %}