-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup_edit.php
More file actions
122 lines (112 loc) · 3.61 KB
/
group_edit.php
File metadata and controls
122 lines (112 loc) · 3.61 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
<html>
<head>
<title>Group 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->getGroups();
$free = 1;
while (isset($groups[$free])){
$free += 1;
}
$post = $_POST;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($free == $_POST["id"]){
$group = PostInsertDB($data_base, $post, 'Group');
}else{
$group = $groups[$_POST["id"]];
$group = PostUpdateDB($data_base, $post, $group);
}
?>
<form method="get">
<?php if ($free == $group->getId()){ ?>
<label for="submit">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"];
$group = $groups[$id];
}else{
$id = $free;
$group = new Group((object)[
"id"=>$free,
"number"=>"Number",
"specialty"=>"Specialty",
"department"=>"1",
"amount"=>"1"]);
}
?>
<form method="post">
<br>
<label for="id">ID:</label>
<select name="id" onchange="window.location.href = 'group_edit.php?id='+this.value;">
<?php
$was = false;
foreach ($groups as $current_group){
echo "<option value=\"".$current_group->getId()."\"";
if ($current_group->getId() == $id){
$was = true;
echo " selected ";
}
echo ">".$current_group->getId()."(".$current_group->getNumber().")";
echo "</option>";
}
echo "<option value=\"".$free."\"";
if (!$was){
echo " selected ";
}
echo "> NEW </option>";
?>
</select>
<br>
<label for="number">Last Name:</label>
<input name="number" type="text" placeholder="<?php echo $group->getNumber(); ?>">
<br>
<label for="specialty">Specialty:</label>
<input name="specialty" type="text" placeholder="<?php echo $group->getSpecialty(); ?>">
<br>
<label for="department">Department:</label>
<select name="department">
<?php foreach ($university->getDepartments() as $department){
echo "<option value=\"".$department->getId()."\"";
if ($department->getId() == strval($group->getDepartment())){
echo " selected ";
}
echo ">".$department->getName();
echo "</option>";
}?>
</select>
<br>
<label for="amount">Amount:</label>
<input name="amount" type="number" min="1" max="322" placeholder="<?php echo $group->getAmount(); ?>">
<br>
<input type="submit">
</form>
<?php } ?>
</div>
</div>
</body>
</html>