-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnastenkaEdit.php
172 lines (146 loc) · 5.1 KB
/
nastenkaEdit.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
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<title>Pridanie/uprava</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
$("#includeHeader").load("all/header.php");
// prihlaseneho uzivatela musi nacitat az neskor
$(function(){
$("#includeHeader").load("all/header.php");
});
</script>
</head>
<body>
<div id="includeHeader"></div>
<div class="container pageLike" style="padding-left: 0px; height:100vh; margin-top: 240px">
<?php
// Function for testing input format
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(isset($_POST['datumEdit'])) {
echo '<script>alert("EDIT");</script>';
}
if(isset($_POST['datumDelete'])) {
// connect DB
include $_SERVER['DOCUMENT_ROOT'] . "/authentification/connectdbbljpm.php";
$dtdelete = test_input($_POST["datumDelete"]);
$sql = "DELETE FROM nastenka where datum = '".$dtdelete."'";
$retval = mysqli_query( $conn, $sql );
if(! $retval ) {
mysqli_close($conn);
die('Nepodarilo sa zmazat data :( ' . mysqli_error());
?>
<script>window.location = "nastenka.php";</script>
<?php
}else{
mysqli_close($conn);
?>
<script>window.location = "nastenka.php";</script>
<?php
}
}
if(isset($_POST['add'])) {
// connect DB
include $_SERVER['DOCUMENT_ROOT'] . "/authentification/connectdbbljpm.php";
if(isset($_POST["datum_od"]))
$dt_od = test_input($_POST["datum_od"]);
if(isset($_POST["datum_do"]))
$dt_do = test_input($_POST["datum_do"]);
$nadpis = test_input($_POST["nadpis"]);
$oznam_text = test_input($_POST["oznam_text"]);
$sql = "INSERT INTO nastenka ". "(datum, ";
if( $dt_od)
$sql = $sql . "dt_od,";
if( $dt_do)
$sql = $sql . "dt_do,";
$sql = $sql . " nazov, oznam) VALUES(CURRENT_TIMESTAMP, ";
if($dt_od)
$sql = $sql . "'" .$dt_od. "', ";
if($dt_do)
$sql = $sql . "'" .$dt_do. "', ";
$sql = $sql . "'" . mysqli_escape_string($conn, $nadpis) . "', ' " . mysqli_escape_string($conn, $oznam_text) . "' )";
$retval = mysqli_query( $conn, $sql );
if(! $retval ) {
die('Nepodarilo sa ulozit data :( ' . mysqli_error());
}
echo "<center><h1>DATA BOLI ULOZENE!</h1></center>";
echo "<center><h4>Toto okno sa automaticky presmeruje za <span id='odpocet'>5</span> sekund</h4></center>";
mysqli_close($conn);
?>
<script>
setTimeout(function(){
$('#odpocet').text("4");
}, 1000);
setTimeout(function(){
$('#odpocet').text("3");
}, 2000);
setTimeout(function(){
$('#odpocet').text("2");
}, 3000);
setTimeout(function(){
$('#odpocet').text("1");
}, 4000);
setTimeout(function(){
window.location = "nastenka.php";
}, 5000);
</script>
<?php
}else {
?>
<div class="container">
<h2>Pridávanie/ Úprava nástenky</h2>
<br>
<br>
<form method = "post" action = "<?php $_PHP_SELF ?>" class="form-horizontal">
<div class="form-group" >
<label class="control-label col-sm-3" for="datum_od" style="text-align: left;">Dátum od:</label>
<label class="control-label col-sm-3" for="datum_do" style="text-align: left;">Dátum do:</label>
</div>
<div class="form-group">
<div class="col-sm-3">
<input name="datum_od" type="date" class="form-control" id="datum_od" placeholder="Datum od, dňa alebo prázdny">
</div>
<div class="col-sm-3">
<input name="datum_do" type="date" class="form-control" id="datum_do">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="nadpis" style="text-align: left;">Nadpis oznamu:</label>
<label class="control-label col-sm-3" for="oznam_text" style="text-align: left;">Oznam:</label>
</div>
<div class="form-group">
<div class="col-sm-3">
<input name="nadpis" type="text" class="form-control" placeholder="Nadpis pre dôležitý oznam." id="nadpis">
</div>
<div class="col-sm-8">
<textarea name="oznam_text" class="form-control" cols="200" rows="10" placeholder="Velmi dôležitá správa pre všetkých" id="oznam_text"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8" align="right">
<button name="add" id="add" type="submit" class="btn btn-default">Uložiť</button>
</div>
</div>
</form>
</div>
<?php }// ukoncenie if podmienky pre zobrazenie
include $_SERVER['DOCUMENT_ROOT'] . "/nastenka/nastenka_vyber_zobraz.php";
?>
</div>
<div id="includeFooter"></div>
</body>
</html>
<script>
$(window).on('load', function() {
resizeEvent();
});
</script>