This repository was archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcms.php
More file actions
326 lines (282 loc) · 14.6 KB
/
Copy pathcms.php
File metadata and controls
326 lines (282 loc) · 14.6 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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<!DOCTYPE html>
<?php
if (session_status() == PHP_SESSION_NONE) session_start();
$displaylogin = true;
if(!isset($_SESSION['adminloggedin']) || $_SESSION['adminloggedin'] == false){
header('Location: adminlogin.php');
die();
}
?>
<?php
include 'config/dbconfig.php';
//Luam toate variabilele setate in POST si verificam daca sunt valide (adica daca sunt setate si nu sunt goale)
$page = (isset($_POST['page']) && !empty($_POST['page'])) ? $_POST['page'] : null; //id-ul curent al paginii
$section = (isset($_POST['section']) && !empty($_POST['section'])) ? $_POST['section'] : null; //id-ul curent al sectiunii
$subsection = (isset($_POST['subsection']) && !empty($_POST['subsection'])) ? $_POST['subsection'] : null; //id-ul curent al subsectiunii
$content = (isset($_POST['content']) && !empty($_POST['content'])) ? $_POST['content'] : null; //valoarea textarea-ului de content
$contentEN = (isset($_POST['contentEN']) && !empty($_POST['contentEN'])) ? $_POST['contentEN'] : null; //valoarea textarea-ului de contentEN
$newPageName = (isset($_POST['newPageName']) && !empty($_POST['newPageName'])) ? $_POST['newPageName'] : null; //valoarea imputului de new page name
$newSectionName = (isset($_POST['newSectionName']) && !empty($_POST['newSectionName'])) ? $_POST['newSectionName'] : null; //valoarea inputului de new section name
$newSubsectionName = (isset($_POST['newSubsectionName']) && !empty($_POST['newSubsectionName'])) ? $_POST['newSubsectionName'] : null; //valoarea inputului de new subsection name
$deletePage = isset($_POST['deletePage']); //a fost apasat butonul delete page?
$deleteSection = isset($_POST['deleteSection']); //
$deleteSubsection = isset($_POST['deleteSubsection']); //
//Daca valorile de page, section, subsection si content sunt setate then proceed
if($page && $section && $subsection && $content && $contentEN){
try{
//Creem conexiunea la DB
$db = new ContentDB();
//Daca a fost apasat vreun buton de delete
if($deletePage || $deleteSection || $deleteSubsection){
//Verificam care din ele si stergem pagina / section-ul / subsection-ul corespunzator (luat din variabilele de mai sus)
if($deletePage){
$sql = "DELETE FROM pages WHERE id=:page";
$stmt = $db->prepare($sql);
$stmt->bindParam(':page', $page);
$stmt->execute();
}
if($deleteSection){
$sql = "DELETE FROM sections WHERE id=:section";
$stmt = $db->prepare($sql);
$stmt->bindParam(':section', $section);
$stmt->execute();
}
if($deleteSubsection){
$sql = "DELETE FROM subsections WHERE id=:subsection";
$stmt = $db->prepare($sql);
$stmt->bindParam(':subsection', $subsection);
$stmt->execute();
}
}
//Daca exista vreo adaugare de pagina / sectiune / subsectiune
else if($newPageName || $newSectionName || $newSubsectionName){
//INSERT NEW STUFF
if($newPageName){
//Adaugam noua pagina
$sql = "INSERT INTO pages (name) VALUES (:pagename);";
$stmt = $db->prepare($sql);
$stmt->bindParam(':pagename', $newPageName);
$stmt->execute();
//Luam id-ul noii pagini
$sql = "SELECT id FROM pages WHERE name = :pagename";
$stmt = $db->prepare($sql);
$stmt->bindParam(':pagename', $newPageName);
$stmt->execute();
//Updatam field-ul de page cu noul id
$page = $stmt->fetch(PDO::FETCH_ASSOC)['id'];
}
if($newSectionName){
//Adaugam noua sectiune, aici avem nevoie si de id-ul paginii
$sql = "INSERT INTO sections (name, page_id) VALUES (:section, :pageid);";
$stmt = $db->prepare($sql);
$stmt->bindParam(':section', $newSectionName);
$stmt->bindParam(':pageid', $page);
$stmt->execute();
//Luam id-ul noii sectiuni
$sql = "SELECT id FROM sections WHERE name = :section AND page_id = :pageid";
$stmt = $db->prepare($sql);
$stmt->bindParam(':section', $newSectionName);
$stmt->bindParam(':pageid', $page);
$stmt->execute();
//Updatam field-ul de section cu noul id
$section = $stmt->fetch(PDO::FETCH_ASSOC)['id'];
}
if($newSubsectionName){
//Adaugam noua subsectiune, aici avem nevoie si de id-ul sectiunii
$sql = "INSERT INTO subsections (name, section_id) VALUES (:subsection, :sectionid);";
$stmt = $db->prepare($sql);
$stmt->bindParam(':subsection', $newSubsectionName);
$stmt->bindParam(':sectionid', $section);
$stmt->execute();
//Luam id-ul noii subseciuni
$sql = "SELECT id FROM subsections WHERE name = :subsection AND section_id = :sectionid";
$stmt = $db->prepare($sql);
$stmt->bindParam(':subsection', $newSubsectionName);
$stmt->bindParam(':sectionid', $section);
$stmt->execute();
//Updatam field-ul de subsection cu noul id
$subsection = $stmt->fetch(PDO::FETCH_ASSOC)['id'];
}
//Adaugam noul content, aici ne trebuie si id-ul subsectiunii
$sql = "INSERT INTO content (value, subsection_id, language) VALUES (:content, :subsectionid, 'RO');";
$stmt = $db->prepare($sql);
$stmt->bindParam(':content', $content);
$stmt->bindParam(':subsectionid', $subsection);
$stmt->execute();
$sql = "INSERT INTO content (value, subsection_id, language) VALUES (:content, :subsectionid, 'EN');";
$stmt = $db->prepare($sql);
$stmt->bindParam(':content', $contentEN);
$stmt->bindParam(':subsectionid', $subsection);
$stmt->execute();
}
//Daca nici nu dam delete, nici nu adaugam o pagina noua
else{
//UPDATE STUFF
$sql = "UPDATE content SET value=:content WHERE subsection_id=:subsectionid AND language='RO'";
$stmt = $db->prepare($sql);
$stmt->bindParam(':content', $content);
$stmt->bindParam(':subsectionid', $subsection);
$stmt->execute();
$sql = "UPDATE content SET value=:content WHERE subsection_id=:subsectionid AND language='EN'";
$stmt = $db->prepare($sql);
$stmt->bindParam(':content', $contentEN);
$stmt->bindParam(':subsectionid', $subsection);
$stmt->execute();
}
$db = null;
unset($db);
}
catch(PDOException $e){
$e->getMessage();
}
}
else{
echo "<h2 style='color: red'>Da fill la tot coane!</h2>";
}
try{
$db = new ContentDB();
//GET ALL PAGES, SECTIONS, AND SUBSECTIONS FOR OPTIONS
$pageOptions = $sectionOptions = $subsectionOptions = $contentValues = array();
$sql = "SELECT * FROM pages";
$stmt = $db->prepare($sql);
$stmt->execute();
foreach($stmt as $row){
$pageOptions[] = "<option value=" . $row['id'] . ">" . $row['name'] . "</option>";
}
$sql = "SELECT * FROM sections";
$stmt = $db->prepare($sql);
$stmt->execute();
foreach($stmt as $row){
$sectionOptions[$row['page_id']][] = "<option value=" . $row['id'] . ">" . $row['name'] . "</option>";
}
$sql = "SELECT * FROM subsections";
$stmt = $db->prepare($sql);
$stmt->execute();
foreach($stmt as $row){
$subsectionOptions[$row['section_id']][] = "<option value=" . $row['id'] . ">" . $row['name'] . "</option>";
}
$sql = "SELECT * FROM content";
$stmt = $db->prepare($sql);
$stmt->execute();
foreach($stmt as $row){
$contentValues[$row['subsection_id']][$row['language']] = $row['value'];
}
$db = null;
unset($db);
}
catch(PDOException $e){
$e->getMessage();
}
?>
<html>
<head>
<meta name="robots" content="noindex">
<title>CMS UTE :D</title>
</head>
<body>
<form method="post" id="theForm" accept-charset="UTF-8">
<label for="page">Page</label>
<select name="page" id="page" oninput="displayContent(3);">
<?php
foreach($pageOptions as $op){
echo $op;
}
?>
<option value="newPage">new page...</option>
</select>
<button type="submit" onclick="popupDialogue(this);" name="deletePage" id="deletePage">Delete</button>
<div style="display: none" id="addNewPage">
<label for="newPageName">Name</label>
<input type="text" name="newPageName" id="newPageName">
</div>
<br>
<label for="section">Section</label>
<select name="section" id="section" oninput="displayContent(2);">
</select>
<button type="submit" onclick="popupDialogue(this);" name="deleteSection" id="deleteSection">Delete</button>
<div style="display: none" id="addNewSection">
<label for="newSectionName">Name</label>
<input type="text" name="newSectionName" id="newSectionName">
</div>
<br>
<label for="subsection">Subsection</label>
<select name="subsection" id="subsection" oninput="displayContent(1);">
</select>
<button type="submit" onclick="popupDialogue(this);" name="deleteSubsection" id="deleteSubsection">Delete</button>
<div style="display: none" id="addNewSubsection">
<label for="newSubsectionName">Name</label>
<input type="text" name="newSubsectionName" id="newSubsectionName">
</div>
<br>
<label for="content">RO:</label><br><textarea name="content" id="content" style="width: 50vw; height: 50vh"></textarea><br>
<label for="contentEN">EN:</label><br><textarea name="contentEN" id="contentEN" style="width: 50vw; height: 50vh"></textarea><br>
<button type="submit">Submit</button>
</form>
<script>
var sectionOptions = <?php echo json_encode($sectionOptions); ?>;
var subsectionOptions = <?php echo json_encode($subsectionOptions); ?>;
var contentValues = <?php echo json_encode($contentValues); ?>;
displayContent(3);
function displayContent(loc){
var page = document.getElementById('page').value;
var section = document.getElementById('section').value;
var subsection = document.getElementById('subsection').value;
if(page === "newPage"){
document.getElementById("addNewPage").style.display = "block";
document.getElementById("deletePage").style.display = "none";
}
else{
document.getElementById("addNewPage").style.display = "none";
document.getElementById("deletePage").style.display = "inline";
}
if(loc > 1){
if(loc > 2){
var sectionText = "";
if(sectionOptions[page]){
for(var x of sectionOptions[page]){
sectionText += x;
}
}
document.getElementById("section").innerHTML = sectionText + "<option value='newSection'>new section...</option>";
section = document.getElementById('section').value;
}
if(section === "newSection"){
document.getElementById("addNewSection").style.display = "block";
document.getElementById("deleteSection").style.display = "none";
}
else{
document.getElementById("addNewSection").style.display = "none";
document.getElementById("deleteSection").style.display = "inline";
}
var subsectionText = "";
if(subsectionOptions[section]){
for(var x of subsectionOptions[section]){
subsectionText += x;
}
}
document.getElementById("subsection").innerHTML = subsectionText + "<option value='newSubsection'>new subsection...</option>";
subsection = document.getElementById('subsection').value;
}
if(subsection === "newSubsection"){
document.getElementById("addNewSubsection").style.display = "block";
document.getElementById("deleteSubsection").style.display = "none";
}
else{
document.getElementById("addNewSubsection").style.display = "none";
document.getElementById("deleteSubsection").style.display = "inline ";
}
document.getElementById("content").innerHTML = contentValues[subsection]["RO"];
document.getElementById("contentEN").innerHTML = contentValues[subsection]["EN"];
}
// function popupDialogue(el){
// if (confirm('Are you sure you want to delete the thing? Really sure?')) {
// console.log('Thing was deleted from the database.');
// var myInput = document.createElement('input');
// myInput.setAttribute("id", el.id);
// myInput.setAttribute("value", 1);
// document.getElementById('theForm').submit();
// }
// }
</script>
</body>
</html>