#
# FUNKTION: Datei für die Erstellung, Einfügung bzw. Löschung der Bildtitel.
#
INC_NAME_PICTURE_TITLE='inc_tools_picture_title.txt'
GALLERY_MESSAGE_PLEASE_WAIT=${GALLERY_MESSAGE_PLEASE_WAIT:='PLEASE WAIT .....'}

# Einträge des Menü's
TOOLS_MENUE_PICTURE_TITLE_HEAD_LINE=${TOOLS_MENUE_PICTURE_TITLE_HEAD_LINE:='EMPTY'}
TOOLS_MENUE_VALUE_BREAK=${TOOLS_MENUE_VALUE_BREAK:='EMPTY'}
TOOLS_MENUE_PROGRAM_STOP=${TOOLS_MENUE_PROGRAM_STOP:='EMPTY'}
TOOLS_MENUE_PICTURE_TITLE_VALUE_1=${TOOLS_MENUE_PICTURE_TITLE_VALUE_1:='EMPTY'}
TOOLS_MENUE_PICTURE_TITLE_VALUE_2=${TOOLS_MENUE_PICTURE_TITLE_VALUE_2:='EMPTY'}
TOOLS_MENUE_PICTURE_TITLE_VALUE_3=${TOOLS_MENUE_PICTURE_TITLE_VALUE_3:='EMPTY'}
TOOLS_MENUE_PICTURE_TITLE_VALUE_4=${TOOLS_MENUE_PICTURE_TITLE_VALUE_4:='EMPTY'}
TOOLS_MENUE_PICTURE_TITLE_FEED_LINE=${TOOLS_MENUE_PICTURE_TITLE_FEED_LINE:='EMPTY'}
TOOLS_MENUE_PICTURE_TITLE_USER_INFO=${TOOLS_MENUE_PICTURE_TITLE_USER_INFO:='EMPTY'}
clear 2> /dev/null
echo -e "\n\t\t ${TOOLS_MENUE_PICTURE_TITLE_HEAD_LINE} \n\n"
echo -e "  ${TOOLS_MENUE_VALUE_BREAK} ... (0)"
echo -e "  ${TOOLS_MENUE_PICTURE_TITLE_VALUE_1} ... (1)"
echo -e "  ${TOOLS_MENUE_PICTURE_TITLE_VALUE_2} ... (2)"
echo -e "  ${TOOLS_MENUE_PICTURE_TITLE_VALUE_3} ... (3)"
echo -e "  ${TOOLS_MENUE_PICTURE_TITLE_VALUE_4} ... (4)"
echo ""
echo -n "${TOOLS_MENUE_PICTURE_TITLE_FEED_LINE} "

# Benutzereingaben entgegennehmen und überprüfen
START=${START:+0}
STOP=${STOP:+3}
STEP=${STEP:+1}
Q=${Q:+$START}
while [ $Q -lt $STOP ]
do
Q=$[$Q+$STEP]
read PICTURE_TITLE_MENUE_VALUE
  if [ $(echo "${PICTURE_TITLE_MENUE_VALUE}" | grep -c "^[1-4]$") -eq 1 ]
  then
  Q=${Q:+$STOP}
  elif [ $(echo "${PICTURE_TITLE_MENUE_VALUE}" | grep -c "^[0]$") -eq 1 ] || [ "${PICTURE_TITLE_MENUE_VALUE}" = '' ]
  then
  echo -e "\n${TOOLS_MENUE_PROGRAM_STOP}\n"
  exit 1
  else
  echo "${TOOLS_MENUE_PICTURE_TITLE_USER_INFO}"
    if [ $Q -lt $STOP ]
    then
    echo -n "${TOOLS_MENUE_PICTURE_TITLE_FEED_LINE} "
    fi
    if [ ${Q} -ge ${STOP} ]
    then
    echo -e "\n${TOOLS_MENUE_PROGRAM_STOP}\n"
    exit 1
    fi
  fi
