[LON-CAPA-cvs] cvs: loncom /interface lonsearchcat.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 15 Mar 2006 20:56:17 -0000


This is a MIME encoded message

--albertel1142456177
Content-Type: text/plain

albertel		Wed Mar 15 15:56:17 2006 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  - converted to use the page start end helpers
  
  
--albertel1142456177
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20060315155617.txt"

Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.255 loncom/interface/lonsearchcat.pm:1.256
--- loncom/interface/lonsearchcat.pm:1.255	Mon Mar  6 13:23:10 2006
+++ loncom/interface/lonsearchcat.pm	Wed Mar 15 15:56:16 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.255 2006/03/06 18:23:10 www Exp $
+# $Id: lonsearchcat.pm,v 1.256 2006/03/15 20:56:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -198,18 +198,11 @@
                 &Apache::lonnet::logthis('lonsearchcat:'.
                                          'Unable to recover data from '.
                                          $persistent_db_file);
-		my $html=&Apache::lonxml::xmlbegin();
-		$r->print(<<END);
-$html
-<head>
-<title>LON-CAPA Search Error</title></head>
-$bodytag
-We were unable to retrieve data describing your search.  This is a serious
-error and has been logged.  Please alert your LON-CAPA administrator.
-</body>
-</html>
-END
-                return OK;
+		my $msg =
+		    'We were unable to retrieve data describing your search. '.
+		    'This is a serious error and has been logged. '.
+		    'Please alert your LON-CAPA administrator.';
+		return &error_page($r,$msg);
             }
         }
     } else {
@@ -229,10 +222,8 @@
 	} else {
             # This is a stupid error to give to the user.  
             # It really tells them nothing.
-	    my $html=&Apache::lonxml::xmlbegin();
-	    $r->print($html.'<head></head>'.$bodytag.
-                      'Unable to tie hash to db file</body></html>');
-	    return OK;
+	    my $msg = 'Unable to tie hash to db file.';
+	    return &error_page($r,$msg);
 	}
     }
     ##
@@ -369,33 +360,19 @@
             &Apache::lonnet::logthis('lonsearchcat.pm: Unable to create '.
                                      'needed table.  lonmysql error:'.
                                      $errorstring);
-	    my $html=&Apache::lonxml::xmlbegin();
-            $r->print(<<END);
-$html
-<head>
-<title>Search Error</title></head>
-$bodytag
-Unable to create table in which to store search results.  
-The search has been aborted.
-</body>
-</html>
-END
-            return OK;
+
+	    my $msg = 
+		'Unable to create table in which to store search results. '.
+		'The search has been aborted.';
+	    return &error_page($r,$msg);
         }
         delete($env{'form.launch'});
         if (! &make_form_data_persistent($r,$persistent_db_file)) {
-	    my $html=&Apache::lonxml::xmlbegin();
-	    $r->print(<<END);
-$html
-<head>
-<title>Search Error</title></head>
-$bodytag
-Unable to properly store search information.  The search has been aborted.
-</body>
-</html>
-END
-            return OK;
-        }
+	    my $msg=
+		'Unable to properly store search information. '.
+		'The search has been aborted.';
+            return &error_page($r,$msg);
+	}
         ##
         ## Print out the frames interface
         ##
@@ -406,6 +383,14 @@
     return OK;
 } 
 
+sub error_page {
+    my ($r,$msg) = @_;
+    $r->print(&Apache::loncommon::start_page('Search Error').
+	      &mt($msg).
+	      &Apache::loncommon::end_page());
+    return OK;
+}
+
 #
 # The mechanism used to store values away and retrieve them does not
 # handle the case of missing environment variables being significant.
