[LON-CAPA-cvs] cvs: modules /hoeppner lonsearch.pm lonsearchcat.pm

hoeppner lon-capa-cvs-allow@mail.lon-capa.org
Sun, 29 Jun 2008 00:22:16 -0000


This is a MIME encoded message

--hoeppner1214698936
Content-Type: text/plain

hoeppner		Sat Jun 28 20:22:16 2008 EDT

  Modified files:              
    /modules/hoeppner	lonsearch.pm lonsearchcat.pm 
  Log:
  update void of progress 
  
  
--hoeppner1214698936
Content-Type: text/plain
Content-Disposition: attachment; filename="hoeppner-20080628202216.txt"

Index: modules/hoeppner/lonsearch.pm
diff -u modules/hoeppner/lonsearch.pm:1.1 modules/hoeppner/lonsearch.pm:1.2
--- modules/hoeppner/lonsearch.pm:1.1	Sat Jun 28 16:00:01 2008
+++ modules/hoeppner/lonsearch.pm	Sat Jun 28 20:22:14 2008
@@ -23,7 +23,7 @@
 # database DEBUGrmation
 my $dsn = 'DBI:mysql:communities:localhost';
 my $db_user_name = 'root';
-my $db_password = 'password';
+my $db_password = 'holyday7';
 my ($id, $password);
 
 # $dbh is the database handle object
@@ -233,6 +233,36 @@
 	return $keywords;		
 }
 
+# returns the search_type of users last query
+sub getEvalType() {
+	my $user = $_[0];
+	my $logged_in_userid = &getCurrentId($user);
+	my $sql = "select action from communities.Evaluation where user=? and id=?";
+	my $stb = $dbh->prepare($sql)
+	        or die "Couldn't prepare statement: " . $dbh->errstr;
+	$stb->execute($user, $logged_in_userid);
+	my $action = $stb->fetchrow_array();
+	print DEBUG "FETCHED : " . $stb->err . $stb->errstr . "\n";
+	return $action;
+}
+
+sub createEvaluationRow_Copy() {
+	my $search_type = $_[0];
+	my $sort = $_[1];
+	my $rating = 0;
+	my $comment = 'none';
+	my $issuing_user = $_[2];
+	# create the row
+	my $insert = "INSERT INTO communities.Evaluation VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
+				my $stj = $dbh->prepare($insert)
+						        or die "Couldn't prepare statement: " . $dbh->errstr;
+				my @params = (&getCurrentId($issuing_user)+1,$issuing_user, $search_type, $rating, $comment, -1, -1, $sort);
+#				print DEBUG "---eval row with: @params \n";
+				$stj->execute(@params);
+				print DEBUG $stj->err . $stj->errstr;
+#				print DEBUG " created eval row\n";	
+}
+
 sub createEvaluationRow() {
 	my $user = $_[0]; # is that the start user or the issuing user?
 						# for filter: it's the start user ... another param for the issuing one..
@@ -259,10 +289,10 @@
 	my $rating = 0;
 	my $comment = 'none';
 	# create the row
-	my $insert = "INSERT INTO communities.Evaluation VALUES (?, ?, ?, ?, ?, ?, ?)";
+	my $insert = "INSERT INTO communities.Evaluation VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
 				my $stj = $dbh->prepare($insert)
 						        or die "Couldn't prepare statement: " . $dbh->errstr;
-				my @params = (&getCurrentId($issuing_user)+1,$issuing_user, $search_type, $rating, $comment, -1, -1);
+				my @params = (&getCurrentId($issuing_user)+1,$issuing_user, $search_type, $rating, $comment, -1, -1, "unknown");
 #				print DEBUG "---eval row with: @params \n";
 				$stj->execute(@params);
 				print DEBUG $stj->err . $stj->errstr;
@@ -291,6 +321,7 @@
 	createResultRow();
 }
 
