#!/bin/bash
# A maintenance log update script, designed to automatically categorise the work done
# The categorisation ability is currently only aimed at Motorcycle maintenance

# This script is usually called by the Bikemaintain script

# Bike Maintain V0.4b
# Written by Ben Tasker
# Released under the GNU GPL License


# Loads the most commonly used variables
source .config

# Functions Begin

linksadded ()


addlinks ()

createcasefile ()

exportwizard ()

importwizard ()

categorisationwizard ()

categselect ()

Goodbye ()


updatehtmllog ()

updatefulllog ()

dannyboy ()

resultsparse ()


updatecatlog ()

pagefileupdate ()

appendhtml ()

# Functions End

# Polite Preamble

# Load version information
source .version

# Clear all the crud off the screen
clear

# First impressions are the most important, so be nice and polite!
echo "Hello and Welcome to Bike Maintain $VERSION"
echo ""
# YOU DIDN'T SAY PLEASE!!!!!!!!!!!!!!!!!1

# Polite Preamble over, lets get on with it!!!!!

# Section to check loadoptions, only one is ever passed at a time by bikemaintain shell script

if [ "$loadopts" == "caseupdate" ]
then
QUICKTASK="Y"
addlinks
fi
if [ "$loadopts" == "case" ]
then
createcasefile
fi
if [ "$loadopts" == "import" ]
then
importwizard
fi
if [ "$loadopts" == "XYE" ]
then
pagefileupdate
fi

# I'm sure I will add some more at some point

# Begin Nasty Workaround for formatting problem

miles="miles"

# End Nasty Workaround
# Section ends

# Clear the category temp file

echo "" > "$WORKDIR"/cats.txt
echo "Please enter the date you wish to use for your entry (format 01022008)"
# Sets the filename of the entries individual record.
read date
if [ "$date" == "ilovebikes" ]
then
# Don't Ask!!!!
clear
dannyboy
fi
# Cue next nasty workaround
dateref="$date"
# It's ok, It's over!
echo "Please enter the current mileage of the Vehicle"
read mileage
echo "Please enter a name or descriptive for the mechanic"
read mechanic
echo "Please press enter to continue, then enter the service details (including mileage, date and person"
echo "carrying out the work) as you would like it to appear in the logs"
read tmp1
# Loads the set Editor - Default Nano - .config file is the place to be to change it
$EDITOR "$WORKDIR"/data/"$date".tmp 
echo ""
echo "Thank you, do you wish to add this record to the database, or export (Y/n/e)"
echo ""
read handling
if [ "$handling" == "n" ]
then

#They don't wanna add
echo "Cancelling"
#Scrub it
rm -r "$WORKDIR"/data/$date.tmp

#Sod off then, erm I mean....

Goodbye
fi

if [ "$handling" == "e" ]
then

# They wish to export
echo "Passing details to the export wizard"
exportwizard
fi

# They want to add it to the system
echo "$mileage       $date       $mechanic" >> $WORKDIR/data/"$date"
cat "$WORKDIR"/data/"$date".tmp >> "$WORKDIR"/data/"$date"
rm -f "$WORKDIR"/data/"$date".tmp
echo "Thanks, please wait whilst I categorise your entry"

# This is the point where User Error becomes less of a problem

# Not that it makes much difference really

categorisationwizard

# they always blame the developer!

echo "If this has been printed to the screen, something has gone drastically wrong"
echo "WHAT DID YOU BREAK????"