#/bin/bash
# ver 4.51 2014-03-11 12:03:08 
nexttime=5000 #másodpercként mutatja az új képet
EMAIL=erdav@freemail.hu ; SIZE=1280
if  ! which  convert ; then
zenity --error --text='Programot kell telepiteni\nKérni fogom a jelszót'
sudo apt-get -y install imagemagick
fi
#zenity --error --text='Válogasd ki a képeket egy külön könyvtárba! \n Jegyezd meg a mappa nevét!\nKattints az OK gombra!'
#cel=$(zenity --file-selection --directory)
#cd $cel
function szamol {
export DB=1
DB=$DB+1
for i in *.jpg ; do
 let DB=$DB+1
done
}
if [ -e index.php ]; then
 echo -e "\tEgyszer már lefutott" ; echo -e "\tEz funkció még nem mködik"
else
for file in *.JPG ; do
  if [ "$file" == '*.JPG' ] ; then  
    echo "nincs nagybetüs .JPG" ; break 
  fi 
    echo $file | tr " " "_" | sed 's/.JPG$/.jpg/' | xargs mv -v "$file" 
done 
echo atalakitottam kisbetusre
for file in *.jpg ; do
   if [ "$file" == '*.jpg' ] ; then  
    echo "nincs kisbetüs .JPG" ; exit 1 ; 
  fi 
 if [ `echo $file | grep -v [a-zA-Z0-9._]` ] ; then
file2=
  echo `date +%x%H%M%S`$file | tr " -" "_"  | tr  -dc "[a-zA-Z0-9._:]" | xargs mv -v "$file" 
  else
  echo 'nem kell valtoztatni' 
  fi
done
for file in *.jpg ; do
 mv -v "$file" `echo $file | tr " " "_" |  tr -dc  "[a-zA-Z0-9._]" `
