|
109 | 109 | $company_name = sanitizeInput($row['company_name']); |
110 | 110 | $company_phone = sanitizeInput(formatPhoneNumber($row['company_phone'])); |
111 | 111 |
|
112 | | - |
| 112 | + |
113 | 113 | // EMAILING |
114 | | - |
| 114 | + |
115 | 115 | $subject = "Ticket created [$ticket_prefix$ticket_number] - $ticket_subject"; |
116 | 116 | $body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello $contact_name,<br><br>A ticket regarding \"$ticket_subject\" has been created for you.<br><br>--------------------------------<br>$ticket_details--------------------------------<br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: Open<br>Portal: <a href=\'https://$config_base_url/guest_view_ticket.php?ticket_id=$ticket_id&url_key=$url_key\'>View ticket</a><br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone"; |
117 | 117 |
|
118 | 118 | // Verify contact email is valid |
119 | 119 | if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) { |
120 | 120 |
|
121 | | - |
122 | 121 |
|
123 | 122 | // Email Ticket Contact |
124 | 123 | // Queue Mail |
|
184 | 183 | $asset_id = intval($_POST['asset']); |
185 | 184 | $location_id = intval($_POST['location']); |
186 | 185 | $project_id = intval($_POST['project']); |
187 | | - |
| 186 | + |
188 | 187 | mysqli_query($mysqli, "UPDATE tickets SET ticket_category = $category_id, ticket_subject = '$ticket_subject', ticket_priority = '$ticket_priority', ticket_billable = $billable, ticket_details = '$details', ticket_vendor_ticket_number = '$vendor_ticket_number', ticket_contact_id = $contact_id, ticket_vendor_id = $vendor_id, ticket_location_id = $location_id, ticket_asset_id = $asset_id, ticket_project_id = $project_id WHERE ticket_id = $ticket_id"); |
189 | 188 |
|
190 | 189 | // Get contact/ticket details after update for logging / email purposes |
|
208 | 207 | $client_id = intval($row['ticket_client_id']); |
209 | 208 |
|
210 | 209 | // Notify new contact if selected |
211 | | - if ($notify && !empty($config_smtp_host)) { |
| 210 | + if ($notify && !empty($config_smtp_host)) { |
212 | 211 |
|
213 | 212 | // Get Company Name Phone Number and Sanitize for Email Sending |
214 | 213 | $sql = mysqli_query($mysqli, "SELECT company_name, company_phone FROM companies WHERE company_id = 1"); |
|
466 | 465 | $watcher_email = sanitizeInput($row['watcher_email']); |
467 | 466 | $client_id = intval($row['ticket_client_id']); |
468 | 467 | $ticket_id = intval($row['ticket_id']); |
469 | | - |
| 468 | + |
470 | 469 | mysqli_query($mysqli, "DELETE FROM ticket_watchers WHERE watcher_id = $watcher_id"); |
471 | 470 |
|
472 | 471 | // History |
|
795 | 794 |
|
796 | 795 | // Assign Tech to Selected Tickets |
797 | 796 | if (isset($_POST['ticket_ids'])) { |
798 | | - |
| 797 | + |
799 | 798 | // Get a Ticket Count |
800 | 799 | $ticket_count = count($_POST['ticket_ids']); |
801 | 800 |
|
|
884 | 883 |
|
885 | 884 | } |
886 | 885 | } // End For Each Ticket ID Loop |
887 | | - |
| 886 | + |
888 | 887 | mysqli_query($mysqli, "UPDATE tickets SET ticket_updated_at = NOW() WHERE ticket_id = $merge_into_ticket_id"); |
889 | 888 |
|
890 | 889 | $_SESSION['alert_message'] = "<strong>$ticket_count</strong> tickets merged into <strong>$ticket_prefix$merge_into_ticket_number</strong>"; |
|
932 | 931 | mysqli_query($mysqli, "UPDATE tickets SET ticket_status = 4, ticket_resolved_at = NOW() WHERE ticket_id = $ticket_id"); |
933 | 932 |
|
934 | 933 | mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = '$details', ticket_reply_type = '$ticket_reply_type', ticket_reply_time_worked = '$ticket_reply_time_worked', ticket_reply_by = $session_user_id, ticket_reply_ticket_id = $ticket_id"); |
935 | | - |
| 934 | + |
936 | 935 | // Logging |
937 | 936 | logAction("Ticket", "Resolve", "$session_name resolved $ticket_prefix$ticket_number - $ticket_subject", $client_id, $ticket_id); |
938 | 937 |
|
|
962 | 961 | $company_name = sanitizeInput($row['company_name']); |
963 | 962 | $company_phone = sanitizeInput(formatPhoneNumber($row['company_phone'])); |
964 | 963 |
|
965 | | - |
| 964 | + |
966 | 965 | // EMAIL |
967 | 966 | $subject = "Ticket resolved - [$ticket_prefix$ticket_number] - $ticket_subject | (pending closure)"; |
968 | 967 | $body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello $contact_name,<br><br>Your ticket regarding \"$ticket_subject\" has been marked as solved and is pending closure.<br><br>$details<br><br> If your request/issue is resolved, you can simply ignore this email. If you need further assistance, please reply or <a href=\'https://$config_base_url/guest_view_ticket.php?ticket_id=$ticket_id&url_key=$url_key\'>re-open</a> to let us know! <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Portal: https://$base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone"; |
|
972 | 971 |
|
973 | 972 | $data = []; |
974 | 973 |
|
975 | | - |
| 974 | + |
976 | 975 |
|
977 | 976 | // Email Ticket Contact |
978 | 977 | // Queue Mail |
|
1071 | 1070 |
|
1072 | 1071 | // Logging |
1073 | 1072 | logAction("Ticket", "Resolved", "$session_name resolved Ticket $ticket_prefix$ticket_number", $client_id, $ticket_id); |
1074 | | - |
| 1073 | + |
1075 | 1074 | customAction('ticket_resolve', $ticket_id); |
1076 | 1075 | } |
1077 | 1076 |
|
|
1203 | 1202 |
|
1204 | 1203 |
|
1205 | 1204 | } // End For Each Ticket ID Loop |
1206 | | - |
| 1205 | + |
1207 | 1206 | $_SESSION['alert_message'] = "<strong>$ticket_count</strong> Tickets added to Project <strong>$project_name</strong>"; |
1208 | 1207 |
|
1209 | 1208 | } |
|
1916 | 1915 |
|
1917 | 1916 | // Add internal note to ticket, and link to invoice in database |
1918 | 1917 | mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = 'Created invoice <a href=\"invoice.php?invoice_id=$invoice_id\">$config_invoice_prefix$invoice_number</a> for this ticket.', ticket_reply_type = 'Internal', ticket_reply_time_worked = '00:01:00', ticket_reply_by = $session_user_id, ticket_reply_ticket_id = $ticket_id"); |
1919 | | - |
| 1918 | + |
1920 | 1919 | mysqli_query($mysqli, "UPDATE tickets SET ticket_invoice_id = $invoice_id WHERE ticket_id = $ticket_id"); |
1921 | 1920 |
|
1922 | 1921 | // Logging |
|
2031 | 2030 | header("Location: " . $_SERVER["HTTP_REFERER"]); |
2032 | 2031 | } |
2033 | 2032 |
|
| 2033 | +if (isset($_GET['force_recurring_ticket'])) { |
| 2034 | + |
| 2035 | + enforceUserPermission('module_support', 2); |
| 2036 | + validateCSRFToken($_GET['csrf_token']); |
| 2037 | + |
| 2038 | + $scheduled_ticket_id = intval($_GET['force_recurring_ticket']); |
| 2039 | + |
| 2040 | + $sql = mysqli_query($mysqli, "SELECT * FROM scheduled_tickets WHERE scheduled_ticket_id = $scheduled_ticket_id"); |
| 2041 | + |
| 2042 | + if (mysqli_num_rows($sql) > 0) { |
| 2043 | + $row = mysqli_fetch_array($sql); |
| 2044 | + $schedule_id = intval($row['scheduled_ticket_id']); |
| 2045 | + $subject = sanitizeInput($row['scheduled_ticket_subject']); |
| 2046 | + $details = mysqli_real_escape_string($mysqli, $row['scheduled_ticket_details']); |
| 2047 | + $priority = sanitizeInput($row['scheduled_ticket_priority']); |
| 2048 | + $frequency = sanitizeInput(strtolower($row['scheduled_ticket_frequency'])); |
| 2049 | + $billable = intval($row['scheduled_ticket_billable']); |
| 2050 | + $old_next_scheduled_date = sanitizeInput($row['scheduled_ticket_next_run']); |
| 2051 | + $created_id = intval($row['scheduled_ticket_created_by']); |
| 2052 | + $assigned_id = intval($row['scheduled_ticket_assigned_to']); |
| 2053 | + $contact_id = intval($row['scheduled_ticket_contact_id']); |
| 2054 | + $client_id = intval($row['scheduled_ticket_client_id']); |
| 2055 | + $asset_id = intval($row['scheduled_ticket_asset_id']); |
| 2056 | + $url_key = randomString(156); |
| 2057 | + |
| 2058 | + $ticket_status = 1; // Default |
| 2059 | + if ($assigned_id > 0) { |
| 2060 | + $ticket_status = 2; // Set to open if we've auto-assigned an agent |
| 2061 | + } |
| 2062 | + |
| 2063 | + // Sanitize Config Vars from get_settings.php and Session Vars from check_login.php |
| 2064 | + $config_ticket_prefix = sanitizeInput($config_ticket_prefix); |
| 2065 | + $config_ticket_from_name = sanitizeInput($config_ticket_from_name); |
| 2066 | + $config_ticket_from_email = sanitizeInput($config_ticket_from_email); |
| 2067 | + $config_base_url = sanitizeInput($config_base_url); |
| 2068 | + |
| 2069 | + // Assign this new ticket the next ticket number & increment config_ticket_next_number by 1 (for the next ticket) |
| 2070 | + $ticket_number = $config_ticket_next_number; |
| 2071 | + $new_config_ticket_next_number = $config_ticket_next_number + 1; |
| 2072 | + mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1"); |
| 2073 | + |
| 2074 | + // Raise the ticket |
| 2075 | + mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = '$ticket_status', ticket_billable = $billable, ticket_url_key = '$url_key', ticket_created_by = $created_id, ticket_assigned_to = $assigned_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id"); |
| 2076 | + $id = mysqli_insert_id($mysqli); |
| 2077 | + |
| 2078 | + // Notifications |
| 2079 | + |
| 2080 | + customAction('ticket_create', $id); |
| 2081 | + |
| 2082 | + // Get client/contact/ticket details |
| 2083 | + $sql = mysqli_query( |
| 2084 | + $mysqli, |
| 2085 | + "SELECT client_name, contact_name, contact_email, ticket_prefix, ticket_number, ticket_priority, ticket_subject, ticket_details FROM tickets |
| 2086 | + LEFT JOIN clients ON ticket_client_id = client_id |
| 2087 | + LEFT JOIN contacts ON ticket_contact_id = contact_id |
| 2088 | + WHERE ticket_id = $id" |
| 2089 | + ); |
| 2090 | + $row = mysqli_fetch_array($sql); |
| 2091 | + |
| 2092 | + $contact_name = sanitizeInput($row['contact_name']); |
| 2093 | + $contact_email = sanitizeInput($row['contact_email']); |
| 2094 | + $client_name = sanitizeInput($row['client_name']); |
| 2095 | + $contact_name = sanitizeInput($row['contact_name']); |
| 2096 | + $contact_email = sanitizeInput($row['contact_email']); |
| 2097 | + $ticket_prefix = sanitizeInput($row['ticket_prefix']); |
| 2098 | + $ticket_number = intval($row['ticket_number']); |
| 2099 | + $ticket_priority = sanitizeInput($row['ticket_priority']); |
| 2100 | + $ticket_subject = sanitizeInput($row['ticket_subject']); |
| 2101 | + $ticket_details = mysqli_real_escape_string($mysqli, $row['ticket_details']); |
| 2102 | + |
| 2103 | + $data = []; |
| 2104 | + |
| 2105 | + // Notify client by email their ticket has been raised, if general notifications are turned on & there is a valid contact email |
| 2106 | + if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1 && filter_var($contact_email, FILTER_VALIDATE_EMAIL)) { |
| 2107 | + |
| 2108 | + $email_subject = "Ticket created - [$ticket_prefix$ticket_number] - $ticket_subject (scheduled)"; |
| 2109 | + $email_body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello $contact_name,<br><br>A ticket regarding \"$ticket_subject\" has been automatically created for you.<br><br>--------------------------------<br>$ticket_details--------------------------------<br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: Open<br>Portal: https://$config_base_url/portal/ticket.php?id=$id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone"; |
| 2110 | + |
| 2111 | + $email = [ |
| 2112 | + 'from' => $config_ticket_from_email, |
| 2113 | + 'from_name' => $config_ticket_from_name, |
| 2114 | + 'recipient' => $contact_email, |
| 2115 | + 'recipient_name' => $contact_name, |
| 2116 | + 'subject' => $email_subject, |
| 2117 | + 'body' => $email_body |
| 2118 | + ]; |
| 2119 | + |
| 2120 | + $data[] = $email; |
| 2121 | + |
| 2122 | + } |
| 2123 | + |
| 2124 | + // Add to the mail queue |
| 2125 | + addToMailQueue($mysqli, $data); |
| 2126 | + |
| 2127 | + // Set the next run date (based on the scheduled date, rather than now, so things keep their schedule) |
| 2128 | + $dt_old_next_scheduled_date = new DateTime($old_next_scheduled_date); |
| 2129 | + if ($frequency == "weekly") { |
| 2130 | + $next_run = date_add($dt_old_next_scheduled_date, date_interval_create_from_date_string('1 week')); |
| 2131 | + } elseif ($frequency == "monthly") { |
| 2132 | + $next_run = date_add($dt_old_next_scheduled_date, date_interval_create_from_date_string('1 month')); |
| 2133 | + } elseif ($frequency == "quarterly") { |
| 2134 | + $next_run = date_add($dt_old_next_scheduled_date, date_interval_create_from_date_string('3 months')); |
| 2135 | + } elseif ($frequency == "biannually") { |
| 2136 | + $next_run = date_add($dt_old_next_scheduled_date, date_interval_create_from_date_string('6 months')); |
| 2137 | + } elseif ($frequency == "annually") { |
| 2138 | + $next_run = date_add($dt_old_next_scheduled_date, date_interval_create_from_date_string('12 months')); |
| 2139 | + } |
| 2140 | + |
| 2141 | + // Update the run date |
| 2142 | + $next_run = $next_run->format('Y-m-d'); |
| 2143 | + mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_next_run = '$next_run' WHERE scheduled_ticket_id = $schedule_id"); |
| 2144 | + |
| 2145 | + // Logging |
| 2146 | + logAction("Ticket", "Create", "$session_name force created recurring scheduled $frequency ticket - $config_ticket_prefix$ticket_number - $subject", $client_id, $id); |
| 2147 | + |
| 2148 | + $_SESSION['alert_message'] = "Recurring Ticket Forced"; |
| 2149 | + |
| 2150 | + header("Location: " . $_SERVER["HTTP_REFERER"]); |
| 2151 | + |
| 2152 | + } else { |
| 2153 | + $_SESSION['alert_type'] = "error"; |
| 2154 | + $_SESSION['alert_message'] = "Recurring Ticket Force failed"; |
| 2155 | + header("Location: " . $_SERVER["HTTP_REFERER"]); |
| 2156 | + } |
| 2157 | + |
| 2158 | +} |
| 2159 | + |
2034 | 2160 | if (isset($_GET['delete_recurring_ticket'])) { |
2035 | 2161 |
|
2036 | 2162 | enforceUserPermission('module_support', 3); |
| 2163 | + validateCSRFToken($_GET['csrf_token']); |
2037 | 2164 |
|
2038 | 2165 | $scheduled_ticket_id = intval($_GET['delete_recurring_ticket']); |
2039 | 2166 |
|
|
0 commit comments