#!/bin/bash
# -----------------------------------------------
# Patch for extra char fix
# Path id:  2.0.1.1
# Date: DEC.26.2005
#
# Developer: Vigyan Kaushik (vkaushik@oramon.org)
#
# Instructions: Copy this patch file to oramon/lib dir
# and change the permissions to executable (e.g. 'chmod u+x omp_2011.sh')
# Just run it once and follow the instraction on the screen.
# ------------------------------------------------

# Function to fix the bug.
function extrachar
{
# Fix for index.php file in the oramon root dir.
mv ../index.php ../index.php.old
# Replacing char '&' with null
sed 's/&$arr/$arr/g' ../index.php.old > ../index.php
# done.

# Fix for view.php file in the oramon root dir.
mv ../admin/viewdb.php ../admin/viewdb.php.old
# Replacing char '&' with null
sed 's/&$arr/$arr/g' ../admin/viewdb.php.old > ../admin/viewdb.php
# done.

# Fix for all the lib files in oramon/lib dir.
for file in *.php; do
mv $file $file.old
sed 's/&$arr/$arr/g' $file.old > $file
#rm -f $file.old
done
echo "Completed. If there are no errors, then delete all the old files using rm -f *.old"
}


# Clear the screen
clear
echo ""
echo ""
echo "--------Please Read-----"
echo ""
echo "You are about to run patch 2.0.1.1 fix for oramon 2.0.1 release. It is highly recommended"
echo "that you take backup of the oramon root dir before you start the upgrade."
echo ""
echo ""

echo -n  "Have you taken backup of oramon files? ( y/n ) : "
read text
if [ -z $text ]; then
echo "Please select an answer"
elif [ $text = "y" ] ; then
echo "Applying patch.............."
extrachar
elif [ $text = "n" ] ; then
echo -n "Do you want to take backup now? ( y/n ) : "
read text1
if [ -z $text1 ]; then
echo "Please select an awnser"
elif [ $text1 = "y" ]; then
echo -n "Enter the path of root dir of oramon e.g. /var/www/html/oramon : "
read text2
echo -n "Enter the path for the backup dir e.g. /tmp : "
read text3
if [ -z $text2 ] ; then
text2=/var/www/html/oramon
fi
if [ -z $text3 ] ; then
text3=/tmp
fi
echo "Creating backup tar file $text2/oramon.2.0.1.backup.tar"
tar -cvf $text3/oramon.2.0.1.backup.tar $text2
fi
echo "Applying patch............"
extrachar
fi
