<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package ticketserver::GUI;

use strict;
use warnings;

our @ISA = ("ADBGUI::GUI");

use ADBGUI::BasicVariables;
use ADBGUI::GUI;
use ADBGUI::Tools qw(Log mergeColumnInfos localtime2sql);
use ticketserver::DBDesign qw($TICKETS $BOXES $VERBUND $MAC $MACSPEZIAL $CUSTOMER $SURFTIMEFLAG $INSTALLATIONFLAG $VORLAGE $VORLAGENFLAG $VERBUNDFLAG $DATEOWNFLAG);
use HTTP::Date qw(str2time);
use Time::Local;
use IPC::Run qw( start pump finish timeout );
use JSON qw(to_json from_json);

my $TICKET_FILTER         = 1;
my $TICKET_MAC_DATA       = 2;
my $TICKET_ENDUSER_FILTER = 3;
my $TICKET_ENDUSER_DATA   = 4;
my $TICKET_MAC_DELENTRY   = 5;

sub new {
   my $proto = shift;
   my $class = ref($proto) || $proto;
   my $self = shift;
   my $parent = $self ? ref($self) : "";
   @ISA = ($parent) if $parent;
   $self = $self ? $self : {};
   bless ($self, $class);
   $self-&gt;{config}-&gt;{DEFAULTTABLE} = $TICKETS;
   $self-&gt;{config}-&gt;{DEFAULTJOB} ||= "defaultjob";

   $self-&gt;AddHandler($self-&gt;{config}-&gt;{DEFAULTJOB}, sub {
      my $self = shift;
      my $targetself = shift;
      my $line = shift;
      my $stadium = shift || 0;
      $_ = $line-&gt;{data};
      if (!defined($self-&gt;{state}) || ($self-&gt;{state} == $NOSTATE)) {
         unless ($targetself-&gt;{sessionid} ||
                 $self-&gt;{"q"}-&gt;param("job") ||
                 $self-&gt;{"q"}-&gt;param("user")) {
            #$targetself-&gt;{state} = $NOSTATE;
            my $target = $self-&gt;getHandler("boxtemplate");
            $targetself-&gt;{handler} = $target-&gt;{handler};
            return $targetself-&gt;{handler}($self, $targetself, {});
         } elsif($targetself-&gt;{noStyle}) {
            delete $targetself-&gt;{noStyle};
            print $self-&gt;{"q"}-&gt;header(-charset =&gt; 'utf-8');
            print $self-&gt;{header};
         }
         my $autret;
         return $autret
            if ((!$targetself-&gt;{sessionid}) &amp;&amp; (($autret = $self-&gt;authenticate($line, $targetself, $stadium)) != $ACTIONOK));
         unless ((defined($self-&gt;{"q"}-&gt;param("job")) &amp;&amp;
                         ($self-&gt;{"q"}-&gt;param("job") ne "")) || ($targetself-&gt;{rights} &amp; $MODIFY)) {
            $targetself-&gt;{state} = $NOSTATE;
            my $target = $self-&gt;getHandler("show");
            $targetself-&gt;{handler} = $target-&gt;{handler};
            return $targetself-&gt;{handler}($self, $targetself, {});
         }
         print "&lt;h2&gt;".$self-&gt;{text}-&gt;{T_WELCOME}."&lt;/h2&gt;\n";
         print "&lt;em&gt;".$self-&gt;{text}-&gt;{T_WELCOME_DESC}."&lt;/em&gt;&lt;br&gt;&lt;br&gt;\n" if $self-&gt;{text}-&gt;{T_WELCOME_DESC};
         if ($targetself-&gt;{rights} &amp; ($MODIFY)) {
            print "Installationen:&lt;div class=\"categories\"&gt;\n";
            if ($targetself-&gt;{rights} &amp; ($ADMIN)) {
               print $self-&gt;HashButton( {
                  sessionid =&gt; $targetself-&gt;{sessionid},
                  job =&gt; "show",
                  table =&gt; $CUSTOMER
               }, $self-&gt;{text}-&gt;{B_CUSTOMER}, { link =&gt; 1 } );
               print "&lt;br&gt;";
            }
            print $self-&gt;HashButton( {
               sessionid =&gt; $targetself-&gt;{sessionid},
               job =&gt; "show",
               table =&gt; $USERSTABLENAME
            }, $self-&gt;{text}-&gt;{B_USER_ADMINISTRATION}, { link =&gt; 1 } );
            print "&lt;br&gt;";
            print $self-&gt;HashButton( {
               sessionid =&gt; $targetself-&gt;{sessionid},
               job =&gt; "show",
               table =&gt; $BOXES
            }, $self-&gt;{text}-&gt;{B_BOXES}, { link =&gt; 1 } );
            print "&lt;br&gt;";
            print $self-&gt;HashButton( {
               sessionid =&gt; $targetself-&gt;{sessionid},
               job =&gt; "show",
               table =&gt; $VERBUND
            }, $self-&gt;{text}-&gt;{B_VERBUND}, { link =&gt; 1 } );
            print "&lt;/div&gt;&lt;br&gt;\n";
            print "MAC Adressen:&lt;div class=\"categories\"&gt;\n";
            print $self-&gt;HashButton( {
               sessionid =&gt; $targetself-&gt;{sessionid},
               job =&gt; "show",
               table =&gt; $MAC
            }, $self-&gt;{text}-&gt;{B_MAC}, { link =&gt; 1 } );
            print "&lt;br&gt;";
            print $self-&gt;HashButton( {
               sessionid =&gt; $targetself-&gt;{sessionid},
               job =&gt; "show",
               table =&gt; $MACSPEZIAL
            }, $self-&gt;{text}-&gt;{B_MAC_SPEZIAL}, { link =&gt; 1 } );
            print "&lt;/div&gt;&lt;br&gt;\n";
         }
         print "Tickets:&lt;div class=\"categories\"&gt;\n";
         print $self-&gt;HashButton( {
            sessionid =&gt; $targetself-&gt;{sessionid},
            job =&gt; "register",
         }, "Registrieren", { link =&gt; 1 } );
         print "&lt;br&gt;";
         print $self-&gt;HashButton( {
            sessionid =&gt; $targetself-&gt;{sessionid},
            job =&gt; "show",
            sortby =&gt; $TICKETS.$TSEP.$UNIQIDCOLUMNNAME."_",
            table =&gt; $TICKETS
         }, "Verwalten", { link =&gt; 1 } );
         #if ($targetself-&gt;{rights} &amp; ($ADMIN | $MODIFY)) {
         #   print "&lt;br&gt;";
         #   print $self-&gt;HashButton( {
         #      sessionid =&gt; $targetself-&gt;{sessionid},
         #      job =&gt; "show",
         #      table =&gt; $SURFLOG
         #   }, "Logdaten", { link =&gt; 1 } );
         #}
         print "&lt;/div&gt;\n";
         print "&lt;br&gt;";
         print "Sonstiges:&lt;div class=\"categories\"&gt;\n";
         #if ($targetself-&gt;{rights} &amp; ($ADMIN)) {
            print $self-&gt;HashButton( {
               sessionid =&gt; $targetself-&gt;{sessionid},
               job =&gt; "show",
               table =&gt; $LOG,
               sortby =&gt; $LOG.$TSEP."mydate"."_"
            }, $self-&gt;getTableDefiniton($LOG)-&gt;{label} || $LOG, { link =&gt; 1 } );
            print "&lt;br&gt;";
         #}
         print $self-&gt;HashButton( {
            sessionid =&gt; $targetself-&gt;{sessionid},
            job =&gt; "changepasspre"
         }, $self-&gt;{text}-&gt;{B_CHANGEPASS}, { link =&gt; 1 } );
         print "&lt;/div&gt;\n";
      }
      print "&lt;br&gt;";
      print $self-&gt;HashButton( {
         sessionid =&gt; $targetself-&gt;{sessionid},
         job =&gt; "logout"
      }, $self-&gt;{text}-&gt;{B_LOGOUT});
      return $DONE;
   }, {deleteAll =&gt; 1, noStyle =&gt; 1});

   $self-&gt;AddHandler("addpost", sub {
      my $self       = shift;
      my $targetself = shift;
      my $line       = shift;
      my $stadium    = shift || 0;
      my $table = scalar($self-&gt;{"q"}-&gt;param("table"));
      if (($targetself-&gt;{addresslist} &amp;&amp; (ref($targetself-&gt;{addresslist}) eq "ARRAY")) || ($table &amp;&amp; ($table eq $MAC))) {
         if ($targetself-&gt;{addresslist}) {
            my $result = undef;
            eval {
               $result = from_json($line-&gt;{data});
            };
            if ($@) {
              print " -&gt; Internal error adding address\n";
              #Log("addpost: JSON parse error: ".$@, $ERROR);
              $self-&gt;destructor();
              $targetself-&gt;{state} = $NOSTATE;
              return $DONE;
            }
            unless ($result &amp;&amp;
               (ref($result) eq "HASH") &amp;&amp;
                   ($result-&gt;{result} eq "ok")) {
               print " -&gt; Internal error adding address\n";
               #Log("addpost: error: ".$result-&gt;{result}, $ERROR);
               $self-&gt;destructor();
               $targetself-&gt;{state} = $NOSTATE;
               return $DONE;
            }
            if ($targetself-&gt;{copyid} ||
                $targetself-&gt;{copyiddata}) {
              if ($targetself-&gt;{copyiddata}) {
                 $targetself-&gt;{columns}-&gt;{$targetself-&gt;{table}.$TSEP."tickets"."_".$UNIQIDCOLUMNNAME} = $result-&gt;{id};
                 delete $targetself-&gt;{copyid};
                 delete $targetself-&gt;{copyiddata};
              } else {
                 if (scalar(@{$result-&gt;{data}}) != 1) {
                    print " -&gt; Internal error fething tickt ".$targetself-&gt;{copyid}."\n";
                    $self-&gt;destructor();
                    $targetself-&gt;{state} = $NOSTATE;
                    return $DONE;
                 }
                 print " -&gt; &lt;font color='green'&gt;OK&lt;/font&gt;&lt;br&gt;Creating cloned ticket ";
                 foreach my $curcolumn ("tickets.beschreibung", "tickets.name", "tickets.room", "tickets.maxusedays", "tickets.mydate", "tickets.vorlage_id", "tickets.customer_id") {
                    $targetself-&gt;{copyiddata}-&gt;{$curcolumn} = $result-&gt;{data}-&gt;[0]-&gt;{$curcolumn};
                 }
                 $targetself-&gt;{copyiddata}-&gt;{"tickets.maxusedays"} = $self-&gt;{config}-&gt;{overwritecopymaxusedays}
                    if defined($self-&gt;{config}-&gt;{overwritecopymaxusedays});
                 $targetself-&gt;{copyiddata}-&gt;{"tickets.maxusedays"} ||= $self-&gt;{config}-&gt;{copymaxusedays}
                    if defined($self-&gt;{config}-&gt;{copymaxusedays});
                 $targetself-&gt;{copyiddata}-&gt;{"tickets.mydate"} = $self-&gt;{config}-&gt;{overwriteccopymydate}
                    if defined($self-&gt;{config}-&gt;{overwriteccopymydate});
                 $targetself-&gt;{copyiddata}-&gt;{"tickets.mydate"} = $self-&gt;{config}-&gt;{copymydate} ||
                                                                 $self-&gt;{config}-&gt;{newmydate} || "2030-12-31 00:00:00"
                    if ($targetself-&gt;{copyiddata}-&gt;{"tickets.maxusedays"});
                 $self-&gt;sendLine("JSON NEW ".to_json({
                    columns =&gt; $targetself-&gt;{copyiddata},
                    table   =&gt; "tickets",
                 }));
                 return $RUNNING;
               }
            }
            print "&lt;font color=green&gt; -&gt; ID ".$result-&gt;{id}."&lt;/font&gt;&lt;br&gt;\n";
         } else {
            #print "Generating&lt;br&gt;\n";
            my $address = scalar($self-&gt;{"q"}-&gt;param("address"));
            unless ($address &amp;&amp; $table) {
               print "No table or macs given?!";
               $self-&gt;destructor();
               $targetself-&gt;{state} = $NOSTATE;
               return $DONE;
            }
            $targetself-&gt;{table} = $table;
            #print "ADDRESS:".$address."&lt;br&gt;\n";
            $targetself-&gt;{addresslist} = [split(",", $address)];
            my $tabledef = $self-&gt;getTableDefiniton($targetself-&gt;{table})-&gt;{columns};
            foreach my $column (keys(%$tabledef)) {
               if ($tabledef-&gt;{$column}-&gt;{type} eq "virtual") {
                  next;
               } elsif ($tabledef-&gt;{$column}-&gt;{type} eq "boolean") {
                  $targetself-&gt;{columns}-&gt;{$targetself-&gt;{table}.$TSEP.$column} = $self-&gt;{"q"}-&gt;param($column) ? "1" : "0";
               } elsif (($tabledef-&gt;{$column}-&gt;{type} eq "date") ||
                        # TODO:XXX:FIXME: datetime ist im GUI.pm noch nicht ordentlich behandelt, faellt derzeit auf date zurueck!
                        ($tabledef-&gt;{$column}-&gt;{type} eq "datetime")) {
                  $targetself-&gt;{columns}-&gt;{$targetself-&gt;{table}.$TSEP.$column} = $self-&gt;getStringForDate($column, $_);
               } elsif (($tabledef-&gt;{$column}-&gt;{type} eq $DELETEDCOLUMNNAME) || ($tabledef-&gt;{$column}-&gt;{type} eq 'boolean')) {
                  $targetself-&gt;{columns}-&gt;{$targetself-&gt;{table}.$TSEP.$column} = grep { $_ &amp;&amp; (!/^false$/i) } ($self-&gt;{"q"}-&gt;param($column)) ? '1' : '0';
               } else {
                  my $tmp = $self-&gt;{"q"}-&gt;param($column);
                  # TODO/FIXME: Im Moment unterst�tzen wir nur einzeilige Eingaben!
                  $tmp =~ s/[\n\r]+/ /g;
                  $targetself-&gt;{columns}-&gt;{$targetself-&gt;{table}.$TSEP.$column} = $tmp;
               }
            }
            delete $targetself-&gt;{columns}-&gt;{$targetself-&gt;{table}.$TSEP."address"};
            foreach my $column (keys(%$tabledef)) {
               my $curcolumn = mergeColumnInfos($self-&gt;getDBBackend($targetself-&gt;{table}), $tabledef-&gt;{$column});
               if ($curcolumn-&gt;{syntaxcheck} &amp;&amp; $self-&gt;{"q"}-&gt;param($column) &amp;&amp; (!($self-&gt;{"q"}-&gt;param($column) =~ (/$curcolumn-&gt;{syntaxcheck}/)))) {
                  print "&lt;font color='red'&gt;&lt;b&gt;ERROR:&lt;/b&gt; '".($curcolumn-&gt;{label}."('".$column."')"||"'".$column."'")."'".$self-&gt;{text}-&gt;{WRONG_SYNTAX}.": '".$curcolumn-&gt;{syntaxcheck}."'&lt;/font&gt;&lt;br&gt;\n";
                  $self-&gt;destructor();
                  $targetself-&gt;{state} = $NOSTATE;
                  return $DONE;
               }
               unless (defined($self-&gt;{"q"}-&gt;param($column))) {
                  unless ((!$curcolumn-&gt;{notnull}) ||
                          (($curcolumn-&gt;{type} eq "boolean") ||
                           ($curcolumn-&gt;{type} eq $DELETEDCOLUMNNAME) ||
                           ($curcolumn-&gt;{type} eq "date") ||
                            # TODO:XXX:FIXME: datetime ist im GUI.pm noch nicht ordentlich behandelt, faellt derzeit auf date zurueck!
                           ($curcolumn-&gt;{type} eq "datetime") ||
                           ($curcolumn-&gt;{type} eq $UNIQIDCOLUMNNAME) ||
                           ($curcolumn-&gt;{readonly}))) {
                     print $column;
                     print "(".$curcolumn-&gt;{label}.")" if $curcolumn-&gt;{label};
                     print $self-&gt;{text}-&gt;{IS_MISSING}."\n";
                     $self-&gt;destructor();
                     $targetself-&gt;{state} = $NOSTATE;
                     return $DONE;
                  }
               }
            }
            delete $targetself-&gt;{columns}-&gt;{$targetself-&gt;{table}.$TSEP.$UNIQIDCOLUMNNAME};
            unless ($targetself-&gt;{columns}-&gt;{$targetself-&gt;{table}.$TSEP."tickets"."_".$UNIQIDCOLUMNNAME}) {
               if ($targetself-&gt;{copyid} = scalar($self-&gt;{"q"}-&gt;param("id"))) {
                  print "Requesting ticket ".$targetself-&gt;{copyid}."\n";
                  $self-&gt;sendLine("JSON GET tickets ".$targetself-&gt;{copyid});
               } else {
                  print "Creating new ticket\n";
                  $targetself-&gt;{copyiddata} = {
                     "tickets.vorlage_id"  =&gt; $self-&gt;{config}-&gt;{newvorlage_id}  || 1,
                     "tickets.customer_id" =&gt; $self-&gt;{config}-&gt;{newcustomer_id} || 1,
                     "tickets.mydate"      =&gt; $self-&gt;{config}-&gt;{newmydate}      || "2030-12-31 00:00:00",
                     "tickets.maxusedays"  =&gt; $self-&gt;{config}-&gt;{newmaxusedays}  || 28,
                  };
                  $self-&gt;sendLine("JSON NEW ".to_json({
                     columns =&gt; $targetself-&gt;{copyiddata},
                     table =&gt; "tickets",
                  }));
               }
               return $RUNNING;
            }
         }
         unless (scalar(@{$targetself-&gt;{addresslist}})) {
            print "&lt;br&gt;";
            $targetself-&gt;{state} = $NOSTATE;
            my $target = $self-&gt;getHandler("register");
            $targetself-&gt;{handler} = $target-&gt;{handler};
            $self-&gt;AddHandler($self-&gt;{job}, sub { my $self = shift; return $DONE }, {deleteAll =&gt; 1});
            return $targetself-&gt;{handler}($self, $targetself, {});
         }
         my $curaddress = shift(@{$targetself-&gt;{addresslist}});
         print "Adding ".$curaddress." ";
         $targetself-&gt;{columns}-&gt;{$targetself-&gt;{table}.$TSEP."address"} = $curaddress;
         $self-&gt;sendLine("JSON NEW ".to_json({
            columns =&gt; $targetself-&gt;{columns},
            table   =&gt; $targetself-&gt;{table},
         })."\n");
         return $RUNNING;
      } else {
         return $DONE;
      }
   }, { postRun =&gt; 1 });

   $self-&gt;AddHandler("addpost", sub {
      my $self       = shift;
      my $targetself = shift;
      my $line       = shift;
      my $stadium    = shift || 0;
      $_ = $line-&gt;{data};
      my $table   = scalar($self-&gt;{"q"}-&gt;param("table"));
      my $realydo = scalar($self-&gt;{"q"}-&gt;param("realydo"));
      my $autret;
      if ($table eq $MAC) {
         my $tag = "GET";
         $targetself-&gt;{ticketid}  = scalar($self-&gt;{"q"}-&gt;param("tickets_id"));
         $targetself-&gt;{address}   = scalar($self-&gt;{"q"}-&gt;param("address"));
         $targetself-&gt;{startdate} = scalar($self-&gt;{"q"}-&gt;param("start"));
         if ($targetself-&gt;{state} == $NOSTATE) {
            my $autret;
            if (($autret = $self-&gt;authenticate($line, $targetself, $stadium)) != $ACTIONOK) {
               $self-&gt;destructor()
                  if $autret == $DONE;
               return $autret
            }
            #print "&lt;h2&gt;".$self-&gt;{text}-&gt;{T_SEARCH}."&lt;/h2&gt;\n&lt;em&gt;lalala&lt;/em&gt;&lt;br&gt;&lt;br&gt;\n";
            $self-&gt;sendLine("SETFILTER ".$table." BEGIN");
            $self-&gt;sendLine("mac.tickets_id: ".$targetself-&gt;{ticketid});
            $self-&gt;sendLine("SETFILTER ".$table." END");
            $targetself-&gt;{state} = $TICKET_FILTER;
            return $RUNNING;
         } elsif ($targetself-&gt;{state} == $TICKET_FILTER) {
            return $autret if (($autret = $self-&gt;setFilter($line, $targetself)) != $ACTIONOK);
            $self-&gt;sendLine("JSON GET mac");
            $targetself-&gt;{state} = $TICKET_MAC_DATA;
            return $RUNNING;
         } elsif ($targetself-&gt;{state} == $TICKET_MAC_DATA) {
            if (my $data = from_json($_)) {
               #print "Hello Worldx: ".$table."/".$targetself-&gt;{ticketid}."/".$data."!&lt;br&gt;";
               $targetself-&gt;{maccache} = {};
               unless (scalar(@{$data-&gt;{data}})) {
                  $self-&gt;sendLine("FILTERRESET mac");
                  $targetself-&gt;{state} = $FILTERRESET;
                  return $RUNNING;
                  #$targetself-&gt;{state} = $NOSTATE;
                  #return $DONE;
               }
               my $nomultiple = 0;
               foreach my $mac (@{$data-&gt;{data}}) {
                  #print "TICkET:".join(",", sort { $a cmp $b } keys %$ticket)."&lt;br&gt;\n";
                  #print "MAC: ".$ticket-&gt;{"mac.address"}."&lt;br&gt;\n";
                  $targetself-&gt;{nomultiple}++
                     if ($mac-&gt;{"tickets_id_tickets.nomultiple"});
                  unless ($mac-&gt;{"mac.address"}) {
                     print "&lt;font color=red&gt;WARNING:&lt;/font&gt; No mac address on mac entry ".$self-&gt;HashButton({
                        sessionid         =&gt; $targetself-&gt;{sessionid},
                        job               =&gt; "updatepre",
                        table             =&gt; "mac",
                        $UNIQIDCOLUMNNAME =&gt; $mac-&gt;{"mac.id"},
                     }, $mac-&gt;{"mac.id"}, { link =&gt; 1 })."&lt;br&gt;\n";
                     next;
                  }
                  push(@{$targetself-&gt;{maccache}-&gt;{$mac-&gt;{"mac.address"}}-&gt;{macdata}}, $mac);
                  #if (                     $mac-&gt;{"mac.start"} &amp;&amp;
                  #   (my $start = str2time($mac-&gt;{"mac.start"}))) {
                  #   $targetself-&gt;{curstart} = [$start, $mac-&gt;{"mac.id"}]
                  #      if (!$targetself-&gt;{curstart}-&gt;[0] ||
                  #          ($targetself-&gt;{curstart}-&gt;[0] &gt; $start));
                  #} else {
                  #   print "&lt;font color=red&gt;WARNING:&lt;/font&gt; No start on mac entry ".$mac-&gt;{"mac.id"}."&lt;br&gt;\n";
                  #}
                  #print "ADDING '".$mac-&gt;{"mac.address"}."'&lt;br&gt;\n";
                  #push(@{$targetself-&gt;{endusermacs}}, $ticket-&gt;{"mac.id"});
               }
               $targetself-&gt;{endusermacs} = [keys %{$targetself-&gt;{maccache}}];
               $targetself-&gt;{macids}      = [map {
                  $_-&gt;{"mac.id"}
               } map {
                  (@{$targetself-&gt;{maccache}-&gt;{$_}-&gt;{macdata}})
               } keys %{$targetself-&gt;{maccache}}];
               return $self-&gt;loopEnduser($targetself, undef, $realydo, $targetself-&gt;{nomultiple});
            } else {
               print "Cannot fetch ticket information.\n";
               $self-&gt;destructor();
            }
         } elsif ($targetself-&gt;{state} == $TICKET_ENDUSER_FILTER) {
            return $autret if (($autret = $self-&gt;setFilter($line, $targetself)) != $ACTIONOK);
            $self-&gt;sendLine("JSON GET enduser");
            $targetself-&gt;{state} = $TICKET_ENDUSER_DATA;
            return $RUNNING;
         } elsif ($targetself-&gt;{state} == $TICKET_MAC_DELENTRY) {
            if (/^((UN)?DEL) (\S+) (\S+)(\s(.*))?$/) {
               my $cmd = $1;
               my $uniqid = $3;
               my $action = $4;
               my $error = $5 || '';
               return $self-&gt;loopEnduser($targetself, undef, $realydo, $targetself-&gt;{nomultiple})
                  if ($action eq "OK");
               print "&lt;font color='#FF0000'&gt;&lt;b&gt;ERROR:&lt;/b&gt; ".$error."&lt;/font&gt;\n";
            } else {
               print "PROTKOLL ERROR 244.\n";
            }
            $self-&gt;destructor();
         } elsif ($targetself-&gt;{state} == $FILTERRESET) {
            return $autret if (($autret = $self-&gt;setFilterReset($line, $targetself)) != $ACTIONOK);
            $targetself-&gt;{state} = $NOSTATE;
            return $DONE;
         } elsif ($targetself-&gt;{state} == $TICKET_ENDUSER_DATA) {
            if (my $data = from_json($_)) {
               return $self-&gt;loopEnduser($targetself, $data, $realydo, $targetself-&gt;{nomultiple});
            } else {
               print "Cannot fetch enduser data!\n";
               $self-&gt;destructor();
            }
            $targetself-&gt;{state} = $NOSTATE;
            return $DONE;
         }
      }
      return $DONE;
   }, { postRun =&gt; 1 });

   $self-&gt;AddHandler("registeraddmac", sub {
      my $self = shift;
      my $targetself = shift;
      my $line = shift;
      my $stadium = shift || 0;
      $_ = $line-&gt;{data};
      if ($targetself-&gt;{state} == $NOSTATE) {
         my $autret;
         if (($autret = $self-&gt;authenticate($line, $targetself, $stadium)) != $ACTIONOK) {
            $self-&gt;destructor()
               if $autret == $DONE;
            return $autret
         }
         $self-&gt;sendLine("REGISTERADDMAC ".scalar($self-&gt;{"q"}-&gt;param("mac")));
         $targetself-&gt;{state} = $GETDATA;
         return $RUNNING;
      } elsif ($targetself-&gt;{state} == $GETDATA) {
         if (/^REGISTERADDMAC\s+(\S+)$/) {
            my $action = $1;
            if ($action eq "OK") {
               print "&lt;font color=green&gt;REGISTERADDMAC OK&lt;/font&gt;&lt;br&gt;&lt;br&gt;\n";
            } else {
               print "&lt;font color=red&gt;REGISTERADDMAC ERROR&lt;/font&gt;&lt;br&gt;&lt;br&gt;\n";
            }
         } else {
            print "Protokoll error!\n";
            return $DONE;
         }
         $targetself-&gt;{state} = $NOSTATE;
         my $target = $self-&gt;getHandler("register");
         $targetself-&gt;{handler} = $target-&gt;{handler};
         return $targetself-&gt;{handler}($self, $targetself, {});
      }
      return $DONE;
   });

   $self-&gt;AddHandler("ticketpre", sub {
      my $self = shift;
      my $targetself = shift;
      my $line = shift;
      my $stadium = shift || 0;
      $_ = $line-&gt;{data};
      my $autret = undef;

      my $table       = $self-&gt;{"q"}-&gt;param("table");
      my $overwriteid = $self-&gt;{"q"}-&gt;param("overwriteid");
      $table = $self-&gt;{config}-&gt;{DEFAULTTABLE} unless $self-&gt;getDBBackend($table);
      if ($targetself-&gt;{state} == $NOSTATE) {
         return $autret if (($autret = $self-&gt;authenticate($line, $targetself, $stadium)) != $ACTIONOK);
         $self-&gt;sendLine("FILTERRESET ".$table);
         $targetself-&gt;{state} = $FILTERRESET;
         return $RUNNING;
      } elsif ($targetself-&gt;{state} == $FILTERRESET) {
         return $autret if (($autret = $self-&gt;setFilterReset($line, $targetself)) != $ACTIONOK);
         print "&lt;h2&gt;".$self-&gt;{text}-&gt;{T_EDIT}."&lt;/h2&gt;\n&lt;em&gt;".$self-&gt;{text}-&gt;{T_EDIT_DESC}."&lt;/em&gt;&lt;br&gt;&lt;br&gt;\n";
         $targetself-&gt;{tableQueue} = [];
         my $db = $self-&gt;getDBBackend($table);
         foreach (keys(%{$db-&gt;{tables}})) {
            # TODO:XXX:FIXME: No support for tag "linkto" on column
            if (defined($db-&gt;{tables}-&gt;{$table}-&gt;{columns}-&gt;{$_."_".$UNIQIDCOLUMNNAME})) {
               push(@{$targetself-&gt;{tableQueue}}, $_);
            }
         }
         if (scalar(@{$targetself-&gt;{tableQueue}})) {
            my $curtable = pop(@{$targetself-&gt;{tableQueue}});
            my $sortcolumn = $curtable.$TSEP.$db-&gt;{tables}-&gt;{$curtable}-&gt;{crossShowInSelect} || '';
            $self-&gt;sendLine("GET ".$curtable."    ".$sortcolumn);
            $targetself-&gt;{state} = $GETDATA;
            return $RUNNING;
         } else {
            $self-&gt;sendLine("GET ".$table." ".$self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME));
            $targetself-&gt;{state} = $SHOWTABLE;
            return $RUNNING;
         }
      } elsif ($targetself-&gt;{state} == $GETDATA) {
         return $autret if (($autret = $self-&gt;retrieveTables($line, $targetself, $stadium, $targetself-&gt;{tableQueue})) != $ACTIONOK);
         $self-&gt;sendLine("GET ".$table." ".($overwriteid || $self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME)));
         $targetself-&gt;{state} = $SHOWTABLE;
         return $RUNNING;
      } elsif ($targetself-&gt;{state} == $SHOWTABLE) {
         if (/^GET (\S+) (\S+)(\s(\S+))?(\s(\S+))?(\s*[.*])?$/) {
            my $table = $1;
            my $action = $2;
            my $lines = $4;
            my $filtered = $6;
            $targetself-&gt;{filtered} = $filtered ? 1 : 0;
            my $error = $5.$7;
            if ($action eq "BEGIN") {
               return $RUNNING;
            } elsif ($action eq "FAILED") {
               print "&lt;font color='#FF0000'&gt;&lt;b&gt;ERROR:&lt;/b&gt; ".$error."&lt;/font&gt;\n";
            } elsif ($action eq "NEXT") {
               #print "&lt;font color='#FF0000'&gt;&lt;b&gt;ERROR:&lt;/b&gt; $self-&gt;{text}-&gt;{ERR_LINES_EXPECTED}&lt;/font&gt;\n";
               return $RUNNING;
            } elsif ($action eq "END") {
               $targetself-&gt;{mydefaults}-&gt;{$table.$TSEP.$UNIQIDCOLUMNNAME} = $self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME)
                  if $overwriteid;
               $targetself-&gt;{mydefaults}-&gt;{$table.$TSEP."address"}         = $self-&gt;{"q"}-&gt;param("address")
                  unless $self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME);
               if ($self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME) &amp;&amp;
                  ($self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME) ne $targetself-&gt;{mydefaults}-&gt;{$table.$TSEP.$UNIQIDCOLUMNNAME})) {
                  print "&lt;font color='#FF0000'&gt;&lt;b&gt;ERROR:&lt;/b&gt; Query returned wrong ID.&lt;/font&gt;&lt;br&gt;\n";
                  return $DONE;
               }
               print "&lt;table&gt;&lt;tr&gt;&lt;td bgcolor=#BBBBFF&gt;&amp;Uuml;berschreibe ".($self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME) || "-")." mit:&lt;br&gt;\n";
               print "&lt;FORM method='GET' action='".$self-&gt;{"q"}-&gt;url(-relative=&gt;1)."'&gt;\n";
               print "&lt;input type=text name=overwriteid value='".$overwriteid."'&gt;";
               print "&lt;input name='sessionid' type='hidden' value='".$targetself-&gt;{sessionid}."'&gt;\n";
               print "&lt;input name='job' type='hidden' value='ticketpre'&gt;\n";
               print "&lt;input name='".$UNIQIDCOLUMNNAME."' type='hidden' value='".$self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME)."'&gt;\n"
                  if defined($self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME));
               print "&lt;input name='address' type='hidden' value='".($self-&gt;{"q"}-&gt;param("address") || $targetself-&gt;{mydefaults}-&gt;{$table.$TSEP."address"})."'&gt;\n"
                  if defined(($self-&gt;{"q"}-&gt;param("address") || $targetself-&gt;{mydefaults}-&gt;{$table.$TSEP."address"}));
               print "&lt;input name='verified' type='hidden' value='".$self-&gt;{"q"}-&gt;param("verified")."'&gt;\n"
                  if defined($self-&gt;{"q"}-&gt;param("verified"));
               print "&lt;input type=hidden name=table value='".$self-&gt;{"q"}-&gt;param("table")."'&gt;";
               print "&lt;input type=submit&gt;";
               print "&lt;/form&gt;&lt;/tr&gt;&lt;/td&gt;&lt;/table&gt;&lt;br&gt;&lt;br&gt;";
               print $self-&gt;printFormFor($table, $self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME) ? $self-&gt;{text}-&gt;{FORM_CHANGE} : $self-&gt;{text}-&gt;{FORM_ADD}, $self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME) ? "updatepost" : "addpost", $targetself-&gt;{sessionid}, undef, $overwriteid || $self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME) ? $targetself-&gt;{mydefaults} : undef, scalar($self-&gt;{"q"}-&gt;param($UNIQIDCOLUMNNAME)), $targetself-&gt;{tableCache}, $targetself);
               delete $targetself-&gt;{mydefaults};
            } else {
               print "PROTOKOLL ERROR 4.&lt;br&gt;\n";
               return $PROTOKOLLERROR;
            }
         } elsif (/^([^:]+):\s(.*)$/) {
            my $key = $1;
            my $value = $2;
            $targetself-&gt;{mydefaults}-&gt;{$key} = $value;
            return $RUNNING;
         } else {
            print "PROTOKOLL ERROR 5.&lt;br&gt;\n";
            return $PROTOKOLLERROR;
         }
      }
      return $DONE;
   });

   $self-&gt;AddHandler("register", sub {
      my $self = shift;
      my $targetself = shift;
      my $line = shift;
      my $stadium = shift || 0;
      $_ = $line-&gt;{data};

      if ($targetself-&gt;{state} == $NOSTATE) {
         my $autret;
         if (($autret = $self-&gt;authenticate($line, $targetself, $stadium)) != $ACTIONOK) {
            $self-&gt;destructor()
               if $autret == $DONE;
            return $autret
         }
         $self-&gt;sendLine("JSON REGISTRATIONS");
         $targetself-&gt;{state} = $GETDATA;
         return $RUNNING;
      } elsif ($targetself-&gt;{state} == $GETDATA) {
         if (my $data = from_json($_)) {
            if ($data-&gt;{result} eq "ok") {
               print "&lt;form method=post&gt;\n";
               print "&lt;input type=hidden name=job value='registeraddmac'&gt;";
               print "&lt;input type=text name=mac placeholder='Add mac manually'&gt;&lt;input type=submit&gt;&lt;br&gt;\n";
               print "&lt;input type=hidden name=sessionid value='".$targetself-&gt;{sessionid}."'&gt;";
               print "&lt;/form&gt;\n";
               print "&lt;table border=1&gt;\n";
               print "&lt;tr&gt;&lt;td&gt;MAC&lt;/td&gt;&lt;td&gt;Letzte Sichtung&lt;/td&gt;&lt;td&gt;Accesspoint&lt;/td&gt;&lt;td&gt;Verwendbar&lt;/td&gt;&lt;td&gt;Hersteller&lt;/td&gt;&lt;td&gt;Daten&lt;/td&gt;&lt;td&gt;Tickets&lt;/td&gt;&lt;td&gt;Historie&lt;/td&gt;&lt;/tr&gt;\n";
               foreach my $registration (sort {
                  $b-&gt;[1] &lt;=&gt;
                  $a-&gt;[1]
               } @{$data-&gt;{data}}) {
                  print "&lt;tr&gt;";
                  my $count = 0;
                  foreach my $column (@$registration) {
                     print "&lt;td valign=top&gt;";
                     $count++;
                     if ($count == 1) {
                        print "&lt;a href='gui.pl/".$column."' target='_blank'&gt;".$column."&lt;/a&gt;";
                     } elsif ($count == 2) {
                        if ($column =~ m,^\d+$,) {
                           print "".(time()-$column)." Sekunden";
                        } else {
                           print $column;
                        }
                     } elsif ($count == 4) {
                        if ($column =~ m,^\d+$,) {
                           if ($column) {
                              print "Ja.\n";
                           } else {
                              print "Nein.\n";
                           }
                        } else {
                           print $column;
                        }
                     } elsif ($count == 6) {
                        if (ref($column) eq "HASH") {
                           print $self-&gt;HashButton( {
                              sessionid         =&gt; $targetself-&gt;{sessionid},
                              job               =&gt; "ticketpre",
                              table             =&gt; "enduser",
                              $UNIQIDCOLUMNNAME =&gt; $column-&gt;{"enduser.id"},
                           }, "&lt;font color=".($column-&gt;{"enduser.verified"} ? "green" : "red")."&gt;".$column-&gt;{"enduser.name"}."&lt;br&gt;".$column-&gt;{"enduser.forename"}."&lt;/font&gt;", { link =&gt; 1 } );
                           print "&lt;br&gt;".$self-&gt;HashButton( {
                              sessionid         =&gt; $targetself-&gt;{sessionid},
                              job               =&gt; "delpre",
                              table             =&gt; "enduser",
                              $UNIQIDCOLUMNNAME =&gt; $column-&gt;{"enduser.id"},
                           }, "E.".$column-&gt;{"enduser.id"}." Löschen", { link =&gt; 1 } );
                        } else {
                           print $self-&gt;HashButton( {
                              sessionid         =&gt; $targetself-&gt;{sessionid},
                              job               =&gt; "ticketpre",
                              table             =&gt; "enduser",
                              address           =&gt; $registration-&gt;[0],
                              verified          =&gt; 1,
                           }, "&lt;center&gt;&lt;i&gt;Unregistriert&lt;/i&gt;&lt;/center&gt;", { link =&gt; 1 } );
                        }
                     } elsif ($count == 7) {
                        if (ref($column) eq "ARRAY") {
                           if (@$column) {
                              print join(" | ", map {
                                 $self-&gt;HashButton( {
                                    sessionid         =&gt; $targetself-&gt;{sessionid},
                                    job               =&gt; "setfilter",
                                    table             =&gt; "mac",
                                    searchtickets_id  =&gt; $_,
                                 }, $_, { link =&gt; 1 } );
                              } @$column);
                              print "&lt;br&gt;";
                           }
                           print $self-&gt;HashButton( {
                              sessionid         =&gt; $targetself-&gt;{sessionid},
                              job               =&gt; "addpre",
                              table             =&gt; "mac",
                              mydate            =&gt; localtime2sql(time()),
                              start             =&gt; localtime2sql(time()),
                              address           =&gt; $registration-&gt;[0],
                              autodel           =&gt; 0,
                           }, "Ticket zuweisen", { link =&gt; 1 } );
                        } else {
                           print $column;
                        }
                     } elsif ($count == 8) {
                        print "&lt;table&gt;";
                        #"&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;#&lt;/th&gt;&lt;th&gt;Name / Beschreibung / Raum&lt;/th&gt;&lt;/tr&gt;";
                        foreach my $curticket (sort {
                           $column-&gt;{$a}-&gt;{mac}-&gt;{$MAC.$TSEP.$DELETEDCOLUMNNAME} &lt;=&gt;
                           $column-&gt;{$b}-&gt;{mac}-&gt;{$MAC.$TSEP.$DELETEDCOLUMNNAME} ||
                           $b &lt;=&gt; $a
                        } grep {
                           scalar(keys %{$column-&gt;{$_}-&gt;{macs}})
                        } keys %$column) {
                           my $uniqid = $registration-&gt;[0].':'.$curticket.':macs';
                           #print Dumper($column-&gt;{$curticket}-&gt;{macs});
                           my $gerateanz = scalar(keys %{$column-&gt;{$curticket}-&gt;{macs}});
                           print "&lt;tr&gt;";
                           print "&lt;td valign=top&gt;".$self-&gt;HashButton({
                              sessionid =&gt; $targetself-&gt;{sessionid},
                              job       =&gt; "updatepre",
                              table     =&gt; "tickets",
                              id        =&gt; $curticket,
                           }, getValueForTime((map {
                              ($column-&gt;{$curticket}-&gt;{mac}-&gt;{$_})
                           } ("tickets_id_tickets".$TSEP.$TIMESTAMP,
                              "tickets_id_tickets".$TSEP."usehours",
                              "tickets_id_tickets".$TSEP."used")), "100%", $column-&gt;{$curticket}-&gt;{mac}-&gt;{$MAC.$TSEP.$DELETEDCOLUMNNAME} ? "&lt;s&gt;&lt;font color=#777777&gt;".$curticket."&lt;/font&gt;&lt;/s&gt;" : $curticket), { link =&gt; 1 })."&lt;/td&gt;";
                           print "&lt;td valign=top&gt;&lt;a onClick='if (document.getElementById(".chr(34).$uniqid.chr(34).").style.display == ".chr(34).'block'.chr(34).") { ".
                                                                "document.getElementById(".chr(34).$uniqid.chr(34).").style.display =".chr(34).'none'.chr(34)." } else {".
                                                                "document.getElementById(".chr(34).$uniqid.chr(34).").style.display =".chr(34).'block'.chr(34)." }'&gt;".
                                                                "&lt;nobr&gt;&lt;b&gt;".$gerateanz.'&lt;/b&gt;&lt;/nobr&gt;&lt;/a&gt;&lt;/td&gt;';
                           print "&lt;td&gt;";
                           print $self-&gt;HashButton({
                              sessionid =&gt; $targetself-&gt;{sessionid},
                              job       =&gt; "addpre",
                              table     =&gt; "mac",
                              mydate    =&gt; localtime2sql(time()),
                              start     =&gt; localtime2sql(time()),
                              address   =&gt; join(",", keys %{$column-&gt;{$curticket}-&gt;{macs}}),
                              autodel   =&gt; 0,
                              id        =&gt; $curticket
                           }, join("&lt;br&gt;", grep {
                              $_
                           } map {
                              $column-&gt;{$curticket}-&gt;{mac}-&gt;{$_}
                           } ("tickets_id_tickets.name",
                              "tickets_id_tickets.beschreibung",
                              "tickets_id_tickets.room")) || "---", { link =&gt; 1 });
                           print '&lt;/td&gt;';
                           print "&lt;/tr&gt;";
                           print '&lt;tr&gt;&lt;td colspan=3 valign=top&gt;&lt;div&gt;&lt;span id="'.$uniqid.'" style="display: none;"&gt;&lt;table border=1&gt;';
                           print join("\n", map {
                              "&lt;tr&gt;&lt;td&gt;".
                              $self-&gt;HashButton( {
                                 sessionid         =&gt; $targetself-&gt;{sessionid},
                                 job               =&gt; "setfilter",
                                 table             =&gt; "mac",
                                 searchtickets_id  =&gt; $curticket,
                                 searchaddress  =&gt; $_,
                              }, "&lt;font size=1&gt;".$_."&lt;/font&gt;&lt;/td&gt;", { link =&gt; 1 } ).
                              "&lt;td&gt;".join("&lt;br&gt;", map {
                                $self-&gt;HashButton( {
                                   sessionid         =&gt; $targetself-&gt;{sessionid},
                                   job               =&gt; "updatepre",
                                   table             =&gt; "enduser",
                                   id                =&gt; $_-&gt;{"enduser".$TSEP.$UNIQIDCOLUMNNAME},
                                }, "".($_-&gt;{"enduser".$TSEP."verified"} ? "" : '&lt;s&gt;').
                                       $_-&gt;{"enduser".$TSEP."name"}." ".
                                       $_-&gt;{"enduser".$TSEP."forename"}.
                                      ($_-&gt;{"enduser".$TSEP."verified"} ? "" : '&lt;/s&gt;'), { link =&gt; 1 })
                              } grep {
                                 !$_-&gt;{"enduser".$TSEP.$DELETEDCOLUMNNAME}
                              } @{$column-&gt;{$curticket}-&gt;{macs}-&gt;{$_}})."&lt;/td&gt;&lt;/tr&gt;"
                           } sort {
                            ($column-&gt;{$curticket}-&gt;{macs}-&gt;{$a}-&gt;[0]-&gt;{"enduser".$TSEP."name"} cmp
                             $column-&gt;{$curticket}-&gt;{macs}-&gt;{$b}-&gt;[0]-&gt;{"enduser".$TSEP."name"}) ||
                            ($column-&gt;{$curticket}-&gt;{macs}-&gt;{$a}-&gt;[0]-&gt;{"enduser".$TSEP."forename"} cmp
                             $column-&gt;{$curticket}-&gt;{macs}-&gt;{$b}-&gt;[0]-&gt;{"enduser".$TSEP."forename"})
                           } keys %{$column-&gt;{$curticket}-&gt;{macs}})."&lt;/table&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;";
                           print "&lt;/tr&gt;";
                        }
                        print "&lt;/table&gt;";
                     } else {
                        print $column;
                     }
                     print "&lt;/td&gt;";
                  }
                  print "&lt;/tr&gt;";
               }
               print "&lt;/table&gt;&lt;br&gt;\n";
               #print $action."\n";
            } else {
               print "Request failed at dbmanager.\n";
            }
         } else {
            print "Got non-json data (".length($data)." Bytes ) in return!\n";
         }
      }
      $self-&gt;printTableButtons($targetself, "show");
      return $DONE;
   }); # , {noStyle =&gt; 1});

   $self-&gt;AddHandler("boxtemplate", sub {
      my $self = shift;
      my $targetself = shift;
      my $line = shift;
      my $stadium = shift || 0;
      $_ = $line-&gt;{data};

      my $ip  = $ENV{HTTP_X_USER_IP};
      my $mac = $ENV{HTTP_X_USER_MAC};
      if ($targetself-&gt;{state} == $NOSTATE) {
         if ($stadium == $CONNECTED) {
            my $autret;
            $self-&gt;sendLine("BOXTEMPLATE ".to_json({
               param =&gt; {$self-&gt;{"q"}-&gt;Vars},
               agent =&gt; $self-&gt;{"q"}-&gt;user_agent(),
               ip    =&gt; $ip,
               mac   =&gt; $mac,
               full  =&gt; $self-&gt;{"q"}-&gt;url(-path_info =&gt; 1),
               path  =&gt; $self-&gt;{"q"}-&gt;url(),
            }, { utf8  =&gt; 1 }));
            $targetself-&gt;{state} = $GETDATA;
         }
         return $RUNNING;
      } elsif ($targetself-&gt;{state} == $GETDATA) {
         if (/^BOXTEMPLATE\s+(\S+)$/) {
            my $action = $1;
            if ($action eq "BEGIN") {
               print "Content-type: text/html; charset=utf-8\r\n";
               print "Connection: close\r\n";
               print "\r\n";
               $targetself-&gt;{state} = $INSERTDATA;
               return $RUNNING;
            } elsif ($action eq "RELOAD") {
               print "Location: #\r\nConnetion: close\r\n\r\n";
            } elsif ($action eq "GO") {
               print "Location: https://www.web.de/\r\nConnetion: close\r\n\r\n";
            } else {
               print "Location: ?job=overview\r\nConnetion: close\r\n\r\n";
            }
         }
         return $DONE;
      } elsif ($targetself-&gt;{state} == $INSERTDATA) {
         return $DONE
            if (/^BOXTEMPLATE\s+(\S+)$/);
         my $url = $self-&gt;{"q"}-&gt;param("url");
         my $page = '&lt;form action="https://fl.tickets.cryptomagic.eu/login" method="post"&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Ticket:&lt;/td&gt;&lt;td&gt;&lt;input name="myticket" type="text"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Passwort:&lt;/td&gt;&lt;td&gt;&lt;input name="mypasswort" type="text"&gt;&lt;/td&gt;&lt;/table&gt;&lt;input type=submit&gt;&lt;input name="url" type="hidden" value="'.$url.'"&gt;&lt;/form&gt;';
         s/\%url\%/$url/g;
         s/\%page\%/$page/g;
         print $_."\r\n"; #$self-&gt;htmlUnEscape($_);
         #print "HEADER:".join(";", map { $_."=".$ENV{$_} } sort { $a cmp $b } keys %ENV)."\n";
         return $RUNNING;
      }
      print "internal error\n";
      return $DONE;
   }, {noStyle =&gt; 1});

   $self-&gt;AddHandler("boxstatus", sub {
      my $self = shift;
      my $targetself = shift;
      my $line = shift;
      my $stadium = shift || 0;
      $_ = $line-&gt;{data};

      if ($targetself-&gt;{state} == $NOSTATE) {
         my $autret;
         return $autret if (($autret = $self-&gt;authenticate($line, $targetself, $stadium)) != $ACTIONOK);
         $self-&gt;sendLine("GETBOXSTATUS ".$self-&gt;{"q"}-&gt;param("id"));
         $targetself-&gt;{state} = $GETDATA;
         return $RUNNING;
      } elsif ($targetself-&gt;{state} == $GETDATA) {
         #print "y:".$_."\n";
         #print "Asking for ".$self-&gt;{"q"}-&gt;param("id")."\n";
         if (/^GETBOXSTATUS\s+(\S+)\s+(\S+)$/) {
            my $id = $1;
            my $action = $2;
            if ($action eq "BEGIN") {
               #print "&lt;pre&gt;\n";
               print '&lt;meta http-equiv="refresh" content="20; url=#"&gt;';
               return $RUNNING;
            } elsif ($action eq "END") {
               #print "&lt;/pre&gt;\n";
            } else {
               print "PROTOKOLL ERROR 4711\n";
            }
         } else {
            print $_;
            return $RUNNING;
         }
      }
      $self-&gt;printTableButtons($targetself, "show");
      return $DONE;
   });

   $self-&gt;AddHandler("pdf", sub {
      my $self = shift;
      my $targetself = shift;
      my $line = shift;
      my $stadium = shift || 0;
      $_ = $line-&gt;{data};
      $targetself-&gt;{table} = $TICKETS;
      $targetself-&gt;{table} = $self-&gt;{config}-&gt;{DEFAULTTABLE}
         unless $self-&gt;getTableDefiniton($targetself-&gt;{table});

      if ($targetself-&gt;{state} == $NOSTATE) {
         my $autret;
         return $autret if (($autret = $self-&gt;authenticate($line, $targetself, $stadium)) != $ACTIONOK);
         $self-&gt;sendLine("GET ".$targetself-&gt;{table}." ".$self-&gt;{"q"}-&gt;param("id"));
         $targetself-&gt;{state} = $GETDATA;
         return $RUNNING;
      } elsif ($targetself-&gt;{state} == $GETDATA) {
         my $autret;
         return $autret if (($autret = $self-&gt;retrieveTables($line, $targetself, $stadium)) != $ACTIONOK);
         if (exists($targetself-&gt;{tableCache}-&gt;{$targetself-&gt;{table}})) {
            #print "DONE.".join(",", keys(%{$targetself-&gt;{tableCache}-&gt;{$targetself-&gt;{table}}}))."\n";
            #die(ref($targetself-&gt;{tableCache}-&gt;{$targetself-&gt;{table}}));
            my $curset = $targetself-&gt;{tableCache}-&gt;{$targetself-&gt;{table}}-&gt;[0];
            print "Content-type: application/pdf\r\n\r\n";
            #print "Content-type: text/html\r\n\r\n";
            my $x = #$self-&gt;html2pdf(

               $self-&gt;replacer(
                 #$self-&gt;htmlUnEscape(
                 CGI::unescape(
                 $curset-&gt;{$VORLAGE."_".$UNIQIDCOLUMNNAME."_".$VORLAGE.$TSEP."ticketprint"}), $curset);
            # TODO:FIXME:XXX: Irgenwas macht da &lt;br&gt;s rein!!!!
            $x =~ s/&lt;br&gt;//g;
            $x = $self-&gt;html2pdf($x); # $self-&gt;htmlUnEscape($x));
            print $x;
         } else {
            print "ERROR.\n";
         }
         return $DONE;
      }
   }, {noStyle =&gt; 1});

   $self-&gt;AddHandler("registerbox", sub {
      my $self = shift;
      my $targetself = shift;
      my $line = shift;
      my $stadium = shift || 0;
      $_ = $line-&gt;{data};
      if ($stadium == $STARTUP) {
         print "Content-type: text/plain\r\n\r\n";
         return $RUNNING;
      } elsif ($stadium == $CONNECTED) {
         $self-&gt;sendLine("BOXAUTH ".$self-&gt;{"q"}-&gt;param("boxuser")." ".$self-&gt;{"q"}-&gt;param("boxpass"));
         return $RUNNING;
      } elsif ($targetself-&gt;{state} == $NOSTATE) {
         if (/^BOXAUTH\s+(\S+)\s+(\S+)$/) {
            my $id = $1;
            my $status = $2;
            if ($status eq "OK") {
               $self-&gt;sendLine("REGISTERBOX ".$self-&gt;{"q"}-&gt;param("sshkey"));
               $targetself-&gt;{state} = $INSERTDATA;
               $targetself-&gt;{id} = $id;
               return $RUNNING;
            } else {
               print "FAILED 1\n";
            }
         } else {
            print "FAILED 2\n";
         }
      } elsif ($targetself-&gt;{state} == $INSERTDATA) {
         if (/^REGISTERBOX\s+(\S*)\s+OK$/) {
            my $tunnelport = $1;
            print "OK:Saved\n";
            print "ssh_host = tickets.airnetbox.de\n"; # ".$self-&gt;{"q"}-&gt;param("boxuser").".
            print "serverhostkey = |1|GmFfeA+gmOjpj281Vkah1GeD8bo=|OnJYwjwqN5Ym0T8McxD2Ogb4Juo= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAwUlykcke23qzJtGFvfgdeTI2MMIsswtS4tiz1gx/5xvJhr109VC8A6M0ZSOQ4BtK6U1lMOJo5SgPuFeF0Ttk3vbPT960lGm1z9nsd7iH6PVeKz1j7b9VpS38+5VMcMN8FU3tQAfchtpdzYjmS8To+MK6LrVtC1qfuy94aqc0m2d9Aasf/M286FDn4qaf+DSpyMJl0qBOvmX1rJcE8r3p3e5vDLvPbUNN7Nc1KI2FWQax4JkIfVWo0h/XjacTO/7DOtTuUoPES3EbAOtTkl/1cEkloaf7K1D1e5VPJUzLyqkyDGNSRWJG28IQT4bpjhrQCdRKstPDxmlujXA26e3iyw==_|1|7YlwU3TX/axCIM+5FJbpxU4JUFo=|UM4gpqRnjgh1owJnSnpJpWxF3uE= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAwUlykcke23qzJtGFvfgdeTI2MMIsswtS4tiz1gx/5xvJhr109VC8A6M0ZSOQ4BtK6U1lMOJo5SgPuFeF0Ttk3vbPT960lGm1z9nsd7iH6PVeKz1j7b9VpS38+5VMcMN8FU3tQAfchtpdzYjmS8To+MK6LrVtC1qfuy94aqc0m2d9Aasf/M286FDn4qaf+DSpyMJl0qBOvmX1rJcE8r3p3e5vDLvPbUNN7Nc1KI2FWQax4JkIfVWo0h/XjacTO/7DOtTuUoPES3EbAOtTkl/1cEkloaf7K1D1e5VPJUzLyqkyDGNSRWJG28IQT4bpjhrQCdRKstPDxmlujXA26e3iyw==_\n";
		        print "baseurl = http://tickets.airnetbox.de/cgi-bin/ticketserver/gui.pl?job=boxtemplate&amp;boxid=".$targetself-&gt;{id}."&amp;site=\n";
            print "ssh_remote_listen_port = ".$tunnelport."\n" if ($tunnelport =~ /^\d+$/);
            print "ssh_login = tunnels\n";
            print "ssh_remote_dst_port = 4717\n";
         } else {
            print "FAILED 4\n";
         }
      } else {
         print "FAILED 3\n";
      }
      return $DONE;
   }, {noStyle =&gt; 1});

   return $self;
}

