#!/bin/sh
# example: orders-accept 2 de < mail.txt

game="$1"
lang="$2"

[ -z "$ERESSEA" ] && ERESSEA="$HOME/eressea"
SCRIPT=$(readlink -f "$0")
BIN=$(dirname "$SCRIPT")

cd "$ERESSEA/game-$game"
mkdir -p orders.dir
cd orders.dir
eval "$(python "$BIN/accept-orders.py" "$@")"
if [ -e "$ACCEPT_FILE" ]
then
	rm -f "$LOCKFILE"
	filename=$(basename "$ACCEPT_FILE")
	email="$ACCEPT_MAIL"
	if [ -d "$ERESSEA/orders-php" ]
	then
	  php "$ERESSEA/orders-php/cli.php" insert "$filename" "$lang" "$email"
	fi
fi