#!/bin/bash

#	Copyright 2005, IBM Corporation


#      Do report for all collaboration area.


#
# Usage of the file
if [[ $# -ne 3 ]]
then
 echo "Usage "
 echo "doreportall.sh --db=databasename --dbuser=dbusername --dbpassword=dbuserpassword"
 echo "Example doreportall.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1"
  
 exit 0
fi

# Declare the variables
DBName=`echo $1 |cut -d "=" -f2`;export DBName
DBUSER=`echo $2 |cut -d "=" -f2`;export DBUSER
DBUserPassword=`echo $3 |cut -d "=" -f2`;export DBUserPassword

if [ "$TOP" ]
then
mkdir ${TOP}/logs
mkdir ${TOP}/logs/reportLog
else
mkdir logs
mkdir logs/reportLog
fi

#
sqlplus ${DBUSER}/${DBUserPassword}@${DBName} <<EOF

set heading off;
set pagesize 0;
set feedback off;
spool temp_catalog.txt;
SELECT COA_ID FROM COA where COA_CONTAINER_TYPE='CATALOG';
spool off;
spool temp_category_tree.txt;
SELECT COA_ID FROM COA where COA_CONTAINER_TYPE='CATEGORY_TREE';
spool off;

EOF

# Do the item-workflow collab areas
cat temp_catalog.txt| grep -v SQL > collabId.txt
for i in `cat collabId.txt`
do
echo " "
echo "REPORT FOR ITEM-WORKFLOW COLLABORATION AREA ${i}"
echo " "
./doreport.sh --db="${DBName}" --dbuser="${DBUSER}"  --dbpassword="${DBUserPassword}" --coaid="${i}"
done

# Do the category-workflow collab areas
cat temp_category_tree.txt| grep -v SQL > collabId.txt
for i in `cat collabId.txt`
do
echo " "
echo "REPORT FOR CATEGORY-WORKFLOW COLLABORATION AREA ${i}"
echo " "
./doreport_category.sh --db="${DBName}" --dbuser="${DBUSER}"  --dbpassword="${DBUserPassword}" --coaid="${i}"
done

rm temp_catalog.txt
rm temp_category_tree.txt
rm collabId.txt

if [ "$TOP" ]
then
rm ${TOP}/logs/reportLog/lastreportall.txt
echo "`date |awk '{print "lastReport_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`" >> ${TOP}/logs/reportLog/lastreportall.txt
else
rm logs/reportLog/lastreportall.txt
echo "`date |awk '{print "lastReport_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`" >> logs/reportLog/lastreportall.txt
fi


exit $?

