-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfitlogfunc.php
executable file
·167 lines (139 loc) · 4.15 KB
/
fitlogfunc.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
<?php
function swimpace( $time, $distance )
{
//$time_sec = convert_time_seconds( $time );
// Return swim pace
return round( ( convert_seconds_minutes( $time ) / ($distance / 100 ) ), 2 );
}
function bikepace( $time, $distance )
{
//$time_sec = convert_time_seconds( $time );
// Return bike pace
return round( ( ($distance / ( ( convert_seconds_minutes( $time ) ) / 60)) ), 2 );
}
function runpace( $time, $distance )
{
//$time_sec = convert_time_seconds( $time );
// Return run pace
return round( ( ( convert_seconds_minutes( $time ) / $distance) ), 2 );
}
function convert_time_seconds( $time )
{
$seconds = explode( ":", $time );
// return the total in seconds
return ( ( $seconds[0] * 3600) + ( $seconds[1] * 60 ) + ( $seconds[2] ) );
}
function format_time( $total )
{
// Convert total from seconds to full time again
$_total_time["hrs"] = floor(($total / 3600));
$_total_time["mins"] = floor(($total - ($_total_time["hrs"] * 3600)) / 60);
$_total_time["secs"] = floor(($total - ($_total_time["hrs"] * 3600) - ($_total_time["mins"] * 60)));
// Prefix with 0s where necessary
if (strlen($_total_time["hrs"]) == 1)
$_total_time["hrs"] = "0" . $_total_time["hrs"];
if (strlen($_total_time["mins"]) == 1)
$_total_time["mins"] = "0" . $_total_time["mins"];
if (strlen($_total_time["secs"]) == 1)
$_total_time["secs"] = "0" . $_total_time["secs"];
// Format total time
$total_time = $_total_time["hrs"] . ":" . $_total_time["mins"] . ":" . $_total_time["secs"];
return ( $total_time );
}
function format_date( $old_date )
{
$date_array = explode( "-", $old_date);
$year = $date_array[0];
$month = $date_array[1];
$day = $date_array[2];
// create an integer "date" for use with the date() php function.
$new_date = mktime( 0, 0, 0, $month, $day, $year );
return ( $new_date );
}
function convert_seconds_minutes( $seconds )
{
$_seconds = floatval( $seconds );
$minutes = $_seconds / 60;
return $minutes;
}
function get_prevMonth( $month )
{
// Return the numerical version of the previous month
return (intval($month) - 1);
}
function get_nextMonth( $month )
{
// Return the numerical version of the next month
return (intval($month) + 1);
}
function validate_email( $emailaddy )
{
// Check syntax
$validEmailExpr = "^[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$%&_-])*" .
"@[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$%&_-])*$";
// Validate the email
if( empty( $emailaddy ) )
{
echo "The email field can not be blank.";
return false;
}
elseif ( !eregi( $validEmailExpr, $emailaddy ) )
{
echo "The email must be in the name@domain format.";
return false;
}
elseif ( strlen( $emailaddy ) > 50 )
{
echo "The email address can not exceed 50 characters.";
return false;
}
elseif ( function_exists("getmxrr") && function_exists("gethostbyname") )
{
// Extract the domain of the email address
$maildomain = substr( strstr($emailaddy, '@'), 1 );
if( !( getmxrr( $maildomain, $temp) ||
gethostbyname( $maildomain ) != $maildomain ) )
{
echo "The domain does not appear to exist.";
return false;
}
}
// If we get here, we assume the email address is correct.
return true;
}
function getUserID( $connection )
{
//See if there is a logged in users and if so, retrieve it's user_id
session_start();
$query = "SELECT user_id FROM users WHERE user_name='{$_SESSION["loggedinUserName"]}'";
$result = @ mysql_query( $query, $connection );
//If we only have one row then we are in good shape.
if( mysql_num_rows( $result ) != 1)
return 0;
else
{
$row = mysql_fetch_array( $result );
return $row["user_id"];
}
//If we reach here, return zero for an error!
return 0;
}
function getUserFirstName( $connection, $userID )
{
// First let's grab the user's first name if they set it up in settings.
$query = "SELECT FirstName from user_settings WHERE user_id=" . $userID;
$result = @ mysql_query( $query );
$row = mysql_fetch_array( $result );
if( !$result )
return FALSE;
else
return $row["FirstName"];
}
// Function used to print out information debugging messages to the screen.
function msgBox( $msg, $data )
{
echo "<script type='text/javascript'>
alert('$msg, variable= $data');
</script>";
}
?>