members.php 6.18 KB
Newer Older
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
<?php

include("../lib/members.php");
include_once("../lib/date.php");
$members = new Members;

if ($session->loggedin) {
	$usernames = $members->getMemberList();

	$smarty->assign('members', $usernames);
	$sidebar = $smarty->fetch('members-search.tpl');
	$smarty->assign('secondary', $sidebar);

	// Show Searched for users depending on the method provided
	$value = '';
	$uid = false;
	$pathCount = count($pathlist) -1;
	if ( isset($_POST['search']) ) {
		$value = $_POST['search'];
		$uid = true;
		$usernames = $members->memberSearch($value);
	} else if ( isset($_POST['member']) ) {
		$value = $_POST['member'];
		$uid = true;
		$usernames = $members->memberView($value);
	} else if ( $component['path'] != $path ) {
		$value = $pathlist[$pathCount];
		$usernames = $members->memberView($value);
	}
	if (!empty($value) ) {
		// Redirect if we have found a valid single user
		if (count($usernames) == 1) {
			$smarty->assign('who', $usernames[0]['uid']);
34
			// Add banana widget to the sidebar
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
			$who = $usernames[0]['uid'];
			include("../lib/banana-admin.php");
			// Needs Redirection
			if ($uid) {
				header('Location: ' . $component['path'] . '/' . $usernames[0]['uid']);
			} else {
				// Pictures
				if (file_exists('pictures/people/' . $usernames[0]['uid'] . '.png')) {
					$usernames[0]['picture'] = '/pictures/people/' . $usernames[0]['uid'] . '.png';
				}
				// Account type
				$homedir  = explode('/', $usernames[0]['homedir']);
				$usernames[0]['acctype'] = ucfirst($homedir[2]);
				// Project
				if (file_exists( $usernames[0]['homedir'] . '/.project')) {
					$usernames[0]['project'] = file_get_contents($usernames[0]['homedir'] . '/.project');
				}
				// Plan
				if (file_exists( $usernames[0]['homedir'] . '/.plan')) {
					$usernames[0]['plan'] = file_get_contents($usernames[0]['homedir'] . '/.plan');
				}
56
				// Website
57
				if ( file_exists( $usernames[0]['homedir'] . '/public_html')) {
58 59 60 61 62 63
					$usernames[0]['website'] = true;
				}
				// Bananas stuff
				$bananasql = "SELECT *, date_trunc('second', whn) FROM awards ";
				$bananasql .= "WHERE username ~* ? ORDER BY WHN DESC";
				$awards = $DB->GetAll($bananasql, array("^".$usernames[0]['uid']."$"));
64

Graham Cole's avatar
Graham Cole committed
65 66 67 68
				// arrange by academic year, calculate sums as we go
				foreach ($awards as $award) {
					$acyear = academicYear(strtotime($award['whn']));
					$awards_by_year[$acyear]['awards'][] = $award;
69
					$awards_by_year[$acyear]['sum'] += $award['score'];
Graham Cole's avatar
Graham Cole committed
70
					$bananasum += $award['score'];
71 72 73
				}

				$usernames[0]['awardsbyyear'] = &$awards_by_year;
Graham Cole's avatar
Graham Cole committed
74
				$usernames[0]['bananascore'] = $bananasum;
75 76 77
			}
		}
		$smarty->assign('results', $usernames);
78

79 80
	} else {
	// generate fun data to put on index page
81

82 83 84 85 86 87 88 89 90
		// top 5
		$stats['top'] = $DB->GetAll("SELECT username, sum(score) as sum FROM awards GROUP BY username ORDER BY sum DESC LIMIT 5");

		// top 5 (this academic year)
		$yeartop_sql = "SELECT username, sum(score) as sum FROM awards ";
		$yeartop_sql .= "WHERE whn > date(?) GROUP BY username ORDER BY sum DESC LIMIT 5";
		$stats['yeartop'] = $DB->GetAll($yeartop_sql, array(academicYear(time())."-09-01"));

		// bottom 5
91 92
		// exclude sambws and frostys allways decresing banana that scres up the result
		$stats['bottom'] = $DB->GetAll("SELECT username, sum(score) as sum FROM awards WHERE id!=685 and id!=393 GROUP BY username ORDER BY sum ASC LIMIT 5");
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
		// recent awards
		// today's definition of "recent" is all awards within three days of the newest award and a minimum of five... 
		// if this seems like a dumb method then try something else :-)
		$recentAwards_sql = "(SELECT * FROM awards WHERE whn > (SELECT whn - interval '3 days' FROM awards ORDER BY whn DESC LIMIT 1))";
		$recentAwards_sql .= " UNION (SELECT * FROM awards ORDER BY whn DESC LIMIT 5) ORDER BY 4 DESC";
		$stats['recent'] = $DB->GetAll($recentAwards_sql);


                // retrieve the usernames for top stats, bottom stats, and all users - so we can filter out who's a user and who's not
                foreach ($usernames as $i => $value) {
                        $realUsers[] = $usernames[$i]['uid'];
                }
                foreach ($stats['yeartop'] as $i => $value) {
                        if (in_array(strtolower($stats['yeartop'][$i]['username']), $realUsers)) {
                                $stats['yeartop'][$i]['real'] = TRUE;
                        } else {
                                $stats['yeartop'][$i]['real'] = FALSE;
                        }
                }
                foreach ($stats['top'] as $i => $value) {
                        if (in_array(strtolower($stats['top'][$i]['username']), $realUsers)) {
                                $stats['top'][$i]['real'] = TRUE;
                        } else {
                                $stats['top'][$i]['real'] = FALSE;
                        }
                }
                foreach ($stats['bottom'] as $i => $value) {
                        if (in_array(strtolower($stats['bottom'][$i]['username']), $realUsers)) {
                                $stats['bottom'][$i]['real'] = TRUE;
                        } else {
                                $stats['bottom'][$i]['real'] = FALSE;
                        }
                }
                foreach ($stats['recent'] as $i => $value) {
                        if (in_array(strtolower($stats['recent'][$i]['username']), $realUsers)) {
                                $stats['recent'][$i]['real'] = TRUE;
                        } else {
                                $stats['recent'][$i]['real'] = FALSE;
                        }
                }
133

134
		$smarty->assign("stats", $stats);
Imran Hussain's avatar
Imran Hussain committed
135
		$secondary = $smarty->getTemplateVars("secondary");
136 137 138 139 140 141 142 143 144
		$secondary .= $smarty->fetch("banana-leaders.tpl");
		$smarty->assign("secondary", $secondary);

	}
} else {
	// not logged in. Show a list of members with websites
	$usernames = $members->getMemberList();

	foreach ($usernames as $user) {
145
		if ( file_exists( $user['homedir'] . '/public_html')) {
146 147 148 149 150
			$public_usernames[] = $user;
		}
	}
	$smarty->assign("public_members", $public_usernames);
}
151

152 153 154 155 156 157 158 159
$smarty->assign('url', $component['path']);
$smarty->assign('extra_styles', "/css/members.css");
$result = $smarty->fetch('members.tpl');
$smarty->assign('title', "Members");
$smarty->assign('body', $result);

// End Actual Code
?>