This blob has been accessed 360 times via Git panel.
- <?php
- require("core.php");
- if (!isset($maj_logged_in_username) or ($maj_logged_in_username != $maj_admin_username)) {
- }
- if (file_exists("$maj_data_directory/items")) {
- if ($dh_cat_txt = opendir("$maj_data_directory/items")) {
- while (($entry_cat_txt = readdir($dh_cat_txt)) !== false) {
- if ($entry_cat_txt != "." && $entry_cat_txt != "..") {
- if (file_exists("$maj_data_directory/items/$entry_cat_txt/category.txt")) {
- $category_txt = file_get_contents("$maj_data_directory/items/$entry_cat_txt/category.txt");
- $category_txt = mb_strtolower($category_txt);
- $category_txt = str_replace(" ","_",$category_txt);
- $category_txt = trim($category_txt);
- if (!file_exists("$maj_data_directory/items/$entry_cat_txt/categories")) {
- mkdir("$maj_data_directory/items/$entry_cat_txt/categories");
- }
- if (!file_exists("$maj_data_directory/items/$entry_cat_txt/categories/$category_txt")) {
- mkdir("$maj_data_directory/items/$entry_cat_txt/categories/$category_txt");
- }
- unlink("$maj_data_directory/items/$entry_cat_txt/category.txt");
- }
- }
- }
- closedir($dh_cat_txt);
- }
- }
- if (isset($_POST['new_id']) and !empty($_POST['new_id'])) {
- if (!file_exists("$maj_data_directory/categories")) {
- mkdir("$maj_data_directory/categories");
- }
- $new_id = trim(strip_tags(mb_strtolower(str_replace(" ", "_", $_POST['new_id']))));
- if (!file_exists("$maj_data_directory/categories/$new_id")) {
- mkdir("$maj_data_directory/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("$maj_data_directory/categories/{$_POST['cat_id']}");
- if (file_exists("$maj_data_directory/items")) {
- if ($dh_cat_del = opendir("$maj_data_directory/items")) {
- while (($entry_cat_del = readdir($dh_cat_del)) !== false) {
- if ($entry_cat_del != "." && $entry_cat_del != "..") {
- if (file_exists("$maj_data_directory/items/$entry_cat_del/categories/{$_POST['cat_id']}")) {
- rmdirr("$maj_data_directory/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("$maj_data_directory/categories/{$_POST['cat_id']}/private.txt")) {
- unlink("$maj_data_directory/categories/{$_POST['cat_id']}/private.txt");
- }
- }
- if (isset($_POST['cat_hide']) and !empty($_POST['cat_hide']) and ($_POST['cat_hide'] == "on")) {
- if (file_exists("$maj_data_directory/categories/{$_POST['cat_id']}/members")) {
- rmdirr("$maj_data_directory/categories/{$_POST['cat_id']}/members");
- }
- if (!file_exists("$maj_data_directory/categories/{$_POST['cat_id']}/private.txt")) {
- touch("$maj_data_directory/categories/{$_POST['cat_id']}/private.txt");
- }
- }
- if ((!isset($_POST['cat_book']) or !empty($_POST['cat_book'])) and ($_POST['cat_edit'] == "on")) {
- if (file_exists("$maj_data_directory/categories/{$_POST['cat_id']}/book.txt")) {
- unlink("$maj_data_directory/categories/{$_POST['cat_id']}/book.txt");
- }
- }
- if (isset($_POST['cat_book']) and !empty($_POST['cat_book']) and ($_POST['cat_book'] == "on")) {
- if (!file_exists("$maj_data_directory/categories/{$_POST['cat_id']}/book.txt")) {
- touch("$maj_data_directory/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("$maj_data_directory/categories/{$_POST['cat_id']}/title.txt")) {
- }
- }
- if (empty($_POST['cat_title']) and file_exists("$maj_data_directory/categories/{$_POST['cat_id']}/title.txt")) {
- unlink("$maj_data_directory/categories/{$_POST['cat_id']}/title.txt");
- }
- if (isset($_POST['cat_ren']) and !empty($_POST['cat_ren'])) {
- $cat_rename = mb_strtolower($_POST['cat_ren']);
- $cat_rename = str_replace(" ","_",$cat_rename);
- $cat_rename = trim($cat_rename);
- $cat_oldname = mb_strtolower($_POST['cat_id']);
- $cat_oldname = str_replace(" ","_",$cat_oldname);
- $cat_oldname = trim($cat_oldname);
- if (($cat_rename != $cat_oldname) and !file_exists("$maj_data_directory/categories/$cat_rename")) {
- }
- if (file_exists("$maj_data_directory/items")) {
- if ($dh_cat_ren = opendir("$maj_data_directory/items")) {
- while (($entry_cat_ren = readdir($dh_cat_ren)) !== false) {
- if ($entry_cat_ren != "." && $entry_cat_ren != "..") {
- if (file_exists("$maj_data_directory/items/$entry_cat_ren/categories/$cat_oldname") and !file_exists("$maj_data_directory/items/$entry_cat_ren/categories/$cat_rename")) {
- rename("$maj_data_directory/items/$entry_cat_ren/categories/$cat_oldname","$maj_data_directory/items/$entry_cat_ren/categories/$cat_rename");
- }
- }
- }
- closedir($dh_cat_ren);
- }
- }
- }
- include("css.php");
- echo "\n<style>body { margin: {$maj_wspace}px; }</style>\n";
- ?>
- <title>Categories</title>
- <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="click" 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="click" type="submit" value="click here to go to the index page"></td></tr>
- </form>
- </table>
- <?php
- if (file_exists("$maj_data_directory/categories")) {
- if ($dh_cat = opendir("$maj_data_directory/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 ";
- if (!file_exists("$maj_data_directory/old.txt")) {
- echo "oldest to newest";
- }
- else {
- echo "newest to oldest";
- }
- echo " (reverse of default sort)<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=\"input\" style=\"width: 200px;\" name=\"cat_ren\" value=\"$category\" maxlength=\"30\" autocomplete=\"off\" required></td>";
- echo "<td><input type=\"text\" class=\"input\" name=\"cat_title\" value=\"";
- readfile("$maj_data_directory/categories/$category/title.txt");
- echo "\" autocomplete=\"off\" maxlength=\"90\"></td>";
- echo "<td align=\"center\"><input type=\"checkbox\" name=\"cat_hide\"";
- if (file_exists("$maj_data_directory/categories/$category/private.txt")) {
- echo " checked";
- }
- echo "></td>";
- echo "<td align=\"center\"><input type=\"checkbox\" name=\"cat_book\"";
- if (file_exists("$maj_data_directory/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=\"click\" style=\"width: 100px;\" value=\"submit\"></td>";
- echo "</tr></form>";
- }
- echo "</table>";
- }
- }
- ?>