mirror of https://github.com/itflow-org/itflow
Add ability for client to upload attachments to approved invoices
This commit is contained in:
parent
b50c2295a6
commit
04226101af
|
|
@ -200,4 +200,72 @@ if (isset($_GET['add_ticket_feedback'], $_GET['url_key'])) {
|
|||
echo "Invalid!!";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['guest_quote_upload_file'])) {
|
||||
$quote_id = intval($_POST['quote_id']);
|
||||
$url_key = sanitizeInput($_POST['url_key']);
|
||||
|
||||
// Select only the necessary fields
|
||||
$sql = mysqli_query($mysqli, "SELECT quote_prefix, quote_number, client_id FROM quotes LEFT JOIN clients ON quote_client_id = client_id WHERE quote_id = $quote_id AND quote_url_key = '$url_key'");
|
||||
|
||||
if (mysqli_num_rows($sql) == 1) {
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$quote_prefix = sanitizeInput($row['quote_prefix']);
|
||||
$quote_number = intval($row['quote_number']);
|
||||
$client_id = intval($row['client_id']);
|
||||
|
||||
// Define & create directories, as required
|
||||
mkdirMissing('../uploads/quotes/');
|
||||
$upload_file_dir = "../uploads/quotes/" . $quote_id . "/";
|
||||
mkdirMissing($upload_file_dir);
|
||||
|
||||
// Store attached any file
|
||||
if (!empty($_FILES)) {
|
||||
|
||||
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
|
||||
// Extract file details for this iteration
|
||||
$single_file = [
|
||||
'name' => $_FILES['file']['name'][$i],
|
||||
'type' => $_FILES['file']['type'][$i],
|
||||
'tmp_name' => $_FILES['file']['tmp_name'][$i],
|
||||
'error' => $_FILES['file']['error'][$i],
|
||||
'size' => $_FILES['file']['size'][$i]
|
||||
];
|
||||
|
||||
if ($file_reference_name = checkFileUpload($single_file, array('pdf'))) {
|
||||
|
||||
$file_tmp_path = $_FILES['file']['tmp_name'][$i];
|
||||
|
||||
$file_name = sanitizeInput($_FILES['file']['name'][$i]);
|
||||
$extarr = explode('.', $_FILES['file']['name'][$i]);
|
||||
$file_extension = sanitizeInput(strtolower(end($extarr)));
|
||||
|
||||
// Define destination file path
|
||||
$dest_path = $upload_file_dir . $file_reference_name;
|
||||
|
||||
// Do upload
|
||||
move_uploaded_file($file_tmp_path, $dest_path);
|
||||
mysqli_query($mysqli, "INSERT INTO quote_attachments SET quote_attachment_name = '$file_name', quote_attachment_reference_name = '$file_reference_name', quote_attachment_quote_id = $quote_id");
|
||||
|
||||
// Logging & feedback
|
||||
$_SESSION['alert_message'] = 'File uploaded!';
|
||||
mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Upload', history_description = 'Client uploaded file $file_name', history_quote_id = $quote_id");
|
||||
logAction("File", "Upload", "Guest uploaded file $file_name to quote $quote_prefix$quote_number", $client_id);
|
||||
|
||||
} else {
|
||||
$_SESSION['alert_type'] = 'error';
|
||||
$_SESSION['alert_message'] = 'Something went wrong uploading the file - please let the support team know.';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
} else {
|
||||
echo "Invalid!!";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
<div class="modal" id="uploadFileModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-cloud-upload-alt mr-2"></i>Upload File</h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="guest_post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
<input type="hidden" name="quote_id" value="<?php echo $quote_id; ?>">
|
||||
<input type="hidden" name="url_key" value="<?php echo $url_key; ?>">
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-angle-right"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="description" maxlength="250" placeholder="Description of the file">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<input type="file" class="form-control-file" name="file[]" id="fileInput" accept=".pdf">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="submit" name="guest_quote_upload_file" class="btn btn-primary text-bold"><i class="fa fa-upload mr-2"></i>Upload</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -270,8 +270,7 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
|
|||
<div class="text-center"><?php echo nl2br($config_quote_footer); ?></div>
|
||||
<div class="">
|
||||
<?php
|
||||
if ($quote_status == "Sent" || $quote_status == "Viewed" && strtotime($quote_expire) > strtotime("now")) {
|
||||
?>
|
||||
if ($quote_status == "Sent" || $quote_status == "Viewed" && strtotime($quote_expire) > strtotime("now")) { ?>
|
||||
<a class="btn btn-success confirm-link" href="guest_post.php?accept_quote=<?php echo $quote_id; ?>&url_key=<?php echo $url_key; ?>">
|
||||
<i class="fas fa-fw fa-thumbs-up mr-2"></i>Accept
|
||||
</a>
|
||||
|
|
@ -279,6 +278,11 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
|
|||
<i class="fas fa-fw fa-thumbs-down mr-2"></i>Decline
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($quote_status == "Accepted") { ?>
|
||||
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#uploadFileModal">
|
||||
<i class="fas fa-fw fa-cloud-upload-alt mr-2"></i>Upload File
|
||||
</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
@ -712,5 +716,6 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
|
|||
</script>
|
||||
|
||||
<?php
|
||||
require_once "guest_quote_upload_file_modal.php";
|
||||
require_once "guest_footer.php";
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
||||
Loading…
Reference in New Issue