#!/bin/bash

#	Copyright 2005, IBM Corporation


#      Do report for one collaboration area, whose associated workflow is an item workflow.

#	1. Run the SQL command "select coa_name, coa_id from coa order by coa_id;"
#		in your WPC DB Admin, or sqlplus, window, 
#		to see a list of collab areas and their ids.
#
#	2. Find (the name of) the collab area you want to do this report for,
#		 and write down its id.
#		 (i.e. the values of its "coa_id" field).
#       Be sure the associated workflow of this collab area is an item workflow, and not a category workflow.
#
#	3.  Before running this script, replace the "7" in the sed command below with the collab area id (in quotes) 
#            of the collab area you want to clean.
#
#	4.  Before running this script, fill in the correct <db username>/<db password>@<db schema> in the sqlplus command below.
#
#
#	5. Output will be written to file report.txt
#
# Usage of the file
if [[ $# -ne 4 ]]
then
 echo "Usage "
 echo "doreport.sh --db=databasename --dbuser=dbusername --dbpassword=dbuserpassword --collabid=CollabAreaID"
 echo "Example: doreport.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1 --collabid=6"
 echo "  (Be sure the associated workflow of this collab area is an item, and not a category, workflow)"
  
 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
CollabID=`echo $4 |cut -d "=" -f2`;export CollabID


ReportFile="${CollabID}-{`date |awk '{print "report_item_ca_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`-.txt";export ReportFile
sed s/"clnCoaId"/"${CollabID}"/ create_views.sql > create_views_scratch.sql



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


-- set heading off
-- set line 10000
-- set wrap off
-- set newpage NONE


spool ${ReportFile}



@drop_views
@create_views_scratch
@procs
@report


# Clean up views and scratch files
@drop_views

EOF

rm create_views_scratch.sql

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

exit $?
 


