|
1 |
| -<?php |
2 |
| - |
| 1 | +<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */ |
3 | 2 | namespace BNETDocs\Templates\Packet;
|
4 |
| - |
5 | 3 | use \CarlBennett\MVC\Libraries\Common;
|
6 | 4 | use \CarlBennett\MVC\Libraries\Pair;
|
7 |
| - |
8 |
| -$title = 'Edit Packet'; |
| 5 | +$title = 'Edit Packet'; |
9 | 6 | $description = 'This form allows an individual to edit a packet.';
|
10 |
| - |
11 | 7 | $this->opengraph->attach(new Pair('url', '/packet/edit'));
|
12 | 8 | $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 packets.'; |
17 |
| - break; |
18 |
| - case 'NOT_FOUND': |
19 |
| - $message = 'Cannot find packet by that id.'; |
20 |
| - break; |
21 |
| - case 'EMPTY_NAME': |
22 |
| - $message = 'The name of the packet is required.'; |
23 |
| - break; |
24 |
| - case 'EMPTY_FORMAT': |
25 |
| - $message = 'The format of the packet is required.'; |
26 |
| - break; |
27 |
| - case 'EMPTY_REMARKS': |
28 |
| - $message = 'The remarks of the packet is required.'; |
29 |
| - break; |
30 |
| - case 'INTERNAL_ERROR': |
31 |
| - $message = 'An internal error occurred while processing your request. ' |
32 |
| - . 'Our staff have been notified of the issue. Try again later.'; |
33 |
| - break; |
34 |
| - default: |
35 |
| - $message = $this->getContext()->error; |
| 9 | +$error = $this->getContext()->error; |
| 10 | +switch ($error) |
| 11 | +{ |
| 12 | + case 'ACL_NOT_SET': $message = 'You do not have the privilege to edit packets.'; break; |
| 13 | + case 'NOT_FOUND': $message = 'Cannot find packet by that id.'; break; |
| 14 | + case 'EMPTY_NAME': $message = 'The name of the packet is required.'; break; |
| 15 | + case 'EMPTY_FORMAT': $message = 'The format of the packet is required.'; break; |
| 16 | + case 'EMPTY_REMARKS': $message = 'The remarks of the packet is required.'; break; |
| 17 | + case 'INTERNAL_ERROR': $message = 'An internal error occurred while processing your request. Our staff have been notified of the issue. Try again later.'; break; |
| 18 | + default: $message = $error; |
36 | 19 | }
|
37 |
| - |
38 |
| -require('./header.inc.phtml'); |
39 |
| -?> |
40 |
| - <article> |
41 |
| -<?php if ($this->getContext()->error !== false) { ?> |
42 |
| - <header>Edit Packet</header> |
43 |
| -<?php if (!empty($message)) { ?> |
44 |
| - <section class="red"><p><?php echo $message; ?></p></section> |
45 |
| -<?php } ?> |
46 |
| -<?php if ($this->getContext()->error != "NOT_FOUND") { ?> |
47 |
| - <form method="POST" action="?id=<?php echo |
48 |
| - htmlspecialchars($this->getContext()->packet_id, ENT_HTML5, "UTF-8"); ?>"> |
49 |
| - <section> |
50 |
| - <label for="id">Id:</label> |
51 |
| - <em style="float:right;">(base 10 / decimal format)</em><br/> |
52 |
| - <input type="text" name="id" id="id" tabindex="1" required |
53 |
| - autofocus="autofocus" value="<?php echo |
54 |
| - filter_var( $this->getContext()->id, FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
55 |
| - ?>"/> |
56 |
| - </section> |
57 |
| - <section> |
58 |
| - <label for="name">Name:</label><br/> |
59 |
| - <input type="text" name="name" id="name" tabindex="2" required |
60 |
| - value="<?php echo |
61 |
| - filter_var( $this->getContext()->name, FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
62 |
| - ?>"/> |
63 |
| - </section> |
64 |
| - <section> |
65 |
| - <label for="format">Format:</label> |
66 |
| - <textarea name="format" id="format" tabindex="3" required |
67 |
| - style="height:200px;"><?php echo |
68 |
| - filter_var( $this->getContext()->format, FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
69 |
| - ?></textarea> |
70 |
| - </section> |
71 |
| - <section> |
72 |
| - <label>Used by:</label> |
73 |
| - <table> |
74 |
| - <thead></thead><tbody> |
75 |
| -<?php function add_product_checkbox( $id, $name, $checked ) { ?> |
76 |
| - <td><input type="checkbox" id="used_by_<?php echo $id; ?>" name="used_by[]" value="<?php echo $id; ?>"<?php if ( $checked ) { ?> checked="checked"<?php } ?>/><label for="used_by_<?php echo $id; ?>"><?php echo $name; ?></label></td> |
77 |
| -<?php } |
78 |
| -$product_ubound = count( $this->getContext()->products ); |
79 |
| -for ( $product_i = 0; $product_i < $product_ubound; ++$product_i ) { ?> |
80 |
| - <tr> |
81 |
| -<?php |
82 |
| - $p = $this->getContext()->products[ $product_i ]; |
83 |
| - $checked = in_array( $p, $this->getContext()->used_by ); |
84 |
| - add_product_checkbox( $p->getBnetProductId(), $p->getLabel(), $checked ); |
85 |
| - if ( $product_i + 1 < $product_ubound ) { |
86 |
| - $p = $this->getContext()->products[ ++$product_i ]; |
87 |
| - $checked = in_array( $p, $this->getContext()->used_by ); |
88 |
| - add_product_checkbox( $p->getBnetProductId(), $p->getLabel(), $checked ); |
89 |
| - } |
90 |
| -?> |
91 |
| - </tr> |
92 |
| -<?php } ?> |
93 |
| - </tbody> |
94 |
| - </table> |
95 |
| - </section> |
96 |
| - <section> |
97 |
| - <label for="remarks">Remarks:</label> |
98 |
| - <span style="float:right;"> |
99 |
| - <label for="markdown" title="Use markdown or use raw HTML">Markdown</label> |
100 |
| - <input type="checkbox" name="markdown" id="markdown" tabindex="5" |
101 |
| - title="Use markdown or use raw HTML" value="1"<?=($this->getContext()->markdown?' checked="checked"':'')?>/> |
102 |
| - </span> |
103 |
| - <textarea name="remarks" id="remarks" tabindex="4" required |
104 |
| - style="height:200px;"><?php echo |
105 |
| - htmlspecialchars($this->getContext()->remarks, ENT_HTML5, "UTF-8"); |
106 |
| - ?></textarea> |
107 |
| - </section> |
108 |
| - <section> |
109 |
| - <label>Flags:</label> |
110 |
| - <table> |
111 |
| - <thead></thead><tbody> |
112 |
| - <tr> |
113 |
| - <td><input type="checkbox" id="deprecated" name="deprecated" value="1"<?=($this->getContext()->deprecated?' checked="checked"':'')?> tabindex="6"/> <label for="deprecated">Deprecated</label></td> |
114 |
| - <td><input type="checkbox" id="research" name="research" value="1"<?=($this->getContext()->research?' checked="checked"':'')?> tabindex="7"/> <label for="research">In Research</label></td> |
115 |
| - <td><input type="checkbox" id="published" name="published" value="1"<?=($this->getContext()->published?' checked="checked"':'')?> tabindex="8"/> <label for="published">Published</label></td> |
116 |
| - </tr> |
117 |
| - </tbody> |
118 |
| - </table> |
119 |
| - </section> |
120 |
| - <section style="text-align:center;"> |
121 |
| - <input type="submit" value="Save" tabindex="9"/> |
122 |
| - </section> |
123 |
| - </form> |
124 |
| -<?php } ?> |
125 |
| -<?php } else { ?> |
126 |
| - <header class="green">Edit Packet</header> |
127 |
| - <section class="green"> |
128 |
| - <p>Your packet has been edited.</p> |
129 |
| - <p>Use the navigation to the left to move to another page.</p> |
130 |
| - </section> |
131 |
| -<?php } ?> |
132 |
| - </article> |
133 |
| -<?php require("./footer.inc.phtml"); ?> |
| 20 | +$id = filter_var($this->getContext()->id, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 21 | +$packet_format = filter_var($this->getContext()->format, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 22 | +$packet_id = filter_var($this->getContext()->packet_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 23 | +$packet_name = filter_var($this->getContext()->name, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 24 | +$packet_remarks = filter_var($this->getContext()->remarks, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 25 | +$packet_used_by = $this->getContext()->used_by; |
| 26 | +$products = $this->getContext()->products; |
| 27 | +require('./header.inc.phtml'); ?> |
| 28 | +<div class="container"> |
| 29 | +<? if ($error !== false) { ?> |
| 30 | + <h1>Edit Packet</h1> |
| 31 | +<? if (!empty($message)) { ?> |
| 32 | + <div class="alert alert-danger"><p class="mb-0"><?=$message?></p></div> |
| 33 | +<? } ?> |
| 34 | +<? if ($error != 'NOT_FOUND') { ?> |
| 35 | + <form method="POST" action="?id=<?=$packet_id?>"> |
| 36 | + <div class="form-group"> |
| 37 | + <label class="font-weight-bold">Flags:</label> |
| 38 | + <div class="custom-control custom-switch"><input class="custom-control-input" type="checkbox" id="deprecated" name="deprecated" value="1"<?=($this->getContext()->deprecated?' checked="checked"':'')?> tabindex="6"/><label class="custom-control-label" for="deprecated">Deprecated</label></div> |
| 39 | + <div class="custom-control custom-switch"><input class="custom-control-input" type="checkbox" id="research" name="research" value="1"<?=($this->getContext()->research?' checked="checked"':'')?> tabindex="7"/> <label class="custom-control-label" for="research">In Research</label></div> |
| 40 | + <div class="custom-control custom-switch"><input class="custom-control-input" type="checkbox" id="published" name="published" value="1"<?=($this->getContext()->published?' checked="checked"':'')?> tabindex="8"/> <label class="custom-control-label" for="published">Published</label></div> |
| 41 | + </div> |
| 42 | + <div class="form-group"> |
| 43 | + <label class="font-weight-bold" for="id">Id:</label> |
| 44 | + <input class="bg-dark border border-primary form-control text-light" type="text" name="id" id="id" placeholder="Enter the decimal (base-10) formatted id here" tabindex="1" required autofocus="autofocus" value="<?=$id?>"/> |
| 45 | + </div> |
| 46 | + <div class="form-group"> |
| 47 | + <label class="font-weight-bold" for="name">Name:</label> |
| 48 | + <input class="bg-dark border border-primary form-control text-light" type="text" name="name" id="name" tabindex="2" required value="<?=$packet_name?>"/> |
| 49 | + </div> |
| 50 | + <div class="form-group"> |
| 51 | + <label class="font-weight-bold" for="format">Format:</label> |
| 52 | + <textarea class="bg-dark border border-primary form-control text-light" name="format" id="format" tabindex="3" required><?=$packet_format?></textarea> |
| 53 | + </div> |
| 54 | + <div class="form-group"> |
| 55 | + <label class="font-weight-bold">Used by:</label> |
| 56 | + <table class="table table-sm"> |
| 57 | + <thead></thead><tbody> |
| 58 | +<? function add_product_checkbox($id, $name, $checked) |
| 59 | + { |
| 60 | + printf('<td><div class="custom-control custom-switch"><input class="custom-control-input" type="checkbox" id="used_by_%s" name="used_by[]" value="%s"%s/><label class="custom-control-label" for="used_by_%s">%s</label></td>', $id, $id, ($checked ? ' checked="checked"' : ''), $id, $name); |
| 61 | + } |
| 62 | + $product_ubound = count($products); |
| 63 | + for ($product_i = 0; $product_i < $product_ubound; ++$product_i) |
| 64 | + { |
| 65 | + echo '<tr>'; |
| 66 | + $p = $products[$product_i]; |
| 67 | + add_product_checkbox($p->getBnetProductId(), $p->getLabel(), in_array($p, $packet_used_by)); |
| 68 | + if ($product_i + 1 < $product_ubound) |
| 69 | + { |
| 70 | + $p = $products[++$product_i]; |
| 71 | + add_product_checkbox($p->getBnetProductId(), $p->getLabel(), in_array($p, $packet_used_by)); |
| 72 | + } |
| 73 | + echo '</tr>'; |
| 74 | + } ?> |
| 75 | + </tbody> |
| 76 | + </table> |
| 77 | + </div> |
| 78 | + <div class="form-group"> |
| 79 | + <label class="font-weight-bold" for="remarks">Remarks:</label> |
| 80 | + <span class="float-right"> |
| 81 | + <div class="custom-control custom-switch"> |
| 82 | + <input class="custom-control-input" type="checkbox" name="markdown" id="markdown" tabindex="5" |
| 83 | + title="Use markdown or use raw HTML" value="1"<?=($this->getContext()->markdown?' checked="checked"':'')?>/> |
| 84 | + <label class="custom-control-label" for="markdown" title="Use markdown or use raw HTML">Markdown</label> |
| 85 | + </div> |
| 86 | + </span> |
| 87 | + <textarea class="bg-dark border border-primary form-control text-light" name="remarks" id="remarks" tabindex="4" required><?=$packet_remarks?></textarea> |
| 88 | + </div> |
| 89 | + <div class="form-group text-center"> |
| 90 | + <input class="btn btn-success" type="submit" value="Save" tabindex="9"/> |
| 91 | + </div> |
| 92 | + </form> |
| 93 | +<? } ?> |
| 94 | +<? } else { ?> |
| 95 | + <h1 class="text-success">Edit Packet</h1> |
| 96 | + <div class="alert alert-success"><p class="mb-0">Your packet has been edited.</p></div> |
| 97 | +<? } ?> |
| 98 | +</div> |
| 99 | +<? require('./footer.inc.phtml'); ?> |
0 commit comments