More database tweaks and improved access to forum search engine
authormoodler <moodler>
Mon, 23 Dec 2002 15:33:40 +0000 (15:33 +0000)
committermoodler <moodler>
Mon, 23 Dec 2002 15:33:40 +0000 (15:33 +0000)
admin/user.php
lib/datalib.php
mod/forum/discuss.php
mod/forum/index.php
mod/forum/lib.php
mod/forum/search.php
mod/forum/view.php

index 593a239..4749cd6 100644 (file)
@@ -6,8 +6,6 @@
 
     $recordsperpage = 30;
 
-    $db->debug = true;
-
     optional_variable($newuser, "");
     optional_variable($delete, "");
     optional_variable($confirm, "");
index 69d8eb5..32f94d0 100644 (file)
@@ -754,7 +754,8 @@ function get_users_longtimenosee($cutofftime) {
                                    {$CFG->prefix}user_students s
                              WHERE u.lastaccess > '0' 
                                AND u.lastaccess < '$cutofftime' 
-                               AND u.id = s.userid");
+                               AND u.id = s.userid
+                          GROUP BY u.id");
 }
 
 
index ed619bc..e5668d5 100644 (file)
 
     $navmiddle = "<A HREF=\"../forum/index.php?id=$course->id\">".get_string("forums", "forum")."</A> -> <A HREF=\"../forum/view.php?f=$forum->id\">$forum->name</A>";
 
+    $searchform = forum_print_search_form($course, $search, true, "plain");
+
     if ($course->category) {
         print_header("$course->shortname: $discussion->name", "$course->fullname",
                  "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
-                  $navmiddle -> $navtail", "", "", true, "", navmenu($course, $cm));
+                  $navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
     } else {
         print_header("$course->shortname: $discussion->name", "$course->fullname",
-                 "$navmiddle -> $navtail", "", "", true);
+                 "$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
     }
 
     forum_print_discussion($course, $forum, $discussion, $post, $displaymode);
index cdff434..672aebf 100644 (file)
     add_to_log($course->id, "forum", "view forums", "index.php?id=$course->id");
 
     $strforums = get_string("forums", "forum");
+    $strforum = get_string("forum", "forum");
+    $strdescription = get_string("description");
+    $strdiscussions = get_string("discussions", "forum");
+    $strsubscribed = get_string("subscribed", "forum");
+
+    $searchform = forum_print_search_form($course, "", true, "plain");
 
     if ($course->category) {
         print_header("$course->shortname: $strforums", "$course->fullname",
                     "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> $strforums",
-                    "", "", true, "", navmenu($course));
+                    "", "", true, $searchform, navmenu($course));
     } else {
-        print_header("$course->shortname: $strforums", "$course->fullname", "$strforums");
+        print_header("$course->shortname: $strforums", "$course->fullname", "$strforums", 
+                    "", "", true, $searchform, navmenu($course));
     }
-    $strforum = get_string("forum", "forum");
-    $strdescription = get_string("description");
-    $strdiscussions = get_string("discussions", "forum");
-    $strsubscribed = get_string("subscribed", "forum");
+
 
     $table->head  = array ($strforum, $strdescription, $strdiscussions);
     $table->align = array ("LEFT", "LEFT", "CENTER");
         }
     }
 
-    echo "<DIV ALIGN=CENTER>";
-    forum_print_search_form($course, $search);
-    echo "</DIV>";
 
     print_footer($course);
 
index 40271e4..f96685b 100644 (file)
@@ -408,7 +408,7 @@ function forum_get_child_posts($parent) {
 }
 
 
