Blob: uusopiskelija.php

Blob id: 3a79738cc6b22ed114484ac315eaa1d28cdb641b

Size: 3.7 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
 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
<?php
	include "../src/connect.php";
	include "../src/kirjautunut.php";
	if (!$op) { // Jos ei opettaja, potki pois
		// Redirect
		$newURL = "../public/index.php";
		header('Location: '.$newURL);
		die();
	}
	// Otetaan tietokannasta harjoittelupaikkojen tiedot jotta voi autofill tiedot sieltä
	// Annetaan tiedot javascriptille :fear:
	
	// SQL komento: saadaan oppilaat
	$sql = "SELECT * FROM harjoittelupaikat";
	$result = $conn->query($sql); // Aja komento
	// Jos tuloksia
	$paikat = [];
	if ($result->num_rows>0){
		while($row = $result->fetch_assoc()){
			$paikat[] = $row;
		}
	}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Lisää opiskelija</title>
	<link rel="stylesheet" type="text/css" href="../css/style.css">
	<script>
		/**
		 * Class hpaikka
		 * @author Wisdurm
		 */
		class hpaikka
		{
			constructor(ohjaaja, yhteystiedot) {
				this.ohjaaja = ohjaaja;
				this.yhteystiedot = yhteystiedot;
			}
		}
		// Tee dictionary jossa paikkojen nimet vastaa niiden tietoja
		var paikka_map = new Map();
		<?php
			foreach ($paikat as $paikka) {
				echo "paikka_map.set('{$paikka['nimi']}', new hpaikka('{$paikka['ohjaaja']}', '{$paikka['yhteystiedot']}'));";
			}
		?>
		console.log(paikka_map);

		function autofill(){
			// Paikka arvo
			let paikka = document.getElementById("paikka").value;
			if (paikka_map.has(paikka)) { // Tietokanta paikka löydetty
				document.getElementById("ohjaaja").value = paikka_map.get(paikka).ohjaaja;
				document.getElementById("yhteystiedot").value = paikka_map.get(paikka).yhteystiedot;
			} 
		}
	</script>
</head>
<body>
	<?php include "../src/header.php"; ?>
	<main>
	<section>
	  <h1>
		  Lisää opiskelija
	  </h1>
	<form action="../src/lisaa.php" method="POST">
		<fieldset>
			<legend>
				Oppilaan tiedot
			</legend>
			<label for="nimi">Nimi:</label>
			<input required type="text" id="nimi" name="nimi" placeholder="Matti Meikäläinen" required>
			<label for="muuta">Muuta:</label>
			<input type="text" id="muuta" name="muuta" placeholder="Lähellä bussiasemaa">
		</fieldset>
		<fieldset>
			<legend>Yrityksen tiedot</legend>
			<label for="paikka">Paikka:</label>
			<input type="text" id="paikka" name="paikka" placeholder="Kpedu" list="hpaikat" oninput="autofill()">
			<datalist id="hpaikat">
				<?php
	 				foreach ($paikat as $paikka) {
						echo "<option value='{$paikka['nimi']}'></option>";
					}
				?>
			</datalist>
			<br>
			<label for="ohjaaja">Ohjaaja:</label>
			<input type="text" id="ohjaaja" name="ohjaaja" placeholder="Jaakko Pekka">
			<br>
			<label for="yhteystiedot">Yhteystiedot:</label>
			<input type="text" id="yhteystiedot" name="yhteystiedot" placeholder="0401234 tai jaakko@email.com">
			<br>
			<label for="aloitus">Aloitus:</label>
			<input type="date" id="aloitus" name="aloitus" required>
			<br>
			<label for="lopetus">Lopetus:</label>
			<input type="date" id="lopetus" name="lopetus" required>
			<br>
		</fieldset>
		<fieldset>
			<legend>Muuta</legend>
			<label for="status">Status:</label>
			<select name="status">
				<option value="Ei paikkaa" selected>Ei paikkaa</option>
				<option value="Selvityksessä">Selvityksessä</option>
				<option value="Paikka varmistunut">Paikka varmistunut</option>
			</select>
			<br>
			<label for="ruokaraha">Ruokaraha:</label>
			<select name="ruokaraha">
				<option value="Kyllä">Kyllä</option>
				<option value="Ei" selected>Ei</option>
			</select>
		</fieldset>
		<button type="submit" name="submit">
			Lisää
		</button>
		</form>
	</section>
</main>
<?php include "../src/footer.php"; ?>
</body>
</html>