This repository has been archived by the owner on Oct 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intranet_doktorandi.php
183 lines (171 loc) · 7.92 KB
/
intranet_doktorandi.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
<?php
/**
* Created by PhpStorm.
* User: Sabinka
* Date: 5/18/2017
* Time: 2:52 PM
*/
include_once 'session.php';
if (!isset($_SESSION['name'])) {
header('location: index.php');
}
require_once "DB_config.php";
$conn = new mysqli($servername, $username, $password, $db_name);
mysqli_set_charset($conn, "utf8");
if (isset($_POST['linkInsert'])) {
$sql = "INSERT INTO `INCEPTORS_LINKS`(`NAME`, `LINK`) VALUES ('" . $_POST['name'] . "', '" . $_POST['link'] . "')";
$conn->query($sql);
$_POST['linkInsert'] = array();
} else if (isset($_POST['categoryInsert'])) {
$sql = "INSERT INTO `INCEPTORS_DOCUMENTS`(`DOCUMENT`) VALUES ('" . $_POST['name'] . "')";
$conn->query($sql);
$_POST['categoryInsert'] = array();
} else if (isset($_POST['attachmentInsert'])) {
$targetfolder = "uploads/inceptors/";
$targetfolder = $targetfolder . basename($_FILES['file']['name']);
move_uploaded_file($_FILES['file']['tmp_name'], $targetfolder);
$sql = "INSERT INTO `INCEPTORS_ATTACHMENTS`(`ATTACHMENT`, `ATTACHMENT_LINK`, `DOCUMENT_ID`) VALUES ('" . $_POST['name'] . "', '" . $targetfolder . "', " . $_POST['category'] . ")";
$conn->query($sql);
$_POST['attachmentInsert'] = array();
}
?>
<head>
<?php
include_once 'includes.php';
?>
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<script src="assets/js/intranet.js"></script>
</head>
<body>
<?php
include_once 'menu.php';
?>
<div id="main">
<h1><?php echo $lang['intranet.inceptors'] ?></h1>
<table class="table">
<thead>
<tr>
<th><?php echo $lang['document'] ?></th>
<th><?php echo $lang['attachment'] ?></th>
</tr>
<?php
$sql = "SELECT ID, NAME, LINK FROM INCEPTORS_LINKS";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr><th colspan='2'><a href='" . $row['LINK'] . "' target='_blank' contenteditable='true' onBlur='saveToDatabase(this, \"NAME\"," . $row['ID'] . ", \"INCEPTORS_LINKS\")'>" . $row['NAME'] . "</a></th></tr>";
}
}
?>
</thead>
<tbody>
<?php
require_once "Document.php";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT ID, DOCUMENT FROM INCEPTORS_DOCUMENTS";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$documents = array();
while ($row = $result->fetch_assoc()) {
$documents[] = new Document($row["ID"], $row["DOCUMENT"]);
}
foreach ($documents as $document) {
$sql = "SELECT ID, ATTACHMENT, ATTACHMENT_LINK FROM INCEPTORS_ATTACHMENTS WHERE DOCUMENT_ID='" . $document->id . "'";
$result = $conn->query($sql);
echo "<tr>";
echo "<td contenteditable='true' onBlur='saveToDatabase(this, \"DOCUMENT\"," . $document->id . ", \"INCEPTORS_DOCUMENTS\")'>" . $document->document . "</td>";
echo "<td>";
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<a href='" . $row['ATTACHMENT_LINK'] . "' target='_blank' contenteditable='true' onBlur='saveToDatabase(this, \"ATTACHMENT\"," . $row['ID'] . ", \"INCEPTORS_ATTACHMENTS\")'>";
echo " " . $row['ATTACHMENT'] . "</a></br>";
}
}
echo "</td></tr>";
}
}
?>
</tbody>
</table>
<button type="button" class="btn btn-default" data-toggle="modal"
data-target="#linkModal"><?php echo $lang['button.add.link'] ?></button>
<button type="button" class="btn btn-default" data-toggle="modal"
data-target="#categoryModal"><?php echo $lang['button.add.category'] ?></button>
<button type="button" class="btn btn-default" data-toggle="modal"
data-target="#attachmentModal"><?php echo $lang['button.add.attachment'] ?></button>
<div id="linkModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><?php echo $lang['button.add.link'] ?></h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="post" action="">
<label class="control-label"><?php echo $lang['button.add.linkname'] ?> </label>
<input type="text" name="name" required>
<label class="control-label">Link: </label>
<input type="text" name="link" required>
<input type="hidden" name="linkInsert">
<input type="submit" value="<?php echo $lang['button.insert'] ?>" class="btn btn-default"
name="submit">
</form>
</div>
</div>
</div>
</div>
<div id="categoryModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><?php echo $lang['button.add.category'] ?></h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="post" action="">
<label class="control-label"><?php echo $lang['button.add.categoryname'] ?> </label>
<input type="text" name="name" required>
<input type="hidden" name="categoryInsert">
<input type="submit" value="<?php echo $lang['button.insert'] ?>" class="btn btn-default"
name="submit">
</form>
</div>
</div>
</div>
</div>
<div id="attachmentModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><?php echo $lang['button.add.attachment'] ?></h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="post" action="" enctype="multipart/form-data">
<label class=" control-label"><?php echo $lang['button.add.attachmentname'] ?> </label>
<input type="text" name="name" required>
<label class="control-label"><?php echo $lang['button.add.chooseCategory'] ?> </label>
<select name="category" required>
<?php
foreach ($documents as $document) {
echo "<option value='" . $document->id . "'>" . $document->document . "</option>";
}
?>
</select>
<label class="control-label"><?php echo $lang['button.add.attachmentfile'] ?> </label>
<input type="file" id="file" name="file" size="50" required>
<input type="hidden" name="attachmentInsert">
<input type="submit" value="<?php echo $lang['button.insert'] ?>" class="btn btn-default"
name="submit">
</form>
</div>
</div>
</div>
</div>
</div>
</body>