-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsertion.php
317 lines (261 loc) · 11.2 KB
/
insertion.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
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
<?php
include "dbconnect.php";
function datacheck()
{
if(strlen($_POST["name"])>30 || strlen($_POST["father"])>30 || strlen($_POST["mother"])>30)
{
echo"<script>window.alert('Name should not be more than 30 characters');</script>";
return false;
}
if(strlen($_POST["email"])>40)
{
echo"<script>window.alert('E Mail Address shouldn't exceed 40 characters');</script>";
return false;
}
if(strlen($_POST["permanent"])>100 )
{
echo"<script>window.alert('Address should not exceed 100 characters');</script>";
return false;
}
if(strlen(strval($_POST["pin"]))>6)
{
echo"<script>window.alert('Pincode should not exceed 6 characters');</script>";
return false;
}
if(strlen(strval($_POST["alt"]))>11)
{
echo"<script>window.alert('Alternate No. should not exceed 11 characters');</script>";
return false;
}
if(strlen(strval($_POST["amount"]))>11)
{
echo"<script>window.alert('Amount value limit reached!!!!');</script>";
return false;
}
if(strlen(strval($_POST["mobile"]))>11 || strlen($_POST["enroll"])>10)
{
echo"<script>window.alert('Mobile No. should not exceed 11 character and Enrollment No. should not exceed 10 characters');</script>";
return false;
}
if(strlen($_POST["roll"])>12)
{
echo"<script>window.alert('Roll No. should not exceed 12 characters');</script>";
return false;
}
if(strlen($_POST["receipt"])>20)
{
echo"<script>window.alert('Receipt No. should not exceed 20 characters');</script>";
return false;
}
if(!FileUplod_check()){
echo"<script>window.alert('Coudn't upload file');</script>";
return false;
}
if($_POST["sbi"] == "Yes"){
if (!PassBook_check()) {
echo "<script>window.alert('Coudn't upload Pass Book');</script>";
return false;
}
}
return true;
}
function PassBook_check(){
if ($_FILES["passBook"]["error"] !== UPLOAD_ERR_OK ) {
switch ($_FILES["passBook"]["error"]) {
case UPLOAD_ERR_PARTIAL:
echo"<script>window.alert('File only partially uploaded');</script>";
break;
case UPLOAD_ERR_NO_FILE:
echo"<script>window.alert('No file was uploaded');</script>";
break;
case UPLOAD_ERR_EXTENSION:
echo"<script>window.alert('File upload stopped by a PHP extension');</script>";
break;
case UPLOAD_ERR_FORM_SIZE:
echo"<script>window.alert('File exceeds MAX_FILE_SIZE in the HTML form');</script>";
break;
case UPLOAD_ERR_INI_SIZE:
echo"<script>window.alert('File exceeds upload_max_filesize in php.ini');</script>";
break;
case UPLOAD_ERR_NO_TMP_DIR:
echo"<script>window.alert('Temporary folder not found');</script>";
break;
case UPLOAD_ERR_CANT_WRITE:
echo"<script>window.alert('Failed to write file');</script>";
break;
default:
echo"<script>window.alert('Unknown upload error');</script>";
break;
}
return false;
}
// Reject uploaded file larger than _X_MB
if ($_FILES["passBook"]["size"] > (1048576*5)) {
echo"<script>window.alert('max 5Mb');</script>";
return false;
}
// Use fileinfo to get the required file type
$passbook_allow = array('png', 'jpg','jpeg','pdf');
$passbook_name = $_FILES['passBook']['name'];
$ext_passBook = pathinfo($passbook_name, PATHINFO_EXTENSION);
if ( ! in_array($ext_passBook, $passbook_allow)) {
echo"<script>window.alert('Invalid file type');</script>";
return false;
}
return true;
}
//File Rename and uplode
function PassBookuplode($AppNo){
// Replace any characters not \w- in the original filename
$pathinfo_pass = pathinfo($_FILES["passBook"]["name"]);
// $base = $pathinfo_pass["passbook_name"];
// $base = preg_replace("/[^\w-]/", "_", $base);
$passbook_name = $AppNo . "." . $pathinfo_pass["extension"];
$pass_dest = __DIR__ . "/PassBook_Doc/" . $passbook_name;
if ( ! move_uploaded_file($_FILES["passBook"]["tmp_name"], $pass_dest)) {
echo"<script>window.alert('Can't move uploaded Pass Book');</script>";
}
return $pass_dest;
}
//input file check
function FileUplod_check(){
if ($_FILES["fileToUpload"]["error"] !== UPLOAD_ERR_OK ) {
switch ($_FILES["fileToUpload"]["error"]) {
case UPLOAD_ERR_PARTIAL:
echo"<script>window.alert('File only partially uploaded');</script>";
break;
case UPLOAD_ERR_NO_FILE:
echo"<script>window.alert('No file was uploaded');</script>";
break;
case UPLOAD_ERR_EXTENSION:
echo"<script>window.alert('File upload stopped by a PHP extension');</script>";
break;
case UPLOAD_ERR_FORM_SIZE:
echo"<script>window.alert('File exceeds MAX_FILE_SIZE in the HTML form');</script>";
break;
case UPLOAD_ERR_INI_SIZE:
echo"<script>window.alert('File exceeds upload_max_filesize in php.ini');</script>";
break;
case UPLOAD_ERR_NO_TMP_DIR:
echo"<script>window.alert('Temporary folder not found');</script>";
break;
case UPLOAD_ERR_CANT_WRITE:
echo"<script>window.alert('Failed to write file');</script>";
break;
default:
echo"<script>window.alert('Unknown upload error');</script>";
break;
}
return false;
}
// Reject uploaded file larger than _X_MB
if ($_FILES["fileToUpload"]["size"] > (1048576*5)) {
echo"<script>window.alert('max 5Mb');</script>";
return false;
}
// Use fileinfo to get the required file type
$allowed = array('png', 'jpg','jpeg','pdf');
$filename = $_FILES['fileToUpload']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if ( ! in_array($ext, $allowed)) {
echo"<script>window.alert('Invalid file type');</script>";
return false;
}
return true;
}
//File Rename and uplode
function uplodeFile($AppNo){
// Replace any characters not \w- in the original filename
$pathinfo = pathinfo($_FILES["fileToUpload"]["name"]);
$base = $pathinfo["filename"];
$base = preg_replace("/[^\w-]/", "_", $base);
$filename = $AppNo . "." . $pathinfo["extension"];
$destination = __DIR__ . "/Doc/" . $filename;
if ( ! move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $destination)) {
echo"<script>window.alert('Can't move uploaded file');</script>";
}
return $destination;
}
session_start();
//Captcha code
if(!isset($_REQUEST['g-recaptcha-response']) || empty($_POST['g-recaptcha-response']) )
{
$error = "Please fill the captcha.";
//you can use this error var later to show error message on your page
echo"<script>window.alert($error);</script>";
}
else if(urlencode($_REQUEST['g-recaptcha-response'])!=$_SESSION['custom_captcha'])
{
// $cresponse = ;
$error = "INVALID CAPTCHA";
//you can use this var to show error invalid captcha
echo"<script>window.alert('$error');</script>";
echo"<script>window.history.back();</script>";
}
//captcha code end
else if(!datacheck())
{
echo"<script>window.history.back();</script>";
}
//data uplode surver
else
{
$name=$_POST["name"];
$fname=$_POST["father"];
$mname=$_POST["mother"];
$pa=$_POST["permanent"];
$emailad=$_POST["email"];
$pin=$_POST["pin"];
$an=$_POST["alt"];
$mn=$_POST["mobile"];
$pr=filter_input(INPUT_POST,'program');
$rn=$_POST["roll"];
$en=$_POST["enroll"];
$ren=$_POST["receipt"];
$d=$_POST["date"];
$a=$_POST["amount"];
$dos=date("Y/m/d");
date_default_timezone_set("Asia/Kolkata");
$time=date("h:i:s a");
//insertion query
$sql="INSERT INTO IIPS (Name,Fathers_Name,Mothers_Name,PostalAddress,Email,
Pincode,AltNo,MobileNo,CourseEnrolled,ClassRollNo,EnrollmentNo,
ReceiptNo,Date_Receipt,Amount,Date_of_sub,Time_of_sub)
values ('$name','$fname','$mname','$pa','$emailad',$pin,$an,$mn,'$pr','$rn','$en',
'$ren','$d',$a,'$dos','$time');";
$result=$conn->query($sql);
if($result)
{
echo"<script>window.alert('Data stored successfully');</script>";
$appquery="SELECT Application_ID from iips where Date_of_sub = '$dos' and Time_of_sub = '$time';";
$appid=$conn->query($appquery);
while($row=$appid->fetch_assoc())
{
$id=$row["Application_ID"];
echo"<script>window.alert('Your Application ID is: $id . Kindly keep it safe for further usage!!!!');</script>";
}
//File uplode at Doc folder and address of file insertion in data base
$FileAdd_=uplodeFile($id);
$File = "UPDATE iips set ReceiptFile='$FileAdd_' where Application_ID=$id;";
$insertAdd = $conn->query($File);
if($_POST["sbi"] == "Yes"){
$accNo = $_POST["acc_no"];
$ifsc = $_POST["ifsc"];
//Pass Book uplode at PassBook_Doc folder and address of file insertion in data base
$passbook_add=PassBookuplode($id);
$sbi_ac = "UPDATE iips set AccountNo='$accNo' where Application_ID=$id;";
$insertsbi_ac = $conn->query($sbi_ac);
$sbi_ifsc = "UPDATE iips set IFSC='$ifsc' where Application_ID=$id;";
$insertsbi_ifsc = $conn->query($sbi_ifsc);
$sbi_pass = "UPDATE iips set Passbook='$passbook_add' where Application_ID=$id;";
$insertsbi_pass = $conn->query($sbi_pass);
}
//calling php code to send confirmation of registration via Email
include "Confirmation_email.php";
echo"<script>window.alert('A confirmation mail has been sent to you on email !!!');window.history.back();</script>";
}
else
{
echo"$conn->error";
}
}