generated from VERO-Digital-Solutions/web-portal-task
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
205 lines (182 loc) · 5.8 KB
/
search.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
<?php
include 'global.functions.php';
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_POST['search_term'])){
$search_term = trim($_POST['search_term']);
if(!empty($search_term)){
// Autorization
$access_token = autorize();
if($access_token !== false){
// Get Data
$result = get_data($access_token);
if($result){
// Search
$filtered_data = search($search_term, $result);
}
}
}
else{
$filtered_data = false;
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Index</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script>
var search_term = '<?php echo isset($search_term) ? $search_term : ''; ?>',
timer = null,
progress = 100;
$(document).ready(function(){
initialize_timer();
$('#uploadModal').on('hidden.bs.modal', function(e){
$('#file_select_form')[0].reset();
$('#image_preview').attr('src', '').width(0).height(0);
});
$('#formFile').on('change', function(){
read_content(this);
});
});
function initialize_timer(){
if(timer === null){
timer = window.setInterval(function(){
decrease_time();
}, 3600000);
}
}
function decrease_time(){
if(progress > 0){
progress -= 1.66;
}
else{
clearInterval(timer);
timer = null;
send_search();
}
if(progress < 0){
progress = 0;
}
$('.progress-bar').css('width', progress + '%').attr('aria-valuenow', progress);
}
function send_search(){
$.ajax({
url: 'ajax.php',
method: 'POST',
dataType: 'json',
data: {
term: search_term
},
beforeSend: function(){
progress = 100;
$('.progress-bar').css('width', progress + '%').attr('aria-valuenow', progress);
},
success: function(data){
if(data !== undefined){
var html = '';
$.each(data, function(key, val){
html += '<tr>';
html += '<th scope="row" class="text-nowrap">' + val.task + '</th>';
html += '<td class="text-nowrap">' + val.title + '</td>';
html += '<td>' + val.description + '</td>';
html += '<td style="background-color: ' + val.colorCode + '"> </td>';
html += '</tr>';
});
$('#result_table tbody').empty().html(html);
html = '';
}
initialize_timer();
},
error: function(){
}
});
}
function read_content(input){
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#image_preview').attr('src', e.target.result).width(150).height(200);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
</head>
<body>
<div class="container py-5">
<form method="POST" action="search.php">
<div class="d-flex justify-content-center align-items-start">
<input type="text" name="search_term" class="form-control w-50 me-3" value="<?php echo isset($search_term) ? $search_term : ''; ?>" id="search_term" autocomplete="off">
<button type="submit" class="btn btn-primary mb-3 me-3">Search</button>
<a href="index.php" class="btn btn-secondary mb-3">Show All</a>
</div>
</form>
<div class="d-flex justify-content-center">
<div class="progress w-75">
<div class="progress-bar" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<table class="table" id="result_table">
<thead>
<tr>
<th scope="col">task</th>
<th scope="col">title</th>
<th scope="col">description</th>
<th scope="col" width="1%">colorCode</th>
</tr>
</thead>
<tbody>
<?php
if(isset($filtered_data) && !empty($filtered_data)){
foreach($filtered_data as $key => $val){
?>
<tr>
<th scope="row" class="text-nowrap"><?php echo $val->task; ?></th>
<td class="text-nowrap"><?php echo $val->title; ?></td>
<td><?php echo $val->description; ?></td>
<td style="background-color: <?php echo $val->colorCode; ?>"> </td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<div class="d-flex justify-content-center">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadModal">
Show Modal
</button>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="uploadModal" tabindex="-1" aria-labelledby="uploadModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="uploadModalLabel">Modal title</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<form id="file_select_form">
<label for="formFile" class="form-label">Select any image</label>
<input class="form-control" type="file" id="formFile" accept="image/gif, image/jpeg, image/png">
<img id="image_preview" />
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>