#!/bin/bash
################################
###gestione database libri
###by rebellion
################################
###dipendenze: zenity, gtkdialog
################################
## controllo dipendenze
if [ ! -e "/usr/bin/zenity" ] || [ ! -e "/usr/bin/gtkdialog" ] ; then dip=""
if [ ! -e "/usr/bin/zenity" ] ; then dip=$dip" zenity" ; fi ; if [ ! -e "/usr/bin/gtkdialog" ] ; then dip=$dip" gtkdialog" ; fi
zenity --error --width=500 --height=100 --text="Errore: dipendenze non soddisfatte, installa $dip. Applicazione terminata." ; if [ $? -eq 1 ] ; then gnome-terminal --geometry=35x6 --hide-menubar --title="ERRORE dipndenze" -e 'bash -c "echo "" ; echo --------------------------;echo installa: '$dip'; echo --------------------------; echo app terminata, premi invio..; read"' ; fi
exit 0
fi
function inser () {
while [ "$sceltains" != "Cancel" ] && [ "$sceltains" != "abort" ]
do
I=$IFS ; IFS=""
for STATEMENTS in $(gtkdialog --program INSERIMENTO); do
eval $STATEMENTS
done
IFS=$I
if [ "$formato" = "" ]; then formato="brossura"; else formato=${formato##* }; fi
sceltains=$EXIT
if [ "$EXIT" = "OK" ] && ([ -n "$autore" ] && [ -n "$titolo" ])
then
if [ -z "$genere" ] ; then genere="-" ; fi ; if [ -z "$anno" ] ; then anno="-" ; fi ; if [ -z "$editore" ] ; then editore="-" ; fi ; if [ -z "$note" ] ; then note="-" ; fi
num=$(tail -1 $(pwd)/database | awk '{print$8}') ; num=$((${num:0: -1}+1))
echo ${titolo// /§§} ${autore// /§§} ${genere// /§§} ${anno// /§§} ${editore// /§§} $formato ${note// /§§} $num"¶" >> $(pwd)/database
fi
done
} ; export -f inser
function ricer () {
if [ -e $(pwd)/database ] ; then
while [ "$sceltaricer" != "Cancel" ] && [ "$sceltaricer" != "abort" ]
do
I=$IFS ; IFS=""
for STATEMENTS in $(gtkdialog --program RICERCA); do
eval $STATEMENTS
done
IFS=$I
if [ "$formato" != "" ] ; then formato=${formato##* } ; fi
sceltaricer=$EXIT
if [ "$EXIT" != "Cancel" ] && [ "$EXIT" != "abort" ] ; then
if [ "$EXIT" = "OK" ]
then
var_ric=()
risultato=()
arry=("$titolo" "$autore" "$genere" "$anno" "$editore" "$formato")
for ((iii=0;iii<=5;iii++)) ; do
ii=$(($iii+1))
if [ -n "${arry[$iii]}" ]
then
readarray var_ric <<< "$(cat $(pwd)/database | awk -v x=$ii '{print$x}' | grep "${arry[$iii]}" | sort | uniq)"
lungh=$((${#var_ric[@]}-1))
for ((i=0;i<=$lungh;i++)) ; do var_ric[$i]=${var_ric[$i]:0: -1} ; risultato+=("$(cat $(pwd)/database | awk -v x=$ii '$x=="'${var_ric[$i]}'"')") ; done ; var_ric=()
else
risultato+=("$(cat $(pwd)/database)")
fi
done
risultato=("${risultato[@]// /§§§}")
result=$(echo "${risultato[@]}" | tr " " "\n" | sort | uniq -c | awk '$1=="6"')
result=${result//§§§/ }
if [ -z "$result" ]
then
zenity --notification --text="nessuna corrispondenza trovata."
else
stamp=()
results=${result:0: -1}
lung=$(echo $results | grep -o "¶" | wc -l)
for ((i=0;i<=$lung;i++))
do
if [ "$i" -lt "$lung" ] ; then arr=${results##*¶} ; else arr=$results ; fi
cod=$(echo "$arr" | awk '{print$9}') ; if [ "$i" -lt "$lung" ] ; then cod=${cod:1} ; fi
titl=$(echo "$arr" | awk '{print$2}')
titl=${titl//§§/ } ; if [ "$i" -lt "$lung" ] ; then titl=${titl:1} ; fi
auth=$(echo "$arr" | awk '{print$3}')
auth=${auth//§§/ } ; if [ "$i" -lt "$lung" ] ; then auth=${auth:1} ; fi
stamp+=( False "$titl" "$auth" " $cod")
if [ "$i" -lt "$lung" ] ; then
arrs=${#arr}
results=${results:0: -$arrs}
results=${results:0: -1}
fi
done
scel=0
while [ "$scel" = "0" ] ; do
scelt=$(zenity --list --title="risultato ricerca: $(($lung+1)) records" --text="seleziona per visualizzare" --width=600 --height=650 --checklist --separator=" " --print-column=4 --column="" --column="TITOLO" --column="AUTORE" --column="COD" "${stamp[@]}")
scel=$?
if [ "$scel" -eq 0 ] && [ -n "$scelt" ]
then
EXIT=""
contas=1 ; conta=$(echo $scelt | wc -w)
while [ "$EXIT" != "torna al menù" ] && [ "$EXIT" != "abort" ] && [ "$conta" -ne 0 ]
do
sceltss=$(echo $scelt | awk -v x=$contas '{print$x}')
show=$(cat $(pwd)/database | awk '$8=="'$sceltss"¶"'"')
show1=$(echo "$show" | awk '{print$1}') ; show2=$(echo "$show" | awk '{print$2}') ; show3=$(echo "$show" | awk '{print$3}') ; show4=$(echo "$show" | awk '{print$4}') ; show5=$(echo "$show" | awk '{print$5}') ; show6=$(echo "$show" | awk '{print$6}') ; show7=$(echo "$show" | awk '{print$7}') ; show1=${show1//§§/ } ; show2=${show2//§§/ } ; show3=${show3//§§/ } ; show4=${show4//§§/ } ; show5=${show5//§§/ } ; show6=${show6//§§/ } ; show7=${show7//§§/ }
export modifica='
<window title="Visualizzazione Ricerca">
<vbox>
<frame codice: '"$sceltss"'>
<hbox>
<frame Titolo>
<entry max_length="25">
<default>'"$show1"'</default>
<variable>tit</variable>
<visible>disabled</visible>
</entry>
<checkbox draw_indicator="false">
<label>attiva/disattiva la modifica</label>
<action>if true enable:tit</action>
<action>if false disable:tit</action>
</checkbox>
</frame>
<frame Autore>
<entry max_length="25">
<default>'"$show2"'</default>
<variable>aut</variable>
<visible>disabled</visible>
</entry>
<checkbox draw_indicator="false">
<label>attiva/disattiva la modifica</label>
<action>if true enable:aut</action>
<action>if false disable:aut</action>
</checkbox>
</frame>
</hbox>
<hbox>
<frame Genere>
<entry max_length="25">
<default>'"$show3"'</default>
<variable>gen</variable>
<visible>disabled</visible>
</entry>
<checkbox draw_indicator="false">
<label>attiva/disattiva la modifica</label>
<action>if true enable:gen</action>
<action>if false disable:gen</action>
</checkbox>
</frame>
<frame Anno>
<entry max_length="4">
<default>'"$show4"'</default>
<variable>ann</variable>
<visible>disabled</visible>
</entry>
<checkbox draw_indicator="false">
<label>attiva/disattiva la modifica</label>
<action>if true enable:ann</action>
<action>if false disable:ann</action>
</checkbox>
</frame>
</hbox>
<hbox>
<frame Editore>
<entry max_length="25">
<default>'"$show5"'</default>
<variable>edi</variable>
<visible>disabled</visible>
</entry>
<checkbox draw_indicator="false">
<label>attiva/disattiva la modifica</label>
<action>if true enable:edi</action>
<action>if false disable:edi</action>
</checkbox>
</frame>
<frame Formato>
<entry max_length="8">
<default>'"$show6"'</default>
<variable>for</variable>
<visible>disabled</visible>
</entry>
<checkbox draw_indicator="false">
<label>attiva/disattiva la modifica</label>
<action>if true enable:for</action>
<action>if false disable:for</action>
</checkbox>
</frame>
</hbox>
<hbox>
<frame Note>
<entry max_length="25">
<default>'"$show7"'</default>
<variable>not</variable>
<visible>disabled</visible>
</entry>
<checkbox draw_indicator="false">
<label>attiva/disattiva la modifica</label>
<action>if true enable:not</action>
<action>if false disable:not</action>
</checkbox>
</frame>
</hbox>
</frame>
<hbox>
<button>
<label>applica modifica</label>
</button>
<button>
<label>elimina</label>
</button>
<button>
<label>successivo</label>
</button>
<button>
<label>precedente</label>
</button>
<button>
<label>torna al menù</label>
</button>
</hbox>
</vbox>
</window>
'
I=$IFS
IFS=""
for mod in $(gtkdialog --program modifica) ; do
eval $mod
done
IFS=$I ; echo $mod > filer
if [ "$EXIT" = "precedente" ] ; then contas=$((contas+1)) ; elif [ "$EXIT" = "successivo" ] ; then contas=$((contas+1)) ; fi
if [ "$contas" -gt "$conta" ] ; then contas=1 ; elif [ "$contas" -lt "$conta" ] ; then contas=$conta ; fi
done
fi
done
fi
fi
fi
done
else zenity --notification --window-icon="error" --text="nessun database presente."
fi
} ; export -f ricer
function riord () {
funz="riordino"
} ; export -f riord
export RICERCA='
<window title="GESTIONE LIBRERIA">
<vbox>
<frame ricerca titolo>
<entry max_length="25">
<variable>titolo</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame ricerca autore>
<entry max_length="25">
<variable>autore</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame ricerca genere>
<entry max_length="25">
<variable>genere</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame ricerca editore>
<entry max_length="25">
<variable>editore</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame ricerca anno 1a pubblicazione>
<entry max_length="4">
<variable>anno</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame ricerca formato>
<table>
<width>450</width><height>110</height>
<variable>formato</variable>
<item>() brossura</item>
<item>() rilegato</item>
<item>() digitale</item>
</table>
</frame>
<hbox>
<button cancel></button>
<button ok></button>
</hbox>
</vbox>
</window>
'
export INSERIMENTO='
<window title="GESTIONE LIBRERIA">
<vbox>
<frame inserimento Titolo>
<entry max_length="25">
<variable>titolo</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame inserimento Autore>
<entry max_length="25">
<variable>autore</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame inserimento Genere>
<entry max_length="25">
<variable>genere</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame Inserimento Editore>
<entry max_length="25">
<variable>editore</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame Inserimento Anno 1a Pubblicazione>
<entry max_length="4">
<variable>anno</variable>
<width>450</width><height>30</height>
</entry>
</frame>
<frame Formato>
<table>
<width>450</width><height>110</height>
<variable>formato</variable>
<item>() brossura</item>
<item>() rilegato</item>
<item>() digitale</item>
</table>
</frame>
<frame inserimento Note>
<edit editable="true">
<variable>note</variable>
<width>450</width><height>150</height>
</edit>
</frame>
<hbox>
<button cancel></button>
<button ok></button>
</hbox>
</vbox>
</window>
'
export MAIN_DIALOG='
<window decorated="false" title="GESTIONE ARCHIVIO LIBRERIA" width-request="500" height-request="500">
<vbox>
<frame>
<text>
<label>"GESTIONE ARCHIVIO LIBRERIA"</label>
</text>
</frame>
<frame>
<text>
<label>"Inserimento dati"</label>
</text>
<button>
<label>inserimento</label>
<action>inser</action>
</button>
</frame>
<frame>
<text>
<label>"Ricerca (e modifica) libri per campi"</label>
</text>
<button>
<label>ricerca</label>
<action>ricer</action>
</button>
</frame>
<frame>
<text>
<label>"Riordina il database"</label>
</text>
<button>
<label>riordina</label>
<action>riord</action>
</button>
</frame>
<hbox>
<button cancel></button>
</hbox>
</vbox>
</window>
'
while [ "$scelta" != "Cancel" ] && [ "$scelta" != "abort" ]
do
scelta=$(gtkdialog --program=MAIN_DIALOG)
scelta=${scelta:0: -1} ; scelta=${scelta##*=} ; scelta=${scelta:1}
done
exit 0