Source of: tutorial/login-clanwar/clanwar-v3.php (Download Source)
Last Modified: Fri, 16 Feb 2007 13:38:18 UTC

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
    if(isset($_GET['ClanwarID']))
    {
        // clanwar-details
    }
    else
    {
        $sql = "SELECT
                    ID,
                    Name,
                FROM
                    clanwar_spiel
                ORDER BY
                    Name ASC;";
        $spielqry = new Query($sql);
        if($spielqry->error())
        {
            die("<pre>".$spielqry->getError()."</pre>\n");
        }
        while($spiel = $spielqry->fetch())
        {
            // ...
            $tabelle = new HTML('table');
            $tabelle->addAttribut('class', 'cw_uebersicht');

            $reihe = new HTML('tr');
            $zelle = new HTML('th');
            $zelle->addAttribut('colspan', '5');
            $zelle->addInhalt($spiel['Name']);
            $reihe->addInhalt($zelle);
            $tabelle->addInhalt($reihe);

            $reihe      = new HTML('tr');

            $datum      = new HTML('td');
            $gegner     = new HTML('td');
            $ergebnis   = new HTML('td');
            $ligapunkte = new HTML('td');
            $details    = new HTML('td');

            $datum->addInhalt('Datum');
            $gegner->addInhalt('Gegner');
            $ergebnis->addInhalt('Ergebnis');
            $ligapunkte->addInhalt('Ligapunkte');
            $details->addInhalt('Details');

            $reihe->addInhalt($datum);
            $reihe->addInhalt($gegner);
            $reihe->addInhalt($ergebnis);
            $reihe->addInhalt($ligapunkte);
            $reihe->addInhalt($details);
            $tabelle->addInhalt($reihe);

            $sql = "SELECT
                        ID,
                        DATE_FORMAT(Datum, '".DATE_STYLE."') as Changedatum,
                        Gegner,
                        GegnerUrl,
                        Liga,
                        LigapunkteWir
                    FROM
                        clanwar
                    WHERE
                        Spiel = '".$spiel['ID']."'
                    ORDER BY
                        Datum DESC;";
            $cws = new Query($sql);
            if($cws->error())
            {
                die("<pre>".$cws->getError()."</pre>\n");
            }
            $punkte = array();
            $punkte['win'] = 0;
            $punkte['draw'] = 0;
            $punkte['lose'] = 0;
            if($cws->numRows())
            {
                while($cw = $cws->fetch())
                {
                    $sql = "SELECT
                                SUM(PunkteWir) as Wir,
                                SUM(PunkteSie) as Sie,
                            FROM
                                clanwar_runden_seiten,
                                clanwar_runden
                            WHERE
                                RundenID = clanwar_runden`.`ID AND
                                Clanwar_ID = '".$cw['ID']."';";
                    $punkteqry = new Query($sql);
                    if($punkteqry->error())
                    {
                        die("<pre>".$punkteqry->getError()."</pre>\n");
                    }
                    $cw_punkte = $punkteqry->fetch();

                    $reihe = new HTML('tr');
                    $datum = new HTML('td');
                    $gegner = new HTML('td');
                    $ergebnis = new HTML('td');
                    $ligapunkte = new HTML('td');
                    $details = new HTML('td');

                    $datum->addInhalt($cw['Changedatum']);
                    $url = new HTML('a');
                    $url->addAttribut('href', $cw['GegnerUrl']);
                    $url->addInhalt($cw['Gegner']);
                    $gegner->addInhalt($url);

                    if($cw_punkte['Wir'] < $cw_punkte['Sie'])
                    {
                        $punkte['lose']++;
                        $farbe = "Rot";
                    }
                    elseif($cw_punkte['Wir'] > $cw_punkte['Sie'])
                    {
                        $punkte['win']++;
                        $farbe = "Grün";
                    }
                    else
                    {
                        $punkte['draw']++;
                        $farbe = "Gelb";
                    }

                    $span = new HTML('span');
                    $span->addAttribut('style', 'color: '.
                                                array_search($farbe, $farben).
                                                ';');
                    // Index zu der Farbe suchen
                    $span->addInhalt($cw_punkte['Wir'].":".$cw_punkte['Sie']);
                    $ergebnis->addInhalt($span);
                    $ligapunkte->addInhalt($cw['LigapunkteWir']);
                    $link = new HTML('a');
                    $link->addAttribut('href', 'index.php'.
                                               '?section=clanwars'.
                                               '&ClanwarID='.$cw['ID']);
                    $link->addInhalt('Details');
                    $details->addInhalt($link);

                    $reihe->addInhalt($datum);
                    $reihe->addInhalt($gegner);
                    $reihe->addInhalt($ergebnis);
                    $reihe->addInhalt($ligapunkte);
                    $reihe->addInhalt($details);
                    $tabelle->addInhalt($reihe);

                }
            }
            else
            {
                $reihe = new HTML('tr');
                $zelle = new HTML('td');
                $zelle->addAttribut('colspan', '5');
                $zelle->addInhalt('Kein Clanwar in diesem Spiel');
                $reihe->addInhalt($zelle);
                $tabelle->addInhalt($reihe);
            }

            $reihe = new HTML('tr');
            $zelle = new HTML('td');
            $zelle->addAttribut('colspan', '5');
            $zelle->addInhalt('Wins: '.$punkte['win'].
                              ' Draws: '.$punkte['draw'].
                              ' Loses: '.$punkte['lose'].
                              ' Insg.: '.array_sum($punkte));
            $reihe->addInhalt($zelle);
            $tabelle->addInhalt($reihe);

            $tabelle->ausgeben();
        }
        $spielqry->free();
        unset($ligaqry);
    }
?>