diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | includes/tablesort.inc | 92 | ||||
-rw-r--r-- | misc/arrow-asc.gif | bin | 0 -> 74 bytes | |||
-rw-r--r-- | misc/arrow-desc.gif | bin | 0 -> 73 bytes | |||
-rw-r--r-- | modules/comment.module | 35 | ||||
-rw-r--r-- | modules/comment/comment.module | 35 | ||||
-rw-r--r-- | modules/forum.module | 61 | ||||
-rw-r--r-- | modules/forum/forum.module | 61 | ||||
-rw-r--r-- | modules/node.module | 4 | ||||
-rw-r--r-- | modules/node/node.module | 4 | ||||
-rw-r--r-- | modules/statistics.module | 132 | ||||
-rw-r--r-- | modules/statistics/statistics.module | 132 | ||||
-rw-r--r-- | modules/tracker.module | 26 | ||||
-rw-r--r-- | modules/tracker/tracker.module | 26 | ||||
-rw-r--r-- | modules/user.module | 22 | ||||
-rw-r--r-- | modules/user/user.module | 22 | ||||
-rw-r--r-- | modules/watchdog.module | 33 | ||||
-rw-r--r-- | modules/watchdog/watchdog.module | 33 |
18 files changed, 427 insertions, 292 deletions
@@ -2,6 +2,7 @@ Drupal x.x.x, xxxx-xx-xx (to be released) ------------------------ - added support for configurable URLs. +- added support for sortable table columns. - database backend: * added support for database table prefxing. - performance improvements: diff --git a/includes/tablesort.inc b/includes/tablesort.inc new file mode 100644 index 000000000..184176114 --- /dev/null +++ b/includes/tablesort.inc @@ -0,0 +1,92 @@ +<?php + +function tablesort_init($header) { + static $ts; + + if (!$ts) { + $ts["order"] = tablesort_get_order($header); + $ts["order_sql"] = tablesort_get_order_sql($header, $ts["order"]); + $ts["sort"] = tablesort_get_sort($header); + $ts["query_string"] = tablesort_get_querystring(); + } + return $ts; +} + +function tablesort_pager() { + return array ("order" => $_GET['order'], "sort" => $_GET['sort']); +} + +function tablesort_sql($header) { + $ts = tablesort_init($header); + return " ORDER BY ". $ts["order_sql"]. " ". strtoupper($ts["sort"]); +} + +function tablesort($cell, $header) { + global $theme; + + $ts = tablesort_init($header); + + // special formatting for the currently sorted column header + if ($cell["data"] == $ts["order"]) { + $cell["class"] = "cell-highlight"; + $image = " <img src=\"". $theme->image("arrow-". $ts["sort"]. ".gif"). "\"></img>"; + } + $cell["data"] = l($cell["data"], $_GET["q"], array(), "sort=". $ts["sort"]. "&order=". urlencode($cell["data"]). $ts["query_string"]). $image; + return $cell; +} + +function tablesort_get_querystring() { + $cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST; + // reset ($cgi); + foreach ($cgi as $key => $val) { + if ($key != "order" && $key != "sort" && $key != "q") { + $query_string .= "&" . $key . "=" . $val; + } + } + return $query_string; +} + +function tablesort_get_order($headers) { + if ($_GET['order'] != NULL) { + return $_GET['order']; + } + else { + foreach ($headers as $header) { + if ($header["sort"] == 'asc' || $header["sort"] == 'desc') { + return $header["data"]; + } + elseif (!$first) { + // the first column specified is initial 'order by' field unless otherwise specified + $first = $header["data"]; + } + } + return $first; + } +} + +function tablesort_get_order_sql($header, $order) { + foreach ($header as $cell) { + if ($cell["data"] == $order) { + return $cell["field"]; + } + } +} + +function tablesort_get_sort($headers) { + if ($_GET['sort']) { + return ($_GET['sort'] == 'desc') ? 'asc' : 'desc'; + } + // user has not specified a sort. check module for default and if none, use 'asc' + else { + foreach ($headers as $header) { + if (isset($header["sort"])) { + return $header["sort"]; + } + } + } + return 'asc'; +} + + + +?> diff --git a/misc/arrow-asc.gif b/misc/arrow-asc.gif Binary files differnew file mode 100644 index 000000000..6a68f198c --- /dev/null +++ b/misc/arrow-asc.gif diff --git a/misc/arrow-desc.gif b/misc/arrow-desc.gif Binary files differnew file mode 100644 index 000000000..3ccadeb2d --- /dev/null +++ b/misc/arrow-desc.gif diff --git a/modules/comment.module b/modules/comment.module index 5ac4815ac..3c4d9920c 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -60,7 +60,7 @@ function comment_help($section = "admin/comment/help") { $output .= "<p>So that users know how their votes affect the comment, these examples include the vote value as part of the label, although that is optional.</p>"; $output .= "<p>Using the weight option, you can control the order in which the votes appear to users. Setting the weight heavier (positive numbers) will make the vote label appear at the bottom of the list. Lighter (a negative number) will push it to the top. To encourage positive voting, a useful order might be higher values, positive votes, at the top, with negative votes at the bottom.</p>"; - $output .= "<h4>Moderators/vote values matrix</h4>"; + $output .= "<h4>Moderator vote/values matrix</h4>"; $output .= strtr("<p>Next go to %comment-matrix. Enter the values for the vote labels for each permission role in the vote matrix. The values entered here will be used to create the rating for each comment.</p>", array("%comment-matrix" => l(t("comment management » comment moderation » matrix"), "admin/comment/moderation/,atrix") )); $output .= "<p>NOTE: Comment ratings are calculated by averaging user votes with the initial rating.</p>"; @@ -814,7 +814,7 @@ function comment_link($type, $node = 0, $main = 0) { menu("admin/comment/moderation/votes", "votes", "comment_admin", comment_help("admin/comment/moderation/votes")); menu("admin/comment/moderation/matrix", "matrix", "comment_admin", comment_help("admin/comment/moderation/matrix")); menu("admin/comment/moderation/filters", "thresholds", "comment_admin", comment_help("admin/comment/moderation/filters")); - menu("admin/comment/roles", "initial comment scores", "comment_admin", comment_help("admin/comment/roles"), 6); + menu("admin/comment/moderation/roles", "initial comment scores", "comment_admin", comment_help("admin/comment/roles"), 6); } } @@ -948,15 +948,24 @@ function comment_save($id, $edit) { function comment_admin_overview($status = 0) { - $result = pager_query("SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.status = '". check_query($status). "' ORDER BY c.timestamp DESC", 50); + $header = array( + array("data" => t("Subject"), "field" => "subject"), + array("data" => t("Author"), "field" => "u.name"), + array("data" => t("Status"), "field" => "status"), + array("data" => t("Time"), "field" => "timestamp", "sort" => "desc"), + array("data" => t("operations"), "colspan" => 2) + ); + + $sql = "SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.status = ". check_query($status); + $sql .= tablesort_sql($header); + $result = pager_query($sql, 50); - $header = array(t("subject"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2)); while ($comment = db_fetch_object($result)) { - $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid")); + $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". format_date($comment->timestamp, "small"). "</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid")); } - if ($pager = pager_display(NULL, 50, 0, "admin")) { - $rows[] = array(array("data" => $pager, "colspan" => 5)); + if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) { + $rows[] = array(array("data" => $pager, "colspan" => 6)); } return table($header, $rows); @@ -964,7 +973,7 @@ function comment_admin_overview($status = 0) { function comment_mod_matrix($edit) { - $output .= "<h3>Moderators/vote values matrix</h3>"; + $output .= "<h3>Moderation vote/value matrix</h3>"; if ($edit) { db_query("DELETE FROM {moderation_roles} "); @@ -974,6 +983,7 @@ function comment_mod_matrix($edit) { } } db_query("INSERT INTO {moderation_roles} (mid, rid, value) VALUES ". implode(", ", $sql)); + $output = status("Vote values saved"); } $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'"); @@ -1009,6 +1019,7 @@ function comment_mod_roles($edit) { if ($edit) { variable_set("comment_roles", $edit); + $output = status("Comment scores saved"); } $start_values = variable_get("comment_roles", array()); @@ -1035,15 +1046,18 @@ function comment_mod_votes($edit) { if ($op == t("Save vote")) { db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid); $mid = 0; + $output = status("Vote saved"); } else if ($op == t("Delete vote")) { db_query("DELETE FROM {moderation_votes} WHERE mid = %d", $mid); db_query("DELETE FROM {moderation_roles} WHERE mid = %d", $mid); $mid = 0; + $output = status("Vote deleted"); } else if ($op == t("Add new vote")) { db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]); $mid = 0; + $output = status("Vote added"); } $output .= "<h3>" . t("Moderation votes overview") . "</h3>"; @@ -1059,7 +1073,7 @@ function comment_mod_votes($edit) { $vote = db_fetch_object(db_query("SELECT vote, weight FROM {moderation_votes} WHERE mid = %d", $mid)); } - $output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ."moderation option</h3>"; + $output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ." moderation option</h3>"; $form .= form_textfield(t("Vote"), "vote", $vote->vote, 32, 64, t("The name of this vote. Example: 'off topic', 'excellent', 'sucky'.")); $form .= form_textfield(t("Weight"), "weight", $vote->weight, 32, 64, t("Used to order votes in the comment control box; heavier sink.")); if ($mid) { @@ -1083,14 +1097,17 @@ function comment_mod_filters($edit) { if ($op == t("Save threshold")) { db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid); $fid = 0; + $output = status("Saved threshold"); } else if ($op == t("Delete threshold")) { db_query("DELETE FROM {moderation_filters} WHERE fid = %d", $fid); $fid = 0; + $output = status("Deleted threshold"); } else if ($op == t("Add new threshold")) { db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]); $fid = 0; + $output = status("Added threshold"); } $output .= "<h3>Comment threshold overview</h3>"; diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 5ac4815ac..3c4d9920c 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -60,7 +60,7 @@ function comment_help($section = "admin/comment/help") { $output .= "<p>So that users know how their votes affect the comment, these examples include the vote value as part of the label, although that is optional.</p>"; $output .= "<p>Using the weight option, you can control the order in which the votes appear to users. Setting the weight heavier (positive numbers) will make the vote label appear at the bottom of the list. Lighter (a negative number) will push it to the top. To encourage positive voting, a useful order might be higher values, positive votes, at the top, with negative votes at the bottom.</p>"; - $output .= "<h4>Moderators/vote values matrix</h4>"; + $output .= "<h4>Moderator vote/values matrix</h4>"; $output .= strtr("<p>Next go to %comment-matrix. Enter the values for the vote labels for each permission role in the vote matrix. The values entered here will be used to create the rating for each comment.</p>", array("%comment-matrix" => l(t("comment management » comment moderation » matrix"), "admin/comment/moderation/,atrix") )); $output .= "<p>NOTE: Comment ratings are calculated by averaging user votes with the initial rating.</p>"; @@ -814,7 +814,7 @@ function comment_link($type, $node = 0, $main = 0) { menu("admin/comment/moderation/votes", "votes", "comment_admin", comment_help("admin/comment/moderation/votes")); menu("admin/comment/moderation/matrix", "matrix", "comment_admin", comment_help("admin/comment/moderation/matrix")); menu("admin/comment/moderation/filters", "thresholds", "comment_admin", comment_help("admin/comment/moderation/filters")); - menu("admin/comment/roles", "initial comment scores", "comment_admin", comment_help("admin/comment/roles"), 6); + menu("admin/comment/moderation/roles", "initial comment scores", "comment_admin", comment_help("admin/comment/roles"), 6); } } @@ -948,15 +948,24 @@ function comment_save($id, $edit) { function comment_admin_overview($status = 0) { - $result = pager_query("SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.status = '". check_query($status). "' ORDER BY c.timestamp DESC", 50); + $header = array( + array("data" => t("Subject"), "field" => "subject"), + array("data" => t("Author"), "field" => "u.name"), + array("data" => t("Status"), "field" => "status"), + array("data" => t("Time"), "field" => "timestamp", "sort" => "desc"), + array("data" => t("operations"), "colspan" => 2) + ); + + $sql = "SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.status = ". check_query($status); + $sql .= tablesort_sql($header); + $result = pager_query($sql, 50); - $header = array(t("subject"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2)); while ($comment = db_fetch_object($result)) { - $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid")); + $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". format_date($comment->timestamp, "small"). "</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid")); } - if ($pager = pager_display(NULL, 50, 0, "admin")) { - $rows[] = array(array("data" => $pager, "colspan" => 5)); + if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) { + $rows[] = array(array("data" => $pager, "colspan" => 6)); } return table($header, $rows); @@ -964,7 +973,7 @@ function comment_admin_overview($status = 0) { function comment_mod_matrix($edit) { - $output .= "<h3>Moderators/vote values matrix</h3>"; + $output .= "<h3>Moderation vote/value matrix</h3>"; if ($edit) { db_query("DELETE FROM {moderation_roles} "); @@ -974,6 +983,7 @@ function comment_mod_matrix($edit) { } } db_query("INSERT INTO {moderation_roles} (mid, rid, value) VALUES ". implode(", ", $sql)); + $output = status("Vote values saved"); } $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'"); @@ -1009,6 +1019,7 @@ function comment_mod_roles($edit) { if ($edit) { variable_set("comment_roles", $edit); + $output = status("Comment scores saved"); } $start_values = variable_get("comment_roles", array()); @@ -1035,15 +1046,18 @@ function comment_mod_votes($edit) { if ($op == t("Save vote")) { db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid); $mid = 0; + $output = status("Vote saved"); } else if ($op == t("Delete vote")) { db_query("DELETE FROM {moderation_votes} WHERE mid = %d", $mid); db_query("DELETE FROM {moderation_roles} WHERE mid = %d", $mid); $mid = 0; + $output = status("Vote deleted"); } else if ($op == t("Add new vote")) { db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]); $mid = 0; + $output = status("Vote added"); } $output .= "<h3>" . t("Moderation votes overview") . "</h3>"; @@ -1059,7 +1073,7 @@ function comment_mod_votes($edit) { $vote = db_fetch_object(db_query("SELECT vote, weight FROM {moderation_votes} WHERE mid = %d", $mid)); } - $output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ."moderation option</h3>"; + $output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ." moderation option</h3>"; $form .= form_textfield(t("Vote"), "vote", $vote->vote, 32, 64, t("The name of this vote. Example: 'off topic', 'excellent', 'sucky'.")); $form .= form_textfield(t("Weight"), "weight", $vote->weight, 32, 64, t("Used to order votes in the comment control box; heavier sink.")); if ($mid) { @@ -1083,14 +1097,17 @@ function comment_mod_filters($edit) { if ($op == t("Save threshold")) { db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid); $fid = 0; + $output = status("Saved threshold"); } else if ($op == t("Delete threshold")) { db_query("DELETE FROM {moderation_filters} WHERE fid = %d", $fid); $fid = 0; + $output = status("Deleted threshold"); } else if ($op == t("Add new threshold")) { db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]); $fid = 0; + $output = status("Added threshold"); } $output .= "<h3>Comment threshold overview</h3>"; diff --git a/modules/forum.module b/modules/forum.module index e1ce357af..942874299 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -145,7 +145,6 @@ function forum_link($type, $node = 0, $main = 0) { function forum_view($node, $main = 0) { - $term_data = array_shift(taxonomy_node_get_terms($node->nid)); if (!$term_data) { // we are previewing @@ -319,15 +318,28 @@ function _forum_last_post($term) { } function forum_get_topics($tid, $sortby, $forum_per_page) { - global $user; + global $user, $forum_topic_list_header; - $term = taxonomy_get_term($tid); - $voc = taxonomy_get_vocabulary($term->vid); + $forum_topic_list_header = array( + array("data" => t("Topic"), "field" => "n.title", "colspan" => "2"), + array("data" => t("Replies"),"field" => "num_comments"), + array("data" => t("Created"), "field" => "n.created"), + array("data" => t("Last reply"), "field" => "date_sort", "sort" => "desc"), + ); $sql_sortby = _forum_get_topic_order($sortby); + for ($i=0; $i < count($forum_topic_list_header); $i++) { + if ($forum_topic_list_header[$i]["field"] == $sql_sortby) { + $forum_topic_list_header[$i]["order"] = $sql_sortby; + } + } + + $term = taxonomy_get_term($tid); + $voc = taxonomy_get_vocabulary($term->vid); // show topics with the correct tid, or in the forum but with shadow = 1 - $sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid ORDER BY $sql_sortby"; + $sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid"; + $sql .= tablesort_sql($forum_topic_list_header); $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum'"; @@ -527,42 +539,12 @@ function forum_theme_list($forums, $parents, $tid) { return table($header, $rows); } -function forum_theme_topic_browser() { - global $tid, $sortby, $forum_per_page, $offset; - - if (empty($sortby)) { - $sortby = variable_get("forum_order",1); - } - if (empty($forum_per_page)) { - $forum_per_page = variable_get("forum_per_page", 25); - } - - $forum_per_page_options = array(10, 25, 50, 75, 100); - foreach ($forum_per_page_options as $value) { - $options .= " <option value=\"$value\"". ($forum_per_page == $value ? " selected=\"selected\"" : "") .">".t("%a topics per page", array("%a" => $value))."</option>\n"; - } - - $output .= "<select name=\"forum_per_page\">$options</select>\n"; - - $options = ""; - $sortby_options = array(1 => t("Date - newest first"), 2 => t("Date - oldest first"), 3 => t("Posts - most active first"), 4=> t("Posts - least active first")); - foreach ($sortby_options as $key => $value) { - $options .= " <option value=\"$key\"". ($sortby == $key ? " selected=\"selected\"" : "") .">$value</option>\n"; - } - - $output .= "\n<select name=\"sortby\">$options</select>\n"; - $output .= form_hidden("tid", $tid); - $output .= form_submit(t("Update settings")); - return form($output); -} function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset) { - global $id, $status, $user, $pager_total; + global $id, $status, $user, $pager_total, $forum_topic_list_header; if ($topics) { - $header = array(array("data" => t("Topic"), "colspan" => "2"), t("Replies"), t("Created"), t("Last reply")); - foreach ($topics as $topic) { // folder is new if topic is new or there are new comments since last visit if ($topic->tid != $tid) { @@ -583,10 +565,7 @@ function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset } } - $rows[] = array(array("data" => t("%a topics, %b topics per page, page %c of %d", array("%a" => $pager_total[0], "%b" => $forum_per_page, "%c" => $offset, "%d" => ceil($pager_total[0]/$forum_per_page))), "colspan" => "5", "class" => "statistics")); - $rows[] = array(array("data" => theme("forum_theme_topic_browser", $sortby, $forum_per_page, $offset), "colspan" => "5", "class" => "settings")); - - if ($pager = pager_display(NULL, $forum_per_page, 0, "default")) { + if ($pager = pager_display(NULL, $forum_per_page, 0, "default", tablesort_pager())) { $rows[] = array(array("data" => $pager, "colspan" => "5", "class" => "pager")); } } @@ -596,7 +575,7 @@ function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset $output = l(t("create new forum topic"), "node/add/forum/$tid") ."<br /><br />"; } - $output .= table($header, $rows); + $output .= table($forum_topic_list_header, $rows); return $output; } diff --git a/modules/forum/forum.module b/modules/forum/forum.module index e1ce357af..942874299 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -145,7 +145,6 @@ function forum_link($type, $node = 0, $main = 0) { function forum_view($node, $main = 0) { - $term_data = array_shift(taxonomy_node_get_terms($node->nid)); if (!$term_data) { // we are previewing @@ -319,15 +318,28 @@ function _forum_last_post($term) { } function forum_get_topics($tid, $sortby, $forum_per_page) { - global $user; + global $user, $forum_topic_list_header; - $term = taxonomy_get_term($tid); - $voc = taxonomy_get_vocabulary($term->vid); + $forum_topic_list_header = array( + array("data" => t("Topic"), "field" => "n.title", "colspan" => "2"), + array("data" => t("Replies"),"field" => "num_comments"), + array("data" => t("Created"), "field" => "n.created"), + array("data" => t("Last reply"), "field" => "date_sort", "sort" => "desc"), + ); $sql_sortby = _forum_get_topic_order($sortby); + for ($i=0; $i < count($forum_topic_list_header); $i++) { + if ($forum_topic_list_header[$i]["field"] == $sql_sortby) { + $forum_topic_list_header[$i]["order"] = $sql_sortby; + } + } + + $term = taxonomy_get_term($tid); + $voc = taxonomy_get_vocabulary($term->vid); // show topics with the correct tid, or in the forum but with shadow = 1 - $sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid ORDER BY $sql_sortby"; + $sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid"; + $sql .= tablesort_sql($forum_topic_list_header); $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum'"; @@ -527,42 +539,12 @@ function forum_theme_list($forums, $parents, $tid) { return table($header, $rows); } -function forum_theme_topic_browser() { - global $tid, $sortby, $forum_per_page, $offset; - - if (empty($sortby)) { - $sortby = variable_get("forum_order",1); - } - if (empty($forum_per_page)) { - $forum_per_page = variable_get("forum_per_page", 25); - } - - $forum_per_page_options = array(10, 25, 50, 75, 100); - foreach ($forum_per_page_options as $value) { - $options .= " <option value=\"$value\"". ($forum_per_page == $value ? " selected=\"selected\"" : "") .">".t("%a topics per page", array("%a" => $value))."</option>\n"; - } - - $output .= "<select name=\"forum_per_page\">$options</select>\n"; - - $options = ""; - $sortby_options = array(1 => t("Date - newest first"), 2 => t("Date - oldest first"), 3 => t("Posts - most active first"), 4=> t("Posts - least active first")); - foreach ($sortby_options as $key => $value) { - $options .= " <option value=\"$key\"". ($sortby == $key ? " selected=\"selected\"" : "") .">$value</option>\n"; - } - - $output .= "\n<select name=\"sortby\">$options</select>\n"; - $output .= form_hidden("tid", $tid); - $output .= form_submit(t("Update settings")); - return form($output); -} function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset) { - global $id, $status, $user, $pager_total; + global $id, $status, $user, $pager_total, $forum_topic_list_header; if ($topics) { - $header = array(array("data" => t("Topic"), "colspan" => "2"), t("Replies"), t("Created"), t("Last reply")); - foreach ($topics as $topic) { // folder is new if topic is new or there are new comments since last visit if ($topic->tid != $tid) { @@ -583,10 +565,7 @@ function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset } } - $rows[] = array(array("data" => t("%a topics, %b topics per page, page %c of %d", array("%a" => $pager_total[0], "%b" => $forum_per_page, "%c" => $offset, "%d" => ceil($pager_total[0]/$forum_per_page))), "colspan" => "5", "class" => "statistics")); - $rows[] = array(array("data" => theme("forum_theme_topic_browser", $sortby, $forum_per_page, $offset), "colspan" => "5", "class" => "settings")); - - if ($pager = pager_display(NULL, $forum_per_page, 0, "default")) { + if ($pager = pager_display(NULL, $forum_per_page, 0, "default", tablesort_pager())) { $rows[] = array(array("data" => $pager, "colspan" => "5", "class" => "pager")); } } @@ -596,7 +575,7 @@ function forum_theme_topic_list($tid, $topics, $sortby, $forum_per_page, $offset $output = l(t("create new forum topic"), "node/add/forum/$tid") ."<br /><br />"; } - $output .= table($header, $rows); + $output .= table($forum_topic_list_header, $rows); return $output; } diff --git a/modules/node.module b/modules/node.module index e87cbff53..a1923ad33 100644 --- a/modules/node.module +++ b/modules/node.module @@ -241,6 +241,8 @@ function node_load($conditions, $revision = -1) { ** Unserialize the revisions field: */ +print "wa: $node->title"; + if ($node->revisions) { $node->revisions = unserialize($node->revisions); } @@ -676,7 +678,7 @@ function node_admin_nodes() { */ $result = pager_query("SELECT n.*, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid ". $filters[$filter][1], 50); - $header = array(NULL, t("title"), t("type"), t("author"), t("status"), t("operations")); + $header = array(t("title"), t("type"), t("author"), t("status"), array ("data" => t("operations"), "colspan" => 2)); while ($node = db_fetch_object($result)) { $rows[] = array(l($node->title, node_url($node)) ." ". (node_is_new($node->nid, $node->changed) ? theme_mark() : ""), module_invoke($node->type, "node", "name"), format_name($node), ($node->status ? t("published") : t("not published")), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid")); diff --git a/modules/node/node.module b/modules/node/node.module index e87cbff53..a1923ad33 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -241,6 +241,8 @@ function node_load($conditions, $revision = -1) { ** Unserialize the revisions field: */ +print "wa: $node->title"; + if ($node->revisions) { $node->revisions = unserialize($node->revisions); } @@ -676,7 +678,7 @@ function node_admin_nodes() { */ $result = pager_query("SELECT n.*, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid ". $filters[$filter][1], 50); - $header = array(NULL, t("title"), t("type"), t("author"), t("status"), t("operations")); + $header = array(t("title"), t("type"), t("author"), t("status"), array ("data" => t("operations"), "colspan" => 2)); while ($node = db_fetch_object($result)) { $rows[] = array(l($node->title, node_url($node)) ." ". (node_is_new($node->nid, $node->changed) ? theme_mark() : ""), module_invoke($node->type, "node", "name"), format_name($node), ($node->status ? t("published") : t("not published")), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid")); diff --git a/modules/statistics.module b/modules/statistics.module index c8901874b..8a83afcb9 100644 --- a/modules/statistics.module +++ b/modules/statistics.module @@ -34,7 +34,7 @@ function statistics_init() { } } -// Footer hook, runs at the end of every page request +// Exit hook, runs at the end of every page request function statistics_exit() { global $user; @@ -113,23 +113,22 @@ function statistics_link($type, $node = 0, $main = 0) { if ($type == "admin" && (user_access("administer statistics module") || (user_access("administer statistics")))) { $help["statistics"] = t("This page gives you an at-a-glance look at your top nodes. It is useful for understanding what content on your site is the most popular."); - $help["referrers"] = t("This page shows you site-wide referrer statistics. You can see 'all referrers', 'external referrers' or 'internal referrers'. Defaults to 'external'. Referrers are web sites, both your site, and other peoples, that point to your web site."); + $help["referrers"] = t("This page shows you site-wide referrer statistics. You can see 'all referrers', 'external referrers' or 'internal referrers'. Referrers are web sites, both your site, and other peoples, that point to your web site."); $help["referrers-internal"] = t("This page shows you only 'internal referrers'. Links pointing to your web site, from within your web site."); $help["referrers-external"] = t("This page shows you only 'external referrers'. Links pointing to your web site from outside your web site."); - $help["access"] = t("This pages shows you who is accessing your web site. You can see the hostnames, referrers. In particular, it is easy to inspect a user's navigation history/trail by clicking the username."); + $help["access"] = t("This pages shows you who is accessing your web site. You can see the hostnames, referrers. In particular, it is easy to inspect a user's navigation history/trail by clicking on <i>track user</i>."); $help["top nodes page"] = t("The statistics module creates a user page that can display summaries of the day's top viewed nodes, the all time top nodes and the last nodes viewed. Each of these summaries can be enabled or disabled individually, and the number of nodes displayed for each can be configured with a drop down menu."); $help["top nodes block"] = t("The statistics module exports a block that can display the top viewed nodes of the day, the all time top viewed nodes and the last nodes viewed. Each of these links can be enabled or disabled individually, and the number of nodes displayed for each can be configured with a drop down menu. If you disable all sections of this block, it will not appear."); $help["who is online block"] = t("The statistics module exports a block that can display how many user's and guests are currently online. You can configure the name of the block, the name of a sub-block for displaying names of user's currently online, how recently a user must have been active to be considered online, the maximum characters to display from a user's name and the maximum number of user names to display."); menu("admin/statistics", "site statistics", "statistics_admin", $help["statistics"], 6); - menu("admin/statistics/statistics", "most popular posts", "statistics_admin", $help["statistics"]); menu("admin/statistics/referrers", "referrer log", "statistics_admin", $help["referrers"]); menu("admin/statistics/referrers/internal", "internal referrers only", "statistics_admin", $help["referrers-internal"]); menu("admin/statistics/referrers/external", "external referrers only", "statistics_admin", $help["referrers-external"]); menu("admin/statistics/log", "access log", "statistics_admin", $help["access"]); - menu("admin/statistics/log/node", "track node", "statistics_admin", $help["access"], 0, 1); - menu("admin/statistics/log/user", "track user", "statistics_admin", $help["access"], 0, 1); - menu("admin/statistics/log/host", "track host", "statistics_admin", $help["access"], 0, 1); + menu("admin/statistics/log/node", "track node", "statistics_admin", $help["access"], 0, 1); //hidden + menu("admin/statistics/log/user", "track user", "statistics_admin", $help["access"], 0, 1); //hidden + menu("admin/statistics/log/host", "track host", "statistics_admin", $help["access"], 0, 1); //hidden menu("admin/statistics/top nodes page", "configure 'top nodes' page", "statistics_admin", $help["top nodes page"], 5); menu("admin/statistics/help", "help", "statistics_help", NULL, 9); @@ -204,9 +203,9 @@ function statistics_admin() { /* non-configuration admin pages */ switch ($op) { case "statistics": - return statistics_admin_displaycounts(); + return statistics_admin_topnodes(); case "referrers": - return statistics_recent_refer() . statistics_top_refer(); + return statistics_top_refer(); case "log": return statistics_admin_displaylog(); } @@ -252,22 +251,32 @@ function statistics_admin() { "statistics_userpage_last_cnt" => variable_get("statistics_userpage_last_cnt", 0) )); default: - return statistics_admin_displaycounts(); + return statistics_admin_topnodes(); } } } } -/* Displays the various admin tables */ -function statistics_admin_count_table($dbfield, $dbrows) { - $result = db_query_range("SELECT s.nid, s.daycount, s.totalcount, s.timestamp, n.title FROM {statistics} s INNER JOIN {node} n USING (nid) WHERE s.%s <> '0' ORDER BY s.%s DESC", $dbfield, $dbfield, 0, $dbrows); +function statistics_admin_topnodes_table() { - $header = array(t("title"), t("today"), t("all time"), t("last hit"), t("operations")); + $header = array( + array("data" => t("title"), "field" => "n.title"), + array("data" => t("today"), "field" => "s.daycount", "sort" => "desc"), + array("data" => t("all time"), "field" => "s.totalcount"), + array("data" => t("last hit"), "field" => "s.timestamp"), + array("data" => t("operations")) + ); + $sql = "SELECT s.nid, s.daycount, s.totalcount, s.timestamp, n.title FROM {statistics} s INNER JOIN {node} n USING (nid)"; + $sql .= tablesort_sql($header); + $result = pager_query($sql, 5); // WHERE s.%s <> '0' while ($nid = db_fetch_array($result)) { $rows[] = array(l($nid["title"], "node/view/". $nid["nid"], array("title" => t("View this posting."))), $nid["daycount"], $nid["totalcount"], format_date($nid["timestamp"], "small"), l("track node", "admin/statistics/log/node/$nid[nid]")); } + if ($pager = pager_display(NULL, 5, 0, "admin", tablesort_pager())) { + $rows[] = array(array("data" => $pager, "colspan" => 5)); + } return table($header, $rows); } @@ -279,28 +288,37 @@ function statistics_admin_accesslog_table($type, $id) { /* retrieve user access logs */ if ($id) { /* retrieve recent access logs for user $id */ - $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE uid = '". check_query($id) ."' ORDER BY timestamp DESC", 50); + $sql = "SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE uid = ". check_query($id); } else { /* retrieve recent access logs for all users */ - $result = pager_query("SELECT nid, url, hostname, uid, MAX(timestamp) AS timestamp FROM {accesslog} WHERE uid <> '0' GROUP BY uid, nid, url, hostname ORDER BY timestamp DESC", 50); + $sql = "SELECT nid, url, hostname, uid, MAX(timestamp) AS timestamp FROM {accesslog} WHERE uid <> '0' GROUP BY uid, nid, url, hostname"; } } else if ($type == 2) { /* retrieve recent access logs for node $id */ - $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE nid = '". check_query($id) ."' ORDER BY timestamp DESC", 50); + $sql = "SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE nid = ". check_query($id); } else if ($type == 3) { /* retrieve recent access logs for hostname $id */ - $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE hostname = '". check_query($id) ."' ORDER BY timestamp DESC", 50); + $sql = "SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE hostname = ". check_query($id); } else { /* retrieve all recent access logs */ - $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} ORDER BY timestamp DESC", 50); + $sql = "SELECT nid, url, hostname, uid, timestamp FROM {accesslog}"; } - $header = array(t("timestamp"), t("post"), t("user"), t("hostname"), t("referrer"), array("data" => t("operations"), "colspan" => "3")); + $header = array( + array("data" => t("timestamp"), "field" => "timestamp"), + array("data" => t("post"), "field" => "nid"), + array("data" => t("user"), "field" => "uid"), + array("data" => t("hostname"), "field" => "hostname"), + array("data" => t("referrer"), "field" => "url"), + array("data" => t("operations"), "colspan" => "3") + ); + $sql .= tablesort_sql($header); + $result = pager_query($sql, 50); while ($log = db_fetch_object($result)) { $user = user_load(array("uid" => $log->uid)); @@ -314,68 +332,48 @@ function statistics_admin_accesslog_table($type, $id) { $rows[] = array(array("data" => format_date($log->timestamp, "small"), "nowrap" => "nowrap"), ($node->nid ? l($node->title, node_url($node)) : message_na()), format_name($user), $log->hostname ? $log->hostname : message_na(), $url, ($log->nid ? l(t("track node"), "admin/statistics/log/node/$log->nid") : ""), ($user->uid ? l(t("track user"), "admin/statistics/log/user/$user->uid") : ""), ($log->hostname ? l(t("track host"), "admin/statistics/log/host/$log->hostname") : "")); } - if ($pager = pager_display(NULL, 50, 0, "admin")) { + if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) { $rows[] = array(array("data" => $pager, "colspan" => 8)); } return table($header, $rows); } - -function statistics_recent_refer() { - - $view = arg(3); - - if ($view == "all") { - $query = "SELECT url,timestamp FROM {accesslog} WHERE url <> '' ORDER BY timestamp DESC"; - } - elseif ($view == "internal") { - $query = "SELECT url,timestamp FROM {accesslog} WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' ORDER BY timestamp DESC"; - $describe = "internal "; - } - else { - $query = "SELECT url,timestamp FROM {accesslog} WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' ORDER BY timestamp DESC"; - $describe = "external "; - } - - $result = db_query_range($query, 0, 25); - $output = "<h3>". t("Most recent $describe referrers") ."</h3>"; - - $header = array(t("URL"), t("date")); - while ($referrer = db_fetch_array($result)) { - $rows[] = array("<a href=\"". $referrer["url"] ."\">". substr($referrer["url"], 0, 100) ."</a>", format_date($referrer["timestamp"], "small")); - } - - $output .= table($header, $rows); - - return $output; -} - - function statistics_top_refer() { - $view = arg(3); + $view = arg(3) ? arg(3) : "all"; if ($view == "all") { - $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url <> '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, MAX(timestamp) AS last_view, COUNT(url) AS count FROM {accesslog} WHERE url <> '' GROUP BY url"; + $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> ''"; } elseif ($view == "internal") { - $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, MAX(timestamp) AS last_view, COUNT(url) AS count FROM {accesslog} WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' GROUP BY url"; + $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%'"; $describe = "internal "; } else { /* default to external */ - $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, MAX(timestamp) AS last_view, COUNT(url) AS count FROM {accesslog} WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' GROUP BY url"; + $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%'"; $describe = "external "; } $output = "<h3>". t("Top $describe referrers of the past %interval", array("%interval" => format_interval(variable_get("statistics_flush_accesslog_timer", 259200)))) ."</h3>"; - $result = db_query($query); + $header = array( + array("data" =>t("URL"), "field" => "url"), + array("data" =>t("last view"), "field" => "last_view"), + array("data" => t("count"), "field" => "count", "sort" => "desc") + ); + $query .= tablesort_sql($header); + $result = pager_query($query, 50, 0, $query_cnt); - $header = array(t("URL"), t("count")); while ($referrer = db_fetch_array($result)) { - $rows[] = array("<a href=\"". $referrer["url"] ."\">". substr($referrer["url"], 0, 100) ."</a>", $referrer["count"]); + $rows[] = array("<a href=\"". $referrer["url"] ."\">". substr($referrer["url"], 0, 100) ."</a>", format_date($referrer["last_view"], "small"), $referrer["count"]); + } + if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) { + $rows[] = array(array("data" => $pager, "colspan" => 3)); } $output .= table($header, $rows); @@ -385,20 +383,10 @@ function statistics_top_refer() { } -function statistics_admin_displaycounts() { - - $output = "<h3>". t("Today's top nodes") ."</h3>\n"; - $output .= statistics_admin_count_table("daycount", 15); - - $output .= "<br />"; - - $output .= "<h3>". t("All time top nodes") ."</h3>\n"; - $output .= statistics_admin_count_table("totalcount", 15); - - $output .= "<br />"; +function statistics_admin_topnodes() { - $output .= "<h3>". t("Last nodes viewed") ."</h3>\n"; - $output .= statistics_admin_count_table("timestamp", 15); + $output = "<h3>". t("Top nodes") ."</h3>\n"; + $output .= statistics_admin_topnodes_table(); return $output; } diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index c8901874b..8a83afcb9 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -34,7 +34,7 @@ function statistics_init() { } } -// Footer hook, runs at the end of every page request +// Exit hook, runs at the end of every page request function statistics_exit() { global $user; @@ -113,23 +113,22 @@ function statistics_link($type, $node = 0, $main = 0) { if ($type == "admin" && (user_access("administer statistics module") || (user_access("administer statistics")))) { $help["statistics"] = t("This page gives you an at-a-glance look at your top nodes. It is useful for understanding what content on your site is the most popular."); - $help["referrers"] = t("This page shows you site-wide referrer statistics. You can see 'all referrers', 'external referrers' or 'internal referrers'. Defaults to 'external'. Referrers are web sites, both your site, and other peoples, that point to your web site."); + $help["referrers"] = t("This page shows you site-wide referrer statistics. You can see 'all referrers', 'external referrers' or 'internal referrers'. Referrers are web sites, both your site, and other peoples, that point to your web site."); $help["referrers-internal"] = t("This page shows you only 'internal referrers'. Links pointing to your web site, from within your web site."); $help["referrers-external"] = t("This page shows you only 'external referrers'. Links pointing to your web site from outside your web site."); - $help["access"] = t("This pages shows you who is accessing your web site. You can see the hostnames, referrers. In particular, it is easy to inspect a user's navigation history/trail by clicking the username."); + $help["access"] = t("This pages shows you who is accessing your web site. You can see the hostnames, referrers. In particular, it is easy to inspect a user's navigation history/trail by clicking on <i>track user</i>."); $help["top nodes page"] = t("The statistics module creates a user page that can display summaries of the day's top viewed nodes, the all time top nodes and the last nodes viewed. Each of these summaries can be enabled or disabled individually, and the number of nodes displayed for each can be configured with a drop down menu."); $help["top nodes block"] = t("The statistics module exports a block that can display the top viewed nodes of the day, the all time top viewed nodes and the last nodes viewed. Each of these links can be enabled or disabled individually, and the number of nodes displayed for each can be configured with a drop down menu. If you disable all sections of this block, it will not appear."); $help["who is online block"] = t("The statistics module exports a block that can display how many user's and guests are currently online. You can configure the name of the block, the name of a sub-block for displaying names of user's currently online, how recently a user must have been active to be considered online, the maximum characters to display from a user's name and the maximum number of user names to display."); menu("admin/statistics", "site statistics", "statistics_admin", $help["statistics"], 6); - menu("admin/statistics/statistics", "most popular posts", "statistics_admin", $help["statistics"]); menu("admin/statistics/referrers", "referrer log", "statistics_admin", $help["referrers"]); menu("admin/statistics/referrers/internal", "internal referrers only", "statistics_admin", $help["referrers-internal"]); menu("admin/statistics/referrers/external", "external referrers only", "statistics_admin", $help["referrers-external"]); menu("admin/statistics/log", "access log", "statistics_admin", $help["access"]); - menu("admin/statistics/log/node", "track node", "statistics_admin", $help["access"], 0, 1); - menu("admin/statistics/log/user", "track user", "statistics_admin", $help["access"], 0, 1); - menu("admin/statistics/log/host", "track host", "statistics_admin", $help["access"], 0, 1); + menu("admin/statistics/log/node", "track node", "statistics_admin", $help["access"], 0, 1); //hidden + menu("admin/statistics/log/user", "track user", "statistics_admin", $help["access"], 0, 1); //hidden + menu("admin/statistics/log/host", "track host", "statistics_admin", $help["access"], 0, 1); //hidden menu("admin/statistics/top nodes page", "configure 'top nodes' page", "statistics_admin", $help["top nodes page"], 5); menu("admin/statistics/help", "help", "statistics_help", NULL, 9); @@ -204,9 +203,9 @@ function statistics_admin() { /* non-configuration admin pages */ switch ($op) { case "statistics": - return statistics_admin_displaycounts(); + return statistics_admin_topnodes(); case "referrers": - return statistics_recent_refer() . statistics_top_refer(); + return statistics_top_refer(); case "log": return statistics_admin_displaylog(); } @@ -252,22 +251,32 @@ function statistics_admin() { "statistics_userpage_last_cnt" => variable_get("statistics_userpage_last_cnt", 0) )); default: - return statistics_admin_displaycounts(); + return statistics_admin_topnodes(); } } } } -/* Displays the various admin tables */ -function statistics_admin_count_table($dbfield, $dbrows) { - $result = db_query_range("SELECT s.nid, s.daycount, s.totalcount, s.timestamp, n.title FROM {statistics} s INNER JOIN {node} n USING (nid) WHERE s.%s <> '0' ORDER BY s.%s DESC", $dbfield, $dbfield, 0, $dbrows); +function statistics_admin_topnodes_table() { - $header = array(t("title"), t("today"), t("all time"), t("last hit"), t("operations")); + $header = array( + array("data" => t("title"), "field" => "n.title"), + array("data" => t("today"), "field" => "s.daycount", "sort" => "desc"), + array("data" => t("all time"), "field" => "s.totalcount"), + array("data" => t("last hit"), "field" => "s.timestamp"), + array("data" => t("operations")) + ); + $sql = "SELECT s.nid, s.daycount, s.totalcount, s.timestamp, n.title FROM {statistics} s INNER JOIN {node} n USING (nid)"; + $sql .= tablesort_sql($header); + $result = pager_query($sql, 5); // WHERE s.%s <> '0' while ($nid = db_fetch_array($result)) { $rows[] = array(l($nid["title"], "node/view/". $nid["nid"], array("title" => t("View this posting."))), $nid["daycount"], $nid["totalcount"], format_date($nid["timestamp"], "small"), l("track node", "admin/statistics/log/node/$nid[nid]")); } + if ($pager = pager_display(NULL, 5, 0, "admin", tablesort_pager())) { + $rows[] = array(array("data" => $pager, "colspan" => 5)); + } return table($header, $rows); } @@ -279,28 +288,37 @@ function statistics_admin_accesslog_table($type, $id) { /* retrieve user access logs */ if ($id) { /* retrieve recent access logs for user $id */ - $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE uid = '". check_query($id) ."' ORDER BY timestamp DESC", 50); + $sql = "SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE uid = ". check_query($id); } else { /* retrieve recent access logs for all users */ - $result = pager_query("SELECT nid, url, hostname, uid, MAX(timestamp) AS timestamp FROM {accesslog} WHERE uid <> '0' GROUP BY uid, nid, url, hostname ORDER BY timestamp DESC", 50); + $sql = "SELECT nid, url, hostname, uid, MAX(timestamp) AS timestamp FROM {accesslog} WHERE uid <> '0' GROUP BY uid, nid, url, hostname"; } } else if ($type == 2) { /* retrieve recent access logs for node $id */ - $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE nid = '". check_query($id) ."' ORDER BY timestamp DESC", 50); + $sql = "SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE nid = ". check_query($id); } else if ($type == 3) { /* retrieve recent access logs for hostname $id */ - $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE hostname = '". check_query($id) ."' ORDER BY timestamp DESC", 50); + $sql = "SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE hostname = ". check_query($id); } else { /* retrieve all recent access logs */ - $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} ORDER BY timestamp DESC", 50); + $sql = "SELECT nid, url, hostname, uid, timestamp FROM {accesslog}"; } - $header = array(t("timestamp"), t("post"), t("user"), t("hostname"), t("referrer"), array("data" => t("operations"), "colspan" => "3")); + $header = array( + array("data" => t("timestamp"), "field" => "timestamp"), + array("data" => t("post"), "field" => "nid"), + array("data" => t("user"), "field" => "uid"), + array("data" => t("hostname"), "field" => "hostname"), + array("data" => t("referrer"), "field" => "url"), + array("data" => t("operations"), "colspan" => "3") + ); + $sql .= tablesort_sql($header); + $result = pager_query($sql, 50); while ($log = db_fetch_object($result)) { $user = user_load(array("uid" => $log->uid)); @@ -314,68 +332,48 @@ function statistics_admin_accesslog_table($type, $id) { $rows[] = array(array("data" => format_date($log->timestamp, "small"), "nowrap" => "nowrap"), ($node->nid ? l($node->title, node_url($node)) : message_na()), format_name($user), $log->hostname ? $log->hostname : message_na(), $url, ($log->nid ? l(t("track node"), "admin/statistics/log/node/$log->nid") : ""), ($user->uid ? l(t("track user"), "admin/statistics/log/user/$user->uid") : ""), ($log->hostname ? l(t("track host"), "admin/statistics/log/host/$log->hostname") : "")); } - if ($pager = pager_display(NULL, 50, 0, "admin")) { + if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) { $rows[] = array(array("data" => $pager, "colspan" => 8)); } return table($header, $rows); } - -function statistics_recent_refer() { - - $view = arg(3); - - if ($view == "all") { - $query = "SELECT url,timestamp FROM {accesslog} WHERE url <> '' ORDER BY timestamp DESC"; - } - elseif ($view == "internal") { - $query = "SELECT url,timestamp FROM {accesslog} WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' ORDER BY timestamp DESC"; - $describe = "internal "; - } - else { - $query = "SELECT url,timestamp FROM {accesslog} WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' ORDER BY timestamp DESC"; - $describe = "external "; - } - - $result = db_query_range($query, 0, 25); - $output = "<h3>". t("Most recent $describe referrers") ."</h3>"; - - $header = array(t("URL"), t("date")); - while ($referrer = db_fetch_array($result)) { - $rows[] = array("<a href=\"". $referrer["url"] ."\">". substr($referrer["url"], 0, 100) ."</a>", format_date($referrer["timestamp"], "small")); - } - - $output .= table($header, $rows); - - return $output; -} - - function statistics_top_refer() { - $view = arg(3); + $view = arg(3) ? arg(3) : "all"; if ($view == "all") { - $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url <> '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, MAX(timestamp) AS last_view, COUNT(url) AS count FROM {accesslog} WHERE url <> '' GROUP BY url"; + $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> ''"; } elseif ($view == "internal") { - $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, MAX(timestamp) AS last_view, COUNT(url) AS count FROM {accesslog} WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' GROUP BY url"; + $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%'"; $describe = "internal "; } else { /* default to external */ - $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' GROUP BY url ORDER BY count DESC"; + $query = "SELECT url, MAX(timestamp) AS last_view, COUNT(url) AS count FROM {accesslog} WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' GROUP BY url"; + $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%'"; $describe = "external "; } $output = "<h3>". t("Top $describe referrers of the past %interval", array("%interval" => format_interval(variable_get("statistics_flush_accesslog_timer", 259200)))) ."</h3>"; - $result = db_query($query); + $header = array( + array("data" =>t("URL"), "field" => "url"), + array("data" =>t("last view"), "field" => "last_view"), + array("data" => t("count"), "field" => "count", "sort" => "desc") + ); + $query .= tablesort_sql($header); + $result = pager_query($query, 50, 0, $query_cnt); - $header = array(t("URL"), t("count")); while ($referrer = db_fetch_array($result)) { - $rows[] = array("<a href=\"". $referrer["url"] ."\">". substr($referrer["url"], 0, 100) ."</a>", $referrer["count"]); + $rows[] = array("<a href=\"". $referrer["url"] ."\">". substr($referrer["url"], 0, 100) ."</a>", format_date($referrer["last_view"], "small"), $referrer["count"]); + } + if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) { + $rows[] = array(array("data" => $pager, "colspan" => 3)); } $output .= table($header, $rows); @@ -385,20 +383,10 @@ function statistics_top_refer() { } -function statistics_admin_displaycounts() { - - $output = "<h3>". t("Today's top nodes") ."</h3>\n"; - $output .= statistics_admin_count_table("daycount", 15); - - $output .= "<br />"; - - $output .= "<h3>". t("All time top nodes") ."</h3>\n"; - $output .= statistics_admin_count_table("totalcount", 15); - - $output .= "<br />"; +function statistics_admin_topnodes() { - $output .= "<h3>". t("Last nodes viewed") ."</h3>\n"; - $output .= statistics_admin_count_table("timestamp", 15); + $output = "<h3>". t("Top nodes") ."</h3>\n"; + $output .= statistics_admin_topnodes_table(); return $output; } diff --git a/modules/tracker.module b/modules/tracker.module index 26fc8674a..31eefb0c2 100644 --- a/modules/tracker.module +++ b/modules/tracker.module @@ -27,14 +27,26 @@ function tracker_link($type) { function tracker_posts($id = 0) { + $header = array( + array("data" => t("Type"), "field" => "type"), + array("data" => t("Title"), "field" => "title"), + array("data" => t("Author"), "field" => "uid"), + array("data" => t("Last Post"), "field" => "last_activity", "sort" => "desc") + ); if ($id) { - $sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.uid = '". check_query($id) ."' AND n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'"); + + $sql = "SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.uid = '". check_query($id) ."' AND n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name"; + $sql .= tablesort_sql($header); + $sresult = pager_query($sql, 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'"); + } else { - $sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1"); - } - $header = array(t("Type"), t("Title"), t("Author")); + $sql = "SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name"; + $sql .= tablesort_sql($header); + $sresult = pager_query($sql, 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1"); + + } while ($node = db_fetch_object($sresult)) { if ($id) { @@ -60,11 +72,11 @@ function tracker_posts($id = 0) { $comments = ""; } - $rows[] = array(array("data" => $type, "class" => "type"), array("data" => $title . $comments, "class" => "content"), array("data" => $author, "class" => "author")); + $rows[] = array(array("data" => $type, "class" => "type"), array("data" => $title . $comments, "class" => "content"), array("data" => $author, "class" => "author"), array("data" => format_date($node->last_activity, "small"), "class" => "last_post")); } if ($pager = pager_display(NULL, 10)) { - $rows[] = array(array("data" => $pager, "colspan" => 3)); + $rows[] = array(array("data" => $pager, "colspan" => 4)); } $output = "<div id=\"tracker\">"; @@ -94,4 +106,4 @@ function tracker_page() { } } -?> +?>
\ No newline at end of file diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module index 26fc8674a..31eefb0c2 100644 --- a/modules/tracker/tracker.module +++ b/modules/tracker/tracker.module @@ -27,14 +27,26 @@ function tracker_link($type) { function tracker_posts($id = 0) { + $header = array( + array("data" => t("Type"), "field" => "type"), + array("data" => t("Title"), "field" => "title"), + array("data" => t("Author"), "field" => "uid"), + array("data" => t("Last Post"), "field" => "last_activity", "sort" => "desc") + ); if ($id) { - $sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.uid = '". check_query($id) ."' AND n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'"); + + $sql = "SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.uid = '". check_query($id) ."' AND n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name"; + $sql .= tablesort_sql($header); + $sresult = pager_query($sql, 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'"); + } else { - $sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1"); - } - $header = array(t("Type"), t("Title"), t("Author")); + $sql = "SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name"; + $sql .= tablesort_sql($header); + $sresult = pager_query($sql, 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1"); + + } while ($node = db_fetch_object($sresult)) { if ($id) { @@ -60,11 +72,11 @@ function tracker_posts($id = 0) { $comments = ""; } - $rows[] = array(array("data" => $type, "class" => "type"), array("data" => $title . $comments, "class" => "content"), array("data" => $author, "class" => "author")); + $rows[] = array(array("data" => $type, "class" => "type"), array("data" => $title . $comments, "class" => "content"), array("data" => $author, "class" => "author"), array("data" => format_date($node->last_activity, "small"), "class" => "last_post")); } if ($pager = pager_display(NULL, 10)) { - $rows[] = array(array("data" => $pager, "colspan" => 3)); + $rows[] = array(array("data" => $pager, "colspan" => 4)); } $output = "<div id=\"tracker\">"; @@ -94,4 +106,4 @@ function tracker_page() { } } -?> +?>
\ No newline at end of file diff --git a/modules/user.module b/modules/user.module index c05bec7c5..cae3014fc 100644 --- a/modules/user.module +++ b/modules/user.module @@ -1608,21 +1608,29 @@ function user_admin_edit($edit = array()) { function user_admin_account() { $query = arg(3); - $queries = array("ORDER BY u.timestamp DESC", "ORDER BY u.uid DESC", "WHERE u.status = 0 ORDER BY u.uid DESC"); + $queries = array("", "WHERE u.status = 0"); foreach (user_roles(1) as $key => $value) { - $queries[] = "WHERE r.name = '$value' ORDER BY u.uid DESC"; + $queries[] = "WHERE r.name = '$value'"; } - $result = pager_query("SELECT u.uid, u.name, u.timestamp FROM {role} r INNER JOIN {users} u ON r.rid = u.rid ". $queries[$query ? $query : 0], 50); + $sql = "SELECT u.uid, u.name, u.timestamp FROM {role} r INNER JOIN {users} u ON r.rid = u.rid ". $queries[$query ? $query : 0]; + + $header = array( + array ("data" => t("uid"), "field" => "u.uid"), + array ("data" => t("username"), "field" => "u.name"), + array ("data" => t("last access"), "field" => "u.timestamp", "sort" => "asc"), + t("operations") + ); + $sql .= tablesort_sql($header); + $result = pager_query($sql, 50); - $header = array(t("username"), t("last access"), t("operations")); while ($account = db_fetch_object($result)) { - $rows[] = array(format_name($account), format_date($account->timestamp, "small"), l(t("edit account"), "admin/user/edit/$account->uid")); + $rows[] = array($account->uid, format_name($account), format_date($account->timestamp, "small"), l(t("edit account"), "admin/user/edit/$account->uid")); } - $pager = pager_display(NULL, 50, 0, "admin"); + $pager = pager_display(NULL, 50, 0, "admin", tablesort_pager()); if (!empty($pager)) { - $rows[] = array(array("data" => $pager, "colspan" => 3)); + $rows[] = array(array("data" => $pager, "colspan" => 4)); } return table($header, $rows); } diff --git a/modules/user/user.module b/modules/user/user.module index c05bec7c5..cae3014fc 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1608,21 +1608,29 @@ function user_admin_edit($edit = array()) { function user_admin_account() { $query = arg(3); - $queries = array("ORDER BY u.timestamp DESC", "ORDER BY u.uid DESC", "WHERE u.status = 0 ORDER BY u.uid DESC"); + $queries = array("", "WHERE u.status = 0"); foreach (user_roles(1) as $key => $value) { - $queries[] = "WHERE r.name = '$value' ORDER BY u.uid DESC"; + $queries[] = "WHERE r.name = '$value'"; } - $result = pager_query("SELECT u.uid, u.name, u.timestamp FROM {role} r INNER JOIN {users} u ON r.rid = u.rid ". $queries[$query ? $query : 0], 50); + $sql = "SELECT u.uid, u.name, u.timestamp FROM {role} r INNER JOIN {users} u ON r.rid = u.rid ". $queries[$query ? $query : 0]; + + $header = array( + array ("data" => t("uid"), "field" => "u.uid"), + array ("data" => t("username"), "field" => "u.name"), + array ("data" => t("last access"), "field" => "u.timestamp", "sort" => "asc"), + t("operations") + ); + $sql .= tablesort_sql($header); + $result = pager_query($sql, 50); - $header = array(t("username"), t("last access"), t("operations")); while ($account = db_fetch_object($result)) { - $rows[] = array(format_name($account), format_date($account->timestamp, "small"), l(t("edit account"), "admin/user/edit/$account->uid")); + $rows[] = array($account->uid, format_name($account), format_date($account->timestamp, "small"), l(t("edit account"), "admin/user/edit/$account->uid")); } - $pager = pager_display(NULL, 50, 0, "admin"); + $pager = pager_display(NULL, 50, 0, "admin", tablesort_pager()); if (!empty($pager)) { - $rows[] = array(array("data" => $pager, "colspan" => 3)); + $rows[] = array(array("data" => $pager, "colspan" => 4)); } return table($header, $rows); } diff --git a/modules/watchdog.module b/modules/watchdog.module index 08863f15c..0d3165351 100644 --- a/modules/watchdog.module +++ b/modules/watchdog.module @@ -71,21 +71,36 @@ function watchdog_overview($type) { $color = array("user" => "#FFEEAA", "message" => "#FFFFFF", "special" => "#A49FFF", "warning" => "#FFAA22", "httpd" => "#99DD99", "error" => "#EE4C4C"); $query = array("user" => "WHERE type = 'user'", "regular" => "WHERE type = 'message'", "special" => "WHERE type = 'special'", "warning" => "WHERE type = 'warning'", "error" => "WHERE type = 'error'", "httpd" => "WHERE type = 'httpd'", "actions" => "WHERE link != ''"); - $result = pager_query("SELECT w.*, u.name, u.uid FROM {watchdog} w LEFT JOIN {users} u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY w.timestamp DESC", 50); + $header = array( + array("data" => t("date"), "field" => "w.timestamp", "sort" => "desc"), + array("data" => t("event"), "field" => "w.message"), + array("data" => t("user"), "field" => "u.name"), + array("data" => t("operations"), "colspan" => "2") + ); + $sql = "SELECT w.*, u.name, u.uid FROM {watchdog} w LEFT JOIN {users} u ON w.uid = u.uid ". ($type ? $query[$type] : ""); + $sql .= tablesort_sql($header); + $result = pager_query($sql, 50); while ($watchdog = db_fetch_object($result)) { if ($background = $color[$watchdog->type]) { - $data .= " <tr style=\"background-color: $background\"><td>". format_date($watchdog->timestamp, "small") ."</td><td>". substr(strip_tags($watchdog->message), 0, 64) ."</td><td style=\"text-align: center;\">". format_name($watchdog) ."</td><td style=\"text-align: center;\">$watchdog->link</td><td style=\"text-align: center;\">". l(t("view details"), "admin/watchdog/view/$watchdog->wid") ."</td></tr>"; + $rows[] = array( + array("data" => format_date($watchdog->timestamp, "small"), "style" => "background-color: $background"), + array("data" => substr(strip_tags($watchdog->message), 0, 64), "style" => "background-color: $background"), + array("data" => format_name($watchdog), "style" => "background-color: $background"), + array("data" => $watchdog->link, "style" => "background-color: $background"), + array("data" => l(t("view details"), "admin/watchdog/view/$watchdog->wid"), "style" => "background-color: $background") + ); } } - $output .= "<table>"; - $output .= " <tr><th>" . t("date") . "</th><th>" . t("event") . "</th><th>" . t("user") . "</th><th colspan=\"2\">" . t("operations") . "</th></tr>"; - $output .= ($data ? $data : "<tr><td style=\"text-align: center;\" colspan=\"4\">". t("No system messages currently available.") ."</td></tr>"); - $output .= (($pager = pager_display(NULL, 50, 0, "admin")) ? "<tr><td style=\"text-align: center;\" colspan=\"4\">$pager</td></tr>" : ""); - $output .= "</table>"; - - return $output; + if (!$rows) { + $rows[] = array(array("data" => t("No <i>%s</i> messages currently available.", array("%s" => $type)), "colspan" => "5")); + } + $pager = pager_display(NULL, 50, 0, "admin", tablesort_pager()); + if (!empty($pager)) { + $rows[] = array(array("data" => $pager, "colspan" => "5")); + } + return table($header, $rows); } function watchdog_view($id) { diff --git a/modules/watchdog/watchdog.module b/modules/watchdog/watchdog.module index 08863f15c..0d3165351 100644 --- a/modules/watchdog/watchdog.module +++ b/modules/watchdog/watchdog.module @@ -71,21 +71,36 @@ function watchdog_overview($type) { $color = array("user" => "#FFEEAA", "message" => "#FFFFFF", "special" => "#A49FFF", "warning" => "#FFAA22", "httpd" => "#99DD99", "error" => "#EE4C4C"); $query = array("user" => "WHERE type = 'user'", "regular" => "WHERE type = 'message'", "special" => "WHERE type = 'special'", "warning" => "WHERE type = 'warning'", "error" => "WHERE type = 'error'", "httpd" => "WHERE type = 'httpd'", "actions" => "WHERE link != ''"); - $result = pager_query("SELECT w.*, u.name, u.uid FROM {watchdog} w LEFT JOIN {users} u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY w.timestamp DESC", 50); + $header = array( + array("data" => t("date"), "field" => "w.timestamp", "sort" => "desc"), + array("data" => t("event"), "field" => "w.message"), + array("data" => t("user"), "field" => "u.name"), + array("data" => t("operations"), "colspan" => "2") + ); + $sql = "SELECT w.*, u.name, u.uid FROM {watchdog} w LEFT JOIN {users} u ON w.uid = u.uid ". ($type ? $query[$type] : ""); + $sql .= tablesort_sql($header); + $result = pager_query($sql, 50); while ($watchdog = db_fetch_object($result)) { if ($background = $color[$watchdog->type]) { - $data .= " <tr style=\"background-color: $background\"><td>". format_date($watchdog->timestamp, "small") ."</td><td>". substr(strip_tags($watchdog->message), 0, 64) ."</td><td style=\"text-align: center;\">". format_name($watchdog) ."</td><td style=\"text-align: center;\">$watchdog->link</td><td style=\"text-align: center;\">". l(t("view details"), "admin/watchdog/view/$watchdog->wid") ."</td></tr>"; + $rows[] = array( + array("data" => format_date($watchdog->timestamp, "small"), "style" => "background-color: $background"), + array("data" => substr(strip_tags($watchdog->message), 0, 64), "style" => "background-color: $background"), + array("data" => format_name($watchdog), "style" => "background-color: $background"), + array("data" => $watchdog->link, "style" => "background-color: $background"), + array("data" => l(t("view details"), "admin/watchdog/view/$watchdog->wid"), "style" => "background-color: $background") + ); } } - $output .= "<table>"; - $output .= " <tr><th>" . t("date") . "</th><th>" . t("event") . "</th><th>" . t("user") . "</th><th colspan=\"2\">" . t("operations") . "</th></tr>"; - $output .= ($data ? $data : "<tr><td style=\"text-align: center;\" colspan=\"4\">". t("No system messages currently available.") ."</td></tr>"); - $output .= (($pager = pager_display(NULL, 50, 0, "admin")) ? "<tr><td style=\"text-align: center;\" colspan=\"4\">$pager</td></tr>" : ""); - $output .= "</table>"; - - return $output; + if (!$rows) { + $rows[] = array(array("data" => t("No <i>%s</i> messages currently available.", array("%s" => $type)), "colspan" => "5")); + } + $pager = pager_display(NULL, 50, 0, "admin", tablesort_pager()); + if (!empty($pager)) { + $rows[] = array(array("data" => $pager, "colspan" => "5")); + } + return table($header, $rows); } function watchdog_view($id) { |