forked from praem90/Resume-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
474 lines (421 loc) · 22 KB
/
index.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<?php
session_start();
include_once 'inc/function.find_date.php';
include_once 'inc/docx.php';
include_once 'inc/PdfParser.php';
// include_once 'inc/PdfParser/Parser.php';
include_once 'inc/class.php';
$functions = new functions();
$sql = 'select firstname,email,dob,mobile,city as place,filename,lastLoginDate from rms_user as u, rms_resume_details as d where u.userid = d.userid';
$res = $functions->query($sql);
$skills_arr = [];
if ($res) {
while ($row = mysqli_fetch_assoc($res)) {
$resume_details[$row['filename']] = $row;
}
} else {
echo $functions->error();
}
function reArrayFiles(&$file_post)
{
$file_ary = [];
$file_count = count($file_post['name']);
$file_keys = array_keys($file_post);
for ($i = 0; $i < $file_count; $i++) {
foreach ($file_keys as $key) {
$file_ary[$i][$key] = $file_post[$key][$i];
}
}
return $file_ary;
}
if (isset($_POST) && isset($_POST['Do'])) {
$target_dir = 'resumes/';
if (!is_dir($target_dir)) {
mkdir('resumes');
}
$glob = glob('resumes/*.*');
$glob = sprintf('%02d', count($glob) + 1);
$files = reArrayFiles($_FILES['offer-main']);
$details = [];
foreach ($files as $fileToUpload) {
// $fileToUpload = $_FILES['offer-main'];
$do = 'offer-main-form';
$uploadOk = 1;
$imageFileType = pathinfo($fileToUpload['name'], PATHINFO_EXTENSION);
$target_file = $target_dir.$glob.'-'.$fileToUpload['name'];
$check = getimagesize($fileToUpload['tmp_name']);
if ($fileToUpload['size'] > 500000) {
$msg = 'Sorry, your file is too large.';
$uploadOk = 0;
}
// Allow certain file formats
if ($imageFileType != 'docx' && $imageFileType != 'doc' && $imageFileType != 'xlsx' && $imageFileType != 'pptx' && $imageFileType != 'pdf') {
$msg = 'Sorry, invalid file type.';
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
// $msg = "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($fileToUpload['tmp_name'], $target_file)) {
$msg = 'The Resume has been uploaded.';
if ($imageFileType == 'pdf') {
$pdfObj = new PdfParser();
$resumeText = $pdfObj->parseFile($target_file);
// $resumeText = $pdfObj->getText();
} else {
$docObj = new DocxConversion($target_file);
$resumeText = $docObj->convertToText();
}
$sql = 'select city from rms_cities';
$res = $functions->query($sql);
$places = [];
if ($res) {
while ($row = mysqli_fetch_assoc($res)) {
$places[] = $row['city'];
}
} else {
die($functions->error());
}
$places_regx = strtolower('/'.implode('|', $places).'/');
$fileInfo = explode(PHP_EOL, $resumeText);
$records = [];
foreach ($fileInfo as $row) {
// if($row == '') continue;
// $parts = explode(',12', $row);
$parts = preg_split('/(?<=[.?!])\s+(?=[a-z])/i', $row);
foreach ($parts as $part) {
if ($part == '') {
continue;
}
// echo $part.'<br><br>';
$part = strtolower($part);
// *************** EMAIL **************
if (strpos($part, '@') || strpos($part, 'mail')) {
$pattern = '/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i';
preg_match_all($pattern, $part, $matches);
foreach ($matches[0] as $match) {
$records['email'][] = $match;
}
}
// *************** DOB **************
if (preg_match('/dob|d.o.b|date of birth/', $part)) {
$dob = preg_split('/:|-/', $part);
foreach ($dob as $db) {
$date = date_parse($db);
if ($date['error_count'] == 0) {
$records['dob'][] = $date['year'].'-'.$date['month'].'-'.$date['day'];
}
}
}
$date = @find_date($part);
if ($date) {
$records['dob'][] = $date['year'].'-'.$date['month'].'-'.$date['day'];
}
// }
$p = '{.*?(\d\d?)[\\/\.\-]([\d]{2})[\\/\.\-]([\d]{4}).*}';
if (preg_match($p, $part)) {
$date = preg_replace($p, '$3-$2-$1', $part);
$dd = new \DateTime($date);
$records['dob'][] = $dd->format('Y-m-d');
}
// *************** MOBILE **************
preg_match_all('/\d{10}/', $part, $matches);
if (count($matches[0])) {
foreach ($matches[0] as $mob) {
$records['mobile'][] = $mob;
}
}
preg_match_all('/\d{12}/', $part, $matches);
if (count($matches[0])) {
foreach ($matches[0] as $mob) {
$records['mobile'][] = $mob;
}
}
preg_match_all('/(\d{5}) (\d{5})/', $part, $matches);
if (count($matches[0])) {
foreach ($matches[0] as $mob) {
$records['mobile'][] = $mob;
}
}
// *************** SKILLS **************
preg_match_all('/production|sales|call center|Accounts|marketting|tele communication|engineer|software engineering|software engineer|manufacturing|office administration|human resource|admin|secretarial|customer service|call center|finance account/', $part, $matches);
if (count($matches[0])) {
foreach ($matches[0] as $skill) {
$records['skills'][] = $skill;
}
}
// *************** PLACE **************
preg_match_all($places_regx, $part, $matches);
if (count($matches[0])) {
foreach ($matches[0] as $skill) {
$records['place'][] = ucwords($skill);
}
}
// *************** NAME **fe************
if (isset($records['email'])) {
foreach ($records['email'] as $email) {
$e = explode('@', $email);
$records['name'][] = $e[0];
// code...
}
}
}
}
foreach ($records as $key => $value) {
$records[$key] = array_unique($value);
}
$records['text'] = $resumeText;
$records['filename'] = $target_file;
$details[] = $records;
} else {
$msg = 'Sorry, there was an error uploading your file.';
break;
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include_once 'inc/head.php'; ?>
</head>
<body>
<div id="wrapper">
<?php include_once 'inc/nav.php'; ?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">Resume Parser</h2>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
<div class="col-md-12 ">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Upload your resume </h3>
</div>
<div class="panel-body">
<ul class="nav nav-tabs">
<li class="active"><a href="#mainOffer" data-toggle="tab">Upload</a></li>
<li><a href="#Resumes" data-toggle="tab">Resumes</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane fade in active" id="mainOffer">
<h3></h3>
<?php if (!isset($resumeText)) {
?>
<div class="col-md-6 col-sm-offset-3">
<form id="offer-main-form" enctype="multipart/form-data" method="post">
<div class="alert alert-info alert-dismissable ">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<p></p>
</div>
<div class="progress hidden">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
<span class="sr-only">45% Complete</span>
</div>
</div>
<div class="form-group text-center">
<input type="file" class="hidden" name="offer-main[]" multiple id="offer-main">
<input type="hidden" name="Do" value="ChangeOfferMain">
<input type="hidden" name="table" value="offer">
<div class="btn btn-primary" onclick="$('#offer-main').click()" id="btn-offer-main">Upload Resume</div>
<span id="info-offer-main"></span>
</div>
</form>
</div>
<?php
} else {
?>
<div class="col-sm-6 col-sm-offset-3">
<?php foreach ($details as $key => $records) {
?>
<h1></h1>
<h3>
<?php $fname = explode('/', $records['filename']);
echo end($fname) ?>
</h3>
<form action="inc/do.php" id="Records<?php echo $key ?>" name="Records<?php echo $key ?>" method="post">
<div class="alert alert-info alert-dismissable ">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<p></p>
</div>
<div class="form-group">
<label for="name">Name</label>
<select id="name" class="form-control">
<?php
if (isset($records['name'])) {
foreach ($records['name'] as $value) {
?><option value="<?php echo $value ?>"><?php echo $value ?></option><?php
}
}
?>
<option value="0">Enter name</option>
</select>
<input class="form-control hidden" name="name" id="name" type="text" value="" >
<input type="hidden" name="filename" id="filename" value="<?php echo end($fname) ?>" >
</div>
<div class="form-group">
<label for="email">Email</label>
<select id="email" class="form-control">
<?php
if (isset($records['email'])) {
foreach ($records['email'] as $value) {
?><option value="<?php echo $value ?>"><?php echo $value ?></option><?php
}
}
?>
<option value="0">Enter Email</option>
</select>
<input class="form-control hidden" name="email" id="email" type="text" value="" >
</div>
<div class="form-group">
<label for="mobile">Mobile No</label>
<select id="mobile" class="form-control">
<?php
if (isset($records['mobile'])) {
foreach ($records['mobile'] as $value) {
?><option value="<?php echo $value ?>"><?php echo $value ?></option><?php
}
}
?>
<option value="0">Enter mobile no</option>
</select>
<input class="form-control hidden" name="mobile" id="mobile" type="text" value="" >
</div>
<div class="form-group">
<label for="place">Place</label>
<select id="place" class="form-control">
<?php
if (isset($records['place'])) {
foreach ($records['place'] as $value) {
?><option value="<?php echo $value ?>"><?php echo $value ?></option><?php
}
}
?>
<option value="0">Enter place</option>
</select>
<input class="form-control hidden" name="place" id="place" type="text" value="" >
</div>
<div class="form-group">
<label for="skill">Skills</label>
<select id="skill" class="form-control">
<?php
if (isset($records['skill'])) {
foreach ($records['skill'] as $value) {
?><option value="<?php echo $value ?>"><?php echo $value ?></option><?php
}
}
?>
<option value="0">Enter skill</option>
</select>
<input class="form-control hidden" name="skill" id="skill" type="text" value="" >
</div>
<div class="form-group">
<label for="dob">DOB</label>
<select id="dob" class="form-control">
<?php
if (isset($records['dob'])) {
foreach ($records['dob'] as $value) {
?><option value="<?php echo $value ?>"><?php echo $value ?></option><?php
}
}
?>
<option value="0">Enter dob</option>
</select>
<input placeholder="DOB" class="form-control hidden" name="dob" id="dob" type="text" value="" >
</div>
<div class="form-group">
<label for="resumeText">Resume Text</label>
<textarea class="form-control" name="resumeText" id="resumeText">
<?php echo $records['text'];
?>
</textarea>
</div>
<button class="btn btn-primary" type="submit">Save</button>
</form>
<h1></h1>
<?php
}
?>
</div>
<?php
} ?>
</div>
<div class="tab-pane fade in" id="Resumes">
<h1></h1>
<div class="col-sm-12">
<table class="table table-bordered" id="resumeList">
<thead>
<tr>
<th>S.No</th>
<th>File Name</th>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Place</th>
<th>DOB</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
foreach ($resume_details as $resume_detail) {
?><tr><?php
?><td><?php echo $i;
$i++;
?></td><?php
?><td><a href="<?php echo 'resumes/'.$resume_detail['filename'] ?>" target="_blank"><?php echo $resume_detail['filename'];
?></a></td><?php
?><td><?php echo $resume_detail['firstname'];
?></td><?php
?><td><?php echo $resume_detail['email'];
?></td><?php
?><td><?php echo $resume_detail['mobile'];
?></td><?php
?><td><?php echo $resume_detail['place'];
?></td><?php
?><td><?php echo $resume_detail['dob'];
?></td><?php
?><td><?php echo $resume_detail['lastLoginDate'];
?></td><?php
?></tr><?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /.row -->
</div>
</div>
<!-- /#page-wrapper -->
<?php include_once 'inc/footer.php'; ?>
</div>
<!-- /#wrapper -->
<?php include_once 'inc/foot.php'; ?>
<script>
$(function () {
$('#offer-main').on('change',function () {
$('#offer-main-form').submit()
})
$('#resumeList').dataTable()
<?php if (isset($msg)) {
?>
$('#<?php echo $do ?> .alert').show(300).delay(3000).hide(200).find('p').text("<?php echo $msg ?>")
<?php
} ?>
})
</script>
</body>
</html>