Skip to content

Commit 653b174

Browse files
authored
Merge pull request #1105 from itflow-org/import-chk
Import CSV - Check file uploaded
2 parents b5256fb + 7a561a8 commit 653b174

10 files changed

+52
-12
lines changed

client_asset_import_modal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<p><strong>Format csv file with headings & data:</strong><br>Name, Description, Type, Make, Model, Serial, OS, Assigned To, Location</p>
1515
<hr>
1616
<div class="form-group my-4">
17-
<input type="file" class="form-control-file" name="file" accept=".csv">
17+
<input type="file" class="form-control-file" name="file" accept=".csv" required>
1818
</div>
1919
<hr>
2020
<div>Download <a href="post.php?download_client_assets_csv_template=<?php echo $client_id; ?>">sample csv template</a></div>

client_contact_import_modal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<p><strong>Format csv file with headings & data:</strong><br>Name, Title, Department, Email, Phone, Extension, Mobile, Location</p>
1414
<hr>
1515
<div class="form-group my-4">
16-
<input type="file" class="form-control-file" name="file" accept=".csv">
16+
<input type="file" class="form-control-file" name="file" accept=".csv" required>
1717
</div>
1818
<hr>
1919
<div>Download: <a class="text-bold" href="post.php?download_client_contacts_csv_template=<?php echo $client_id; ?>">sample csv template</a></div>

client_import_modal.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
</button>
99
</div>
1010
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
11-
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
1211
<div class="modal-body bg-white">
1312
<p><strong>Format csv file with headings & data:</strong><br>Client Name, Industry, Referral, Website, Location Name, Location Phone, Location Address, City, State, Postal Code, Country, Contact Name, Title, Contact Phone, Extension, Contact Mobile, Contact Email, Hourly Rate, Currency, Payment Terms, Tax ID, Abbreviation</p>
1413
<hr>
1514
<div class="form-group my-4">
16-
<input type="file" class="form-control-file" name="file" accept=".csv">
15+
<input type="file" class="form-control-file" name="file" accept=".csv" required>
1716
</div>
1817
<hr>
1918
<div>Download: <a class="text-bold" href="post.php?download_clients_csv_template">sample csv template</a></div>

client_location_import_modal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<p><strong>Format csv file with headings & data:</strong><br>Name, Description, Address, City, State, Postal Code, Phone, Hours</p>
1414
<hr>
1515
<div class="form-group my-4">
16-
<input type="file" class="form-control-file" name="file" accept=".csv">
16+
<input type="file" class="form-control-file" name="file" accept=".csv" required>
1717
</div>
1818
<hr>
1919
<div>Download: <a class="text-bold" href="post.php?download_client_locations_csv_template=<?php echo $client_id; ?>">sample csv template</a></div>

client_login_import_modal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<p><strong>Format csv file with headings & data:</strong><br>Name, Description, Username, Password, URL</p>
1414
<hr>
1515
<div class="form-group my-4">
16-
<input type="file" class="form-control-file" name="file" accept=".csv">
16+
<input type="file" class="form-control-file" name="file" accept=".csv" required>
1717
</div>
1818
<hr>
1919
<div>Download <a class="text-bold" href="post.php?download_client_logins_csv_template=<?php echo $client_id; ?>">sample csv template</a></div>

post/user/asset.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,18 @@
473473

474474
$client_id = intval($_POST['client_id']);
475475
$file_name = $_FILES["file"]["tmp_name"];
476+
476477
$error = false;
477478

479+
if (!empty($_FILES["file"]["tmp_name"])) {
480+
$file_name = $_FILES["file"]["tmp_name"];
481+
} else {
482+
$_SESSION['alert_message'] = "Please select a file to upload.";
483+
$_SESSION['alert_type'] = "error";
484+
header("Location: " . $_SERVER["HTTP_REFERER"]);
485+
exit();
486+
}
487+
478488
//Check file is CSV
479489
$file_extension = strtolower(end(explode('.',$_FILES['file']['name'])));
480490
$allowed_file_extensions = array('csv');

post/user/client.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,17 @@
387387
if (isset($_POST["import_clients_csv"])) {
388388

389389
enforceUserPermission('module_client', 2);
390-
391-
$file_name = $_FILES["file"]["tmp_name"];
392390
$error = false;
393391

392+
if (!empty($_FILES["file"]["tmp_name"])) {
393+
$file_name = $_FILES["file"]["tmp_name"];
394+
} else {
395+
$_SESSION['alert_message'] = "Please select a file to upload.";
396+
$_SESSION['alert_type'] = "error";
397+
header("Location: " . $_SERVER["HTTP_REFERER"]);
398+
exit();
399+
}
400+
394401
//Check file is CSV
395402
$file_extension = strtolower(end(explode('.',$_FILES['file']['name'])));
396403
$allowed_file_extensions = array('csv');
@@ -589,7 +596,7 @@
589596
if (isset($_GET['download_clients_csv_template'])) {
590597

591598
$delimiter = ",";
592-
$filename = strtoAZaz09($client_name) . "-Clients-Template.csv";
599+
$filename = "Clients-Template.csv";
593600

594601
//create a file pointer
595602
$f = fopen('php://memory', 'w');

post/user/contact.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,17 @@
822822
enforceUserPermission('module_client', 2);
823823

824824
$client_id = intval($_POST['client_id']);
825-
$file_name = $_FILES["file"]["tmp_name"];
826825
$error = false;
827826

827+
if (!empty($_FILES["file"]["tmp_name"])) {
828+
$file_name = $_FILES["file"]["tmp_name"];
829+
} else {
830+
$_SESSION['alert_message'] = "Please select a file to upload.";
831+
$_SESSION['alert_type'] = "error";
832+
header("Location: " . $_SERVER["HTTP_REFERER"]);
833+
exit();
834+
}
835+
828836
//Check file is CSV
829837
$file_extension = strtolower(end(explode('.',$_FILES['file']['name'])));
830838
$allowed_file_extensions = array('csv');

post/user/credential.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,17 @@
377377
enforceUserPermission('module_credential', 2);
378378

379379
$client_id = intval($_POST['client_id']);
380-
$file_name = $_FILES["file"]["tmp_name"];
381380
$error = false;
382381

382+
if (!empty($_FILES["file"]["tmp_name"])) {
383+
$file_name = $_FILES["file"]["tmp_name"];
384+
} else {
385+
$_SESSION['alert_message'] = "Please select a file to upload.";
386+
$_SESSION['alert_type'] = "error";
387+
header("Location: " . $_SERVER["HTTP_REFERER"]);
388+
exit();
389+
}
390+
383391
//Check file is CSV
384392
$file_extension = strtolower(end(explode('.',$_FILES['file']['name'])));
385393
$allowed_file_extensions = array('csv');

post/user/location.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,17 @@
429429
enforceUserPermission('module_client', 2);
430430

431431
$client_id = intval($_POST['client_id']);
432-
$file_name = $_FILES["file"]["tmp_name"];
433432
$error = false;
434433

434+
if (!empty($_FILES["file"]["tmp_name"])) {
435+
$file_name = $_FILES["file"]["tmp_name"];
436+
} else {
437+
$_SESSION['alert_message'] = "Please select a file to upload.";
438+
$_SESSION['alert_type'] = "error";
439+
header("Location: " . $_SERVER["HTTP_REFERER"]);
440+
exit();
441+
}
442+
435443
//Check file is CSV
436444
$file_extension = strtolower(end(explode('.',$_FILES['file']['name'])));
437445
$allowed_file_extensions = array('csv');

0 commit comments

Comments
 (0)