Blob: harjoittelupaikat.php

Blob id: b865e7f9562e5dbb7ff3c7976e83956604cd36ae

Size: 3.3 KB

 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
<?php
    include "../src/connect.php";
	include "../src/kirjautunut.php";

    $sql = "SELECT * FROM harjoittelupaikat";
    $result = $conn->query($sql);

    $harjoittelupaikat = [];
    if ($result->num_rows>0) {
        while($row = $result->fetch_assoc()) {
            $harjoittelupaikat[] = $row;
        }
    }

    $conn->close();
?>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Harjoittelupaikat</title>
    <link rel="stylesheet" type="text/css" href="../css/style.css">
</head>
<body>
    <?php include "../src/header.php"; ?>
    <h1>
        Harjoittelupaikat
    </h1>
	<?php if ($op): ?>
    	<a href="../public/uusharjoittelupaikka.php"><button>Lisää harjoittelupaikka</button></a>
	<?php endif; ?>
    <main>
		<?php if (!empty($harjoittelupaikat)): ?>
			<div class="table-container">
				<table>
					<thead>
						<tr>
							<th>Nimi</th>
							<th>Ohjaaja</th>
							<th>Yhteystiedot</th>
							<?php // Ei muokkaus riviä, jos ei ole oikeuksia muokata
							if ($logged_in)
							{
								echo "<th>Muokkaus</th>";
							}
							?>
						</tr>
					</thead>
					<tbody>
						<?php
							foreach ($harjoittelupaikat as $harjoittelupaikka) {
								if (isset($_GET['id']) and $harjoittelupaikka['id'] === $_GET['id']) { // Muokataan
									// Kopioitu index.php:stä, siellä on lisää kommentteja
									echo "<form action='../src/muokkaa.php' method='POST'>";
									echo "<input type='hidden' id='taulukko' name='taulukko' value=harjoittelupaikat>";
									echo "<input type='hidden' id='id' name='id' value={$harjoittelupaikka['id']}>";
									echo "<td> <input type='text' name='nimi' id='nimi' value='" . $harjoittelupaikka["nimi"] . "'> </td>";
									echo "<td> <input type='text' name='ohjaaja' id='ohjaaja' value='" . $harjoittelupaikka["ohjaaja"] . "'> </td>";
									echo "<td> <input type='text' name='yhteystiedot' id='yhteystiedot' value='" . $harjoittelupaikka["yhteystiedot"] . "'> </td>";
									echo "<td> <button type='submit'>Tallenna muutokset</button></td>"; 
									echo "</form>";
								}
								else { // Ei muokata
									echo "<tr>";
									echo "<td>" . $harjoittelupaikka["nimi"] . "</td>";
									echo "<td>" . $harjoittelupaikka["ohjaaja"] . "</td>";
									echo "<td>" . $harjoittelupaikka["yhteystiedot"] . "</td>";
									if ($op) { // Jos opettaja tai muokkaa omia tietoja
											echo "<td class='muokkaus-column'>" . // Poista nappi
												"<form action='../src/poista.php' method='POST'>
												<input type='hidden' id='nimi' name='nimi' value={$harjoittelupaikka['nimi']}>
												<input type='hidden' id='taulukko' name='taulukko' value=harjoittelupaikat>
												<button type='submit'>Poista</button>
												</form>";
											echo "" . // Muokkaa nappi
												"<form action='../public/harjoittelupaikat.php?id={$harjoittelupaikka['id']}' method='GET'>
												<input type='hidden' id='id' name='id' value={$harjoittelupaikka['id']}>
												<button type='submit'>Muokkaa</button>
												</form>"
													. "</td>";
										}
									echo "</tr>";
								}
							}
						?>
					</tbody>
				</table>
			</div>
    	<?php else: ?>
			<p>Harjoittelupaikkoja ei löytynyt</p>
		<?php endif; ?>
    </main>
	<?php include "../src/footer.php"; ?>
</body>
</html>