@@ -467,7 +452,6 @@
 
 sub course_search {
     my $r=shift;
-    my $bodytag=&Apache::loncommon::bodytag('Course Search');
     my $pretty_search_string = '<b>'.$env{'form.courseexp'}.'</b>';
     my $search_string = $env{'form.courseexp'};
     my @New_Words;
@@ -484,9 +468,10 @@
     my $discuss=$env{'form.crsdiscuss'};
     my @allwords=($search_string,@New_Words);
     $totalfound=0;
-    my $html=&Apache::lonxml::xmlbegin();
-    $r->print($html.'<head><title>LON-CAPA Course Search</title></head>'.
-	      $bodytag.'<hr /><center><font size="+2" face="arial">'.$pretty_search_string.'</font></center><hr /><b>'.&mt('Course content').':</b><br />');
+    $r->print(&Apache::loncommon::start_page('Course Search').
+	      '<hr /><center><font size="+2" face="arial">'.
+	      $pretty_search_string.'</font></center>'.
+	      '<hr /><b>'.&mt('Course content').':</b><br />');
     $r->rflush();
 # ======================================================= Go through the course
     my $c=$r->connection;
@@ -584,7 +569,7 @@
     }
  
 # =================================================== Done going through course
-    $r->print('</body></html>');
+    $r->print(&Apache::loncommon::end_page());
 }
 
 # =============================== This pulls up a resource and its dependencies
@@ -660,16 +645,6 @@
 
 } # End of course search scoping
 
-sub search_html_header {
-    my $html=&Apache::lonxml::xmlbegin();
-    my $Str = <<ENDHEADER;
-$html
-<head>
-<title>The LearningOnline Network with CAPA</title>
-</head>
-ENDHEADER
-    return $Str;
-}
 
 ######################################################################
 ######################################################################
@@ -687,11 +662,11 @@
 sub print_basic_search_form {
     my ($r,$closebutton,$hidden_fields) = @_;
     my $result = ($env{'form.catalogmode'} ne 'groupsearch');
-    my $bodytag=&Apache::loncommon::bodytag('Search').
+    my $bread_crumb =
         &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Search_Basic',
                                    undef,undef,
                                    $env{'form.catalogmode'} ne 'groupsearch');
-    my $scrout = &search_html_header().$bodytag;
+    my $scrout = &Apache::loncommon::start_page('Search').$bread_crumb;
     if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) {
         # Define interface components
         my $userelatedwords= '<label>'.
@@ -802,10 +777,7 @@
 </form>
 ENDENDCOURSE
     }
-    $scrout.=(<<ENDDOCUMENT);
-</body>
-</html>
-ENDDOCUMENT
+    $scrout .= &Apache::loncommon::end_page();
     $r->print($scrout);
     return;
 }
@@ -824,7 +796,7 @@
 ######################################################################
 sub print_advanced_search_form{
     my ($r,$closebutton,$hidden_fields) = @_;
-    my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search').
+    my $bread_crumb = 
         &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching',
                                             'Search_Advanced',
                                             undef,undef,
@@ -837,9 +809,9 @@
 <input type="reset" name="reset" value='$lt{"reset"}' />
 $closebutton
 END
-    my $scrout=&search_html_header();
+    my $scrout= &Apache::loncommon::start_page('Advanced Catalog Search');
     $scrout .= <<"ENDHEADER";
-$bodytag
+$bread_crumb
 <form method="post" action="/adm/searchcat" name="advsearch">
 <p>
 $advanced_buttons
@@ -1034,9 +1006,8 @@
     $scrout.=<<ENDDOCUMENT;
 $advanced_buttons
 </form>
-</body>
-</html>
 ENDDOCUMENT
+    $scrout .= &Apache::loncommon::end_page();
     $r->print($scrout);
     return;
 }
@@ -2046,7 +2017,7 @@
     if (! defined($table) || $table eq '' || $table =~ /\D/ ) {
         $r->print("Unable to retrieve search results.  ".
                   "Unable to determine the table results were stored in.  ".
-                  "</body></html>");
+		  &Apache::loncommon::end_page());
         return undef;
     }
     ##
