Navigation Menu

Skip to content

Commit

Permalink
Add a "closed" status to chapters
Browse files Browse the repository at this point in the history
Requires:
ALTER TABLE  `chapters` ADD  `status` TINYINT NOT NULL
  • Loading branch information
kemayo committed Jan 19, 2013
1 parent 937ad43 commit 7e124f6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
8 changes: 6 additions & 2 deletions include/admin.php
Expand Up @@ -147,8 +147,12 @@
}
redirect("admin#chapter" . $chapter['chapterid']);
}
$db->query("UPDATE chapters SET title = %s, slug = %s WHERE chapterid = %d",
array($_POST['title'], $_POST['slug'], $chapterid));
$status = 0;
if(!empty($_POST['closed'])) {
$status = STATUS_CLOSED;
}
$db->query("UPDATE chapters SET title = %s, slug = %s, status = %d WHERE chapterid = %d",
array($_POST['title'], $_POST['slug'], $status, $chapterid));
} else {
$order = $db->quick("SELECT MAX(order) + 1 FROM chapters");
$chapterid = $db->insert_id(
Expand Down
2 changes: 2 additions & 0 deletions index.php
Expand Up @@ -16,6 +16,8 @@
error_reporting(E_ALL);
}

define('STATUS_CLOSED', 1);

$template_fallbacks = array(
// 'template_name' => 'template_to_use_instead'
'admin_head.php' => 'head.php',
Expand Down
3 changes: 2 additions & 1 deletion install/setup.sql
Expand Up @@ -21,7 +21,8 @@ INDEX `bydate` ( `pub_date` )
`title` VARCHAR( 255 ) NOT NULL ,
`slug` VARCHAR( 32 ) NOT NULL ,
`order` TINYINT NOT NULL ,
`parentid` INT NOT NULL
`parentid` INT NOT NULL ,
`status` TINYINT NOT NULL
) ENGINE = MYISAM;

CREATE TABLE `chapters_text` (
Expand Down
7 changes: 7 additions & 0 deletions template/default/admin_chapter.php
Expand Up @@ -13,6 +13,13 @@
<label>Description</label>
<textarea name="description" rows="8" cols="40"><?php echo htmlentities($description); ?></textarea>

<label>Closed</label>
<input name="closed" type="checkbox" value="1"<?php
if($status == STATUS_CLOSED) {
echo ' checked="checked"';
}
?>>

<input type="submit" name="submit" value="save" />
</form>

Expand Down
21 changes: 19 additions & 2 deletions template/default/admin_comic.php
Expand Up @@ -24,13 +24,30 @@

<label>Chapter</label>
<select name="chapterid">
<?php foreach($chapters as $c) {
<?php
$closed = array();
foreach($chapters as $c) {
if($c['status'] == STATUS_CLOSED) {
$closed[] = $c;
continue;
}
echo '<option value="', $c['chapterid'], '"';
if($c['chapterid'] == $chapterid) {
echo ' selected="selected"';
}
echo '>', $c['title'], '</option>', "\n";
} ?>
}
if($closed) {
echo '<option disabled="disabled">---CLOSED---</option>';
foreach($closed as $c) {
echo '<option value="', $c['chapterid'], '"';
if($c['chapterid'] == $chapterid) {
echo ' selected="selected"';
}
echo '>', $c['title'], '</option>', "\n";
}
}
?>
</select>

<label>Filename</label>
Expand Down

0 comments on commit 7e124f6

Please sign in to comment.