sub loopEnduser {
   my $self = shift;
   my $targetself = shift;
   my $data = shift;
   my $justdo = shift;
   my $nodelete = shift;
   if ($data) {
      foreach my $enduser (@{$data-&gt;{data}}) {
         die $enduser
            unless $enduser-&gt;{"enduser.address"};
         $targetself-&gt;{maccache}-&gt;{$enduser-&gt;{"enduser.address"}}-&gt;{userdata} = $enduser;
      }
   }
   if ($justdo) {
      if ($nodelete &amp;&amp; (my $nextmacid = pop(@{$targetself-&gt;{macids}}))) {
         print "Removed ".$nextmacid."&lt;br&gt;\n";
         $self-&gt;sendLine("DEL ".$MAC." ".$nextmacid);
         $targetself-&gt;{state} = $TICKET_MAC_DELENTRY;
         return $RUNNING;
      } else {
         $self-&gt;sendLine("FILTERRESET mac");
         $targetself-&gt;{state} = $FILTERRESET;
         return $RUNNING;
         #$targetself-&gt;{state} = $NOSTATE;
         #return $DONE;
      }
   } else {
      if (my $nextendusermac = pop(@{$targetself-&gt;{endusermacs}})) {
         $targetself-&gt;{curnextendusermac} = $nextendusermac;
         $self-&gt;sendLine("SETFILTER enduser BEGIN 1");
         #foreach my $mac (keys %{$targetself-&gt;{maccache}}) {
         #   $self-&gt;sendLine("enduser.address: ".uc($mac));
         #   print "MAC:".$mac."&lt;br&gt;\n";
         #   #last;
         #}
         #print "MAC:".$nextendusermac."&lt;br&gt;\n";
         $self-&gt;sendLine("enduser.address: ".uc($nextendusermac));
         $self-&gt;sendLine("SETFILTER enduser END 1");
         $targetself-&gt;{state} = $TICKET_ENDUSER_FILTER;
      } else {
         print "&lt;form method=post&gt;&lt;br&gt;Folgende Ger&amp;auml;tezuordnungen bestehen bereits für das Ticket ";
         print $self-&gt;HashButton({
            sessionid         =&gt; $targetself-&gt;{sessionid},
            job               =&gt; "updatepre",
            table             =&gt; "tickets",
            $UNIQIDCOLUMNNAME =&gt; $targetself-&gt;{ticketid},
         }, "&lt;b&gt;".$targetself-&gt;{ticketid}."&lt;/b&gt;", { link =&gt; 1 });
         print ".&lt;br&gt;&lt;br&gt;";
         print $nodelete ? "&lt;font color=red&gt;&lt;b&gt;Diese werden bei Zuordnung gel&amp;ouml;scht!&lt;/b&gt;&lt;/font&gt;" : "Diese bleiben erhalten, und ein weiterer Eintrag wird hinzugefuegt";
         print "&lt;br&gt;&lt;br&gt;Als Nutzungsbeginn fuer das neue Ger&amp;auml;t wird der ausgewählte Zeitpunkt &amp;uuml;bernommen:&lt;br&gt;&lt;br&gt;\n";
         print "&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt;MAC&lt;/td&gt;&lt;td&gt;Vorname&lt;/td&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Nutzungsbeginn&lt;/td&gt;&lt;/tr&gt;";
         my $first = 0;
         foreach my $mac (sort {
            my $aa = $a;
            my $ab = $b;
            my $arrya = [sort {
               $a &lt;=&gt; $b
            } map {
               str2time($_-&gt;{"mac.start"})
            } @{$targetself-&gt;{maccache}-&gt;{$aa}-&gt;{macdata}}];
            my $arryb = [sort {
               $a &lt;=&gt; $b
            } map {
               str2time($_-&gt;{"mac.start"})
            } @{$targetself-&gt;{maccache}-&gt;{$ab}-&gt;{macdata}}];
            #print $arrya-&gt;[0]."&lt;=&gt;".$arryb-&gt;[0]."&lt;br&gt;\n";
            ($arrya-&gt;[0] || undef) &lt;=&gt;
            ($arryb-&gt;[0] || undef) ||
            scalar(@$arryb) &lt;=&gt;
            scalar(@$arrya)
         } keys %{$targetself-&gt;{maccache}}) {
            unless (($targetself-&gt;{maccache}-&gt;{$mac}-&gt;{macdata} &amp;&amp;
                 ref($targetself-&gt;{maccache}-&gt;{$mac}-&gt;{macdata}) eq "ARRAY")) {
               print "Internal memory inconsistency in maccache for mac ".$mac."\n";
               $self-&gt;destructor();
            }
            print "&lt;tr&gt;&lt;td valign=top&gt;".$mac."&lt;/td&gt;";
            print "&lt;td valign=top&gt;".($targetself-&gt;{maccache}-&gt;{$mac}-&gt;{userdata}-&gt;{"enduser.forename"}||"-")."&lt;/td&gt;";
            print "&lt;td valign=top&gt;".($targetself-&gt;{maccache}-&gt;{$mac}-&gt;{userdata}-&gt;{"enduser.name"}||"-")."&lt;/td&gt;";
            print "&lt;td valign=top&gt;";
            #print scalar(@{$targetself-&gt;{maccache}-&gt;{$mac}-&gt;{macdata}})." Einträge&lt;br&gt;";
            print "&lt;font size=1&gt;";
            print join("&lt;br&gt;\n", map {
               "&lt;input type=radio name=start value='".$_-&gt;{"mac.start"}."'".(
               #($targetself-&gt;{curstart}-&gt;[1] eq $_-&gt;{"mac.id"})
               (!$first)
               ?  " checked" : "").
               "&gt;".#$first." ".
               (
               #($targetself-&gt;{curstart}-&gt;[1] eq $_-&gt;{"mac.id"})
               !$first++
               ? "&lt;b&gt;".$_-&gt;{"mac.start"}."&lt;/b&gt;" : $_-&gt;{"mac.start"})." (".$self-&gt;HashButton({
                  sessionid         =&gt; $targetself-&gt;{sessionid},
                  job               =&gt; "updatepre",
                  table             =&gt; "mac",
                  $UNIQIDCOLUMNNAME =&gt; $_-&gt;{"mac.id"},
               }, "&lt;font size=1&gt;".$_-&gt;{"mac.id"}."&lt;/font&gt;", { link =&gt; 1 }).")";
            } sort {
               str2time($a-&gt;{"mac.start"}) &lt;=&gt;
               str2time($b-&gt;{"mac.start"})
            } @{$targetself-&gt;{maccache}-&gt;{$mac}-&gt;{macdata}})."&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;\n";
            #print "&amp;nbsp;&amp;nbsp;".$_."&lt;br&gt;\n";
         }
         print "&lt;tr&gt;&lt;td colspan=3&gt;Nutzungsbeginn nicht übernehmen&lt;/td&gt;&lt;td&gt;&lt;input type=radio name=start value='".$targetself-&gt;{startdate}."'&gt;&lt;font size=1&gt;".$targetself-&gt;{startdate}."&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;";
         print "&lt;/table&gt;";
         print "&lt;br&gt;M&amp;ouml;chten Sie dies durchführen?&lt;br&gt;\n";
         print "&lt;input type=hidden name=sessionid value='".$targetself-&gt;{sessionid}."'&gt;";
         print "&lt;input type=hidden name=address value='".$targetself-&gt;{address}."'&gt;";
         print "&lt;input type=hidden name=tickets_id value='".$targetself-&gt;{ticketid}."'&gt;";
         print "&lt;input type=hidden name=table value='".$self-&gt;{"q"}-&gt;param("table")."'&gt;";
         #print "&lt;input type=text name=vorlage_id value='".$self-&gt;{"q"}-&gt;param("vorlage_id")."'&gt;";
         #print "&lt;input type=text name=customer_id value='".$self-&gt;{"q"}-&gt;param("customer_id")."'&gt;";
         print "&lt;input type=hidden name=job value=".$self-&gt;{"q"}-&gt;param("job")."&gt;";
         print "&lt;input type=submit name=realydo value='Ja'&gt;";
         print "&lt;/form&gt;";
         $self-&gt;destructor();
         $targetself-&gt;{state} = $NOSTATE;
         return $DONE;
      }
   }
   return $RUNNING;
}

