-
Notifications
You must be signed in to change notification settings - Fork 0
/
donate-pdf.php
146 lines (129 loc) · 5.16 KB
/
donate-pdf.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
<?php
session_start();
if(!isset($_SESSION['id'])){
header("location: login.php");
}
require "database/connection.php";
if(isset($_SESSION['id'])){
$id = $_SESSION['id'];
}
$sql = "SELECT * FROM users WHERE user_id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('s', $id);
if($stmt->execute()){
$result = $stmt->get_result();
if($result->num_rows > 0){
$row = $result->fetch_assoc();
}
}
require "includes/login-header.php";
?>
<style>
.loader-container {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 9999;
text-align: center;
}
.loader {
border: 8px solid #f3f3f3;
border-top: 8px solid #3498db;
border-radius: 50%;
width: 50px;
height: 50px;
margin: 15% auto;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
<section class="container-fluid login-wrapper pt-4">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-6">
<div class="login-form">
<a href="javascript:history.back();" style="font-size: 1.4rem;"><i class="bi bi-arrow-left" style="margin-right: .5rem;"></i>
</a>
<h2 class="pt-2 text-center" style="font-size: 2rem; line-height: 1.3;">Donate Pdf</h2>
<!-- <a href="edit-donate-pdf.php" style="color: blue; font-weight: 500; font-size: 1.1rem;">Edit Pdf</a> -->
<form id="dp_form" class="pt-0 mt-3" method="POST" enctype="multipart/form-data">
<?php
if(isset($error['file'])){
echo $error['file'];
}
?>
<p>Help Smart Campus by donating the PDF you have for other students to have access to. You can also monetize your books by adding prices.</p>
<div class="input-group mb-5">
<input type="text" name="title" id="course_title" class="form-control" placeholder="Course Title" required>
</div>
<div class="input-group mb-5">
<input type="text" name="price" id="price" class="form-control" placeholder="Enter Price" required>
</div>
<div class="form-group mb-5">
<label for="desc">Description</label>
<textarea class="form-control" name="desc" id="desc" required></textarea>
</div>
<div class="mb-5" >
<label for="file">Upload Pdfs</label>
<input class="form-control" type="file" id="file" name="file" placeholder="Upload Pdfs" required>
</div>
<div class="form-group mt-5">
<button type="submit" name="donate-pdf-btn" id="donate-pdf-btn" class="form-control getStarted-btn">Upload</button>
</div>
</form>
<div id="loader" class="loader-container">
<div class="loader"></div>
</div>
</div>
</div>
</div>
</div>
</section>
<?php require "includes/login-footer.php"; ?>
<script src="js/jquery2.js"></script>
<script src="js/index.js"></script>
<script src="./assets/js/sweetalert.js"></script>
</body>
</html>
<script>
$(document).ready(function(){
$('#dp_form').on('submit', function(e){
e.preventDefault();
var formData = new FormData(this);
var fileSize = $('#file')[0].files[0].size;
var maxSize = 5000000000;
if(fileSize > maxSize){
$('#message').html('Image size is too large');
} else{
$.ajax({
url: 'backend/donate-pdf.php',
type: 'POST',
data: formData,
processData: false,
contentType: false,
beforeSend: function() {
// Show the loader when the upload starts
$('#loader').show();
},
success: function(response){
$('#loader').hide();
$('#message').html(response);
Swal.fire(
'Success',
'Uploaded Successfully',
'success'
)
}
});
}
});
$('#dp_form')[0].reset();
});
</script>