@@ -2055,7 +2026,8 @@
     my $connection_result = &Apache::lonmysql::connect_to_db();
     if (!defined($connection_result)) {
         $r->print("Unable to connect to the MySQL database where your results".
-                  " are stored. </body></html>");
+                  " are stored.".
+		  &Apache::loncommon::end_page());
         &Apache::lonnet::logthis("lonsearchcat: unable to get lonmysql to".
                                  " connect to database.");
         &Apache::lonnet::logthis(&Apache::lonmysql::get_error());
@@ -2063,7 +2035,8 @@
     }
     my $table_check = &Apache::lonmysql::check_table($table);
     if (! defined($table_check)) {
-        $r->print("A MySQL error has occurred.</form></body></html>");
+        $r->print("A MySQL error has occurred.</form>".
+		  &Apache::loncommon::end_page());
         &Apache::lonnet::logthis("lonmysql was unable to determine the status".
                                  " of table ".$table);
         return undef;
@@ -2121,17 +2094,20 @@
     ##
     my $total_results = &Apache::lonmysql::number_of_rows($table);
     if (! defined($total_results)) {
-        $r->print("A MySQL error has occurred.</form></body></html>");
+        $r->print("A MySQL error has occurred.</form>".
+		  &Apache::loncommon::end_page());
         &Apache::lonnet::logthis("lonmysql was unable to determine the number".
                                  " of rows in table ".$table);
         &Apache::lonnet::logthis(&Apache::lonmysql::get_error());
         return;
     }
     my $result;
-    my $html=&Apache::lonxml::xmlbegin();
+    my $html     = &Apache::lonxml::xmlbegin();
+    my $head     = &Apache::lonxml::headtag('Results');
+    my $end_head = &Apache::loncommon::endheadtag();
     $result.=<<END;
 $html
-<head>
+$head
 <script>
     function change_sort() {
         var newloc = "/adm/searchcat?phase=results";
@@ -2141,8 +2117,7 @@
         parent.resultsframe.location= newloc;
     }
 </script>
-<title>Results</title>
-</head>
+$end_head
 $bodytag
 <form name="statusform" action="" method="post">
 <input type="hidden" name="Queue" value="" />
@@ -2167,10 +2142,8 @@
 Search:$pretty_query_string
 </p>
 </form>
-</body>
-</html>
 END
-    $r->print($result);
+    $r->print($result.&Apache::loncommon::end_page());
     return;
 }
 
@@ -2370,11 +2343,11 @@
     #
     # Print run_search header
     #
-    my $html=&Apache::lonxml::xmlbegin();
+    my $html = &Apache::lonxml::xmlbegin();
+    my $head = &Apache::loncommon::head('Search Status');
     $r->print(<<END);
 $html
-<head>
-<title>Search Status</title></head>
+$head
 $bodytag
 <form name="statusform" action="" method="post">
 <input type="hidden" name="Queue" value="" />
@@ -2410,12 +2383,14 @@
     my $table =$env{'form.table'};
     if (! defined($table) || $table eq '' || $table =~ /\D/ ) {
         $r->print("Unable to determine table id to store search results in.".
-                  "The search has been aborted.</body></html>");
+                  "The search has been aborted.".
+		  &Apache::loncommon::end_page());
         return;
     }
     my $table_status = &Apache::lonmysql::check_table($table);
     if (! defined($table_status)) {
-        $r->print("Unable to determine status of table.</body></html>");
+        $r->print("Unable to determine status of table.".
+		  &Apache::loncommon::end_page());
         &Apache::lonnet::logthis("Bogus table id of $table for ".
                                  "$env{'user.name'} @ $env{'user.domain'}");
         &Apache::lonnet::logthis("lonmysql error = ".
@@ -2429,7 +2404,8 @@
                                  &Apache::lonmysql::get_debug());
         &Apache::lonnet::logthis('table status = "'.$table_status.'"');
         $r->print("The table id,$table, we tried to use is invalid.".
-                  "The search has been aborted.</body></html>");
+                  "The search has been aborted.".
+		  &Apache::loncommon::end_page());
         return;
     }
     ##
