Skip to content

Commit 3e06fb2

Browse files
committed
Add packet id editing
1 parent c232503 commit 3e06fb2

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

src/controllers/Packet/Edit.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function &run(Router &$router, View &$view, array &$args) {
2727
$model->csrf_token = CSRF::generate($model->csrf_id, 900); // 15 mins
2828
$model->error = null;
2929
$model->format = null;
30+
$model->id = null;
3031
$model->markdown = null;
3132
$model->name = null;
3233
$model->packet = null;
@@ -50,8 +51,9 @@ public function &run(Router &$router, View &$view, array &$args) {
5051
} else {
5152
$flags = $model->packet->getOptionsBitmask();
5253

53-
$model->format = $model->packet->getPacketFormat();
54+
$model->id = $model->packet->getPacketId();
5455
$model->name = $model->packet->getPacketName();
56+
$model->format = $model->packet->getPacketFormat();
5557
$model->remarks = $model->packet->getPacketRemarks(false);
5658
$model->markdown = ($flags & Packet::OPTION_MARKDOWN);
5759
$model->published = ($flags & Packet::OPTION_PUBLISHED);
@@ -84,6 +86,7 @@ protected function handlePost(Router &$router, PacketEditModel &$model) {
8486
$csrf_id = (isset($data["csrf_id" ]) ? $data["csrf_id" ] : null);
8587
$csrf_token = (isset($data["csrf_token"]) ? $data["csrf_token"] : null);
8688
$csrf_valid = CSRF::validate($csrf_id, $csrf_token);
89+
$id = (isset($data["id" ]) ? $data["id" ] : null);
8790
$name = (isset($data["name" ]) ? $data["name" ] : null);
8891
$format = (isset($data["format" ]) ? $data["format" ] : null);
8992
$remarks = (isset($data["remarks" ]) ? $data["remarks" ] : null);
@@ -92,6 +95,7 @@ protected function handlePost(Router &$router, PacketEditModel &$model) {
9295
$publish = (isset($data["publish" ]) ? $data["publish" ] : null);
9396
$save = (isset($data["save" ]) ? $data["save" ] : null);
9497

98+
$model->id = $id;
9599
$model->name = $name;
96100
$model->format = $format;
97101
$model->remarks = $remarks;
@@ -116,6 +120,7 @@ protected function handlePost(Router &$router, PacketEditModel &$model) {
116120

117121
try {
118122

123+
$model->packet->setPacketId($model->id);
119124
$model->packet->setPacketName($model->name);
120125
$model->packet->setPacketFormat($model->format);
121126
$model->packet->setPacketRemarks($model->remarks);

src/libraries/Packet.php

+4
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@ public function setPacketFormat($value) {
580580
$this->packet_format = $value;
581581
}
582582

583+
public function setPacketId($value) {
584+
$this->packet_id = $value;
585+
}
586+
583587
public function setPacketName($value) {
584588
$this->packet_name = $value;
585589
}

src/models/Packet/Edit.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Edit extends Model {
1111
public $csrf_token;
1212
public $error;
1313
public $format;
14+
public $id;
1415
public $markdown;
1516
public $name;
1617
public $packet;

src/templates/Packet/Edit.phtml

+15-7
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,23 @@ require("./header.inc.phtml");
5959
htmlspecialchars($this->getContext()->csrf_token, ENT_HTML5, "UTF-8");
6060
?>"/>
6161
<section>
62-
<label for="title">Name:</label><br/>
63-
<input type="text" name="name" id="name" tabindex="1" required
62+
<label for="id">Id:</label>
63+
<em style="float:right;">(base 10 / decimal format)</em><br/>
64+
<input type="text" name="id" id="id" tabindex="1" required
6465
autofocus="autofocus" value="<?php echo
66+
filter_var($this->getContext()->id, FILTER_SANITIZE_STRING);
67+
?>"/>
68+
</section>
69+
<section>
70+
<label for="name">Name:</label><br/>
71+
<input type="text" name="name" id="name" tabindex="2" required
72+
value="<?php echo
6573
filter_var($this->getContext()->name, FILTER_SANITIZE_STRING);
6674
?>"/>
6775
</section>
6876
<section>
6977
<label for="format">Remarks:</label>
70-
<textarea name="format" id="format" tabindex="2" required
78+
<textarea name="format" id="format" tabindex="3" required
7179
style="height:200px;"><?php echo
7280
htmlspecialchars($this->getContext()->format, ENT_HTML5, "UTF-8");
7381
?></textarea>
@@ -76,20 +84,20 @@ require("./header.inc.phtml");
7684
<label for="remarks">Remarks:</label>
7785
<span style="float:right;">
7886
<label for="markdown" title="Use markdown or use raw HTML">Markdown</label>
79-
<input type="checkbox" name="markdown" id="markdown" tabindex="4"
87+
<input type="checkbox" name="markdown" id="markdown" tabindex="5"
8088
title="Use markdown or use raw HTML" value="1"<?php
8189
if ($this->getContext()->markdown)
8290
echo " checked=\"checked\"";
8391
?>/>
8492
</span>
85-
<textarea name="remarks" id="remarks" tabindex="3" required
93+
<textarea name="remarks" id="remarks" tabindex="4" required
8694
style="height:200px;"><?php echo
8795
htmlspecialchars($this->getContext()->remarks, ENT_HTML5, "UTF-8");
8896
?></textarea>
8997
</section>
9098
<section>
91-
<input type="submit" name="publish" value="Publish" tabindex="5"/>
92-
<input type="submit" name="save" value="Unpublish" tabindex="6"/>
99+
<input type="submit" name="publish" value="Publish" tabindex="6"/>
100+
<input type="submit" name="save" value="Unpublish" tabindex="7"/>
93101
</section>
94102
</form>
95103
<?php } ?>

0 commit comments

Comments
 (0)