sub html2pdf {
   my $self = shift;
   my $html = shift;
   my $cmd = "/bin/bash -c '/usr/bin/html2ps | /usr/bin/ps2pdf -'";
   my $in;
   my $out;
   my $erro;
   my $h = start ["/bin/bash", "-c", "/usr/bin/html2ps | /usr/bin/ps2pdf -"], \$in, \$out, \$erro, timeout( 10 );
   $in .= $html;
   pump $h while length $in;
   finish $h;
   return $out;
}

sub authenticate {
   my $self = shift;
   my $line = shift;
   my $targetself = shift;
   my $stadium = shift || 0;
   if ($stadium == $STARTUP) {
      #print "&lt;center&gt;&lt;h2&gt;Neue Oberfl&amp;auml;che&lt;/h2&gt;Bitte verwenden Sie ab nun die &lt;a href='http://192.168.0.109/build/index.html'&gt;Neue Oberfl�che&lt;/a&gt;!&lt;br&gt;&lt;br&gt;Falls mit dieser Probleme auftreten sollten, k�nnen Sie im Folgenden die bisherige Oberfl�che verwenden.&lt;/center&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;hr&gt;\n";
   }
   return $self-&gt;SUPER::authenticate($line, $targetself, $stadium, @_);
}

sub getValueForTime {
  my $time = shift;
  my $usetime = shift;
  my $used = shift;
  my $width = shift;
  my $value = shift || $time;
  my $color = undef;
  $usetime =~ s,\,,.,g;
  $time = str2time($time);
  if (!$time || !$time || ((timegm(gmtime($time)) &lt; time()) || ($usetime &amp;&amp; ($used &gt;= int($usetime * 60))))) {
     $color .= "#FFAAAA"; # rot
  } else {
     $color .= "#AAFFAA"; # Gruen
  }
  my $tmp = "&lt;table bgcolor='".$color."' '.($width ? 'width='.$width.' ' : '').'height=100% cellspacing=0 cellpadding=2&gt;&lt;tr&gt;&lt;td bgcolor='".$color."' valign=center align=center&gt;";
  $value = "&lt;b&gt;".$value."&lt;/b&gt;" if ($used);
  $tmp .= $value."&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";
  return $tmp;
}

