xref: /web-bugs/www/fix.php (revision 9d47b05f)
1<?php
2
3use App\Repository\BugRepository;
4use App\Repository\ReasonRepository;
5
6session_start();
7
8/* Admin interface for closing bug reports via direct link */
9
10// Obtain common includes
11require_once '../include/prepend.php';
12
13$bug_id = (int) $_REQUEST['id'];
14
15if (!$bug_id) {
16    redirect('index.php');
17}
18
19// Authenticate
20bugs_authenticate($user, $pw, $logged_in, $user_flags);
21
22// fetch info about the bug into $bug
23$bugRepository = $container->get(BugRepository::class);
24$bug = $bugRepository->findOneById($bug_id);
25
26if (!is_array($bug)) {
27    response_header('No Such Bug');
28    display_bug_error("No such bug #{$bug_id}");
29    response_footer();
30    exit;
31}
32
33// If bug exists, continue..
34$RESOLVE_REASONS = $FIX_VARIATIONS = $errors = [];
35
36if ($logged_in != 'developer') {
37    $errors[] = 'The username or password you supplied was incorrect.';
38}
39
40$project = !empty($_GET['project']) ? $_GET['project'] : false;
41
42$reasonRepository = $container->get(ReasonRepository::class);
43list($RESOLVE_REASONS, $FIX_VARIATIONS) = $reasonRepository->findByProject($site);
44
45// Handle reason / comments
46$reason = isset($_REQUEST['r']) ? filter_var($_REQUEST['r'], FILTER_SANITIZE_STRING) : '';
47$ncomment = isset($_POST['ncomment']) ? trim($_POST['ncomment']) : '';
48
49if (!$reason || !isset($RESOLVE_REASONS[$reason])) {
50    $errors[] = 'You have to use a valid reason to resolve this bug.';
51}
52
53if (isset($RESOLVE_REASONS[$reason]) && $RESOLVE_REASONS[$reason]['status'] == 'Not a bug' && $ncomment == '') {
54    $errors[] = 'You must provide a comment when marking a bug \'Not a bug\'';
55}
56
57// Handle errors
58if ($errors) {
59    response_header('Error in resolving bug');
60    display_bug_error($errors);
61?>
62
63<form method="post" action="fix.php">
64    <input type="hidden" name="id" value="<?php echo $bug_id; ?>">
65
66<?php // Note: same block is used also in bug.php!
67if ($logged_in == 'developer') {
68?>
69    <div class="explain">
70        Welcome back, <?php echo $user; ?>! (Not <?php echo $user; ?>?
71        <a href="logout.php">Log out.</a>)
72    </div>
73<?php } else { ?>
74    <div class="explain">
75        Welcome! If you don't have a Git account, you can't do anything here.<br>
76        You can <a href="bug.php?id=<?php echo $bug_id; ?>&amp;edit=3">add a comment by following this link</a>
77        or if you reported this bug, you can <a href="bug.php?id=<?php echo $bug_id; ?>&amp;edit=2">edit this bug over here</a>.
78        <div class="details">
79            <label for="svnuser">php.net Username:</label>
80            <input type="text" id="svnuser" name="user" value="<?php echo htmlspecialchars($user) ?>" size="10" maxlength="20">
81            <label for="svnpw">php.net Password:</label>
82            <input type="password" id="svnpw" name="pw" value="<?php echo htmlspecialchars($pw) ?>" size="10">
83            <label for="save">Remember:</label><input style="vertical-align:middle;" type="checkbox" id="save" name="save" <?php echo !empty($_POST['save']) ? 'checked="checked"' : ''; ?>>
84        </div>
85    </div>
86<?php } ?>
87    <table>
88        <tr>
89            <th><a href="quick-fix-desc.php">Reason:</a></th>
90            <td colspan="5">
91                <select name="r">
92                    <?php echo show_reason_types($reason); ?>
93                </select>
94            </td>
95        </tr>
96        <tr>
97            <th>Note:</th>
98            <td colspan="5"><textarea cols="80" rows="8" name="ncomment" wrap="physical"><?php echo htmlspecialchars($ncomment); ?></textarea></td>
99        </tr>
100    </table>
101    <input type="submit" value="Resolve">
102</form>
103<?php
104    response_footer();
105    exit;
106}
107
108// Update bug
109$status = $RESOLVE_REASONS[$reason]['status'];
110if (isset($FIX_VARIATIONS[$reason][$bug['bug_type']])) {
111    $qftext = $FIX_VARIATIONS[$reason][$bug['bug_type']];
112} else {
113    $qftext = $RESOLVE_REASONS[$reason]['message'];
114}
115$ncomment = $qftext . (!empty($ncomment) ? "\n\n".$ncomment : "");
116
117// If the report already has the status of the resolution, bounce over to the main bug form
118// which shows the appropriate error message.
119if ($status == $bug['status']) {
120    redirect("bug.php?id={$bug_id}&edit=1&in[resolve]={$reason}");
121}
122
123// Standard items
124$in = [
125    'status' => $status,
126    'bug_type' => $bug['bug_type'],
127    'php_version' => $bug['php_version'],
128    'php_os' => $bug['php_os'],
129    'assign' => $bug['assign'],
130];
131
132// Assign automatically when closed
133if ($status == 'Closed' && $in['assign'] == '') {
134    $in['assign'] = $auth_user->handle;
135}
136
137try {
138    // Update bug
139    $dbh->prepare("
140        UPDATE bugdb
141        SET
142            status = ?,
143            assign = ?,
144            ts2 = NOW()
145        WHERE id = ?
146    ")->execute([
147        $status,
148        $in['assign'],
149        $bug_id,
150    ]);
151
152    // Add changelog entry
153    $changed = bug_diff($bug, $in);
154    if (!empty($changed)) {
155        $log_comment = bug_diff_render_html($changed);
156        if (!empty($log_comment)) {
157            $result = bugs_add_comment($bug_id, $auth_user->email, $auth_user->name, $log_comment, 'log');
158        }
159    }
160
161    // Add possible comment
162    if (!empty($ncomment)) {
163        $result = bugs_add_comment($bug_id, $auth_user->email, $auth_user->name, $ncomment, 'comment');
164    }
165
166    // Send emails
167    mail_bug_updates($bug, $in, $auth_user->email, $ncomment);
168    redirect("bug.php?id={$bug_id}&thanks=1");
169} catch (\Exception $e) {
170    // If we end up here, something went wrong.
171    response_header('Resolve Bug: Problem');
172    display_bug_error($e->getMessage());
173    response_footer();
174}
175