-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcourses.php
More file actions
174 lines (138 loc) · 4.18 KB
/
Copy pathcourses.php
File metadata and controls
174 lines (138 loc) · 4.18 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
171
172
173
174
<?php
/*
Runner's Medium
http://www.runnersmedium.com/
courses.php
view & manage courses
copyright 2009 Mark Baltrusaitis <http://josieprogramme.com>
*/
require('lib/base.php');
$user->signinCheck(signin());
$stop = false;
// user
$theid = $user->ID();
// display a message?
if (isset($_SESSION['msg']) && $_SESSION['msg'] != '') {
$message = $_SESSION['msg'];
// don't show this message again
unset($_SESSION['msg']);
}
// defaults
$rows = MAX_RESULTS;
$page = 1;
$ext = new extHelper();
// selected page
if(isset($_GET['page']) && is_numeric($_GET['page'])) {
$page = $_GET['page'];
}
// offset
$offset = ($page - 1) * $rows;
// calc total pages
$result = $conn->query('SELECT COUNT(id) FROM courses WHERE user = '.mysql_real_escape_string($theid));
$count = $conn->getRow($result);
$max = ceil($count/$rows);
if ($count > 0) {
$result = $conn->query('SELECT a.id, a.name, ROUND(a.distance, 2) AS distance, a.city, a.comments, b.username,
(SELECT COUNT(id) FROM runs WHERE course = a.id AND user = '.$theid.') AS runs,
(SELECT ROUND(SUM(distance), 2) FROM runs WHERE course = a.id AND user = '.$theid.') AS total,
(SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(duration))) FROM runs WHERE course = a.id AND user = '.$theid.') AS ave,
(SELECT date FROM runs WHERE course = a.id AND user = '.$theid.' ORDER BY date DESC LIMIT 1) AS lastran
FROM courses AS a LEFT JOIN users AS b ON (a.user = b.id) WHERE user = '.$theid.' ORDER BY lastran DESC LIMIT '.
mysql_real_escape_string($offset).', '.
mysql_real_escape_string($rows));
// check for invalid page parameter
if ($conn->rowCount($result) == 0) {
$error = '<a href="'.root().'courses">no entries for that page</a>';
$stop = true;
}
} else {
// no runs yet
$message = '<a href="'.root().'newcourse">you have not entered any courses yet. Click here to map your first course.</a>';
$stop = true;
}
$title = 'Runner\'s Medium - Courses';
require('header.php');
?>
<div id="content">
<?php
messages($error, $message);
if (!$stop && $conn->rowCount($result) > 0) :
?>
<div class="heading">
<h2>My Courses</h2>
<a href="<?php echo root(); ?>newcourse">map a new course</a>
</div>
<div id="main">
<table id="feed">
<colgroup>
<col />
<col class="alt" />
<col />
</colgroup>
<thead>
<tr>
<td>Name & location</td>
<td>Details</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
<?php
while ($line = $conn->fetchAssoc($result)) :
// id
$courseid = format($line['id']);
// others
if (notempty($line['distance'])) {
$dist = format_d($line['distance']);
} else {
$dist = 0;
}
if (empty($line['total'])) {
$total = 0;
} else {
$total = format_d($line['total']);
}
if ($total > 0) {
$ave = format_t($line['ave']);
} else {
$ave = 0;
}
if ($line['runs'] == 1) {
$ranit = format($line['runs']).' run';
} else {
$ranit = format($line['runs']).' runs';
}
?>
<tr id="item-<?php echo $courseid; ?>">
<td>
<h4><?php echo format($line['name']); ?></h4>
<?php echo format($line['city']); ?>
</td>
<td>
distance: <em><?php echo $dist; ?></em> <?php echo format($user->getUnits(true)); ?><br />
<?php echo $ranit; ?> for <?php echo $total; ?> <?php echo $user->getUnits(true); ?><br />
ave time completed: <?php echo $ave; ?><br />
created by: <em><?php echo $line['username']; ?></em>
</td>
<td class="actions">
<a href="<?php echo root(); ?>newrun?course=<?php echo $courseid; ?>">run it</a>
<a href="<?php echo root(); ?>editcourse?id=<?php echo $courseid; ?>">edit</a>
<a class="delete" onclick="deleteItem('course', <?php echo $courseid; ?>)">x</a>
</td>
</tr>
<?php endwhile; // results loop ?>
</tbody>
</table>
</div>
<?php
// pagination
$ext->paging('courses?', $page, $max);
?>
<div id="side"></div>
<?php
endif; // no results
?>
</div>
<?php
require('footer.php');
?>