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 1438
This module displays statistics and reports for FlightPath

Code

function stats_report_access_stats() {
  $rtn = "";


  fp_add_css(fp_get_module_path("admin") . '/css/admin.css');

  $min = intval(@$_REQUEST ["min"]);
  if ($min < 1 || $min > 2000) 
   {
    $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='&gt;'>
      </form>
      " . t("Unique students in time frame") . ": <!--STUDENTS-->. " . t("Unique faculty/staff in time frame") . ": <!--STAFF--> <br>";

  $rtn .= "<hr>
            <table class='watchdog-table' cellspacing='0' cellpadding='4'>
            <tr>
              <th>" . t("ID") . "</th>
              <th>" . t("User") . "</th>
              <th>" . t("User Type") . "</th>
              <th>" . t("Action") . "</th>
              <th>" . t("Msg") . "</th>
              <th>" . t("Time") . "</th>
              
            </tr>";

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

  $interval = time() - ($min * 60);
  $pol = "";
  $res = db_query("SELECT * FROM watchdog
              WHERE `timestamp` > ?
              ORDER BY `timestamp` DESC 
              ", $interval);
  while ($cur = db_fetch_array($res)) {
    extract($cur, 3, "db");
    $wid = $cur ['wid'];
    $account = fp_load_user($db_user_id);

    $pol = ($pol == "even") ? "odd" : "even";

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

    $vars = @unserialize($db_variables);
    if (!$vars) {
      $vars = '';
    }

    $message = strip_tags(t($db_message, $vars));
    if (strlen($message) > 100) {
      $message = trim(substr($message, 0, 100)) . "...";
    }


    $pretty_date = format_date(convert_time($db_timestamp));

    $user_type = "";
    if ($account->is_student) {
      $user_type .= "<span>" . t("Student") . "</span>";
    }
    if ($account->is_faculty) {
      $user_type .= "<span style='background-color: lightyellow;'>" . t("Faculty") . "</span>";
    }

    $rtn .= "<tr class='row-$pol'>
          <td valign='top'>" . l($wid, "admin/config/watchdog/$wid") . "</td>
          <td valign='top'>$account->name</td>
          <td valign='top'>$user_type</td>
          <td valign='top'>$db_type</td>
          <td valign='top'>$message</td>
          <td valign='top'>$minago " . t("min ago") . " &nbsp; <em>($pretty_date)</em></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;
}