#!/bin/bash
# Generates a report of all records stored in system as one (very) long text file
# Created to replace system of creating report by default. Reduces unnecessary disk space usage

# Loads the most commonly used variables
source .config

goodbye ()
{

#Au Revoir
echo "Cya"
exit
}

all ()
{
# Create all the reports, category full and any other formats that may get dreamt up

# thats not how you spell dreamt is it????

source datarefs/fullreportlist
mv fulllog /home/"$USER"/Desktop/
echo "Your Report (filename fulllog) is now available on your Desktop (/home/$USER/Desktop)"
source datarefs/clutchloglist
mv clutchlog /home/"$USER"/Desktop/
echo "Your Report (filename clutchlog) is now available on your Desktop (/home/$USER/Desktop)"
source datarefs/MOTloglist
mv MOTlog /home/"$USER"/Desktop/
echo "Your Report (filename MOTlog) is now available on your Desktop (/home/$USER/Desktop)"
source datarefs/Oilloglist
mv Oillog /home/"$USER"/Desktop/
echo "Your Report (filename Oillog) is now available on your Desktop (/home/$USER/Desktop)"
source datarefs/Serviceloglist
mv servicelog /home/"$USER"/Desktop/
echo "Your Report (filename servicelog) is now available on your Desktop (/home/$USER/Desktop)"
source datarefs/Brakeloglist
mv Brakelog /home/"$USER"/Desktop/
echo "Your Report (filename Brakelog) is now available on your Desktop (/home/$USER/Desktop)"
source datarefs/chainloglist
mv chainlog /home/"$USER"/Desktop/
echo "Your Report (filename chainlog) is now available on your Desktop (/home/$USER/Desktop)"
source datarefs/Tyreloglist
mv Tyrelog /home/"$USER"/Desktop/
echo "Your Report (filename Tyrelog) is now available on your Desktop (/home/$USER/Desktop)"
source datarefs/cleanloglist
mv cleanlog /home/"$USER"/Desktop/
echo "Your Report (filename cleanlog) is now available on your Desktop (/home/$USER/Desktop)"
source datarefs/engineloglist
mv enginelog /home/"$USER"/Desktop/
echo "Your Report (filename enginelog) is now available on your Desktop (/home/$USER/Desktop)"
ALL="0"

# Lets move along to

stage2
}

fulllog ()
{
source datarefs/fullreportlist
mv fulllog /home/"$USER"/Desktop/
echo "Your Report (filename fulllog) is now available on your Desktop (/home/$USER/Desktop)"
FULL=0
stage2
}

clutchlog ()
{
source datarefs/clutchloglist
mv clutchlog /home/"$USER"/Desktop/
echo "Your Report (filename clutchlog) is now available on your Desktop (/home/$USER/Desktop)"
CLUTCH=0
stage2
}

motlog ()
{
source datarefs/MOTloglist
mv MOTlog /home/"$USER"/Desktop/
echo "Your Report (filename MOTlog) is now available on your Desktop (/home/$USER/Desktop)"
MOT=0
stage2
}


oillog ()
{
source datarefs/Oilloglist
mv Oillog /home/"$USER"/Desktop/
echo "Your Report (filename Oillog) is now available on your Desktop (/home/$USER/Desktop)"
OIL=0
stage2
}

servicelog ()
{
source datarefs/Serviceloglist
mv servicelog /home/"$USER"/Desktop/
echo "Your Report (filename servicelog) is now available on your Desktop (/home/$USER/Desktop)"
SERVICE=0
stage2
}

brakes ()
{
source datarefs/Brakeloglist
mv Brakelog /home/"$USER"/Desktop/
echo "Your Report (filename Brakelog) is now available on your Desktop (/home/$USER/Desktop)"
BRAKES=0
stage2

}

chainlog ()
{
source datarefs/chainloglist
mv chainlog /home/"$USER"/Desktop/
echo "Your Report (filename chainlog) is now available on your Desktop (/home/$USER/Desktop)"
CHAIN=0
stage2
}

tyrelog ()
{
source datarefs/Tyreloglist
mv Tyrelog /home/"$USER"/Desktop/
echo "Your Report (filename Tyrelog) is now available on your Desktop (/home/$USER/Desktop)"
TYRE=0
stage2
}

clean ()
{
source datarefs/cleanloglist
mv cleanlog /home/"$USER"/Desktop/
echo "Your Report (filename cleanlog) is now available on your Desktop (/home/$USER/Desktop)"
CLEAN=0
stage2
}

engine ()
{
source datarefs/engineloglist
mv enginelog /home/"$USER"/Desktop/
echo "Your Report (filename enginelog) is now available on your Desktop (/home/$USER/Desktop)"
ENGINE=0
stage2
}


