root/components/members.php @ 314

Revision 314, 7.2 KB (checked in by chckens, 6 years ago)

fix some wrong banana totals and links from this years leaderboard

Line 
1<?php
2
3include("../lib/members.php");
4include_once("../lib/date.php");
5$members = new Members;
6
7if ($session->loggedin) {
8    $usernames = $members->getMemberList();
9
10    $smarty->assign('members', $usernames);
11    $sidebar = $smarty->fetch('members-search.tpl');
12    $smarty->assign('secondary', $sidebar);
13
14    // Show Searched for users depending on the method provided
15    $value = '';
16    $uid = false;
17    $pathCount = count($pathlist) -1;
18    if ( isset($_POST['search']) ) {
19        $value = $_POST['search'];
20        $uid = true;
21        $usernames = $members->memberSearch($value);
22    } else if ( isset($_POST['member']) ) {
23        $value = $_POST['member'];
24        $uid = true;
25        $usernames = $members->memberView($value);
26    } else if ( $component['path'] != $path ) {
27        $value = $pathlist[$pathCount];
28        $usernames = $members->memberView($value);
29    }
30    if (!empty($value) ) {
31        // Redirect if we have found a valid single user
32        if (count($usernames) == 1) {
33            $smarty->assign('who', $usernames[0]['uid']);
34            // Add banana widget to the sidebar
35            $who = $usernames[0]['uid'];
36            include("../lib/banana-admin.php");
37            // Needs Redirection
38            if ($uid) {
39                header('Location: ' . $component['path'] . '/' . $usernames[0]['uid']);
40            } else {
41                // Pictures
42                if (file_exists('pictures/people/' . $usernames[0]['uid'] . '.png')) {
43                    $usernames[0]['picture'] = '/pictures/people/' . $usernames[0]['uid'] . '.png';
44                }
45                // Account type
46                $homedir  = explode('/', $usernames[0]['homedir']);
47                $usernames[0]['acctype'] = ucfirst($homedir[2]);
48                // Project
49                if (file_exists( $usernames[0]['homedir'] . '/.project')) {
50                    $usernames[0]['project'] = file_get_contents($usernames[0]['homedir'] . '/.project');
51                }
52                // Plan
53                if (file_exists( $usernames[0]['homedir'] . '/.plan')) {
54                    $usernames[0]['plan'] = file_get_contents($usernames[0]['homedir'] . '/.plan');
55                }
56                // Website   
57                if ( file_exists( $usernames[0]['homedir'] . '/public_html') &&
58                     !file_exists( $usernames[0]['homedir'] . '/public_html/robots.txt'))  {
59                    $usernames[0]['website'] = true;
60                }
61                // Blog
62                require_once("/usr/share/adodb/adodb.inc.php");
63                $BlogDB = NewADOConnection('postgres8');
64                $BlogDB->Connect('dbname=blogs');
65                $BlogDB->SetFetchMode(ADODB_FETCH_ASSOC);
66                require_once('../lib/blog/validation.lib.php');
67                if (blogger($usernames[0]['uid'])) {
68                    $usernames[0]['blog'] = $BlogDB->GetOne("select title from users where username='".$usernames[0]['uid']."'");
69                }
70                // Bananas stuff
71                $bananasql = "SELECT *, date_trunc('second', whn) FROM awards ";
72                $bananasql .= "WHERE username ~* ? ORDER BY WHN DESC";
73                $awards = $DB->GetAll($bananasql, array("^".$usernames[0]['uid']."$"));
74               
75                // add academic year to each award, perform slightly nasty hack to add sum for academic year to last of the year
76                $yearSum = 0;
77                unset($acYear);
78                unset($yearStart);
79                foreach ($awards as $i => $award) {
80                    $awards[$i]['acYear'] = academicYear(strtotime($award['whn']));
81                    if ($acYear != $awards[$i]['acYear']) {
82                        if(isset($yearStart)) {
83                            $awards[$yearStart]['yearSum'] = $yearSum;
84                            $yearSum = 0;
85                        }
86                        $yearSum += $award['score'];
87                        $acYear = $awards[$i]['acYear'];
88                        $yearStart = $i;
89                    } else {
90                        $yearSum += $award['score'];
91                    }
92                }
93                if(isset($yearStart)) $awards[$yearStart]['yearSum'] = $yearSum;
94               
95               
96                $usernames[0]['awards'] = $awards;
97                $bananasumsql = "select sum(score) as sum from awards where username ~* ?";
98                $bananasum = $DB->GetAll($bananasumsql, array("^".$usernames[0]['uid']."$"));
99                $usernames[0]['bananascore'] = $bananasum[0]['sum'];
100            }
101        }
102        $smarty->assign('results', $usernames);
103   
104    } else {
105    // generate fun data to put on index page
106       
107        // top 5
108        $stats['top'] = $DB->GetAll("SELECT username, sum(score) as sum FROM awards GROUP BY username ORDER BY sum DESC LIMIT 5");
109
110        // top 5 (this academic year)
111        $yeartop_sql = "SELECT username, sum(score) as sum FROM awards ";
112        $yeartop_sql .= "WHERE whn > date(?) GROUP BY username ORDER BY sum DESC LIMIT 5";
113        $stats['yeartop'] = $DB->GetAll($yeartop_sql, array(academicYear(time())."-09-01"));
114
115        // bottom 5
116        $stats['bottom'] = $DB->GetAll("SELECT username, sum(score) as sum FROM awards GROUP BY username ORDER BY sum ASC LIMIT 5");
117        // recent awards
118        // today's definition of "recent" is all awards within three days of the newest award and a minimum of five...
119        // if this seems like a dumb method then try something else :-)
120        $recentAwards_sql = "(SELECT * FROM awards WHERE whn > (SELECT whn - interval '3 days' FROM awards ORDER BY whn DESC LIMIT 1))";
121        $recentAwards_sql .= " UNION (SELECT * FROM awards ORDER BY whn DESC LIMIT 5) ORDER BY 4 DESC";
122        $stats['recent'] = $DB->GetAll($recentAwards_sql);
123
124
125                // retrieve the usernames for top stats, bottom stats, and all users - so we can filter out who's a user and who's not
126                foreach ($usernames as $i => $value) {
127                        $realUsers[] = $usernames[$i]['uid'];
128                }
129                foreach ($stats['yeartop'] as $i => $value) {
130                        if (in_array(strtolower($stats['yeartop'][$i]['username']), $realUsers)) {
131                                $stats['yeartop'][$i]['real'] = TRUE;
132                        } else {
133                                $stats['yeartop'][$i]['real'] = FALSE;
134                        }
135                }
136                foreach ($stats['top'] as $i => $value) {
137                        if (in_array(strtolower($stats['top'][$i]['username']), $realUsers)) {
138                                $stats['top'][$i]['real'] = TRUE;
139                        } else {
140                                $stats['top'][$i]['real'] = FALSE;
141                        }
142                }
143                foreach ($stats['bottom'] as $i => $value) {
144                        if (in_array(strtolower($stats['bottom'][$i]['username']), $realUsers)) {
145                                $stats['bottom'][$i]['real'] = TRUE;
146                        } else {
147                                $stats['bottom'][$i]['real'] = FALSE;
148                        }
149                }
150                foreach ($stats['recent'] as $i => $value) {
151                        if (in_array(strtolower($stats['recent'][$i]['username']), $realUsers)) {
152                                $stats['recent'][$i]['real'] = TRUE;
153                        } else {
154                                $stats['recent'][$i]['real'] = FALSE;
155                        }
156                }
157   
158        $smarty->assign("stats", $stats);
159        $secondary = $smarty->get_template_vars("secondary");
160        $secondary .= $smarty->fetch("banana-leaders.tpl");
161        $smarty->assign("secondary", $secondary);
162
163    }
164} else {
165    // not logged in. Show a list of members with websites
166    $usernames = $members->getMemberList();
167
168    foreach ($usernames as $user) {
169        if ( file_exists( $user['homedir'] . '/public_html') &&
170             !file_exists( $user['homedir'] . '/public_html/robots.txt'))  {
171            $public_usernames[] = $user;
172        }
173    }
174    $smarty->assign("public_members", $public_usernames);
175}
176   
177
178$smarty->assign('url', $component['path']);
179$smarty->assign('extra_styles', "/css/members.css");
180$result = $smarty->fetch('members.tpl');
181$smarty->assign('title', "Members");
182$smarty->assign('body', $result);
183
184// End Actual Code
185?>
Note: See TracBrowser for help on using the browser.