Copy as a new ticket): it starts with * that ticket's subject, details, priority, category, billing, contact, asset, site, vendor and * tasks, for the same client - which can be changed, and its lists follow. */ enforceUserPermission('module_support', 2); $client_id = intval($_GET['client_id'] ?? 0); $contact_id = intval($_GET['contact_id'] ?? 0); // From a drag over empty time on Dispatch: that agent, booked for that time on the viewer's own // clock, for that long - and back to Dispatch once it is saved $prefill_assigned_to = isset($_GET['assigned_to']) && preg_match('/^\d+$/', (string) $_GET['assigned_to']) ? intval($_GET['assigned_to']) : intval($session_user_id); $prefill_schedule = preg_match('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/', (string) ($_GET['schedule'] ?? '')) ? (string) $_GET['schedule'] : ''; $prefill_schedule_minutes = $prefill_schedule !== '' ? ticketScheduleMinutesValue($_GET['schedule_minutes'] ?? 0) : CALENDAR_TICKET_MINUTES; $return_to = ($_GET['return_to'] ?? '') === 'dispatch' ? 'dispatch' : ''; $project_id = intval($_GET['project_id'] ?? 0); $asset_id = intval($_GET['asset_id'] ?? 0); $location_id = intval($_GET['location_id'] ?? 0); $vendor_id = intval($_GET['vendor_id'] ?? 0); // Opened for one template - New ticket from it, on the template's page - it starts filled in $selected_ticket_template_id = intval($_GET['ticket_template_id'] ?? 0); $ticket_template_apply_on_load = $selected_ticket_template_id > 0; // A ticket started from somewhere that knows what it is about (a license's // Renewal Ticket) - plain text in, escaped here $prefill_subject = mb_substr(trim((string) ($_GET['subject'] ?? '')), 0, 500); $prefill_details = trim((string) ($_GET['details'] ?? '')); $prefill_details_html = $prefill_details !== '' ? '

' . nl2br(escapeHtml($prefill_details)) . '

' : ''; if ($client_id) { enforceClientAccess(); } // A copy of a ticket the agent may reach $copy = intval($_GET['copy_ticket_id'] ?? 0) ? ticketRow($_GET['copy_ticket_id']) : null; if ($copy && intval($copy['ticket_client_id']) && !hasClientAccess($copy['ticket_client_id'])) { $copy = null; } $copy_client_id = 0; $prefill_priority = 'Medium'; $prefill_category_id = 0; $prefill_billable = intval($config_ticket_default_billable) === 1; $existing_tasks = []; if ($copy) { $prefill_subject = (string) $copy['ticket_subject']; $prefill_details_html = (string) $copy['ticket_details']; $prefill_priority = (string) $copy['ticket_priority']; $prefill_category_id = intval($copy['ticket_category']); $prefill_billable = intval($copy['ticket_billable']) === 1; if (!$client_id) { $copy_client_id = intval($copy['ticket_client_id']); } if ($client_id === intval($copy['ticket_client_id']) || $copy_client_id) { $contact_id = $contact_id ?: intval($copy['ticket_contact_id']); $asset_id = $asset_id ?: intval($copy['ticket_asset_id']); $location_id = $location_id ?: intval($copy['ticket_location_id']); $vendor_id = $vendor_id ?: intval($copy['ticket_vendor_id']); } $sql_copy_tasks = mysqli_query($mysqli, "SELECT task_name, task_completion_estimate FROM tasks WHERE task_ticket_id = " . intval($copy['ticket_id']) . " ORDER BY task_order ASC, task_id ASC"); while ($task = mysqli_fetch_assoc($sql_copy_tasks)) { $existing_tasks[] = ['name' => (string) $task['task_name'], 'estimate' => intval($task['task_completion_estimate'])]; } } // Raised about a service (its page's Report a problem) - one of this client's that is not archived $service = intval($_GET['service_id'] ?? 0) ? serviceRow($_GET['service_id']) : null; if ($service && (!$client_id || intval($service['service_client_id']) !== $client_id || $service['service_archived_at'])) { $service = null; } // ...and starts with what whoever picks it up needs: what it runs on, who to call, how it comes back if ($service) { if ($prefill_subject === '') { $prefill_subject = $service['service_name'] . ': '; } $service_assets = serviceLinked($service['service_id'], 'asset'); if ($prefill_details === '') { $prefill_details = serviceTicketDetails($service, $service_assets, serviceLinked($service['service_id'], 'vendor')); $prefill_details_html = '

' . nl2br(escapeHtml($prefill_details)) . '

'; } // Runs on one thing - that is the asset $service_assets = array_values(array_filter($service_assets, function ($row) { return !$row['archived_at']; })); if (!$asset_id && count($service_assets) === 1) { $asset_id = intval($service_assets[0]['id']); } } ob_start(); ?>