include_once "auth.inc.php"; $result = array("error" => ""); $action = $_POST["action"]; if (!is_admin()) { $result["error"] = "musisz być administratorem"; die(json_encode($result)); } switch ($action) { case "remove": $username = $_POST["username"]; auth_remove_user($username); break; case "edit": $username = $_POST["username"]; $password = $_POST["password"]; $is_admin = $_POST["is_admin"]; if (!empty($password)) { auth_change_password($username, $password); } auth_change_is_admin($username, $is_admin == "true" ? 1 : 0); break; case "add": $username = $_POST["username"]; $password = $_POST["password"]; $is_admin = $_POST["is_admin"]; auth_add_user($username, $password, $is_admin == "true" ? 1 : 0); break; default: $result["error"] = "unknown command '{$action}'"; } echo utf8_encode(json_encode($result));
<body> <?php include_once "init.inc.php"; include_once "auth.inc.php"; init(); if (!isset($_POST["setup"])) { ?> <form method='POST'> username: <input type='text' name='username'><br> password: <input type='password' name='password'><br> <input type='submit' value='setup' name='setup'> </form> <?php } else { $username = $_POST["username"]; $password = $_POST["password"]; mysql_query("CREATE TABLE tags (\n\t\t\t\ttag_name VARCHAR(128) PRIMARY KEY\n\t\t\t);\n\t\t") or die(mysql_error()); mysql_query("CREATE TABLE categories_to_archive_files (\n\t\t\t\tsignature VARCHAR(128) REFERENCES archive_files,\n\t\t\t\ttag_name VARCHAR(128) REFERENCES tags\n\t\t\t);\n\t\t") or die(mysql_error()); mysql_query("CREATE TABLE people (\n\t\t\t\tperson_id INTEGER PRIMARY KEY AUTO_INCREMENT,\n\t\t\t\ttitle VARCHAR(128),\n\t\t\t\tname VARCHAR(128),\n\t\t\t\tsurname VARCHAR(128),\n\t\t\t\tbirth_date DATE,\n\t\t\t\tdeath_date DATE,\n\t\t\t\tcheck(birth_date < death_date)\n\t\t\t);\n\t\t") or die(mysql_error()); mysql_query("CREATE TABLE archive_files (\n\t\t\t\tsignature VARCHAR(128) PRIMARY KEY,\n\t\t\t\tdate_from DATE,\n\t\t\t\tdate_to DATE,\n\t\t\t\tdescription TEXT,\n\t\t\t\tcheck(date_lower_bound < date_upper_bound)\n\t\t\t);\n\t\t") or die(mysql_error()); mysql_query("CREATE TABLE people_to_archive_files (\n\t\t\t\tperson_id INTEGER REFERENCES people,\n\t\t\t\tsignature VARCHAR(128) REFERENCES archive_files\n\t\t\t);\n\t\t") or die(mysql_error()); mysql_query("CREATE TABLE users (\n\t\t\t\tusername VARCHAR(128) PRIMARY KEY,\n\t\t\t\tpassword VARCHAR(128),\n\t\t\t\tsalt VARCHAR(128),\n\t\t\t\tis_admin BOOLEAN\n\t\t\t);\n\t\t") or die(mysql_error()); auth_add_user($username, $password, true); echo "OK"; } ?> </body> </html>