-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrit.php
More file actions
executable file
·151 lines (138 loc) · 7.81 KB
/
Copy pathwrit.php
File metadata and controls
executable file
·151 lines (138 loc) · 7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
declare(strict_types=1);
$import = ['auth', 'csrf', 'view', 'html', 'text', 'writ', 'block', 'user', 'notify'];
require __DIR__ . '/lib/boot.php';
$u = $app->auth->requireUser();
$uid = $app->auth->id();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_writ']) && $app->csrf->check()) {
$id = $app->writ->create([
'writer_id' => $uid,
'facility_id' => $app->auth->facilityId(),
'title' => 'Untitled',
'work' => '',
]);
$app->redirect('writ.php?w=' . $id);
}
$wid = (int) ($_GET['w'] ?? $_POST['writ_id'] ?? 0);
$w = $wid ? $app->writ->find($wid) : null;
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $w && $app->csrf->check() && isset($_POST['submit_draft'])) {
$app->writ->saveDraft($wid, $uid, [
'title' => clean_title($_POST['title'] ?? ''),
'work' => clean_title($_POST['work'] ?? ''),
'block_id' => (int) ($_POST['block'] ?? 0),
'notes' => clean_body($_POST['notes'] ?? ''),
'draft' => clean_body($_POST['draft'] ?? ''),
'draft_wordcount' => wordcount($_POST['draft'] ?? ''),
'writing_time' => (int) ($_POST['writing_time'] ?? 0),
]);
$app->writ->submitDraft($wid, $uid);
$app->notify->toEditorOf($uid, 'new_writ', 'Writ submitted: ' . clean_title($_POST['title'] ?? ''), 'review.php?w=' . $wid);
$app->notify->toObserversOf($uid, 'new_writ', 'Writ submitted: ' . clean_title($_POST['title'] ?? ''), 'writ.php?w=' . $wid);
$app->redirect('writ.php?w=' . $wid);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $w && $app->csrf->check() && isset($_POST['submit_correction'])) {
$app->writ->saveCorrection($wid, $uid, [
'notes' => clean_body($_POST['notes'] ?? ''),
'correction' => clean_body($_POST['correction'] ?? ''),
'correction_wordcount' => wordcount($_POST['correction'] ?? ''),
]);
$app->writ->submitCorrection($wid, $uid);
$app->notify->toEditorOf($uid, 'edited_writ', 'Correction submitted', 'review.php?w=' . $wid);
$app->redirect('writ.php?w=' . $wid);
}
if ($wid && $w && (int) $w['writer_id'] === $uid) {
$app->writ->markViewed($wid, $uid);
}
$app->view->start('Writ', 'writs');
echo '<p>' . post_button('New writ +', 'Start writing something new', 'writ.php', 'new_writ', (string) $uid, 'newNoteButton', $app->csrf->token()) . '</p>';
if (!$w) {
echo '<p class="sans">Open a writ from your list, or start a new one.</p>';
$app->view->end();
exit;
}
if ((int) $w['writer_id'] !== $uid && !$app->auth->atLeast('observer')) {
$app->redirect('');
}
$owner = (int) $w['writer_id'] === $uid;
if ($w['kind'] === 'test') {
$app->redirect('take-test.php?w=' . $wid);
}
if ($w['draft_status'] === 'submitted') {
echo '<p class="sans noticegreen">Submitted and waiting for review.</p>';
$app->view->end();
exit;
}
if ($w['edits_status'] === 'submitted') {
echo '<p class="sans noticegreen">Correction submitted and waiting to be scored.</p>';
$app->view->end();
exit;
}
if ($w['draft_status'] === 'reviewed' && $w['edits_status'] === 'scored') {
echo '<h3 class="lt">' . h($w['work']) . ' — ' . h($w['title']) . '</h3>';
echo '<h4 class="lt">Score: ' . h((string) $w['score']) . '<small class="dk">/' . h((string) $w['outof']) . '</small></h4>';
echo '<h4 class="review">Scoring</h4><section class="writcontent remarks">' . nl_text($w['scoring']) . '</section>';
echo '<h4 class="review">Draft</h4><section class="writcontent draft">' . nl_text($w['draft']) . '</section>';
echo '<h4 class="review">Editor revision</h4><section class="writcontent revision">' . nl_text($w['edits']) . '</section>';
echo '<h4 class="review">Correction</h4><section class="writcontent correction">' . nl_text($w['correction']) . '</section>';
echo '<p>' . history_button($app->writ->hasHistory($w), 'history.php?w=' . $wid) . '</p>';
$app->view->end();
exit;
}
$reviewed = $w['draft_status'] === 'reviewed';
$redraft = $w['draft_status'] === 'redraft';
$blocks = [];
if ($u['type'] === 'writer') {
$thisEditor = (int) ($u['editor_id'] ?? 0);
$blocks = $thisEditor ? $app->block->forEditor($thisEditor, true) : [];
}
if (!$owner) {
echo '<h3 class="lt">' . h($w['work']) . ' — ' . h($w['title']) . '</h3>';
if ($w['instructions']) {
echo '<h4 class="review">Instructions</h4><section class="writcontent remarks">' . nl_text($w['instructions']) . '</section>';
}
echo '<h4 class="review">Draft</h4><section class="writcontent draft">' . nl_text($w['draft']) . '</section>';
if ($w['edits']) {
echo '<h4 class="review">Editor revision</h4><section class="writcontent revision">' . nl_text($w['edits']) . '</section>';
}
echo '<p>' . history_button($app->writ->hasHistory($w), 'history.php?w=' . $wid) . '</p>';
$app->view->end();
exit;
}
echo '<form id="editform" method="post">' . $app->csrf->field();
echo '<input type="hidden" name="writ_id" value="' . (int) $wid . '">';
echo '<input type="hidden" name="user_form" value="' . (int) $uid . '">';
echo '<p class="sans"><label>Block <select name="block" id="block" onchange="onNavWarn()">';
echo '<option value="0">Main</option>';
foreach ($blocks as $b) {
$sel = ((int) $w['block_id'] === (int) $b['id']) ? ' selected' : '';
echo '<option value="' . (int) $b['id'] . '"' . $sel . '>' . h($app->block->named($b)) . '</option>';
}
echo '</select></label></p>';
echo '<p class="sans">Work<br><input name="work" id="work" class="readBox" maxlength="122" value="' . h($w['work']) . '" onchange="onNavWarn()"></p>';
echo '<p class="sans">Title<br><input name="title" id="title" class="writingBox" maxlength="122" required value="' . h($w['title']) . '" onchange="onNavWarn()"></p>';
if ($w['instructions']) {
echo '<h4 class="review">Instructions</h4><section class="writcontent remarks">' . nl_text($w['instructions']) . '</section>';
}
if ($redraft && $w['edit_notes']) {
echo '<h4 class="review">Redraft remarks</h4><section class="writcontent remarks">' . nl_text($w['edit_notes']) . '</section>';
}
echo '<p>' . history_button($app->writ->hasHistory($w), 'history.php?w=' . $wid) . '</p>';
echo '<button type="button" class="lt_button" title="Save (Ctrl + S)" onclick="pwAjaxForm(\'editform\',\'ajax/save-writ.php\',\'ajax_changes\');offNavWarn();">Save</button> ';
echo '<span id="wordCount" class="wordCounter"></span> <span id="ajax_changes"></span>';
if ($reviewed) {
echo '<h4 class="review">Editor revision</h4><section class="writcontent revision">' . nl_text($w['edits']) . '</section>';
echo '<h4 class="review">Remarks</h4><section class="writcontent remarks">' . nl_text($w['edit_notes']) . '</section>';
echo '<p class="sans">Your correction</p>';
echo '<textarea name="correction" id="writingArea" class="writingBox" rows="12" cols="82" spellcheck="false" onchange="onNavWarn()">' . h($w['correction']) . '</textarea>';
echo '<input type="hidden" name="correction_wordcount" id="wordCountInput" value="0">';
echo '<p><input type="submit" name="submit_correction" class="lt_button" value="Submit correction"></p>';
} else {
echo '<textarea name="draft" id="writingArea" class="writingBox" rows="12" cols="82" spellcheck="false" autocapitalize="none" onchange="onNavWarn()" placeholder="Draft contents...">' . h($w['draft']) . '</textarea>';
echo '<input type="hidden" name="draft_wordcount" id="wordCountInput" value="0">';
echo '<input type="hidden" name="save_draft" value="1">';
echo '<p><input type="submit" name="submit_draft" class="lt_button" value="Submit for review"></p>';
}
echo '<p class="sans">Notes<br><textarea name="notes" rows="4" cols="82" onchange="onNavWarn()">' . h($w['notes']) . '</textarea></p>';
echo '</form>';
echo '<script src="js/pw99.js"></script><script>pwWord("writingArea","wordCount","wordCountInput");pwNoPaste("writingArea");pwBindSave("editform","ajax/save-writ.php","ajax_changes");</script>';
$app->view->end();