%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% klausurmanagement.sty : Package zum Management von
%                Klausuren und Pruefungen
% Wolfgang May, (c) 2003-2008
% Institut fuer Informatik, Georg-August Universit"at G"ottingen
%
% Adapted from a previous style that was used at 
% Inst.f.Informatik @ Freiburg University (1994-...)
% Inst.f.Informatik @ Mannheim University 
%      (originally written by Stefan Trageser)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\basename{klausurmanagement}%
\ProvidesPackage{klausurmanagement}%
%\RequirePackage{goe-ifi}%
\RequirePackage{version}%
\RequirePackage{ifthen}%
%\RequirePackage[utf8]{inputenc}%
\RequirePackage{supertabular}%

\newtoks\myteilnehmerdatei
\newtoks\klausurquelldatei

\newif\ifpublic\publictrue
\newif\ifenglish\englishtrue
\newif\ifbenotet\benotettrue
\newif\ifscheinbenotet\scheinbenotettrue %% for the individual
  %  instance - note: the same lecture can be graded for some 
  %  students and not graded for others

\includeversion{german}%
\excludeversion{english}%

\def\undefineallproperties{%
  \ifdefined\kdatum\def\datum{\kdatum}\else\def\datum{}\fi
  \def\punkte{0}%
  \def\note{}%
  \def\geschlecht{none}%
  \def\name{}%
  \def\vorname{}%
  \def\matrikel{}%
  \def\studiengang{}%
  \def\thema{}%
  \def\perscode{}%
  \def\qcode{}%
}%
\undefineallproperties

\def\titel{}
\def\fach{}
\def\dozent{}
\def\ects{}
\def\semester{}
\def\hoechstpunktzahl{0}
\def\mindestpunktzahl{}
\newcommand{\deactivateeightbit}{%
   \count@=127
   \loop
     \catcode\count@=12
     \ifnum\count@<255%
     \advance\count@\@ne
   \repeat}
\newcommand{\activateeightbit}{%
   \count@=127
   \loop
     \catcode\count@=\active
     \ifnum\count@<255%
     \advance\count@\@ne
   \repeat}
 
\def\abovetabletext{}



\newcounter{Cgeschlecht}
\newcounter{Cname}
\newcounter{Cvorname}
\newcounter{Cmail}
\newcounter{Cmatr}
\newcounter{Cfach}
\newcounter{Cpunkte}
\newcounter{Cnote}
\newcounter{Cdatum}
\newcounter{Cperscode}
\newcounter{Cqcode}
\newcounter{linesPerItem}

