aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/functions.php
blob: 60408a2b733f879d3ddeb32e11e5f765fc6e05af (plain)
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php

function failure($reason, $httpcode, $ajax = true, $heading = NULL){

	# send header with $httpcode
	header($_SERVER['SERVER_PROTOCOL'] . " " . $httpcode);

	# just echo the reason to the ajax response
	if($ajax){
		echo $reason;
		exit;
	}

	// TODO: Put pretty HTML here, please

	# print full error page
	if($heading != NULL)
		echo $heading;

	echo $reason;

	# exit the script here
	exit;
}

function print_login(){
if(isset($_GET["goto"]) && $_GET["goto"] != "")
	$goto = $_GET["goto"];
else
	$goto = "index";
?>
<form class="form-horizontal" method="POST" action="/?page=action&task=login&goto=<?php echo $goto; ?>">
<fieldset>

<!-- Form Name -->
<legend><h1>Junge Gemeinde Adlershof</h1><p>Login required</p></legend>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="name">Username*:</label>  
  <div class="col-md-5">
  <input id="name" name="name" placeholder="Put your username here." class="form-control input-md" required="" type="text">
  </div>
</div>

<!-- Password input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="password">Password*:</label>
  <div class="col-md-5">
    <input id="password" name="password" placeholder="Put your password here." class="form-control input-md" required="" type="password">
  </div>
</div>

<!-- Button -->
<div class="form-group">
  <label class="col-md-4 control-label" for="submit"></label>
  <div class="col-md-4">
    <button id="submit" name="submit" class="btn btn-info">Log In</button>
  </div>
</div>

</fieldset>
</form>
</div>
<?php
}

function print_index(){
?>
        <h1>Junge Gemeinde Adlershof</h1>
        </div>
        <div class="row">
	</div>
<?php
}

function print_list(){
	global $db;

	$result = $db->doQuery("SELECT * FROM " . DBPREFIX . "member;");
?>
	<h1>Adress Liste</h1>
	<br>
        </div>
        <div class="row">
	<table width='60%' class='table table-striped'>
		<thead>
			<tr>
				<th><p>#</p></th>
				<th><p>Name</p></th>
				<th><p>Adresse</p></th>
				<th><p>Telefon</p></th>
				<th><p>Handynummer</p></th>
				<th><p>E-Mail</p></th>
				<th><p>Geburtstag</p></th>
				<th><p>ändern</p></th>
			</tr>
		</thead>
		<tbody>
		<?php
		$count = 1;
		while ( $row = $result->fetch_array(MYSQLI_ASSOC) ){
			echo "<tr>
				<td>$count</td>
				<td>".htmlentities($row['name'])."</td>
				<td>".htmlentities($row['adresse'])."</td>
				<td>".htmlentities($row['telefonnummer'])."</td>
				<td>".htmlentities($row['handynummer'])."</td>
				<td>".htmlentities($row['email'])."</td>
				<td>".htmlentities($row['geburtstag'])."</td>
				<td><a href='/?page=update&id=".htmlentities($row['member_id'])."'><input type='checkbox' name='change' value='true'></a></td>
			<tr>";
			$count++;
		}
		?>
		<?php /*
		<tr><td align='center'><a href=\"/liste/".$row[0]."\">".$count."</a></td><td align='left'><a href=\"/liste/".$row[0]."\">".$row[1]."</a></td><td align='left'>
		<a href=\"/liste/".$row[0]."\">".$row[2]."</a></td><td align='left'><a href=\"/liste/".$row[0]."\">".$row[3]."</a></td><td align='left'><a href=\"/liste/".$row[0]."\">".$row[4]."</a></td><td align='left'><a href=\"/liste/".$row[0]."\">".$row[5]."</a></td><td align='left'><a href=\"/liste/".$row[0]."\">".$row[6]."</a></td><td align='center'><a href=\"/liste/".$row[0]."\"><input type='checkbox' name='change' value='true'</td></a><tr>
		*/
		?>
		</tbody>
	</table>
	<form method="POST" action="/?page=add">
		<button id="singlebutton" class="btn btn-info" type="submit">Füge jemanden hinzu</button>
	</form>
</div>
</div>
				
<?php
}

