-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions.php
91 lines (71 loc) · 2.89 KB
/
functions.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
<?php
function findTripInfo($users_id) {
if(!isset($_SESSION['users_units']) || (isset($_SESSION['users_units']) && $_SESSION['users_units'] == "US")) {
$speed_units = "mph";
$distance_units = "miles";
$miles_multiplier = 0.621371;
}
else {
$speed_units = "km/h";
$distance_units = "km";
$miles_multiplier = 1;
}
$leaflogs_query_sql = "select leaflogs_timestamp,unix_timestamp(leaflogs_timestamp) as unixtime from leaflogs where leaflogs_ignore = 0 and leaflogs_user_id = " . $users_id . " order by leaflogs_timestamp asc";
$leaflogs_query = mysql_query($leaflogs_query_sql);
$previousTimestampUnix = 0;
$previousTimestampMysql = "";
$theStart = array();
$theEnd = array();
$recordNumber = 0;
$recordsInSet = array();
$recordsInSetCounter = 0;
while($leaflogs = mysql_fetch_array($leaflogs_query)) {
//echo $leaflogs['leaflogs_timestamp'] . " is " . $leaflogs['unixtime'] . "<BR>";
/* more than a 10 min gap... */
if(($leaflogs['unixtime'] - $previousTimestampUnix) > $_SESSION['users_trip_delimiter'] * 60) {
//echo "End! " . $leaflogs['unixtime'] . " minus " . $previousTimestampUnix . "<BR>";
$theStart[] = $leaflogs['leaflogs_timestamp'];
if($recordNumber > 0) {
$theEnd[] = $previousTimestampMysql;
$recordsInSet[] = $recordsInSetCounter;
$recordsInSetCounter = 0;
}
}
$previousTimestampUnix = $leaflogs['unixtime'];
$previousTimestampMysql = $leaflogs['leaflogs_timestamp'];
$recordNumber ++;
$recordsInSetCounter ++;
}
/* add in the last timeperiod read */
$theEnd[] = $previousTimestampMysql;
$recordsInSet[] = $recordsInSetCounter;
$resultsArray = array();
for($n = 0; $n < count($theStart); $n ++) {
//echo "start: " . $theStart[$n] . " end: " . $theEnd[$n] . "( " . $recordsInSet[$n] . " records)<BR>";
$resultsArray[] = array("start"=>$theStart[$n],
"end"=>$theEnd[$n],
"records"=>$recordsInSet[$n]);
}
return($resultsArray);
}
function generateRandomString($length = 10) {
$characters = '23456789abcdefghijkmnpqrstuvwxyz';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
function sendWelcomeEmail($emailAddress, $password) {
$theEmail = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/WelcomeEmail.template');
$theEmail = str_replace("%%email%%", $emailAddress, $theEmail);
$theEmail = str_replace("%%password%%", $password, $theEmail);
$to = $emailAddress;
$subject = 'Welcome to LeafLogger.com';
$headers = 'From: [email protected]' . "\r\n" .
'bcc: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $theEmail, $headers);
}
?>