sub Column_Handler {
   my $self = shift;
   my $targetself = shift;
   my $table = shift;
   my $row = shift;
   my $curcolumn = shift;

   my $columnvalue = $self-&gt;getValuesForColumn($curcolumn, $table, $row);
   my $isQooxdoo = 0;
   my $i = 0;
   while(1) {
      my ($package, $filename, $line) = caller($i++);;
      if (($package =~ m,Qooxdoo,i) ? 1 : 0) {
         $isQooxdoo++;
         last;
      }
      last unless $package;
   }
   if ($table eq $TICKETS) {
      my $usetime = $row-&gt;{$table.$TSEP."usehours"} || 0;
      $usetime =~ s,\,,.,g;
      my $used = $row-&gt;{$table.$TSEP."used"};
      #die $package.":".$filename.":".$line
      #   if ($curcolumn eq $UNIQIDCOLUMNNAME);
      if (!$isQooxdoo &amp;&amp; ($curcolumn eq $UNIQIDCOLUMNNAME)) {
         my $tmp = $self-&gt;HashButton( {
            sessionid         =&gt; $targetself-&gt;{sessionid},
            job               =&gt; "pdf",
            $UNIQIDCOLUMNNAME =&gt; $columnvalue
         }, "&lt;img src='/bilder/ticket.png' align='absmiddle'&gt;", { link =&gt; 1 } ) unless $targetself-&gt;{hidebuttons};
         return $tmp."&amp;nbsp;".$columnvalue;
      } elsif (($curcolumn eq $TIMESTAMP)) {
         #$columnvalue = "&lt;b&gt;".$columnvalue."&lt;/b&gt;" if ($row-&gt;{$table.$TSEP."used"});
         $columnvalue =~ s/\s+/\&lt;br\&gt;/g
            if !$isQooxdoo;
         return getValueForTime($columnvalue, $usetime, $used, "100%");
      } elsif ($curcolumn eq "usehours") {
         return "&amp;nbsp;&lt;i&gt;Bis zum Verfall&lt;/i&gt;&amp;nbsp;" unless ($row-&gt;{$table.$TSEP."usehours"});
         if ($used) {
            return "&amp;nbsp;Noch ".int(($usetime * 60)-$used)." von ".int($usetime * 60)." Minuten&lt;br&gt;";
         } else {
            return "&amp;nbsp;".int($usetime * 60)." Minuten ab erstem Login&amp;nbsp;";
         }
      } elsif (!$isQooxdoo) {
        return "&amp;nbsp;".$columnvalue."&amp;nbsp;";
      }
   } elsif (($table eq $MAC) ||
            ($table eq "enduser")) {
      if (($curcolumn eq "address") &amp;&amp; (!$isQooxdoo)) {
         return $self-&gt;HashButton({
            sessionid         =&gt; $targetself-&gt;{sessionid},
            job               =&gt; "setfilter",
            searchaddress     =&gt; $columnvalue,
            table             =&gt; ($table eq $MAC) ? "enduser" : $MAC,
         }, $columnvalue, { link =&gt; 1 })." | ".
         $self-&gt;HashButton({
            sessionid         =&gt; $targetself-&gt;{sessionid},
            job               =&gt; "registeraddmac",
            mac               =&gt; $columnvalue,
         }, "[REGISTER]", { link =&gt; 1 });
      }
   } elsif ($table eq $BOXES) {
      if (($curcolumn eq $NAMECOLUMNNAME) &amp;&amp; (!$isQooxdoo)) {
         my $tmp = $targetself-&gt;{hidebuttons} ? "" : $self-&gt;HashButton({
            sessionid         =&gt; $targetself-&gt;{sessionid},
            job               =&gt; "boxstatus",
            $UNIQIDCOLUMNNAME =&gt; $row-&gt;{$table.$TSEP.$UNIQIDCOLUMNNAME},
         }, "INFO", { link =&gt; 1 });
         return $tmp."&amp;nbsp;".$columnvalue;
      }
   }
   return $self-&gt;SUPER::Column_Handler($targetself, $table, $row, $curcolumn);
}

