Manage Personal Accounts
← Return

This demo shows an account management program created using a flat-file relational database. There are 2 data tables - 'accounts' and 'categories', and relationships are established with key-value pairs. All are stored as text files and converted to arrays for processing.
Click here for a Demo
ACCOUNTS Code
Download
ACCOUNTS/index.php ▾
<?php
include ("inc/database-definitions.php");
//include ("inc/functions-no-write.php");
include ("inc/functions.php");
$pageid = "home";
if (isset($_GET['page'])) {
$pageid = $_GET['page'];
}
include ("inc/header.php");
echo "<main>";
if (!file_exists ("pages/". $pageid . ".php") ){
echo "This admin page does not exist";
}
else {
include ("pages/" . $pageid . ".php");
}
echo "</main>";
include ("inc/footer.php");
?>
ACCOUNTS/pages
add-update-account.php ▾
<?php
$accountid = getFromQueryString ('account');
$accountrecord = assignPostValuesToRecord ($_POST, $accountrecordkeys);
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
$error = false;
//Check if new account
if (!$accountid ) {
if (isset ($_POST['name'])) {
$accountid = createRecordId ($_POST['name']);
}
if ($accountid === '') {
echo "<div class = 'error'>Unable to create account id from name</div>";
$error = true;
}
//Check if file already exists
else if (file_exists ('data/accounts/' . $accountid . '.txt')) {
echo "<div class = 'error'>Account already exists</div>";
$error = true;
}
}
//Check for missing information
$categories = array();
if (isset ($_POST['categories'])) {
$categories = $_POST['categories'];
}
if (!$categories) {
echo "<div class = 'error'>Select a category</div>";
$error = true;
}
if (!$accountrecord['username']) {
echo "<div class = 'error'>Select a username</div>";
$error = true;
}
if (!$accountrecord['password']) {
echo "<div class = 'error'>Select a password</div>";
$error = true;
}
if (!$error) {
writeDatabaseRecord($accountrecord, 'data/accounts/' . $accountid . '.txt');
removeMapEntries ("data/category-account-map.txt", '', $accountid);
foreach ($categories as $item) {
addMapEntry ("data/category-account-map.txt", $item, $accountid);
}
}
}
echo "<div class = 'content-column'>";
if ($accountid) {
$accountrecord = readDatabaseRecord($accountrecordkeys, 'data/accounts/' . $accountid . '.txt');
echo "<h2>Edit account: " . $accountrecord['name'] . "</h2>";
}
else {
echo "<h2>Add account</h2>";
}
echo "<form method = 'post' action = 'index.php?page=add-update-account&account=" . $accountid . "'>";
echo "<div class = 'half-column'>";
echo "<label for= 'name-id' >Name</a><br>";
echo "<input id = 'name-id' type = 'text' name = 'name' value = '" . $accountrecord ['name'] . " '/>";
echo "<br><br><label for= 'url-id' >URL</a><br>";
echo "<input id = 'url-id' type = 'text' name = 'url' value = '" . $accountrecord ['url'] . " '/>";
echo "<br><br>Categories: <br>";
$selectedarray = selectMapEntries ('data/category-account-map.txt', '', $accountid);
$categories = readArray ("data/categories.txt", ',');
foreach ($categories as $item) {
$item = trim ($item);
if (in_array ($item, $selectedarray)) {
echo "<input type = 'checkbox' name = 'categories[]' value = '" . $item . "' checked />" . $item ;
}
else {
echo "<input type = 'checkbox' name = 'categories[]' value = '" . $item . "' />" . $item ;
}
echo "<br>";
}
echo "</div><div class = 'half-column'>";
echo "<label for= 'username-id' >Username</a><br>";
echo "<input id = 'username-id' type = 'text' name = 'username' value = '" . $accountrecord ['username'] . " '/>";
echo "<br><br><label for= 'password-id' >Password</a><br>";
echo "<input id = 'password-id' type = 'text' name = 'password' value = '" . $accountrecord ['password'] . " '/>";
echo "<br><br><label for= 'details-id' >Details</a><br><br>";
echo "<textarea name = 'details' id = 'details-id' cols = '80' rows = '10'>" . $accountrecord ['details'] . " </textarea>";
echo "</div>";
echo "<br><br><input class = 'submitbutton' type = 'submit' name = 'submit' value = 'Submit'>";
echo "</form>";
echo "</div><div class = 'sidebar-column'>";
echo "<a class = 'adminbutton' href = 'index.php'>← Home</a>";
echo "<a class = 'adminbutton' href = 'index.php?page=display-account&account=" . $accountid . "'>View</a>";
echo "<a class = 'adminbutton' href = 'index.php?page=remove-account&account=" . $accountid . "'>Remove</a>";
echo "</div>";
?>
detailed-accounts.php ▾
<br><br><div class = 'dropdownwrap'>
<div class = 'dropdownbutton' id = 'accounts-by-category' onclick= 'accordionToggle(this.id)'><h2>Detailed Accounts by Category ▾</h2></div>
<div id ='accounts-by-category-content' class = 'dropdowncontent1' style = 'display: none; ' >
<?php
$categories = readArray ('data/categories.txt', ',');
//Detailed accounts by category
foreach ($categories as $cat) {
$cat = trim ($cat);
echo "<div class = 'box'>";
echo "<br><h3>Category: " . ucwords ($cat) . "</h3>";
$selectedarray = selectMapEntries ('data/category-account-map.txt', $cat, '');
$accounts = getRecordIdsFromFolder ("data/accounts");
foreach ($accounts as $accountid) {
if (in_array ($accountid, $selectedarray)) {
$accountrecord = readDatabaseRecord($accountrecordkeys, 'data/accounts/' . $accountid . '.txt');
echo "<a href = 'index.php?page=display-account&account=" . $accountid . "'><h4>" . $accountrecord['name'] . "</h4></a>";
echo " <b>Username: </b> " . $accountrecord['username'] . " <b>Password: </b> " . $accountrecord['password'] ;
if ($accountrecord['details'] !== "") {
echo " <b> Details: </b>" . $accountrecord['details'];
}
echo "<br>";
}
}
echo "</div>";
}
//Detailed accounts in alphabetical order
?>
</div></div>
<br>
<div class = 'dropdownwrap'>
<div class = 'dropdownbutton' id = 'accounts-alpha' onclick= 'accordionToggle(this.id)'><h2>Detailed Accounts in Alphabetical Order ▾</h2></div>
<div id ='accounts-alpha-content' class = 'dropdowncontent1' style = 'display: none; ' >
<?php
echo "<br><br><h32>Accounts in Alphabetical Order</h3>";
foreach ($accounts as $accountid) {
$accountrecord = readDatabaseRecord($accountrecordkeys, 'data/accounts/' . $accountid . '.txt');
echo " <a href = 'index.php?page=display-account&account=" . $accountid . "'><h4>" . $accountrecord['name'] . "</h4></a>";
echo " <b>Username: </b> " . $accountrecord['username'] . " <b>Password: </b> " . $accountrecord['password'] ;
if ($accountrecord['details'] !== "") {
echo " <b> Details: </b>" . $accountrecord['details'];
}
$selectedarray = selectMapEntries ('data/category-account-map.txt', '', $accountid);
$selectedstring = implode (',', $selectedarray);
echo " <b>Categories: </b>" . $selectedstring;
echo "<br>";
}
?>
</div></div>
display-account.php ▾
<?php
$accountid = getFromQueryString ('account');
$accountrecord = readDatabaseRecord($accountrecordkeys, 'data/accounts/' . $accountid . '.txt');
echo "<div class = 'content-column'>";
echo "<h2>Account: </h2>";
echo "<b>Name: </b>" . $accountrecord['name'];
echo "<br><br><b>URL: </b><a href = '" . $accountrecord['url'] . "'><b>" . $accountrecord['url'] . "</b></a>";
echo "<br><br><b>Username: </b>" . $accountrecord['username'];
echo "<br><br><b>Password: </b>" . $accountrecord['password'];
$selectedarray = selectMapEntries ('data/category-account-map.txt', '', $accountid);
$selectedstring = implode (',',$selectedarray);
echo "<br><br><b>Categories: </b>" . $selectedstring;
echo "<br><br><b>Details: </b>" . nl2br($accountrecord['details']);
echo "</div><div class = 'sidebar-column'>";
echo "<a class = 'adminbutton' href = 'index.php'>← Home</a>";
echo "<a class = 'adminbutton' href = 'index.php?page=add-update-account&account=" . $accountid ."'>Edit</a>";
?>
home.php ▾
<a class = 'menuitem' href = 'index.php?page=add-update-account'>Add New Account</a>
<?php
$categories = readArray ('data/categories.txt', ',');
echo "<div>";
sort($categories);
foreach ($categories as $cat) {
$cat = trim ($cat);
$selectedaccounts = selectMapEntries ('data/category-account-map.txt', $cat, '');
echo "</div><div class = 'box'>";
echo "<h4>" . ucwords(str_replace ('-', ' ', $cat)) . "</h4><br>";
$accounts = getRecordIdsFromFolder ("data/accounts");
foreach ($accounts as $accountid) {
if (in_array ($accountid, $selectedaccounts)) {
$accountrecord = readDatabaseRecord($accountrecordkeys, 'data/accounts/' . $accountid . '.txt');
echo "<a class = 'gridcolumn' href = 'index.php?page=display-account&account=" . $accountid . "'>" . $accountrecord['name'] . "</a>";
}
}
}
echo "</div>";
echo "<h2>All Accounts</h2>";
echo "<div class = 'box'>";
$accounts = getRecordIdsFromFolder ("data/accounts");
foreach ($accounts as $accountid) {
$accountrecord = readDatabaseRecord($accountrecordkeys, 'data/accounts/' . $accountid . '.txt');
echo "<a class = 'gridcolumn' href = 'index.php?page=display-account&account=" . $accountid . "'>" . $accountrecord['name'] . " </a>";
}
echo "</div>";
echo "<br><br><br><h2>Uncategorized</h2>";
$array1 = scandir ("data/accounts");
foreach ($array1 as $item) {
if ($item !== "." && $item !== ".."){
$accountid = str_replace (".txt", "", $item);
$selectedarray = selectmapEntries ('data/category-account-map.txt', '', $accountid);
if (! $selectedarray) {
$accountrecord = readDatabaseRecord($accountrecordkeys, 'data/accounts/' . $accountid . '.txt');
echo "<a class = 'gridcolumn' href = 'index.php?page=display-account&account=" . $accountid . "'>" . $accountrecord['name'] . "</a>";
}
}
}
?> remove-account.php ▾
<?php
//Copyright (c) 2021, Susan V. Rodgers, Lila Avenue, LLC, lilaavenue@gmail.com
echo "<div class = 'content-column'>";
$accountid = "";
if (isset ($_GET["account"])){
$accountid = filter_input(INPUT_GET, "account", FILTER_SANITIZE_STRING) ;
}
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
$_SESSION['accounts-counter']++;
if (isset($_POST ['removeflag'])) {
$removeflag = trim($_POST['removeflag']);
if ($removeflag === "REMOVE") {
if (file_exists ("data/accounts/" . $accountid . ".txt")) {
moveToTrash ("accounts", $accountid);
echo "<h2>Account removed</h2>";
}
}
}
}
if (file_exists ("data/accounts/" . $accountid . ".txt") ) {
echo "<h2>Remove account: " . $accountid . "</h2>";
?>
<form method = 'post' action = 'index.php?page=remove-account&account=<?php echo $accountid ;?>'>
<h3>Are you sure you want to move <?php echo $accountid ; ?> to the Trash Bin?</h3><br>
NO: <input type = 'radio' name = 'removeflag' value = '' checked />
YES <input type = 'radio' name = 'removeflag' value = 'REMOVE' />
<br><br><input class = 'submitbutton' type = 'submit' name = 'submit' value='Remove'/>
</form>
<?php
}
else {
echo "<h2>This account has been removed</h2>";
}
echo "</div><div class = 'sidebar-column'>";
echo "<a class = 'adminbutton' href = 'index.php?page=home'>Return </a><br>";
echo "</div>";
?>
settings.php ▾
<?php
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
if (isset ($_POST['newcategory'])) {
$newcategory = createRecordId ($_POST['newcategory']) ;
if ($newcategory) {
addNameToArray ('data/categories.txt', $newcategory,',');
}
else {
echo "<div class = 'error'>Invalid characters in name</div>";
}
}
else if (isset ($_POST['submit-credentials'])) {
if (isset ($_POST['username'])) {
file_put_contents ("data/username.txt", $_POST['username']);
}
if (isset ($_POST['password'])) {
file_put_contents ("data/password.txt", $_POST['password']);
}
$username = file_get_contents ("data/username.txt");
$password = file_get_contents ("data/password.txt");
}
else if (isset ($_POST['removearray'])) {
foreach ($_POST['removearray'] as $item) {
removeNameFromArray ('data/categories.txt', $item, ',') ;
}
}
}
?>
<h2>Manage Categories</h2><br>
<form method = 'post' action = 'index.php?page=settings'>
<h4>New Category</h4><input type = 'text' name = 'newcategory' /><br>
<br><br> <input class = 'submitbutton' type = 'submit' name = 'submit' value='Submit'>
</form>
<form method = 'post' action = 'index.php?page=settings'>
<h4>All categories - check to remove</h4><br>
<?php
$array1 = readArray("data/categories.txt", ',');
foreach ($array1 as $item) {
echo "<input type = 'checkbox' name = 'removearray[]' value = '" . $item . "' />";
echo "<a href = 'index.php?page=update-category&category=" . $item . "'>";
echo ucwords (str_replace ('-', ' ', $item)) . "<a><br>";
}
?>
<input class = 'submitbutton' type = 'submit' name = 'remove' value='Remove'>
</form>
<br><br><h4>Trash</h4>
<?php
echo "<button class = 'pink-button' onclick = 'setCheckboxes()'>Remove All</button>";
echo "<form method = 'post' action = 'index.php?page=settings'>";
$array1 = scandir ("data/trash");
foreach ($array1 as $item) {
if ($item !== '.' && $item !== "..") {
$array2 = explode ("----", $item);
echo " <input id = 'restore-" . $item . "' type= 'checkbox' name = 'restorearray[]' value = '".$item . "' />";
echo "<label for = 'restore-" . $item . "'>Restore </label>";
echo " ";
echo " <input class = 'checkbox' id = 'remove-" . $item . "' type= 'checkbox' name = 'removearray[]' value = '".$item . "'/>";
echo "<label for = 'remove-" . $item . "'>Delete </label>";
echo " ";
echo $item . "<br>";
}
}
echo "<br><br><input class = 'submitbutton' name = 'submit-trash' type = 'submit' value = 'Submit' />";
echo "</form>";
?>
update-category.php ▾
<?php
//Copyright (c) 2021, Susan V. Rodgers, Lila Avenue, LLC, lilaavenue@gmail.com
$category = "";
if (isset ($_GET['category'])) {
$category = filter_input(INPUT_GET, "category", FILTER_SANITIZE_STRING) ;
}
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
if (isset ($_POST['selected'])) {
$selected = $_POST['selected'];
foreach ($selected as $accountid) {
addMapEntry ("data/category-account-map.txt", $category, $accountid);
}
}
}
?>
<div class = 'content-column'>
<h2>Update Category</h2>
<h4> <?php echo ucwords (str_replace ('-', ' ', $category)); ?> </h4>
<form method = 'post' action = 'index.php?page=update-category&category=<?php echo $category ;?>'>
<?php
$currentarray = selectMapEntries ('data/category-account-map.txt', $category, "");
$accounts = getRecordIdsFromFolder ("data/accounts");
foreach ($accounts as $accountid) {
$array1 = scandir ('data/accounts');
$selectedarray = selectMapEntries ('data/category-account-map.txt', '', $accountid);
$selectedstring = implode (',', $selectedarray);
if (in_array($accountid, $currentarray)) {
echo "<input id = '" . $accountid . "' type = 'checkbox' name = 'selected[]' value = '" . $accountid . "' checked />";
echo "<label for = '" .$accountid . "'><a href = 'index.php?page=add-update-accountd&accountid=" . $accountid . "'>" . $accountid . "</a></label>";
}
else {
echo "<input id = '" . $accountid . "' type = 'checkbox' name = 'selected[]' value = '" . $accountid . "' /> ";
echo "<label for = '" .$accountid . "'><a href = 'index.php?page=add-update-account&accountid=" . $accountid . "'>" . $accountid . "</a></label>";
}
echo " " . $selectedstring . "</br>";
}
?>
<br><br> <input class = 'submitbutton' name = 'submit' type = 'submit' value='Select'>
</form>
</div><div class = 'sidebar-column'>
</div>
ACCOUNTS/inc
database-definitions.php ▾
<?php
$dl1 = "%!%";
$dl2 = "#%#";
$accountrecordkeys = array ("name" , "url" , "username" , "password" , "details" );
?> footer.php ▾
<footer>
<?php
if ($pageid !== 'display-document') {
echo "<a href = '../../data/images/download-files/ACCOUNTS.zip'><br>Download Code<br></a>";
echo "<br>Copyright © " . date('Y') ." Susan Rodgers, <a href = 'https://lilaavenue.com'>Lila Avenue</a><br><br><br><br>";
}
?>
</footer>
</div>
<script>
function accordionToggle(bttn) {
///Used tp display sections in Control Panel
var x = document.getElementById(bttn+"-content");
if (x.style.display === "block" ) {
x.style.display = 'none';
}
else {
x.style.display = 'block';
}
}
</script>
</body>
</html> functions-no-write.php ▾
<?php
function createRecordId ($name) {
$newname = "";
if ($name !== "") {
$newname = trim ($name);
$newname = str_replace (" " , "-", $newname);
$newname = strtolower ($newname);
$newname = preg_replace('/[^A-Za-z0-9-?!]/', '', $newname);
$newname = preg_replace('/-+/', '-', $newname);
}
return $newname;
}
function initializeRecord ($keys){
$record = array ();
foreach ($keys as $Id => $key) {
$record[$key] = "";
}
return ($record);
}
function readDatabaseRecord ($keys, $filename) {
global $dl1;
//Initialize record
$record = array();
foreach ($keys as $Id => $key) {
$record[$key] = "";
}
if ($filename && file_exists($filename)) {
$string = file_get_contents ($filename);
$fArray1= explode ($dl1, $string);
foreach ($keys as $Id => $key) {
if (array_key_exists ($Id, $fArray1)) {
$record [$key] = $fArray1[$Id];
}
}
}
return $record;
}
function writeDatabaseRecord ($record, $filename) {
global $dl1;
$String = implode ($dl1, $record);
//file_put_contents ($filename, $String);
}
// Maps for table relationships
function addMapEntry ($map, $key1, $key2) {
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
$newentry = $key1 . $dl2 . $key2 . "\n";
array_push ($fArray1, $newentry);
$fArray1 = array_unique ($fArray1);
sort ($fArray1);
//writeArray ($map, $fArray1, $dl1);
}
function removeMapEntries ($map, $key0, $key1) {
//Remove entries containing either or both key0 and key1
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Id => $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (0, $fArray2) && array_key_exists (1, $fArray2)) {
if ($key0 && $key1 ) {
if ( $fArray2[0] === $key0 && $fArray2[1] === $key1 ) {
//unset ($fArray1 [$Id]);
}
}
else if (! $key0 && $key1 ) {
if ($fArray2[1] === $key1) {
//unset ($fArray1 [$Id]);
}
}
else if ($key0 && !$key1) {
if ($fArray2[0] === $key0) {
//unset ($fArray1 [$Id]);
}
}
}
}
// writeArray ($map, $fArray1, $dl1);
}
function selectMapEntries ($map, $key0, $key1) {
//for many-to-many relationships
//returns an array with selected key
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
$selectedarray = array();
if ($key0 && !$key1 ) {
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (1, $fArray2)) {
if ($fArray2[0] == $key0 ){
array_push ($selectedarray, $fArray2[1]);
}
}
}
}
else if (!$key0 && $key1) {
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (1, $fArray2)) {
if ($fArray2[1] === $key1) {
array_push ($selectedarray, $fArray2[0]);
}
}
}
}
return $selectedarray;
}
function selectMapKey ($map, $key0, $key1) {
//For one-to-many relationships
//returns a single value
global $dl1, $dl2;
$returnvalue = '';
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Id => $Item1) {
$fArray2 = explode ($dl2, $Item1);
if ( array_key_exists (1, $fArray2)) {
if (!$key0 && $key1) {
if ($fArray2[1] === $key1) {
$returnvalue = $fArray2[0];
break;
}
}
else if ($key0 && ! $key1) {
if ($fArray2[0] === $key0){
$returnvalue = $fArray2[1];
break;
}
}
}
}
return $returnvalue;
}
function extractFromMap($map, $key) {
//returns a new array of either the the first or second columns
global $dl1, $dl2;
$selectedarray = array();
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if ($key == 0) {
array_push ($selectedarray, $fArray2[0]);
}
else if ($key == 1) {
if (array_key_exists (1, $fArray2)) {
array_push ($selectedarray, $fArray2[1]);
}
}
}
return $selectedarray;
}
function moveToTrash ($table, $recordid) {
$oldfilename = 'data/' . $table . '/' . $recordid . '.txt';
$newfilename = 'data/trash/' . $table . '----' . $recordid . '.txt';
if (file_exists ($oldfilename)) {
//rename ($oldfilename, $newfilename);
}
}
//ARRAYS
function readArray ($filename, $delimiter){
$fArray1 = array();
if (file_exists($filename)) {
$String = file_get_contents ($filename);
if ($String !== "") {
$fArray1 = explode ($delimiter, $String);
}
}
return $fArray1;
}
function writeArray ($filename, $array, $delimiter){
$String = implode ($delimiter, $array);
//file_put_contents ($filename, $String);
}
function addNameToArray ($filename, $name, $delimiter) {
if (file_exists($filename)) {
$String = file_get_contents ($filename);
$fArray1 = explode ($delimiter, $String);
array_push ($fArray1, $name);
$fArray1 = array_unique ($fArray1);
sort ($fArray1);
$String = implode ($delimiter, $fArray1);
$String = preg_replace('/,+/', ',', $String);
//file_put_contents ($filename, $String);
}
}
function removeNameFromArray ($filename, $name, $delimiter) {
if (file_exists($filename)) {
$String = file_get_contents ($filename);
$fArray = explode ($delimiter, $String);
foreach ($fArray as $Id => $Item) {
$Item = trim ($Item);
if ($Item === $name) {
//unset ($fArray [$Id]);
}
}
array_values ($fArray);
sort ($fArray);
$String = implode ($delimiter, $fArray);
//file_put_contents ($filename, $String);
}
}
//Validate 'GET' value
function getFromQueryString ($label) {
$value = "";
if (isset ($_GET[$label])) {
$value = $_GET[$label];
if (specialChars($value) || strlen ($value) > 300) {
//Invalid input
$value = '';
}
}
return $value;
}
//Filter input text
function sanitizeFormInput($text) {
global $dl1, $dl2;
$text = trim($text);
$text = str_replace ($dl1, '', $text);
$text = str_replace ($dl2, '', $text);
return $text;
}
function showWords ($text) {
$fancytext = str_replace (',', ', ', $text);
$fancytext = ucwords (str_replace ('-', ' ', $fancytext));
return $fancytext;
}
//CHECK FOR DUPLICATE EMAILS
function checkForDuplicateEmail ($sendtoemail, $message) {
global $dl1, $dl2;
$error = false;
$emailarchive = readArray ('data/email-archive.txt', $dl1);
$emailentry = date ("Y-m-d") . $dl2 .$sendtoemail . $dl2 . $message . "\n";
if ( in_array ($emailentry, $emailarchive)) {
$error = true;
echo "<div class = 'error'>Message is a duplicate</div>";
}
else {
array_push ( $emailarchive, $emailentry);
$String = implode ($dl1, $emailarchive);
//file_put_contents ('data/email-archive.txt', $String);
}
return $error;
}
function randomString () {
$String = "";
$chars = "abcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen($chars);
for ($i = 0; $i < 7; $i++) {
$String .= $chars[rand(0, $size - 1)];
}
return $String;
}
function assignPostValuesToRecord ($postarray, $keys) {
//Assign values to record
$record = array();
foreach ($keys as $Id => $key) {
$record[$key] = "";
if (isset ($postarray[$key])) {
$record[$key] = sanitizeFormInput ($postarray[$key]);
}
}
return $record;
}
function saveToLog ($text) {
global $dl1, $dl2;
$currenttime = date ("h-i:sa");
$date = date ("Y-m-d");
$filename = 'data/log.txt';
$String = file_get_contents ($filename);
$String = $String . "\n\n " . $date . " " . $currenttime . " ". $text;
//file_put_contents ($filename, $String);
}
function formatDate ($inputdate) {
$returndate = '';
if (is_numeric (substr ($inputdate, 0,4))) {
//format yyyy/mm/dd
$month = substr ($inputdate, 5, 2);
$day = substr ($inputdate, 8,2);
$year = substr ($inputdate, 0, 4);
$returndate = $year . '-' . $month . '-' . $day;
}
else if (is_numeric (substr ($inputdate, 0, 2))) {
//Year is last mm/dd/yyyy
$month = substr ($inputdate, 0, 2);
$day = substr ($inputdate, 3,2);
$year = substr ($inputdate, 6, 4);
$returndate = $year . '-' . $month . '-' . $day;
}
else {
//default current date
$returndate = date('Y-m-d');
}
return $returndate;
}
function specialChars($str) {
return preg_match("/[^a-zA-Z0-9-:!?*@#$,\.\s]/", $str) > 0;
}
function notPhoneNumber($str) {
return preg_match('/[^0-9-\)\(\s]/', $str) > 0;
}
function getRecordIdsFromFolder ($folder) {
$Newarray = array();
$Array1 = scandir ($folder);
foreach ($Array1 as $Item1) {
if (substr ($Item1, 0, 1) !== '.') {
$Recordid = str_replace (".txt", "", $Item1);
$Recordid = str_replace ('.php', '', $Recordid);
$Recordid = str_replace ('.css', '', $Recordid);
$Recordid = trim ($Recordid);
array_push ($Newarray, $Recordid);
}
}
return $Newarray;
}
?>
functions.php ▾
<?php
function createRecordId ($name) {
$newname = "";
if ($name !== "") {
$newname = trim ($name);
$newname = str_replace (" " , "-", $newname);
$newname = strtolower ($newname);
$newname = preg_replace('/[^A-Za-z0-9-?!]/', '', $newname);
$newname = preg_replace('/-+/', '-', $newname);
}
return $newname;
}
function initializeRecord ($keys){
$record = array ();
foreach ($keys as $Id => $key) {
$record[$key] = "";
}
return ($record);
}
function readDatabaseRecord ($keys, $filename) {
global $dl1;
//Initialize record
$record = array();
foreach ($keys as $Id => $key) {
$record[$key] = "";
}
if ($filename && file_exists($filename)) {
$string = file_get_contents ($filename);
$fArray1= explode ($dl1, $string);
foreach ($keys as $Id => $key) {
if (array_key_exists ($Id, $fArray1)) {
$record [$key] = $fArray1[$Id];
}
}
}
return $record;
}
function writeDatabaseRecord ($record, $filename) {
global $dl1;
$String = implode ($dl1, $record);
file_put_contents ($filename, $String);
}
// Maps for table relationships
function addMapEntry ($map, $key1, $key2) {
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
$newentry = $key1 . $dl2 . $key2 . $dl2 . "\n";
array_push ($fArray1, $newentry);
$fArray1 = array_unique ($fArray1);
sort ($fArray1);
writeArray ($map, $fArray1, $dl1);
}
function removeMapEntries ($map, $key0, $key1) {
//Remove entries containing either or both key0 and key1
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Id => $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (0, $fArray2) && array_key_exists (1, $fArray2)) {
if ($key0 && $key1 ) {
if ( $fArray2[0] === $key0 && $fArray2[1] === $key1 ) {
unset ($fArray1 [$Id]);
}
}
else if (! $key0 && $key1 ) {
if ($fArray2[1] === $key1) {
unset ($fArray1 [$Id]);
}
}
else if ($key0 && !$key1) {
if ($fArray2[0] === $key0) {
unset ($fArray1 [$Id]);
}
}
}
}
writeArray ($map, $fArray1, $dl1);
}
function selectMapEntries ($map, $key0, $key1) {
global $dl1, $dl2;
$fArray1 = readArray ($map, $dl1);
//returns an array with selected key
global $dl1, $dl2;
$selectedarray = array();
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if (array_key_exists (1, $fArray2)) {
if ($key0 && !$key1 ) {
if ($fArray2[0] == $key0 ){
array_push ($selectedarray, $fArray2[1]);
}
}
else if (!$key0 && $key1) {
if ($fArray2[1] === $key1) {
array_push ($selectedarray, $fArray2[0]);
}
}
}
}
return $selectedarray;
}
function selectMapKey ($map, $key0, $key1) {
//returns an single value
global $dl1, $dl2;
$returnvalue = '';
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Id => $Item1) {
$fArray2 = explode ($dl2, $Item1);
if ( array_key_exists (1, $fArray2)) {
if (!$key0 && $key1) {
if ($fArray2[1] === $key1) {
$returnvalue = $fArray2[0];
break;
}
}
else if ($key0 && ! $key1) {
if ($fArray2[0] === $key0){
$returnvalue = $fArray2[1];
break;
}
}
}
}
return $returnvalue;
}
function extractFromMap($map, $key) {
//returns a new array of either the the first or second columns
global $dl1, $dl2;
$selectedarray = array();
$fArray1 = readArray ($map, $dl1);
foreach ($fArray1 as $Item1) {
$fArray2 = explode ($dl2, $Item1);
if ($key == 0) {
array_push ($selectedarray, $fArray2[0]);
}
else if ($key == 1) {
if (array_key_exists (1, $fArray2)) {
array_push ($selectedarray, $fArray2[1]);
}
}
}
return $selectedarray;
}
function moveToTrash ($table, $recordid) {
$oldfilename = 'data/' . $table . '/' . $recordid . '.txt';
$newfilename = 'data/trash/' . $table . '----' . $recordid . '.txt';
if (file_exists ($oldfilename)) {
rename ($oldfilename, $newfilename);
}
}
//ARRAYS
function readArray ($filename, $delimiter){
$fArray1 = array();
if (file_exists($filename)) {
$String = file_get_contents ($filename);
if ($String !== "") {
$fArray1 = explode ($delimiter, $String);
}
}
return $fArray1;
}
function writeArray ($filename, $array, $delimiter){
$String = implode ($delimiter, $array);
file_put_contents ($filename, $String);
}
function addNameToArray ($filename, $name, $delimiter) {
if (file_exists($filename)) {
$String = file_get_contents ($filename);
$fArray1 = explode ($delimiter, $String);
array_push ($fArray1, $name);
$fArray1 = array_unique ($fArray1);
sort ($fArray1);
$String = implode ($delimiter, $fArray1);
$String = preg_replace('/,+/', ',', $String);
file_put_contents ($filename, $String);
}
}
function removeNameFromArray ($filename, $name, $delimiter) {
if (file_exists($filename)) {
$String = file_get_contents ($filename);
$fArray = explode ($delimiter, $String);
foreach ($fArray as $Id => $Item) {
$Item = trim ($Item);
if ($Item === $name) {
unset ($fArray [$Id]);
}
}
array_values ($fArray);
sort ($fArray);
$String = implode ($delimiter, $fArray);
file_put_contents ($filename, $String);
}
}
//Validate 'GET' value
function getFromQueryString ($label) {
$value = "";
if (isset ($_GET[$label])) {
$value = $_GET[$label];
if (specialChars($value) || strlen ($value) > 300) {
//Invalid input
$value = '';
}
}
return $value;
}
//Filter input text
function sanitizeFormInput($text) {
global $dl1, $dl2;
$text = trim($text);
$text = str_replace ($dl1, '', $text);
$text = str_replace ($dl2, '', $text);
return $text;
}
function showWords ($text) {
$fancytext = str_replace (',', ', ', $text);
$fancytext = ucwords (str_replace ('-', ' ', $fancytext));
return $fancytext;
}
function assignPostValuesToRecord ($postarray, $keys) {
//Assign values to record
$record = array();
foreach ($keys as $Id => $key) {
$record[$key] = "";
if (isset ($postarray[$key])) {
$record[$key] = sanitizeFormInput ($postarray[$key]);
}
}
return $record;
}
function specialChars($str) {
return preg_match("/[^a-zA-Z0-9-:!?*,\.\s]/", $str) > 0;
}
function getRecordIdsFromFolder ($folder) {
$Newarray = array();
$Array1 = scandir ($folder);
foreach ($Array1 as $Item1) {
if (substr ($Item1, 0, 1) !== '.') {
$Recordid = str_replace (".txt", "", $Item1);
$Recordid = str_replace ('.php', '', $Recordid);
$Recordid = str_replace ('.css', '', $Recordid);
$Recordid = trim ($Recordid);
array_push ($Newarray, $Recordid);
}
}
return $Newarray;
}
?>
header.php ▾
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel= 'stylesheet' type='text/css' href= 'inc/style.css?v=2'>
<title>Accounts</title>
</head>
<body >
<div class = 'outerwrap <?php echo $pageid ; ?>'>
<div class = 'headerwrap'>
<a class = 'return' href = '../../accounts'>← Return</a><br><br>
<?php
echo "<br><br><img class = 'round' src = 'data/ralph-in-bag2.jpg' alt = 'Ralph in bag'>";
echo " <a href = 'index.php'><h1>Manage My Accounts</h1></a>";
$menuarray = array ( 'home', 'detailed-accounts', 'settings');
foreach ($menuarray as $item) {
if ($pageid === trim($item)) {
echo "<a class = 'menuitem current' href = 'index.php?page=" . $item . "'>" . ucwords (str_replace ("-", " ", $item )) . "</a>";
}
else {
echo "<a class = 'menuitem ' href = 'index.php?page=" . $item . "'>" . ucwords (str_replace ("-", " ", $item )) . "</a>";
}
}
?>
</div>
style.css ▾
body {
font-size: 16px;
margin: 0 auto;
font-family: "Arial", sans-serif;
font-size: 16px;
box-sizing: border-box;
color: black;
}
h1, h2, h3 {
text-align: center;
color: #186c99;
}
h1 {
margin-bottom: 5px;
}
h3, h4 {
color: #186c99;
margin: 5px auto;
}
a {
text-decoration: none;
color:#652c77;
}
a:hover {
color: darkmagenta;
}
.centered {
text-align: center;
}
.round {
border-radius: 50%;
border: 1px solid #bbb;
width: 160px;
}
/** Outerwrap */
.outerwrap {
display: block;
margin: auto;
max-width: 100%;
width: 1300px;
box-sizing: border-box;
text-align: center;
}
/** Header */
.headerwrap {
text-align: center;
}
/** Menu */
a.menuitem {
color: #652c77;
padding: 5px;
border: 1px solid #bbb;
margin: 5px;
display: inline-block;
}
.current {
background-color: #ddd;
}
/** Main */
main {
text-align: left;
}
/** Columns */
.content-column, .sidebar-column, .half-column, .column1, .column2, .column3 , .gridcolumn {
display: inline-block;
text-align: left;
box-sizing: border-box;
vertical-align: top;
max-width: 100%;
}
.column1 {
width: 300px;
}
.column2 {
width: 100px;
text-align: right;
margin: 0 10px;
}
.column3 {
width: 200px;
}
.content-column {
width: 80%;
padding: 0;
}
.sidebar-column {
width: 20%;
margin-top: 60px;
}
.half-column , .half-column-1, .half-column-2{
width: 50%;
padding: 20px;
}
.box {
display: block;
box-sizing: border-box;
max-width: 100%;
padding-top: 30px;
background-color: #eee;
padding: 10px;
margin: 5px;
}
a.gridcolumn {
width: 200px;
margin: 2px 10px 0 0;
}
.detailed-accounts, .transactions {
font-size: 14px;
}
/** Forms and buttons */
a.adminbutton, .submitbutton {
display: block;
margin: 10px auto;
padding: 5px 8px;
font-weight: normal;
text-align: center;
color: white;
width: 100px;
}
a.adminbutton {
background-color: #5a5078;
}
.submitbutton, .pink-button {
background-color: pink;
color: black;
margin: 10px 0;
}
textarea, input {
max-width: 100%;
vertical-align: bottom;
box-sizing: border-box;
border: 1px solid #bbb;
background-color: #eee;
padding: 5px;
}
input {
max-width: 400px;
}
input[type=checkbox], input[type=radio] {
max-width: 20px;
padding: 0;
margin: 5px;
}
.error {
color: red;
text-align: center;
}
footer {
margin-top: 100px;
}
ACCOUNTS/data
accounts ▾
americat-express-platinum.txt
big-stretch-gym.txt
catflix.txt
catstack.txt
chasetail-national-bank.txt
chasetail-spendit-card.txt
doubledebt-credit-card.txt
fastdriver-car-insurance.txt
felinia-gas-and-electric-co.txt
felinia-internet.txt
felinia-savings-and-loan.txt
felinia-water-dept.txt
furniturescratchers-forum.txt
furrbank.txt
meetamate-services.txt
meowmore-cellular.txt
misskittycatmailcom.txt
misskittymeowmailcom.txt
mousetv.txt
spendazon.txt
the-nip-shoppe.txt
wealthy-cats.txt
xxx.txt
big-stretch-gym.txt
catflix.txt
catstack.txt
chasetail-national-bank.txt
chasetail-spendit-card.txt
doubledebt-credit-card.txt
fastdriver-car-insurance.txt
felinia-gas-and-electric-co.txt
felinia-internet.txt
felinia-savings-and-loan.txt
felinia-water-dept.txt
furniturescratchers-forum.txt
furrbank.txt
meetamate-services.txt
meowmore-cellular.txt
misskittycatmailcom.txt
misskittymeowmailcom.txt
mousetv.txt
spendazon.txt
the-nip-shoppe.txt
wealthy-cats.txt
xxx.txt
categories.txt ▾
bank,email,media,retail,test,utilities category-account-map.txt ▾
bank#%#americat-express-platinum#%#
%!%bank#%#chasetail-national-bank#%#
%!%bank#%#chasetail-spendit-card#%#
%!%bank#%#doubledebt-credit-card#%#
%!%bank#%#felinia-savings-and-loan#%#
%!%bank#%#furrbank#%#
%!%bank-and-credit-cards#%#chasetail-national-bank#%#
%!%bank-and-credit-cards#%#chasetail-spendit-card#%#
%!%bank-and-credit-cards#%#doubledebt-credit-card#%#
%!%bank-and-credit-cards#%#felinia-savings-and-loan#%#
%!%bank-and-credit-cards#%#furrbank#%#
%!%bank-and-credit-cards#%#furrbank-and-credit-cards#%#
%!%bank-and-credit-cards#%#test#%#
%!%email#%#misskittycatmailcom#%#
%!%email#%#misskittymeowmailcom#%#
%!%media#%#catflix#%#
%!%media#%#catstack#%#
%!%media#%#furniturescratchers-forum#%#
%!%media#%#grabfin#%#
%!%media#%#meetamate-services#%#
%!%media#%#mousetv#%#
%!%media#%#wealthy-cats#%#
%!%media#%#xxx#%#
%!%payment-account#%#americancat-platinum#%#
%!%payment-account#%#catflix#%#
%!%payment-account#%#doubledebt-credit-card#%#
%!%payment-account#%#felinia-gas-and-electric-co#%#
%!%payment-account#%#felinia-internet#%#
%!%payment-account#%#felinia-water-dept#%#
%!%payment-account#%#mousetv#%#
%!%payment-source#%#chasetail-national-bank#%#
%!%payment-source#%#felinia-savins-and-loan#%#
%!%retail#%#big-stretch-gym#%#
%!%retail#%#spendazon#%#
%!%retail#%#the-nip-shoppe#%#
%!%utilities#%#fastdriver-car-insurance#%#
%!%utilities#%#felinia-gas-and-electric-co#%#
%!%utilities#%#felinia-internet#%#
%!%utilities#%#felinia-water-dept#%#
%!%utilities#%#meowmore-cellular#%#
ralph-in-bag2.jpg ▾
��� JFIF �� C !"$"$�� C�� "