|
1 |
| -<?php |
2 |
| - |
| 1 | +<?php /* vim: set colorcolumn=: */ |
3 | 2 | namespace BNETDocs\Templates\Document;
|
4 |
| - |
5 | 3 | use \CarlBennett\MVC\Libraries\Common;
|
6 | 4 | use \CarlBennett\MVC\Libraries\Pair;
|
7 |
| - |
8 |
| -$title = "Edit Document"; |
9 |
| -$description = "This form allows an individual to edit a document."; |
10 |
| - |
11 |
| -$this->opengraph->attach(new Pair("url", "/document/edit")); |
12 |
| -$this->opengraph->attach(new Pair("type", "article")); |
13 |
| - |
14 |
| -switch ($this->getContext()->error) { |
15 |
| - case "ACL_NOT_SET": |
16 |
| - $message = "You do not have the privilege to edit documents."; |
17 |
| - break; |
18 |
| - case "NOT_FOUND": |
19 |
| - $message = "Cannot find document by that id."; |
20 |
| - break; |
21 |
| - case "EMPTY_TITLE": |
22 |
| - $message = "The title of the document is required."; |
23 |
| - break; |
24 |
| - case "EMPTY_CONTENT": |
25 |
| - $message = "The content of the document is required."; |
26 |
| - break; |
27 |
| - case "INTERNAL_ERROR": |
28 |
| - $message = "An internal error occurred while processing your request. " |
29 |
| - . "Our staff have been notified of the issue. Try again later."; |
30 |
| - break; |
31 |
| - default: |
32 |
| - $message = $this->getContext()->error; |
| 5 | +$title = 'Edit Document'; |
| 6 | +$description = 'This form allows an individual to edit a document.'; |
| 7 | +$this->opengraph->attach(new Pair('url', '/document/edit')); |
| 8 | +$this->opengraph->attach(new Pair('type', 'article')); |
| 9 | +$document_id = $this->getContext()->document_id; |
| 10 | +$document_url = ($this->getContext()->document ? $this->getContext()->document->getURI() : Common::relativeUrlToAbsolute('/document/' . rawurlencode($document_id))); |
| 11 | +$error = $this->getContext()->error; |
| 12 | +switch ($error) |
| 13 | +{ |
| 14 | + case 'ACL_NOT_SET': $message = 'You do not have the privilege to edit documents.'; break; |
| 15 | + case 'NOT_FOUND': $message = 'Cannot find document by that id.'; break; |
| 16 | + case 'EMPTY_TITLE': $message = 'The title of the document is required.'; break; |
| 17 | + case 'EMPTY_CONTENT': $message = 'The content of the document is required.'; break; |
| 18 | + case 'INTERNAL_ERROR': $message = 'An internal error occurred while processing your request. Our staff have been notified of the issue. Try again later.'; break; |
| 19 | + default: $message = $error; |
33 | 20 | }
|
34 |
| - |
35 |
| -require("./header.inc.phtml"); |
36 |
| -?> |
37 |
| - <article> |
38 |
| -<?php if ($this->getContext()->error !== false) { ?> |
39 |
| - <header>Edit Document</header> |
40 |
| -<?php if (!empty($message)) { ?> |
41 |
| - <section class="red"><p><?php echo $message; ?></p></section> |
42 |
| -<?php } ?> |
43 |
| -<?php if ($this->getContext()->error != "NOT_FOUND") { ?> |
44 |
| - <form method="POST" action="?id=<?php echo |
45 |
| - htmlspecialchars($this->getContext()->document_id, ENT_HTML5, "UTF-8"); ?>"> |
46 |
| - <section> |
47 |
| - <label for="title">Title:</label><br/> |
48 |
| - <input type="text" name="title" id="title" tabindex="1" required |
49 |
| - autofocus="autofocus" value="<?php echo |
50 |
| - filter_var($this->getContext()->title, FILTER_SANITIZE_STRING); |
51 |
| - ?>"/> |
52 |
| - </section> |
53 |
| - <section> |
54 |
| - <label for="content">Content:</label> |
55 |
| - <span style="float:right;"> |
56 |
| - <label for="markdown" title="Use markdown or use raw HTML">Markdown</label> |
57 |
| - <input type="checkbox" name="markdown" id="markdown" tabindex="3" |
58 |
| - title="Use markdown or use raw HTML" value="1"<?php |
59 |
| - if ($this->getContext()->markdown) |
60 |
| - echo " checked=\"checked\""; |
61 |
| - ?>/> |
62 |
| - </span> |
63 |
| - <textarea name="content" id="content" tabindex="2" required |
64 |
| - style="height:200px;"><?php echo |
65 |
| - htmlspecialchars($this->getContext()->content, ENT_HTML5, "UTF-8"); |
66 |
| - ?></textarea> |
67 |
| - </section> |
68 |
| - <section> |
69 |
| - <input type="submit" name="publish" value="Publish" tabindex="4"/> |
70 |
| - <input type="submit" name="save" value="Unpublish" tabindex="5"/> |
71 |
| - </section> |
72 |
| - </form> |
73 |
| -<?php } ?> |
74 |
| -<?php } else { ?> |
75 |
| - <header class="green">Edit Document</header> |
76 |
| - <section class="green"> |
77 |
| - <p>Your document has been edited.</p> |
78 |
| - <p>Use the navigation to the left to move to another page.</p> |
79 |
| - </section> |
80 |
| -<?php } ?> |
81 |
| - </article> |
82 |
| -<?php require("./footer.inc.phtml"); ?> |
| 21 | +$form_content = filter_var($this->getContext()->content, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 22 | +$form_markdown = $this->getContext()->markdown; |
| 23 | +$form_title = filter_var($this->getContext()->title, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 24 | +require('./header.inc.phtml'); ?> |
| 25 | +<div class="container mb-3"> |
| 26 | + <h1><?=$title?></h1> |
| 27 | + <p><?=$description?></p> |
| 28 | +<? if (is_null($error) || $error == 'NOT_FOUND') { |
| 29 | + require('./Document/Form.inc.phtml'); |
| 30 | + } else if ($error !== false) { ?> |
| 31 | + <div class="alert alert-danger"> |
| 32 | + <p class="mb-0"><?=$message?></p> |
| 33 | + </div> |
| 34 | +<? } else { ?> |
| 35 | + <div class="alert alert-success"> |
| 36 | + <p class="mb-0">The document was successfully edited!</p> |
| 37 | + </div> |
| 38 | + <a class="btn btn-primary" href="<?=Common::relativeUrlToAbsolute('/document/' . rawurlencode($document_id))?>">Back</a> |
| 39 | +<? } ?> |
| 40 | +</div> |
| 41 | +<? require('./footer.inc.phtml'); ?> |
0 commit comments