+# last Id of evaluation that was a search ..
 sub getLastId() {
 	my $user = $_[0];
 	my $sql = "select max(id) from communities.Evaluation where user=? and action LIKE 'search;%'";
@@ -302,6 +333,19 @@
 	return $logged_in_userid;	
 }
 
+# last sort algorithm of evaluation that was a search ..
+sub getLastSort() {
+	my $user = $_[0];
+	my $id = &getLastId($user);
+	my $sql = "select sort from communities.Evaluation where id=?";
+	my $stb = $dbh->prepare($sql)
+	        or die "Couldn't prepare statement: " . $dbh->errstr;
+	$stb->execute($id);	
+	my $logged_in_userid = $stb->fetchrow_array(); # this is not user id but the current Evaluation id for the user
+	print DEBUG "query result: $logged_in_userid; status?:" .$stb->err . " ".$stb->errstr ." " . $dbh->errstr . "\n";
+	return $logged_in_userid;	
+}
+
 # extends the result list with all resources, that 
 # were used in the same course and were authored by a member of the start users SAC
 sub expandSAC() {
@@ -1255,6 +1299,18 @@
 	print DEBUG "$num results \n" ;
 }
 
+sub saveSort() {
+	my $sort = $_[0];
+	my $user = $_[1];
+	my $last_id = &getCurrentId($user);
+#	$last_id--; # to get the right row... obscure fix
+	print DEBUG "saving sort for ".$user. " " . $sort . " " .$last_id."\n";
+	my $sth = $dbh->prepare("UPDATE communities.Evaluation set sort=? where id=? and user=?")
+				            or die "Couldn't prepare statement: " . $dbh->errstr;;
+	$sth->execute($sort,$last_id,$user);
+	print DEBUG "---on saving total: " .$sth->err() . $sth->errstr() ."\n";	
+}
+
 sub createResultRow() {
 	my $url = $_[0];
 	my $extension = $_[1];
Index: modules/hoeppner/lonsearchcat.pm
diff -u modules/hoeppner/lonsearchcat.pm:1.1 modules/hoeppner/lonsearchcat.pm:1.2
--- modules/hoeppner/lonsearchcat.pm:1.1	Sat Jun 28 16:00:01 2008
+++ modules/hoeppner/lonsearchcat.pm	Sat Jun 28 20:22:14 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.1 2008/06/28 20:00:01 hoeppner Exp $
+# $Id: lonsearchcat.pm,v 1.2 2008/06/29 00:22:14 hoeppner Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -112,8 +112,9 @@
     my $file = '/home/httpd/perl/logs/test.log';		# Name the file
 	open(INFO, ">>$file");		# Open the file
 	INFO->autoflush(1);  
+	print INFO "---------------------------------------------- \n";
 	print INFO "handler: " . $ENV{'form.phase'} . "\n";
-	print INFO "#### before handler: " . $env{'form.table'};  
+#	print INFO "#### before handler: " . $env{'form.table'};  
     #
     # set form defaults
     #
@@ -142,12 +143,12 @@
     ## 
     ## Pick up form fields passed in the links.
     ##
+    
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
              ['catalogmode','launch','acts','mode','form','element','pause',
               'phase','persistent_db_id','table','start','show',
               'cleargroupsort','titleelement','area','inhibitmenu', 'algorithm', 'degree', 'connectivitywac', 
-              'connectivitysac', 'instances', 'proximity', 'username','sort', 'url_id', 'rating', 'comment']);      
-              
+              'connectivitysac', 'instances', 'proximity', 'username','sort', 'url_id', 'rating', 'comment']);       
               
     ##
     ## The following is a trick - we wait a few seconds if asked to so
@@ -352,7 +353,7 @@
                   bug=>'Searching',});
     }
 	   
-	print INFO "#### before switch: " . $env{'form.table'}  ;
+#	print INFO "#### before switch: " . $env{'form.table'} . "\n";
 	   
     ##
     ## Switch on the phase
