sqldate.sh

 


###
### sqldate.sh
###
###  Generate html tables w/links to ORACLE-APACHE stored procedures
###
###  Sample URL
###      http://domain/pls/SID/count_records?xdate=11-DEC-02
###
###
###  Usage
###     sh ./sqldate.sh domain SID procedure YYYY > procedure.html
###    


 if [ $# -lt 4 ]; then
    echo " "
    echo "Usage: sqldate.sh domain oracle_sid stored_procedure year "
    echo " "
    echo "For example: "
    echo " "
    echo "    sqldate.sh domain SID stored_procedure  2003"
    echo " "
    exit 1
 else
    domain=$1
    SID=$2
    proc=$3
    year=$4
 fi

ctr=3

echo "<html><head>"
echo "<META content=text/css http-equiv=Content-Style-Type>"
echo "<LINK href=\"../white.css\" rel=\"stylesheet\" type=\"text/css\">"
echo "<title>$SID - $domain - $proc - $SID - $year</title></head>"
echo "<body> <font class=grey2>"
    
echo "<center>"
echo "<h2>$SID $domain <br> $proc </h2>"

for month in `echo 1 2 3 4 5 6 7 8 9 10 11 12`
do

    header1=`cal $month $year | head -1 `

    z=`cal $month $year | wc -l`
    lines=`expr $z - 1`
    
    zyear=`echo $year | cut -c 3,4`
    
    
    case $month in
       1) zmonth="JAN" ;;
       2) zmonth="FEB" ;;
       3) zmonth="MAR" ;;
       4) zmonth="APR" ;;
       5) zmonth="MAY" ;;
       6) zmonth="JUN" ;;
       7) zmonth="JUL" ;;
       8) zmonth="AUG" ;;
       9) zmonth="SEP" ;;
       10) zmonth="OCT" ;;
       11) zmonth="NOV" ;;
       12) zmonth="DEC" ;;
    esac
    
    
    if [ $ctr = 3 ]
    then
        echo "<table cellpadding=10>"
        echo "<tr>"
        ctr=0
    fi

    echo "<td valign=top>"

    
    
    echo "<h3>$header1</h3>"
    
    echo "<table border=1>"
    
    x=0
    y=`cal $month $year | tail -$lines | sed "s/   / x /g"` 
    set $y
    while [ $# -gt 1 ]
    do     
    
        if [ "$1" = "x" ]
        then
            sun=`echo "<tr><td align=right>&nbsp;</td>"`
        else 
            if [ "$1" = "Su" ]
            then
                sun=`echo "<tr><th>Su</th>"`
            else
                xlen=`echo $1 | wc -m`
                if [ $xlen -eq 2 ]
                then
                   xday=`echo 0${1}`
                else
                   xday=$1
                fi
                sun=`echo "<tr><td align=right><a href=\"http://$domain/pls/$SID/$proc?xdate=${xday}-${zmonth}-${zyear}&xSID=$SID\">$1</a></td>"`
            fi
        fi
    
        if [ "$2" = "x" ] || [ "$2" = "" ]
        then
            mon=`echo "<td align=right>&nbsp;</td>"`
        else 
            if [ "$2" = "Mo" ]
            then
                mon=`echo "<th>Mo</th>"`
            else
                xlen=`echo $2 | wc -m`
                if [ $xlen -eq 2 ]
                then
                   xday=`echo 0${2}`
                else
                   xday=$2
                fi
                mon=`echo "<td align=right><a href=\"http://$domain/pls/$SID/$proc?xdate=${xday}-${zmonth}-${zyear}&xSID=$SID\">$2</a></td>"`
                
            fi
        fi
    
        if [ "$3" = "x" ] || [ "$3" = "" ]
        then
            tue=`echo "<td align=right>&nbsp;</td>"`
        else 
            if [ "$3" = "Tu" ]
            then
                tue=`echo "<th>Tu</th>"`
            else
                xlen=`echo $3 | wc -m`
                if [ $xlen -eq 2 ]
                then
                   xday=`echo 0${3}`
                else
                   xday=$3
                fi
                tue=`echo "<td align=right><a href=\"http://$domain/pls/$SID/$proc?xdate=${xday}-${zmonth}-${zyear}&xSID=$SID\">$3</a></td>"`
            fi
        fi
    
        if [ "$4" = "x" ] || [ "$4" = "" ]
        then
            wed=`echo "<td align=right>&nbsp;</td>"`
        else 
            if [ "$4" = "We" ]
            then
                wed=`echo "<th>We</th>"`
            else
                xlen=`echo $4 | wc -m`
                if [ $xlen -eq 2 ]
                then
                   xday=`echo 0${4}`
                else
                   xday=$4
                fi
                wed=`echo "<td align=right><a href=\"http://$domain/pls/$SID/$proc?xdate=${xday}-${zmonth}-${zyear}&xSID=$SID\">$4</a></td>"`
            fi
        fi
    
        if [ "$5" = "x" ] || [ "$5" = "" ]
        then
            thu=`echo "<td align=right>&nbsp;</td>"`
        else 
            if [ "$5" = "Th" ]
            then
                thu=`echo "<th>Th</th>"`
            else
                xlen=`echo $5 | wc -m`
                if [ $xlen -eq 2 ]
                then
                   xday=`echo 0${5}`
                else
                   xday=$5
                fi
                thu=`echo "<td align=right><a href=\"http://$domain/pls/$SID/$proc?xdate=${xday}-${zmonth}-${zyear}&xSID=$SID\">$5</a></td>"`
            fi
        fi
    
        if [ "$6" = "x" ] || [ "$6" = "" ]
        then
            fri=`echo "<td align=right>&nbsp;</td>"`
        else 
            if [ "$6" = "Fr" ]
            then
                fri=`echo "<th>Fr</th>"`
            else
                xlen=`echo $6 | wc -m`
                if [ $xlen -eq 2 ]
                then
                   xday=`echo 0${6}`
                else
                   xday=$6
                fi
                fri=`echo "<td align=right><a href=\"http://$domain/pls/$SID/$proc?xdate=${xday}-${zmonth}-${zyear}&xSID=$SID\">$6</a></td>"`
            fi
        fi
    
        if [ "$7" = "x" ] || [ "$7" = "" ]
        then
            sat=`echo "<td align=right>&nbsp;</td></tr>"`
        else 
            if [ "$7" = "Sa" ]
            then
                sat=`echo "<th>Sa</th></tr>"`
            else
                xlen=`echo $7 | wc -m`
                if [ $xlen -eq 2 ]
                then
                   xday=`echo 0${7}`
                else
                   xday=$7
                fi
                sat=`echo "<td align=right><a href=\"http://$domain/pls/$SID/$proc?xdate=${xday}-${zmonth}-${zyear}&xSID=$SID\">$7</a></td></tr>"`
            fi
        fi
    
    
        echo $sun 
        echo $mon 
        echo $tue 
        echo $wed 
        echo $thu 
        echo $fri 
        echo $sat 
    
        shift
        shift
        shift
        shift
        shift
        shift
        shift
    
    done
    echo "</table>"
    echo "</td>"
    
    if [ $ctr = 2 ]
    then
        echo "</tr></table>"
    fi

    ctr=`expr $ctr + 1`

done
echo "</center>"
    
echo "</body>"
echo "</html>"