[Tex/LaTex] Fancy headers on even and odd pages

fancyhdr

I would to get some help in getting my headers to show up like this on the odd pages:

enter image description here

and like below in the even pages:

enter image description here

Here is my minimal code:

\documentclass{book}
\usepackage[a4paper, left=1.5cm, right=1.5cm, bindingoffset=1.5cm]{geometry}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}

\definecolor{mybluei}{RGB}{199,234,253}
\definecolor{gmitblue}{RGB}{93,138,168}

\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[mybluei] (current page.north west) rectangle ($(current page.north east)+(0,-1in)$);
    %\node[anchor=north west, text=white, font=\Large\scshape, minimum size=1in, inner xsep=5mm] at (current page.north west) {A reasonably long title};
    \node[anchor=north east, minimum size=1in, inner xsep=5mm] at ($(current page.north east)+(0,-.35in)$) 
    {Configuration Issues, System Design\hspace{.5cm} {\Huge\textbf{\textcolor{white}{\thechapter}}} \thepage};
\end{tikzpicture}
}
\fancyhead[LO]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[mybluei] (current page.north west) rectangle ($(current page.north east)+(0,-1in)$);
    %\node[anchor=north west, text=white, font=\Large\scshape, minimum size=1in, inner xsep=5mm] at (current page.north west) {A reasonably long title};
    \node[anchor=north west, minimum size=1in, inner xsep=5mm] at ($(current page.north west)+(0,-.35in)$)
    {\thepage {\Huge\textbf{\textcolor{white}{\thechapter}}} \hspace{.5cm} Configuration Issues, System Design};
\end{tikzpicture}
}
\fancyfoot[CE]{
    \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\Large, minimum size=.5in] at (current page.south west) {\thepage};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south east) {\today};
\end{tikzpicture}
}
\fancyfoot[CO]{
    \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south west) {\today};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\Large, minimum size=.5in] at (current page.south east) {\thepage};
\end{tikzpicture}
}
\setlength{\headheight}{12pt}

\title{A reasonably long title}
\date{\today}
\author{The author}

\begin{document}
\maketitle
\chapter{first chapter}
\lipsum
\lipsum

\chapter{second chapter}
\lipsum[10-19]
\end{document} 

Best Answer

I am not sure if you wanted the footers as well, since your OP showed only the headers. In any case, here's a solution for the headers. Your try was not bad, but for example you didn't take into account the distances from the side of the page to the page number, chapter letter/number, and title. They should be the same on both sides, so here's a small example that shows that.

Note that the header and footer are not present when the chapter starts. That's a feature, but you could change this.

Output (various pages)

Chapter
enter image description here

Appendix, even page
enter image description here

Appendix, odd page
enter image description here

Code

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{geometry}
\usepackage{etoolbox,fancyhdr}

\usetikzlibrary{calc}

\definecolor{ultramarine}{RGB}{0,45,97}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{line}{RGB}{70,160,216}
\definecolor{fillh}{RGB}{225,233,251}

\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}

% uncomment this to see the distances are the same for evena nd odd pages.
%\tikzset{
%   every node/.style={draw}
%}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhf{}
\fancyhead[E]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[fillh] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[anchor=south west, font=\sffamily, text width=1cm] (evenpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\thepage};
    \node[anchor=south west, text width=1.5cm, text=white, font=\fontsize{2cm}{5.5cm}\selectfont] (chapter) at (evenpagenum.south east) {\thechapter};
    \node[anchor=south west] at (chapter.south east) {\leftmark};
\end{tikzpicture}
}%
\fancyhead[O]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[fillh] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[align=right, anchor=south east, font=\sffamily, text width=1cm] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\thepage};
    \node[align=right, anchor=south east, text width=1.5cm, text=white, font=\fontsize{2cm}{5.5cm}\selectfont] (chapter) at (evenpagenum.south west) {\thechapter};
    \node[align=right, anchor=south east] at (chapter.south west) {\leftmark};
\end{tikzpicture}
}
\fancyfoot[CE]{}
\fancyfoot[CO]{}
\setlength{\headheight}{12pt}

\begin{document}
\chapter{Problems}
\section{Problem 1}
\subsection{Problem 1}
\lipsum[1]
\subsection{Solution 1}
\lipsum[1-7]
\cleardoublepage

\appendix
\chapter{Appendix \thechapter}
\lipsum[1-20]

\end{document}