· 5 years ago · Feb 01, 2020, 04:28 PM
1<?php
2#specific functionality
3function secure($string, $action) {
4 $secret_key = 'test key';
5 $secret_iv = 'test key';
6
7 $output = false;
8 $encrypt_method = "AES-256-CBC";
9 $key = hash( 'sha256', $secret_key );
10 $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
11 if( $action == 'e' ) {
12 $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
13 }
14 else if( $action == 'd' ){
15 $output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
16 }
17 return $output;
18}
19function redirect($pageLink, $type){
20 if($type == 'php') {
21 header("location: $pageLink");
22 }
23 else if($type == 'java'){
24 echo '<script type="text/javascript">';
25 echo 'window.location.href="'.$pageLink.'";';
26 echo '</script>';
27 }
28 else if($type == 'meta'){
29 echo "<meta http-equiv='refresh' content='".$pageLink."'>";
30 }
31}
32function refresh(){
33 header("location: ".$_SERVER['PHP_SELF']);
34}
35function wordInArray($word, $array, $offset=0) {
36 if(!is_array($array)) $array = array($array);
37 foreach($array as $query) {
38 if(strpos($word, $query, $offset) !== false){
39 return true;
40 }
41 }
42 return false;
43}
44function idRoleNo(){
45 global $myData;
46 if ($myData['role'] == "normal") {
47 return 1;
48 }
49 elseif ($myData['role'] == "premium") {
50 return 2;
51 }
52 elseif ($myData['role'] == "agent") {
53 return 3;
54 }
55 elseif ($myData['role'] == "institute") {
56 return 4;
57 }
58 elseif ($myData['role'] == "c.manager") {
59 return 5;
60 }
61 elseif ($myData['role'] == "s.manager") {
62 return 6;
63 }
64 elseif ($myData['role'] == "admin") {
65 return 7;
66 }
67 elseif ($myData['role'] == "superadmin") {
68 return 8;
69 }
70 elseif ($myData['role'] == "arbn") {
71 return 9;
72 }
73 else{
74 return 0;
75 }
76}
77function accessLevel($no){
78 if (idRoleNo()) {
79 if (idRoleNo() >= $no) {
80 return true;
81 }
82 else{
83 return false;
84 }
85 }
86 else{
87 return false;
88 }
89}
90function accessLevelRedirect($no){
91 global $homeSite;
92 if (accessLevel($no)) {
93 return true;
94 }
95 else{
96 header("location: index.php");
97 }
98}
99function roleNo($role){
100 global $myData;
101 if ($role == "normal") {
102 return 1;
103 }
104 elseif ($role == "premium") {
105 return 2;
106 }
107 elseif ($role == "agent") {
108 return 3;
109 }
110 elseif ($role == "institute") {
111 return 4;
112 }
113 elseif ($role == "c.manager") {
114 return 5;
115 }
116 elseif ($role == "s.manager") {
117 return 6;
118 }
119 elseif ($role == "admin") {
120 return 7;
121 }
122 elseif ($role == "superadmin") {
123 return 8;
124 }
125 elseif ($role == "arbn") {
126 return 9;
127 }
128 else{
129 return 0;
130 }
131}
132#retrive common basic data
133function getCookie(){
134 if (empty($_SESSION['accessCode'])) {
135 if (!empty($_COOKIE['accessCode'])) {
136 $_SESSION['accessCode'] = $_COOKIE['accessCode'];
137 }
138 }
139 return true;
140}
141function validLogin(){
142 if (!empty($_SESSION['accessCode'])) {
143 global $con, $myData;
144 $accessCode = $_SESSION['accessCode'];
145 $edata = secure($accessCode, 'd');
146 $ddata = explode("-@rbn-",$edata);
147 $uid = $ddata[0];
148 $fbid = $ddata[1];
149 $database = $con->prepare("SELECT * FROM userdb WHERE aid = ? AND fbid = ?");
150 $database->bind_param("is", $uid, $fbid);
151 $database->execute();
152 $databaseResult = $database->get_result();
153 if($databaseResult->num_rows>0){
154 while ($databaseResultRow = $databaseResult->fetch_assoc()) {
155 $myData = $databaseResultRow;
156 }
157 $database->close();
158 return true;
159 }
160 else{
161 $database->close();
162 logout();
163 return false;
164 }
165 }
166 else{
167 return false;
168 }
169}
170function myIssueOfficeData(){
171 global $con, $myIssueOfficeData, $myData;
172 $database = $con->prepare("SELECT * FROM locdb WHERE aid = ?");
173 $database->bind_param("i", $myData['issueOffice']);
174 $database->execute();
175 $databaseResult = $database->get_result();
176 while ($databaseResultRow = $databaseResult->fetch_assoc()) {
177 $myIssueOfficeData = $databaseResultRow;
178 }
179 $database->close();
180 return true;
181}
182function logout(){
183 unset($_COOKIE['accessCode']);
184 setcookie("accessCode", "", time() - 3600);
185 session_destroy();
186 session_unset();
187 return true;
188}
189function appData(){
190 global $con, $appData;
191 $database = $con->prepare("SELECT * FROM appdb WHERE aid = 1");
192 $database->execute();
193 $databaseResult = $database->get_result();
194 while ($databaseResultRow = $databaseResult->fetch_assoc()) {
195 $appData = $databaseResultRow;
196 }
197 $database->close();
198 return true;
199}
200function publicData(){
201 global $con, $publicData;
202 $database = $con->prepare("SELECT * FROM publicdb WHERE aid = 1");
203 $database->execute();
204 $databaseResult = $database->get_result();
205 while ($databaseResultRow = $databaseResult->fetch_assoc()) {
206 $publicData = $databaseResultRow;
207 }
208 $database->close();
209 return true;
210}
211function alertNotice(){
212 global $publicData, $modalTitle, $modalMessage;
213 $modalTitle = "Notice";
214 if (!isset($_SESSION['noticed'])) {
215 $modalMessage = $publicData['notice'];
216 $_SESSION['noticed'] = $publicData['notice'];
217 return true;
218 }
219 else{
220 if ($_SESSION['noticed'] != $publicData['notice']) {
221 unset($_SESSION["noticed"]);
222 $modalMessage = $publicData['notice'];
223 $_SESSION['noticed'] = $publicData['notice'];
224 return true;
225 }
226 else{
227 return false;
228 }
229 }
230 return true;
231}
232#specific data from passed data
233function idData($eid){
234 global $con, $idData;
235 $did = secure($eid, 'd');
236 $database = $con->prepare("SELECT * FROM userdb WHERE aid = ?");
237 $database->bind_param("i", $did);
238 $database->execute();
239 $databaseResult = $database->get_result();
240 if ($databaseResult->num_rows>0) {
241 while ($databaseResultRow = $databaseResult->fetch_assoc()) {
242 $idData = $databaseResultRow;
243 }
244 $database->close();
245 return true;
246 }
247 else{
248 $database->close();
249 return false;
250 }
251}
252function dcData($eid){
253 global $con, $dcData;
254 $did = secure($eid, 'd');
255 $database = $con->prepare("SELECT * FROM dcdb WHERE aid = ?");
256 $database->bind_param("i", $did);
257 $database->execute();
258 $databaseResult = $database->get_result();
259 if ($databaseResult->num_rows>0) {
260 while ($databaseResultRow = $databaseResult->fetch_assoc()) {
261 $dcData = $databaseResultRow;
262 }
263 $database->close();
264 return true;
265 }
266 else{
267 $database->close();
268 return false;
269 }
270}
271function formData($eid){
272 global $con, $formData;
273 $did = secure($eid, 'd');
274 $database = $con->prepare("SELECT * FROM allformdb WHERE aid = ?");
275 $database->bind_param("i", $did);
276 $database->execute();
277 $databaseResult = $database->get_result();
278 if ($databaseResult->num_rows>0) {
279 while ($databaseResultRow = $databaseResult->fetch_assoc()) {
280 $formData = $databaseResultRow;
281 }
282 $database->close();
283 return true;
284 }
285 else{
286 $database->close();
287 return false;
288 }
289}
290function fbidData($efbid){
291 global $con, $fbidData;
292 $dfbid = secure($efbid, 'd');
293 $database = $con->prepare("SELECT * FROM userdb WHERE fbid = ?");
294 $database->bind_param("i", $dfbid);
295 $database->execute();
296 $databaseResult = $database->get_result();
297 if ($databaseResult->num_rows>0) {
298 while ($databaseResultRow = $databaseResult->fetch_assoc()) {
299 $fbidData = $databaseResultRow;
300 }
301 $database->close();
302 return true;
303 }
304 else{
305 $database->close();
306 return false;
307 }
308}
309function idIssueOfficeData($aid){
310 global $con, $idIssueOfficeData;
311 $database = $con->prepare("SELECT * FROM locdb WHERE aid = ?");
312 $database->bind_param("i", $aid);
313 $database->execute();
314 $databaseResult = $database->get_result();
315 while ($databaseResultRow = $databaseResult->fetch_assoc()) {
316 $idIssueOfficeData = $databaseResultRow;
317 }
318 $database->close();
319 return true;
320}
321function isBlockedData($data){
322 global $con;
323 $database = $con->prepare("SELECT aid FROM blockdb WHERE data = ?");
324 $database->bind_param("s", $data);
325 $database->execute();
326 $databaseResult = $database->get_result();
327 if($databaseResult->num_rows>0){
328 return true;
329 }
330 else{
331 return false;
332 }
333}
334function dotmDataViewPermission($data){
335 global $con, $publicData;
336 if ($publicData['checkDotmData'] == 1) {
337 if (idRoleNo()) {
338 if (accessLevel(2)) {
339 return true;
340 }
341 else{
342 $database = $con->prepare("SELECT aid FROM userdb WHERE appid = ? OR licenseNo = ? OR referenceNo = ?");
343 $database->bind_param("sss", $data, $data, $data);
344 $database->execute();
345 $databaseResult = $database->get_result();
346 if($databaseResult->num_rows>0){
347 return true;
348 }
349 else{
350 return false;
351 }
352 }
353 }
354 else{
355 $database = $con->prepare("SELECT aid FROM userdb WHERE appid = ? OR licenseNo = ? OR referenceNo = ?");
356 $database->bind_param("sss", $data, $data, $data);
357 $database->execute();
358 $databaseResult = $database->get_result();
359 if($databaseResult->num_rows>0){
360 return true;
361 }
362 else{
363 return false;
364 }
365 }
366 }
367 else{
368 return true;
369 }
370}
371?>