done

# Bildtitel erstellen bzw. Bildtitel in die Bilder-Gallerie einfügen
PICTURE_NUMBERS=${PICTURE_NUMBERS:=1}
TEXT_FILE_DIRECTORY=${TEXT_FILE_DIRECTORY:='EMPTY'}
PICTURE_TITLE_FILE_NAME_PART_A=${PICTURE_TITLE_FILE_NAME_PART_A:='EMPTY'}
# LANGUAGE_NAME_PART_B -> inc_language_selection.txt
LANGUAGE_NAME_PART_B=${LANGUAGE_NAME_PART_B:='EMPTY'}
if [ "${LANGUAGE_NAME_PART_B}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 1 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
exit 1
fi
PICTURE_TITLE_FILE_NAME_PART_B=${LANGUAGE_NAME_PART_B}
PICTURE_TITLE_FILE_NAME_PART_C=${PICTURE_TITLE_FILE_NAME_PART_C:='EMPTY'}
if [ "${PICTURE_TITLE_FILE_NAME_PART_A}" = 'EMPTY' ] || [ "${PICTURE_TITLE_FILE_NAME_PART_B}" = 'EMPTY' ] || [ "${PICTURE_TITLE_FILE_NAME_PART_C}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 2 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
exit 1
fi
PICTURE_TITLE_FILE_NAME_PATH="./${TEXT_FILE_DIRECTORY}/${PICTURE_TITLE_FILE_NAME_PART_A}${PICTURE_TITLE_FILE_NAME_PART_B}${PICTURE_TITLE_FILE_NAME_PART_C}"
PICTURE_TITLE_FILE_NAME_PATH_OLD="./${TEXT_FILE_DIRECTORY}/${PICTURE_TITLE_FILE_NAME_PART_A}${PICTURE_TITLE_FILE_NAME_PART_B}_OLD${PICTURE_TITLE_FILE_NAME_PART_C}"
PICTURE_DIRECTORY=${PICTURE_DIRECTORY:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_A=${TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_A:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_B=${TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_B:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_C=${TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_C:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_A=${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_A:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_B=${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_B:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_C=${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_C:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_D=${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_D:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_E=${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_E:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_A=${TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_A:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_B=${TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_B:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_C=${TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_C:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_D=${TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_D:='EMPTY'}
TOOLS_PICTURE_TITLE_MENUE_USER_INFO=${TOOLS_PICTURE_TITLE_MENUE_USER_INFO:='EMPTY'}
# Verzeichnis für die Textdateien erstellen, falls es nicht existiert
if [ ! -d "./${TEXT_FILE_DIRECTORY}" ]
then
mkdir ${TEXT_FILE_DIRECTORY}
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 3 \nDIRECTORY: CAN NOT CREATE DIRECTORY »./${TEXT_FILE_DIRECTORY}« \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
  exit 1
  fi
fi

if [ ${PICTURE_TITLE_MENUE_VALUE} -eq 1 ]
then
# Datei für die Bildertitel automatisch erstellen
  clear 2> /dev/null
  if [ -f ${PICTURE_TITLE_FILE_NAME_PATH} ]
  then
  cp -u ${PICTURE_TITLE_FILE_NAME_PATH} ${PICTURE_TITLE_FILE_NAME_PATH_OLD}
    if [ $? -ge 1 ]
    then
    echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 4-1 \nFILE: CAN NOT COPY FILE »${PICTURE_TITLE_FILE_NAME_PATH}« \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
    exit 1
    fi
  fi
  START=${START:+1}
  STOP=${STOP:+$PICTURE_NUMBERS}
  STEP=${STEP:+1}
  N=${N:+$START}
  while [ $N -le $STOP ]          
  do
    if [ $N -gt 1 ]
    then
    echo "${N}:" >> ${PICTURE_TITLE_FILE_NAME_PATH}
      if [ $? -ge 1 ]
      then
      echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 4-2 \nFILE: CAN NOT WRITE FILE »${PICTURE_TITLE_FILE_NAME_PATH}« \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
      exit 1
      fi
    else
    echo "${N}:" > ${PICTURE_TITLE_FILE_NAME_PATH}
      if [ $? -ge 1 ]
      then
      echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 4-3 \nFILE: CAN NOT WRITE FILE »${PICTURE_TITLE_FILE_NAME_PATH}« \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
      exit 1
      fi
    fi
  N=$[$N+$STEP]
  done
  echo -e "\n\n\t\t${TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_C}\n"
  echo -e "${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_B}"
  echo -e "${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_C}"
  echo -e "${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_D}"
  echo -e "${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_E}\n"
elif [ ${PICTURE_TITLE_MENUE_VALUE} -eq 2 ]
then
# Datei für die Bildertitel manuell erstellen
  clear 2> /dev/null
  echo -e "\n\t\t${TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_A}\n\n"
  echo -e "  ${TOOLS_MENUE_VALUE_BREAK} ... (0)"
  echo -e "  ${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_A}"
  echo ""
  echo -n "${TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_A} "
  START=${START:+0}
  STOP=${STOP:+3}
  STEP=${STEP:+1}
  Q=${Q:+$START}
  while [ $Q -lt $STOP ]
  do
  Q=$[$Q+$STEP]
  read PICTURE_NUMBERS
    if [ $(echo ${PICTURE_NUMBERS} | grep -c "^[1-9][0-9]\{0,4\}$") -eq 1 ]
    then
      if [ -f ${PICTURE_TITLE_FILE_NAME_PATH} ]
      then
      cp -u ${PICTURE_TITLE_FILE_NAME_PATH} ${PICTURE_TITLE_FILE_NAME_PATH_OLD}
	if [ $? -ge 1 ]
	then
	echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 5-1 \nFILE: CAN NOT COPY FILE »${PICTURE_TITLE_FILE_NAME_PATH}« \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
	exit 1
	fi
      fi
      START=${START:+1}
      STOP=${STOP:+$PICTURE_NUMBERS}
      STEP=${STEP:+1}
      N=${N:+$START}
      while [ $N -le $STOP ]          
      do
	if [ $N -gt 1 ]
	then
	echo "${N}:" >> ${PICTURE_TITLE_FILE_NAME_PATH}
	  if [ $? -ge 1 ]
	  then
	  echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 5-2 \nFILE: CAN NOT WRITE FILE »${PICTURE_TITLE_FILE_NAME_PATH}« \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
	  exit 1
	  fi
	else
	echo "${N}:" > ${PICTURE_TITLE_FILE_NAME_PATH}
	  if [ $? -ge 1 ]
	  then
	  echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 5-3 \nFILE: CAN NOT WRITE FILE »${PICTURE_TITLE_FILE_NAME_PATH}« \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
	  exit 1
	  fi
	fi
      N=$[$N+$STEP]
      done
      echo -e "\n\n\t\t${TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_B}\n"
      echo -e "${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_B}"
      echo -e "${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_C}"
      echo -e "${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_D}"
      echo -e "${TOOLS_PICTURE_TITLE_MENUE_MAIN_LINE_E}\n"
    Q=${Q:+$STOP}
    elif [ $(echo "${PICTURE_NUMBERS}" | grep -c "^[0]$") -eq 1 ] || [ "${PICTURE_NUMBERS}" = '' ]
    then
      echo -e "\n${TOOLS_MENUE_PROGRAM_STOP}\n"
      exit 1
    else
    echo "${TOOLS_PICTURE_TITLE_MENUE_USER_INFO}"
      if [ $Q -lt $STOP ]
      then
      echo -n "${TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_A} "
      fi
      if [ ${Q} -ge ${STOP} ]
      then
      echo -e "\n${TOOLS_MENUE_PROGRAM_STOP}\n"
      exit 1
      fi
    fi
  done
elif [ ${PICTURE_TITLE_MENUE_VALUE} -eq 3 ]
then
# Bildtitel einer vorhandenen Textdatei in die Bildergalerie übernehmen
  clear 2> /dev/null
  echo -e "\n\n\t\t${TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_D}\n"
  if [ ! -f ${PICTURE_TITLE_FILE_NAME_PATH} ]
  then
  echo -e "${TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_B}\n"
  exit 1
  fi
  # Datei für die Erstellung der HTML-Dateien Galerie-Bilder (Hauptbilder) einbinden
  DIR_PROGRAMS=${DIR_PROGRAMS:='EMPTY'}
  CREATE_HTML_FILES_B=${CREATE_HTML_FILES_B:='EMPTY'}
  if [ "${DIR_PROGRAMS}" != 'EMPTY' ] || [ ${CREATE_HTML_FILES_B} != 'EMPTY' ]
  then
    if [ -f ${DIR_PROGRAMS}${CREATE_HTML_FILES_B} ]
    then
    echo -e "${GALLERY_MESSAGE_PLEASE_WAIT}\n"
    source ${DIR_PROGRAMS}${CREATE_HTML_FILES_B}
      if [ $? -ge 1 ]
      then
      echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 6-1 \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
      exit 1
      fi
    echo -e "  ${TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_C}\n"
    else
    echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 6-2 \nFILE: »${DIR_PROGRAMS}${CREATE_HTML_FILES_B}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
    exit 1
    fi
  else
  echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 6-3 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
  exit 1
  fi
elif [ ${PICTURE_TITLE_MENUE_VALUE} -eq 4 ]
then
# Bildtitel (Hauptbilder) aus der Bildergalerie entfernen
  clear 2> /dev/null
  echo -e "\n\n\t\t${TOOLS_PICTURE_TITLE_MENUE_HEAD_LINE_E}\n"
  if [ ! -f ${PICTURE_TITLE_FILE_NAME_PATH} ]
  then
  echo -e "${TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_B}\n"
  exit 1
  fi
  # Datei für die Erstellung der HTML-Dateien für Galeriebilder (Hauptbilder) einbinden
  DIR_PROGRAMS=${DIR_PROGRAMS:='EMPTY'}
  CREATE_HTML_FILES_B=${CREATE_HTML_FILES_B:='EMPTY'}
  if [ "${DIR_PROGRAMS}" != 'EMPTY' ] || [ ${CREATE_HTML_FILES_B} != 'EMPTY' ]
  then
    if [ -f ${DIR_PROGRAMS}${CREATE_HTML_FILES_B} ]
    then
    if [ -f ${PICTURE_TITLE_FILE_NAME_PATH} ]
    then
    mv ${PICTURE_TITLE_FILE_NAME_PATH} ${PICTURE_TITLE_FILE_NAME_PATH_OLD}
      if [ $? -ge 1 ]
      then
      echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 7-1 \nFILE: CAN NOT TO RENAME FILE »${PICTURE_TITLE_FILE_NAME_PATH}« \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
      exit 1
      fi
    fi
    echo -e "${GALLERY_MESSAGE_PLEASE_WAIT}\n"
    source ${DIR_PROGRAMS}${CREATE_HTML_FILES_B}
      if [ $? -ge 1 ]
      then
      echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 7-2 \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
      exit 1
      fi
    echo -e "  ${TOOLS_PICTURE_TITLE_MENUE_FEED_LINE_D}\n"
    else
    echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 7-3 \nFILE: »${DIR_PROGRAMS}${CREATE_HTML_FILES_B}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
    exit 1
    fi
  else
  echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 7-4 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
  exit 1
  fi
else
echo -e "\nERROR-CODE: GALLERY TOOLS PICTURE-TITLE 8 \nSCRIPT-NAME: ${INC_NAME_PICTURE_TITLE}\n"
exit 1
fi