sub printTableButtons {
   my $self = shift;
   my $targetself = shift;
   $self-&gt;SUPER::printTableButtons($targetself, @_);
   print "&amp;nbsp;".$self-&gt;HashButton( {
      sessionid =&gt; $targetself-&gt;{sessionid},
      job       =&gt; "register",
   }, "Tickets registrieren", { link =&gt; 1 } );
}

sub doFormularColumn {
   my $self = shift;
   my $options = shift;
   my $moreparams = [@_];
   if (@$moreparams) {
      Log("You have to migrate the use of doFormularColumn (now hash is used for parameters)", $ERROR);
      return undef;
   }
   unless ($options-&gt;{table} &amp;&amp; $options-&gt;{column} &amp;&amp; $options-&gt;{targetself}) {
      Log("doFormularColumn: Missing parameters: table:".$options-&gt;{table}.":column:".$options-&gt;{column}.":targetself:".$options-&gt;{targetself}.":more:".scalar(@$moreparams).": !", $ERROR);
      return undef;
   }
   my $viewstatus  = $self-&gt;getViewStatus({
      column     =&gt; $options-&gt;{column},
      table      =&gt; $options-&gt;{table},
      targetself =&gt; $options-&gt;{targetself},
      action     =&gt; $LISTACTION,
   });
   my $curtabledef = $self-&gt;getTableDefiniton($options-&gt;{table});
   my $columndef = mergeColumnInfos($self-&gt;getDBBackend($options-&gt;{table}), $curtabledef-&gt;{columns}-&gt;{$options-&gt;{column}});
   my $default = $self-&gt;getDefaultValue($options);
   my $return = '';
   if ($options-&gt;{table} eq $TICKETS) {
      if ($options-&gt;{column} eq $TIMESTAMP) {
         if ($options-&gt;{html}) {
            my $labely = $columndef-&gt;{label} || $options-&gt;{column};
            $return .= $self-&gt;printLabelHeader($columndef, $labely, $options-&gt;{column});
            $return .= "&lt;select name='".$options-&gt;{column}."' onChange='if (this.options[this.selectedIndex].value == ".chr(34).chr(34).") { document.getElementById(".chr(34).$options-&gt;{column}.chr(34).").style.display=".chr(34).'block'.chr(34)." } else { document.getElementById(".chr(34).$options-&gt;{column}.chr(34).").style.display=".chr(34).'none'.chr(34)." }'&gt;\n";
            $return .= "   &lt;option value='".$options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$options-&gt;{column}}."'&gt;".$options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$options-&gt;{column}}."&lt;/option&gt;\n" if $options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$options-&gt;{column}};
            foreach my $curtime (["Eine Stunde" =&gt;   3600],
                                 ["Fünf Stunden" =&gt; 18000],
                                 ["Ein Tag" =&gt;      86400],
                                 ["Eine Woche" =&gt;  604800],
                                 ["30 Tage" =&gt;   18144000],
                                 ["Ein Jahr" =&gt;  31536000]) {
               my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime(time()+($curtime-&gt;[1]));
               my $tmp = ($year+1900)."-".($mon+1)."-".($day)." ".($hour).":".($min).":".($sec);
               $return .= "  &lt;option value='".$tmp."'&gt;".$curtime-&gt;[0]."&lt;/option&gt;\n";
            }
            $return .= "   &lt;option value=''&gt;Eigene Eingabe&lt;/option&gt;\n" if ($options-&gt;{targetself}-&gt;{rights} &amp; $DATEOWNFLAG);
            $return .= "&lt;/select&gt;";
            #print "&lt;br&gt;&lt;font size=1&gt;".$options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$options-&gt;{column}}."\n" if $options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$options-&gt;{column}};
            $return .= " ".$columndef-&gt;{unit} if ($columndef-&gt;{unit});
            $return .= "&lt;br&gt;";
            if ($options-&gt;{targetself}-&gt;{rights} &amp; $DATEOWNFLAG) {
               $return .= '&lt;div&gt;&lt;span id="'.$options-&gt;{column}.'" style="display: none;"&gt;';
               $return .= $self-&gt;printDateQuestion($options-&gt;{column}, $self-&gt;getDatePredefFor($options-&gt;{column}, $default, $columndef-&gt;{endday}));
               $return .= "&lt;/span&gt;&lt;/div&gt;";
            }
            $return .= "&lt;/td&gt;&lt;/tr&gt;\n";
            return $return;
         } else {
            return undef
               if ($options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$TIMESTAMP} eq "own");
            my @now = ();
            if ($options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$TIMESTAMP} =~ m,(\d+)y,) {
               @now = localtime(time() + 60*60*24*365*$1);
                                            #sek #hour #day #year
            } elsif ($options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$TIMESTAMP} =~ m,(\d+)w,) {
               @now = localtime(time() + 60*60*24*7*$1);
                                            #sek #hour #day #week
            } elsif ($options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$TIMESTAMP} =~ m,(\d+)d,) {
               @now = localtime(time() + 60*60*24*$1);
                                            #sek #hour #day
            } elsif ($options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$TIMESTAMP} =~ m,(\d+)h,) {
               @now = localtime(time() + 60*60*$1);
                                            #sek #hour
            } elsif ($options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$TIMESTAMP} eq "own") {
               @now = localtime(time());
            }
            return scalar(($now[5]+1900)."-".($now[4]+1)."-".$now[3]." ".$now[2].":".$now[1].":".$now[0])
               if @now;
            return $self-&gt;SUPER::doFormularColumn($options, @$moreparams);
         }
      # TODO:FIXME:XXX: getViewStatus uebelst reingepached... ordentlich machen!!!! Muss ins Framework!
      } elsif ($viewstatus eq "hidden") {
         return $options-&gt;{html} ? "&lt;input type=hidden name='".$options-&gt;{column}."' value='".$options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$options-&gt;{column}}."'&gt;" : $default;
      }
   } elsif (($options-&gt;{column} eq $CUSTOMER."_".$UNIQIDCOLUMNNAME) &amp;&amp; (!($options-&gt;{targetself}-&gt;{rights} &amp; $ADMIN))) {
      return $options-&gt;{html} ? "&lt;input type=hidden name='".$options-&gt;{column}."' value='".$options-&gt;{mydefaults}-&gt;{$options-&gt;{table}.$TSEP.$options-&gt;{column}}."'&gt;" : $default;
   }
   return $self-&gt;SUPER::doFormularColumn($options, @$moreparams);
}

