-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdepartment_edit.php
More file actions
99 lines (90 loc) · 2.72 KB
/
department_edit.php
File metadata and controls
99 lines (90 loc) · 2.72 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
<html>
<head>
<title>Department 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);
$groups = $university->getDepartments();
$free = 1;
while (isset($groups[$free])){
$free += 1;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$post = $_POST;
if ($free == $_POST["id"]){
$department = PostInsertDB($data_base, $post, 'Department');
}else{
$department = $groups[$_POST["id"]];
$department = PostUpdateDB($data_base, $post, $department);
}
?>
<form method="get">
<?php if ($free == $department->getId()){ ?>
<label for="submit">Department added successfully.</label>
<?php }else{ ?>
<label for="submit">Changed successfully.</label>
<?php } ?>
<input name="submit" type="submit" value="Continue">
<?php
}else{
if(isset($_GET["id"]) && $_GET["id"]!=$free){
$id = $_GET["id"];
$department = $groups[$id];
}else{
$id = $free;
$department = new Department((object)[
"id"=>$free,
"name"=>"Name"]);
}
?>
<form method="post">
<br>
<label for="id">ID:</label>
<select name="id" onchange="window.location.href = 'department_edit.php?id='+this.value;">
<?php
$was = false;
foreach ($groups as $current_department){
echo "<option value=\"".$current_department->getId()."\"";
if ($current_department->getId() == $id){
$was = true;
echo " selected ";
}
echo ">".$current_department->getId()."(".$current_department->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 $department->getName(); ?>">
<br>
<input type="submit">
<?php } ?>
</form>
</div>
</div>
</body>
</html>