# /bin/bash/
# Script to generate html codes for e97 photopage
# Author: Madurasinghe A.M. (E/97/160)
# Email: madura@cs.pdn.ac.lk
# Date : 10.02.2003
if [ $# -ne 2 ]
 then 
   echo "Usage: $0 Rows Columns"
   exit
fi

no=1 
count=0 
rowcount=0
total=0
lines=`wc -l name.txt | awk -F " " {'print $1'}` 
rows=$1
columns=$2
items=`expr $rows \* $columns`
      
if test `expr $lines % $items` -eq 0
   then 
     files=`expr $lines / $items`
   else 
     files=`expr $lines / $items + 1`
fi
echo
echo "Total No of Photos : $lines"
echo "Total No of HTML Pages : $files"
echo
echo -n "Processing... "
for i in `cat name.txt | cut -c 1-5`
  do
    total=`expr $total + 1`
    if test -f photo$no.html 
       then 
         echo >> photo$no.html
       else 
      #   echo
      #   echo -n "Generating File $no  "
         cat header.txt > photo$no.html
    fi

    name=`cat name.txt | grep $i | awk -F " " {'print $3 " " $2'}`
   
    if test $count -eq 0
      then 
        echo "<tr>" >> photo$no.html
    fi

    count=`expr $count + 1`
    #echo -n "##"  
    echo "       <td>
       <p align = \"center\"><img src=\"/image/$i.jpg\">
       <p align = \"center\"><b>$name</b></p>
       </td>" >> photo$no.html
       
        completed=`expr $total \* 100 / $lines`
        if [ $completed -lt 10 ]
          then echo -n "0"  
        fi   
        echo -n "$completed% completed."
        echo -en "\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
    
    if [ $count -eq $columns ] || [ $total -eq $lines ]
       then 
         echo "</tr>" >> photo$no.html
         count=0 
         rowcount=`expr $rowcount + 1`
    fi
 
    if [ $rowcount -eq $rows ] || [ $total -eq $lines ]
     then
     
      j=1
      echo "<tr align=center>" >> photo$no.html   
      echo "<td colspan=6>" >> photo$no.html

      if test $no -ne 1
        then 
         echo "<a href = photo`expr $no - 1`.html>Previous</a>" >> photo$no.html
      fi

      while [ $j -lt `expr $files + 1` ]
        do
         if test $no -eq $j
           then
             echo $no >> photo$no.html
           else
             echo "<a href = photo$j.html>$j</a>" >> photo$no.html
         fi
         j=`expr $j + 1` 
        done

      if test $no -ne $files
        then 
          echo "<a href = photo`expr $no + 1`.html>Next</a>" >> photo$no.html
      fi
    
      echo "</td></tr>" >> photo$no.html
      cat footer.txt >> photo$no.html
      rowcount=0
      no=`expr $no + 1`
    fi
  done
echo -e "\n"




BACK

Mail your comment to Madurasinghe Attanayake