@@ -368,8 +369,8 @@
     }  elsif ($env{'form.phase'} eq 'extenddirect') {
     	# TODO first ...use implementation and write results	
     	my $table = $env{'form.table'};
-    	print INFO 'calling expand with r: ' .$r ."\n";
-    	print INFO 'calling expand with table: ' .$table ."\n";
+  #  	print INFO 'calling expand with r: ' .$r ."\n";
+  #  	print INFO 'calling expand with table: ' .$table ."\n";
     	
     	# need to give the keywords as parameter for all extends..where do i get them TODO
     	
@@ -377,27 +378,27 @@
     	&Apache::lonsearch::createEvaluationRow('startuser', $env{'form.basicexp'}, 'a', 'd', 'c', 's', 'r','direct', $env{'user.name'}.':'.$env{'user.domain'});  	   	
 		&Apache::lonsearch::expandPrePost($env{'form.url_id'}, $table, $r, $env{'user.name'}.':'.$env{'user.domain'});
 		# then display again
-		print INFO "phase extenddirect: " .$env{'form.user'} . " " . $env{'form.domain'} . "\n";
+	#	print INFO "phase extenddirect: " .$env{'form.user'} . " " . $env{'form.domain'} . "\n";
 		&display_results($r,$importbutton,$closebutton,$diropendb,
                          $env{'form.area'},$env{'form.user'},$env{'form.domain'});
     } elsif ($env{'form.phase'} eq 'extendsac') {
     	# TODO first ...use implementation and write results	
     	my $table = $env{'form.table'};
-    	print INFO 'calling expand sac with r: ' .$r ."\n";
-    	print INFO 'calling expand sac with table: ' .$table ."\n";
-    	print INFO 'keywords ' . $env{'form.basicexp'}."\n";
-    	print INFO 'createrow with ' . $env{'user.name'}.':'.$env{'user.domain'} ."\n";
+    #	print INFO 'calling expand sac with r: ' .$r ."\n";
+    #	print INFO 'calling expand sac with table: ' .$table ."\n";
+    #	print INFO 'keywords ' . $env{'form.basicexp'}."\n";
+   # 	print INFO 'createrow with ' . $env{'user.name'}.':'.$env{'user.domain'} ."\n";
     	&Apache::lonsearch::createEvaluationRow('startuser', $env{'form.basicexp'}, 'a', 'd', 'c', 's', 'r','sac',$env{'user.name'}.':'.$env{'user.domain'});
 		my $startuser;
-		print INFO "++++++####++++++username: " . $env{'form.username'} ."\n";
+	#	print INFO "++++++####++++++username: " . $env{'form.username'} ."\n";
 		if ($env{'form.username'} ne '') { # if no explicit start user mentioned, assume the logged in user
 			$startuser = $env{'form.username'};
 		} else {
 			$startuser = $env{'user.name'}.':'.$env{'user.domain'};
 		}
-    	print INFO "+++++++++++++commuser " .$startuser ."\n";  
+ #   	print INFO "+++++++++++++commuser " .$startuser ."\n";  
     	my $keywords = &Apache::lonsearch::getKeywords($env{'user.name'}.':'.$env{'user.domain'});  	
-    	print INFO "# # # # # # key: $keywords\n";
+ #   	print INFO "# # # # # # key: $keywords\n";
 		&Apache::lonsearch::expandSAC($env{'form.url_id'}, $table, $r, $startuser, $keywords,$env{'user.name'}.':'.$env{'user.domain'},'AssignedSAC20');
 		# then display again
 #		print INFO "phase extendsac: " .$env{'form.user'} . " " . $env{'form.domain'} . "\n";
@@ -408,28 +409,28 @@
 #                         $env{'form.area'},"working");
 	#&print_sort_form($r,"whatsthis", "working ... please stand by");
 	my $table = $env{'form.table'};
-print INFO 'calling expand sac with r: ' .$r ."\n";
-    	print INFO 'calling expand sac with table: ' .$table ."\n";
-    	print INFO 'keywords ' . $env{'form.basicexp'}."\n"; 
+#print INFO 'calling expand sac with r: ' .$r ."\n";
+ #   	print INFO 'calling expand sac with table: ' .$table ."\n";
+   # 	print INFO 'keywords ' . $env{'form.basicexp'}."\n"; 
     	my $keywords = &Apache::lonsearch::getKeywords($env{'user.name'}.':'.$env{'user.domain'});
-    	print INFO "# # # # # # key: $keywords\n";
-    	print INFO 'createrow with ' . $env{'user.name'}.':'.$env{'user.domain'} ."\n";
+   # 	print INFO "# # # # # # key: $keywords\n";
+   # 	print INFO 'createrow with ' . $env{'user.name'}.':'.$env{'user.domain'} ."\n";
     	&Apache::lonsearch::createEvaluationRow('startuser', $keywords, 'a', 'd', 'c', 's', 'r','wac',$env{'user.name'}.':'.$env{'user.domain'});
 		my $startuser;
-		print INFO "++++++####++++++username: " . $env{'form.username'} ."\n";
+#		print INFO "++++++####++++++username: " . $env{'form.username'} ."\n";
 		if ($env{'form.username'} ne '') { # if no explicit start user mentioned, assume the logged in user
 			$startuser = $env{'form.username'};
 		} else {
 			$startuser = $env{'user.name'}.':'.$env{'user.domain'};
 		}
-		print INFO "+++++++++++++commuser " .$startuser ."\n"; 
+#		print INFO "+++++++++++++commuser " .$startuser ."\n"; 
 		&Apache::lonsearch::expandSAC($env{'form.url_id'}, $table, $r, $startuser, $env{'form.basicexp'},$env{'user.name'}.':'.$env{'user.domain'},'AssignedWAC50');
 		# then display again
 #		print INFO "phase extendsac: " .$env{'form.user'} . " " . $env{'form.domain'} . "\n";
 		&display_results($r,$importbutton,$closebutton,$diropendb,
                          $env{'form.area'});
     } elsif ($env{'form.phase'} eq 'results') {
- 		print INFO "phase results: " .$env{'form.user'} . " " . $env{'form.domain'} . "\n";
+ #		print INFO "phase results: " .$env{'form.user'} . " " . $env{'form.domain'} . "\n";
         &display_results($r,$importbutton,$closebutton,$diropendb,
                          $env{'form.area'});
     } elsif ($env{'form.phase'} =~ /^(sort|run_search)$/) {
@@ -438,23 +439,35 @@
                  ['query','customquery','customshow',
                   'libraries','pretty_string']);
         if ($env{'form.phase'} eq 'sort') {
+        	if ($env{'form.algorithm'} eq 'UsedAuthors' || $env{'form.algorithm'} eq 'RelatedCoordinators') {
+        		$env{'form.sortfield'} = "stdno";
+        	}
+        	print INFO "		sort eq sort -> printsortform: " . $env{'form.sortfield'} ."\n";
             &print_sort_form($r,$pretty_string);        
 
-} elsif ($env{'form.phase'} eq 'run_search') {  
+		} elsif ($env{'form.phase'} eq 'run_search') {  
         	# 'degree', 'connectivitywac','connectivitysac', 'instances'
         	$env{'finished'} = 'false';
         	
         	# clean out old results
         	my $table = $env{'form.table'};
-        	print INFO "YYYYYYYYYYYYY table $table \n"; #
+  #      	print INFO "YYYYYYYYYYYYY table $table \n"; #
         	&Apache::lonsearch::clearResults($env{'user.name'}."_".$env{'user.domain'}."_".$table);
-        	
+        	if ($env{'form.algorithm'} eq 'usedauthors' || $env{'form.algorithm'} eq 'relatedcoordinators') {
+        		$env{'form.sortfield'} = 'stdno';
+        	} else {
+        		$env{'form.sortfield'} = 'access';
+        	}
+        	print INFO "		sort from run_search: " . $env{'form.sortfield'};
             &run_search($r,$query,$customquery,$customshow,
                         $libraries,$pretty_string,$env{'form.area'}, $env{'form.algorithm'},
                         $env{'form.degree'},$env{'form.connectivitywac'},$env{'form.connectivitysac'},
-                        $env{'form.instances'},$env{'form.proximity'});
+                        $env{'form.instances'},$env{'form.proximity'},$env{'form.sortfield'});
+                      
+                      print INFO "		sort after run_search: " . $env{'form.sortfield'}."\n";  
+                        
             		&display_results($r,$importbutton,$closebutton,$diropendb,
-                         $env{'form.area'},$env{'user.name'},$env{'user.domain'});            
+                         $env{'form.area'},$env{'user.name'},$env{'user.domain'}, $env{'form.sortfield'});            
 #                        		&display_results($r,$importbutton,$closebutton,$diropendb,
 #                         $env{'form.area'},$env{'form.user'},$env{'form.domain'});                                               
         }
