#!/bin/bash
hh=`hostname`
input=`dialog --keep-window --begin 2 2 --inputbox "Enter User Name for DB: " 7 30 BHM\
--and-widget --keep-window --begin 9 2 --insecure --passwordbox "Enter DB Password" 7 30 \
--and-widget --keep-window --begin 16 2 --inputbox "Enter MYSQL Server address" 7 40 $hh 2>&1 > /dev/tty`
#--and-widget --keep-window --begin 23 2 --inputbox "Enter IsfHostName : " 7 30 2>&1 > /dev/tty`

usr="$(echo $input | cut -d" " -f1)"
pass="$(echo $input | cut -d" " -f2)"
host="$(echo $input | cut -d" " -f3)"
#isfHost="$(echo $input | cut -d" " -f4)"

#input=`dialog --keep-window --begin 2 2 --inputbox "Enter IsfId: " 7 30 \
#--and-widget --keep-window --begin 9 2 --inputbox "Enter ProductId" 7 30 2>&1 > /dev/tty`

#isfId="$(echo $input | cut -d" " -f1)"
#productId="$(echo $input | cut -d" " -f2)"

#pass=`echo -n "$pass"|md5sum`
#pass=${pass:0:32};

	CMD=`mysql -u $usr -p$pass -h $host BHM -e"create table drInfo (doc_Id VARCHAR(10), passWord VARCHAR(20), email VARCHAR(30), firstName VARCHAR(15), lastName VARCHAR(15), reg_date DATE, addressPerm VARCHAR(100), medLiscNum VARCHAR(20), spclZtion VARCHAR(15), conNumber VARCHAR(15), PRIMARY KEY(doc_Id)); create table userInfo (user_Id VARCHAR(10), docId VARCHAR(10), passWord VARCHAR(20), email VARCHAR(30), firstName VARCHAR(15), lastName VARCHAR(15), reg_date DATE, dateBirth DATE, seX VARCHAR(1), password_clear VARCHAR(1), logins VARCHAR(5), addressTemp VARCHAR(100), addressPerm VARCHAR(100), age VARCHAR(2), drName VARCHAR(25), conNumber VARCHAR(15), height VARCHAR(3), weight VARCHAR(3), occuPation VARCHAR(10), BMI VARCHAR(10), PRIMARY KEY(user_Id), FOREIGN KEY(docId) REFERENCES drInfo(doc_Id) );create table dataInfo( docId VARCHAR(50), userId VARCHAR(50), totEnerExp VARCHAR(50), numSteps VARCHAR(50), lyingDownTime VARCHAR(50), sleepTime VARCHAR(50), physActivityDur VARCHAR(50), sedenTary VARCHAR(10), modActivity VARCHAR(10), vigrousActivity VARCHAR(10), veryVigActivity VARCHAR(10), dataOfData VARCHAR(50), FOREIGN KEY(docId) REFERENCES drInfo(doc_Id) , FOREIGN KEY(userId) REFERENCES userInfo(user_Id)); create table sendComment(comment VARCHAR(2000), docId VARCHAR(15), userId VARCHAR(15), timeOfComment TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY(docId) REFERENCES drInfo(doc_Id), FOREIGN KEY(userId) REFERENCES userInfo(user_Id));" > temp 2>&1`

stat=`grep -c ERROR temp`
msg=`grep ERROR temp`
rm temp

if [ $stat != 0 ]; then
{
	dialog --colors --msgbox "\Z1\Zb\ZuERROR IN OPERATION!! \\n $CMD \\n $msg" 20 30
}
else
{
	dialog --infobox "Data Created " 5 30
	sleep 1
}
fi
