\documentclass[a4paper, 13pt]{article}

% Packages
\usepackage[a4paper, inner=1.5cm, outer=1.5cm, top=1.5cm, bottom=3cm, bindingoffset=0cm]{geometry}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{fontspec,xunicode,xltxtra}
\usepackage{float}
\usepackage{kantlipsum,lipsum}
\usepackage{eso-pic}
\usepackage{ragged2e}
\usepackage{fancyhdr}
\usepackage{background,wallpaper}
\usepackage{changepage}
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{pgf-pie,qrcode}
\usepackage{etoolbox}
\usepackage{pdfpages}
\usepackage{forloop}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage[absolute,overlay]{textpos}

% Font % TODO: Colored emojis? (very hard)
\setmainfont[Path=./fonts/]{tierra-nueva.otf}[BoldFont=tierra-nueva-bold.otf]
\newfontfamily\emojifont[Path=./fonts/]{twitter-emoji.ttf}
\newfontfamily\cartamarina[Path=./fonts/]{carta-marina.otf}
%\newfontfamily\emojifont[Path=./fonts/]{emoji-one-color.otf}
%\def\emojifont{\font\Emoj={./fonts/emoji-one-color.otf:mode=node;colr=yes;}\Emoj }

% GERMAN
\usepackage[ngerman=ngerman-x-latest]{hyphsubst}
\usepackage[ngerman]{babel}

% Fancy quote stuff
\usepackage[autostyle=false, style=german]{csquotes}
\MakeOuterQuote{"}

% Figures
\graphicspath{{figures/}}
\newcounter{bottlecnt} % Bottle counter
\newcounter{bottlemax} % Bottle loop end

% Flip image if odd
\newcommand\oddflip[2][]{
	\checkoddpage
	\ifoddpage\includegraphics[#1]{#2}
	\else\scalebox{-1}[1]{\includegraphics[#1]{#2}}
	\fi
}

\newcommand\disableheader{
	\backgroundsetup{contents={}}
}

\newcommand\enableheader{
	\backgroundsetup{contents={\oddflip[keepaspectratio=true, width=\paperwidth]{kordel.png}},scale=1.1,placement=top,opacity=1,position={0.4\textwidth, 3.3cm}}
}

% Awesome column type
\newcolumntype{R}{>{\raggedright\arraybackslash}p{.30\textwidth}}

% Advertisements
\newcommand\advert[1]{
	\newpage
	\disableheader
	\thispagestyle{empty}
	\includepdf[noautoscale=true,width=\paperwidth]{parts/advertisements/#1.pdf}
	\enableheader
}

\newcommand\adverthalf[1]{
	\newpage
	\disableheader
	\thispagestyle{empty}
	\includepdf[noautoscale=true,angle=90,width=\paperwidth]{parts/advertisements/#1.pdf}
	\enableheader
}

\newcommand\adverthalfnorot[1]{
	\newpage
	\disableheader
	\thispagestyle{empty}
	\includepdf[noautoscale=true,width=\paperwidth]{parts/advertisements/#1.pdf}
	\enableheader
}

% Class page
\newcommand\classoverview[1]{
	\newpage
	\disableheader
	\thispagestyle{empty}
	\includepdf[pages=-,noautoscale=true,width=\paperwidth]{parts/overview/#1.pdf}
	\enableheader
}

% Trips
\newcommand\trip[1]{
	\newpage
	\disableheader
	\thispagestyle{empty}
	\includepdf[pages=-,noautoscale=true,width=\paperwidth]{parts/trips/#1.pdf}
	\enableheader
}

% Other PDFs
\newcommand\other[1]{
	\newpage
	\disableheader
	\thispagestyle{empty}
	\includepdf[pages=-,noautoscale=true,width=\paperwidth]{parts/other/#1.pdf}
	\enableheader
}

% Header & footer
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headheight}{60pt}
\addtolength{\topmargin}{-35pt}
\pagestyle{fancy}
\fancyheadoffset{1.5cm}
\fancyfootoffset{1.5cm}
\fancyhf{}
\fancyhead[L]{\hspace*{1cm}\vspace*{0cm}{\cartamarina\Huge{\rightmark}}}
\fancyfoot[R]{\vspace*{-0.8cm}\oddflip[keepaspectratio=true, width=\paperwidth]{welle.png}}
\fancyfoot[L]{
	% Hacky but works :)
	\checkoddpage
	\begin{textblock*}{1cm}(\ifoddpage 1.4cm \else 18.6cm \fi, \paperheight-2.1cm)
		\begin{center}
			\huge{\thepage}
		\end{center}
	\end{textblock*}
}

% Custom title command for header
\renewcommand{\sectionmark}[1]{\markright{#1}}
\renewcommand{\title}[1]{
	\par\refstepcounter{section}
	\sectionmark{#1}
	\addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}
}
\newcommand{\subtitle}[2]{
	\sectionmark{#1 #2}
	\addcontentsline{toc}{subsection}{#2}
}
\newcommand{\subtitletoc}[2]{
	\addcontentsline{toc}{subsection}{#2}
}

% I don't like paragraph indentation
\setlength{\parindent}{0pt}

\begin{document}

\author{RBS Ulm TG13}

% Updated: https://tex.stackexchange.com/a/7657
% Import all tex files from a directory
\def\app@exe{\immediate\write18}
\def\inputall#1{
	\app@exe{cat #1/*.tex > #1/files.tmp}
	\InputIfFileExists{#1/files.tmp}{}{}
	\AtEndDocument{\app@exe{rm -f #1/files.tmp}}}

\def\part#1{\input{parts/#1.tex}\newpage}
\def\student{\input{parts/studenttemplate.tex}}
\def\teacherprofile{\input{parts/teacherprofiletemplate.tex}}
\def\quotepage{\input{parts/quotetemplate.tex}}
\def\ranking{\input{parts/rankingtemplate.tex}}
\def\generated#1{\input{parts/generated/#1.tex}}

\part{titlepage}
\part{tableofcontents}
\part{introduction}
\adverthalfnorot{gardena}
\part{questionnaire}
\advert{asb}
\part{teachers}
\advert{daad}
\part{secrets}
\advert{ihk}
\part{studentprofiles}
\advert{uni-ulm}
\part{trips}
\advert{abihome}
\part{conclusion}
\adverthalfnorot{b-group}
\part{imprint}
\part{final}

\end{document}
