-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrengthworkouts.php
More file actions
170 lines (147 loc) · 5.85 KB
/
strengthworkouts.php
File metadata and controls
170 lines (147 loc) · 5.85 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
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
<?php
/* File: strengthworkouts.php
Desciption: Implementation file for the entering and editing of strength workouts.
Author: Eric A. Bonney
Date: December 18, 2009
Updated: December 31, 2009 - removed the template stuff relating to the exercise select
as it is now loaded dynamically with javascript.
*/
require_once "includes/db.inc";
require_once "HTML/Template/IT.php";
require_once "Date.php";
require_once "fitlogfunc.php";
$edit_date = $_GET["edit_date"];
$type = $_GET["type"];
// Create the template and load the correct template file.
$template = new HTML_Template_IT( "./templates" );
$template->loadTemplatefile( "strengthworkouts.tpl", true, true );
session_start();
// Get a connection to the database.
if( !($connection = @mysql_connect( $hostName, $username, $password ) ) )
die( "Could not connect to database" );
// Now that we are connected, select the correct database.
if( !mysql_select_db( $databaseName, $connection ) )
showerror();
//See if we have an authenticated user, if so, setup the appropriate message.
if( isset( $_SESSION["loggedinUserName"] ) )
{
$exerciseDescription;
$firstRun = 1;
$userID = getUserID( $connection );
$yearmoday = explode( "-", $edit_date );
// See if the users is trying to display a month other than the current month.
if( $yearmoday != NULL )
{
$display_mo = new Date();
$display_mo->setDayMonthYear( $yearmoday[2], $yearmoday[1], $yearmoday[0] );
}
else
$display_mo = new Date();
$template->setCurrentBlock( "NAVIGATION" );
$template->setVariable( "MONTH", $display_mo->format( "%A %B %e, %Y" ) );
$template->parseCurrentBlock();
// Load the category select box.
$template->setCurrentBlock( "CATEGORYSELECT" );
$query = "SELECT DISTINCT category FROM flexercise_type WHERE user_id={$userID}";
$result = @ mysql_query( $query, $connection );
while( $row = mysql_fetch_array( $result ) )
{
$template->setVariable( "CATEGORY", $row["category"] );
// Set the category box selection if any.
if( setSelectCategoryOption( $category, $row["category"], $template ) )
$template->setVariable( "SELECTED", 'selected="selected"' );
$template->parseCurrentBlock();
}
// Load the templates select box.
$template->setCurrentBlock( "TEMPLATESELECT" );
$query = "SELECT DISTINCT description FROM flexercise_templates WHERE user_id={$userID}";
$result = @ mysql_query( $query, $connection );
while( $row = mysql_fetch_array( $result ) )
{
$template->setVariable( "TEMPLATE", $row["description"] );
$template->parseCurrentBlock();
}
// Get the current days exercise_id from flstrength
$query = "SELECT * FROM flstrength WHERE user_id={$userID} AND workout_date='" . $edit_date . "'";
$result = @ mysql_query( $query, $connection );
if( mysql_num_rows( $result) > 0 )
{
$row = mysql_fetch_array( $result );
// Get the sets information from flexercises
$query = "SELECT * FROM flexercises where exercises_id={$row["exercises_id"]}";
$results = @ mysql_query( $query, $connection );
while( $rowSet = mysql_fetch_array( $results ) )
{
// If we have reached the beg of a new exercise, set the desc
if( intval($rowSet["set_number"]) == 1 && !$firstRun )
{
$template->setCurrentBlock( "WORKOUTS" );
$template->setVariable( "EXECHEADER", $exerciseDescription );
$template->parseCurrentBlock();
}
// Get the category and description of the exercise.
$query = "SELECT category, exercise FROM flexercise_type WHERE user_id={$userID} AND exercise_type_id={$rowSet["exercise_type_id"]}";
$exerciseDesc = @ mysql_query( $query, $connection );
$rowExerciseDesc = mysql_fetch_array( $exerciseDesc );
$exerciseDescription = $rowExerciseDesc["category"] . ":" . $rowExerciseDesc["exercise"];
// Populate the template with the current days workouts.
$template->setCurrentBlock( "SETS" );
$template->setVariable( "SETNUM", $rowSet["set_number"] );
$template->setVariable( "REPS", $rowSet["reps"] );
$template->setVariable( "WEIGHT", $rowSet["weight"] );
$template->parseCurrentBlock();
$firstRun=0;
}
$template->setCurrentBlock( "WORKOUTS" );
$template->setVariable( "EXECHEADER", $exerciseDescription );
$template->parseCurrentBlock();
$template->setCurrentBlock( "TIMES" );
$template->setVariable( "STARTTIME", $row["time_of_day"] );
$template->setVariable( "DURATION", $row["duration"] );
$template->parseCurrentBlock();
$template->setCurrentBlock( "NOTES" );
$template->setVariable( "STRNOTES", $row["notes"] );
$template->parseCurrentBlock();
$template->setCurrentBlock( "DATEAREA" );
$template->setVariable("DATE", $display_mo->format( "%Y-%m-%d" ) );
$template->setVariable("TYPE", $type );
$template->setVariable( "STRID", $row["exercises_id"] );
$template->parseCurrentBlock();
}
else
{
$template->setCurrentBlock( "DATEAREA" );
$template->setVariable("DATE", $display_mo->format( "%Y-%m-%d" ) );
$template->setVariable("TYPE", $type );
$template->setVariable( "STRID", "0" );
$template->parseCurrentBlock();
$template->setCurrentBlock( "TIMES" );
$template->setVariable( "STARTTIME", "" );
$template->setVariable( "DURATION", "" );
$template->parseCurrentBlock();
$template->setCurrentBlock( "NOTES" );
$template->setVariable( "STRNOTES", "" );
$template->parseCurrentBlock();
}
}
else
{
//Seems the user has attempted to navigate directly to the dashboard without
//logging in. Send them to the logout page with an error message.
$_SESSION["headerMessage"] = "Error!!";
$_SESSION["message"] = "You must first log into the system before you can view the page.";
// Send user to the logout page.
header( "Location: logout.php" );
exit;
}
//Show the user the Month View page.
$template->show();
/******************************* Helper Functions ******************************************/
function setSelectCategoryOption( $comp1, $comp2, $template )
{
if( !strcmp( $comp1, $comp2 ) )
return true;
else
return false;
}
?>