\newcommand{\teilnehmerdatei}[1]{%
   \global\myteilnehmerdatei{#1}%
   \analyzeParticipantsFile}
\newcommand{\klausurdatei}[1]{%
   \global\klausurquelldatei{#1}%
   \analyzeParticipantsFile}

\newif\ifects\ectsfalse
\newif\ifbestanden\bestandenfalse
\newcommand{\kltitel}[1]{\def\titel{#1}}
\newcommand{\klfach}[1]{\def\fach{#1}}
\newcommand{\klvorlesung}[1]{\def\vorlesung{#1}}
\newcommand{\klvorlAbbrev}[1]{\def\vorlAbbrev{#1}}
\newcommand{\kldozent}[1]{\def\dozent{#1}}
\newcommand{\klsemester}[1]{\def\semester{#1}}
\newcommand{\klects}[1]{\ectstrue\def\ects{#1}}
\newcommand{\kldatum}[1]{\def\kdatum{#1}\def\datum{#1}}
\newcommand{\prdatum}[1]{\def\mdldatum{#1}}
\newcommand{\klhoechstpunktzahl}[1]{\def\hoechstpunktzahl{#1}}
\newcommand{\klmindestpunktzahl}[1]{\def\mindestpunktzahl{#1}}
\newcommand{\klgeschlecht}[1]{\def\geschlecht{#1}}
\newcommand{\klname}[1]{\def\name{#1}}
\newcommand{\klvorname}[1]{\def\vorname{#1}}
\newcommand{\klperscode}[1]{\def\perscode{#1}}
\newcommand{\klqcode}[1]{\def\qcode{#1}}
\newcommand{\klmatrikel}[1]{\def\matrikel{#1}}
\newcommand{\kleinzelnote}[1]{\def\note{#1}}
\newcommand{\klthema}[1]{\def\thema{#1}}
\newcommand{\unbenotet}[1]{\benotetfalse\scheinbenotetfalse}
\newcommand{\benotet}[1]{\benotettrue\scheinbenotettrue}
\newcommand{\nichtbestanden}{5.0}

% specify necessary points for each mark:
%
% \klnote{1}{85}{80}{75}  means ... 1.0 for more than 85 points,
%                                   1.3 for 80-84.9999 points etc
% \klnote{2}{70}{65}{60}
% \klnote{3}{55}{50}{45}
% \klnote{4}{40}{30}{30}

\newcounter{tmpcount}%
\newcommand{\klnote}[4]{%
   \setcounter{tmpcount}{#1}%
   \expandafter\def\csname p\roman{tmpcount}Null\endcsname{#2}%
   \expandafter\def\csname p\roman{tmpcount}Drei\endcsname{#3}%
   \expandafter\def\csname p\roman{tmpcount}Sieben\endcsname{#4}%
   \ifthenelse{\value{tmpcount}=4}{%
            \def\vierpunktzahl{#2}%
            \ifthenelse{\mindestpunktzahl=\vierpunktzahl}%
              {}{\PackageError{klausurmanagement}{Angegebene Mindestpunktzahl: \mindestpunktzahl\ ungleich Punktzahl fuer 4: \vierpunktzahl}\@eha}%
           }{}%
}


% defaultdefinition just to define commands pXXXYYY:

\klhoechstpunktzahl{99}
\klmindestpunktzahl{99}
\klnote{1}{99}{99}{99}
\klnote{2}{99}{99}{99}
\klnote{3}{99}{99}{99}
\klnote{4}{99}{99}{99}

% and now we have a command for calculating the mark from given points

\newcommand{\bewertung}{%
     \ifthenelse{\punkte>\hoechstpunktzahl}%
        {\global\scheinbenotetfalse}
        {\global\scheinbenotettrue   
         \renewcommand{\note}{5.0}%
         \ifthenelse{\punkte<\pivNull}{}{\renewcommand{\note}{4.0}}%
         \ifthenelse{\punkte<\piiiSieben}{}{\renewcommand{\note}{3.7}}%
         \ifthenelse{\punkte<\piiiDrei}{}{\renewcommand{\note}{3.3}}%
         \ifthenelse{\punkte<\piiiNull}{}{\renewcommand{\note}{3.0}}%
         \ifthenelse{\punkte<\piiSieben}{}{\renewcommand{\note}{2.7}}%
         \ifthenelse{\punkte<\piiDrei}{}{\renewcommand{\note}{2.3}}%
         \ifthenelse{\punkte<\piiNull}{}{\renewcommand{\note}{2.0}}%
         \ifthenelse{\punkte<\piSieben}{}{\renewcommand{\note}{1.7}}%
         \ifthenelse{\punkte<\piDrei}{}{\renewcommand{\note}{1.3}}%
         \ifthenelse{\punkte<\piNull}{}{\renewcommand{\note}{1.0}}%
        }%
}

\newcounter{flag}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Analyze Header of Participants File:
%
% * inside the participants file, entries are separated by a line
%   containing only a dot.
% * it begins with a ``prototypical'' entry that tells the
%   names of the attributes, e.g.,
%
%      geschlecht
%      vorname
%      name
%      matrikel
%      punkte
%      .
%
% * then the data entries follow in the same order, e.g.
%
%      m
%      john
%      doe
%      0815
%      10
%      .
% * always separated by a ``.''
%
% * note: entries whose first line is "nopublic" will not be listed in
%   the public list
%
% * finally the file ends with a line that contains only a "$" %$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\analyzeParticipantsFile{%
  \newcount\attributanz 
  \attributanz=0%
  \setcounter{Cgeschlecht}{99}
  \setcounter{Cname}{99}
  \setcounter{Cvorname}{99}
  \setcounter{Cperscode}{99}
  \setcounter{Cqcode}{99}
  \setcounter{Cmail}{99}
  \setcounter{Cmatr}{99}
  \setcounter{Cfach}{99}
  \setcounter{Cpunkte}{99}
  \setcounter{Cdatum}{99}
  \setcounter{Cnote}{99}
  
  \newread\inputfile%
  \openin\inputfile=\the\myteilnehmerdatei%
  % Bestimmung der Attributanzahl eines Paketes und Zuordnung von
  % Rangfolgenummern zu den Attributen

  %\inputencoding{utf8}
  \read\inputfile to \dummy 
  %% note that linebreak in next line is NECESSARY
  \whiledo{\not\equal{\dummy}{.
     }}{\advance\attributanz by 1
        \ifthenelse{\equal{\dummy}{geschlecht
            }}{\setcounter{Cgeschlecht}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{name
            }}{\setcounter{Cname}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{vorname
            }}{\setcounter{Cvorname}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{perscode
            }}{\setcounter{Cperscode}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{qcode
            }}{\setcounter{Cqcode}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{mail
            }}{\setcounter{Cmail}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{fach
            }}{\setcounter{Cfach}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{studiengang
            }}{\setcounter{Cfach}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{matrikel
            }}{\setcounter{Cmatr}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{punkte
            }}{\setcounter{Cpunkte}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{note
            }}{\setcounter{Cnote}{\attributanz}}{}
        \ifthenelse{\equal{\dummy}{datum
            }}{\setcounter{Cdatum}{\attributanz}}{}
        \read\inputfile to \dummy}

  \closein\inputfile
  \setcounter{linesPerItem}{\attributanz} 
  \stepcounter{linesPerItem}%
 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Read an Entry of the Participants File:
%

\def\readentry{%
\setcounter{tmpcount}{1}%
 \publictrue
 \englishfalse
 \whiledo{\value{tmpcount}<\value{linesPerItem}}%
 {\read\inputfile to\dummy
  \ifthenelse{\equal{\dummy}{nopublic
      }}{\global\publicfalse\read\inputfile to\dummy}{}%
  \ifthenelse{\equal{\dummy}{english
      }}{\global\englishtrue\read\inputfile to\dummy}{}%
  \ifthenelse{%
     \value{Cgeschlecht}=\value{tmpcount}}{\let\geschlecht\dummy}{%
  \ifthenelse{\value{Cname}=\value{tmpcount}}{\let\name\dummy}{%
  \ifthenelse{\value{Cvorname}=\value{tmpcount}}{\let\vorname\dummy}{%
  \ifthenelse{\value{Cperscode}=\value{tmpcount}}{\let\perscode\dummy}{%
  \ifthenelse{\value{Cqcode}=\value{tmpcount}}{\let\qcode\dummy}{%
  \ifthenelse{\value{Cmail}=\value{tmpcount}}{\let\mail\dummy}{%
  \ifthenelse{\value{Cmatr}=\value{tmpcount}}{\let\matrikel\dummy}{%
  \ifthenelse{\value{Cfach}=\value{tmpcount}}{\let\studiengang\dummy}{%
  \ifthenelse{\value{Cpunkte}=\value{tmpcount}}{\let\punkte\dummy}{%
  \ifthenelse{\value{Cnote}=\value{tmpcount}}{\let\note\dummy}{%
  \ifthenelse{\value{Cdatum}=\value{tmpcount}}{\let\datum\dummy}{%
    % keyword did not match any predefined entry
    }{}}}}}}}}}}}%
  \stepcounter{tmpcount}%                   
 }
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   Protokolle und Klausuren drucken
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\ifloesung
\loesungtrue

\def\includenoaux#1{\relax\@includenoaux#1}
\def\@includenoaux#1 {%
  \clearpage
  \@tempswatrue
  \if@partsw
    \@tempswafalse
    \edef\reserved@b{#1}%
    \@for\reserved@a:=\@partlist\do
      {\ifx\reserved@a\reserved@b\@tempswatrue\fi}%
  \fi
  \if@tempswa
    \let\@auxout\@partaux
    \if@filesw
      \immediate\openout\@partaux #1.aux
      \protected@write\@partaux{\relax}%
    \fi
    \@input@{#1.tex}%
    \clearpage
    \@writeckpt{#1}%
    \if@filesw
      \immediate\closeout\@partaux
    \fi
  \else
    \deadcycles\z@
    \@nameuse{cp@#1}%
  \fi
  \let\@auxout\@mainaux}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   Protokolle fuer muendliche Pruefungen drucken
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\alleprotokolle{%
  \newread\inputfile%
  \openin\inputfile=\the\myteilnehmerdatei%
  \read\inputfile to \dummy
  %% first: overread the header (see above at analyzeParticipantsFile)
  %%%%%%% note that the linebreak in the subsequent line is NECESSARY!
  \whiledo{\not\equal{\dummy}{.
     }}{\read\inputfile to \dummy}

  %% now: read data items until the end sign "$" is reached         %$
  %%%%%%% note that the linebreak in the subsequent line is NECESSARY!
  \whiledo{\not\equal{\dummy}{$
    }}%$
    { \readentry
      \includenoaux{protokollbogen}

      \read\inputfile to \dummy
      \whiledo{\not\equal{\dummy}{.
              } \and  \not\equal{\dummy}{$
              }}%$
        {\read\inputfile to \dummy}%
    }
  %% now, the "$" has been read                                %$
  \closein\inputfile
  \undefineallproperties
} % end of alleprotokolle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   Print Exam Sheets
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\printklausurmitohneml{
  \undefineallproperties
  \def\perscode{9999}%   fake perscode 
  \loesungOn  %% einmal mit Loesung drucken, dabei wird auch
              %% das .aux erzeugt
  \include{\the\klausurquelldatei}
  \loesungOff %% Klausuren ohne Loesung setzen
  \includenoaux{\the\klausurquelldatei}
}

\def\alleklausuren{%
  \undefineallproperties
  % WM 3.3.2018: next 5 lines separated above as \printklausurmitohneml
  % \loesungOn  %% einmal mit Loesung drucken, dabei wird auch
  %             %% das .aux erzeugt
  % \include{\the\klausurquelldatei}
  % \loesungOff %% Klausuren ohne Loesung setzen
  % \includenoaux{\the\klausurquelldatei}
  \loesungOff %% Klausuren ohne Loesung setzen
  \includenoaux{\the\klausurquelldatei}
  \newread\inputfile%
  \openin\inputfile=\the\myteilnehmerdatei%
  \read\inputfile to \dummy
  %% first: overread the header (see above at analyzeParticipantsFile)
  %%%%%%% note that the linebreak in the subsequent line is NECESSARY!
  \whiledo{\not\equal{\dummy}{.
     }}{\read\inputfile to \dummy}

  %% now: read data items until the end sign "$" is reached         %$
  %%%%%%% note that the linebreak in the subsequent line is NECESSARY!
  \whiledo{\not\equal{\dummy}{$
    }}%$
    { \readentry
      \includeversion{german}%
      \excludeversion{english}%
      \ifenglish
         \excludeversion{german}%
         \includeversion{english}%
      \fi
      \includenoaux{\the\klausurquelldatei}

      \read\inputfile to \dummy
      \whiledo{\not\equal{\dummy}{.
              } \and  \not\equal{\dummy}{$
              }}%$
        {\read\inputfile to \dummy}%
    }
  %% now, the "$" has been read                                %$
  \closein\inputfile
  \undefineallproperties
} % end of alleklausuren


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Process input list and write as table lines to an aux file
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\PrepareForReports{%
  % first, generate an output to an intermediate file
  % (that can also be used for generating other things)
  \catcode`\"=11
  \deactivateeightbit % allow to handle German UTF-8 Umlauts

  \newread\inputfile%
  \newwrite\auxOut%
  \openin\inputfile=\the\myteilnehmerdatei%
  \read\inputfile to \dummy
  \whiledo{\not\equal{\dummy}{.
      }}{\read\inputfile to \dummy}
  \immediate\openout\auxOut=\jobname .tab%
  \whiledo{\not\equal{\dummy}{$
   }}% $
   { \readentry
     \ifbenotet\ifthenelse{\value{Cnote}<99}{}{\bewertung}\fi
     \ifthenelse{\equal{\note}{.
         }}{\def\note{bestanden}}{}%
     \ifthenelse{\equal{\note}{5
         }}{\def\note{nicht bestanden}}{}%
     %% and write entry to auxiliary .tab file
     \ifpublic
       \immediate\write\auxOut{%
       \string\tableline{public}{\name}{\vorname}{\matrikel}{{\perscode}{\qcode}}{\punkte}{\note}{\datum}{\studiengang}}%
     \else
       \immediate\write\auxOut{%
       \string\tableline{nopublic}{\name}{\vorname}{\matrikel}{{\perscode}{\qcode}}{\punkte}{\note}{\datum}{\studiengang}}\fi
     \read\inputfile to \dummy
     \whiledo{\not\equal{\dummy}{.
              } \and  \not\equal{\dummy}{$ 
               }}%$
         {\read\inputfile to \dummy}%
   }%
  \closein\inputfile
  \immediate\closeout\auxOut
  \catcode`\"=\active
  \activateeightbit
  \undefineallproperties
}


%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
%
% Print Participants List (Names)
% 
%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

\def\printTeilnehmerliste{%
  \newtoks\numOfCols
  \def\personOrGroup{\dozent}%
  \@ifundefined{institutehead}{\relax}{\institutehead}%
  \vskip1.5cm

  \numOfCols{2}%
  \tablefirsthead{\hline 
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}Teilnehmerliste: \vorlesung} \\
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
    \hline Name & Vorname\\\hline} 
  \tablehead{\hline 
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}Teilnehmerliste: \vorlesung} \\
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
    \hline Name & Vorname\\\hline} 
  \def\tableline##1##2##3##4##5##6##7##8##9{##2&##3\\}%
  \tabletail{\hline}%
  \begin{center}
    \begin{supertabular}{|l|l|l|}
      \@input{\jobname .tab}%
    \end{supertabular}
  \end{center}
}

%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
%
% Print Participants List (Numbers)
% 
%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

\def\printTeilnehmerNummern{%
  \newtoks\numOfCols
  \def\personOrGroup{\dozent}%
  \@ifundefined{institutehead}{\relax}{\institutehead}%
  \vskip1.5cm

  \numOfCols{1}%
  \tablefirsthead{\hline 
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}Teilnehmerliste: \vorlesung} \\
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
    \hline Matrikelnummer\\\hline} 
  \tablehead{\hline 
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}Teilnehmerliste: \vorlesung} \\
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
    \hline Matrikelnummer\\\hline} 
  \def\tableline##1##2##3##4##5##6##7##8##9{##4\\}%
  \tabletail{\hline}%
  \begin{center}
    \begin{supertabular}{|l|}
      \@input{\jobname .tab}%
    \end{supertabular}
  \end{center}
}

%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
%
% Print Stickers
% 
%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

\def\printTischkarten{%
 \def\tableline##1##2##3##4##5##6##7##8##9{%
   \fbox{\vbox to 3cm{%
      \vfill
      \hbox to .33\textwidth{\Large\bf\sf\hfill##2\hfill}%
      \vskip0.3cm
      \hbox to .33\textwidth{\Large\bf\sf\hfill##3\hfill}%
      \vskip0.3cm
      \hbox to .33\textwidth{\hfill{\Large\bf\sf\@firstoftwo##5\hfill\@secondoftwo##5}\hfill}%
      \vfill}}}%
  \@input{\jobname .tab}%
  \cleardoublepage

}


%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
%
% Internal List of results (Name + MatNo + Grade + Studies)
% 
%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

\def\printInternalList{%
 \newtoks\numOfCols
 \def\personOrGroup{\dozent}%
 \@ifundefined{institutehead}{\relax}{\institutehead}%
 \vskip1.5cm

 \abovetabletext

 \ifthenelse{\value{Cnote}=99}{%
  % the note (grade) is not given in the sources but is
  % calculated from the points (for written exams)
  % => output points and grade
  \ifthenelse{\value{Cfach}=99}{%
    % if fach/subject is given: output it
    % Cfach=99 => not given
   \numOfCols{5}%
   \tablefirsthead{\hline 
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung\ \semester} \\
     \hline Name & Vorname & MatNo & Punkte & Note\\\hline}
   \tablehead{\hline 
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung\ (Forts.)} \\
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
     \hline Name & Vorname & MatNo & Punkte & Note\\\hline} 
   \def\tableline##1##2##3##4##5##6##7##8##9{##2&##3&##4&##6&##7\\}%
   \tabletail{\hline}%
   \begin{center}
     \begin{supertabular}{|l|l|l|l|l|}
       \@input{\jobname .tab}%
     \end{supertabular}
   \end{center}
  }%
  {% else: fach is given 
   \numOfCols{6}%
   \tablefirsthead{\hline 
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung\ \semester} \\
     \hline Name & Vorname & MatNo & Punkte & Note & Studiengang\\\hline}
   \tablehead{\hline 
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung\ (Forts.)} \\
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
     \hline Name & Vorname & MatNo & Punkte & Note & Studiengang\\\hline} 
   \def\tableline##1##2##3##4##5##6##7##8##9{##2&##3&##4&##6&##7&##9\\}%
   \tabletail{\hline}%
   \begin{center}
     \begin{supertabular}{|l|l|l|l|l|l|}
       \@input{\jobname .tab}%
     \end{supertabular}
   \end{center}
  }%
 }%
 %
 {%%%%%% no punkte, only note+datum (e.g. for oral exams)
  \ifthenelse{\value{Cfach}=99}{%
   \numOfCols{5}%
   \tablefirsthead{\hline 
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung\ \semester} \\
     \hline Name & Vorname & MatNo & Note & Datum\\\hline}
   \tablehead{\hline 
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung\ (Forts.)} \\
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
     \hline Name & Vorname & MatNo & Note & Datum\\\hline} 
   \def\tableline##1##2##3##4##5##6##7##8##9{##2&##3&##4&##7&##8\\}%
   \tabletail{\hline}%
   \begin{center}
     \begin{supertabular}{|l|l|l|l|l|}
       \@input{\jobname .tab}%
     \end{supertabular}
   \end{center}
  }%
  {%% else: with fach/subject
   \numOfCols{6}%
   \tablefirsthead{\hline 
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung\ \semester} \\
     \hline Name & Vorname & MatNo & Note & Datum& Studiengang\\\hline}
   \tablehead{\hline 
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung\ (Forts.)} \\
     \multicolumn{\the\numOfCols}{|c|}
        {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
     \hline Name & Vorname & MatNo & Note & Datum& Studiengang\\\hline} 
   \def\tableline##1##2##3##4##5##6##7##8##9{##2&##3&##4&##7&##8&##9\\}%
   \tabletail{\hline}%
   \begin{center}
     \begin{supertabular}{|l|l|l|l|l|l|}
       \@input{\jobname .tab}%
     \end{supertabular}
   \end{center}
  }%
 }%
}

%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
%
% Public List of Results (MatNo/perscode + Grade)
% 
%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

\def\printPublicList{%
  \newtoks\numOfCols
  \def\personOrGroup{\dozent}%
  \@ifundefined{institutehead}{\relax}{\institutehead}%
  \vskip-1cm

  Vorl"aufiges Ergebnis
  \bigskip

 \newif\if@kt@first\@kt@firsttrue
 \ifthenelse{\value{Cnote}=99}{%
  % the note (grade) is not given in the sources but is
  % calculated from the points (for written exams)
  % => output points and grade
  \numOfCols{3}%
  \tablefirsthead{\hline 
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung} \\
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
    \hline MatNo & Punkte & Note\\\hline} 
  \tablehead{\hline 
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung\ (Forts.)} \\
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
    \hline Code & Punkte & Note\\\hline} 
  \def\tableline##1##2##3##4##5##6##7##8##9{%
  \ifthenelse{\equal{##1}{nopublic}}{}%
     {\if@kt@first\global\@kt@firstfalse\else\\\fi##4&##6&##7}}%
  \tabletail{\hline}%
  \begin{center}
    \begin{supertabular}{|l|l|l|}
      \@input{\jobname .tab}%
      \\
    \end{supertabular}
  \end{center}
  }
  {% else: no points, only grade are given 
  \numOfCols{2}%
  \tablefirsthead{\hline 
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung} \\
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
    \hline MatNo & Note\\\hline} 
  \tablehead{\hline 
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}Ergebnisse: \vorlesung\ (Forts.)} \\
    \multicolumn{\the\numOfCols}{|c|}
       {\bf\rule[-3mm]{0mm}{8mm}\semester} \\
    \hline MatNo & Note\\\hline} 
  \def\tableline##1##2##3##4##5##6##7##8##9{%
    \ifthenelse{\equal{##1}{nopublic}}{}%
     {\if@kt@first\global\@kt@firstfalse\else\\\fi\@firstoftwo##5&##7}}%
  \tabletail{\hline}%
  \begin{center}
    \begin{supertabular}{|l|l|l|}
      \@input{\jobname .tab}%
      \\
    \end{supertabular}
  \end{center}
 }
}

%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
%
% SQL File zum Input der Ergebnisse in Datenbank erzeugen
%  
%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

\def\writeToSQL{%
  % generate output for an SQL Database
  % INSERT INTO \vorlkurzname VALUES(name,vorname,matrikel,punkte,note)
  \catcode`\"=11
  \newwrite\auxOut%
  \immediate\openout\auxOut=\vorlAbbrev .sql%  
  \protected@write\auxOut{DROP TABLE \vorlAbbrev;}
  \protected@write\auxOut{CREATE TABLE \vorlAbbrev }
  \protected@write\auxOut{  (Name VARCHAR2(30),}
  \protected@write\auxOut{   Vorname VARCHAR2(30),}
  \protected@write\auxOut{   MatNo NUMBER,}
  \protected@write\auxOut{   Punkte NUMBER,}
  \protected@write\auxOut{   Note NUMBER);}
  \protected@write\auxOut{}

  \def\tableline##1##2##3##4##5##6##7##8##9
   {\protected@write\auxOut{INSERT INTO \vorlAbbrev}
    \protected@write\auxOut{ VALUES(\string"##2\string",
             \string"##3\string",##4,##6,##7);}}%
  \@input{\jobname .tab}%

  \protected@write\auxOut{}
  \protected@write\auxOut{-- Teilnehmerliste erzeugen }
  \protected@write\auxOut{SELECT Name, Vorname FROM \vorlAbbrev }
  \protected@write\auxOut{ ORDER BY Name;}
  \protected@write\auxOut{}
  \protected@write\auxOut{-- Public Notenliste in ASCII erzeugen}
  \protected@write\auxOut{SELECT PersCode, Note FROM \vorlAbbrev }
  \protected@write\auxOut{ ORDER BY PersCode;}

  \immediate\closeout\auxOut
  \catcode`\"=\active
}

%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
%
% ASCII output erzeugen
% customize it: put \def\myline in the below style in 
%   your .tex file (overwrites the default definition)
%
% e.g. the below lines print the grade as 1,7 instead of 1.7
%
%\def\kommanote#1.#2{#1,#2}
%\def\myline#1#2#3#4#5#6#7#8{%
%   \mylineii{#1}{#2}{#3}{#4}{\kommanote#5}{#6}{#7}{#8}}
%\def\mylineii#1#2#3#4#5#6#7#8{%
%   {\protected@write\auxOut{#2; #3; #4; #5; #6; #7; #8}}}
%  
%oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

\def\myline#1#2#3#4#5#6#7#8#9{%
   {\protected@write\auxOut{ #5, #6, #7, #4, #3, #2 }}}%

\def\CustomizedOutputToAscii{%
  %% produces CSV-style output
  %%    grade; points; matno; family name; given name
  %% see above writeToSQL for sample usage
  \catcode`\"=11
  \newwrite\auxOut%
  \immediate\openout\auxOut=\vorlAbbrev .txt%  
  \def\tableline##1##2##3##4##5##6##7##8##9{%
    \myline{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}{##9}}%
  \@input{\jobname .tab}%


  \immediate\closeout\auxOut
  \catcode`\"=\active
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Print Certificates for Participants (in German: ``Scheine'')
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newbox\scheinbox
\newenvironment{scheine}{%
  \setcounter{flag}{2}
  \newcommand{\zweiproseite}{\setcounter{flag}{0}}%
  \newcommand{\einschein}{\scheinDoIt
                          \box\scheinbox}%
  \newcommand{\allescheine}{\allescheineDoIt}}
  {}

\def\allescheineDoIt{%
  \newread\inputfile%
  \openin\inputfile=\the\myteilnehmerdatei%
  \read\inputfile to \dummy
  %% first: overread the header (see above at analyzeParticipantsFile)
  %%%%%%% note that the linebreak in the subsequent line is NECESSARY!
  \whiledo{\not\equal{\dummy}{.
     }}{\read\inputfile to \dummy}

  %% now: read data items until the end sign "$" is reached         %$
  %%%%%%% note that the linebreak in the subsequent line is NECESSARY!
  \whiledo{\not\equal{\dummy}{$
    }}%$
    { \readentry\bestandentrue %% if non-graded list of students
      \ifthenelse{\equal{\note}{5
         }}{\bestandenfalse}{\bestandentrue}%
      \ifthenelse{\value{Cpunkte}<99}%
       {\ifthenelse{\punkte<\mindestpunktzahl}%
         {\bestandenfalse}{\bestandentrue}}{}%   
       \ifthenelse{\value{Cnote}<99}%
        {\ifx\note\nichtbestanden\bestandenfalse\fi}{}%
      \ifbestanden%
        \ifthenelse{\value{flag}=0}%
                 {\newpage~\setcounter{flag}{2}}{}%
        \ifthenelse{\value{flag}=1}{}{}%
        \addtocounter{flag}{-1}%
        \vfill
        \ifbenotet\ifthenelse{\value{Cnote}<99}{}{\bewertung}\fi
        \scheinDoIt% defines the \box\scheinbox
        \box\scheinbox%
        \vfill
      \fi
 
      \read\inputfile to \dummy
      \whiledo{\not\equal{\dummy}{.
              } \and  \not\equal{\dummy}{$
              }}%$
        {\read\inputfile to \dummy}%
    }
  %% now, the "$" has been read                                %$
  % if we have two output items per page, and only one is filled,
  % add an empty output box
  \ifthenelse{\value{flag}=1}{\ \vfill
                            \scheinDoIt
                            \vbox to \ht\scheinbox {\vfill}
                            \vfill}{}
  \ \newpage
  \closein\inputfile
  \undefineallproperties
} % end of alleScheineDoIt