@@ -467,7 +480,7 @@
                   		$env{'user.name'}.':'.$env{'user.domain'}, 
                   		&Apache::lonmysql::number_of_rows($env{'form.table'})      
                   );
-		print INFO "after rating username is: " . $env{'form.username'} ."\n";
+#		print INFO "after rating username is: " . $env{'form.username'} ."\n";
 		&display_results($r,$importbutton,$closebutton,$diropendb,
                          $env{'form.area'}, $env{'form.username'});
     } elsif ($env{'form.phase'} eq 'course_search') {
@@ -1025,8 +1038,8 @@
     #
     my $user = $env{'form.user'};
     my $domain = $env{'form.domain'};
-    print INFO "user/domain at search: $user $domain \n";
-    print INFO "user/domain at search: " .$user .":". $domain .".\n";
+  #  print INFO "user/domain at search: $user $domain \n";
+  #  print INFO "user/domain at search: " .$user .":". $domain .".\n";
     $scrout.='<form name="loncapa_search" method="post" '.
              'action="/adm/searchcat">'.
              '<input type="hidden" name="phase" value="basic_search" />'.
@@ -2797,13 +2810,13 @@
 #                        $env{'form.instances'},);
 	
     my ($r,$query,$customquery,$customshow,$serverlist,
-        $pretty_string,$area,$algorithm,$degree,$connectivitywac,$connectivitysac,$instances,$proximity) = @_;
+        $pretty_string,$area,$algorithm,$degree,$connectivitywac,$connectivitysac,$instances,$proximity,$sortenv) = @_;
         
 # open a log file
     my $file = '/home/httpd/perl/logs/test.log';		# Name the file