categselect ()
{

# For all intents and purposes the main menu of this script

clear
echo "Below is a list of reports that will be generated"
echo ""
if [ "$MOT" == "1" ]
then
echo "1 M.O.T entry = Yes"
else
echo "1 M.O.T entry = No"
fi
if [ "$CHAIN" == "1" ]
then
echo "2 Chain maintenance = Yes"
else
echo "2 Chain maintenance = No"
fi
if [ "$TYRE" == "1" ]
then
echo "3 Tyres = Yes"
else
echo "3 Tyres = No"
fi
if [ "$CLEAN" == "1" ]
then
echo "4 Cleaning = Yes"
else
echo "4 Cleaning = No"
fi
if [ "$ENGINE" == "1" ]
then
echo "5 Engine = Yes"
else
echo "5 Engine = No"
fi
if [ "$BRAKES" == "1" ]
then
echo "6 Brakes = Yes"
else
echo "6 Brakes = No"
fi
if [ "$SERVICE" == "1" ]
then
echo "7 Servicing = Yes"
else
echo "7 Servicing = No"
fi
if [ "$OIL" == "1" ]
then
echo "8 Oil Change = Yes"
else
echo "8 Oil Change = No"
fi
if [ "$CLUTCH" == "1" ]
then
echo "9 Clutch maintenance = Yes"
else
echo "9 Clutch maintenance = No"
fi
if [ "$FULL" == "1" ]
then
echo "10 Full Log = Yes"
else
echo "10 Full Log = No"
fi
if [ "$ALL" == "1" ]
then
echo "11 All Reports = Yes"
else
echo "11 All Reports = No"
fi

echo ""
echo "To toggle a report simply enter its number and press enter. If you are happy with the selection just press enter"
read categchange
if [ "$categchange" == "9" ]
then
if [ "$CLUTCH" == "1" ]
then
CLUTCH=0
else
CLUTCH=1
fi
categselect
fi

if [ "$categchange" == "1" ]
then
if [ "$MOT" == "1" ]
then
MOT=0
else
MOT=1
fi
categselect
fi



if [ "$categchange" == "8" ]
then
if [ "$OIL" == "1" ]
then
OIL=0
else
OIL=1
fi
categselect
fi

if [ "$categchange" == "7" ]
then
if [ "$SERVICE" == "1" ]
then
SERVICE=0
else
SERVICE=1
fi
categselect
fi

if [ "$categchange" == "6" ]
then
if [ "$BRAKES" == "1" ]
then
BRAKES=0
else
BRAKES=1
fi
categselect
fi


if [ "$categchange" == "5" ]
then
if [ "$ENGINE" == "1" ]
then
ENGINE=0
else
ENGINE=1
fi
categselect
fi

if [ "$categchange" == "4" ]
then
if [ "$CLEAN" == "1" ]
then
CLEAN=0
else
CLEAN=1
fi
categselect
fi

if [ "$categchange" == "3" ]
then
if [ "$TYRE" == "1" ]
then
TYRE=0
else
TYRE=1
fi
categselect
fi

if [ "$categchange" == "2" ]
then
if [ "$CHAIN" == "1" ]
then
CHAIN=0
else
CHAIN=1
fi
categselect
fi
if [ "$categchange" == "10" ]
then
if [ "$FULL" == "1" ]
then
FULL=0
else
FULL=1
fi
categselect
fi
if [ "$categchange" == "11" ]
then
if [ "$ALL" == "1" ]
then
ALL=0
else
ALL=1
fi
categselect
fi
if [ "$categchange" == "" ]
then
stage2
fi
echo "Sorry I didn't recognise that, please try again"
echo "It is currently case sensitive"
categselect
}

stage2 ()
{
if [ "$ALL" == "0" ]
then
all
fi
if [ "$CLUTCH" == "1" ]
then
clutchlog
fi

if [ "$MOT" == "1" ]
then
motlog
fi

if [ "$OIL" == "1" ]
then
oillog
fi

if [ "$SERVICE" == "1" ]
then
servicelog
fi

if [ "$BRAKES" == "1" ]
then
brakes
fi

if [ "$ENGINE" == "1" ]
then
engine
fi

if [ "$CLEAN" == "1" ]
then
clean
fi


if [ "$TYRE" == "1" ]
then
tyrelog
fi


if [ "$CHAIN" == "1" ]
then
chainlog
fi

if [ "$FULL" == "1" ]
then
fulllog
fi

# Once it has checked that all relevant variables have been satisfied, it moves to this bit


echo "Your requested reports have been generated"

# And leaves
goodbye
}

# Lets jump straight to the functions. No time for niceties ;-)
categselect