Merge branch 'master' into topic/simple_image_upload
[sgn.git] / cgi-bin / solpeople / admin / stats_new.pl
blobc610ebaca1e27f75c6029bad17998c13c86ecfbb
1 #!/usr/bin/perl -w
2 use strict;
3 use CXGN::Page;
4 use CXGN::Login;
5 use CXGN::Contact;
6 use CXGN::People;
8 my $page=CXGN::Page->new("SGN Stats","johnathon");
9 my $dbh = CXGN::DB::Connection->new("sgn_people");
11 my $logged_in_person_id=CXGN::Login->new($dbh)->verify_session();
12 my $logged_in_user=CXGN::People::Person->new($logged_in_person_id);
13 my $logged_in_person_id=$logged_in_user->get_sp_person_id();
14 my $logged_in_username=$logged_in_user->get_first_name()." ".$logged_in_user->get_last_name();
15 my $logged_in_user_type=$logged_in_user->get_user_type();
17 my $user_table;
18 my ($time_to_check) = $page->get_encoded_arguments("hours");
19 print STDERR "Time: '$time_to_check'\n";
20 if($logged_in_user_type eq 'curator'){
21 if($time_to_check <= 0){
22 $time_to_check = 24;#THIS IS THE DEFAULT TIME
24 my $people_logged_in;
25 $people_logged_in = $dbh->selectall_arrayref("select sp_person_id, username, extract(epoch from current_timestamp - last_access_time), last_access_time from sp_person where extract(epoch from current_timestamp - last_access_time) <= ? order by last_access_time DESC", undef, $time_to_check*60*60);
26 $user_table = "<table align='left' style='width: 55%'><tr><th>ID:</th><th>Username:</th><th>Mins since last action:</th><th>Timestamp:</th></tr><tr><td>";
27 $people_logged_in = epoch_to_minutes($people_logged_in);
28 for my $row(@$people_logged_in){
29 $user_table .="<tr><td align='center'>";
30 for my $cell(@$row){
31 $user_table .="$cell</td><td align='center'>";
33 $user_table .= "</tr>";
35 $user_table .="</table>";
38 else
40 $page->message_page('Sorry, but you are not authorized to view statistics.');
43 sub epoch_to_minutes{
44 my $people_logged_in = $_[0];
45 for my $person(@$people_logged_in){
46 $person->[2] = int($person->[2]/60);
48 return $people_logged_in;
51 $page->header("SGN Stats", "SGN Stats");
52 print <<html;
54 <script type='text/javascript' language='javascript'>
55 function lookup_person(id){
56 if(id > 0){
57 if(window.XMLHttpRequest){
58 http_request = new XMLHttpRequest();
60 else if(window.ActiveXObject){
61 http_request = new ActiveXObject("Microsoft.XMLHTTP");
63 if (!http_request) {
64 alert('Giving up :( Cannot create an XMLHTTP instance');
65 return false;
67 http_request.onreadystatechange = function() { writeData(http_request); };
68 http_request.open('GET', 'get_person.pl?id='+id, true);
69 http_request.send("id="+id);
71 function writeData(http_request){
72 if(http_request.readyState == 4){
73 if(http_request.status == 200){
74 var table = document.getElementById("idnumbers");
75 table.innerHTML += http_request.responseText;
77 else{
78 alert("Error " + http_request.status);
83 </script>
84 <br />
85 <form method="get" action="stats.pl" name="time" id="time"><label for="minutes">Time restraint (in hours): &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
86 <input type="text" size="5" name="hours" id="hours" value="$time_to_check" />
87 <input type="submit" id="submit" value="Submit" /></form>
88 <form id="lookup" name="lookup" action="javascript:lookup_person(document.lookup.number.value)">
89 <span id="request" name="request"
90 style="cursor: pointer; text-decoration: underline"
91 onclick="javascript:lookup_person(document.lookup.number.value)">
92 Obtain user info on id number:
93 </span>
94 <input type="text" size="5" name="number" />
95 <input type="submit" id="sumbitnum" value="Submit" />
96 </form>
98 <script type="text/javascript" language="javascript">document.time.hours.focus();</script>
99 $user_table
100 <table style="width: 45%" name="idnumbers" id="idnumbers"><tr><th>Username:</th><th>Timestamp:</th></tr></table>
102 html
104 $page->footer();