sub getViewStatus {
   my $self = shift;
   my $options = shift;
   my $moreparams = [@_];
   unless ($options-&gt;{table} &amp;&amp; $options-&gt;{column} &amp;&amp; $options-&gt;{targetself} &amp;&amp; (!@$moreparams)) {
      Log("getViewStatus: Missingx parameters: table:".$options-&gt;{table}.":column:".$options-&gt;{column}.":targetself:".$options-&gt;{targetself}.":morex:".scalar(@$moreparams).": !", $ERROR);
      return undef;
   }
   my $tabledef = $self-&gt;getTableDefiniton($options-&gt;{table}); # $self-&gt;{DB}-&gt;{tables}-&gt;{$options-&gt;{table}};
   my $columndef = mergeColumnInfos($self-&gt;getDBBackend($options-&gt;{table}), $tabledef-&gt;{columns}-&gt;{$options-&gt;{column}});
   if ($options-&gt;{table} eq $TICKETS) {
      if ((($options-&gt;{column} eq $VERBUND."_".$UNIQIDCOLUMNNAME)  &amp;&amp; (!($options-&gt;{targetself}-&gt;{rights} &amp; $VERBUNDFLAG))) ||
          (($options-&gt;{column} eq $BOXES."_".$UNIQIDCOLUMNNAME)    &amp;&amp; (!($options-&gt;{targetself}-&gt;{rights} &amp; $INSTALLATIONFLAG))) ||
          (($options-&gt;{column} eq "usehours")                      &amp;&amp; (!($options-&gt;{targetself}-&gt;{rights} &amp; $SURFTIMEFLAG))) ||
          (($options-&gt;{column} eq $VORLAGE."_".$UNIQIDCOLUMNNAME)  &amp;&amp; (!($options-&gt;{targetself}-&gt;{rights} &amp; $VORLAGENFLAG)))  ) {# ||
          #(($options-&gt;{column} eq $CUSTOMER."_".$UNIQIDCOLUMNNAME) &amp;&amp; (!($options-&gt;{targetself}-&gt;{rights} &amp; $MODIFY)))) {
         # TODO:XXX:FIXME: "hidden" -&gt; $HIDDEN ueberall
         return "hidden";
      }
   }
   return "hidden"
      if (($options-&gt;{column} eq $CUSTOMER."_".$UNIQIDCOLUMNNAME) &amp;&amp; (!($options-&gt;{targetself}-&gt;{rights} &amp; $MODIFY)));
   # TODO:XXX:FIXME: "hidden", "readonly", ... -&gt; $HIDDEN, $READONLY,... ueberall!!
   return $self-&gt;SUPER::getViewStatus($options);
}

sub Buttons {
   my $self = shift;
   my $targetself = shift;
   my $dstjob = shift;
   my $table = shift;
   my $row = shift;
   my $addbutton = shift || 0;
   my $ret = '';

   if ($addbutton &amp;&amp; ($table eq $TICKETS)) {
      $ret .= $self-&gt;HashButton( {
         sessionid =&gt; $targetself-&gt;{sessionid},
         job =&gt; 'addpre',
         table =&gt; $targetself-&gt;{table}||''
      }, ($self-&gt;{text}-&gt;{I_ADD} ? '&lt;img align="middle" src="'.$self-&gt;{text}-&gt;{I_ADD}.'"&gt;' : '').$self-&gt;{text}-&gt;{B_ADD}, { link =&gt; 1 })." ";
      $ret .= " " if $ret;
      $ret .= $self-&gt;HashButton( {
         sessionid =&gt; $targetself-&gt;{sessionid},
         job =&gt; 'search',
         table =&gt; $targetself-&gt;{table}||''
      }, $self-&gt;{text}-&gt;{T_SEARCH}, { link =&gt; 1 });
   } else {
      return $self-&gt;SUPER::Buttons($targetself, $dstjob, $table, $row, $addbutton, @_);
   }
}

1;
</pre></body></html>