-	open(INFO, ">>$file");		# Open the file
+#	open(INFO, ">$file");		# Open the file
 	print INFO "logfile opened, search started...\n";
-	INFO->autoflush(1);      
+#	INFO->autoflush(1);      
 	print INFO "algorithm run_search: " . $ENV{'form.algorithm'} . "\n";
    
     my $tabletype = 'metadata';		
@@ -2956,14 +2969,14 @@
 #                }
                 print INFO "finished writing result .\n";
 $|++;
-				close(INFO);
+				
 #                    
 #                $hitcountsum ++;
 #            }
 #            $fh->close();
 
     &update_status($r,&mt('Search Complete [_1]',$server));
-    &update_seconds($r);
+ #   &update_seconds($r);
     #
     &Apache::lonmysql::disconnect_from_db(); # This is unneccessary
     #
@@ -2978,6 +2991,7 @@
                       "persistent_db_id=$env{'form.persistent_db_id'}';".
                   "</script>");
 #    }
+	print INFO " 	... 	after run_search:" .$env{'form.sortfield'} ."\n";
     return;
 }
 
@@ -3022,9 +3036,12 @@
 =cut
 
 ######################################################################
+            #		&display_results($r,$importbutton,$closebutton,$diropendb,
+             #            $env{'form.area'},$env{'user.name'},$env{'user.domain'}, $env{'form.sortfield'});   
 ######################################################################
 sub display_results {
-    my ($r,$importbutton,$closebutton,$diropendb,$area, $username,$status) = @_;
+	print INFO "----++++----called display!! \n";
+    my ($r,$importbutton,$closebutton,$diropendb,$area, $username,$status,$mysort) = @_;
     my $connection = $r->connection;
     $r->print(&search_results_header($importbutton,$closebutton,$status));
     ##
@@ -3103,7 +3120,7 @@
     my @fields = 
         (
          {key=>'count'},
-         {key=>'default'},
+#         {key=>'default'},
          {key=>'title' },
          {key =>'author' },
          {key =>'url',desc=>'URL'},
@@ -3140,6 +3157,7 @@
 	    $env{'form.sortorder'}='asc';
 	}
     }
