-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.php
99 lines (78 loc) · 2.98 KB
/
manage.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
<?php
session_start();
if (!isset($_SESSION['username'])) {
header("Location: login.php");
}
// User vars
$username = $_SESSION['username'];
$fileid = $_SESSION['fileid'];
$classroom = $_SESSION['classroom'];
$classroomowned = $_SESSION['classroomowned'];
if (isset($_GET['classroom'])) {
$getClassroom = $_GET['classroom'];
if ($getClassroom != $classroomowned) {
header("Location: welcome.php");
}
} else {
header("Location: welcome.php");
}
include('navbar.php');
include('database.php');
// Get users
$sql = "SELECT * FROM users WHERE classroom = '$getClassroom'";
$result = mysqli_query($db, $sql);
// $count = mysqli_num_rows($result);
// echo($count);
function niceNickname($testo) {
$userSplit = explode('_', $testo);
$niceUsername = ucfirst($userSplit[0]) . ' ' . ucfirst($userSplit[1]);
return $niceUsername;
}
?>
<div class="container page-wrapper">
<div class="columns is-desktop">
<div class="column">
<h3 class="title is-3">📚 Utenti</h3>
<?php while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { ?>
<button id="<?= $row['fileid'] ?>" class="button is-warning user-card" onclick="readDataAjax('<?= $row['fileid'] ?>', '<?= niceNickname($row['username']) ?>')">
<p class="subtitle"><span id="selected"></span> <?= niceNickname($row['username']) ?></p>
</button>
<?php } ?>
</div>
<div class="column is-four-fifths">
<h3 class="title is-3">👀 Viewing code of: <span id="username"></span></h3>
<div id="manageEditor"></div>
</div>
</div>
</div>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<!-- Codemirror -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/codemirror.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/mode/python/python.min.js"></script>
<script>
let codeEditor = CodeMirror(document.querySelector('#manageEditor'), {
lineNumbers: true,
lineWrapping: true,
tabSize: 2,
mode: 'python',
theme: 'ayu-mirage',
readOnly: true
});
function readDataAjax(userFile, userName) {
let xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
codeEditor.setValue(xmlhttp.responseText)
}
}
xmlhttp.open("POST", 'save.php', true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("action=read&userid=" + userFile);
// aggiorna titolo
$('#username').html(userName);
}
</script>
<?php include('footer.php'); ?>
</body>
</html>