done
mkdir print
mkdir big
cd print
mv -v ../*.jpg .

szamol 
# echo 'Ez itt a nulladik kep <a href=index.php> Vissza    </a>' > 0.s.html
# MOST=1
echo .
pwd
(
for i in *.jpg 
do
  let MOST=$MOST+1 ;
  let NEXTIMG=$MOST+1
  echo '<html><head>' > ../$MOST.html
  echo '<META HTTP-EQUIV="Content-Type" CONTENT="text/html"; charset="utf-8">' >> ../$MOST.html
  echo -n "  <script LANGUAGE=\"JavaScript\">
  function kovi() {
  setTimeout(\" window.location.href='" >> ../$MOST.html
  echo -n $NEXTIMG >> ../$MOST.html
  echo ".html'\",$nexttime);} </script>
  </head><body bgcolor=black text=white link=white vlink=yellow  onload=\"kovi();\">" >> ../$MOST.html 
  echo '<div style="position: absolute; left: 18px; top: 25px; background-color: rgb(51, 0, 0);">'  >> ../$MOST.html
  echo '<a href="../index.php" title="azaz visszalépés a kicsi képekre"> Vissza a főoldalra  </a>' >> ../$MOST.html
  echo '</div>'  >> ../$MOST.html
  
  if [ "$1" != "--print" ] ; then
  echo '<div style="position: absolute; left: 86px; top: 25px; background-color: rgb(0, 0, 0);">'  >> ../$MOST.html
  let last=MOST-1 
  echo '<div style="position: absolute; left: 400px; top: 5px; background-color: rgb(51, 10, 0);">'  >> ../$MOST.html
  echo "<a href=$last.s.html title="azaz visszalépés az eloző képre"> Last clip  </a>" >> ../$MOST.html
  echo '</div>'  >> ../$MOST.html
 
    echo "<a href=print/$i > Print size </a>" >> ../$MOST.html
  echo '</div>'  >> ../$MOST.html
  echo '<div style="position: absolute; left: 600px; top: 25px; background-color: rgb(255, 0, 0);">'  >> ../$MOST.html
    echo "<a href=$MOST.s.html > Stop </a>" >> ../$MOST.html
  echo '</div>'  >> ../$MOST.html
#   else #   echo $1 #   echo dollar1 egyenlo no printtel
  fi
  echo "<a href=$NEXTIMG.html title=\"Kattints!\"><img src=\"big/$i\" width=99% ></a>" >> ../$MOST.html
  echo '<img alt="" src="12345.gif" style="border: 0px solid ; position: absolute; left: 700px; top: 25px;">'  >> ../$MOST.html
  echo '</body></html>' >> ../$MOST.html

  echo '<html><head>' > ../$MOST.s.html
  echo '<META HTTP-EQUIV="Content-Type" CONTENT="text/html"; charset="utf-8">' >> ../$MOST.s.html
  echo "</head><body bgcolor=black text=white link=white vlink=yellow  >" >> ../$MOST.s.html 

  echo '<a href="../index.php" title="azaz visszalépés a kicsi képekre"> Vissza a fő oldalra  </a>' >> ../$MOST.s.html
  if [ "$1" != "--print" ] ; then
    echo "<a href=print/$i > Print size </a>" >> ../$MOST.s.html    
    echo "<a href=$NEXTIMG.html > Dia film START :) </a>" >> ../$MOST.s.html
  fi
  echo "<a href=$last.s.html title="azaz visszalépés a képre"> last clip  </a>" >> ../$MOST.s.html
  echo "<br><a href=$NEXTIMG.s.html title=\"Kattints!\"><img src=\"big/$i\" width=95% ></a>" >> ../$MOST.s.html
  echo '</body></html>' >> ../$MOST.s.html

  nice -n17  convert "$i" -resize $SIZE ../big/"$i" ;  nice -n17  convert ../big/"$i" -resize 200 ../"$i"

#  let MOST=$MOST+1 ;
  let SZAZALEK=$MOST*100/$DB ; echo  "$SZAZALEK"

done
echo "most=$MOST" > /tmp/most.log
  let MOST=$MOST+1;
  echo '<html><head>' > ../$MOST.html
  echo '<META HTTP-EQUIV="Content-Type" CONTENT="text/html"; charset="utf-8">' >> ../$MOST.html
  echo -n "  <script LANGUAGE=\"JavaScript\">
  function kovi() {
  setTimeout(\" window.location.href='" >> ../$MOST.html
  echo -n '1.html' >> ../$MOST.html
  echo "'\",3000);} </script></head><body bgcolor=black text=white link=white vlink=yellow  onload=\"kovi();\">" >> ../$MOST.html 


 echo '<h1> end </h1>' >> ../$MOST.html
 echo '<h2> Ez itt az internet vege! Finish ! </h2> ' >> ../$MOST.html



) |
 zenity --progress \
          --title="Képek módosítása honlap készítés céljából. Utána már csak fel kell másolni"  \
          --text="Folyamatban van. Nagyon folyamatban van. Komolyan..." \
          --percentage=0 \
         --auto-close \
         --auto-kill \
          #--pulsate 

#  echo '<html><head>' > ../$MOST.html
#  echo '<META HTTP-EQUIV="Content-Type" CONTENT="text/html"; charset="utf-8">' >> ../$MOST.html
#  echo -n "  <script LANGUAGE=\"JavaScript\">
#  function kovi() {
#  setTimeout(\" window.location.href='" >> ../$MOST.html
#  echo -n '1.html' >> ../$MOST.html
#  echo "'\",4000);} </script></head><body bgcolor=black text=white link=white vlink=yellow  onload=\"kovi();\">" >> ../$MOST.html 


# echo '<h1> end </h1>' >> ../$MOST.html
# echo '<h2> Ez itt az internet vege! Finish ! </h2> ' >> ../$MOST.html


echo -e "\t Kész van a képek módosítása!"
#cp index.html index_old.html
#cp index.php index_old.php
cd ..
pwd | xargs basename | tr "_" " " > /tmp/mkweb.tmp
 read HEAD < /tmp/mkweb.tmp
echo $HEAD
echo -n 'Kérem írja be a honlap fõoldalán lévõ szöveget! '
read -t20 HEAD2
if [  "$HEAD2" ] ; then
  HEAD=$HEAD2
fi
echo '<br>' > /tmp/mkweb_foot
echo '<html><head>' > index.php
echo '<META HTTP-EQUIV="Content-Type" CONTENT="text/html"; charset="utf-8" >' >> index.php
echo "<?php \$f=fopen('count.txt','r');" >> index.php

echo "if(! \$f) { \$num=0; \$f=fopen('count.txt','a'); } else "  >> index.php

echo " \$num=fread(\$f,11); fclose(\$f); \$num ++ ;
      \$f=fopen('count.txt','w'); fwrite(\$f,\$num,11); fflush(\$f); fclose(\$f);
      \$f=fopen('date.html','a'); fwrite(\$f,\$num . date(' Y-m-d H:i:s ') . gethostbyaddr( getenv('REMOTE_ADDR')) . \"<br>\\n\" ,199); fflush(\$f); fclose(\$f); ?>"  >> index.php
echo '</head>' >> index.php
echo '<body bgcolor="maroon" text="gold" link="silver" vlink="seagreen" alink="deepskyblue" >' >> index.php
#echo -n 'Kérem írja be az e-mail címét! '
#read EMAIL
echo "<p align=right><a href=\"date.html\"> <?php echo \$num ?></a> <a href=mailto:$EMAIL> e-mail </a> <a href=../index.php> vissza </a></p>" >> index.php
MOST=1
for file in *.jpg ; do

if [ `identify -format "%[fx:w]"  $file ` -ge `identify -format "%[fx:h]"  $file` ]; then
# echo "\nifekvo";  
 echo "<a href=\"$MOST.html\" onClick=\"window.open('$MOST.html','_self','toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=1,width=1024,height=768');return false;\" > <img src=\"$file\" border=0  hspace=0 vspace=0 ></a>" >> index.php

else 
# echo "\nallo" ; 
 echo "<a href=\"$MOST.html\" onClick=\"window.open('$MOST.html','_self','toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=1,width=1024,height=768');return false;\" > <img src=\"$file\" border=0  hspace=0 vspace=0 ></a>" >> /tmp/mkweb_foot 
fi
  let MOST=$MOST+1
#  echo -e "\b\b\b\b\b $MOST %"
done
cat /tmp/mkweb_foot >> index.php
echo '</body></html>' >> index.php
#cp index.php index.html
#rm index.php
fi
echo -e "\a"
espeak -vhu "Kész van a másolás"
zenity --error --text='Kész van\nsikerült'

