Subversion-Projekte lars-tiefland.em_wm

Revision

Revision 47 | Revision 54 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
16 lars 1
<?
2
	define("IN_ADMIN", true);
3
	require("include/common.php");
47 lars 4
	$g=Spiele::listSpiele(0,0);
5
	$g_anz=$g->numRows();
6
	$g_max=2*$config->groups*$config->teams_per_group;
7
	if ($g_anz>=$g_max && $mode=="new")
8
	{
9
		$smarty->assign("meld","Ein Fehler ist aufgetreten!");
10
		$smarty->assign("db_meld","In dieser $config->type sind nur $g_max Spiele zulässig!");
11
		$smarty->assign("error",true);
12
		$smarty->display("meld.tpl");
13
		exit;
14
	}
16 lars 15
	$mode=isset($_POST["mode"])?$_POST["mode"]:"";
16
	$id=intval(isset($_POST["id"])?$_POST["id"]:0);
44 lars 17
	$smarty->assign("mode", $mode);
18
	$smarty->assign("id", $id);
45 lars 19
	$a=User_login(true);
20
	if ($a->getAuth())
32 lars 21
	{
44 lars 22
		$g_m1=intval(isset($_POST["g_m1"])?$_POST["g_m1"]:0);
23
		$g_m2=intval(isset($_POST["g_m2"])?$_POST["g_m2"]:0);
24
		$g_g1=intval(isset($_POST["g_g1"])?$_POST["g_g1"]:0);
25
		$g_g2=intval(isset($_POST["g_g2"])?$_POST["g_g2"]:0);
26
		$g_location=intval(isset($_POST["g_location"])?$_POST["g_location"]:0);
27
		$g_type=intval(isset($_POST["g_typ"])?$_POST["g_typ"]:-1);
28
		$g_name=addslashes(isset($_POST["g_name"])?$_POST["g_name"]:"");
29
		$month=intval(isset($_POST["Month"])?$_POST["Month"]:-1);
30
		$day=intval(isset($_POST["Day"])?$_POST["Day"]:-1);
31
		$hour=intval(isset($_POST["Hour"])?$_POST["Hour"]:-1);
32
		$game=new Spiele($id);
33
		$t=new Typ($g_type);
34
		$sql_t="SELECT count(*) AS anzahl FROM games WHERE g_type=$g_type";
35
		$res_t=$db->query($sql_t);
52 lars 36
		$row_t=$res_t->fetchRow();
44 lars 37
		$anz=$row_t["anzahl"];
38
		if ($hour >=0 AND $day > 0 AND $month > 0)
16 lars 39
		{
44 lars 40
			$g_date=mktime($hour, 0, 0, $month, $day, 2006);
41
		}
42
		if ($mode=="save" || $mode=="update")
43
		{
44
			$game->update($g_name, $g_m1, $g_m2, $g_g1, $g_g2, $g_location, $g_date, $g_type);
45
		}
46
 
47
		function fill_form()
48
		{
49
			global $db, $smarty, $id, $new_mode, $g_date, $title, $game;
50
			$t_namen[]="Bitte wählen!";
16 lars 51
			$t_ids[]=-1;
44 lars 52
			$typ_namen[]="Bitte wählen!";
53
			$typ_ids[]=-1;
54
			$l_namen[]="Bitte wählen!";
55
			$l_ids[]=-1;
56
			$g_l=Gruppe::listeGruppe(0,0);
52 lars 57
			while($row_g=$g_l->fetchRow())
16 lars 58
			{
44 lars 59
				$g_id=$row_g["g_id"];
60
				$g_name=$row_g["g_name"];
61
				$t_namen[]="---------- Gruppe $g_name ----------";
62
				$t_ids[]=-1;
63
				$sql_t="SELECT * FROM teams WHERE t_group=$g_id";
64
				$t_l=$db->query($sql_t);
52 lars 65
				while ($row_t=$t_l->fetchRow())
44 lars 66
				{
67
					$t_name=$row_t["t_name"];
68
					$t_id=$row_t["t_id"];
69
					$t_namen[]=$t_name;
70
					$t_ids[]=$t_id;
71
				}
19 lars 72
			}
44 lars 73
			$l_l=Ort::listeOrt(0,0);
52 lars 74
			while ($row_l=$l_l->fetchRow())
44 lars 75
			{
76
				$l_name=$row_l["l_name"];
77
				$l_id=$row_l["l_id"];
78
				$l_namen[]=$l_name;
79
				$l_ids[]=$l_id;
80
			}
81
			$typ_l=Typ::listeTyp(0,0);
52 lars 82
			while ($row_typ=$typ_l->fetchRow())
44 lars 83
			{
84
				$typ_name=$row_typ["t_name"];
85
				$typ_id=$row_typ["t_id"];
86
				$typ_namen[]=$typ_name;
87
				$typ_ids[]=$typ_id;
88
			}
89
			$smarty->assign("id", $id);
90
			$smarty->assign("g_date", (!isset($g_date))?$game->g_date:$g_date);
91
			$smarty->assign("g_name", ($game->g_name));
92
			$smarty->assign("akt_typ_id", $game->g_type);
93
			$smarty->assign("akt_m1_id", $game->g_m1);
94
			$smarty->assign("akt_m2_id", $game->g_m2);
95
			$smarty->assign("akt_l_id", $game->g_location);
96
			$smarty->assign("g_g1", $game->g_g1);
97
			$smarty->assign("g_g2", $game->g_g2);
98
			$smarty->assign("t_namen", $t_namen);
99
			$smarty->assign("t_ids", $t_ids);
100
			$smarty->assign("typ_namen", $typ_namen);
101
			$smarty->assign("typ_ids", $typ_ids);
102
			$smarty->assign("l_ids", $l_ids);
103
			$smarty->assign("l_namen", $l_namen);
104
			$smarty->assign("mode", $new_mode);
105
			$smarty->assign("title", $title);
106
			$smarty->assign("extra", ($new_mode=="save")?"disabled=\"disabled\"":"");
107
			$smarty->display("edit_games.tpl");
16 lars 108
		}
44 lars 109
 
110
		switch ($mode)
16 lars 111
		{
44 lars 112
			case "edit":
113
				$title="Spiel $id ändern";
114
				$new_mode="update";
115
				break;
116
			case "new":
117
				$title="neues Spiel eingeben";
118
				$new_mode="save";
119
				break;
120
			case "delete":
121
			case "ask":
122
				$title="Spiel $id löschen";
123
				$new_mode="delete";
124
				break;
125
			case "save":
126
				$title="neues Spiel speichern";
127
				$new_mode="save";
128
				break;
129
			case "update":
130
				$title="Spiel $id speichern";
131
				$new_mode="update";
132
				break;
19 lars 133
		}
44 lars 134
		if ($mode=="edit" OR $mode=="new")
18 lars 135
		{
44 lars 136
			fill_form();
18 lars 137
		}
44 lars 138
		else
18 lars 139
		{
44 lars 140
			switch ($mode)
141
			{
142
				case "save":
143
				case "delete":
144
				case "update":
145
					if (!checkdate($month, $day, $config->year))
30 lars 146
					{
35 lars 147
						$meld="Ein Fehler ist aufgetreten!";
44 lars 148
						$db_meld="$day.$month.$config->year ist kein gültiges Datum!";
35 lars 149
						$error=true;
150
						$smarty->assign("db_meld", $db_meld);
151
						$smarty->assign("error", $error);
152
						$smarty->assign("meld", $meld);
153
						fill_form();
30 lars 154
					}
155
					else
156
					{
44 lars 157
						if (($mode=="save" && $anz >=$t->t_max) || ($mode=="update" && $anz>$t->t_max))
31 lars 158
						{
44 lars 159
								$meld="Ein Fehler ist aufgetreten!";
160
								$db_meld="Es kann nur $t->t_max Spiele vom Typ \"$t->t_name\" geben! Bitte den Typ oder ein vorhandenes Spiel ändern!";
161
							$error=true;
162
							$smarty->assign("db_meld", $db_meld);
163
							$smarty->assign("error", $error);
164
							$smarty->assign("meld", $meld);
165
							fill_form();
31 lars 166
						}
167
						else
168
						{
44 lars 169
							$res=$game->save($mode);
170
							if (true == DB::isError($res))
35 lars 171
							{
44 lars 172
								$smarty->assign("meld", "Ein Fehler ist aufgetreten!");
173
								$smarty->assign("db_meld", $res->getUserInfo());
174
								$smarty->assign("error", true);
35 lars 175
							}
176
							else
177
							{
44 lars 178
								if ($mode=="save")
179
								{
180
									$akt="hinzugefügt";
181
								}
182
								elseif ($mode=="update")
183
								{
184
									$akt="geändert";
185
								}
186
								else
187
								{
188
									$akt="gelöscht";
189
								}
190
								$smarty->assign("title", $title);
191
								$smarty->assign("meld", "Datensatz erfolgreich $akt!");
192
								$smarty->assign("db_meld", "");
193
								$smarty->assign("error", false);
35 lars 194
							}
44 lars 195
							$smarty->display("meld.tpl");
31 lars 196
						}
30 lars 197
					}
44 lars 198
					break;
199
				case "ask":
200
					$smarty->assign("title", $title);
201
					$smarty->assign("art", "Spiel");
202
					$smarty->assign("id", $id);
203
					$smarty->assign("name",$game->g_name);
204
					$smarty->display("del.tpl");
205
					break;
206
				default:
207
					$smarty->assign("title", $title);
208
					$smarty->assign("meld","Ein Fehler ist aufgetreten!");
209
					$smarty->assign("db_meld", "Ungültiger Modsu!");
210
					$smarty->assign("error", true);
211
					$smarty->display("meld.tpl");
212
			}
18 lars 213
		}
214
	}
16 lars 215
?>