Event Calendar 1
A flat file database can be used to create an event calendar. A single table, the 'events' table is used, along with a single join array, which joins events with dates.
PHP date functions are used to determine the number of days in each month and the weekdays for each date. The calendar shows the current year and the previous and next years. when the user selects previous or next, that year becomes the new current year, so that future and past events can be accessed.

PHP date functions are used to determine the number of days in each month and the weekdays for each date. The calendar shows the current year and the previous and next years. when the user selects previous or next, that year becomes the new current year, so that future and past events can be accessed.

View Code
Top-level folder:
admin.php ▾
<?php
session_start();
include ("inc/db-functions.php");
$adminpage = 'control-panel';
if (isset ($_GET['adminpage'])) {
$adminpage = $_GET['adminpage'];
}
include ("inc/admin-header.php");
$loggedin = false;
if (isset($_SESSION['admin'])) {
if ( $_SESSION['admin'] === 'thenipshoppe') {
$loggedin = true;
if (file_exists ("admin-pages/". $adminpage . ".php") ){
include ("inc/convert-markdown.php");
echo "<div class = 'adminwrap'>";
echo "<main class = 'admin'>";
include ("admin-pages/" . $adminpage . ".php");
echo "</main></div>";
}
else {
echo "This admin page does not exist";
}
}
else {
echo "You must be logged in to view this page: <a href = 'login.php'>Log In</a>";
}
}
else {
echo "You must be logged in to view this page: <a href = 'login.php'>Log In</a>";
}
include ("inc/footer.php");
?>
index.php ▾
<?php
session_start();
include ("inc/db-functions.php");
$loggedin = false;
if (isset($_SESSION['admin'])) {
if ( $_SESSION['admin'] === 'thenipshoppe') {
$loggedin = true;
}
}
$pageid = "calendar";
if (isset($_GET['page'])) {
$pageid = $_GET['page'];
}
include ("inc/header.php");
if (file_exists ("pages/". $pageid . ".php") ){
echo "<main>";
include ("pages/" . $pageid . ".php");
echo "</main>";
}
else {
echo "This page does not exist<br><br>";
}
include ("inc/footer.php");
?>
login.php ▾
<?php
session_start();
$loggedin = false;
$username = $password = "";
$pageid = 'login';
include ("inc/header.php") ;
echo "<main>";
if ($_SERVER ["REQUEST_METHOD"] === "POST" ) {
// Checks if the user is trying to log in
if (isset($_POST['username'])) {
$username = filter_input(INPUT_POST, "username", FILTER_SANITIZE_STRING) ;
}
if (isset($_POST['password'])) {
$password = filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING) ;
}
if ($username === "nipusername" && $password === "nippassword") {
$_SESSION['admin'] = 'thenipshoppe';
$loggedin = true;
echo "<h2>You are now logged in.</h2>";
}
}
if ($loggedin === false) {
?>
<h1>Log In</h1>
<h2>Please enter your username and password</h2>
<form method="post" action="login.php">
<h3><b>Username:</b>
<input type="text" name="username" value= 'nipusername' /></h3><br>
<h3 ><b>Password:</b>
<input type="password" name="password" value='nippassword' /></h3><br>
<input class = 'pinkbutton' type="submit" value = "Enter" name = 'submit'>
</form>
<?php
}
echo "</main>";
include ("inc/footer.php");
?>
logout.php ▾
<?php
session_start();
session_unset();
session_destroy();
$pageid = 'logout';
$loggedin = false;
include ("inc/header.php");
echo "You are now logged out. ";
echo "<br>";
include ("inc/footer.php");
?>
admin-pages folder:
add-update-event.php ▾
<?php
$month = "01";
$year = date ("Y");
$day = date ("d");
//CHECK FOR INPUT DATES
if (isset ($_GET["year"])){
$year = trim ($_GET["year"]);
}
$monthnum = 1;
$eventid = "";
if (isset ($_GET["event"])){
$eventid = filter_input(INPUT_GET, "event", FILTER_SANITIZE_STRING) ;
}
$eventrecord = readDatabaseRecord("events", $eventid);
$map = "data/maps/date-event-map.txt";
$datearray = selectMapEntries ($map, "", $eventid);
$datestring = implode (" ", $datearray);
$copyflag = "";
if (isset ($_GET['copyflag'])) {
$eventid = "";
}
//RETRIEVE FORM INPUT
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
//ASSIGN INPUT TO RECORD FIELDS
foreach ($dbtables["events"] as $label) {
if (isset ($_POST[$label])) {
$eventrecord [$label] = trim($_POST[$label]);
}
}
if (isset ($_POST['submit-info'])) {
if ($eventrecord['category'] === "") {
echo "<div class = 'error' >Choose Class or Event</div><br>";
}
else {
if ($eventid === "" ) {
$eventid = createRecordKey ( "events", $eventrecord['title']);
}
if ($eventid !== "") {
$eventrecord['html-content'] = convertTextToHTML($eventrecord['markdown-content']);
writeDatabaseRecord ("events", $eventrecord, $eventid);
}
}
}
if (isset ($_POST['submit-dates'])) {
$datearray = array();
if (isset ($_POST['datearray'])) {
$datearray = $_POST['datearray'];
}
if ($eventid !== "") {
removeEventFromMapByYear ($map, "", $eventid, $year);
foreach ($datearray as $item) {
addMapEntry ($map, $item, $eventid) ;
}
sortMap ($map);
$datearray = selectMapEntries ($map, "", $eventid);
$datestring = implode (" ", $datearray);
}
}
if (isset ($_POST['submit-image'])) {
$folder = "calendar-thumbnails";
$newname = "image";
$newimagename = "";
if (isset ($_POST['newimagename'])) {
$newimagename = $_POST['newimagename'];
include ("inc/uploaded-image.php");
}
}
}
?>
<div class = 'content-column'>
<div class = 'half-column left'>
<div class = 'adminbox'>
<?php
if ($eventid === "") {
echo "<h2>Add Event</h2>";
}
else {
echo "<h2> Edit Event</h2>";
}
include ("inc/event-form.php");
?>
<br><br><br>
</div>
<div class = 'adminbox'>
<h2>Upload Image</h2>
<form action="admin.php?adminpage=add-update-event&event=<?php echo $eventid ;?>" method="post" enctype="multipart/form-data">
<input type="file" name="file" >
<br><h3>Provide a name for this image: </h3><input type = 'text' name = 'newimagename' />
<br><input class = 'submitbutton' type = 'submit' name ="submit-image" value = 'Upload'>
</form>
</div>
<?php
echo "<br>";
include ("inc/media-library.php");
echo "<br><br>";
?>
</div><div class = 'half-column'>
<h2>Select Dates</h2>
<?php include ("inc/select-event-dates.php"); ?>
</div>
</div><div class = 'sidebar-column'>
<?php
echo "<a class = 'pinkbutton' href = 'index.php?page=calendar'>View Calendar</a>";
echo "<a class = 'pinkbutton' href = 'admin.php?adminpage=display-all-events'>Display all events</a>";
if ($eventid !== "" && file_exists ("data/events/" . $eventid . ".txt")){
echo "<a class = 'pinkbutton' href = 'admin.php?adminpage=add-update-event'>Add Event</a>";
echo "<a class = 'pinkbutton' href = 'admin.php?page=calendar-event&event=" . $eventid . "'>Display Event</a>";
echo "<a class = 'pinkbutton' href = 'admin.php?adminpage=remove-event&event=" . $eventid . "'> Remove Event</a>";
echo "<a class = 'pinkbutton' href = 'admin.php?adminpage=add-update-event&event=" . $eventid . "©flag=copy'>Copy Event</a>";
}
?>
</div>
display-all-events.php ▾
<?php
$array1 = scandir ("data/events");
foreach ($array1 as $item1) {
if ($item1 !== "." && $item1 !== "..") {
$eventid = str_replace (".txt", "", $item1);
$eventrecord = readDatabaseRecord ("events", $eventid);
echo "<br><a href = 'admin.php?adminpage=add-update-event&event=" . $eventid . "'>" . $eventrecord['title'] . "</a>";
}
}
remove-event.php ▾
<?php
if (isset ($_GET['event'])) {
$eventid = $_GET['event'];
}
$removeflag = false;
if ($_SERVER ["REQUEST_METHOD"] == "POST" ) {
if (isset($_POST ['removeflag'])) {
if ($_POST['removeflag'] === "REMOVE") {
//Remove this event from event array
$map = "data/maps/date-event-map.txt";
removeFromMap ($map, "", $eventid);
//rename ("data/events/" . $eventid . ".txt", "data/trash/" . $eventid . ".txt");
$removeflag = true;
}
}
}
?>
<div class = 'content-column'>
<h3>Remove Event: <?php echo $eventid; ?></h3><br>
<?php
if ($removeflag === false) {
?>
<form method = 'post' action = 'admin.php?adminpage=remove-event&event=<?php echo $eventid; ?>'>
<h3>Are you sure you want to move <?php echo $eventid ; ?> 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 "This Text Block has been removed";
}
?>
</div><div class = 'sidebar-column'>
<a class = 'pinkbutton' href = 'index.php?page=calendar'>Return to Calendar</a><br>
<a class = 'pinkbutton' href = 'index.php?page=display-all-events'>Display All Events</a><br>
</div>
data/events folder:
caturday-celebration.txt ▾
Caturday Celebration%%%%%%%%%%%%%%%%%%%%%%%%%%%
fantastic-fridays.txt ▾
Fantastic Fridays%%%Join us every Friday evening from 5pm - 7pm to enjoy samples of our newest inventory as well as tasty treats from our test kitchens. A great way to unwind after a hard week and ajust your cattitude for the weekend!%%%Join us every Friday evening from 5pm - 7pm to enjoy samples of our newest inventory as well as tasty treats from our test kitchens. A great way to unwind after a hard week and ajust your cattitude for the weekend!%%%%%%5pm - 9pm%%%%%%%%%events%%%%%%
kitten-festival.txt ▾
Kitten Festival%%%Special event for our little ones. Lots of kKitten-friendly nip served. Whisker painting and tail chasing contests - fun for all ages!%%%Special event for our little ones. Lots of kKitten-friendly nip served. Whisker painting and tail chasing contests - fun for all ages!%%%%%%11am - 4pm%%%%%%%%%events%%%%%%
learn-to-grill-chipmunk.txt ▾
Learn to Grill Chipmunk%%%Chef Boris is returning this spring with a new series.
<br>
<br>$125/5 classes, Monday evenings in Feb and March, 2020.%%%Chef Boris is returning this spring with a new series.
$125/5 classes, Monday evenings in Feb and March, 2020.%%%%%%5pm- 7pm%%%Chef Boris of the Small Game Grille is back!%%%%%%classes%%%%%%
nippy-christmas-cookies.txt ▾
Nippy Christmas Cookies%%%Learn how to make Christmas cookies infused with Santaland Nip. Your holidays will sparkle when your family and guests enjoy these fabulous treats!<br>
<br>$5/ 3 Sessions%%%Learn how to make Christmas cookies infused with Santaland Nip. Your holidays will sparkle when your family and guests enjoy these fabulous treats!
$5/ 3 Sessions%%%%%%5pm - 7pm%%%Holiday Favorites%%%%%%classes%%%%%%
santa-claws-visits.txt ▾
Santa Claws Visits%%%Santa Claws is making a special trip to the Nip Shoppe on Saturday, December 21. Bring the kittens!%%%Santa Claws is making a special trip to the Nip Shoppe on Saturday, December 21. Bring the kittens!%%%%%%Saturday, Deceber 4, 11am - 3pm%%%Direct from the North Pole!%%%%%%events%%%%%%
inc folder:
admin-header.php ▾
<?php
$section = "";
if (isset ($_GET['section'])) {
$section = $_GET['section'];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>'The Nip Shoppe'</title>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Elsie" rel="stylesheet">
<link rel= 'stylesheet' type='text/css' href= 'inc/style.css'>
</head>
<body>
<div class = 'header'>
<a class = 'menuitem' href = 'index.php?page=about'>About</a>
<a class = 'site-title' href = 'index.php'>The Nip Shoppe</a>
<a class = 'menuitem' href = 'index.php?page=contact'>Contact</a>
</header>
convert-markdown.php ▾
<?php
/*Copyright (c) 2019, Susan V. Rodgers, Lila Avenue, LLC, lilaavenue@gmail.com
This code is part of the LilaWorks Content Management System
*/
function convertTextToHTML ($text) {
$newstring0 = $text;
$newstring0 = str_replace (PHP_EOL, "<br>", $newstring0);
//Hoizontal Rule - 4 underscores
$newstring0 = str_replace ("____", "<hr>", $newstring0);
//Blockquote
if (strpos ($newstring0,">") !== false) {
if (strpos ($newstring0, "\>" ) != strpos ($newstring0, ">") - 1){
$newstring1 = convertQuoteToHTML($newstring0);
$newstring0 = $newstring1;
}
}
//H5
if (strpos ($newstring0,"##### ") !== false ) {
$newstring1 = convertHeadersToHTML("##### ", "<h5>", "</h5>", $newstring0);
$newstring0 = $newstring1;
}
//H4
if (strpos ($newstring0,"#### ") !== false ) {
$newstring1 = convertHeadersToHTML("#### ", "<h4>", "</h4>", $newstring0);
$newstring0 = $newstring1;
}
//H3
if (strpos($newstring0, "### ") !== false) {
$newstring1 = convertHeadersToHTML("### ", "<h3>", "</h3>", $newstring0);
$newstring0 = $newstring1;
}
//H2
if (strpos ($newstring0,"## ") !== false ) {
$newstring1 = convertHeadersToHTML("## ", "<h2>", "</h2>", $newstring0);
$newstring0 = $newstring1;
}
//H1
if (strpos ($newstring0,"# ") !== false) {
$newstring1 = convertHeadersToHTML("# ", "<h1>", "</h1>", $newstring0);
$newstring0 = $newstring1;
}
//Bold and Italic
if (strpos ($newstring0,"***") !== false) {
$newstring1 = convertInLineToHTML("***", "<b><i>", "</i></b>", $newstring0);
$newstring0 = $newstring1;
}
//Alternate Bold and Italic
if (strpos ($newstring0,"___") !== false) {
$newstring1 = convertInLineToHTML("___*", "<b><i>", "</i></b>", $newstring0);
$newstring0 = $newstring1;
}
//image
if (strpos ($newstring0, "!") !== false) {
$newstring1 = convertImagesToHTML($newstring0);
$newstring0 = $newstring1;
}
//link
if (strpos ($newstring0, "[") !== false) {
if (strpos ($newstring0, "\[" ) != strpos ($newstring0, "[") - 1){
$newstring1 = convertLinksToHTML($newstring0);
$newstring0 = $newstring1;
}
}
//unordered list
if (strpos ($newstring0,"* ") !== false) {
$newstring0 = convertListToHTML ($newstring0) ;
}
//Bold
if (strpos ($newstring0,"**") !== false) {
$newstring1 = convertInLineToHTML("**", "<b>", "</b>", $newstring0);
$newstring0 = $newstring1;
}
//Alternate Bold
if (strpos ($newstring0,"__") !== false) {
$newstring1 = convertInLineToHTML("__*", "<b>", "</b>", $newstring0);
$newstring0 = $newstring1;
}
//Italics
if (strpos ($newstring0,"*") !== false) {
if (strpos ($newstring0, "\*" ) != strpos ($newstring0, "*") - 1){
$newstring0 = convertInLineToHTML("*", "<i>", "</i>", $newstring0);
}
}
//Alternate Italics
//if (strpos ($newstring0,"_") !== false) {
// if (strpos ($newstring0, "\_" ) != strpos ($newstring0, "_") - 1){
// $newstring0 = convertInLineToHTML("_", "<i>", "</i>", $newstring0);
// }
//}
//numeric list
if (preg_match ('/[0-9]\./', $newstring0) || preg_match ('/[0-9][0-9]\./', $newstring0)) {
$newstring0 = convertNumListToHTML ($newstring0) ;
}
$newstring = $newstring0;
$newstring = str_replace ("ENDCODEBLOCK", "</pre></div>", $newstring);
$newstring = str_replace ("CODEBLOCK", "<div class = 'codeblock'><pre>", $newstring);
$newstring = str_replace ("ENDQUOTE", "</blockquote>", $newstring);
$newstring = str_replace ("QUOTE", "<blockquote>", $newstring);
$newstring = str_replace ("ENDCAPTION", "</div>", $newstring);
$newstring = str_replace ("CAPTION", "<div class = 'caption'>", $newstring);
//Justify Images
$newstring = str_replace ("LEFT", "", $newstring);
$newstring = str_replace ("RIGHT", "", $newstring);
//Start new line after image
$newstring = str_replace ("BREAK", "<div style = 'clear: both; float: none;'></div>", $newstring);
//Remove extra spaces between list items
$newstring = str_replace ("</li>" . "<br>", "</li>", $newstring);
//COLUMNS
$newstring = str_replace ("3COL3", "</div><div class = 'third-column'>", $newstring);
$newstring = str_replace ("3COL2", "</div><div class = 'third-column'>", $newstring);
$newstring = str_replace ("3COL1", "<div class = 'third-column'>", $newstring);
$newstring = str_replace ("2COL2", "</div><div class = 'half-column'>", $newstring);
$newstring = str_replace ("2COL1", "<div class = 'half-column'>", $newstring);
$newstring = str_replace ("ENDCOL", "</div>", $newstring);
//REMOVE EXTRA LINE BREAKS
$newstring = str_replace ("</h1><br>", "</h1>", $newstring);
$newstring = str_replace ("</h2><br>" , "</h2>", $newstring);
$newstring = str_replace ("</h3><br>" ,"</h3>", $newstring);
$newstring = str_replace ("</h4><br>" ,"</h4>", $newstring);
$newstring = str_replace ("</h5><br>" ,"</h5>", $newstring);
$newstring = str_replace ("<hr><br>" ,"<hr>", $newstring);
$newstring = str_replace ("</div><br>" ,"</div>", $newstring);
$newstring = str_replace ("\\", "", $newstring);
return $newstring;
}
function convertInlineToHTML($markdown, $htmlstart, $htmlend, $string) {
$newstring = "";
$array1 = explode ($markdown, $string);
$flag = 0;
foreach ($array1 as $id => $item) {
if ($flag === 0) {
$newstring = $newstring . $item;
$flag = 1;
}
else {
$newstring = $newstring . $htmlstart . $item . $htmlend;
$flag = 0;
}
}
return $newstring;
}
function convertHeadersToHTML ($markdown, $htmlstart, $htmlend, $string) {
$newstring = "";
$array1 = explode ("<br>", $string);
$array2 = $array1;
foreach ($array1 as $id => $item1) {
$item1 = trim ($item1);
$pos0 = strpos ($item1, $markdown);
if ($pos0 === 0) {
$newitem = str_replace ($markdown, $htmlstart, $item1);
$newitem = $newitem . $htmlend;
$array2[$id] = $newitem;
}
}
$newstring = implode ("<br>", $array2);
return $newstring;
}
function convertImagesToHTML($text) {
$newstring = "";
$array1 = explode ("!", $text);
$array2 = $array1;
foreach ($array1 as $id => $item) {
$item = trim ($item);
$newitem = $item;
if ($id === 0) {
//beginning of string
$newitem = $item;
}
else if (strpos ($item, "[") !== 0) {
//regular exclamation point, not image
$newitem = "!" . $item;
}
else {
$newimagefield = "";
$lastpos = 0;
$pos1 = strpos ($item, "[");
$pos2 = strpos ($item, "]");
$pos3 = strpos ($item, "(");
$pos4 = strpos ($item, ")");
//echo "HERE" . $pos1 . " " . $pos2 . " " . $pos3 . " " . $pos4;
$altlength = $pos2 - $pos1;
$srclength = $pos4 - $pos3;
$alt = substr ($item, $pos1+1 , $altlength-1);
$src = substr ($item, $pos3+1, $srclength-1);
if (strpos ($item, "RIGHT")!== false) {
$newimagefield = '<img src = "' . $src . ' " alt = " ' . $alt . '" class = "image-right" />';
}
else if (strpos ($item, "LEFT")!== false) {
$newimagefield = '<img src = "' . $src . ' " alt = " ' . $alt . '" class = "image-left" />';
}
else {
$newimagefield = '<img src = "' . $src . ' " alt = " ' . $alt . '" />';
}
$newitem = $newimagefield . substr ($item, $pos4+1);
$newitem = str_replace ("LEFT", "", $newitem);
$newitem = str_replace ("RIGHT", "", $newitem) ;
}
$newstring = $newstring . $newitem;
}
return $newstring;
}
function convertLinksToHTML($text){
$newstring = "";
$array1 = explode("[", $text);
foreach ($array1 as $id => $item) {
if ($id === 0) {
$newitem = $item;
}
else {
$linkfield = "";
$pos1 = 0;
$pos2 = strpos ($item, "]");
$pos3 = strpos ($item, "(");
$pos4 = strpos ($item, ")");
$namelength = $pos2;
$hreflength = $pos4 - $pos3;
$name = substr ($item, 0 , $namelength);
$href = substr ($item, $pos3+1, $hreflength -1);
$linkfield = "<a href = '" . $href . "'>" . $name . "</a>";
//remove markup for image and replace with html
$newitem = $linkfield . substr ($item, $pos4+1);
}
$newstring = $newstring . $newitem;
}
return $newstring;
}
function convertListToHTML ($string) {
//converts unordered list to html
$newstring = "";
$array1 = explode ("<br>", $string);
$array2 = $array1;
$endflag = true;
$startflag = false;
foreach ($array1 as $id => $item1) {
$item1 = trim ($item1);
$pos0 = strpos ($item1, "* ");
//Markdown character starts the line
if ($pos0 === 0) {
$newitem = substr ($item1, 2);
$newitem = "<li>" . $newitem . "</li>";
if ($startflag === false) {
//first list item
$newitem = "<ul>" . $newitem;
$startflag= true;
$endflag = false;
$array2[$id] = $newitem;
}
//continuing list item
$array2[$id] = $newitem;
}
//not list item
else if ($startflag === true) {
if ($item1 !== "" ) {
//this is the line following the last list line
$array2[$id] = "</ul>" . $item1;
$endflag = true;
$startflag = false;
}
}
}
$newstring = implode ("<br>", $array2);
if ($endflag === false) {
$newstring = $newstring ."</ul>";
}
return $newstring;
}
function convertNumListToHTML ($string) {
//converts unordered list to html
$newstring = "";
$array1 = explode ("<br>", $string);
$array2 = $array1;
$endflag = true;
$startflag = false;
foreach ($array1 as $id => $item1) {
$item1 = trim ($item1);
//check is line starts with 1 or 2 digit number followed by a period
if (is_numeric (substr ($item1, 0, 1)) && (substr ($item1, 1, 1) === "." || substr($item1, 2, 1) === ".")) {
//this line part of numbered list
$pos1 = strpos ($item1, ".");
//remove characters up to first period
$newitem = substr ($item1, $pos1 + 1);
$newitem = "<li>" . $newitem;
$newitem = $newitem . "</li>";
if ($startflag === false) {
//first list item
$newitem = "<ol>" . $newitem;
$startflag= true;
$endlfag = false;
$array2[$id] = $newitem;
}
else {
//continuing list item
$array2[$id] = $newitem;
}
}
//not list item
else if ($startflag === true) {
if ($item1 !== ""){
//this is the line following the last list line
$array2[$id] = "</ol>" . $array2[$id];
$newstring = $newstring . "</or>". $item1;
$endflag = true;
$startflag = false;
}
}
}
$newstring = implode ("<br>", $array2);
if ($endflag === false && $startflag === true) {
$newstring = $newstring ."</ol>";
}
return $newstring;
}
function convertQuoteToHTML ( $string) {
$newstring = "";
$array1 = explode ("<br>", $string);
$array2 = $array1;
$closingtagadded = false;
$startingtagadded = false;
foreach ($array1 as $id => $item1) {
$newitem = "";
$item1 = trim ($item1);
$pos0 = strpos ($item1, ">");
$item1 = str_replace (">", "", $item1);
//Markdown character starts the line
if ($pos0 === 0) {
if ($startingtagadded === false) {
$newitem = "<blockquote>" . $item1;
$startingtagadded = true;
$closingtagadded = false;
}
$array2[$id] = $newitem;
}
else if ($closingtagadded === false) {
//check if this is the line following the last list line
if ($startingtagadded === true) {
$array2[$id] = "</blockquote>" . $array2[$id];
$closingtagadded = true;
$startingtagadded = false;
}
}
}
$newstring = implode ("<br>", $array2);
if ($closingtagadded === false && $startingtagadded === true) {
$newstring = $newstring . "</blockquote>" ;
}
return $newstring;
}
function convertHorizontalRuleToHTML ($newstring0) {
$newstring = "";
$array1 = explode ("<br>", $newstring0);
$array2 = $array1;
foreach ($array1 as $id => $item) {
$item = trim ($item);
$pos1 = strpos ($item, "______");
if ($pos1 !== false ) {
$array2[$id] = "<hr>";
}
}
$newstring = implode ("<br>", $array2);
$newstring = str_replace ("<br />" . "</li>", "</li>", $newstring);
return $newstring;
}
?>
db-functions.php ▾
<?php
//READ INDEX TABLES
$dl1 = "%%%";
$dl2 = "%#%";
$dl3 = "$$$";
$dbtables = array (
"events" => array ("title", "html-content", "markdown-content", "thumbnail", "time", "description", "image", "category", "dates", "background-color")
);
function checkForDelimiters ($array) {
$error = false;
global $dl1, $dl2;
foreach ($array as $item) {
if (! is_array($item)) {
if (strpos ($item, $dl1) !== false || strpos($item, $dl2) !== false) {
echo "<div class = 'error'>Invalid Characters - cannot include " . $dl1 . " or " . $dl2 . "</div>";
$error = true;
}
}
}
return $error;
}
function createRecordKey ($table, $newname) {
$newkey = "";
if ($newname === '') {
echo "<div class = 'error'>Missing Name</div>";
}
else {
if (strlen ($newname) > 50) {
echo "<div class = 'error'>Title must be less than 50 characters</div>";
}
else {
$newkey = str_replace(" ", "-", $newname);
$newkey = strtolower ($newkey);
$newkey = preg_replace('/[^\A-Za-z0-9-]+/', '', $newkey);
if ($newkey === "") {
echo "<div class = 'error'>Invalid Record Name</div>";
}
else {
//REMOVE MULTIPLE DASHES
$newkey = preg_replace('/-+/', '-', $newkey);
// CHECK THAT THIS RECORD DOESN'T ALREADY EXIST
$filename = "data/" . $table . "/" . $newkey . ".txt";
if (file_exists ($filename)) {
echo "<div class = 'error'>record with this name already exists</div>";
}
}
}
}
return $newkey;
}
function createKey ($name) {
if ($name !== "") {
$newname = str_replace (" " , "-", $name);
$newname = strtolower ($newname);
$newname = preg_replace('/[^\A-Za-z0-9-]+/', '', $newname);
if ($newname === "") {
echo "<div class = 'error'>Invalid node name</div>";
}
}
return $newname;
}
function readDatabaseRecord($table, $recordid) {
//read a record in a multi-record table
global $dbtables;
global $dl1, $dl2;
//INITIALIZE TABLE TO EMPTY
$record = array();
foreach ($dbtables[$table] as $label) {
$record[$label] = "";
}
if ($recordid !== "") {
$filename = "data/" . $table . "/" . $recordid . ".txt";
if (file_exists($filename)) {
$string = file_get_contents ($filename);
$array1= explode ($dl1, $string);
foreach ($dbtables[$table] as $id => $label) {
$record[$label] = "";
if (array_key_exists ($id, $array1)) {
$record [$label] = $array1[$id];
}
}
}
}
return $record;
}
function readDatabaseRecord2($table) {
//read a record in a single-record table
global $dbtables;
global $dl1, $dl2;
//INITIALIZE TABLE TO EMPTY
$record = array();
foreach ($dbtables[$table] as $label) {
$record[$label] = "";
}
$filename = "data/" . $table . ".txt";
if (file_exists($filename)) {
$string = file_get_contents ($filename);
$array1= explode ($dl1, $string);
foreach ($dbtables[$table] as $id => $label) {
$record[$label] = "";
if (array_key_exists ($id, $array1)) {
$record [$label] = $array1[$id];
}
}
return $record;
}
}
function writeDatabaseRecord ($table, $record, $recordid) {
global $dl1, $dl2;
//print_r ($record);
$filename = "data/" . $table . "/" . $recordid . ".txt";
$newstring = implode ($dl1, $record);
//file_put_contents ($filename, $newstring);
}
function writeDatabaseRecord2 ($table, $record) {
global $dl1, $dl2;
$filename = "data/" . $table . ".txt";
$newstring = implode ($dl1, $record);
//file_put_contents ($filename, $newstring);
}
function writeDatabaseRecord3 ($record, $filename) {
global $dl1, $dl2;
//print_r ($record);
$newstring = implode ($dl1, $record);
//file_put_contents ($filename, $newstring);
}
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){
global $dl1;
$array = array();
if (file_exists($filename)) {
$string = file_get_contents ($filename);
if ($string !== "") {
$array = explode ($dl1, $string);
}
}
return $array;
}
function writeArray ($filename, $array){
global $dl1;
$string = implode ($dl1, $array);
//file_put_contents ($filename, $string);
}
function removeNameFromArray ($filename, $name) {
global $dl1;
if (file_exists($filename)) {
$string = file_get_contents ($filename);
$array = explode ($dl1, $string);
foreach ($array as $id => $item) {
if ($item === $name) {
unset ($array [$id]);
}
}
$string = implode ($dl1, $array);
//file_put_contents ($filename, $string);
}
}
function replaceNameInArray ($array, $oldname, $newname) {
global $dl1;
$filename = "data/" . $array . ".txt";
$string = file_get_contents ($filename);
$array = explode ($dl1, $string);
foreach ($array as $id => $item) {
if ($item === $oldname) {
$array[$id] = $newname;
}
}
$string = implode ($dl1, $array);
//file_put_contents ($filename, $string);
}
//JOIN MAPS
function addMapEntry ($map, $key1, $key2) {
global $dl1, $dl2;
$mapstring = file_get_contents ($map);
$newentry = $key1 . $dl2 . $key2 . $dl2 . "\n";
$mapstring = $mapstring . $dl1 . $newentry;
$mapstring = trim ($mapstring, $dl1);
$maparray = explode ($dl1, $mapstring);
array_unique ($maparray);
$mapstring = implode ($dl1, $maparray);
//file_put_contents ($map, $mapstring);
}
//JOIN MAPS
function addMapEntrySort ($map, $key1, $key2) {
global $dl1, $dl2;
$mapstring = file_get_contents ($map);
$newentry = $key1 . $dl2 . $key2 . $dl2 . "\n";
$mapstring = $mapstring . $dl1 . $newentry;
$mapstring = trim ($mapstring, $dl1);
$maparray = explode ($dl1, $mapstring);
array_unique ($maparray);
sort ($maparray);
$mapstring = implode ($dl1, $maparray);
//file_put_contents ($map, $mapstring);
}
function removeFromMap ($map, $key0, $key1) {
global $dl1, $dl2;
$mapstring = file_get_contents ($map);
$maparray = explode ($dl1, $mapstring);
foreach ($maparray as $id => $entrystring) {
$entryarray = explode ($dl2, $entrystring);
$mapkey1 = $mapkey2 = "";
if (array_key_exists (0, $entryarray)) {
$mapkey0 = $entryarray[0];
}
if (array_key_exists (1, $entryarray)) {
$mapkey1 = $entryarray[1];
}
if ($key0 !== "" && $key1 !== "") {
if ( $mapkey0 === $key0 && $mapkey1 === $key1 ) {
unset ($maparray [$id]);
}
}
else if ($key0 === "" && $key1 !== "") {
if ($mapkey1 === $key1) {
unset ($maparray [$id]);
}
}
else if ($key0 !== "" && $key1 == "") {
if ($mapkey0 === $key0) {
unset ($maparray [$id]);
}
}
}
$mapstring = implode ($dl1, $maparray);
//file_put_contents ($map, $mapstring);
}
function renameKeyInMap ($map, $key0, $key1, $newkey) {
global $dl1, $dl2;
$mapstring = file_get_contents ($map);
$maparray = explode ($dl1, $mapstring);
foreach ($maparray as $id => $entrystring) {
$entryarray = explode ($dl2, $entrystring);
$mapkey1 = $mapkey2 = "";
if (array_key_exists (0, $entryarray)) {
$mapkey0 = $entryarray[0];
}
if (array_key_exists (1, $entryarray)) {
$mapkey1 = $entryarray[1];
}
if ($key0 === "" && $key1 !== "") {
if ($mapkey1 === $key1) {
$maparray[$id] = $mapkey0 . $dl2 . $newkey . $dl2 . "\n";
}
}
else if ($key0 !== "" && $key1 == "") {
if ($mapkey0 === $key0) {
$maparray[$id] = $newkey . $dl2 . $mapkey1 . $dl2 . "\n";
}
}
}
$mapstring = implode ($dl1, $maparray);
//file_put_contents ($map, $mapstring);
}
function selectMapEntries ($map, $key0, $key1) {
//returns an array with selected key
global $dl1, $dl2;
$selectedarray = array();
$mapstring = file_get_contents ($map);
$maparray = explode ($dl1, $mapstring);
foreach ($maparray as $entrystring) {
$entryarray = explode ($dl2, $entrystring);
$mapkey0 = $mapkey1 = "";
if (array_key_exists (0, $entryarray)) {
$mapkey0 = $entryarray[0];
}
if (array_key_exists (1, $entryarray)) {
$mapkey1 = $entryarray[1];
}
if ($key0 !== "" && $key1 === "") {
if ($mapkey0 === $key0 ){
array_push ($selectedarray, $mapkey1);
}
}
else if ($key0 === "" && $key1 !== "") {
if ($mapkey1 === $key1) {
array_push ($selectedarray, $mapkey0);
}
}
}
return $selectedarray;
}
function selectMapEntries2 ($map, $key0, $key1) {
//returns an array with both keys
global $dl1, $dl2;
$selectedarray = array();
$mapstring = file_get_contents ($map);
$maparray = explode ($dl1, $mapstring);
foreach ($maparray as $id => $entrystring) {
$entryarray = explode ($dl2, $entrystring);
$mapkey0 = $mapkey1 = "";
if (array_key_exists (0, $entryarray)) {
$mapkey0 = $entryarray[0];
}
if (array_key_exists (1, $entryarray)) {
$mapkey1 = $entryarray[1];
}
if ($key0 !== "" && $key1 === "") {
if ($mapkey0 === $key0 ){
array_push ($selectedarray, $entrystring);
}
}
else if ($key0 === "" && $key1 !== "") {
if ($mapkey1 === $key1) {
array_push ($selectedarray, $entrystring);
}
}
}
return $selectedarray;
}
function extractFromMap($map, $key) {
//returns a new array of either the the first or second elements
global $dl1, $dl2;
$selectedarray = array();
$mapstring = file_get_contents ($map);
$maparray = explode ($dl1, $mapstring);
sort ($maparray);
foreach ($maparray as $item) {
$array = explode ($dl2, $item);
$mapkey0 = $mapkey1 = "";
if (array_key_exists (0, $array)) {
$mapkey0 = $array[0];
}
if (array_key_exists (1, $array)) {
$mapkey1 = $array[1];
}
if ($key == 0) {
array_push ($selectedarray, $mapkey0);
}
else if ($key == 1) {
array_push ($selectedarray, $mapkey1);
}
}
return $selectedarray;
}
function removeEventFromMapByYear ($map, $date, $event, $year) {
global $dl1, $dl2;
$mapstring = file_get_contents ($map);
//Remove events for selected year
$array1 = explode ($dl1, $mapstring);
foreach ($array1 as $id => $item1) {
$array2 = explode ($dl2, $item1);
if (array_key_exists (0, $array2) && array_key_exists (1, $array2)) {
if (substr ($array2[0], 0, 4) === $year) {
if ($array2[1] === $event) {
unset ($array1 [$id]);
}
}
}
}
$mapstring = implode ($dl1, $array1);
//file_put_contents ($map, $mapstring);
}
function sortMap ($map) {
global $dl1, $dl2;
$string = file_get_contents ($map);
$array = explode ($dl1, $string);
sort ($array);
$string = implode ($dl1, $array);
//file_put_contents ($map, $string);
}
?>
display-events-for-day.php ▾
<?php
$currentdate = $year . $month . $xpadded;
$weekday = date("w", mktime(0,0,0,$month, $xpadded, $year));
//show events for this date
$map = "data/date-event-map.txt";
$selectedarray = selectMapEntries ($map, $year . "-" . $month . "-" . $xpadded, "");
foreach ($selectedarray as $item) {
$eventid = $item;
$eventrecord = readDatabaseRecord ("events", $eventid);
echo "<a href = 'index.php?page=display-event&event=" . $eventid . "'>" . $eventrecord['title'] . "</a><br>";
}
//show events if within start and end dates
$map = "data/start-date-event-map.txt";
$selectedarray = extractFromMap($map, 1, "");
foreach ($selectedarray as $item) {
$eventid = $item;
$eventrecord = readDatabaseRecord ("events", $eventid);
$currentdate = $year . "-" . $month . "-" . $xpadded;
if ($currentdate >= $eventrecord['start-date'] && $currentdate <= $eventrecord['end-date']) {
echo "<a href = 'index.php?page=display-event&event=" . $eventid . "'>" . $eventrecord['title'] . "</a><br>";
}
}
//show events for this day of week
$map = "data/weekday-event-map.txt";
$selectedarray = selectMapEntries ($map, $weekday, "" );
foreach ($selectedarray as $item) {
$eventid = $item;
$eventrecord = readDatabaseRecord ("events", $eventid);
$currentdate = $year . "-" . $month . "-" . $xpadded;
$startdate = $eventrecord['start-date'];
if ($eventrecord ['start-date'] === "") {
$startdate = 0000-00-00;
}
$enddate = $eventrecord['end-date'];
if ($eventrecord['end-date'] === "") {
$enddate = 9999-99-99;
}
if ($currentdate <= $enddate && $currentdate >= $startdate) {
echo "<a href = 'index.php?page=display-event&event=" . $eventid . "'>" . $eventrecord['title'] . "</a><br>";
}
}
?>
event-form.php ▾
<form method='post' action='admin.php?adminpage=add-update-event&event=<?php echo $eventid ;?>'>
<?php
echo "<h3>Title: </h3><textarea name = 'title' type = 'textarea' rows='1' cols='50' >" . $eventrecord['title'] . "</textarea>";
echo "<br><h3>Brief Description for Calendar:</h3><textarea name = 'description' type = 'textarea' rows='1' cols='80' >" . $eventrecord['description'] . "</textarea>";
echo "<br><h3>Detailed Description for Event Page:</h3><textarea name = 'markdown-content' type = 'textarea' rows='6' cols='80' >" . $eventrecord['markdown-content'] . "</textarea>";
echo "<br><h3>Time:</h3> <input type = 'text' name = 'time' value = '" . $eventrecord['time'] . "'/>";
echo "<br><h3>Category:</h3>";
if ($eventrecord ['category'] === 'classes') {
echo "<input type = 'radio' name = 'category' value = 'classes' checked />Class";
}
else {
echo "<input type = 'radio' name = 'category' value = 'classes' />Class";
}
echo " ";
if ($eventrecord ['category'] === 'events') {
echo "<input type = 'radio' name = 'category' value = 'events' checked />Event";
}
else {
echo "<input type = 'radio' name = 'category' value = 'events' />Event";
}
echo "<br><br><h3>Add an Image:</h3>";
if ($eventrecord ['image'] !== '') {
echo "<input type = 'radio' name = 'image-flag' value = 'image' checked />Image";
echo " ";
echo "<input type = 'radio' name = 'image-flag' value = '' />No Image";
}
else {
echo "<input type = 'radio' name = 'image-flag' value = 'image' />Image";
echo " ";
echo "<input type = 'radio' name = 'image-flag' value = '' checked />No Image";
}
echo "<br><h3>Image Name:</h3><input id = 'imageinput' type = 'hidden' name = 'image' value = '" . $eventrecord['image'] . "'/><br>";
$imagename = str_replace ("data/images/calendar-thumbnails/", "", $eventrecord['image']);
echo "<div id = 'eventimagename'>";
echo $imagename ;
echo "</div>";
echo "<img id = 'eventimage' src = '" . $eventrecord['image'] . " ' alt = ' ' width = '120' /><br><br>";
?>
<input class = 'submitbutton' type = 'submit' name = 'submit-info' value='Update Event'/> <br>
</form>
footer.php ▾
<?php
if ($loggedin === true ) {
echo "<br><a class = 'pinkbutton' href = 'index.php?page=calendar'>View Calendar</a>";
echo "<a class = 'pinkbutton' href = 'admin.php?adminpage=add-update-event'>Add Event</a>";
echo "<a class = 'pinkbutton' href = 'admin.php?adminpage=display-all-events'>Display all events</a>";
echo "<br><br><a href = 'logout.php'>Log Out</a><br>";
}
else {
if ($pageid !== 'login') {
echo "<a class = 'pinkbutton' href = 'login.php'>Log In</a><br>";
}
}
?>
<a class = 'greenbutton' href = '../../projects'>Return to Projects</a><br><br>
<br><br><br>Copyright © <?php echo date('Y'); ?> Susan Rodgers, <a href = 'https://lilaavenue.com'>Lila Avenue</a><br><br>
<br><br>
<script src= "inc/scripts.js"></script>
</body>
</html>
header.php ▾
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>'The Nip Shoppe'</title>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Elsie" rel="stylesheet">
<link rel= 'stylesheet' type='text/css' href= 'inc/style.css'>
</head>
<body>
<div class = 'outerwrap'>
<div class = 'header'>
<?php
if ($pageid === 'about') {
echo "<a class = 'menuitem highlighted' href = 'index.php?page=classes'>Classes</a>";
}
else {
echo "<a class = 'menuitem' href = 'index.php?page=classes'>Classes</a>";
}
echo "<a class = 'site-title' href = 'index.php'>The Nip Shoppe</a> ";
if ($pageid === 'events') {
echo "<a class = 'menuitem highlighted' href = 'index.php?page=events'>Events</a>";
}
else {
echo "<a class = 'menuitem' href = 'index.php?page=events'>Events</a>";
}
?>
</div>
list-all-events.php ▾
<?php
$map = "data/maps/date-event-map.txt";
$array1 = extractFromMap ($map, 1 );
$array1 = array_unique ($array1);
foreach ($array1 as $item) {
$eventid = $item;
$eventrecord = readDatabaseRecord ("events", $eventid);
$selecteddates = selectMapEntries ("data/maps/date-event-map.txt", "", $eventid);
$eventcurrentflag = false;
foreach ($selecteddates as $item1) {
if ($item1 >= date("Y/m/d")) {
$eventcurrentflag = true;
}
}
if ($eventcurrentflag === true ) {
if ($eventrecord['category'] === $eventcategory || $eventcategory === "") {
$eventrecord = readDatabaseRecord ("events", $eventid);
echo "<div class = 'event-box'>";
echo "<div class = 'half-column'>";
if ($eventrecord['image'] !== "") {
echo "<img src = '" . $eventrecord['image'] . "' alt = '" . $eventrecord['title'] . "'>";
}
echo "<br><a href = 'index.php?page=calendar-event&event=" . $eventid . "'><h3>" . $eventrecord['title'] . "</h3></a>";
echo "</div><div class = 'half-column'>";
foreach ($selecteddates as $item) {
if ($item >= date("Y/m/d")) {
$eventcurrentflag = true;
$year = intval (substr ($item, 0, 4));
$month = intval (substr ($item, 5, 2));
$day = intval(substr ($item, 8, 2));
$string = date("l F d, Y", mktime(0,0,0,$month, $day, $year));
echo "<br> " . $string;
}
}
echo "</div></div>";
}
}
}
?>
markdown-instructions.php ▾
<div class = 'editing-column' >
<button id = 'editing' onclick= 'accordionToggle(this.id)'>Markdown Tips ▼</button>
<div id ='accordion' style = 'display: none; text-align: left; ' >
<b>Heading 1 </b># Heading<br>
<b>Heading 2 </b>## Heading<br>
<b>Heading 3 </b>### Heading<br>
<b>Heading 4 </b>#### Heading<br>
<b>Heading 5 </b>##### Heading<br>
<b>**</b> Bold <b> **</b><br>
<b>*</b> Italic <b>*</b><br>
<b>Quote Section </b>>Text<br>
<b>Underline </b>___ <br>
<b>Image </b> ! [image description ] (image file )<br>
<b>Image Right </b> ! [image description ] (image file) RIGHT <br>
<b>Image Left </b> ! [image description ] (image file) LEFT<br>
<b>Link </b> [ link name ] ( link url )<br>
<b>Image Link </b> [ ! [ image description ] ( image file ) ] (link url)<br>
<b>New Line After Image </b>BREAK<br>
<b>Indented block </b>BLOCK....ENDBLOCK<br>
<b>List </b>* item (asterisk followed by a space)<br>
<b>Numeric List </b>1. item
<br>
</div>
</div>
<script>
function accordionToggle() {
var y = "accordion";
var x = document.getElementById(y);
if (x.style.display === "block" ) {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
</script>
media-library.php ▾
<?php
/*Copyright (c) 2019, Susan V. Rodgers, Lila Avenue, LLC, lilaavenue@gmail.com
This code is part of the LilaWorks Content Management System
*/
echo "<br><br><h3 >Image Library: </h3>";
$array1 = scandir( "data/images");
foreach ($array1 as $item) {
if ($item !== "." && $item !== "..") {
$folder = trim ($item);
if (is_dir("data/images/" . $folder)) {
//Only show calendar thumbnails for add-update-event page
if ($adminpage !== 'add-update-event'|| $folder === 'calendar-thumbnails') {
echo "<div class = 'toggle-dropdownwrap'>";
$displayfolder = str_replace ("-", " ", $folder);
$displayfolder = ucwords($displayfolder);
echo "<button class = 'toggle-banner-media' id = '" . $folder . "' onclick= 'accordionToggle(this.id)' >" . $displayfolder . " ▾</button>";
echo "<div id = '" . $folder . "-accordion' style = 'display: none;'>";
$array2 = scandir("data/images/" . $folder);
foreach ($array2 as $id => $item) {
if ($item !== "." && $item !== "..") {
$image = trim ($item);
$key = $folder . ($id + 1);
echo "<div class = 'admin-gridcolumn'>";
if ($adminpage === 'add-update-post' || $adminpage === 'add-update-block') {
//IMAGE GETS INSERTED INTO TEXT
$imagefile = "data/images/" . $folder . "/" . $image ;
echo "<div id = '" . $key . "' class = 'select-image' onclick = 'selectImage(this.id)'>";
echo "<img id = '" . $key . "-image' src = '" . $imagefile . "' alt ='". $imagefile ."' width = '130' />";
echo "</div><br>";
}
else if ($adminpage === 'add-update-event') {
//IMAGE GETS INSERTED INTO FORM
$imagefile = "data/images/" . $folder . "/" . $image ;
echo "<div id = '" . $key . "' class = 'select-image' onclick = 'selectEventImage(this.id)'>";
echo "<img id = '" . $key . "-image' src = '" . $imagefile . "' alt ='". $imagefile ."' width = '130' />";
echo "</div><br>";
}
else {
echo "<a href = 'admin.php?adminpage=image-edit&folder=" . $folder . "&image=" . $image . "'><img src = 'data/images/" . $folder . "/" . $image . "' alt = 'media image' width = '130' /></a><br>";
}
echo $image;
echo "</div>";
}
}
echo "</div></div>";
}
}
}
}
?>
scripts.js ▾
function selectBlock(id) {
var array1 = document.getElementsByClassName('sort');
if (array1.length > 0) {
if ( array1[id].innerHTML !== "" ) {
document.getElementById('open-slot').innerHTML = array1[id].innerHTML;
array1[id].innerHTML = "";
}
}
}
function insertBlock(id) {
var array1 = document.getElementsByClassName('sort');
var array2 = document.getElementsByClassName('sort2');
var array3 = document.getElementsByClassName('sort3');
var array4 = document.getElementsByClassName('form-input');
var text;
var text1
var j = 0;
var newarray = new Array;
//check that there is a value in open slot
if (document.getElementById('open-slot').innerHTML !== "") {
array2[id].innerHTML = document.getElementById('open-slot').innerHTML;
//move not-empty values into newarray
for (i = 0; i < array3.length; i++) {
//alert (array3[i].innerHTML);
if (array3[i].innerHTML) {
text = array3[i].innerHTML;
newarray[j] = text;
//alert (newarray[j]);
j++;
}
}
//return values to array1
for (i = 0; i < array1.length; i++) {
array1[i].innerHTML = newarray[i];
}
for (i = 0; i < array4.length; i++) {
array4[i].value = newarray[i];
}
document.getElementById('open-slot').innerHTML = "";
array2[id].innerHTML = "";
}
}
function accordionToggle(bttn) {
var y = bttn+"-accordion";
var x = document.getElementById(y);
if (x.style.display === "block" ) {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
function selectEventImage(key) {
var pic = (document.getElementById(key+'-image').alt);
document.getElementById('imageinput').value = pic;
var imgname = pic.replace("data/images/calendar-thumbnails/", "");
document.getElementById('eventimagename').innerHTML = imgname;
document.getElementById('eventimage').src = pic;
alert ("Image added - remember to click update");
}
select-event-dates.php ▾
<form method='post' action='admin.php?adminpage=add-update-event&event=<?php echo $eventid ;?>&year=<?php echo $year; ?>&month=<?php echo $month; ?>'>
<?php
//SHOW YEAR SELECTION
$yeararray = array ($year-1, $year, $year+1);
foreach ($yeararray as $item) {
if ($item === $year) {
echo "<a href = 'admin.php?adminpage=add-update-event&event=" . $eventid . "&year=" . $item . "&month=" . $month . "'><b>" . $item . "</b></a> ";
}
else {
echo "<a href = 'admin.php?adminpage=add-update-event&event=" . $eventid . "&year=" . $item . "&month=" . $month . "'>" . $item . "</a> ";
}
}
echo "<br><br>";
$monthchararray2 = array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
for ($m = 0; $m <= 11; $m++) {
if (array_key_exists ($m, $monthchararray2)) {
$monthname = $monthchararray2[$m];
//MONTH HEADER
echo "<div class = 'cal-block'>";
echo "<h3>" . $monthname . " " . $year . "</h3>";
//WEEKDAY NAME LABELS
$dayofweekarray = array ("Sun","Mon" ,"Tues", "Wed", "Thurs", "Fri", "Sat");
foreach ($dayofweekarray as $item) {
echo "<div class = 'dow-header-block'>" . $item . "</div>";
}
//CALENDAR FOR THIS MONTH
$firstline = true;
$daysinmonth = cal_days_in_month(CAL_GREGORIAN, $monthnum, $year);
for ($x = 1; $x <= $daysinmonth ; $x++) {
$xpadded = str_pad($x,2,0 , STR_PAD_LEFT);
$dayofweek = date("w", mktime(0,0,0,$month,$x,$year));
//FILL IN BLANK DAYS AT BEGINNING OF MONTH
if ($firstline === true) {
for ($i = 0; $i < $dayofweek; $i++) {
echo "<div class = 'dayblock4'> </div>";
}
$firstline = false;
}
if ($xpadded == date("d") && $month == date("m") && $year == date("Y")) {
echo "<div class = 'dayblock2 '>";
}
else {
echo "<div class = 'dayblock'>";
}
if (in_array ($year . "/" . $month . "/" . $xpadded, $datearray)) {
echo $x . "<br><input type = 'checkbox' name = 'datearray[]' value = '" .$year . "/" . $month . "/" . $xpadded . "' checked >" ;
}
else {
echo $x . "<br><input type = 'checkbox' name = 'datearray[]' value = '" .$year . "/" . $month . "/" . $xpadded . "' >" ;
}
echo "</div>";
}
echo "</div>";
if ($month === "12") {
$month = "01";
$year = $year + 1;
$monthnum = 1;
}
else {
$monthnum = $monthnum + 1;
$month = str_pad($monthnum ,2,0 , STR_PAD_LEFT);
}
}
}
?>
<br><br>
<input class = 'submitbutton' type = 'submit' name = 'submit-dates' value='Update Dates '/>
</form>
single-event.php ▾
<?php
$dayofweekarray = array ("Sun","Mon" ,"Tues", "Wed", "Thurs", "Fri", "Sat");
$eventrecord = readDatabaseRecord ("events" , $eventid);
echo "<div class = 'calendar-event'>";
echo "<a href = 'index.php?page=calendar-event&event=" . $eventid . "' ><h2>" . $eventrecord['title'] . "</h2></a><br>";
if ($eventrecord['image'] !== "") {
echo "<br><img src = '" . $eventrecord['image'] . "' alt = '" . $eventrecord['title'] . "' width = '120' />";
}
echo $eventrecord['html-content'] ;
echo "<br><b>Time: </b>" . $eventrecord['time'] ;
echo "<br><br><b>Dates: </b>";
$datearray = selectMapEntries ("data/maps/date-event-map.txt", "", $eventid);
foreach ($datearray as $item) {
$year = intval (substr ($item, 0, 4));
$month = intval (substr ($item, 5, 2));
$day = intval(substr ($item, 8, 2));
$string = date("l F d, Y", mktime(0,0,0,$month, $day, $year));
echo "<br> " . $string;
}
echo "</div>";
if ($loggedin === true) {
echo "<a class = 'pinkbutton' href = 'admin.php?adminpage=add-update-event&event=" . $eventid . "'>Edit Event</a>";
}
?>
style.css ▾
body {
font-size: 16px;
margin: 0 auto;
font-family: "lato", sans-serif;
font-size: 1em;
box-sizing: border-box;
color: #333;
background-color: #356335;
}
a{
text-decoration: none;
}
h1 {
margin-top: 0;
}
h1, h2 {
text-align: center;
color: #356335;
}
h2 {
display: inline-block;
}
h3, a h3 {
color: white;
vertical-align: top;
text-decoration: none;
}
.event-box h3, .event-box h3 a {
color: green;
}
a h3:hover, a:hover {
color: aquamarine;
}
.adminwrap h3 {
font-size: 1em;
display: block;
margin-bottom: 0;
margin-top: 20px;
}
textarea, input {
max-width: 100%;
border: 1px solid #bbb;
padding: 5px;
font-family: 'Lato', sans-serif;
margin-bottom: 10px;
}
.error {
color: red;
font-size: 1.2em;
font-weight: bold;
}
/** HEADER AND NAVIGATION */
.header, .adminwrap .header {
text-align: center;
background-color: #356335;
display: block;
margin: 0 auto 10px auto;
top: 0;
width: 100%;
border-top: 5px solid lightcoral;
}
a.site-title {
font-family: 'Elsie', cursive;
text-align: center;
color: white;
font-size: 46px;
letter-spacing: 1px;
}
a.menuitem {
color: white;
display: inline-block;
font-size: 1.3em;
padding: 5px 20px;
margin: 10px auto;
}
.highlighted {
text-decoration: underline;
}
/** PAGE SECTIONS */
.outerwrap {
display: block;
margin: auto;
box-sizing: border-box;
text-align: center;
}
main {
margin: 20px auto;
padding: 40px 0 0 0 ;
text-align: center;
display: block;
background-color: white;
max-width: 1000px;
}
.full-column {
display: block;
width: auto;
text-align: center;
}
.content-column, .sidebar-column, .half-column, .fourth-column, .third-column {
display: inline-block;
box-sizing: border-box;
margin: auto;
vertical-align: top;
text-align: left;
max-width: 100%;
}
.content-column {
width: 70%;
}
.sidebar-column {
width: 25%;
}
.fourth-column {
width: 25%;
}
.half-column {
width: 50%;
padding: 20px;
}
.third-column {
width: 66%;
}
.two-thirds-column {
width: 33%;
}
.centered {
text-align: center;
}
.right {
text-align: right;
}
.left {
text-align: left;
}
a.nav-left, a.nav-right {
display: inline-block;
padding: 0 40px;
font-size: .7em;
}
.inner-grid {
display: block;
text-align: left;
margin: auto;
}
.headerbutton {
padding: 5px 15px;
margin: 5px;
text-align: center;
background-color: #356335;
color: white;
box-sizing: border-box;
display: inline-block;
font-size: 1.1em;
}
.greenbutton, .pinkbutton, .submitbutton {
width: 160px;
border: 1px solid darkgreen;
background-color: green;
border-radius: 3px;
padding: 5px;
font-size: 1em;
display: block;
margin: 10px auto;
padding: 10px;
font-weight: bold;
box-sizing: border-box;
text-align: center;
}
.pinkbutton {
background-color: lightcoral;
}
a.pinkbutton, a.greenbutton, input.pinkbutton, .submitbutton {
color: white;
font-size: 1em;
}
input.submitbutton {
background-color: #7e227e;
display: inline-block;
}
footer {
margin: 40px auto;
}
/** STYLES FOR CALENDAR */
.inner-grid {
display: block;
text-align: left;
margin: auto;
background-color: #ddd;
}
/** dayblock: default day, dayblock2: current date, dayblock3: day with event, dayblock4: leading and trailing empty blocks */
.dayblock, .dayblock2, .dow-header-block, .dayblock3, .dayblock4 {
font-size: .9em;
display: inline-block;
margin: auto;
padding: 5px;
background-color: #356335;
background-color: #ddd;
border: 1px solid black;
width: 14.28%;
height: 200px;
box-sizing: border-box;
vertical-align: top;
max-height: 100%;
line-height: 120%;
}
.dayblock2 {
background-color:#bbb;
}
.dayblock3 {
background-color: #666;
padding: 3px;
box-sizing: border-box;
text-align: left;
font-size: .9em;
color: white;
}
.dayblock3 a {
color: white;
}
.dayblock3:hover {
background-color: #888;
}
.dayblock3 img {
display: block;
width: 130px;
max-width: 100%;
margin: auto;
max-height: 140px;
}
.dow-header-block {
padding: 5px;
border: none;
height: auto;
text-transform: uppercase;
text-align: center;
background-color: #666;
color: white;
font-size: 1em;
}
.event-box {
border: 1px solid #666;
line-height: 140%;
color: white;
max-width: 90%;
margin: 5px auto;
padding: 10px;
color: #356335;
}
.event-box img {
max-width: 120px;
max-height: 100px;
display: inline-block;
}
cal-header {
font-size: .8em;
margin: auto;
max-width: 95%;
}
.calendar-page b {
color: blueviolet;
}
.calendar-page h2 {
display: inline-block;
color: white;
}
.calendar-page .nav-left, .calendar-page .nav-right {
margin: 0 20px;
}
.calendar-page img {
display: block;
}
.calendar-event {
border: 1px solid #ddd;
margin: 10px auto;
padding: 20px;
line-height: 130%;
}
.cal-block {
display: inline-block;
width: 45%;
margin: 5px;
box-sizing: border-box;
vertical-align: top;
text-align: left;
}
/** Admin */
.adminwrap main {
max-width: 100%;
font-size: 1em;
}
.adminwrap h3 {
color: grey;
}
.adminwrap .dayblock, .adminwrap .dayblock2, .adminwrap .dayblock3, .adminwrap .dayblock4 {
height: 50px;
padding: 3px;
background-color: #888;
}
/** PRINT CALENDAR PAGES */
.print-calendar-page .dayblock, .print-calendar-page .dayblock2, .print-calendar-page .dayblock3, .print-calendar-page .dayblock4 {
height: 170px;
background-color: white;
color: black;
}
.print-calendar-page {
background-color: white;
color: black;
padding: 20px;
}
.print-calendar-page h1 {
color: black;
vertical-align: top;
}
.print-calendar-page main img {
max-height: 100px;
}
.print-events-page .event-box {
color: black;
background-color: white;
text-align: left;
}
.print-events-page h3 {
text-align: left;
margin-top: 0;
padding-top: 5px;
}
.print-calendar-page .logo img{
border: 3px solid black;
width: 140px;
}
.print-title {
display: inline-block;
vertical-align: top;
padding: 30px;
font-size: 1.2em;
font-weight: bold;
}
/** BREAKPOINT */
@media only screen and (max-width: 650px) {
.outerwrap {
width: 98%;
}
.headerbutton {
display: block;
width: 120px;
margin: 5px auto;
font-size: .8em;
}
.calendarbutton2, .highlightbutton2, .calendarbutton3 {
font-size: .8em;
}
}
@media only screen and (max-width: 520px) {
.calendarbutton2, .highlightbutton2, .calendarbutton3 {
font-size: .7em;
}
h2 {
font-size: 1.1em;
}
}
uploaded-image.php ▾
<?php
/*Copyright (c) 2019, Susan V. Rodgers, Lila Avenue, LLC, lilaavenue@gmail.com
This code is part of the LilaWorks Content Management System
*/
$successflag = false;
$file = $_FILES['file'];
$fileName= $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
$array = explode (".", $fileName);
$extension = strtolower (end($array));
$allowed = array('jpg', 'jpeg', 'png' , 'pdf', 'gif');
//Remove illegal characters from file name
$newimagename = str_replace(" ", "-", $newimagename);
$newimagename = strtolower ($newimagename);
$newimagename = preg_replace('/[^\A-Za-z0-9-]+/', '', $newimagename);
//get first part of name, before extension
$newimagename = $newimagename . "." . $extension;
$errorarray = array(
0=>"There is no error, the file uploaded with success",
1=>"The uploaded file exceeds the maxiumum file size allowed",
2=>"The uploaded file exceeds the maxiumum file size allowed",
3=>"The uploaded file was only partially uploaded",
4=>"No file was uploaded",
6=>"Missing a temporary folder"
);
if (in_array($extension, $allowed)) {
if ($fileSize < 1000000 ){
if ( ! file_exists ("data/images/" . $folder . "/" . $newimagename)) {
$fileDestination = "data/images/" . $folder . "/" . $newimagename;
// move_uploaded_file($fileTmpName, $fileDestination);
if ($fileError === 0) {
$successflag = true;
echo "<h2>File successfully uploaded</h2><br>";
}
else {
if (array_key_exists ($fileError, $errorarray)) {
echo "Error #: " . $fileError . " " . $errorarray[$fileError];
}
}
}
else {
echo "<div class = 'error'> The Image: '" . $newimagename . "' already exists.</div>";
}
}
else {
echo "File too large to upload";
}
}
?>
pages folder:
calendar-event.php ▾
<div class = 'content-column'>
<?php
$eventid = $savedeventid = "";
if (isset ($_GET["event"])){
$eventid = filter_input(INPUT_GET, "event", FILTER_SANITIZE_STRING) ;
$savedeventid = $eventid;
}
$eventrecord = readDatabaseRecord ("events" , $eventid);
$return = $eventrecord['category'];
echo "<a href = 'index.php?page=" . $return . "'><h3>←Return to " . $return . "</h3></a>";
include ("inc/single-event.php");
?>
</div>
calendar.php ▾
<?php
//SET DATE TO CURRENT DATE
$month = date("m");
$day = date ("d");
$year = date ("Y");
//CHECK FOR INPUT DATES
if (isset ($_GET["year"])){
$year = trim ($_GET["year"]);
}
if (isset ($_GET["month"])){
$month = trim ($_GET["month"]);
}
$monthnum = intval ($month);
$prevmonth = $nextmonth = $prevyear = $nextyear = "";
if ($month === "01") {
$prevmonth = "12";
$prevyear = $year - 1;
}
else {
$prevmonthnum = $monthnum - 1;
$prevmonth = str_pad ($prevmonthnum ,2,0 , STR_PAD_LEFT);
$prevyear = $year;
}
if ($month == "12") {
$nextmonth = "01";
$nextyear = $year + 1;
}
else {
$nextmonthnum = $monthnum + 1;
$nextmonth = str_pad($nextmonthnum,2,0 , STR_PAD_LEFT);
$nextyear = $year;
}
$monthchararray = array("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
$monthchararray2 = array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
echo "<h1>Calendar</h1>";
echo "<div class = ' cal-header '>";
//SHOW YEAR SELECTIONS
$yeararray = array ($year-1, $year, $year+1);
foreach ($yeararray as $item) {
if ($item === $year) {
echo "<a href = 'index.php?page=calendar&year=" . $year . "&month=" . $month . "'><b>" . $item . "</b></a> ";
}
else {
echo "<a href = 'index.php?page=calendar&year=" . $item . "&month=" . $month . "'>" . $item . "</a> ";
}
}
echo "<br>";
//SHOW MONTH SELECTION
for ($m = 0; $m <= 11; $m++) {
$mpadded = str_pad ($m +1 ,2,0 , STR_PAD_LEFT);
if (array_key_exists ($m, $monthchararray)) {
if ( $mpadded === $month){
echo "<a href = 'index.php?page=calendar&year=" . $year . "&month=" . $mpadded . "'><b>" . $monthchararray[$m] . "</b></a> ";
}
else {
echo "<a href = 'index.php?page=calendar&year=" . $year . "&month=" . $mpadded . "'>" . $monthchararray[$m] . "</a> ";
}
}
}
echo "</div>";
//SHOW SELECTED MONTH WITH ARROWS
echo "<a class = 'nav-left' href = 'index.php?page=calendar&year=" . $prevyear . "&month=" . $prevmonth . "&day=01'>❮</a>";
if (array_key_exists ($monthnum - 1, $monthchararray2)) {
echo "<h2>" . $monthchararray2[$monthnum -1] . " " . $year . "</h2>";
}
echo "<a class = 'nav-right' href = 'index.php?page=calendar&year=" . $nextyear . "&month=" . $nextmonth . "&day=01'>❯</a>";
echo "<br><br>";
//SHOW WEEKDAY NAME LABELS
$dayofweekarray = array ("Sun","Mon" ,"Tues", "Wed", "Thurs", "Fri", "Sat");
echo "<div class = 'inner-grid'>";
foreach ($dayofweekarray as $item) {
echo "<div class = 'dow-header-block'>" . $item . "</div>";
}
echo "<br>";
//SHOW CALENDAR
$firstline = true;
$daysinmonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
for ($x = 1; $x <= $daysinmonth ; $x++) {
$xpadded = str_pad($x,2,0 , STR_PAD_LEFT);
$dayofweek = date("w", mktime(0,0,0,$month,$x,$year));
//FILL IN BLANK DAYS AT BEGINNING OF MONTH
if ($firstline === true) {
for ($i = 0; $i < $dayofweek; $i++) {
echo "<div class = 'dayblock4'> </div>";
}
$firstline = false;
}
$map = "data/maps/date-event-map.txt";
$currentdate = $year . "/" . $month . "/" . $xpadded;
$eventsforday = selectMapEntries ($map, $currentdate, "");
if (count ($eventsforday) > 0) {
echo "<a href = 'index.php?page=events-for-day&year=" .$year . "&month=" . $month . "&day=" . $xpadded . "'><div class = 'dayblock3'>";
echo $x . "<br>";
$currentdate = $year . $month . $xpadded;
//show events for this date
foreach ($eventsforday as $item) {
$eventid = $item;
$eventrecord = readDatabaseRecord ("events", $eventid);
echo $eventrecord['time'] . "<br>";
echo $eventrecord['title'] ;
if ($eventrecord['image'] !== "") {
echo "<img src = '" . $eventrecord['image'] . "' alt = '" . $eventrecord['title'] ."' /><br>";
}
echo "<div class = 'cal-description'>". $eventrecord['description'] . "</div>";
}
echo "</a>";
}
else if ($x == date("d") && $month == date("m") && $year == date("Y")) {
echo "<div class = 'dayblock2'>";
echo $x ;
}
else {
echo "<div class = 'dayblock'>";
echo $x ;
}
echo "</div>";
}
echo "</div>";
?>
classes.php ▾
<?php
echo "<h1>Classes</h1>";
$eventcategory = 'classes';
include ("inc/list-all-events.php");
?>
display-all-events.php ▾
<h2>Events</h2>
<div class = 'content-column'>
<?php
$array1 = scandir ("data/events");
foreach ($array1 as $item1) {
if ($item1 !== "." && $item1 !== "..") {
$eventid = str_replace (".txt", "", $item1);
include ("inc/single-event.php");
echo "<br><br><hr>";
}
}
?>
</div><div class = 'sidebar-column'>
<a class = 'pinkbutton' href = 'index.php?page=home'>Return to Calendar</a>
<?php
if ($loggedin === true) {
echo "<a class = 'pinkbutton' href = 'admin.php?adminpage=add-update-event'>Add Event</a>";
}
?>
</div>
display-event.php ▾
<div class = 'content-column'>
<?php
include ("inc/single-event.php") ;
?>
</div><div class = 'sidebar-column'>";
<a class = 'pinkbutton' href = 'index.php?page=home'>Calendar</a><br>
<?php
if ($loggedin === true) {
echo " <a class = 'pinkbutton' href = 'admin.php?adminpage=display-all-events'>Display All Events</a>";
echo "<a class = 'pinkbutton' href = 'admin.php?adminpage=add-update-event&event=<?php echo $eventid;?>'>Edit Event</a> ":
}
?>
</div>
display-events.php ▾
<div class = 'content-column'>
<?php
$array1 = scandir ("data/events");
foreach ($array1 as $item1) {
if ($item1 !== "." && $item1 !== "..") {
$eventid = str_replace (".txt","", $item1);
echo "<a href = 'admin.php?adminpage=add-update-event&event=" . $eventid . "'>" . $eventid . "</a>";
echo "<br>" . $eventid;
}
}
?>
</div><div class = 'sidebar-column'>
</div>
events-for-day.php ▾
<div class = 'content-column'>
<?php
$month = date ("m");
$day = date ("d");
$year = date ("Y");
if (isset ($_GET["year"])){
$year = trim ($_GET["year"]);
}
if (isset ($_GET["month"])){
$month = trim ($_GET["month"]);
}
if (isset ($_GET["day"])){
$day = trim ($_GET["day"]);
}
//Show day of week
$string = date("l F d Y", mktime(0,0,0,$month, $day, $year));
$weekday = date("l", mktime(0,0,0,$month, $day, $year));
echo "<h2>" . $string . "</h2><br>";
echo "<a href = 'index.php?page=calendar'>←Return</a>";
$map = "data/maps/date-event-map.txt";
$selectedarray = selectMapEntries ($map, $year . "/" . $month . "/" . $day, "");
foreach ($selectedarray as $item) {
$eventid = $item;
include ("inc/single-event.php");
}
?>
</div>
events.php ▾
<?php
$eventcategory = 'events';
echo "<h1>Events</h1>";
include ("inc/list-all-events.php");
?>
print-month.php ▾
<?php
$year = $month = "";
if (isset ($_GET["year"])){
$year = $_GET["year"];
}
if (isset ($_GET["month"])){
$month = $_GET["month"];
}
echo "<h1>Calendar</h1>";
echo "<h3>Month: " . $month . " " . $year . "</h3>";
echo "<div class = 'full-width-column'> ";
$array1 = scandir ("data/calendar/" . $year . "/" . $month);
foreach ($array1 as $item) {
if ($item !== "." && $item !== "..") {
$item = trim ($item);
$displayitem = str_replace (".txt", "", $item);
echo "<h4>". $displayitem . "</h3>";
$string = file_get_contents ("data/calendar/" . $year . "/" . $month . "/" . $item);
$array2 = explode ("%%%", $string);
if (array_key_exists (0, $array2)) {
if ($array2[0] !== "") {
echo "<b>Journal</b>: " . nl2br($array2[0]);
}
}
if (array_key_exists (1, $array2)) {
if ($array2[1] !== "") {
echo "<b>Work</b>: " . nl2br($array2[1]) . "<br>";
}
}
if (array_key_exists (2, $array2)) {
if ($array2[2] !== "") {
echo "<b>Dreams</b> " . nl2br($array2[2]) . "<br>";
}
}
echo "<hr>";
}}
echo "</div>";
?>