-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubject_edit.php
More file actions
100 lines (91 loc) · 2.7 KB
/
subject_edit.php
File metadata and controls
100 lines (91 loc) · 2.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
<html>
<head>
<title>Subject Edit</title>
<link rel="stylesheet" href="style/form-style.css">
</head>
<body>
<div class="form_holder">
<div class="form">
<?php
/**
* Created by Zhufyak V.V.
* User: zhufy
* E-mai: zhufyakvv@gmail.com
* Git: https://github.com/zhufyakvv
* Date: 30.04.2017
* Time: 16:19
*/
include_once "Entities/University.php";
include_once "private/DBPropertyManager.php";
include_once "private/DBPost.php";
$data_base = new DBPropertyManager();
$data_base->link();
$data_base->select_db("University");
$university = new University($data_base);
$subjects = $university->getSubjects();
$free = 1;
while (isset($subjects[$free])){
$free += 1;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$post = $_POST;
if ($free == $_POST["id"]){
$subject = PostInsertDB($data_base, $post, 'Subject');
}else{
$subject = $subjects[$_POST["id"]];
$subject = PostUpdateDB($data_base, $post, $subject);
}
?>
<form method="get">
<?php if ($free == $subject->getId()){ ?>
<label for="submit">Subject added successfully.</label>
<?php }else{ ?>
<label for="submit">Changed successfully.</label>
<?php } ?>
<input name="submit" type="submit" value="Continue">
</form>
<?php
}else{
if(isset($_GET["id"]) && $_GET["id"]!=$free){
$id = $_GET["id"];
$subject = $subjects[$id];
}else{
$id = $free;
$subject = new Subject((object)[
"id"=>$free,
"name"=>"Name"]);
}
?>
<form method="post">
<br>
<label for="id">ID:</label>
<select name="id" onchange="window.location.href = 'subject_edit.php?id='+this.value;">
<?php
$was = false;
foreach ($subjects as $current_subject){
echo "<option value=\"".$current_subject->getId()."\"";
if ($current_subject->getId() == $id){
$was = true;
echo " selected ";
}
echo ">".$current_subject->getId()."(".$current_subject->getName().")";
echo "</option>";
}
echo "<option value=\"".$free."\"";
if (!$was){
echo " selected ";
}
echo "> NEW </option>";
?>
</select>
<br>
<label for="name">Name:</label>
<input name="name" type="text" placeholder="<?php echo $subject->getName(); ?>">
<br>
<input type="submit">
</form>
<?php } ?>
</div>
</div>
</body>
</html>