@@ -2558,7 +2534,7 @@
     # We have run out of time or run out of servers to talk to and
     # results to get, so let the client know the top frame needs to be
     # loaded from /adm/searchcat
-    $r->print("</body></html>");
+    $r->print(&Apache::loncommon::end_page());
 #    if ($env{'form.catalogmode'} ne 'groupsearch') {
         $r->print("<script>".
                       "window.location='/adm/searchcat?".
@@ -2637,7 +2613,8 @@
     if ($env{'form.catalogmode'} eq 'groupsearch') {
         if (! tie(%groupsearch_db,'GDBM_File',$diropendb,
                   &GDBM_WRCREAT(),0640)) {
-            $r->print('Unable to store import results.</form></body></html>');
+            $r->print('Unable to store import results.</form>'.
+		      &Apache::loncommon::end_page());
             $r->rflush();
             return;
         } 
@@ -2650,7 +2627,8 @@
     ## Get the number of results 
     my $total_results = &Apache::lonmysql::number_of_rows($table);
     if (! defined($total_results)) {
-        $r->print("A MySQL error has occurred.</form></body></html>");
+        $r->print("A MySQL error has occurred.</form>".
+		  &Apache::loncommon::end_page());
         &Apache::lonnet::logthis("lonmysql was unable to determine the number".
                                  " of rows in table ".$table);
         &Apache::lonnet::logthis(&Apache::lonmysql::get_error());
@@ -2757,9 +2735,10 @@
          &viewoptions().'</td></tr></table>'
          );
     if ($total_results == 0) {
-        $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2">'.
+        $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2" />'.
                   '<h3>'.&mt('There are currently no results').'.</h3>'.
-                  "</form></body></html>");
+                  "</form>".
+		  &Apache::loncommon::end_page());
         return;
     } else {
         $r->print('<center>'.
@@ -2822,7 +2801,7 @@
              ."</center>\n"
              );
     }
-    $r->print("</form></body></html>");
+    $r->print("</form>".&Apache::loncommon::end_page());
     $r->rflush();
     untie %groupsearch_db if (tied(%groupsearch_db));
     return;
@@ -3019,8 +2998,10 @@
 ######################################################################
 sub search_results_header {
     my ($importbutton,$closebutton) = @_;
-    my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
-    my $result = '';
+    my $result = 
+	&Apache::lonxml::xmlbegin().
+	&Apache::loncommon::headtag();
+
     # output beginning of search page
     # conditional output of script functions dependent on the mode in
     # which the search was invoked
@@ -3110,8 +3091,11 @@
     }
 </script>
 SCRIPT
+
+    my $end_head = &Apache::loncommon::endheadtag();
+    my $bodytag  = &Apache::loncommon::bodytag(undef,undef,undef,1);
     $result.=<<END;
-</head>
+$end_head
 $bodytag
 <form name="results" method="post" action="/adm/searchcat" >
 <input type="hidden" name="Queue" value="" />
