Summary/count of logged in users by type

Remember to always back up your data before making any changes to it.
Always try out your customizations on a test server first, NOT the live one.
The following customization was tested in PowerSchool 7.11.1, so it might not work in the newer versions.
The following customization was not tested in Internet Explorer.

Did I ever mentioned to you that I love statistics? Probably not. I’m really fascinated with grouping, ordering and analyzing raw data and I can’t be the only one out there. That’s why, when I look to the Current Users page (home.html found in /admin/logins) I get all sorts of ideas.

For example, I wanted to know how many parents and students were logged in to our system after the release of the Report Cards or the Online Forms on our Parent Portal. So I asked myself: why not, rather than having to eye-ball through the whole table/list on the page (that could reach up to 300 entries on some occasions), have a one-line summary at the top, listing the totals by type/category?

Summary of logged in users by type/category

Summary of logged in users by type/category

And here is what I answered back:

Let’s start by editing home.html file in /admin/logins (I assume that you already have a copy of it in your PowerSchool customization folder).

  1. Open the file in a text editor and locate the closing head tag (</head>).
  2. The entire customization is based on JavaScript/jQuery code, so just before the </head> tag add a pair of script tags (<script></script>). All the code to follow on this page will be placed in between those <script> tags.
  3. Let’s define our variables first.
    //get the text in all first columns from each row with the exception of the first one and remove the “.” at the end
    var totalUsers = $j(“table tbody tr:last”).find(“td:eq(0)”).text().slice(0,-1);
    //a 2-dimensional array that containing the category/type name and the respective default total value (zero)
    var typeRows = [[“Faculty”,0],[“Teacher”,0],[“Parent”,0],[“Student”,0]];
    //the string (holding the summary) that will be added after the default text at the top (within the H1 tag)
    var myString = “”;
    //total number of defined/identified entries
    var totalIdentified = 0;
    //total number of non-defined/non-identified entries
    var totalOthers = 0;
    //get all second columns from each row with the exception of the first one
    var myTDs = $j(“table tbody tr:gt(0)”).find(“td:eq(1)”);
  4. Inside the “on document ready” jQuery function $j(document).ready(function() { …… } (if there isn’t one, add it) add the following piece of code:
    //iterating through the text in all second columns from each row with the exception of the first one
    myTDs.each(function(){
      for (var i = 0; i < typeRows.length; i++){
          //check if there is a match
        if ($j(this).text() == typeRows[i][0]){
            //no of matches for that particular type/category is incremented
            typeRows[i][1]++;
            //total no of matches is incremented
            totalIdentified++;
        }
      }
    });
    //start building the string that will be displayed at the top
    for (var i = 0; i < typeRows.length; i++){
        if (typeRows[i][1] > 0) myString += typeRows[i][1] + ” ” + typeRows[i][0] + “, “;
    }
    //get all “others” (no match found for them)
    totalOthers = totalUsers – totalIdentified;
    //if there really are “others” (value > 0) put their number at the and of the string
    if (totalOthers > 0) myString += totalOthers + ” others”;
    //if not, leave the string as it is (removing the two characters – “,” and the ” ” – at the end)
    else myString = myString.slice(0,-2);
    //add the total number of users at the beginning of the string
    myString = totalUsers + ” users (” + myString + “)”;
    //add the string above to the text that is already found in the H1 tag
    $j(“h1”).html($j(“h1”).html() + “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;” + myString);

Not too complicated, is it?

Leave a comment