-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpert_prof.php
More file actions
339 lines (285 loc) · 13 KB
/
expert_prof.php
File metadata and controls
339 lines (285 loc) · 13 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
327
328
329
330
331
332
333
334
335
336
337
338
339
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Expert</title>
<link rel="stylesheet" href="http://localhost:8888/./css/main.css">
<link rel='stylesheet' href="http://localhost:8888/resources/font-awesome.min.css">
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous"> -->
</head>
<body>
<?php
session_start();
if(!isset($_SESSION['login'])){
$_SESSION['error'] = "[RIGHTS] Вам запрещен доступ на эту страницу!";
header('Location: '. 'http://localhost:8888/error.php');
exit();
}
?>
<?php
include "menu.php";
?>
<header class="header">
<div class="header__wrapper">
<h1 class="header__title" style="color: #000; border-bottom: 1px solid #000000;">
Skills
</h1>
<div class="header__text">
Выберете 7 качеств для профессии
</div>
</div>
</header>
<!-- job_listing_area_start -->
<main class="section">
<div class="container" id="internals">
<h3 class="category__title">Категория 1</h3>
<ul class="job_lists">
<li class="single_jobs">
<div class="jobs_left">
<div class="jobs_conetent">
<h4>Качество бла бла бла бла бла бла бла бла бла бла бла бла бла бла бла бла</h4>
</div>
</div>
<div class="jobs_right">
<div class="apply_now">
<a class="heart_mark" href="#"> <i class="fa fa-heart"></i> </a>
</div>
</div>
</li>
<li class="single_jobs">
<div class="jobs_left">
<div class="jobs_conetent">
<h4>Качество</h4>
</div>
</div>
<div class="jobs_right">
<div class="apply_now">
<a class="heart_mark" href="#"> <i class="fa fa-heart"></i> </a>
</div>
</div>
</li>
<li class="single_jobs"><div class="jobs_left"><div class="jobs_conetent"><h4>Качество</h4></div></div><div class="jobs_right"><div class="apply_now"><a class="heart_mark" href="#"> <i class="fa fa-heart"></i> </a></div></div></li>
<li class="single_jobs">
<div class="jobs_left">
<div class="jobs_conetent">
<h4>Качество</h4>
</div>
</div>
<div class="jobs_right">
<div class="apply_now">
<a class="heart_mark" href="#"> <i class="fa fa-heart"></i> </a>
</div>
</div>
</li>
</ul>
<h3 class="category__title">Категория 2</h3>
<ul class="job_lists">
<li class="single_jobs">
<div class="jobs_left">
<div class="jobs_conetent">
<h4>Качество</h4>
</div>
</div>
<div class="jobs_right">
<div class="apply_now">
<a class="heart_mark" href="#"> <i class="fa fa-heart"></i> </a>
</div>
</div>
</li>
<li class="single_jobs">
<div class="jobs_left">
<div class="jobs_conetent">
<h4>Качество</h4></a>
</div>
</div>
<div class="jobs_right">
<div class="apply_now">
<a class="heart_mark" href="#"> <i class="fa fa-heart"></i> </a>
</div>
</div>
</li>
</ul>
</div>
</main>
<button id="continueButton" class="btn btn-outline-primary">Продолжить</button>
<div id="hiddenFragment" style="display: none;">
<div class="header__text" style="text-align: center">Распределение ПВК по важности</div>
<div class="header__text" style="text-align: center">Перетащите каждое название ПВК на соответствующее место по важности:</div>
<ol>
<li draggable="true" id="1">Название 1</li>
<li draggable="true" id="2">Название 2</li>
<li draggable="true" id="3">Название 3</li>
<li draggable="true" id="4">Название 4</li>
<li draggable="true" id="5">Название 5</li>
<li draggable="true" id="6">Название 6</li>
<li draggable="true" id="7">Название 7</li>
</ol>
<div style="text-align: center;">
<button class="submit btn btn-outline-success" disabled>Отправить</button>
</div>
</div>
<script>
const continueButton = document.getElementById('continueButton');
const hiddenFragment = document.getElementById('hiddenFragment');
async function init(){
var $_GET = {},
args = location.search.substr(1).split(/&/);
for (var i=0; i<args.length; ++i) {
var tmp = args[i].split(/=/);
if (tmp[0] != "") {
$_GET[decodeURIComponent(tmp[0])] = decodeURIComponent(tmp.slice(1).join("").replace("+", " "));
}
}
const prof = await fetch("http://localhost:8888/backend/get_profession.php?id=" + $_GET['id']);
console.log("http://localhost:8888/backend/get_profession.php?id=" + $_GET['id']);
const prof_conv = await prof.json();
// TODO: do error for no profession
console.log(prof_conv['success'])
if (prof_conv['success'] == true){
window.location.replace("http://localhost:8888/error.php");
}
const title = document.querySelector(".header__text");
title.setAttribute("id", prof_conv["id"]);
title.innerText += ` ${prof_conv.name}.`;
const res = await fetch("http://localhost:8888/backend/get_categories.php");
const conv = await res.json();
const internals = document.getElementById("internals");
internals.innerHTML = "";
for (const cat in conv) {
let current_internals = '<h3 class="category__title">' + conv[cat]['name'] + '</h3> <ul class="job_lists">';
let cur = (parseInt(cat)+1).toString();
//console.log("http://localhost:8888/backend/get_internals_by_category.php?category="+cur);
const iternals = await fetch("http://localhost:8888/backend/get_internals_by_category.php?category="+cur);
const iternals_conv = await iternals.json();
for(const iter in iternals_conv){
console.log("hello");
current_internals += `<li class="single_jobs"><div class="jobs_left"><div class="jobs_conetent"><h4>${iternals_conv[iter]['name']}</h4></div></div><div class="jobs_right"><div class="apply_now"><a id=${iternals_conv[iter]['id']} class="heart_mark" href="#"></a></div></div></li>`;
}
current_internals += '</ul>';
internals.innerHTML = internals.innerHTML+current_internals;
}
}
window.addEventListener('DOMContentLoaded',init);
//---------------------------------------------------------
function post(path, params, method='post') {
const form = document.createElement('form');
form.method = method;
form.action = path;
for (const key in params) {
if (params.hasOwnProperty(key)) {
const hiddenField = document.createElement('input');
hiddenField.type = 'hidden';
hiddenField.name = key;
hiddenField.value = params[key];
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
let globalSet = new Set();
const getCheckedItems = () => {
const checkedItems = document.querySelectorAll(".heart_mark.checked");
return Array.from(checkedItems).map(({id}) => id);
};
const getGlobalSetInObject = () => Object.fromEntries([...globalSet].map((value, index) => [`k${index}`, value]));
const toggleDisabledButton = () => {
const checkedElements = getCheckedItems();
if (checkedElements.length === 7) {
continueButton.addEventListener('click', function() {
hiddenFragment.style.display = 'block';
});
document.querySelector(".submit").disabled = false;
const listItems = document.querySelectorAll("ol li");
const globalArray = [...globalSet]; // Преобразовать Set в массив
let i = 0;
listItems.forEach((item) => {
let id = item.getAttribute("id");
if (!checkedElements.includes(id)) {
(async function(index) {
let internalResponse = await fetch("http://localhost:8888/backend/get_internal.php?id=" + globalArray[index]);
let internal = await internalResponse.json();
item.innerText = internal['name'];
})(i);
i++;
}
});
} else {
document.querySelector(".submit").disabled = true;
}
};
const toggleCheckbox = (e) => {
const buttonHome = e.target.closest("a");
e.preventDefault();
const a = e.target.closest("a");
const checkedCheckboxes = getCheckedItems();
if (!a || !a.classList.contains("heart_mark") || (!((checkedCheckboxes.includes(a.id) && checkedCheckboxes.length >= 7) || checkedCheckboxes.length < 7))) {
return;
}
if (a.classList.contains("checked")) {
a.classList.remove("checked");
globalSet.delete(a.id);
} else {
a.classList.add("checked");
globalSet.add(a.id);
}
toggleDisabledButton();
};
const submitHandler = async () => {
const professionId = document.querySelector(".header__text").id;
body: JSON.stringify(Object.assign(getGlobalSetInObject(), {
prof_id: professionId,
})),
post('/backend/rate.php',Object.assign(getGlobalSetInObject(), {prof_id: professionId,}));
};
document.querySelector(".submit").addEventListener("click", submitHandler);
document.addEventListener("click", toggleCheckbox);
//-------------------------------------------------
const items = document.querySelectorAll('li');
let draggedItem = null;
for (let i = 0; i < items.length; i++) {
const item = items[i];
item.addEventListener('dragstart', function() {
draggedItem = item;
setTimeout(function() {
item.style.display = 'none';
}, 0);
});
item.addEventListener('dragend', function() {
setTimeout(function() {
draggedItem.style.display = 'block';
draggedItem = null;
}, 0);
});
for (let j = 0; j < items.length; j++) {
const dropzone = items[j];
dropzone.addEventListener('dragover', function(e) {
e.preventDefault();
});
dropzone.addEventListener('dragenter', function(e) {
e.preventDefault();
this.style.backgroundColor = '#e0e0e0';
});
dropzone.addEventListener('dragleave', function() {
this.style.backgroundColor = '#ffffff';
});
dropzone.addEventListener('drop', function() {
if (this.nextSibling === draggedItem) {
this.parentNode.insertBefore(draggedItem, this.nextSibling.nextSibling);
} else {
this.parentNode.insertBefore(draggedItem, this.nextSibling);
}
this.style.backgroundColor = '#ffffff';
});
}
}
</script>
<!-- job_listing_area_end dsddfdds-->
<script src="http://localhost:8888/./js/app.js"></script>
<!-- <script src="http://localhost:8888/./js/Lab1-expert.js"></script> -->
<!-- <script src="http://localhost:8888/./js/Lab1-expertcheckbox.js"></script> -->
<script src="./js/menu.js"></script>
</body>
</html>