forked from ewic/php_timeclock
/
points.php
105 lines (88 loc) · 2.5 KB
/
points.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
<?php
ob_start(); // Output buffering - allows header rewrites to happen at anytime before flushing the buffer
session_start();
require_once("incdir.php.inc");
require_once("config.php");
include_php_dir("includes");
mysql_init();
document_header();
echo include_javascript_dir("js",$debug);
echo include_stylesheet_dir("stylesheets",$debug);
check_validated();
//Any pre-page logic should go here!
open_page("Race for Excellence");
draw_page();
close_page();
ob_end_flush(); // Flush the buffer out to client
document_footer(); mysql_end();
function draw_page() {
?>
<div class="container">
<?php
open_panel('teamlist','Race For Excellence',false);
draw_team_panel();
close_panel();
open_panel('userlist','Points',false);
draw_user_list();
close_panel();
?>
</div>
<?php
}
function draw_team_panel() {
global $points_brackets;
$teams = get_team_leaders();
$teampoints = array();
while ($team = $teams->fetch_array()) {
$teampoints[$team['user_id']]=get_team_point_total($team['user_id']);
}
$highest = max($teampoints);
$bracket = 100;
while ($bracket < $highest) {
$bracket = current($points_brackets);
next($points_brackets);
}
foreach ($teampoints as $team=>$teampoint) {
$tlinfo = get_user_info($team);
echo 'Team '.$tlinfo['lname'];
draw_progress_bar($teampoint, $bracket);
}
}
function draw_user_list() {
$users = get_users('user');
?>
<table class="userlist table table-condensed">
<tr>
<th>Name</th>
<th>Points</th>
</tr>
<?php
while ($row = $users->fetch_array()) {
$points=get_points_total($row['user_id']);
echo '<tr class="userlist"';
echo ' onclick="openPoints('.$row['user_id'].')">';
echo '<td>'.$row['fname'].' '.$row['lname'].'</td>';
echo '<td>'.$points.'</td>';
echo '</tr>';
}
?>
</table>
<?php
}
function draw_progress_bar($progress,$total) {
$percent = round(($progress/$total)*100);
?>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $percent; ?>" aria-valuemin="0" aria-valuemax="<?php echo $total; ?>" style="width:<?php echo $percent; ?>%;">
<span><?php echo $progress; ?> Points</span>
</div>
</div>
<?php
}
?>
<!-- popup javascript -->
<script type="text/javascript">
function openPoints(id) {
window.open('edit_points.php?user_id='+id,'_blank','height=540,width=680,menubar=no,status=no,titlebar=no,toolbar=no');
}
</script>