#!/usr/bin/perl -w


#--------------------------------------------------------------------------------
# Module
#--------------------------------------------------------------------------------
BEGIN { push(@INC, '..'); push(@INC, '../../pm'); }
use strict;
use lh;
require ig;


#--------------------------------------------------------------------------------
# Konstanten / Variablen
#--------------------------------------------------------------------------------
use constant PFAD_HTML_AKTUELLES => 'aktuelles.html';


#--------------------------------------------------------------------------------
# main
#--------------------------------------------------------------------------------
@pm = (2, 0, 0, 0, 1, 0);
&start_script_ig;

get_tmpl(PFAD_HTML_AKTUELLES);
&aktuelles_anzeigen;

&end_script_ig;


#--------------------------------------------------------------------------------
# aktuelles_anzeigen
#--------------------------------------------------------------------------------
sub aktuelles_anzeigen
{
    my @aw_id = (0,1,2,4,3);
    my @aw_name = ('Alles','Kämpfe','Städte','Meilensteine','Eigenes');
    $html->param('aw_ignews_art' => html_register(\@aw_id, \@aw_name, $ignews_art, 'ig/aktuelles.cgi?action=change&ignews_art=', 5));
    my $lo_where_aw = '';
    if ($ignews_art == 3)
        { $lo_where_aw = "and (igid1 = $igid or igid2 = $igid)"; }
    elsif ($ignews_art>0)
        { $lo_where_aw = "and (art1 = $ignews_art or art2 = $ignews_art or art3 = $ignews_art)"; }

    my $sth_aktuelles = $dbh->prepare("
        select lfdnr, tick, sektor, feldid, txtnr, (igid1 = ? or igid2 = ?), p1, p2, p3, p4, p5, p6, p7, p8, p9, p10
        from   lh_aktuelles
        where  1=1
        $lo_where_aw
        order by 1 desc
        limit 0, 50");

    my @loop_data;
    $sth_aktuelles->execute($igid,$igid);
    while (my ($lfdnr, $tick, $sektor, $feldid, $txtnr, $meins, @para) = $sth_aktuelles->fetchrow_array)
        {
        my %record;
        $record{'tick'}   = 1+int($tick/20);
        $record{'sektor'} = "<a href='/cgi-bin/ig/karte.cgi?feldid=$feldid'>$sektor</a>";
        $record{'text'}   = get_text('AKTUELLES', $txtnr, 0, @para);
        if ($meins)
            {
            $record{'class_tick'}   = 'b';
            $record{'class_sektor'} = 'b';
            $record{'class_text'}   = 'b';
            }
        push(@loop_data, \%record);
        }

    $html->param('loop' => \@loop_data);
}