function print_update_list($id){
	global $db;

	$sql 	= $db->prepare("SELECT * FROM " . DBPREFIX . "member WHERE member_id = %d", $id);
	$result = $db->doQuery($sql);
	if(!$result){
		echo "Fail!";
		exit;
	}
	while ( $row = $result->fetch_array(MYSQLI_ASSOC) ){
?>
	        <h1>Änderung für <?php echo htmlentities($row['name']); ?></h1>
        	</div>
	        <div class="row">
			<form method='POST' action='/?page=action&task=update&id=<?php echo htmlentities($row['memberid']); ?>&goto=liste'>
				<table class='table'>
					<thead>
						<tr>
						<th>Name</th>
						<th>Adresse</th>
						<th>Telefon</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td><input type='text' name='name' value='<?php echo htmlentities($row['name']); ?>'></td>
							<td><input type='text' name='adresse' value='<?php echo htmlentities($row['adresse']); ?>'></td>
							<td><input type='text' name='telefonnummer' value='<?php echo htmlentities($row['telefonnummer']); ?>'></td>
						</tr>
					</tbody>
					<thead>
						<tr>
						<th>Handynummer</th>
						<th>E-Mail</th>
						<th>Geburtstag</th>
						</tr>
					<tbody>
						<tr>
							<td><input type='text' name='handynummer' value='<?php echo htmlentities($row['handynummer']); ?>'></td>
							<td><input type='text' name='email' value='<?php echo htmlentities($row['email']); ?>'></td>
							<td><input type='text' name='geburtstag' value='<?php echo htmlentities($row['geburtstag']); ?>'></td>
						</tr>
					</tbody>
				</table>
				<button id="singlebutton" name="singlebutton" class="btn btn-info" type="submit">Ändere!</button>
			</form>
		</div>
<?php
	}
}

function print_add_entry_to_list(){
?>
		<h1>Füge die Daten hinzu</h1>
	</div>
		<div class="row">
			<form method='POST' action='/?page=action&task=add&goto=liste'>
				<table class='table'>
					<thead>
						<tr>
						<th>Name</th>
						<th>Adresse</th>
						<th>Telefon</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td><input type='text' name='name' placeholder='Name'></td>
							<td><input type='text' name='adresse' placeholder='Adresse'></td>
							<td><input type='text' name='telefonnummer' placeholder='Telefonnummer'></td>
						</tr>
					</tbody>
					<thead>
						<tr>
						<th>Handynummer</th>
						<th>E-Mail</th>
						<th>Geburtstag</th>
						</tr>
					<tbody>
						<tr>
							<td><input type='text' name='handynummer' placeholder='Handynummer'></td>
							<td><input type='text' name='email' placeholder='E-Mail'></td>
							<td><input type='text' name='geburtstag' placeholder='Geburtstag'></td>
						</tr>
					</tbody>
				</table>
				<button id="singlebutton" name="singlebutton" class="btn btn-info" type="submit">Hinzufügen!</button>
			</form>
		</div>
<?php
}

function _add_entry(){
	global $db;

	$sql = $db->prepare("INSERT INTO " . DPREFIX . "member (id, name, adresse, telefonnummer, handynummer, email, geburtstag) VALUES (NULL. %s, %s, %s, %s, %s, %s);", $_POST['name'], $_POST['adresse'], $_POST['telefonnummer'], $_POST['handynummer'], $_POST['email'], $_POST['geburtstag']);
	if( ! $db->doQuery($sql) )
		return false;
	else
		return true;
}

function print_404(){
	header($_SERVER['HTTP_PROTOCOL'] . ' 404 Not Found');
?>
<?php
}