FROM php:8.2.11-apache

ARG MRBS_RELEASE=v1.11.4

RUN a2enmod rewrite
RUN a2enmod ssl
RUN apt-get update && apt-get install libldap2-dev libicu-dev zlib1g-dev libpng-dev ldap-utils -y
RUN docker-php-ext-install mysqli
RUN apt-get update && apt-get install -y locales && \
  sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen && \
  sed -i 's/^# *\(en_GB.UTF-8\)/\1/' /etc/locale.gen && \
  sed -i 's/^# *\(es_ES.UTF-8\)/\1/' /etc/locale.gen && \
  locale-gen
  
RUN \
  echo "**** fetch mrbs ****" && \
  rm -rf /var/www/html && \
  mkdir -p /var/www/html && \
  curl -o /tmp/mrbs.tar.gz -L \
    "https://github.com/meeting-room-booking-system/mrbs-code/archive/${MRBS_RELEASE}.tar.gz" && \
  echo "**** extract only folder 'web' ****" && \
  tar -C /var/www/html --strip-components=2 -zxvf /tmp/mrbs.tar.gz $(tar --exclude="*/*" -tf /tmp/mrbs.tar.gz)web && \
  mkdir -p /usr/share/mrbs && \
  tar -C /usr/share/mrbs --wildcards --strip-components=1 -zxvf /tmp/mrbs.tar.gz $(tar --exclude="*/*" -tf /tmp/mrbs.tar.gz)tables.*.sql && \
  echo "**** cleanup ****" && \
  rm -rf /tmp/*

RUN docker-php-ext-install mysqli pdo pdo_mysql ldap intl gd

COPY themes/ /var/www/html/Themes
   
COPY config.inc.php /var/www/html/