@@ -3123,12 +3107,12 @@
 ######################################################################
 ######################################################################
 sub search_status_header {
-    my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
-    my $html=&Apache::lonxml::xmlbegin();
+    my $bodytag = &Apache::loncommon::bodytag(undef,undef,undef,1);
+    my $html    = &Apache::lonxml::xmlbegin();
+    my $head    = &Apache::loncommon::head('Search Status');
     return <<ENDSTATUS;
 $html
-<head>
-<title>Search Status</title></head>
+$head
 $bodytag
 <h3>Search Status</h3>
 Sending search request to LON-CAPA servers.<br />
@@ -3151,16 +3135,17 @@
         "&persistent_db_id=".$env{'form.persistent_db_id'};
     my $run_search_link = $basic_link."&phase=run_search";
     my $results_link = &results_link();
-    my $html=&Apache::lonxml::xmlbegin();
+    my $html     = &Apache::lonxml::xmlbegin();
+    my $head     = &Apache::loncommon::headtag('LON-CAPA Digital Library Search Results');
+    my $end_head = &Apache::loncommon::endheadtag();
     my $result = <<"ENDFRAMES";
 $html
-<head>
+$head
 <script>
 var targetwin = opener;
 var queue = '';
 </script>
-<title>LON-CAPA Digital Library Search Results</title>
-</head>
+$end_head
 <frameset rows="150,*">
     <frame name="statusframe"  src="$run_search_link">
     <frame name="resultsframe" src="$results_link">
@@ -3592,17 +3577,13 @@
     } else {
         $errorstring = &mt('Unable to understand the search phrase <b>[_1]</b>:<i>[_2]</i>.',$field,$env{'form.'.$field});
     }
-    my $bodytag = &Apache::loncommon::bodytag('Search');
     my $heading = &mt('Unparsed Field');
     my $revise  = &mt('Revise search request');
     # make query information persistent to allow for subsequent revision
-    my $html=&Apache::lonxml::xmlbegin();
+    my $start_page = &Apache::loncommon::start_page('Search');
+    my $end_page   = &Apache::loncommon::end_page();
     $r->print(<<ENDPAGE);
-$html
-<head>
-<title>The LearningOnline Network with CAPA</title>
-</head>
-$bodytag
+$start_page
 <form method="post" action="/adm/searchcat">
 $hidden_fields
 $closebutton
@@ -3614,8 +3595,7 @@
 <p>
 <a href="/adm/searchcat?$parms&persistent_db_id=$env{'form.persistent_db_id'}">$revise</a>
 </p>
-</body>
-</html>
+$end_page
 ENDPAGE
 }
 
@@ -3645,13 +3625,10 @@
     my $errormsg = &mt('You did not fill in enough information for the search to be started.  You need to fill in relevant fields on the search page in order for a query to be processed.');
     my $revise = &mt('Revise Search Request');
     my $heading = &mt('Unactionable Search Queary');
-    my $html=&Apache::lonxml::xmlbegin();
+    my $start_page = &Apache::loncommon::start_page('Search');
+    my $end_page   = &Apache::loncommon::end_page();
     $r->print(<<ENDPAGE);
-$html
-<head>
-<title>The LearningOnline Network with CAPA</title>
-</head>
-$bodytag
+$start_page
 <form method="post" action="/adm/searchcat">
 $hidden_fields
 $closebutton
@@ -3663,8 +3640,7 @@
 <p>
 <a href="/adm/searchcat?$parms&persistent_db_id=$env{'form.persistent_db_id'}">$revise</a>&nbsp;
 </p>
-</body>
-</html>
+$end_page
 ENDPAGE
     return;
 }
@@ -3691,16 +3667,10 @@
 sub output_date_error {
     my ($r,$message,$closebutton,$hidden_fields)=@_;
     # make query information persistent to allow for subsequent revision
-    my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
-    my $html=&Apache::lonxml::xmlbegin();
+    my $start_page = &Apache::loncommon::start_page('Search');
+    my $end_page   = &Apache::loncommon::end_page();
     $r->print(<<RESULTS);
-$html
-<head>
-<title>The LearningOnline Network with CAPA</title>
-</head>
-$bodytag
-<img align='right' src='/adm/lonIcons/lonlogos.gif' />
-<h1>Search Catalog</h1>
+$start_page
 <form method="post" action="/adm/searchcat">
 $hidden_fields
 <input type='button' value='Revise search request'
@@ -3711,8 +3681,7 @@
 <p>
 $message
 </p>
-</body>
-</html>
+$end_page
 RESULTS
 }
 

--albertel1142456177--