This blob has been accessed 324 times via Git panel.
- <?php
- session_start();
- header("Cache-control: private");
- error_reporting(E_ERROR);
- require("core.php");
- if (isset($_SESSION['logged_in']) and ($_SESSION['user_agent'] != $_SERVER['HTTP_USER_AGENT'])) {
- header("Location: login.php");
- }
- $login_username = file_get_contents("data/username.txt");
- if (!isset($_SESSION['logged_in']) or ($_SESSION['logged_in'] != $login_username)) {
- }
- if (file_exists("data/items")) {
- if ($dh_cat_txt = opendir("data/items")) {
- while (($entry_cat_txt = readdir($dh_cat_txt)) !== false) {
- if ($entry_cat_txt != "." && $entry_cat_txt != "..") {
- if (file_exists("data/items/$entry_cat_txt/category.txt")) {
- $category_txt = file_get_contents("data/items/$entry_cat_txt/category.txt");
- $category_txt = strtolower($category_txt);
- $category_txt = str_replace(" ","_",$category_txt);
- $category_txt = trim($category_txt);
- if (!file_exists("data/items/$entry_cat_txt/categories")) {
- mkdir("data/items/$entry_cat_txt/categories");
- }
- if (!file_exists("data/items/$entry_cat_txt/categories/$category_txt")) {
- mkdir("data/items/$entry_cat_txt/categories/$category_txt");
- }
- unlink("data/items/$entry_cat_txt/category.txt");
- }
- }
- }
- closedir($dh_cat_txt);
- }
- }
- if (isset($_POST['new_id']) and !empty($_POST['new_id'])) {
- if (!file_exists("data/categories")) {
- mkdir("data/categories");
- }
- $new_id = trim(strip_tags(strtolower(str_replace(" ", "_", $_POST['new_id']))));
- if (!file_exists("data/categories/$new_id")) {
- mkdir("data/categories/$new_id");
- }
- if (isset($_POST['new_title']) and !empty($_POST['new_title'])) {
- $new_title = ucfirst(strip_tags(trim($_POST['new_title'])));
- }
- }
- if (isset($_POST['cat_del']) and !empty($_POST['cat_del']) and ($_POST['cat_del'] == "on")) {
- rmdirr("data/categories/{$_POST['cat_id']}");
- if (file_exists("data/items")) {
- if ($dh_cat_del = opendir("data/items")) {
- while (($entry_cat_del = readdir($dh_cat_del)) !== false) {
- if ($entry_cat_del != "." && $entry_cat_del != "..") {
- if (file_exists("data/items/$entry_cat_del/categories/{$_POST['cat_id']}")) {
- rmdirr("data/items/$entry_cat_del/categories/{$_POST['cat_id']}");
- }
- }
- }
- closedir($dh_cat_del);
- }
- }
- }
- if ((!isset($_POST['cat_hide']) or !empty($_POST['cat_hide'])) and ($_POST['cat_edit'] == "on")) {
- if (file_exists("data/categories/{$_POST['cat_id']}/private.txt")) {
- unlink("data/categories/{$_POST['cat_id']}/private.txt");
- }
- }
- if (isset($_POST['cat_hide']) and !empty($_POST['cat_hide']) and ($_POST['cat_hide'] == "on")) {
- if (file_exists("data/categories/{$_POST['cat_id']}/members")) {
- rmdirr("data/categories/{$_POST['cat_id']}/members");
- }
- if (!file_exists("data/categories/{$_POST['cat_id']}/private.txt")) {
- touch("data/categories/{$_POST['cat_id']}/private.txt");
- }
- }
- if ((!isset($_POST['cat_book']) or !empty($_POST['cat_book'])) and ($_POST['cat_edit'] == "on")) {
- if (file_exists("data/categories/{$_POST['cat_id']}/book.txt")) {
- unlink("data/categories/{$_POST['cat_id']}/book.txt");
- }
- }
- if (isset($_POST['cat_book']) and !empty($_POST['cat_book']) and ($_POST['cat_book'] == "on")) {
- if (!file_exists("data/categories/{$_POST['cat_id']}/book.txt")) {
- touch("data/categories/{$_POST['cat_id']}/book.txt");
- }
- }
- if (isset($_POST['cat_title']) and !empty($_POST['cat_title'])) {
- $cat_title = ucfirst(strip_tags(trim($_POST['cat_title'])));
- if ($cat_title != file_get_contents("data/categories/{$_POST['cat_id']}/title.txt")) {
- }
- }
- if (empty($_POST['cat_title']) and file_exists("data/categories/{$_POST['cat_id']}/title.txt")) {
- unlink("data/categories/{$_POST['cat_id']}/title.txt");
- }
- if (isset($_POST['cat_ren']) and !empty($_POST['cat_ren'])) {
- $cat_rename = strtolower($_POST['cat_ren']);
- $cat_rename = str_replace(" ","_",$cat_rename);
- $cat_rename = trim($cat_rename);
- $cat_oldname = strtolower($_POST['cat_id']);
- $cat_oldname = str_replace(" ","_",$cat_oldname);
- $cat_oldname = trim($cat_oldname);
- if (($cat_rename != $cat_oldname) and !file_exists("data/categories/$cat_rename")) {
- }
- if (file_exists("data/items")) {
- if ($dh_cat_ren = opendir("data/items")) {
- while (($entry_cat_ren = readdir($dh_cat_ren)) !== false) {
- if ($entry_cat_ren != "." && $entry_cat_ren != "..") {
- if (file_exists("data/items/$entry_cat_ren/categories/$cat_oldname") and !file_exists("data/items/$entry_cat_ren/categories/$cat_rename")) {
- rename("data/items/$entry_cat_ren/categories/$cat_oldname","data/items/$entry_cat_ren/categories/$cat_rename");
- }
- }
- }
- closedir($dh_cat_ren);
- }
- }
- }
- ?>
- <title>Categories</title>
- <style>
- body {
- color: #666666;
- margin: 10px;
- padding: 0px;
- text-align: left;
- font-family: <?php
- if (file_exists("data/fonts/body.txt")) {
- $font_body = file_get_contents("data/fonts/body.txt");
- echo "{$font_body},";
- }
- ?> arial, helvetica, sans-serif;
- font-size: 11px;
- background-color: #FFFFFF;
- }
- p, td {
- font-size: 11px;
- }
- a {
- font-weight: bold;
- text-decoration: none;
- }
- a:link, a:visited {
- color: #666666;
- }
- a:hover {
- color: #336699;
- }
- a:active {
- color: #336699;
- }
- .input {
- color: #666666;
- background: #ffffff;
- border: #999999 solid 1px;
- width: 300px;
- font-family: <?php
- if (file_exists("data/fonts/input.txt")) {
- $font_input = file_get_contents("data/fonts/input.txt");
- echo "{$font_input},";
- }
- ?> arial, helvetica, sans-serif;
- font-size: 11px;
- }
- .id {
- color: #666666;
- background: #ffffff;
- border: #999999 solid 1px;
- width: 150px;
- font-family: <?php
- if (file_exists("data/fonts/input.txt")) {
- $font_input = file_get_contents("data/fonts/input.txt");
- echo "{$font_input},";
- }
- ?> arial, helvetica, sans-serif;
- font-size: 11px;
- }
- .submit {
- color: #666666;
- background: #ffffff;
- border: #999999 solid 1px;
- width: 100px;
- font-family: <?php
- if (file_exists("data/fonts/input.txt")) {
- $font_input = file_get_contents("data/fonts/input.txt");
- echo "{$font_input},";
- }
- ?> arial, helvetica, sans-serif;
- font-size: 11px
- }
- </style>
- <p><b>Add Category</b><br>Enter a unique category ID and optional title or description.</p>
- <table border="0" cellspacing="1" cellpadding="2">
- <form enctype="multipart/form-data" action="cat.php" method="post">
- <tr><td>category id*</td><td><input type="text" class="input" name="new_id" autocomplete="off" maxlength="30" autofocus required></td></tr>
- <tr><td>title or description</td><td><input type="text" class="input" name="new_title" autocomplete="off" maxlength="90"></td></tr>
- <tr><td></td><td><input type="submit" class="input" value="click here to add a new category"></td></tr>
- </form>
- <form enctype="multipart/form-data" action="index.php" method="post">
- <tr><td></td><td><input class="input" type="submit" value="click here to go to the index page"></td></tr>
- </form>
- </table>
- <?php
- if (file_exists("data/categories")) {
- if ($dh_cat = opendir("data/categories")) {
- while (($entry_cat = readdir($dh_cat)) !== false) {
- if ($entry_cat != "." && $entry_cat != ".." && fnmatch("*", $entry_cat)) {
- $show_cat[] = $entry_cat;
- }
- }
- closedir($dh_cat);
- }
- sort($show_cat);
- reset($show_cat);
- $count_cat = count($show_cat);
- if ($count_cat > 0) {
- echo "<p><b>Category Management</b><br>Hiding a category will make it, and all associated entries, accessible to you only. Override per entry if needed.";
- echo "<br>Booking a category, for lack of a better term, will unconditionally display all associated entries from oldest to newest.<br>Deleting a category will unfile all its associated entries.</p>";
- echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"2\">";
- echo "<tr><td>category id</td><td align=\"center\">title or description</td><td align=\"center\">hide</td>";
- echo "<td align=\"center\">book</td><td align=\"center\">delete</td><td></td></tr>";
- foreach ($show_cat as $category) {
- echo "<form enctype=\"multipart/form-data\" action=\"cat.php\" method=\"post\">";
- echo "<tr><td><input type=\"text\" class=\"id\" name=\"cat_ren\" value=\"$category\" maxlength=\"30\" autocomplete=\"off\" required></td>";
- echo "<td><input type=\"text\" class=\"input\" name=\"cat_title\" value=\"";
- readfile("data/categories/$category/title.txt");
- echo "\" autocomplete=\"off\" maxlength=\"90\"></td>";
- echo "<td align=\"center\"><input type=\"checkbox\" name=\"cat_hide\"";
- if (file_exists("data/categories/$category/private.txt")) {
- echo " checked";
- }
- echo "></td>";
- echo "<td align=\"center\"><input type=\"checkbox\" name=\"cat_book\"";
- if (file_exists("data/categories/$category/book.txt")) {
- echo " checked";
- }
- echo "></td>";
- echo "<td align=\"center\"><input type=\"checkbox\" name=\"cat_del\"></td>";
- echo "<td><input type=\"hidden\" name=\"cat_id\" value=\"$category\"><input type=\"hidden\" name=\"cat_edit\" value=\"on\"><input type=\"submit\" class=\"submit\" value=\"submit\"></td>";
- echo "</tr></form>";
- }
- echo "</table>";
- }
- }
- ?>