-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-file.php
134 lines (118 loc) · 5.9 KB
/
add-file.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
<?php
$page_title = "Add File";
include("./connection/db.php");
//check if someone was signed in
if(!isset($_SESSION['id'])){
header("Location: ./signin.php");
exit;
} else {
$query_get_all_users = "SELECT `id`, `position`, `office` FROM `users`";
$result_get_all_users = mysqli_query($db, $query_get_all_users);
$all_users = mysqli_fetch_all($result_get_all_users, MYSQLI_ASSOC);
$query_get_all_offices = "SELECT `office`, COUNT(*) FROM `users` GROUP BY `office`";
$result_get_all_offices = mysqli_query($db, $query_get_all_offices);
$all_offices = mysqli_fetch_all($result_get_all_offices, MYSQLI_ASSOC);
if(isset($_POST['upload'])){
$fileName = $_FILES['file']['name'];
$fileType = $_FILES['file']['type'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$uploadPath = './storage/uploads/';
$newFileName = uniqid() . '_' . $fileName;
$uploadFilePath = $uploadPath . $newFileName;
move_uploaded_file($fileTmpName, $uploadFilePath);
$upload_id = makeid();
$notification_id = makeid();
$log_id = makeid();
$type = $_POST['type'];
$forwardto = $_POST['forward-to'];
$from = $_SESSION['id'];
$notification_msg = "document uploaded";
$query_upload_file = "INSERT INTO `document`(`id`, `type`, `fileName`, `forID`, `fromID`) VALUES ('$upload_id','$type','$newFileName','$forwardto','$from')";
$query_add_notofication = "INSERT INTO `notification`(`id`, `sender`, `receiver`,`docID`, `class`, `message`) VALUES ('$notification_id','$from','$forwardto','$upload_id','notification-sent','$notification_msg')";
$query_add_log = "INSERT INTO `log`(`id`, `documentID`, `status`, `updatedBy`, `forOffice`) VALUES ('$log_id', '$upload_id', 'sent', '$from', '$forwardto')";
if(mysqli_query($db, $query_upload_file)){
if(mysqli_query($db, $query_add_notofication)){
if(mysqli_query($db, $query_add_log)){
$uploaded = "File Uploaded";
} else {
echo "Log not saved: " . $db->error;
}
} else {
echo "Notification not sent: " . $db->error;
}
} else {
echo "Document record not saved: " . $db->error;
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include("./components/head.php"); ?>
</head>
<body>
<div class="col-lg-8 mx-auto">
<main class="add-file pt-5 pb-5">
<!--Start Breadcrumbs-->
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="./">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Add File</li>
</ol>
</nav>
<!--End Breadcrumbs-->
<h3 class="page-heading mb-5">ADD FILE</h3>
<?php if(isset($uploaded)): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?php echo $uploaded; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<form method="POST" enctype="multipart/form-data">
<div class="mb-4">
<label for="type" class="form-label">Select document type</label>
<select name="type" id="type" class="form-select" required>
<option selected disabled></option>
<option value="MOA">MOA</option>
<option value="Project Proposal">Project Proposal</option>
<option value="Training Designs">Training Designs</option>
<option value="Annual Operational Plans">
Annual Operational Plans
</option>
<option value="Quarterly Operational Plans">
Quarterly Operational Plans
</option>
<option value="Work and Financial Plans">
Work and Financial Plans
</option>
<option value="Others">Others</option>
</select>
</div>
<div class="row">
<div class="col mb-4">
<label for="forward-to" class="form-label">Forward to</label>
<select name="forward-to" id="forward-to" class="form-select" required>
<option selected disabled></option>
<?php foreach($all_users as $user): ?>
<?php if($user['id'] != $_SESSION['id']): ?>
<option value="<?php echo $user['id'] ?>"><?php echo $user['office']?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="mb-4">
<label for="file" class="form-label">File</label>
<input type="file" name="file" id="file" class="form-control" accept=".pdf, .doc, .docx" required />
</div>
<div class="col">
<button name="upload" type="submit" class="btn btn-primary">Upload</button>
</div>
</form>
</main>
</div>
<script src="./assets/js/bootstrap.bundle.min.js"></script>
</body>
</html>