Source of: tutorial/login-clanwar/map-del-v2.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
<?php
    case 'del':
        if(isset($_POST['submit']) AND "Map löschen" == $_POST['submit'])
        {
            if(!$_POST['map'])
            {
                $error = new HTML('p');
                $error->addInhalt('Bitte geben sie eine gültige Map an.');
                $error->ausgeben();
            }
            else
            {
                // zuerst das Bild löschen, dann aus der DB löschen
                $sql = "SELECT
                            `Bild`
                        FROM
                            `clanwar_maps`
                        WHERE
                            `ID` = '".$_POST['map']."';";
                $map = new Query($sql);
                if($map->error())
                {
                    die("<pre>".$map->getError()."</pre>\n");
                }
                $row = $map->fetch();
                $pfad = $row['Bild'];
                $map->free();
                unset($map);
                if(!unlink($pfad))
                {
                    $error = new HTML('p');
                    $error->addInhalt('Konnte Bild nicht löschen, siehe PHP Fehlermeldung.');
                    $error->ausgeben();
                }
                else
                {
                    $sql = "DELETE FROM
                                `clanwar_maps`
                            WHERE
                                `ID` = '".$_POST['map']."';";
                    $delete = new Query($sql);
                    if($delete->error())
                    {
                        die("<pre>".$delete->getError()."</pre>\n");
                    }
                    $ok = new HTML('p');
                    $ok->addInhalt('Map wurde gelöscht');
                    $ok->ausgeben();
                }
            }
        }
        else
        {
            $formular = new HTML('form');
            $formular->addAttribut('method', 'post');
            $formular->addAttribut('action', 'index.php?section=admin&site=map&action=del');
            $formular->addAttribut('class', 'formular');

            $überschrift = new HTML('p');
            $überschrift->addInhalt('Map löschen');
            $formular->addInhalt($überschrift);
            // Überschrift fertig

            $liste = new HTML('ol');

            $eintrag = new HTML('li');

            $label = new HTML('label');
            $label->addAttribut('for','map');
            $label->addInhalt('Map');

            $select = new HTML('select');
            $select->addAttribut('id', 'map');
            $select->addAttribut('name', 'map');

            $default = new HTML('option');
            $default->addAttribut('value', '0');
            $default->addAttribut('selected');
            $default->addInhalt('Bitte wählen');
            $select->addInhalt($default);

            $sql = "SELECT
                        ID,
                        Name
                    FROM
                        clanwar_map
                    ORDER BY
                        Name ASC;";
            $maps = new Query($sql);
            if($maps->error())
            {
                die("<pre>".$maps->getError()."</pre>\n");
            }
            while($row = $maps->fetch())
            {
                $option = new HTML('option');
                $option->addAttribut('value', $row['ID']);
                $option->addInhalt($row['Name']);
                $select->addInhalt($option);
            }

            $eintrag->addInhalt($label);
            $eintrag->addInhalt($select);
            $liste->addInhalt($eintrag);

            $eintrag = new HTML('li');

            $submit = new HTMLempty('input');
            $submit->addAttribut('type', 'submit');
            $submit->addAttribut('name', 'submit');
            $submit->addAttribut('value', 'Map löschen');

            $reset = new HTMLempty('input');
            $reset->addAttribut('type', 'reset');
            $reset->addAttribut('name', 'submit');
            $reset->addAttribut('value', 'Daten zurücksetzen');

            $sessid = new HTMLempty('input');
            $sessid->addAttribut('type', 'hidden');
            $sessid->addAttribut('name', session_name());
            $sessid->addAttribut('value', session_id());

            $eintrag->addInhalt($submit);
            $eintrag->addInhalt($reset);
            $eintrag->addInhalt($sessid);
            $liste->addInhalt($eintrag);

            $formular->addInhalt($liste);
            $formular->ausgeben();
        }
        break;
?>