-function forum_search_posts($search, $courseid) {
+function forum_search_posts($search, $courseid, $page=0, $recordsperpage=50) {
 /// Returns a list of posts that were found
     global $CFG;
 
@@ -418,6 +418,13 @@ function forum_search_posts($search, $courseid) {
         $notteacherforum = "";
     }
 
+    if ($CFG->dbtype == "mysql") {
+        $limit = "LIMIT $page,$recordsperpage";
+    } else {
+        $limit = "LIMIT $recordsperpage,$page";
+    }
+
+
     return get_records_sql("SELECT p.*,u.firstname,u.lastname,u.email,u.picture
                             FROM {$CFG->prefix}forum_posts p,  
                                  {$CFG->prefix}forum_discussions d, 
@@ -429,7 +436,7 @@ function forum_search_posts($search, $courseid) {
                               AND d.course = '$courseid' 
                               AND d.forum = f.id 
                               $notteacherforum
-                         ORDER BY p.modified DESC LIMIT 0, 50");
+                         ORDER BY p.modified DESC $limit");
 }
 
 function forum_get_ratings($postid, $sort="u.firstname ASC") {
@@ -1016,18 +1023,30 @@ function forum_print_mode_form($discussion, $mode) {
     echo "</P></CENTER>\n";
 }
 
-function forum_print_search_form($course, $search="", $return=false) {
+function forum_print_search_form($course, $search="", $return=false, $type="") {
     global $CFG;
 
-    $output = "<TABLE BORDER=0 CELLPADDING=10 CELLSPACING=0><TR><TD ALIGN=CENTER>";
-    $output .= "<FORM NAME=search ACTION=\"$CFG->wwwroot/mod/forum/search.php\">";
-    $output .= "<FONT SIZE=\"-1\">";
-    $output .= "<INPUT NAME=search TYPE=text SIZE=15 VALUE=\"$search\"><BR>";
-    $output .= "<INPUT VALUE=\"".get_string("searchforums", "forum")."\" TYPE=submit>";
-    $output .= "</FONT>";
-    $output .= "<INPUT NAME=id TYPE=hidden VALUE=\"$course->id\">";
-    $output .= "</FORM>";
-    $output .= "</TD></TR></TABLE>";
+    if ($type == "plain") {
+        $output = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD NOWRAP>";
+        $output .= "<FORM NAME=search ACTION=\"$CFG->wwwroot/mod/forum/search.php\">";
+        $output .= "<FONT SIZE=\"-1\">";
+        $output .= "<INPUT NAME=search TYPE=text SIZE=15 VALUE=\"$search\">";
+        $output .= "<INPUT VALUE=\"".get_string("searchforums", "forum")."\" TYPE=submit>";
+        $output .= "</FONT>";
+        $output .= "<INPUT NAME=id TYPE=hidden VALUE=\"$course->id\">";
+        $output .= "</FORM>";
+        $output .= "</TD></TR></TABLE>";
+    } else {
+        $output = "<TABLE BORDER=0 CELLPADDING=10 CELLSPACING=0><TR><TD ALIGN=CENTER>";
+        $output .= "<FORM NAME=search ACTION=\"$CFG->wwwroot/mod/forum/search.php\">";
+        $output .= "<FONT SIZE=\"-1\">";
+        $output .= "<INPUT NAME=search TYPE=text SIZE=15 VALUE=\"$search\"><BR>";
+        $output .= "<INPUT VALUE=\"".get_string("searchforums", "forum")."\" TYPE=submit>";
+        $output .= "</FONT>";
+        $output .= "<INPUT NAME=id TYPE=hidden VALUE=\"$course->id\">";
+        $output .= "</FORM>";
+        $output .= "</TD></TR></TABLE>";
+    }
 
     if ($return) {
         return $output;
index ab0cf48..09314ce 100644 (file)
     $strsearch = get_string("search", "forum");
     $strsearchresults = get_string("searchresults", "forum");
 
+    $searchform = forum_print_search_form($course, $search, true, "plain");
+
     if ($search) {
         print_header("$course->shortname: $strsearchresults", "$course->fullname",
                  "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> -> 
                   <A HREF=\"index.php?id=$course->id\">$strforums</A> -> 
-                  <A HREF=\"search.php?id=$course->id\">$strsearch</A> -> \"$search\"", "search.search");
+                  <A HREF=\"search.php?id=$course->id\">$strsearch</A> -> \"$search\"", "search.search", 
+                  "", "",  $searchform);
     } else {
         print_header("$course->shortname: $strsearch", "$course->fullname",
                  "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> -> 
-                  <A HREF=\"index.php?id=$course->id\">$strforums</A> -> $strsearch", "search.search");
+                  <A HREF=\"index.php?id=$course->id\">$strforums</A> -> $strsearch", "search.search",
+                  "", "",  $searchform);
     }
 
-    echo "<DIV ALIGN=CENTER>";
-    forum_print_search_form($course, $search);
-    echo "</DIV>";
-
     if ($search) {
     
         if (!$posts = forum_search_posts($search, $course->id)) {
-            print_heading("<BR>".get_string("nopostscontaining", "forum", $search));
+            print_heading(get_string("nopostscontaining", "forum", $search));
 
         } else {
             foreach ($posts as $post) {
index 3b0ba90..0d61609 100644 (file)
@@ -40,6 +40,9 @@
         error("Must specify a course module or a forum ID");
     }
 
+    if (!$buttontext) {
+        $buttontext = forum_print_search_form($course, $search, true, "plain");
+    } 
 
     if ($course->category) {
         require_login($course->id);