-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.php
More file actions
110 lines (102 loc) · 2.88 KB
/
function.php
File metadata and controls
110 lines (102 loc) · 2.88 KB
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
<?php
function password_encrypt($password){
$hash_format = "$2y$10$";
$salt_length = 22;
$salt = generate_salt($salt_length);
$format_and_salt = $hash_format . $salt;
$hash = crypt($password, $format_and_salt);
return $hash;
}
function generate_salt($length){
$unique_random_string = md5(uniqid(mt_rand(), true));
$base64_string = base64_encode($unique_random_string);
$modified_base64_string = str_replace('+', '-', $base64_string);
$salt = substr($modified_base64_string, 0, $length);
return $salt;
}
function password_check($password, $existing_hash){
$hash = crypt($password, $existing_hash);
if($hash === $existing_hash){
return true;
}
else{
return false;
}
}
function find_admin($username, $password, $connect){
$sql = "SELECT * FROM admin WHERE username='$username' LIMIT 1";
$result = $connect->query($sql);
$admin = $result->fetch_assoc();
if(password_check($password, $admin["password"])){
return true;
}
else{
return false;
}
}
function find_client($username, $password, $connect){
$sql = "SELECT * FROM client WHERE username='$username' LIMIT 1";
$result = $connect->query($sql);
$employee = $result->fetch_assoc();
if(password_check($password, $employee["password"])){
return true;
}
else{
return false;
}
}
function find_employee($username, $password, $connect){
$sql = "SELECT * FROM employee WHERE username='$username' LIMIT 1";
$result = $connect->query($sql);
$admin = $result->fetch_assoc();
if(password_check($password, $admin["password"])){
return true;
}
else{
return false;
}
}
function get_latitude_value($lati){
$p = str_split($lati);
$deg = "" . $p[0] . $p[1];
$redeg = intval($deg);
$sec = "";
$i=1;
for($i=2; $i < strlen($lati); $i++) {
$sec .= $p[$i];
}
$resec = floatval($sec);
$secval = $resec/60;
$latival = $redeg+$secval;
return $latival;
}
function get_longtitude_value($longti){
$p = str_split($longti);
$deg = "" . $p[1].$p[2];
$redeg = intval($deg);
$sec = "";
for($i=3; $i < strlen($longti); $i++) {
$sec .= $p[$i];
}
$resec = floatval($sec);
$secval = $resec/60;
$longtival = $redeg+$secval;
return $longtival;
}
function arrayreturns($lat, $long, $client, $connect)
{
$result = array();
for ($i=0; $i < count($client) ; $i++) { # code...
$id = $client[$i];
$query = $connect->query("SELECT lat, longti FROM client WHERE id='$id'");
$row = $query->fetch_assoc();
$clientlat = ($lat - $row['lat']) * ($lat - $row['lat']);
$clientlong = ($long - $row['longti']) * ($long - $row['longti']);
$clientdistance = $clientlong + $clientlat;
$result[$id] = $clientdistance;
//echo $id . " distance from savar: " . $clientdistance . "<br>";
}
asort($result);
return $result;
}
?>