-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunos.php
232 lines (201 loc) · 9.41 KB
/
unos.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
session_start();
if (isset($_SESSION['level']) == false) {
header("Location:prijava.php");
exit();
}
if ($_SESSION['level'] == 0) {
header("Location:index.php");
exit();
}
include "connect.php";
define("UPLPATH", "media/images/");
$id = NULL;
$title = NULL;
$about = NULL;
$content = NULL;
$category = NULL;
$archive = NULL;
if(isset($_GET["edit_id"])) {
$edit_id = $_GET["edit_id"];
$query = "SELECT * FROM clanak WHERE id=$edit_id";
$result = mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$title = $row['naslov'];
$about = $row['sazetak'];
$content = $row['tekst'];
$picture = $row['slika'];
$category = $row['kategorija'];
$archive = $row['arhiva'];
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lumberjack Revival</title>
<meta name="description" content="Projekt iz PWA, napravio Antonio Jurešić 2020.">
<meta name="author" content="Antonio Jurešić">
<meta name="keywords" content="HTML, CSS, PHP, JavaScript">
<link rel="stylesheet" href="stylesheet.css">
<link rel="stylesheet" href="css/LumberjackStylesheet.css">
</head>
<body>
<div class="page_wrapper">
<?php include "header.php"; ?>
<section>
<form enctype="multipart/form-data" method="POST" action="skripta.php">
<div class="form-item">
<label for="title">Article title: </label>
<div class="form-field">
<?php echo "<input type='text' name='title' id='title' value='" . $title . "' required>"; ?>
</div>
<span id="error_title" class="error"></span>
</div>
<br>
<div class="form-item">
<label for="about">Short text (max 100 characters)</label>
<div class="form-field">
<?php echo "<textarea name='about' id='about' maxlength='100' required>". $about . "</textarea>"; ?>
</div>
<span id="error_about" class="error"></span>
</div>
<br>
<div class="form-item">
<label for="content">Article text: </label>
<div class="form-field">
<?php echo "<textarea name='content' id='content' required>" . $content . "</textarea>"; ?>
</div>
<span id="error_content" class="error"></span>
</div>
<br>
<div class="form-item">
<label for="picture">Article picture: </label>
<div class="form-field">
<?php
if(isset($_GET["edit_id"])) {
echo "<input name='picture' id='picture' type='file' accept='image/png,image/jpeg,image/gif'/>";
echo " <img src=' " . UPLPATH . $picture . "' style='width: 100%;'>";
} else {
echo "<input name='picture' id='picture' type='file' accept='image/png,image/jpeg,image/gif' required/>";
}
?>
</div>
<span id="error_picture" class="error"></span>
</div>
<br>
<div class="form-item">
<label for="category">Category: </label>
<div class="form-field">
<select name="category" id="category" required>
<?php
if($category == "news") {
echo "<option value='news' selected='selected'>News</option>";
echo "<option value='lifestyle'>Lifestyle</option>";
} else if($category == "lifestyle") {
echo "<option value='news'>News</option>";
echo "<option value='lifestyle' selected='selected'>Lifestyle</option>";
} else {
echo "<option value='' disabled selected>Chose category</option>";
echo "<option value='news'>News</option>";
echo "<option value='lifestyle'>Lifestyle</option>";
}
?>
</select>
</div>
<span id="error_category" class="error"></span>
</div>
<br>
<div class="form-item">
<label for="archive">Spremiti u arhivu:
<div class="form-field">
<?php
if($archive == NULL || $archive == "0") {
echo "<input type='checkbox' name='archive' id='archive'>";
} else if ($archive == "1") {
echo "<input type='checkbox' name='archive' id='archive' checked>";
}
?>
</div>
</label>
</div>
<br>
<div class="form-item">
<?php echo "<input type='hidden' name='id' class='form-field-textual' value='" . $id . "'>";?>
</div>
<br>
<div class="form-item">
<button type="reset" id="reset" name ="reset" value="reset">Reset</button>
<button type="submit" id="submit" name ="submit" value="submit">Submit</button>
</div>
</form>
</section>
</div>
<?php include "footer.php"; ?>
</body>
</html>
<script>
document.getElementById("submit").onclick = function(event) {
var sendForm = true;
//Title must be between 5 and 30 characters
var fieldTitle = document.getElementById("title");
var title = document.getElementById("title").value;
if (title.length < 5 || title.length > 30) {
sendForm = false;
fieldTitle.style.border="0.25vw dashed red";
document.getElementById("error_title").innerHTML = "Title must be between 5 and 30 characters<br>";
} else {
fieldTitle.style.border="0.25vw solid green";
document.getElementById("error_title").innerHTML = "";
}
//About must be between 10 and 100 characters
var fieldAbout = document.getElementById("about");
var about = document.getElementById("about").value;
if (about.length < 10 || about.length > 100) {
sendForm = false;
fieldAbout.style.border="0.25vw dashed red";
document.getElementById("error_about").innerHTML = "About must be between 10 and 100 characters<br>";
} else {
fieldAbout.style.border="0.25vw solid green";
document.getElementById("error_about").innerHTML = "";
}
//Content can't be empty
var fieldContent = document.getElementById("content");
var content = document.getElementById("content").value;
if (content.length == 0) {
sendForm = false;
fieldContent.style.border="0.25vw dashed red";
document.getElementById("error_content").innerHTML = "Content can't be empty!<br>";
} else {
fieldContent.style.border="0.25vw solid green";
document.getElementById("error_content").innerHTML = "";
}
//Picture can't be empty
var fieldPicture = document.getElementById("picture");
var picture = document.getElementById("picture").value;
if (picture.length == 0 && window.location.href.indexOf("edit_id") == false) {
sendForm = false;
fieldPicture.style.border="0.25vw dashed red";
document.getElementById("error_picture").innerHTML = "Picture can't be empty, upload a picture!<br>";
} else {
fieldPicture.style.border="0.25vw solid green";
document.getElementById("error_picture").innerHTML = "";
}
//Category can't be empty
var fieldCategory = document.getElementById("category");
if(document.getElementById("category").selectedIndex == 0) {
sendForm = false;
fieldCategory.style.border="0.25vw dashed red";
document.getElementById("error_category").innerHTML="Category can't be empty!<br>";
} else {
fieldCategory.style.border="0.25vw solid green";
document.getElementById("error_category").innerHTML="";
}
if (sendForm != true) {
event.preventDefault();
}
}
</script>