function z__admin_display_watchdog

7.x admin.module z__admin_display_watchdog()
6.x admin.module z__admin_display_watchdog()

Displays recent watchdog entries, from the watchdog table

File

modules/admin/admin.module, line 1447
The administrative configurations for FlightPath.

Code

function z__admin_display_watchdog() {

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

  $rtn = "";

  $rtn .= "<p>View recent watchdog entries</p>";

  $severity_array = array(
    5 => "notice",
    1 => "alert",
    3 => "error",
    7 => "debug",
  );

  $results_per_page = 50;



  $type_line = $severity_line = $limit_start = "";

  @$sev_filter = $_GET ["sev_filter"];
  @$type_filter = $_GET ["type_filter"];
  @$page = $_GET ["page"];

  $limit_start = 0;
  if ($page != "" && is_numeric($page)) {
    $limit_start = $results_per_page * ($page - 1);
  }
  else {
    $page = 1;
  }



  // Filters:
  $rtn .= "<form method='GET' action='" . fp_url("admin/config/watchdog") . "' class='watchdog-filters'>
            ";

  $rtn .= "Filter by:
           <span class='type-filter'>
            Type:
            <select name='type_filter'>
              <option value=''>-Any-</option>";
  $res = db_query("SELECT distinct(type) as type 
                   FROM watchdog 
                   ORDER BY type");
  while ($cur = db_fetch_object($res)) {
    $sel = ($type_filter == $cur->type) ? "selected" : "";
    $rtn .= "<option value='$cur->type' $sel>$cur->type</option>";
  }


  $rtn .= "</select>
            </span>";


  $rtn .= "
            <span class='severity-filter'>
            Severity:
            <select name='sev_filter'>
              <option value=''>-Any-</option>";
  foreach ($severity_array as $key => $value) {
    $sel = "";
    if ($sev_filter == $key) {
      $sel = "selected";
    }

    $rtn .= "<option value='$key' $sel>$value</option>";
  }

  $rtn .= "</select>
            </span>";




  $rtn .= "<input type='submit' value='&gt;'>";
  // Hack if clean URLs are not enabled:
  $rtn .= "<input type='hidden' name='q' value='admin/config/watchdog'>";

  $rtn .= "</form>";

  $params = array();

  if (@$_GET ["type_filter"] != "") {
    //$type_line = " AND type = '" . mysql_real_escape_string($_GET["type_filter"]) . "' ";
    $type_line = " AND `type` = :type ";
    $params [":type"] = $_GET ["type_filter"];
  }

  if (@$_GET ["sev_filter"] != "") {
    //$severity_line = " AND severity = '" . mysql_real_escape_string($_GET["sev_filter"]) . "' ";
    $severity_line = " AND severity = :sev ";
    $params [":sev"] = $_GET ["sev_filter"];
  }


  $pol = "even";

  $rtn .= "<table class='watchdog-table' cellspacing='0' cellpadding='4'>
              <tr>
                <th>ID</th>
                <th>When</th>
                <th>Type</th>
                <th>Msg</th>
                <th>Severity</th>
                <th>User</th>
              </tr>";
  // Okay, let's display the recent watchdog entries.
  $query = "SELECT * FROM watchdog
                   WHERE 1
                   $type_line
                   $severity_line
                   ORDER BY wid DESC
                   ";
  $res = db_query($query . " LIMIT $limit_start, $results_per_page", $params);
  while ($cur = db_fetch_object($res)) {
    $pol = ($pol == "even") ? "odd" : "even";

    $o_msg = t($cur->message, unserialize($cur->variables));
    $o_type = $cur->type;

    // shorten msg if necessary
    $msg = substr(strip_tags($o_msg), 0, 130);
    if ($msg != $o_msg) {
      $msg = trim($msg) . "...";
    }

    $type = substr($o_type, 0, 20);
    if ($type != $o_type) {
      $type = trim($type) . "...";
    }



    $severity = $severity_array [$cur->severity];
    $when = format_date(convert_time($cur->timestamp), "short");


    $rtn .= "
              <tr class='row-$pol row-$severity'>                
                <td valign='top'>" . l($cur->wid, "admin/config/watchdog/$cur->wid", "sev_filter=$sev_filter&type_filter=$type_filter&page=$page") . "</td>
                <td valign='top'>$when</td>
                <td valign='top'>$type</td>                
                <td valign='top'>$msg</td>                
                <td valign='top'>$severity</td>                
                <td valign='top'>$cur->user_name</td>                
              
              </tr>    
    
            ";

  }


  $rtn .= "</table>";

  // Now, do the page

  // Figure out the total number of results
  $total = db_result(db_query("SELECT count(wid) as count
                               FROM watchdog WHERE 1 
                               $type_line 
                               $severity_line", $params));


  // Now, divide by the number of results per page.
  $pages = ceil($total / $results_per_page);

  $base_query = "sev_filter=$sev_filter&type_filter=$type_filter";

  $rtn .= "<div class='fp-pager'>";
  if ($page > 1) {
    $rtn .= "<span class='pager-link pager-first'>" . l("&laquo; first", "admin/config/watchdog", $base_query . "&page=1") . "</span>";
    $rtn .= "<span class='pager-link pager-prev'>" . l("&lt; prev", "admin/config/watchdog", $base_query . "&page=" . ($page - 1)) . "</span>";
  }
  else {
    $rtn .= "<span class='pager-link pager-first'>&laquo; first</span>";
    $rtn .= "<span class='pager-link pager-prev'>&lt; prev</span>";
  }

  // page numbers here
  // Let's get the previous X page numbers, and next X (if possible)
  $start_page_num = $page - 5;
  if ($start_page_num < 1) {
    $start_page_num = 1;
  }
  $end_page_num = $page + 5;
  if ($end_page_num > $pages) {
    $end_page_num = $pages;
  }

  if ($start_page_num > 1) {
    $rtn .= "<span class='pager-elip'>...</span>";
  }

  for ($t = $start_page_num; $t <= $end_page_num; $t++) {
    if ($page == $t) {
      // current page
      $rtn .= "<span class='pager-link pager-number pager-current'>$t</span>";
    }
    else {
      $rtn .= "<span class='pager-link pager-number'>" . l($t, "admin/config/watchdog", $base_query . "&page=$t") . "</span>";
    }
  }


  if ($end_page_num < $pages) {
    $rtn .= "<span class='pager-elip'>...</span>";
  }



  if ($page < $pages) {
    $rtn .= "<span class='pager-link pager-next'>" . l("next &gt;", "admin/config/watchdog", $base_query . "&page=" . ($page + 1)) . "</span>";
    $rtn .= "<span class='pager-link pager-last'>" . l("last &raquo;", "admin/config/watchdog", $base_query . "&page=$pages") . "</span>";
  }
  else {
    $rtn .= "<span class='pager-link pager-next'>next &gt;</span>";
    $rtn .= "<span class='pager-link pager-last'>last &raquo;</span>";
  }

  $rtn .= "</div>";




  return $rtn;

}