function stats_report_access_stats

7.x stats.module stats_report_access_stats()
6.x stats.module stats_report_access_stats()
4.x stats.module stats_report_access_stats()
5.x stats.module stats_report_access_stats()

This report shows recent activity in FlightPath. It can also be used to see if anyone is "online" in that they would have activity less than 5 minutes old.

Return value

unknown

File

modules/stats/stats.module, line 1238
This module displays statistics and reports for FlightPath

Code

function stats_report_access_stats() {
  $rtn = "";


  $min = trim(addslashes(@$_REQUEST ["min"]));
  if ($min == "") 
   {
    $min = "20";
  }


  $rtn .= "
      <form action='" . fp_url("stats/reports/access") . "' method='GET'>
      " . t("Activity over the last") . " 
      <input type='text' name='min' value='$min' size='2'>
      ";



  $rtn .= t("minutes") . ": <input type='submit' value='->'>
      </form>
      " . t("Unique students in time frame") . ": <!--STUDENTS-->. " . t("Unique faculty/staff in time frame") . ": <!--STAFF--> <br>";

  $rtn .= "<table border='1' width='700'>
            <tr>
              <th>" . t("User") . "</th>
              <th>" . t("UID") . "</th>
              <th>" . t("CWID") . "</th>
              <th>" . t("Name") . "</th>
              <th>" . t("Type") . "</th>
              <th>" . t("Action") . "</th>
              <th>" . t("Extra") . "</th>
              <th>" . t("Time") . "</th>
            </tr>";

  $cwid_array = array();
  $student_actions = $staff_actions = 0;

  $interval = time() - ($min * 60);

  $res = db_query("SELECT * FROM watchdog
              WHERE `timestamp` > '?'
              ORDER BY `timestamp` DESC ", $interval);
  while ($cur = db_fetch_array($res)) {
    extract($cur, 3, "db");

    $account = fp_load_user($db_user_id);

    $bgcol = "white";
    if ($account->is_student) {
      $bgcol = "lightblue";
    }
    else if ($account->is_faculty) {
      $bgcol = "pink";
    }

    $minago = round((time() - $db_timestamp) / 60, 0);

    $extra_data = trim(substr($db_extra_data, 0, 18));
    if (strlen($extra_data) < strlen($db_extra_data)) 
     {
      $extra_data .= "...";
    }

    $pretty_date = format_date($db_timestamp);

    $user_type = "";
    if ($account->is_student) {
      $user_type .= "<div>" . t("student") . "</div>";
    }
    if ($account->is_faculty) {
      $user_type .= "<div>" . t("faculty") . "</div>";
    }

    $rtn .= "<tr style='background-color:$bgcol'>
          <td valign='top' class='tenpt'>$account->name</td>
          <td valign='top' class='tenpt'>$account->cwid</td>
          <td valign='top' class='tenpt'>$account->id</td>
          <td valign='top' class='tenpt'>$account->f_name $account->l_name</td>          
          <td valign='top' class='tenpt'>$user_type</td>
          <td valign='top' class='tenpt'>$db_type</td>
          <td valign='top' class='tenpt'>" . t($db_message, unserialize($db_variables)) . "</td>
          <td valign='top' class='tenpt'>$minago " . t("min ago") . " &nbsp; <font size='1'>$pretty_date</font></td>
        </tr>";

    // Let's increase our counters, if this is a new CWID.
    if (!in_array($db_user_id, $cwid_array)) {
      $cwid_array [] = $db_user_id;
      if ($account->is_student) {
        $student_actions++;
      }
      else if ($account->is_faculty) {
        $staff_actions++;
      }
    }


  }

  // Add in our student and staff action counts
  $rtn = str_replace("<!--STUDENTS-->", $student_actions, $rtn);
  $rtn = str_replace("<!--STAFF-->", $staff_actions, $rtn);


  $rtn .= "</table>";


  return $rtn;
}