-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.information.php
170 lines (168 loc) · 6.63 KB
/
add.information.php
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
@session_start();
$activeTitle = "Add School İnformation";
$activePage = "add.information";
require 'up.html.php';
require 'login.control.php';
?>
<?php
//!Rol idsi 2 olan register unit sadece information ekleyebilir
if ($_SESSION['role'] != 2) {
header("location: authorizationcontrol.php");
die();
}
?>
<?php
require 'navbar.php'?>
<?php
//! Veri tabanına information ekleme
if (isset($_POST['submit_form'])) {
//!Hata mesajlarını göstermek için boş bir dizi
$errors = array();
//!htmlspecialchars() kullanıcıdan alınan veriyi güvenli hale getirir
//! eğer kullanıcı zararlı bir kod gönderirse bunu html etiketlerine dönüştürür
require_once 'db.php';
$schoolName = htmlspecialchars($_POST['form_name']);
$schoolYear = htmlspecialchars($_POST['form_year']);
$schoolTerm = htmlspecialchars($_POST['form_term']);
$schoolAbout = htmlspecialchars($_POST['form_about']);
$schoolSummary = htmlspecialchars($_POST['form_summary']);
$schoolAddress = htmlspecialchars($_POST['form_address']);
$addedUnitid = $_SESSION['id'];
$addedUnitName = $_SESSION['userName'];
//?Aynı Okul isminden var mı yok mu kontrol etme
$sql = "SELECT * FROM informations WHERE schoolname = :form_name";
$SORGU = $DB->prepare($sql);
$SORGU->bindParam(':form_name', $schoolName);
$SORGU->execute();
$isSchoolName = $SORGU->fetch(PDO::FETCH_ASSOC);
/* echo '<pre>';
print_r($isSchoolName);
die(); */
//!Eğer aynı isimde ders varsa hata ver
if ($isSchoolName) {
$errors[] = "There is a School with the same name !";
//!Eğer aynı isimde ders yoksa kaydet
} else {
// Insert into Database
$sql = "INSERT INTO informations (schoolname,schoolyear,schoolterm,schoolabout,schoolsummary,schooladdress,addedunitid,addedunitname) VALUES (:form_name,:form_year,:form_term,:form_about,:form_summary,:form_address,:addedunitid,:addedunitname)";
$SORGU = $DB->prepare($sql);
$SORGU->bindParam(':form_name', $schoolName);
$SORGU->bindParam(':form_year', $schoolYear);
$SORGU->bindParam(':form_term', $schoolTerm);
$SORGU->bindParam(':form_about', $schoolAbout);
$SORGU->bindParam(':form_summary', $schoolSummary);
$SORGU->bindParam(':form_address', $schoolAddress);
$SORGU->bindParam(':addedunitid', $addedUnitid);
$SORGU->bindParam(':addedunitname', $addedUnitName);
$SORGU->execute();
$approves[] = "School İnformation Added Successfully...";
}
}
?>
<div class="container">
<div class="row justify-content-center mt-3">
<div class="col-6">
<form method="POST" class="needs-validation" novalidate>
<h1 class="alert alert-info text-center">Add School İnformation</h1>
<?php
//! Hata mesajlarını göster
if (!empty($errors)) {
foreach ($errors as $error) {
echo "<div class='position-fixed top-0 end-0 p-3' style='z-index: 5'>
<div class='toast align-items-center text-white bg-danger border-0' role='alert' aria-live='assertive' aria-atomic='true' data-bs-delay='5000'>
<div class='d-flex'>
<div class='toast-body'>
$error
</div>
<button type='button' class='btn-close btn-close-white me-2 m-auto' data-bs-dismiss='toast' aria-label='Close'></button>
</div>
</div>
</div>";
}
}
?>
<?php
//! Başarılı mesajlarını göster
if (!empty($approves)) {
foreach ($approves as $approve) {
echo "<div class='position-fixed top-0 end-0 p-3' style='z-index: 5'>
<div class='toast align-items-center text-white bg-success border-0' role='alert' aria-live='assertive' aria-atomic='true' data-bs-delay='5000'>
<div class='d-flex'>
<div class='toast-body'>
$approve
</div>
<button type='button' class='btn-close btn-close-white me-2 m-auto' data-bs-dismiss='toast' aria-label='Close'></button>
</div>
</div>
</div>";
}
}
?>
<div class="form-floating mb-3">
<input type="text" class="form-control" value="<?php echo $_SESSION['userName'] ?>"disabled readonly>
<label>Added By Register Unit Name</label>
</div>
<div class="form-floating mb-3">
<input type="text" class="form-control" id="floatingInput" placeholder="School Name" name="form_name" required>
<label for="floatingInput">School Name</label>
<div class="invalid-feedback fw-bold">
Please Write Your School Name !
</div>
</div>
<div class="form-floating mb-3">
<select class="form-select" name="form_year" id="floatingSelect" aria-label="Floating label select example"required>
<option selected disabled value="">Select Year</option>
<?php
//! 1950'den bugüne kadar yılları seçen bir döngü
for ($i = 1950; $i <= date("Y"); $i++) {
echo "<option value='$i'>$i</option>";
}
?>
</select>
<label for="floatingSelect">School Year</label>
<div class="invalid-feedback fw-bold">
Select Your School Year !
</div>
</div>
<div class="form-floating mb-3 ">
<select class="form-select" name="form_term" id="floatingSelect2" aria-label="Floating label select example 2" required>
<option selected disabled value="">Select Term</option>
<option value="I">I</option>
<option value="II">II</option>
</select>
<label for="floatingSelect2">School Term</label>
<div class="invalid-feedback fw-bold">
Select Your School Term !
</div>
</div>
<div class="form-floating mb-3 ">
<textarea class="form-control" name="form_about" placeholder="School About" id="floatingTextarea3" style="height: 100px" required></textarea>
<label for="floatingTextarea3">School About</label>
<div class="invalid-feedback fw-bold">
Write Your School About !
</div>
</div>
<div class="form-floating mb-3 ">
<textarea class="form-control" name="form_summary" placeholder="School About Summary" id="floatingTextarea4" style="height: 100px" required></textarea>
<label for="floatingTextarea4">School About Summary</label>
<div class="invalid-feedback fw-bold">
Write Your School About Summary !
</div>
</div>
<div class="form-floating mb-3 ">
<textarea class="form-control" name="form_address" placeholder="School Address" id="floatingTextarea2" style="height: 100px" required></textarea>
<label for="floatingTextarea2">School Address</label>
<div class="invalid-feedback fw-bold">
Write Your School Address !
</div>
</div>
<button type="submit" name="form_submit" class="btn btn-primary mt-3 ">Add School İnformation
<i class="bi bi-send"></i>
</button>
</form>
</div>
</div>
</div>
<?php require 'footer.php';?>
<?php require 'down.html.php';?>