|
50 | 50 | $subject = "Quote Accepted - $client_name - Quote $quote_prefix$quote_number"; |
51 | 51 | $body = "Hello, <br><br>This is a notification that a quote has been accepted in ITFlow. <br><br>Client: $client_name<br>Quote: <a href=\'https://$config_base_url/quote.php?quote_id=$quote_id\'>$quote_prefix$quote_number</a><br><br>~<br>$company_name - Billing<br>$config_quote_from_email"; |
52 | 52 |
|
53 | | - $data[] = [ |
54 | | - 'from' => $config_quote_from_email, |
55 | | - 'from_name' => $config_quote_from_name, |
56 | | - 'recipient' => $config_quote_notification_email, |
57 | | - 'subject' => $subject, |
58 | | - 'body' => $body, |
59 | | - ]; |
| 53 | + $data[] = [ |
| 54 | + 'from' => $config_quote_from_email, |
| 55 | + 'from_name' => $config_quote_from_name, |
| 56 | + 'recipient' => $config_quote_notification_email, |
| 57 | + 'subject' => $subject, |
| 58 | + 'body' => $body, |
| 59 | + ]; |
60 | 60 |
|
61 | 61 | $mail = addToMailQueue($data); |
62 | 62 | } |
|
200 | 200 | echo "Invalid!!"; |
201 | 201 | } |
202 | 202 | } |
| 203 | + |
| 204 | +if (isset($_POST['guest_quote_upload_file'])) { |
| 205 | + $quote_id = intval($_POST['quote_id']); |
| 206 | + $url_key = sanitizeInput($_POST['url_key']); |
| 207 | + |
| 208 | + // Select only the necessary fields |
| 209 | + $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'"); |
| 210 | + |
| 211 | + if (mysqli_num_rows($sql) == 1) { |
| 212 | + $row = mysqli_fetch_array($sql); |
| 213 | + $quote_prefix = sanitizeInput($row['quote_prefix']); |
| 214 | + $quote_number = intval($row['quote_number']); |
| 215 | + $client_id = intval($row['client_id']); |
| 216 | + |
| 217 | + // Define & create directories, as required |
| 218 | + $upload_file_dir = "../uploads/clients/$client_id/"; |
| 219 | + mkdirMissing($upload_file_dir); |
| 220 | + |
| 221 | + // Store attached any file |
| 222 | + if (!empty($_FILES)) { |
| 223 | + |
| 224 | + for ($i = 0; $i < count($_FILES['file']['name']); $i++) { |
| 225 | + // Extract file details for this iteration |
| 226 | + $single_file = [ |
| 227 | + 'name' => $_FILES['file']['name'][$i], |
| 228 | + 'type' => $_FILES['file']['type'][$i], |
| 229 | + 'tmp_name' => $_FILES['file']['tmp_name'][$i], |
| 230 | + 'error' => $_FILES['file']['error'][$i], |
| 231 | + 'size' => $_FILES['file']['size'][$i] |
| 232 | + ]; |
| 233 | + |
| 234 | + if ($file_reference_name = checkFileUpload($single_file, array('pdf'))) { |
| 235 | + |
| 236 | + $file_tmp_path = $_FILES['file']['tmp_name'][$i]; |
| 237 | + |
| 238 | + $file_name = sanitizeInput($_FILES['file']['name'][$i]); |
| 239 | + $extarr = explode('.', $_FILES['file']['name'][$i]); |
| 240 | + $file_extension = sanitizeInput(strtolower(end($extarr))); |
| 241 | + |
| 242 | + // Extract the file mime type and size |
| 243 | + $file_mime_type = sanitizeInput($single_file['type']); |
| 244 | + $file_size = intval($single_file['size']); |
| 245 | + |
| 246 | + // Define destination file path |
| 247 | + $dest_path = $upload_file_dir . $file_reference_name; |
| 248 | + |
| 249 | + // Get/Create a top-level folder called Client Uploads |
| 250 | + $folder_sql = mysqli_query($mysqli, "SELECT * FROM folders WHERE folder_name = 'Client Uploads' AND parent_folder = 0 AND folder_client_id = $client_id LIMIT 1"); |
| 251 | + if (mysqli_num_rows($folder_sql) == 1) { |
| 252 | + // Get |
| 253 | + $row = mysqli_fetch_array($folder_sql); |
| 254 | + $folder_id = $row['folder_id']; |
| 255 | + } else { |
| 256 | + // Create |
| 257 | + mysqli_query($mysqli,"INSERT INTO folders SET folder_name = 'Client Uploads', parent_folder = 0, folder_location = 1, folder_client_id = $client_id"); |
| 258 | + $folder_id = mysqli_insert_id($mysqli); |
| 259 | + logAction("Folder", "Create", "Automatically created folder Client Uploads", $client_id, $folder_id); |
| 260 | + } |
| 261 | + |
| 262 | + // Do move/upload |
| 263 | + move_uploaded_file($file_tmp_path, $dest_path); |
| 264 | + |
| 265 | + // Create reference in files |
| 266 | + mysqli_query($mysqli,"INSERT INTO files SET file_reference_name = '$file_reference_name', file_name = '$file_name', file_description = 'Uploaded via $quote_prefix$quote_number', file_ext = '$file_extension', file_mime_type = '$file_mime_type', file_size = $file_size, file_folder_id = $folder_id, file_client_id = $client_id"); |
| 267 | + $file_id = mysqli_insert_id($mysqli); |
| 268 | + |
| 269 | + // Associate file with quote |
| 270 | + mysqli_query($mysqli, "INSERT INTO quote_files SET quote_id = $quote_id, file_id = $file_id"); |
| 271 | + |
| 272 | + // Logging & feedback |
| 273 | + $_SESSION['alert_message'] = 'File uploaded!'; |
| 274 | + appNotify("Quote File", "$file_name was uploaded to quote $quote_prefix$quote_number", "quote.php?quote_id=$quote_id", $client_id); |
| 275 | + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Upload', history_description = 'Client uploaded file $file_name', history_quote_id = $quote_id"); |
| 276 | + logAction("File", "Upload", "Guest uploaded file $file_name to quote $quote_prefix$quote_number", $client_id); |
| 277 | + |
| 278 | + } else { |
| 279 | + $_SESSION['alert_type'] = 'error'; |
| 280 | + $_SESSION['alert_message'] = 'Something went wrong uploading the file - please let the support team know.'; |
| 281 | + logApp("Guest", "error", "Error uploading file to invoice"); |
| 282 | + } |
| 283 | + |
| 284 | + } |
| 285 | + } |
| 286 | + |
| 287 | + header("Location: " . $_SERVER["HTTP_REFERER"]); |
| 288 | + |
| 289 | + } else { |
| 290 | + echo "Invalid!!"; |
| 291 | + } |
| 292 | +} |
| 293 | + |
203 | 294 | ?> |
0 commit comments