function print_mailer() { global $form_name, $form_header, $form_rcpt, $form_thankyou, $form_error, $form_invalid; if (form_is_posted() && form_is_valid()) { $name = $_POST['name']; $mail = $_POST['mail']; $subj = "=?UTF-8?B?" . base64_encode($form_name) . "?=\n"; $body = make_body(); $head = "From: {$name} ({$_SERVER['REMOTE_ADDR']}) <{$mail}>\n"; $head .= "Reply-To: {$name} <{$mail}>\n"; $head .= "MIME-Version: 1.0\n"; $head .= "Content-Type: text/plain; charset=UTF-8"; if (mail($form_rcpt, $subj, $body, $head)) { echo $form_thankyou; } else { echo $form_error; print_form(); } } else { if (form_is_posted()) { print_form($form_invalid); } else { print_form($form_header); } } }
function add_changes_for_ticket($ticket, $ticketLabels) { global $trac_db, $tickets, $labels, $users_list, $milestones, $skip_comments, $time_in_us, $verbose; $res = $trac_db->query("SELECT ticket_change.* FROM ticket_change, ticket WHERE ticket.id = ticket_change.ticket AND ticket = {$ticket} ORDER BY ticket, time, field <> 'comment'"); foreach ($res->fetchAll() as $row) { if ($verbose) { print_r($row); } if (!isset($tickets[$row['ticket']])) { echo "Skipping comment " . $row['time'] . " on unknown ticket " . $row['ticket'] . "\n"; continue; } $timestamp = date("j M Y H:i e", $row['time'] / ($time_in_us ? 1000000 : 1)); if ($row['field'] == 'comment') { if ($row['newvalue'] != '') { $text = '**Comment by ' . $row['author'] . ' on ' . $timestamp . "**\n" . $row['newvalue']; } else { $text = '**Modified by ' . $row['author'] . ' on ' . $timestamp . "**"; } $resp = github_add_comment($tickets[$row['ticket']], translate_markup($text)); } else { if (in_array($row['field'], ['component', 'priority', 'type', 'resolution'])) { if (in_array($labels[strtoupper($row['field'])[0]][crc32($row['oldvalue'])], $ticketLabels)) { $index = array_search($labels[strtoupper($row['field'])[0]][crc32($row['oldvalue'])], $ticketLabels); $ticketLabels[$index] = $labels[strtoupper($row['field'])[0]][crc32($row['newvalue'])]; } else { $ticketLabels[] = $labels[strtoupper($row['field'])[0]][crc32($row['newvalue'])]; } $resp = github_update_issue($tickets[$ticket], array('labels' => array_values(array_filter($ticketLabels, 'strlen')))); } else { if ($row['field'] == 'status') { $resp = github_update_issue($tickets[$ticket], array('state' => $row['newvalue'] == 'closed' ? 'closed' : 'open')); } else { if ($row['field'] == 'summary') { $resp = github_update_issue($tickets[$ticket], array('title' => $row['newvalue'])); } else { if (false and $row['field'] == 'description') { // TODO? $body = make_body($row['newvalue']); $timestamp = date("j M Y H:i e", $row['time'] / ($time_in_us ? 1000000 : 1)); // TODO: //$body = '**Reported by ' . obfuscate_email($row['reporter']) . ' on ' . $timestamp . "**\n" . $body; $resp = github_update_issue($tickets[$ticket], array('body' => $body)); } else { if ($row['field'] == 'owner') { if (!empty($row['newvalue'])) { $assignee = isset($users_list[$row['newvalue']]) ? $users_list[$row['newvalue']] : NULL; } else { $assignee = NULL; } $resp = github_update_issue($tickets[$ticket], array('assignee' => $assignee)); } else { if ($row['field'] == 'milestone') { if (empty($row['newvalue'])) { $milestone = NULL; } else { $milestone = $milestones[crc32($row['newvalue'])]; } $resp = github_update_issue($tickets[$ticket], array('milestone' => $milestone)); } else { echo "WARNING: ignoring change of {$row['field']} to {$row['newvalue']}\n"; continue; } } } } } } } if (isset($resp['url'])) { // OK echo "Added change {$resp['url']}\n"; } else { // Error $error = print_r($resp, 1); echo "Failed to add a comment for " . $row['ticket'] . ": {$error}\n"; return false; } // Wait 1sec to ensure the next event will be after // just added (apparently github can reorder // changes/comments if added too fast) sleep(1); } return true; }