+    print INFO "		sort display: " . $env{'form.sortfield'} . "\n"; # . " no, instead: " . $mysort;
     my $sortform = &mt('Sort by [_1] [_2]',
                        &Apache::loncommon::select_form($env{'form.sortfield'},
                                                       'sortfield',
@@ -3150,16 +3168,19 @@
                                                        desc=>&mt('Descending')
                                                        ))
                        );
+                       print INFO $sortform . "\n";
     ##
     ## Output links (if necessary) for 'prev' and 'next' pages.
     $r->print
         ('<table width="100%"><tr><td width="25%" align="right">'.
          '<nobr>'.$sortform.'</nobr>'.
          '<input type="hidden" name="catalogmode" value="import"/>'.
+#         '<input type="hidden" name="sortfield" value="'.$env{'form.sortfield'}.'"/>'.
          '</td><td width="25%" align="right">'.
          &prev_next_buttons($min,$env{'form.show'},$total_results).
          '</td><td align="right">'.
-         &viewoptions().'</td></tr></table>'
+         &viewoptions().'</td></tr></table>'.
+         '?????????????????????'
          );
     if ($total_results == 0) { #  && ($env{'finished' eq 'false'})
    # 	if ($env{'finished' eq 'false'}) {
@@ -3193,6 +3214,17 @@
     }
     if ($env{'form.sortfield'} ne 'default' && 
         exists($sort_fields{$env{'form.sortfield'}})) {
+        print INFO "++++ save sort: " . $env{'form.sortfield'}." ".$env{'user.name'}.":".$env{'user.domain'} . "\n";
+		# get the last sort...if ne unkown -> create new eval row
+		my $userhandle = $env{'user.name'}.":".$env{'user.domain'};
+		my $lastsort = &Apache::lonsearch::getLastSort($userhandle);
+		print INFO "%%%%%% lastsort/ current: " . $lastsort. " ". $env{'form.sortfield'} ."\n";
+#		if ($lastsort ne 'unkown') {
+#	        my $algodata = &Apache::lonsearch::getEvalType($userhandle);
+#	        print INFO "+F%%%%%% action: " . $algodata ."\n";
+#	        &Apache::lonsearch::createEvaluationRow_Copy($algodata, $env{'form.sortfield'}, $userhandle);
+#		}
+        &Apache::lonsearch::saveSort($env{'form.sortfield'}, $userhandle); # ok
         $sort_command = $env{'form.sortfield'}.' IS NOT NULL '.
             'ORDER BY '.$env{'form.sortfield'}.' '.$order.
             '  LIMIT '.($min-1).','.($max-$min+1);
@@ -3230,6 +3262,7 @@
              &prev_next_buttons($min,$env{'form.show'},$total_results,
                                 "table=".$env{'form.table'}.
                                 "&phase=results".
+                                "&sort=".$env{'form.sortfield'}.
                                 "&persistent_db_id=".
                                 $env{'form.persistent_db_id'})
              ."</center>\n"

--hoeppner1214698936--